From 896b8819b880446f2e271536c9eac59d48e5d135 Mon Sep 17 00:00:00 2001 From: fedora Cloud User Date: Tue, 2 Apr 2024 14:51:53 +0000 Subject: [PATCH] cse.c->main.c, cleaning up. --- cse.c | 207 ---------------------------------------------------------- 1 file changed, 207 deletions(-) delete mode 100644 cse.c diff --git a/cse.c b/cse.c deleted file mode 100644 index bfd1f8f..0000000 --- a/cse.c +++ /dev/null @@ -1,207 +0,0 @@ -/** - * @file cse.c - * - * @brief Code file for entry point CXL Switch Emulator - * - * @copyright Copyright (C) 2024 Jackrabbit Founders LLC. All rights reserved. - * - * @date Jan 2024 - * @author Barrett Edwards - * - */ -/* INCLUDES ==================================================================*/ - -/* gettid() - */ -#define _GNU_SOURCE - -#include - -/* printf() - */ -#include - -/* memset() - */ -#include - -/* autl_prnt_buf() - */ -#include - -/* mctp_init() - * mctp_set_mh() - * mctp_run() - */ -#include - -#include "signals.h" - -#include "options.h" - -#include "state.h" - -#include "fmapi_handler.h" -#include "emapi_handler.h" - -/* MACROS ====================================================================*/ - -#ifdef CSE_VERBOSE - #define INIT unsigned step = 0; - #define ENTER if (opts[CLOP_VERBOSITY].u64 & CLVB_CALLSTACK) printf("%d:%s Enter\n", gettid(), __FUNCTION__); - #define STEP step++; if (opts[CLOP_VERBOSITY].u64 & CLVB_STEPS) printf("%d:%s STEP: %u\n", gettid(), __FUNCTION__, step); - #define HEX32(m, i) if (opts[CLOP_VERBOSITY].u64 & CLVB_STEPS) printf("%d:%s STEP: %u %s: 0x%x\n", gettid(), __FUNCTION__, step, m, i); - #define INT32(m, i) if (opts[CLOP_VERBOSITY].u64 & CLVB_STEPS) printf("%d:%s STEP: %u %s: %d\n", gettid(), __FUNCTION__, step, m, i); - #define EXIT(rc) if (opts[CLOP_VERBOSITY].u64 & CLVB_CALLSTACK) printf("%d:%s Exit: %d\n", gettid(), __FUNCTION__,rc); -#else - #define ENTER - #define EXIT(rc) - #define STEP - #define HEX32(m, i) - #define INT32(m, i) - #define INIT -#endif // CSE_VERBOSE - -#define IFV(u) if (opts[CLOP_VERBOSITY].u64 & u) - -/* ENUMERATIONS ==============================================================*/ - -/* STRUCTS ===================================================================*/ - - -/* PROTOTYPES ================================================================*/ - -/* GLOBAL VARIABLES ==========================================================*/ - -/* FUNCTIONS =================================================================*/ - -/** - * cse main - * - * STEPS - * 0: Parse CLI options - * 1: Register Signal Handlers - * 2: Initialize global state array - * 3: Load state file - * 4: Print the state - * 5: MCTP Init - * 6: Run MCTP - * 7: While loop - * 8: Stop MCTP - * 9: Free memory - */ -int main(int argc, char* argv[]) -{ - INIT - int rv; - struct mctp *m; - - // Initialize varaibles - stop_requested = 0; - rv = 1; - - // 0: Parse CLI options - rv = options_parse(argc,argv); - if (rv != 0) - { - printf("Error: Parse options failed: %d\n", rv); - goto end; - } - - STEP // 1: Register Signal Handlers - signals_register(); - - STEP // 2: Initialize global state array - cxl_state = state_init(32, 32, 256); - if (cxl_state == NULL) - { - printf("Error: state init failed \n"); - goto end_options; - } - - STEP // 3: Load state file - if (opts[CLOP_CONFIG_FILE].set) - { - rv = state_load(cxl_state, opts[CLOP_CONFIG_FILE].str); - if (rv < 0) - { - printf("Error: state load config file failed \n"); - goto end_state; - } - } - - STEP // 5: Print the state - if (opts[CLOP_PRINT_STATE].set) - state_print(cxl_state); - - STEP // 6: MCTP Init - m = mctp_init(); - if (m == NULL) - goto end_state; - - // Set supported MCTP Message Versions - mctp_set_version(m, MCMT_CXLFMAPI, 0xF2,0xF1,0xFF,0x00); - mctp_set_version(m, MCMT_CXLCCI, 0xF2,0xF1,0xFF,0x00); - - // Set Message handler functions - mctp_set_handler(m, MCMT_CXLFMAPI, fmapi_handler); - mctp_set_handler(m, MCMT_CSE, emapi_handler); - - // Set MCTP verbosity levels - mctp_set_verbosity(m, opts[CLOP_MCTP_VERBOSITY].u64); - - STEP // 7: Run MCTP - rv = mctp_run(m, opts[CLOP_TCP_PORT].u16, MCRM_SERVER, 1, 1); - if (rv != 0) - { - switch (rv) - { - case -1: - printf("Socket create failed\n"); - break; - case -2: - printf("Socket bind failed\n"); - break; - case -3: - printf("Socket connect failed"); - break; - case 1: - printf("Could not create Connection Handler Thread\n"); - break; - case 2: - printf("MCTP threads failed to start\n"); - break; - } - goto end_mctp; - } - - STEP // 8: While loop - while ( stop_requested == 0 ) - { - sleep(1); - } - - STEP // 9: Stop MCTP - mctp_stop(m); - -end_mctp: - - mctp_free(m); - - rv = 0; - -end_state: - - state_free(cxl_state); - -end_options: - - options_free(opts); - -end: - - EXIT(rv) - - return rv; -}; -