diff options
Diffstat (limited to 'lib/ipmi_ekanalyzer.c')
-rw-r--r-- | lib/ipmi_ekanalyzer.c | 2898 |
1 files changed, 1441 insertions, 1457 deletions
diff --git a/lib/ipmi_ekanalyzer.c b/lib/ipmi_ekanalyzer.c index 2ac1012..96d3b44 100644 --- a/lib/ipmi_ekanalyzer.c +++ b/lib/ipmi_ekanalyzer.c @@ -45,9 +45,9 @@ #define NO_MORE_INFO_FIELD 0xc1 #define TYPE_CODE 0xc0 /*Language code*/ -/***************************************************************** -* CONSTANT -*****************************************************************/ +/* + * CONSTANT + */ const int ERROR_STATUS = -1; const int OK_STATUS = 0; @@ -59,10 +59,10 @@ const int SIZE_OF_FILE_TYPE = 3; const unsigned char AMC_MODULE = 0x80; const int PICMG_ID_OFFSET = 3; const unsigned int COMPARE_CANDIDATE = 2; -/*In AMC.0 or PICMG 3.0 specification offset start from 0 with 3 bytes of -* Mfg.ID, 1 byte of Picmg record Id, and -* 1 byte of format version, so the data offset start from 5 -*/ +/* In AMC.0 or PICMG 3.0 specification offset start from 0 with 3 bytes of + * Mfg.ID, 1 byte of Picmg record Id, and + * 1 byte of format version, so the data offset start from 5 + */ const int START_DATA_OFFSET = 5; const int LOWER_OEM_TYPE = 0xf0; const int UPPER_OEM_TYPE = 0xfe; @@ -361,16 +361,18 @@ static void ipmi_ek_display_clock_config_record( * ***************************************************************************/ static void -ipmi_ekanalyzer_usage( void ) +ipmi_ekanalyzer_usage(void) { - lprintf(LOG_NOTICE, "Ekeying analyzer tool version 1.00"); - lprintf(LOG_NOTICE, "ekanalyzer Commands:"); lprintf(LOG_NOTICE, - " print [carrier | power | all] <oc=filename1> <b1=filename2>..."); +"Ekeying analyzer tool version 1.00"); + lprintf(LOG_NOTICE, +"ekanalyzer Commands:"); + lprintf(LOG_NOTICE, +" print [carrier | power | all] <oc=filename1> <b1=filename2>..."); lprintf(LOG_NOTICE, - " frushow <b2=filename>"); +" frushow <b2=filename>"); lprintf(LOG_NOTICE, - " summary [match | unmatch | all] <oc=filename1> <b1=filename2>..."); +" summary [match | unmatch | all] <oc=filename1> <b1=filename2>..."); } /************************************************************************** @@ -395,53 +397,41 @@ ipmi_ekanalyzer_usage( void ) * ipmi_ekanalyzer_module_type for a list of valid type. ***************************************************************************/ static int -ipmi_ek_get_file_type( char * argument ) +ipmi_ek_get_file_type(char *argument) { - int index_name=0; - int filetype = ERROR_STATUS; - - if( strlen (argument) > MIN_ARGUMENT ){ - if( strncmp( argument, "oc=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = ON_CARRIER_FRU_FILE; - } - else if( strncmp( argument, "a1=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = A1_AMC_FRU_FILE; - } - else if( strncmp( argument, "a2=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = A2_AMC_FRU_FILE; - } - else if( strncmp( argument, "a3=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = A3_AMC_FRU_FILE; - } - else if( strncmp( argument, "a4=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = A4_AMC_FRU_FILE; - } - else if( strncmp( argument, "b1=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = B1_AMC_FRU_FILE; - } - else if( strncmp( argument, "b2=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = B2_AMC_FRU_FILE; - } - else if( strncmp( argument, "b3=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = B3_AMC_FRU_FILE; - } - else if( strncmp( argument, "b4=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = B4_AMC_FRU_FILE; - } - else if( strncmp( argument, "rt=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = RTM_FRU_FILE; - } - else if( strncmp( argument, "rc=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = CONFIG_FILE; - } - else if( strncmp( argument, "sm=", SIZE_OF_FILE_TYPE ) == 0 ) { - filetype = SHELF_MANAGER_FRU_FILE; - } - else{ - filetype = ERROR_STATUS; - } - } - return filetype; + int index_name=0; + int filetype = ERROR_STATUS; + if (strlen(argument) <= MIN_ARGUMENT) { + return filetype; + } + if (strncmp(argument, "oc=", SIZE_OF_FILE_TYPE) == 0) { + filetype = ON_CARRIER_FRU_FILE; + } else if (strncmp(argument, "a1=", SIZE_OF_FILE_TYPE) == 0) { + filetype = A1_AMC_FRU_FILE; + } else if (strncmp(argument, "a2=", SIZE_OF_FILE_TYPE) == 0) { + filetype = A2_AMC_FRU_FILE; + } else if (strncmp(argument, "a3=", SIZE_OF_FILE_TYPE) == 0) { + filetype = A3_AMC_FRU_FILE; + } else if (strncmp(argument, "a4=", SIZE_OF_FILE_TYPE) == 0) { + filetype = A4_AMC_FRU_FILE; + } else if (strncmp(argument, "b1=", SIZE_OF_FILE_TYPE) == 0) { + filetype = B1_AMC_FRU_FILE; + } else if (strncmp(argument, "b2=", SIZE_OF_FILE_TYPE) == 0) { + filetype = B2_AMC_FRU_FILE; + } else if (strncmp(argument, "b3=", SIZE_OF_FILE_TYPE) == 0) { + filetype = B3_AMC_FRU_FILE; + } else if (strncmp(argument, "b4=", SIZE_OF_FILE_TYPE) == 0) { + filetype = B4_AMC_FRU_FILE; + } else if (strncmp(argument, "rt=", SIZE_OF_FILE_TYPE) == 0) { + filetype = RTM_FRU_FILE; + } else if (strncmp(argument, "rc=", SIZE_OF_FILE_TYPE) == 0) { + filetype = CONFIG_FILE; + } else if (strncmp(argument, "sm=", SIZE_OF_FILE_TYPE) == 0) { + filetype = SHELF_MANAGER_FRU_FILE; + } else { + filetype = ERROR_STATUS; + } + return filetype; } /************************************************************************** @@ -465,200 +455,194 @@ ipmi_ek_get_file_type( char * argument ) * ***************************************************************************/ int -ipmi_ekanalyzer_main( struct ipmi_intf * intf, int argc, char ** argv ) +ipmi_ekanalyzer_main(struct ipmi_intf *intf, int argc, char **argv) { - int rc = ERROR_STATUS; - int file_type[MAX_FILE_NUMBER]; - int tmp_ret = 0; - char * filename[MAX_FILE_NUMBER]; - unsigned int argument_offset = 0; - unsigned int type_offset = 0; - /*list des multi record*/ - struct ipmi_ek_multi_header * list_head = NULL; - struct ipmi_ek_multi_header * list_record = NULL; - struct ipmi_ek_multi_header * list_last = NULL; - - if ( (argc == 0) || ( (argc - 1) > MAX_FILE_NUMBER ) ){ - lprintf(LOG_ERR, "Too few or too many arguments!"); - ipmi_ekanalyzer_usage(); - rc = ERROR_STATUS; - } - else if ( strcmp(argv[argument_offset], "help") == 0) { - ipmi_ekanalyzer_usage(); - rc = 0; - } - else if ( (strcmp(argv[argument_offset], "frushow") == 0) - && (argc > (MIN_ARGUMENT-1) ) - ){ - for ( type_offset = 0; type_offset < (argc-1); type_offset++ ){ - argument_offset++; - file_type[type_offset] = ipmi_ek_get_file_type (argv[argument_offset]); - if ( file_type[type_offset] != ERROR_STATUS ){ - if ( file_type[type_offset] != CONFIG_FILE ){ - /* because of strlen doesn't count '\0', we need to add 1 byte for - * this character to filename size - */ - filename[type_offset] = malloc( strlen(argv[argument_offset]) + 1 - - SIZE_OF_FILE_TYPE - ); - if( filename[type_offset] != NULL ){ - strcpy(filename[type_offset], - &argv[argument_offset][SIZE_OF_FILE_TYPE]); - printf("Start converting file '%s'...\n", filename[type_offset]); - /* Display FRU header offset */ - rc = ipmi_ek_display_fru_header (filename[type_offset]); - - if ( rc != ERROR_STATUS ){ - /* Display FRU header info in detail record */ - tmp_ret = ipmi_ek_display_fru_header_detail(filename[type_offset]); - /* Convert from binary data into multi record structure */ - rc = ipmi_ekanalyzer_fru_file2structure ( filename[type_offset], - &list_head, &list_record, &list_last ); - - ipmi_ek_display_record ( list_record, list_head, list_last ); - /* Remove record of list */ - while ( list_head != NULL ){ - ipmi_ek_remove_record_from_list( list_head, - &list_head,&list_last ); - if (verbose > 1) - printf("record has been removed!\n"); - } - } - free(filename[type_offset]); - filename[type_offset] = NULL; - } - } - } - else{ - lprintf(LOG_ERR, "Invalid file type!"); - lprintf(LOG_ERR, " ekanalyzer frushow <xx=frufile> ..."); - } - } - } - else if ( (strcmp(argv[argument_offset], "print") == 0) - || (strcmp(argv[argument_offset], "summary") == 0) - ){ - /*Display help of the correspond command if there is not enought argument - * passing in command line - */ - if ( argc < MIN_ARGUMENT ){ - lprintf(LOG_ERR, "Not enough parameters given."); - if ( strcmp(argv[argument_offset], "print") == 0 ){ - lprintf(LOG_ERR, " ekanalyzer print [carrier/power/all]" - " <xx=frufile> <xx=frufile> [xx=frufile]" - ); - } - else{ - lprintf(LOG_ERR, " ekanalyzer summary [match/ unmatch/ all]" - " <xx=frufile> <xx=frufile> [xx=frufile]" - ); - } - } - else{ - char * option; - /*index=1 indicates start position of first file name in command line*/ - int index = 1; - int filename_size=0; - - argument_offset++; - if ( (strcmp(argv[argument_offset], "carrier") == 0) - || (strcmp(argv[argument_offset], "power") == 0) - || (strcmp(argv[argument_offset], "all") == 0) - ){ - option = argv[argument_offset]; - index ++; - argc--; - } - else if ( ( strcmp(argv[argument_offset], "match") == 0 ) - || ( strcmp(argv[argument_offset], "unmatch") == 0 ) - ){ - option = argv[argument_offset]; - index ++; - argc--; - } - /*since the command line must receive xx=filename, so the position of - * "=" sign is 2 - */ - else if ( strncmp(&argv[argument_offset][2], "=", 1) == 0 ){ - option = "default"; - /* Since there is no option from user, the first argument - * becomes first file type */ - index = 1; /* index of argument */ - } - else{ - option = "invalid"; - printf("Invalid option '%s'\n", argv[argument_offset]); - argument_offset--; - if (strcmp(argv[0], "print") == 0){ - lprintf (LOG_ERR, " ekanalyzer print [carrier/power/all]" - " <xx=frufile> <xx=frufile> [xx=frufile]" - ); - } - else{ - lprintf (LOG_ERR, " ekanalyzer summary [match/ unmatch/ all]" - " <xx=frufile> <xx=frufile> [xx=frufile]" - ); - } - rc = ERROR_STATUS; - } - if ( strcmp(option, "invalid") != 0 ){ - int i=0; - - for ( i = 0; i < (argc-1); i++){ - file_type[i] = ipmi_ek_get_file_type (argv[index]); - if ( file_type[i] == ERROR_STATUS ){ - /* display the first 2 charactors (file type) of argument */ - lprintf(LOG_ERR, "Invalid file type: %c%c\n", argv[index][0], - argv[index][1]); - ipmi_ekanalyzer_usage(); - rc = ERROR_STATUS; - break; - } - /*size is equal to string size minus 3 bytes of file type plus - * 1 byte of '\0' since the strlen doesn't count the '\0' - */ - filename_size = strlen( argv[index] ) - SIZE_OF_FILE_TYPE + 1; - if ( filename_size > 0 ){ - filename[i] = malloc( filename_size ); - if (filename[i] != NULL) - strcpy( filename[i], &argv[index][SIZE_OF_FILE_TYPE] ); - } - rc = OK_STATUS; - index++; - } - if ( rc != ERROR_STATUS ){ - if (verbose > 0){ - for (i = 0; i < (argc-1); i++){ - printf ("Type: %s, ", - val2str(file_type[i], ipmi_ekanalyzer_module_type)); - printf("file name: %s\n", filename[i]); - } - } - if (strcmp(argv[0], "print") == 0){ - rc = ipmi_ekanalyzer_print( - (argc-1), option, filename, file_type); - } - else{ - rc = ipmi_ekanalyzer_ekeying_match( - (argc-1), option, filename, file_type); - } - for (i = 0; i < (argc-1); i++){ - if (filename[i] != NULL){ - free(filename[i]); - filename[i] = NULL; - } - } - } /* End of ERROR_STATUS */ - } /* End of comparison of invalid option */ - } /* End of else MIN_ARGUMENT */ - } /* End of print or summary option */ - else{ - lprintf(LOG_ERR, "Invalid ekanalyzer command: %s", argv[0]); - ipmi_ekanalyzer_usage(); - rc = ERROR_STATUS; - } + int rc = ERROR_STATUS; + int file_type[MAX_FILE_NUMBER]; + int tmp_ret = 0; + char *filename[MAX_FILE_NUMBER]; + unsigned int argument_offset = 0; + unsigned int type_offset = 0; + /* list des multi record */ + struct ipmi_ek_multi_header *list_head = NULL; + struct ipmi_ek_multi_header *list_record = NULL; + struct ipmi_ek_multi_header *list_last = NULL; + + if (argc == 0) { + lprintf(LOG_ERR, "Not enough parameters given."); + ipmi_ekanalyzer_usage(); + return (-1); + } else if ((argc - 1) > MAX_FILE_NUMBER) { + lprintf(LOG_ERR, "Too too many parameters given."); + return (-1); + } - return rc; + if (strcmp(argv[argument_offset], "help") == 0) { + ipmi_ekanalyzer_usage(); + return 0; + } else if ((strcmp(argv[argument_offset], "frushow") == 0) + && (argc > (MIN_ARGUMENT-1))) { + for (type_offset = 0; type_offset < (argc-1); type_offset++ ) { + argument_offset++; + file_type[type_offset] = ipmi_ek_get_file_type(argv[argument_offset]); + if (file_type[type_offset] == ERROR_STATUS + || file_type[type_offset] == CONFIG_FILE) { + lprintf(LOG_ERR, "Invalid file type!"); + lprintf(LOG_ERR, " ekanalyzer frushow <xx=frufile> ..."); + return (-1); + } + /* because of strlen doesn't count '\0', + * we need to add 1 byte for this character + * to filename size + */ + filename[type_offset] = malloc(strlen(argv[argument_offset]) + + 1 - SIZE_OF_FILE_TYPE); + if (filename[type_offset] == NULL) { + lprintf(LOG_ERR, "malloc failure"); + return (-1); + } + strcpy(filename[type_offset], + &argv[argument_offset][SIZE_OF_FILE_TYPE]); + printf("Start converting file '%s'...\n", + filename[type_offset]); + /* Display FRU header offset */ + rc = ipmi_ek_display_fru_header (filename[type_offset]); + if (rc != ERROR_STATUS) { + /* Display FRU header info in detail record */ + tmp_ret = ipmi_ek_display_fru_header_detail(filename[type_offset]); + /* Convert from binary data into multi record structure */ + rc = ipmi_ekanalyzer_fru_file2structure (filename[type_offset], + &list_head, &list_record, &list_last ); + ipmi_ek_display_record(list_record, list_head, list_last); + /* Remove record of list */ + while (list_head != NULL) { + ipmi_ek_remove_record_from_list(list_head, + &list_head,&list_last ); + if (verbose > 1) { + printf("record has been removed!\n"); + } + } + } + free(filename[type_offset]); + filename[type_offset] = NULL; + } + } else if ((strcmp(argv[argument_offset], "print") == 0) + || (strcmp(argv[argument_offset], "summary") == 0)) { + /* Display help text for corresponding command + * if not enough parameters were given. + */ + char * option; + /* index=1 indicates start position of first file + * name in command line + */ + int index = 1; + int filename_size=0; + if (argc < MIN_ARGUMENT) { + lprintf(LOG_ERR, "Not enough parameters given."); + if (strcmp(argv[argument_offset], "print") == 0) { + lprintf(LOG_ERR, + " ekanalyzer print [carrier/power/all]" + " <xx=frufile> <xx=frufile> [xx=frufile]"); + } else { + lprintf(LOG_ERR, + " ekanalyzer summary [match/ unmatch/ all]" + " <xx=frufile> <xx=frufile> [xx=frufile]"); + } + return ERROR_STATUS; + } + argument_offset++; + if ((strcmp(argv[argument_offset], "carrier") == 0) + || (strcmp(argv[argument_offset], "power") == 0) + || (strcmp(argv[argument_offset], "all") == 0)) { + option = argv[argument_offset]; + index ++; + argc--; + } else if ((strcmp(argv[argument_offset], "match") == 0) + || ( strcmp(argv[argument_offset], "unmatch") == 0)) { + option = argv[argument_offset]; + index ++; + argc--; + } else if ( strncmp(&argv[argument_offset][2], "=", 1) == 0) { + /* since the command line must receive xx=filename, + * so the position of "=" sign is 2 + */ + option = "default"; + /* Since there is no option from user, the first argument + * becomes first file type + */ + index = 1; /* index of argument */ + } else { + option = "invalid"; + printf("Invalid option '%s'\n", argv[argument_offset]); + argument_offset--; + if (strcmp(argv[0], "print") == 0) { + lprintf (LOG_ERR, + " ekanalyzer print [carrier/power/all]" + " <xx=frufile> <xx=frufile> [xx=frufile]"); + } else { + lprintf (LOG_ERR, + " ekanalyzer summary [match/ unmatch/ all]" + " <xx=frufile> <xx=frufile> [xx=frufile]"); + } + rc = ERROR_STATUS; + } + if (strcmp(option, "invalid") != 0) { + int i=0; + for (i = 0; i < (argc-1); i++) { + file_type[i] = ipmi_ek_get_file_type (argv[index]); + if (file_type[i] == ERROR_STATUS) { + /* display the first 2 charactors (file type) of argument */ + lprintf(LOG_ERR, "Invalid file type: %c%c\n", + argv[index][0], + argv[index][1]); + ipmi_ekanalyzer_usage(); + rc = ERROR_STATUS; + break; + } + /* size is equal to string size minus 3 bytes of file type plus + * 1 byte of '\0' since the strlen doesn't count the '\0' + */ + filename_size = strlen(argv[index]) - SIZE_OF_FILE_TYPE + 1; + if (filename_size > 0) { + /* TODO - check malloc() retval */ + filename[i] = malloc( filename_size ); + if (filename[i] != NULL) { + strcpy(filename[i], &argv[index][SIZE_OF_FILE_TYPE]); + } + } + rc = OK_STATUS; + index++; + } + if (rc != ERROR_STATUS) { + if (verbose > 0) { + for (i = 0; i < (argc-1); i++) { + printf ("Type: %s, ", + val2str(file_type[i], + ipmi_ekanalyzer_module_type)); + printf("file name: %s\n", filename[i]); + } + } + if (strcmp(argv[0], "print") == 0) { + rc = ipmi_ekanalyzer_print((argc-1), + option, filename, file_type); + } else { + rc = ipmi_ekanalyzer_ekeying_match((argc-1), + option, filename, file_type); + } + for (i = 0; i < (argc-1); i++) { + if (filename[i] != NULL) { + free(filename[i]); + filename[i] = NULL; + } + } + } /* End of ERROR_STATUS */ + } /* End of comparison of invalid option */ + } else { + lprintf(LOG_ERR, "Invalid ekanalyzer command: %s", argv[0]); + ipmi_ekanalyzer_usage(); + rc = ERROR_STATUS; + } + return rc; } /************************************************************************** @@ -685,99 +669,96 @@ ipmi_ekanalyzer_main( struct ipmi_intf * intf, int argc, char ** argv ) * ***************************************************************************/ static int -ipmi_ekanalyzer_print( int argc, char * opt, char ** filename, int * file_type ) +ipmi_ekanalyzer_print(int argc, char *opt, char **filename, int *file_type) { - int return_value = OK_STATUS; - - /*Display carrier topology*/ - if ( (strcmp(opt, "carrier") == 0) || (strcmp(opt, "default") == 0) ){ - tboolean found_flag = FALSE; - int index = 0; - int index_name[argc]; - int list = 0; - /*list of multi record*/ - struct ipmi_ek_multi_header * list_head[argc]; - struct ipmi_ek_multi_header * list_record[argc]; - struct ipmi_ek_multi_header * list_last[argc]; - - for ( list=0; list < argc; list++ ){ - list_head[list] = NULL; - list_record[list] = NULL; - list_last[list] = NULL; - } - - list=0; /* reset list count */ - for ( index = 0; index < argc; index++ ){ - if ( file_type[index] == ON_CARRIER_FRU_FILE ){ - index_name[list] = index; - return_value = ipmi_ekanalyzer_fru_file2structure( filename[index], - &list_head[list], &list_record[list], &list_last[list] ); - list++; - found_flag = TRUE; - } - } - if ( !found_flag ){ - printf("No carrier file has been found\n"); - return_value = ERROR_STATUS; - } - else{ - int i = 0; - for ( i = 0; i < argc; i++ ){ - /*this is a flag to advoid displaying the same data multiple time*/ - tboolean first_data = TRUE; - for ( list_record[i] = list_head[i]; - list_record[i] != NULL; - list_record[i] = list_record[i]->next ){ - if ( list_record[i]->data[PICMG_ID_OFFSET] - == - FRU_AMC_CARRIER_P2P ){ - if ( first_data ){ - printf("%s\n", STAR_LINE_LIMITER); - printf("From Carrier file: %s\n", filename[index_name[i]]); - first_data = FALSE; - } - return_value = ipmi_ek_display_carrier_connectivity( - list_record[i] ); - } - else if ( list_record[i]->data[PICMG_ID_OFFSET] - == - FRU_AMC_CARRIER_INFO ){ - /*See AMC.0 specification Table3-3 for mor detail*/ - #define COUNT_OFFSET 6 - if ( first_data ){ - printf("From Carrier file: %s\n", filename[index_name[i]]); - first_data = FALSE; - } - printf(" Number of AMC bays supported by Carrier: %d\n", - list_record[i]->data[COUNT_OFFSET] ); - } - } - } - /*Destroy the list of record*/ - for ( i = 0; i < argc; i++ ){ - while ( list_head[i] != NULL ){ - ipmi_ek_remove_record_from_list( list_head[i], - &list_head[i], &list_last[i] ); - } - /* display deleted result when we reach the last record */ - if ( ( i == (list-1) ) && verbose ) - printf("Record list has been removed successfully\n"); - } - } - } - else if ( (strcmp(opt, "power") == 0) ){ - printf("Print power information\n"); - return_value = ipmi_ek_display_power(argc, opt, filename, file_type); - } - else if ( strcmp(opt, "all") == 0 ){ - printf("Print all information\n"); - return_value = ipmi_ek_display_power(argc, opt, filename, file_type); - } - else{ - lprintf(LOG_ERR, "Invalid option %s", opt); - return_value = ERROR_STATUS; - } - return return_value; + int return_value = OK_STATUS; + /* Display carrier topology */ + if ((strcmp(opt, "carrier") == 0) || (strcmp(opt, "default") == 0)) { + tboolean found_flag = FALSE; + int index = 0; + int index_name[argc]; + int list = 0; + /* list of multi record */ + struct ipmi_ek_multi_header *list_head[argc]; + struct ipmi_ek_multi_header *list_record[argc]; + struct ipmi_ek_multi_header *list_last[argc]; + + for (list=0; list < argc; list++) { + list_head[list] = NULL; + list_record[list] = NULL; + list_last[list] = NULL; + } + /* reset list count */ + list = 0; + for (index = 0; index < argc; index++) { + if (file_type[index] != ON_CARRIER_FRU_FILE) { + continue; + } + index_name[list] = index; + return_value = ipmi_ekanalyzer_fru_file2structure(filename[index], + &list_head[list], + &list_record[list], + &list_last[list]); + list++; + found_flag = TRUE; + } + if (!found_flag) { + printf("No carrier file has been found\n"); + return_value = ERROR_STATUS; + } else { + int i = 0; + for (i = 0; i < argc; i++) { + /* this is a flag to advoid displaying + * the same data multiple time + */ + tboolean first_data = TRUE; + for (list_record[i] = list_head[i]; + list_record[i] != NULL; + list_record[i] = list_record[i]->next) { + if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_P2P) { + if (first_data) { + printf("%s\n", STAR_LINE_LIMITER); + printf("From Carrier file: %s\n", filename[index_name[i]]); + first_data = FALSE; + } + return_value = ipmi_ek_display_carrier_connectivity(list_record[i]); + } else if (list_record[i]->data[PICMG_ID_OFFSET] == FRU_AMC_CARRIER_INFO) { + /*See AMC.0 specification Table3-3 for mor detail*/ + #define COUNT_OFFSET 6 + if (first_data) { + printf("From Carrier file: %s\n", filename[index_name[i]]); + first_data = FALSE; + } + printf(" Number of AMC bays supported by Carrier: %d\n", + list_record[i]->data[COUNT_OFFSET]); + } + } + } + /*Destroy the list of record*/ + for (i = 0; i < argc; i++) { + while (list_head[i] != NULL) { + ipmi_ek_remove_record_from_list(list_head[i], + &list_head[i], &list_last[i]); + } + /* display deleted result when we + * reach the last record + */ + if ((i == (list-1)) && verbose) { + printf("Record list has been removed successfully\n"); + } + } + } + } else if (strcmp(opt, "power") == 0) { + printf("Print power information\n"); + return_value = ipmi_ek_display_power(argc, opt, filename, file_type); + } else if (strcmp(opt, "all") == 0) { + printf("Print all information\n"); + return_value = ipmi_ek_display_power(argc, opt, filename, file_type); + } else { + lprintf(LOG_ERR, "Invalid option %s", opt); + return_value = ERROR_STATUS; + } + return return_value; } /************************************************************************** @@ -800,86 +781,79 @@ ipmi_ekanalyzer_print( int argc, char * opt, char ** filename, int * file_type ) * ***************************************************************************/ static int -ipmi_ek_display_carrier_connectivity( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_carrier_connectivity(struct ipmi_ek_multi_header *record) { - int return_value = ERROR_STATUS; - struct fru_picmgext_carrier_p2p_record rsc_desc; - struct fru_picmgext_carrier_p2p_descriptor *port_desc; - - if ( record == NULL ){ - lprintf(LOG_ERR, "P2P connectivity record is invalid\n"); - return_value = ERROR_STATUS; - } - else{ - int offset = START_DATA_OFFSET; - if ( verbose > 1 ){ - int k = 0; - printf("Binary data of Carrier p2p connectivity"\ - " record starting from mfg id\n"); - for ( k = 0; k < ( record->header.len ); k++ ){ - printf("%02x ", record->data[k]); - } - printf("\n"); - } - while ( offset <= (record->header.len - START_DATA_OFFSET) ){ - rsc_desc.resource_id = record->data[offset++]; - rsc_desc.p2p_count = record->data[offset++]; - if ( verbose > 0 ){ - printf("resource id= %02x port count= %d\n", - rsc_desc.resource_id,rsc_desc.p2p_count); - } - /*check if it is an AMC Module*/ - if ( ( (rsc_desc.resource_id & AMC_MODULE) ) == AMC_MODULE ) { - /*check if it is an RTM module*/ - if ((rsc_desc.resource_id == AMC_MODULE)){ - printf(" %s topology:\n", val2str( RTM_IPMB_L, - ipmi_ekanalyzer_IPMBL_addr)); - } - else{ - /*The last four bits of resource ID represent site number - * (mask = 0x0f) - */ - printf(" %s topology:\n", - val2str( (rsc_desc.resource_id & 0x0f), - ipmi_ekanalyzer_module_type)); - } - } - else{ - printf(" On Carrier Device ID %d topology: \n", - (rsc_desc.resource_id & 0x0f)); - } - while ( rsc_desc.p2p_count > 0 ){ - unsigned char data[3]; -#ifndef WORDS_BIGENDIAN - data[0] = record->data[offset+0]; - data[1] = record->data[offset+1]; - data[2] = record->data[offset+2]; -#else - data[0] = record->data[offset+2]; - data[1] = record->data[offset+1]; - data[2] = record->data[offset+0]; -#endif - port_desc = (struct fru_picmgext_carrier_p2p_descriptor*)data; - offset += sizeof (struct fru_picmgext_carrier_p2p_descriptor); - if ((port_desc->remote_resource_id & AMC_MODULE) == AMC_MODULE) { - printf("\tPort %d =====> %s, Port %d\n", - port_desc->local_port, - val2str( (port_desc->remote_resource_id & 0x0f), - ipmi_ekanalyzer_module_type), - port_desc->remote_port); + int offset = START_DATA_OFFSET; + struct fru_picmgext_carrier_p2p_record rsc_desc; + struct fru_picmgext_carrier_p2p_descriptor *port_desc; + if (record == NULL) { + lprintf(LOG_ERR, "P2P connectivity record is invalid\n"); + return ERROR_STATUS; + } + if (verbose > 1) { + int k = 0; + printf("Binary data of Carrier p2p connectivity"\ + " record starting from mfg id\n"); + for (k = 0; k < (record->header.len); k++) { + printf("%02x ", record->data[k]); } - else { - printf("\tPort %d =====> On Carrier Device ID %d, Port %d\n", - port_desc->local_port, - (port_desc->remote_resource_id & 0x0f), - port_desc->remote_port); + printf("\n"); + } + while (offset <= (record->header.len - START_DATA_OFFSET)) { + rsc_desc.resource_id = record->data[offset++]; + rsc_desc.p2p_count = record->data[offset++]; + if (verbose > 0) { + printf("resource id= %02x port count= %d\n", + rsc_desc.resource_id, rsc_desc.p2p_count); } - rsc_desc.p2p_count--; - } - } - return_value = OK_STATUS; - } - return return_value; + /* check if it is an AMC Module */ + if ((rsc_desc.resource_id & AMC_MODULE) == AMC_MODULE) { + /* check if it is an RTM module */ + if (rsc_desc.resource_id == AMC_MODULE) { + printf(" %s topology:\n", + val2str(RTM_IPMB_L, + ipmi_ekanalyzer_IPMBL_addr)); + } else { + /* The last four bits of resource ID + * represent site number (mask = 0x0f) + */ + printf(" %s topology:\n", + val2str((rsc_desc.resource_id & 0x0f), + ipmi_ekanalyzer_module_type)); + } + } else { + printf(" On Carrier Device ID %d topology: \n", + (rsc_desc.resource_id & 0x0f)); + } + while (rsc_desc.p2p_count > 0) { + unsigned char data[3]; +# ifndef WORDS_BIGENDIAN + data[0] = record->data[offset + 0]; + data[1] = record->data[offset + 1]; + data[2] = record->data[offset + 2]; +# else + data[0] = record->data[offset + 2]; + data[1] = record->data[offset + 1]; + data[2] = record->data[offset + 0]; +# endif + port_desc = (struct fru_picmgext_carrier_p2p_descriptor*)data; + offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor); + if ((port_desc->remote_resource_id & AMC_MODULE) == AMC_MODULE) { + printf("\tPort %d =====> %s, Port %d\n", + port_desc->local_port, + val2str((port_desc->remote_resource_id & 0x0f), + ipmi_ekanalyzer_module_type), + port_desc->remote_port); + } else { + printf("\tPort %d =====> On Carrier Device ID %d, Port %d\n", + port_desc->local_port, + (port_desc->remote_resource_id & 0x0f), + port_desc->remote_port); + } + rsc_desc.p2p_count--; + } + } + return OK_STATUS; } /************************************************************************** @@ -1050,30 +1024,33 @@ ipmi_ek_display_power( int argc, char * opt, char ** filename, int * file_type ) ***************************************************************************/ static void ipmi_ek_display_current_descriptor( - struct fru_picmgext_carrier_activation_record car, - struct fru_picmgext_activation_record * cur_desc, char * filename ) + struct fru_picmgext_carrier_activation_record car, + struct fru_picmgext_activation_record *cur_desc, + char *filename) { - int index = 0; - float power_in_watt = 0.0; - float current_in_amp = 0.0; - - for ( index = 0; index < car.module_activation_record_count; index++ ){ - /*See AMC.0 specification, Table 3-12 for detail about calculation*/ - current_in_amp = (float) cur_desc[index].max_module_curr * 0.1; - power_in_watt = (float) current_in_amp * AMC_VOLTAGE; - - printf(" Carrier AMC power available on %s:\n", - val2str( cur_desc[index].ibmb_addr, ipmi_ekanalyzer_IPMBL_addr ) ); - printf("\t- Local IPMB Address \t: %02x\n", cur_desc[index].ibmb_addr); - printf("\t- Maximum module Current\t: %.2f Watts (%.2f Amps)\n", - power_in_watt, current_in_amp ); - } - /*Display total power on Carrier*/ - current_in_amp = (float) car.max_internal_curr * 0.1; - power_in_watt = (float) current_in_amp * AMC_VOLTAGE; - printf(" Carrier AMC total power available for all bays from file '%s':", - filename); - printf(" %.2f Watts (%.2f Amps)\n", power_in_watt, current_in_amp ); + int index = 0; + float power_in_watt = 0.0; + float current_in_amp = 0.0; + for (index = 0; index < car.module_activation_record_count; index++) { + /* See AMC.0 specification, Table 3-12 for + * detail about calculation + */ + current_in_amp = (float)cur_desc[index].max_module_curr * 0.1; + power_in_watt = (float)current_in_amp * AMC_VOLTAGE; + printf(" Carrier AMC power available on %s:\n", + val2str( cur_desc[index].ibmb_addr, + ipmi_ekanalyzer_IPMBL_addr)); + printf("\t- Local IPMB Address \t: %02x\n", + cur_desc[index].ibmb_addr); + printf("\t- Maximum module Current\t: %.2f Watts (%.2f Amps)\n", + power_in_watt, current_in_amp); + } + /* Display total power on Carrier */ + current_in_amp = (float)car.max_internal_curr * 0.1; + power_in_watt = (float)current_in_amp * AMC_VOLTAGE; + printf(" Carrier AMC total power available for all bays from file '%s':", + filename); + printf(" %.2f Watts (%.2f Amps)\n", power_in_watt, current_in_amp); } /************************************************************************** @@ -1901,72 +1878,60 @@ ipmi_ek_compare_channel_descriptor( ***************************************************************************/ static int ipmi_ek_compare_link_descriptor( - struct ipmi_ek_amc_p2p_connectivity_record record1, int index1, - struct ipmi_ek_amc_p2p_connectivity_record record2, int index2 ) + struct ipmi_ek_amc_p2p_connectivity_record record1, + int index1, + struct ipmi_ek_amc_p2p_connectivity_record record2, + int index2) { - int result = ERROR_STATUS; - - if (record1.link_desc[index1].type == record2.link_desc[index2].type){ - /*if it is an OEM type, we compare the OEM GUID*/ - if ( (record1.link_desc[index1].type >= LOWER_OEM_TYPE) - && (record1.link_desc[index1].type <= UPPER_OEM_TYPE) - ){ - if ( (record1.guid_count == 0) && (record2.guid_count == 0) ){ - /*there is no GUID for comparison, so the result is always OK*/ - result = OK_STATUS; - } - else{ - int i=0; - int j=0; - - for( i=0; i<record1.guid_count; i++){ - for( j=0; j < record2.guid_count; j++){ - if( memcmp (&record1.oem_guid[i], &record2.oem_guid[j], - SIZE_OF_GUID ) - == 0 - ){ - result = OK_STATUS; - break; - } - } - } - } - } - else{ - result = OK_STATUS; - } - if (result == OK_STATUS){ - if (record1.link_desc[index1].type_ext - == record2.link_desc[index2].type_ext - ){ - unsigned char asym[COMPARE_CANDIDATE]; - int offset = 0; - - asym[offset++] = record1.link_desc[index1].asym_match; - asym[offset] = record2.link_desc[index2].asym_match; - result = ipmi_ek_compare_asym ( asym ); - if (result == OK_STATUS){ - struct fru_picmgext_amc_link_desc_record link[COMPARE_CANDIDATE]; - int index = 0; - - link[index++] = record1.link_desc[index1]; - link[index] = record2.link_desc[index2]; - result = ipmi_ek_compare_number_of_enable_port( link ); - } - else{ - result = ERROR_STATUS; - } - } - else{ - result = ERROR_STATUS; - } - } - } - else{ - result = ERROR_STATUS; - } - - return result; + int result = ERROR_STATUS; + if (record1.link_desc[index1].type != record2.link_desc[index2].type) { + return ERROR_STATUS; + } + /* if it is an OEM type, we compare the OEM GUID */ + if ((record1.link_desc[index1].type >= LOWER_OEM_TYPE) + && (record1.link_desc[index1].type <= UPPER_OEM_TYPE)) { + if ((record1.guid_count == 0) && (record2.guid_count == 0)) { + /*there is no GUID for comparison, so the result is always OK*/ + result = OK_STATUS; + } else { + int i = 0; + int j = 0; + for (i = 0; i < record1.guid_count; i++) { + for (j = 0; j < record2.guid_count; j++) { + if (memcmp(&record1.oem_guid[i], + &record2.oem_guid[j], + SIZE_OF_GUID) == 0) { + result = OK_STATUS; + break; + } + } + } + } + } else { + result = OK_STATUS; + } + if (result != OK_STATUS) { + return result; + } + if (record1.link_desc[index1].type_ext == record2.link_desc[index2].type_ext) { + unsigned char asym[COMPARE_CANDIDATE]; + int offset = 0; + asym[offset++] = record1.link_desc[index1].asym_match; + asym[offset] = record2.link_desc[index2].asym_match; + result = ipmi_ek_compare_asym (asym); + if (result == OK_STATUS){ + struct fru_picmgext_amc_link_desc_record link[COMPARE_CANDIDATE]; + int index = 0; + link[index++] = record1.link_desc[index1]; + link[index] = record2.link_desc[index2]; + result = ipmi_ek_compare_number_of_enable_port(link); + } else { + result = ERROR_STATUS; + } + } else { + result = ERROR_STATUS; + } + return result; } /************************************************************************** @@ -1989,22 +1954,20 @@ ipmi_ek_compare_link_descriptor( ***************************************************************************/ static int -ipmi_ek_compare_asym( unsigned char asym[COMPARE_CANDIDATE] ) +ipmi_ek_compare_asym(unsigned char asym[COMPARE_CANDIDATE]) { - int return_value = ERROR_STATUS; - int first_index = 0; - int second_index = 1; - - if ( (asym[first_index] == 0) && (asym[second_index] == 0) ){ - return_value = OK_STATUS; - } - else if ( (asym[first_index] & asym[second_index]) == 0 ){ - return_value = OK_STATUS; - } - else{ - return_value = ERROR_STATUS; - } - return return_value; + int return_value = ERROR_STATUS; + int first_index = 0; + int second_index = 1; + + if ((asym[first_index] == 0) && (asym[second_index] == 0)) { + return_value = OK_STATUS; + } else if ((asym[first_index] & asym[second_index]) == 0) { + return_value = OK_STATUS; + } else { + return_value = ERROR_STATUS; + } + return return_value; } /************************************************************************** @@ -2027,49 +1990,54 @@ ipmi_ek_compare_asym( unsigned char asym[COMPARE_CANDIDATE] ) ***************************************************************************/ static int ipmi_ek_compare_number_of_enable_port( - struct fru_picmgext_amc_link_desc_record link_desc[COMPARE_CANDIDATE] ) + struct fru_picmgext_amc_link_desc_record link_desc[COMPARE_CANDIDATE]) { - int amc_port_count = 0; - int carrier_port_count = 0; - int return_value = ERROR_STATUS; - int index = 0; - - if (link_desc[index].port_flag_0){ /*bit 0 indicates port 0*/ - amc_port_count++; - } - if (link_desc[index].port_flag_1){ /*bit 1 indicates port 1*/ - amc_port_count++; - } - if (link_desc[index].port_flag_2){ /*bit 2 indicates port 2*/ - amc_port_count++; - } - if (link_desc[index++].port_flag_3){ /*bit 3 indicates port 3*/ - amc_port_count++; - } - - /*2nd link designator*/ - if (link_desc[index].port_flag_0){ /*bit 0 indicates port 0*/ - carrier_port_count++; - } - if (link_desc[index].port_flag_1){ /*bit 1 indicates port 1*/ - carrier_port_count++; - } - if (link_desc[index].port_flag_2){ /*bit 2 indicates port 2*/ - carrier_port_count++; - } - if (link_desc[index].port_flag_3){ /*bit 3 indicates port 3*/ - carrier_port_count++; - } - - if(carrier_port_count == amc_port_count){ + int amc_port_count = 0; + int carrier_port_count = 0; + int return_value = ERROR_STATUS; + int index = 0; + + if (link_desc[index].port_flag_0) { + /*bit 0 indicates port 0*/ + amc_port_count++; + } + if (link_desc[index].port_flag_1) { + /*bit 1 indicates port 1*/ + amc_port_count++; + } + if (link_desc[index].port_flag_2) { + /*bit 2 indicates port 2*/ + amc_port_count++; + } + if (link_desc[index++].port_flag_3) { + /*bit 3 indicates port 3*/ + amc_port_count++; + } - return_value = OK_STATUS; - } - else{ - return_value = ERROR_STATUS; - } + /* 2nd link designator */ + if (link_desc[index].port_flag_0) { + /*bit 0 indicates port 0*/ + carrier_port_count++; + } + if (link_desc[index].port_flag_1) { + /*bit 1 indicates port 1*/ + carrier_port_count++; + } + if (link_desc[index].port_flag_2) { + /*bit 2 indicates port 2*/ + carrier_port_count++; + } + if (link_desc[index].port_flag_3) { + /*bit 3 indicates port 3*/ + carrier_port_count++; + } - return return_value; + if (carrier_port_count == amc_port_count) { + return_value = OK_STATUS; + } else { + return_value = ERROR_STATUS; + } + return return_value; } /************************************************************************** @@ -2096,70 +2064,75 @@ ipmi_ek_compare_number_of_enable_port( * ***************************************************************************/ static tboolean -ipmi_ek_display_link_descriptor( int file_type, unsigned char rsc_id, - char * str, struct fru_picmgext_amc_link_desc_record link_desc ) +ipmi_ek_display_link_descriptor(int file_type, unsigned char rsc_id, + char *str, + struct fru_picmgext_amc_link_desc_record link_desc) { - tboolean isOEMtype = FALSE; - - if (file_type == ON_CARRIER_FRU_FILE){ - printf(" - %s On-Carrier Device ID %d\n", str, (rsc_id & 0x0f) ); - } - else{ - printf(" - %s %s\n", str, - val2str(file_type,ipmi_ekanalyzer_module_type)); - } - - printf(" - Channel ID %d || ", link_desc.channel_id ); - printf("%s", link_desc.port_flag_0 ? "Lane 0: enable" : ""); - printf("%s", link_desc.port_flag_1 ? ", Lane 1: enable" : ""); - printf("%s", link_desc.port_flag_2 ? ", Lane 2: enable" : ""); - printf("%s", link_desc.port_flag_3 ? ", Lane 3: enable" : ""); - - printf("\n"); - printf(" - Link Type: %s \n", - val2str (link_desc.type, ipmi_ekanalyzer_link_type) ); - switch ( link_desc.type ){ - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE: - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1: - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2: - printf(" - Link Type extension: %s\n", - val2str (link_desc.type_ext, ipmi_ekanalyzer_extension_PCIE) ); - printf(" - Link Group ID: %d || ", link_desc.group_id ); - printf("Link Asym. Match: %d - %s\n", - link_desc.asym_match, - val2str (link_desc.asym_match, ipmi_ekanalyzer_asym_PCIE) ); - break; - case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET: - printf(" - Link Type extension: %s\n", - val2str (link_desc.type_ext, ipmi_ekanalyzer_extension_ETHERNET) ); - printf(" - Link Group ID: %d || ", link_desc.group_id ); - printf("Link Asym. Match: %d - %s\n", - link_desc.asym_match, - val2str (link_desc.asym_match, ipmi_ekanalyzer_asym_PCIE) ); - break; - case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE: - printf(" - Link Type extension: %s\n", - val2str (link_desc.type_ext, ipmi_ekanalyzer_extension_STORAGE) ); - printf(" - Link Group ID: %d || ", link_desc.group_id ); - printf("Link Asym. Match: %d - %s\n", - link_desc.asym_match, - val2str (link_desc.asym_match, ipmi_ekanalyzer_asym_STORAGE) ); - break; - default: - printf(" - Link Type extension: %i\n", link_desc.type_ext ); - printf(" - Link Group ID: %d || ", link_desc.group_id ); - printf("Link Asym. Match: %i\n", link_desc.asym_match); - break; - } - /*return as OEM type if link type indicates OEM*/ - if ( (link_desc.type >= LOWER_OEM_TYPE) - && - (link_desc.type <= UPPER_OEM_TYPE) - ){ - isOEMtype = TRUE; - } - - return isOEMtype; + tboolean isOEMtype = FALSE; + if (file_type == ON_CARRIER_FRU_FILE) { + printf(" - %s On-Carrier Device ID %d\n", str, + (rsc_id & 0x0f)); + } else { + printf(" - %s %s\n", str, val2str(file_type, + ipmi_ekanalyzer_module_type)); + } + printf(" - Channel ID %d || ", link_desc.channel_id); + printf("%s", link_desc.port_flag_0 ? "Lane 0: enable" : ""); + printf("%s", link_desc.port_flag_1 ? ", Lane 1: enable" : ""); + printf("%s", link_desc.port_flag_2 ? ", Lane 2: enable" : ""); + printf("%s", link_desc.port_flag_3 ? ", Lane 3: enable" : ""); + printf("\n"); + printf(" - Link Type: %s \n", val2str(link_desc.type, + ipmi_ekanalyzer_link_type)); + switch (link_desc.type) { + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE: + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1: + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2: + printf(" - Link Type extension: %s\n", + val2str(link_desc.type_ext, + ipmi_ekanalyzer_extension_PCIE)); + printf(" - Link Group ID: %d || ", link_desc.group_id); + printf("Link Asym. Match: %d - %s\n", + link_desc.asym_match, + val2str(link_desc.asym_match, + ipmi_ekanalyzer_asym_PCIE)); + break; + case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET: + printf(" - Link Type extension: %s\n", + val2str(link_desc.type_ext, + ipmi_ekanalyzer_extension_ETHERNET)); + printf(" - Link Group ID: %d || ", link_desc.group_id); + printf("Link Asym. Match: %d - %s\n", + link_desc.asym_match, + val2str(link_desc.asym_match, + ipmi_ekanalyzer_asym_PCIE)); + break; + case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE: + printf(" - Link Type extension: %s\n", + val2str(link_desc.type_ext, + ipmi_ekanalyzer_extension_STORAGE)); + printf(" - Link Group ID: %d || ", + link_desc.group_id); + printf("Link Asym. Match: %d - %s\n", + link_desc.asym_match, + val2str(link_desc.asym_match, + ipmi_ekanalyzer_asym_STORAGE)); + break; + default: + printf(" - Link Type extension: %i\n", + link_desc.type_ext); + printf(" - Link Group ID: %d || ", + link_desc.group_id); + printf("Link Asym. Match: %i\n", + link_desc.asym_match); + break; + } + /* return as OEM type if link type indicates OEM */ + if ((link_desc.type >= LOWER_OEM_TYPE) + && (link_desc.type <= UPPER_OEM_TYPE)) { + isOEMtype = TRUE; + } + return isOEMtype; } /************************************************************************** @@ -2180,26 +2153,27 @@ ipmi_ek_display_link_descriptor( int file_type, unsigned char rsc_id, * ***************************************************************************/ static void -ipmi_ek_display_oem_guid( - struct ipmi_ek_amc_p2p_connectivity_record amc_record ) +ipmi_ek_display_oem_guid(struct ipmi_ek_amc_p2p_connectivity_record amc_record) { - int index_oem = 0; - int index = 0; - - if ( amc_record.guid_count == 0 ){ - printf("\tThere is no OEM GUID for this module\n"); - } - for (index_oem = 0; index_oem < amc_record.guid_count; index_oem++){ - printf(" - GUID: "); - for(index = 0; index < SIZE_OF_GUID; index++){ - printf("%02x", amc_record.oem_guid[index_oem].guid[index]); - /*For a better look: putting a "-" after displaying four bytes of GUID*/ - if (!(index % 4)){ - printf("-"); - } - } - printf("\n"); - } + int index_oem = 0; + int index = 0; + if (amc_record.guid_count == 0) { + printf("\tThere is no OEM GUID for this module\n"); + } + for (index_oem = 0; index_oem < amc_record.guid_count; index_oem++) { + printf(" - GUID: "); + for (index = 0; index < SIZE_OF_GUID; index++) { + printf("%02x", + amc_record.oem_guid[index_oem].guid[index]); + /* For a better look: putting a "-" after displaying + * four bytes of GUID + */ + if (!(index % 4)){ + printf("-"); + } + } + printf("\n"); + } } /************************************************************************** @@ -2222,8 +2196,8 @@ ipmi_ek_display_oem_guid( * ***************************************************************************/ static int -ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header * record, - struct ipmi_ek_amc_p2p_connectivity_record * amc_record) +ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header *record, + struct ipmi_ek_amc_p2p_connectivity_record *amc_record) { int index_data = START_DATA_OFFSET; int return_status = OK_STATUS; @@ -2334,20 +2308,18 @@ ipmi_ek_create_amc_p2p_record(struct ipmi_ek_multi_header * record, * ***************************************************************************/ static int -ipmi_ek_get_resource_descriptor( int port_count, int index, - struct fru_picmgext_carrier_p2p_descriptor * port_desc, - struct ipmi_ek_multi_header * record ) +ipmi_ek_get_resource_descriptor(int port_count, int index, + struct fru_picmgext_carrier_p2p_descriptor *port_desc, + struct ipmi_ek_multi_header *record) { - int num_port = 0; - - while ( num_port < port_count ){ - memcpy ( &port_desc[num_port], &record->data[index], - sizeof (struct fru_picmgext_carrier_p2p_descriptor) ); - index += sizeof (struct fru_picmgext_carrier_p2p_descriptor); - num_port++; - } - - return index; + int num_port = 0; + while (num_port < port_count) { + memcpy(&port_desc[num_port], &record->data[index], + sizeof (struct fru_picmgext_carrier_p2p_descriptor)); + index += sizeof (struct fru_picmgext_carrier_p2p_descriptor); + num_port++; + } + return index; } /************************************************************************** @@ -2369,9 +2341,9 @@ ipmi_ek_get_resource_descriptor( int port_count, int index, * ***************************************************************************/ static int -ipmi_ek_display_fru_header(char * filename) +ipmi_ek_display_fru_header(char *filename) { - FILE * input_file; + FILE *input_file; struct fru_header header; int ret = 0; @@ -2424,11 +2396,11 @@ ipmi_ek_display_fru_header(char * filename) * ***************************************************************************/ static int -ipmi_ek_display_fru_header_detail(char * filename) +ipmi_ek_display_fru_header_detail(char *filename) { # define FACTOR_OFFSET 8 # define SIZE_MFG_DATE 3 - FILE * input_file; + FILE *input_file; size_t file_offset = 0; struct fru_header header; time_t tval; @@ -2623,7 +2595,7 @@ ipmi_ek_display_fru_header_detail(char * filename) * ***************************************************************************/ static int -ipmi_ek_display_chassis_info_area(FILE * input_file, long offset) +ipmi_ek_display_chassis_info_area(FILE *input_file, long offset) { size_t file_offset; int ret = 0; @@ -2707,8 +2679,8 @@ ipmi_ek_display_chassis_info_area(FILE * input_file, long offset) * ***************************************************************************/ static size_t -ipmi_ek_display_board_info_area(FILE * input_file, char * board_type, - unsigned int * board_length) +ipmi_ek_display_board_info_area(FILE *input_file, char *board_type, + unsigned int *board_length) { size_t file_offset; int ret = 0; @@ -2845,7 +2817,7 @@ out: * ***************************************************************************/ static int -ipmi_ek_display_product_info_area(FILE * input_file, long offset) +ipmi_ek_display_product_info_area(FILE *input_file, long offset) { size_t file_offset; int ret = 0; @@ -2950,102 +2922,105 @@ ipmi_ek_display_product_info_area(FILE * input_file, long offset) * ***************************************************************************/ static void -ipmi_ek_display_record( struct ipmi_ek_multi_header * record, - struct ipmi_ek_multi_header * list_head, - struct ipmi_ek_multi_header * list_last ) +ipmi_ek_display_record(struct ipmi_ek_multi_header *record, + struct ipmi_ek_multi_header *list_head, + struct ipmi_ek_multi_header *list_last) { - if ( list_head == NULL ){ - printf("***empty list***\n"); - } - else{ - printf("%s\n", EQUAL_LINE_LIMITER); - printf("FRU Multi Info area\n"); - printf("%s\n", EQUAL_LINE_LIMITER); - for ( record = list_head; record != NULL; record = record->next ){ - printf("Record Type ID: 0x%02x\n", record->header.type); - printf("Record Format version: 0x%02x\n", record->header.format); - if (record->header.len > PICMG_ID_OFFSET){ - /* In picmg3.0 specification, picmg record id lower than 4 or - * greater than 0x2d is not supported - */ - #define PICMG_ID_LOWER_LIMIT 0x04 - #define PICMG_ID_UPPER_LIMIT 0x2d - unsigned char picmg_id; - - picmg_id = record->data[PICMG_ID_OFFSET]; - printf("Manufacturer ID: %02x%02x%02x h\n", record->data[2], - record->data[1], record->data[0] ); - if( ( picmg_id < PICMG_ID_LOWER_LIMIT ) - || - ( picmg_id > PICMG_ID_UPPER_LIMIT ) ){ - printf("Picmg record ID: Unsupported {0x%02x}\n", picmg_id ); - } - else{ - printf("Picmg record ID: %s {0x%02x}\n", - val2str(picmg_id, ipmi_ekanalyzer_picmg_record_id), - picmg_id ); - } - switch (picmg_id){ - case FRU_PICMG_BACKPLANE_P2P: /*0x04*/ - ipmi_ek_display_backplane_p2p_record (record); - break; - case FRU_PICMG_ADDRESS_TABLE: /*0x10*/ - ipmi_ek_display_address_table_record (record); - break; - case FRU_PICMG_SHELF_POWER_DIST: /*0x11*/ - ipmi_ek_display_shelf_power_distribution_record (record); - break; - case FRU_PICMG_SHELF_ACTIVATION: /*/0x12*/ - ipmi_ek_display_shelf_activation_record (record); - break; - case FRU_PICMG_SHMC_IP_CONN: /*0x13*/ - ipmi_ek_display_shelf_ip_connection_record (record); - break; - case FRU_PICMG_BOARD_P2P: /*0x14*/ - ipmi_ek_display_board_p2p_record (record); - break; - case FRU_RADIAL_IPMB0_LINK_MAPPING: /*0x15*/ - ipmi_ek_display_radial_ipmb0_record (record); - break; - case FRU_AMC_CURRENT: /*0x16*/ - ipmi_ek_display_amc_current_record (record); - break; - case FRU_AMC_ACTIVATION: /*0x17*/ - ipmi_ek_display_amc_activation_record (record); - break; - case FRU_AMC_CARRIER_P2P: /*0x18*/ - ipmi_ek_display_carrier_connectivity (record); - break; - case FRU_AMC_P2P: /*0x19*/ - ipmi_ek_display_amc_p2p_record (record); - break; - case FRU_AMC_CARRIER_INFO: /*0x1a*/ - ipmi_ek_display_amc_carrier_info_record (record); - break; - case FRU_PICMG_CLK_CARRIER_P2P: /*0x2c*/ - ipmi_ek_display_clock_carrier_p2p_record (record); - break; - case FRU_PICMG_CLK_CONFIG: /*0x2d*/ - ipmi_ek_display_clock_config_record (record); - break; - default: - if (verbose > 0){ - int i; - printf("%02x %02x %02x %02x %02x ", record->header.type, - record->header.format, record->header.len, - record->header.record_checksum, - record->header.header_checksum ); - for ( i = 0; i < record->header.len; i++ ){ - printf("%02x ", record->data[i]); - } - printf("\n"); - } - break; - } - printf("%s\n", STAR_LINE_LIMITER); - } - } - } + if (list_head == NULL) { + printf("***empty list***\n"); + return; + } + printf("%s\n", EQUAL_LINE_LIMITER); + printf("FRU Multi Info area\n"); + printf("%s\n", EQUAL_LINE_LIMITER); + for (record = list_head; record != NULL; record = record->next) { + printf("Record Type ID: 0x%02x\n", record->header.type); + printf("Record Format version: 0x%02x\n", + record->header.format); + if (record->header.len <= PICMG_ID_OFFSET) { + continue; + } + /* In picmg3.0 specification, picmg record + * id lower than 4 or greater than 0x2d + * isn't supported + */ + #define PICMG_ID_LOWER_LIMIT 0x04 + #define PICMG_ID_UPPER_LIMIT 0x2d + unsigned char picmg_id; + + picmg_id = record->data[PICMG_ID_OFFSET]; + printf("Manufacturer ID: %02x%02x%02x h\n", + record->data[2], record->data[1], + record->data[0]); + if ((picmg_id < PICMG_ID_LOWER_LIMIT) + || (picmg_id > PICMG_ID_UPPER_LIMIT)) { + printf("Picmg record ID: Unsupported {0x%02x}\n", picmg_id); + } else { + printf("Picmg record ID: %s {0x%02x}\n", + val2str(picmg_id, ipmi_ekanalyzer_picmg_record_id), + picmg_id); + } + switch (picmg_id) { + case FRU_PICMG_BACKPLANE_P2P: /*0x04*/ + ipmi_ek_display_backplane_p2p_record (record); + break; + case FRU_PICMG_ADDRESS_TABLE: /*0x10*/ + ipmi_ek_display_address_table_record (record); + break; + case FRU_PICMG_SHELF_POWER_DIST: /*0x11*/ + ipmi_ek_display_shelf_power_distribution_record (record); + break; + case FRU_PICMG_SHELF_ACTIVATION: /*/0x12*/ + ipmi_ek_display_shelf_activation_record (record); + break; + case FRU_PICMG_SHMC_IP_CONN: /*0x13*/ + ipmi_ek_display_shelf_ip_connection_record (record); + break; + case FRU_PICMG_BOARD_P2P: /*0x14*/ + ipmi_ek_display_board_p2p_record (record); + break; + case FRU_RADIAL_IPMB0_LINK_MAPPING: /*0x15*/ + ipmi_ek_display_radial_ipmb0_record (record); + break; + case FRU_AMC_CURRENT: /*0x16*/ + ipmi_ek_display_amc_current_record (record); + break; + case FRU_AMC_ACTIVATION: /*0x17*/ + ipmi_ek_display_amc_activation_record (record); + break; + case FRU_AMC_CARRIER_P2P: /*0x18*/ + ipmi_ek_display_carrier_connectivity (record); + break; + case FRU_AMC_P2P: /*0x19*/ + ipmi_ek_display_amc_p2p_record (record); + break; + case FRU_AMC_CARRIER_INFO: /*0x1a*/ + ipmi_ek_display_amc_carrier_info_record (record); + break; + case FRU_PICMG_CLK_CARRIER_P2P: /*0x2c*/ + ipmi_ek_display_clock_carrier_p2p_record (record); + break; + case FRU_PICMG_CLK_CONFIG: /*0x2d*/ + ipmi_ek_display_clock_config_record (record); + break; + default: + if (verbose > 0) { + int i; + printf("%02x %02x %02x %02x %02x ", + record->header.type, + record->header.format, + record->header.len, + record->header.record_checksum, + record->header.header_checksum); + for (i = 0; i < record->header.len; i++) { + printf("%02x ", record->data[i]); + } + printf("\n"); + } + break; + } + printf("%s\n", STAR_LINE_LIMITER); + } } /************************************************************************** @@ -3066,62 +3041,59 @@ ipmi_ek_display_record( struct ipmi_ek_multi_header * record, * ***************************************************************************/ static void -ipmi_ek_display_backplane_p2p_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_backplane_p2p_record(struct ipmi_ek_multi_header *record) { - uint8_t index; - int offset = START_DATA_OFFSET; - struct fru_picmgext_slot_desc * slot_d - = (struct fru_picmgext_slot_desc*) &record->data[offset]; - - offset += sizeof(struct fru_picmgext_slot_desc); - - while ( offset <= record->header.len ) { - printf(" Channel Type: "); - switch ( slot_d -> chan_type ) - { - case 0x00: - case 0x07: - printf("PICMG 2.9\n"); - break; - case 0x08: - printf("Single Port Fabric IF\n"); - break; - case 0x09: - printf("Double Port Fabric IF\n"); - break; - case 0x0a: - printf("Full Channel Fabric IF\n"); - break; - case 0x0b: - printf("Base IF\n"); - break; - case 0x0c: - printf("Update Channel IF\n"); - break; - default: - printf("Unknown IF\n"); - break; - } - printf(" Slot Address: %02x\n", slot_d -> slot_addr); - printf(" Channel Count: %i\n", slot_d -> chn_count); - - for ( index = 0; index < (slot_d -> chn_count); index++ ) { - struct fru_picmgext_chn_desc * d - = (struct fru_picmgext_chn_desc *) &record->data[offset]; - - if ( verbose ){ - printf( "\t" - "Chn: %02x --> " - "Chn: %02x in " - "Slot: %02x\n", - d->local_chn, d->remote_chn, d->remote_slot - ); - } - offset += sizeof(struct fru_picmgext_chn_desc); - } - slot_d = (struct fru_picmgext_slot_desc*) &record->data[offset]; - offset += sizeof(struct fru_picmgext_slot_desc); - } + uint8_t index; + int offset = START_DATA_OFFSET; + struct fru_picmgext_slot_desc *slot_d = + (struct fru_picmgext_slot_desc*)&record->data[offset]; + + offset += sizeof(struct fru_picmgext_slot_desc); + while (offset <= record->header.len) { + printf(" Channel Type: "); + switch (slot_d->chan_type) { + case 0x00: + case 0x07: + printf("PICMG 2.9\n"); + break; + case 0x08: + printf("Single Port Fabric IF\n"); + break; + case 0x09: + printf("Double Port Fabric IF\n"); + break; + case 0x0a: + printf("Full Channel Fabric IF\n"); + break; + case 0x0b: + printf("Base IF\n"); + break; + case 0x0c: + printf("Update Channel IF\n"); + break; + default: + printf("Unknown IF\n"); + break; + } + printf(" Slot Address: %02x\n", slot_d->slot_addr); + printf(" Channel Count: %i\n", slot_d->chn_count); + for (index = 0; index < (slot_d->chn_count); index++) { + struct fru_picmgext_chn_desc *d = + (struct fru_picmgext_chn_desc *)&record->data[offset]; + if (verbose) { + printf("\t" + "Chn: %02x --> " + "Chn: %02x in " + "Slot: %02x\n", + d->local_chn, + d->remote_chn, + d->remote_slot); + } + offset += sizeof(struct fru_picmgext_chn_desc); + } + slot_d = (struct fru_picmgext_slot_desc*)&record->data[offset]; + offset += sizeof(struct fru_picmgext_slot_desc); + } } /************************************************************************** @@ -3142,30 +3114,28 @@ ipmi_ek_display_backplane_p2p_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static void -ipmi_ek_display_address_table_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_address_table_record(struct ipmi_ek_multi_header *record) { - unsigned char entries = 0; - unsigned char i; - int offset = START_DATA_OFFSET; - #define SIZE_SHELF_ADDRESS_BYTE 20 - - printf(" Type/Len: 0x%02x\n", record->data[offset++]); - printf(" Shelf Addr: "); - for ( i = 0; i < SIZE_SHELF_ADDRESS_BYTE; i++ ){ - printf("0x%02x ", record->data[offset++]); - } - printf("\n"); - - entries = record->data[offset++]; - printf(" Addr Table Entries count: 0x%02x\n", entries); - - for ( i = 0; i < entries; i++ ){ - printf("\tHWAddr: 0x%02x - SiteNum: 0x%02x - SiteType: 0x%02x \n", - record->data[offset+0], - record->data[offset+1], - record->data[offset+2]); - offset += 3; - } +#define SIZE_SHELF_ADDRESS_BYTE 20 + unsigned char entries = 0; + unsigned char i; + int offset = START_DATA_OFFSET; + + printf(" Type/Len: 0x%02x\n", record->data[offset++]); + printf(" Shelf Addr: "); + for (i = 0; i < SIZE_SHELF_ADDRESS_BYTE; i++) { + printf("0x%02x ", record->data[offset++]); + } + printf("\n"); + entries = record->data[offset++]; + printf(" Addr Table Entries count: 0x%02x\n", entries); + for (i = 0; i < entries; i++) { + printf("\tHWAddr: 0x%02x - SiteNum: 0x%02x - SiteType: 0x%02x \n", + record->data[offset+0], + record->data[offset+1], + record->data[offset+2]); + offset += 3; + } } /************************************************************************** @@ -3187,36 +3157,38 @@ ipmi_ek_display_address_table_record( struct ipmi_ek_multi_header * record ) ***************************************************************************/ static void ipmi_ek_display_shelf_power_distribution_record( - struct ipmi_ek_multi_header * record ) + struct ipmi_ek_multi_header *record) { - int offset = START_DATA_OFFSET; - unsigned char i,j; - unsigned char feeds = 0; - - feeds = record->data[offset++]; - printf(" Number of Power Feeds: 0x%02x\n", feeds); - - for (i=0; i<feeds; i++) { - unsigned char entries; - unsigned long max_ext = 0; - unsigned long max_int = 0; - max_ext = record->data[offset+0] | (record->data[offset+1]<<8); - printf(" Max External Available Current: %ld Amps\n", (max_ext*10) ); - - offset += 2; - - max_int = record->data[offset+0] | (record->data[offset+1]<<8); - printf(" Max Internal Current:\t %ld Amps\n", (max_int*10)); - offset += 2; - printf(" Min Expected Operating Voltage: %d Volts\n", - (record->data[offset++]/2)); - entries = record->data[offset++]; - printf(" Feed to FRU count: 0x%02x\n", entries); - for (j=0; j<entries; j++) { - printf("\tHW: 0x%02x", record->data[offset++]); - printf("\tFRU ID: 0x%02x\n", record->data[offset++]); - } - } + int offset = START_DATA_OFFSET; + unsigned char i; + unsigned char j; + unsigned char feeds = 0; + + feeds = record->data[offset++]; + printf(" Number of Power Feeds: 0x%02x\n", feeds); + for (i = 0; i < feeds; i++) { + unsigned char entries; + unsigned long max_ext = 0; + unsigned long max_int = 0; + max_ext = record->data[offset+0] + | (record->data[offset+1] << 8); + printf(" Max External Available Current: %ld Amps\n", + (max_ext * 10)); + offset += 2; + max_int = record->data[offset+0] + | (record->data[offset+1] << 8); + printf(" Max Internal Current:\t %ld Amps\n", + (max_int * 10)); + offset += 2; + printf(" Min Expected Operating Voltage: %d Volts\n", + (record->data[offset++] / 2)); + entries = record->data[offset++]; + printf(" Feed to FRU count: 0x%02x\n", entries); + for (j = 0; j < entries; j++) { + printf("\tHW: 0x%02x", record->data[offset++]); + printf("\tFRU ID: 0x%02x\n", record->data[offset++]); + } + } } /************************************************************************** @@ -3237,27 +3209,29 @@ ipmi_ek_display_shelf_power_distribution_record( * ***************************************************************************/ static void -ipmi_ek_display_shelf_activation_record( - struct ipmi_ek_multi_header * record ) +ipmi_ek_display_shelf_activation_record(struct ipmi_ek_multi_header *record) { - unsigned char count = 0; - int offset = START_DATA_OFFSET; - - printf(" Allowance for FRU Act Readiness: 0x%02x\n", - record->data[offset++]); - count = record->data[offset++]; - printf(" FRU activation and Power Desc Cnt: 0x%02x\n", count); - - while ( count > 0 ) { - printf(" FRU activation and Power descriptor:\n"); - printf("\tHardware Address:\t\t0x%02x\n", record->data[offset++]); - printf("\tFRU Device ID:\t\t\t0x%02x\n", record->data[offset++]); - printf("\tMax FRU Power Capability:\t0x%04x Watts\n", - ( record->data[offset+0] | (record->data[offset+1]<<8) )); - offset += 2; - printf("\tConfiguration parameter:\t0x%02x\n", record->data[offset++]); - count --; - } + unsigned char count = 0; + int offset = START_DATA_OFFSET; + + printf(" Allowance for FRU Act Readiness: 0x%02x\n", + record->data[offset++]); + count = record->data[offset++]; + printf(" FRU activation and Power Desc Cnt: 0x%02x\n", count); + while (count > 0) { + printf(" FRU activation and Power descriptor:\n"); + printf("\tHardware Address:\t\t0x%02x\n", + record->data[offset++]); + printf("\tFRU Device ID:\t\t\t0x%02x\n", + record->data[offset++]); + printf("\tMax FRU Power Capability:\t0x%04x Watts\n", + (record->data[offset+0] + | (record->data[offset+1]<<8))); + offset += 2; + printf("\tConfiguration parameter:\t0x%02x\n", + record->data[offset++]); + count --; + } } /************************************************************************** @@ -3279,28 +3253,33 @@ ipmi_ek_display_shelf_activation_record( * ***************************************************************************/ static void -ipmi_ek_display_shelf_ip_connection_record( - struct ipmi_ek_multi_header * record ) +ipmi_ek_display_shelf_ip_connection_record(struct ipmi_ek_multi_header *record) { - int ioffset = START_DATA_OFFSET; - if (ioffset > record->header.len) { - printf(" Shelf Manager IP Address: %d.%d.%d.%d\n", - record->data[ioffset+0], record->data[ioffset+1], - record->data[ioffset+2], record->data[ioffset+3]); - ioffset += 4; - } - if (ioffset > record->header.len) { - printf(" Default Gateway Address: %d.%d.%d.%d\n", - record->data[ioffset+0], record->data[ioffset+1], - record->data[ioffset+2], record->data[ioffset+3]); - ioffset += 4; - } - if (ioffset > record->header.len) { - printf(" Subnet Mask: %d.%d.%d.%d\n", - record->data[ioffset+0], record->data[ioffset+1], - record->data[ioffset+2], record->data[ioffset+3]); - ioffset += 4; - } + int ioffset = START_DATA_OFFSET; + if (ioffset > record->header.len) { + printf(" Shelf Manager IP Address: %d.%d.%d.%d\n", + record->data[ioffset+0], + record->data[ioffset+1], + record->data[ioffset+2], + record->data[ioffset+3]); + ioffset += 4; + } + if (ioffset > record->header.len) { + printf(" Default Gateway Address: %d.%d.%d.%d\n", + record->data[ioffset+0], + record->data[ioffset+1], + record->data[ioffset+2], + record->data[ioffset+3]); + ioffset += 4; + } + if (ioffset > record->header.len) { + printf(" Subnet Mask: %d.%d.%d.%d\n", + record->data[ioffset+0], + record->data[ioffset+1], + record->data[ioffset+2], + record->data[ioffset+3]); + ioffset += 4; + } } /************************************************************************** @@ -3322,28 +3301,30 @@ ipmi_ek_display_shelf_ip_connection_record( * ***************************************************************************/ static void -ipmi_ek_display_shelf_fan_geography_record( - struct ipmi_ek_multi_header * record ) +ipmi_ek_display_shelf_fan_geography_record(struct ipmi_ek_multi_header *record) { - int ioffset = START_DATA_OFFSET; - unsigned char fan_count = 0; - - fan_count = record->data[ioffset]; - ioffset++; - printf(" Fan-to-FRU Entry Count: 0x%02x\n", fan_count); - - while ( (fan_count > 0) && (ioffset <= record->header.len) ) { - printf(" Fan-to-FRU Mapping Entry: {%2x%2x%2x%2x}\n", - record->data[ioffset], record->data[ioffset+1], - record->data[ioffset+2], record->data[ioffset+3] - ); - printf(" Hardware Address: 0x%02x\n", record->data[ioffset++]); - printf(" FRU device ID: 0x%02x\n", record->data[ioffset++]); - printf(" Site Number: 0x%02x\n", record->data[ioffset++]); - printf(" Site Type: 0x%02x\n", record->data[ioffset++]); - fan_count --; - } - + int ioffset = START_DATA_OFFSET; + unsigned char fan_count = 0; + + fan_count = record->data[ioffset]; + ioffset++; + printf(" Fan-to-FRU Entry Count: 0x%02x\n", fan_count); + while ((fan_count > 0) && (ioffset <= record->header.len)) { + printf(" Fan-to-FRU Mapping Entry: {%2x%2x%2x%2x}\n", + record->data[ioffset], + record->data[ioffset+1], + record->data[ioffset+2], + record->data[ioffset+3]); + printf(" Hardware Address: 0x%02x\n", + record->data[ioffset++]); + printf(" FRU device ID: 0x%02x\n", + record->data[ioffset++]); + printf(" Site Number: 0x%02x\n", + record->data[ioffset++]); + printf(" Site Type: 0x%02x\n", + record->data[ioffset++]); + fan_count --; + } } /************************************************************************** @@ -3364,147 +3345,133 @@ ipmi_ek_display_shelf_fan_geography_record( * ***************************************************************************/ static void -ipmi_ek_display_board_p2p_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_board_p2p_record(struct ipmi_ek_multi_header *record) { - unsigned char guid_count; - int offset = START_DATA_OFFSET; - int i = 0; - - guid_count = record->data[offset++]; - printf(" GUID count: %2d\n", guid_count); - - for (i = 0 ; i < guid_count; i++ ) { - int j; - printf("\tGUID: "); - for (j=0; j < sizeof(struct fru_picmgext_guid); j++) { - printf("%02x", record->data[offset+j]); - } - printf("\n"); - offset += sizeof(struct fru_picmgext_guid); - } - - for ( offset; - offset < record->header.len; - offset += sizeof(struct fru_picmgext_link_desc) - ) { - /* to solve little endian /big endian problem */ - unsigned long data; - struct fru_picmgext_link_desc * d; - - data = (record->data[offset+0]) | (record->data[offset+1] << 8)\ - | (record->data[offset+2] << 16)\ - | (record->data[offset+3] << 24); - - d = (struct fru_picmgext_link_desc *) &data; - - printf(" Link Descriptor\n"); - printf("\tLink Grouping ID:\t0x%02x\n", d->grouping); - printf("\tLink Type Extension:\t0x%02x - ", d->ext); - - if (d->type == FRU_PICMGEXT_LINK_TYPE_BASE){ - switch (d->ext){ - case 0: - printf("10/100/1000BASE-T Link (four-pair)\n"); - break; - case 1: - printf("ShMC Cross-connect (two-pair)\n"); - break; - default: - printf("Unknwon\n"); - break; - } - } - else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET){ - switch (d->ext){ - case 0: - printf("Fixed 1000Base-BX\n"); - break; - case 1: - printf("Fixed 10GBASE-BX4 [XAUI]\n"); - break; - case 2: - printf("FC-PI\n"); - break; - default: - printf("Unknwon\n"); - break; - } - } - else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND){ - printf("Unknwon\n"); - } - else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR){ - printf("Unknwon\n"); - } - else if (d->type == FRU_PICMGEXT_LINK_TYPE_PCIE){ - printf("Unknwon\n"); - } - else{ - printf("Unknwon\n"); - } - - printf("\tLink Type:\t\t0x%02x - ",d->type); - if (d->type == 0 || d->type == 0xff){ - printf("Reserved\n"); - } - else if (d->type >= 0x06 && d->type <= 0xef) { - printf("Reserved\n"); - } - else if (d->type >= LOWER_OEM_TYPE && d->type <= UPPER_OEM_TYPE) { - printf("OEM GUID Definition\n"); - } - else { - switch (d->type){ - case FRU_PICMGEXT_LINK_TYPE_BASE: - printf("PICMG 3.0 Base Interface 10/100/1000\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET: - printf("PICMG 3.1 Ethernet Fabric Interface\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND: - printf("PICMG 3.2 Infiniband Fabric Interface\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR: - printf("PICMG 3.3 Star Fabric Interface\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_PCIE: - printf("PICMG 3.4 PCI Express Fabric Interface\n"); - break; - default: - printf("Invalid\n"); - break; - } - } - printf("\tLink Designator: \n"); - printf("\t Port 0 Flag: %s\n", - (d->desig_port & 0x01) ? "enable" : "disable"); - printf("\t Port 1 Flag: %s\n", - (d->desig_port & 0x02) ? "enable" : "disable"); - printf("\t Port 2 Flag: %s\n", - (d->desig_port & 0x04) ? "enable" : "disable"); - printf("\t Port 3 Flag: %s\n", - (d->desig_port & 0x08) ? "enable" : "disable"); - - printf("\t Interface: 0x%02x - ", d->desig_if); - switch (d->desig_if){ - case FRU_PICMGEXT_DESIGN_IF_BASE: - printf("Base Interface\n"); - break; - case FRU_PICMGEXT_DESIGN_IF_FABRIC: - printf("Fabric Interface\n"); - break; - case FRU_PICMGEXT_DESIGN_IF_UPDATE_CHANNEL: - printf("Update Channel\n"); - break; - case FRU_PICMGEXT_DESIGN_IF_RESERVED: - printf("Reserved\n"); - break; - default: - printf("Invalid"); - break; - } - printf("\t Channel Number: 0x%02x\n", d->desig_channel); - } + unsigned char guid_count; + int offset = START_DATA_OFFSET; + int i = 0; + + guid_count = record->data[offset++]; + printf(" GUID count: %2d\n", guid_count); + for (i = 0 ; i < guid_count; i++) { + int j; + printf("\tGUID: "); + for (j = 0; j < sizeof(struct fru_picmgext_guid); j++) { + printf("%02x", record->data[offset+j]); + } + printf("\n"); + offset += sizeof(struct fru_picmgext_guid); + } + for (offset; + offset < record->header.len; + offset += sizeof(struct fru_picmgext_link_desc)) { + /* to solve little endian/big endian problem */ + unsigned long data; + struct fru_picmgext_link_desc * d; + data = (record->data[offset+0]) + | (record->data[offset+1] << 8)\ + | (record->data[offset+2] << 16)\ + | (record->data[offset+3] << 24); + d = (struct fru_picmgext_link_desc *)&data; + + printf(" Link Descriptor\n"); + printf("\tLink Grouping ID:\t0x%02x\n", d->grouping); + printf("\tLink Type Extension:\t0x%02x - ", d->ext); + if (d->type == FRU_PICMGEXT_LINK_TYPE_BASE) { + switch (d->ext) { + case 0: + printf("10/100/1000BASE-T Link (four-pair)\n"); + break; + case 1: + printf("ShMC Cross-connect (two-pair)\n"); + break; + default: + printf("Unknwon\n"); + break; + } + } else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET) { + switch (d->ext) { + case 0: + printf("Fixed 1000Base-BX\n"); + break; + case 1: + printf("Fixed 10GBASE-BX4 [XAUI]\n"); + break; + case 2: + printf("FC-PI\n"); + break; + default: + printf("Unknwon\n"); + break; + } + } else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND) { + printf("Unknwon\n"); + } else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR) { + printf("Unknwon\n"); + } else if (d->type == FRU_PICMGEXT_LINK_TYPE_PCIE) { + printf("Unknwon\n"); + } else { + printf("Unknwon\n"); + } + printf("\tLink Type:\t\t0x%02x - ", d->type); + if (d->type == 0 || d->type == 0xff) { + printf("Reserved\n"); + } else if (d->type >= 0x06 && d->type <= 0xef) { + printf("Reserved\n"); + } else if (d->type >= LOWER_OEM_TYPE && d->type <= UPPER_OEM_TYPE) { + printf("OEM GUID Definition\n"); + } else { + switch (d->type){ + case FRU_PICMGEXT_LINK_TYPE_BASE: + printf("PICMG 3.0 Base Interface 10/100/1000\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET: + printf("PICMG 3.1 Ethernet Fabric Interface\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND: + printf("PICMG 3.2 Infiniband Fabric Interface\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR: + printf("PICMG 3.3 Star Fabric Interface\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_PCIE: + printf("PICMG 3.4 PCI Express Fabric Interface\n"); + break; + default: + printf("Invalid\n"); + break; + } + } + printf("\tLink Designator: \n"); + printf("\t Port 0 Flag: %s\n", + (d->desig_port & 0x01) ? "enable" : "disable"); + printf("\t Port 1 Flag: %s\n", + (d->desig_port & 0x02) ? "enable" : "disable"); + printf("\t Port 2 Flag: %s\n", + (d->desig_port & 0x04) ? "enable" : "disable"); + printf("\t Port 3 Flag: %s\n", + (d->desig_port & 0x08) ? "enable" : "disable"); + printf("\t Interface: 0x%02x - ", d->desig_if); + switch (d->desig_if) { + case FRU_PICMGEXT_DESIGN_IF_BASE: + printf("Base Interface\n"); + break; + case FRU_PICMGEXT_DESIGN_IF_FABRIC: + printf("Fabric Interface\n"); + break; + case FRU_PICMGEXT_DESIGN_IF_UPDATE_CHANNEL: + printf("Update Channel\n"); + break; + case FRU_PICMGEXT_DESIGN_IF_RESERVED: + printf("Reserved\n"); + break; + default: + printf("Invalid"); + break; + } + printf("\t Channel Number: 0x%02x\n", + d->desig_channel); + } } /************************************************************************** @@ -3525,63 +3492,64 @@ ipmi_ek_display_board_p2p_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static void -ipmi_ek_display_radial_ipmb0_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_radial_ipmb0_record(struct ipmi_ek_multi_header *record) { - int offset = START_DATA_OFFSET; - #define SIZE_OF_CONNECTOR_DEFINER 3; /*bytes*/ - - /*Ref: PICMG 3.0 Specification Revision 2.0, Table 3-59*/ - printf(" IPMB-0 Connector Definer: "); - #ifndef WORDS_BIGENDIAN - printf("%02x %02x %02x h\n", record->data[offset], - record->data[offset+1], record->data[offset+2]); - #else - printf("%02x %02x %02x h\n", record->data[offset+2], - record->data[offset+1], record->data[offset]); - #endif - /*3 bytes of connector definer was used*/ - offset += SIZE_OF_CONNECTOR_DEFINER; - - printf (" IPMB-0 Connector version ID: "); - #ifndef WORDS_BIGENDIAN - printf("%02x %02x h\n", record->data[offset], record->data[offset+1]); - #else - printf("%02x %02x h\n", record->data[offset+1], record->data[offset]); - #endif - offset += 2; - - printf(" IPMB-0 Hub Descriptor Count: 0x%02x", record->data[offset++]); - if (record->data[offset] > 0){ - for (offset; offset < record->header.len;){ - unsigned char entry_count = 0; - printf(" IPMB-0 Hub Descriptor\n"); - printf("\tHardware Address: 0x%02x\n", record->data[offset++]); - printf("\tHub Info {0x%02x}: ", record->data[offset]); - /* Bit mask specified in Table 3-59 of PICMG 3.0 Specification */ - if ( (record->data[offset] & 0x01) == 0x01 ){ - printf("IPMB-A only\n"); - } - else if ( (record->data[offset] & 0x02) == 0x02 ){ - printf("IPMB-B only\n"); - } - else if ( (record->data[offset] & 0x03) == 0x03 ){ - printf("IPMB-A and IPMB-B\n"); - } - else{ - printf("Reserved.\n"); - } - offset ++; - - entry_count = record->data[offset++]; - printf("\tAddress Entry count: 0x%02x", entry_count); - while (entry_count > 0){ - printf("\t Hardware Address: 0x%02x\n", record->data[offset++]); - printf("\t IPMB-0 Link Entry: 0x%02x\n",record->data[offset++]); - entry_count --; - } - } - } - +#define SIZE_OF_CONNECTOR_DEFINER 3; /*bytes*/ + int offset = START_DATA_OFFSET; + /* Ref: PICMG 3.0 Specification Revision 2.0, Table 3-59 */ + printf(" IPMB-0 Connector Definer: "); +#ifndef WORDS_BIGENDIAN + printf("%02x %02x %02x h\n", record->data[offset], + record->data[offset+1], record->data[offset+2]); +#else + printf("%02x %02x %02x h\n", record->data[offset+2], + record->data[offset+1], record->data[offset]); +#endif + /* 3 bytes of connector definer was used */ + offset += SIZE_OF_CONNECTOR_DEFINER; + printf(" IPMB-0 Connector version ID: "); +#ifndef WORDS_BIGENDIAN + printf("%02x %02x h\n", record->data[offset], + record->data[offset+1]); +#else + printf("%02x %02x h\n", record->data[offset+1], + record->data[offset]); +#endif + offset += 2; + printf(" IPMB-0 Hub Descriptor Count: 0x%02x", + record->data[offset++]); + if (record->data[offset] < 1) { + return; + } + for (offset; offset < record->header.len;) { + unsigned char entry_count = 0; + printf(" IPMB-0 Hub Descriptor\n"); + printf("\tHardware Address: 0x%02x\n", + record->data[offset++]); + printf("\tHub Info {0x%02x}: ", record->data[offset]); + /* Bit mask specified in Table 3-59 + * of PICMG 3.0 Specification + */ + if ((record->data[offset] & 0x01) == 0x01) { + printf("IPMB-A only\n"); + } else if ((record->data[offset] & 0x02) == 0x02) { + printf("IPMB-B only\n"); + } else if ((record->data[offset] & 0x03) == 0x03) { + printf("IPMB-A and IPMB-B\n"); + } else { + printf("Reserved.\n"); + } + offset ++; + entry_count = record->data[offset++]; + printf("\tAddress Entry count: 0x%02x", entry_count); + while (entry_count > 0) { + printf("\t Hardware Address: 0x%02x\n", + record->data[offset++]); + printf("\t IPMB-0 Link Entry: 0x%02x\n", + record->data[offset++]); + entry_count --; + } + } } /************************************************************************** @@ -3602,13 +3570,14 @@ ipmi_ek_display_radial_ipmb0_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static void -ipmi_ek_display_amc_current_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_amc_current_record(struct ipmi_ek_multi_header *record) { - unsigned char current; - current = record->data[START_DATA_OFFSET]; - printf(" Current draw: %.1f A @ 12V => %.2f Watt\n", - (float) current/10.0, ((float)current/10.0)*12.0 ); - printf("\n"); + unsigned char current; + current = record->data[START_DATA_OFFSET]; + printf(" Current draw: %.1f A @ 12V => %.2f Watt\n", + (float)current / 10.0, + ((float)current / 10.0) * 12.0); + printf("\n"); } /************************************************************************** @@ -3630,29 +3599,27 @@ ipmi_ek_display_amc_current_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static void -ipmi_ek_display_amc_activation_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_amc_activation_record(struct ipmi_ek_multi_header *record) { - uint16_t max_current; - int offset = START_DATA_OFFSET; - - max_current = record->data[offset]; - max_current |= record->data[++offset] << 8; - printf(" Maximum Internal Current(@12V): %.2f A [ %.2f Watt ]\n", - (float) max_current / 10, - (float) max_current / 10 * 12); - printf(" Module Activation Readiness: %i sec.\n", - record->data[++offset]); - - printf(" Descriptor Count: %i\n", record->data[++offset]); - for(++offset; (offset < record->header.len); offset += 3 ) - { - struct fru_picmgext_activation_record * a = - (struct fru_picmgext_activation_record *) &record->data[offset]; - - printf("\tIPMB-Address:\t\t0x%x\n", a->ibmb_addr); - printf("\tMax. Module Current:\t%.2f A\n", (float)a->max_module_curr/10); - printf("\n"); - } + uint16_t max_current; + int offset = START_DATA_OFFSET; + + max_current = record->data[offset]; + max_current |= record->data[++offset] << 8; + printf(" Maximum Internal Current(@12V): %.2f A [ %.2f Watt ]\n", + (float) max_current / 10, + (float) max_current / 10 * 12); + printf(" Module Activation Readiness: %i sec.\n", + record->data[++offset]); + printf(" Descriptor Count: %i\n", record->data[++offset]); + for (++offset; (offset < record->header.len); offset += 3) { + struct fru_picmgext_activation_record *a = + (struct fru_picmgext_activation_record *)&record->data[offset]; + printf("\tIPMB-Address:\t\t0x%x\n", a->ibmb_addr); + printf("\tMax. Module Current:\t%.2f A\n", + (float)a->max_module_curr / 10); + printf("\n"); + } } /************************************************************************** @@ -3674,119 +3641,133 @@ ipmi_ek_display_amc_activation_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static void -ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_amc_p2p_record(struct ipmi_ek_multi_header *record) { - int index_data = START_DATA_OFFSET; - int oem_count = 0; - int ch_count = 0; - int index=0; - - oem_count = record->data[index_data++]; - printf("OEM GUID count: %02x\n", oem_count); - - if ( oem_count > 0 ){ - while ( oem_count > 0 ){ - printf("OEM GUID: "); - for ( index = 1; index <= SIZE_OF_GUID; index++ ){ - printf("%02x", record->data[index_data++]); - /* For a better look, display a "-" character after each 5 bytes - * of OEM GUID */ - if ( !(index % 5) ){ - printf("-"); - } - } - printf("\n"); - oem_count--; - } - } - if ( ( record->data[index_data] & AMC_MODULE ) == AMC_MODULE ){ - printf("AMC module connection\n"); - } - else{ - printf("On-Carrier Device %02x h\n", ( record->data[index_data] & 0x0f )); - } - index_data ++; - ch_count = record->data[index_data++]; - printf("AMC Channel Descriptor count: %02x h\n", ch_count); - - if ( ch_count > 0 ){ - for ( index = 0; index < ch_count; index++ ){ - unsigned int data; - struct fru_picmgext_amc_channel_desc_record * ch_desc; - printf(" AMC Channel Descriptor {%02x%02x%02x}\n", - record->data[index_data+2], record->data[index_data+1], - record->data[index_data] - ); - data = record->data[index_data] | - (record->data[index_data + 1] << 8) | - (record->data[index_data + 2] << 16); - ch_desc = ( struct fru_picmgext_amc_channel_desc_record * ) &data; - printf(" Lane 0 Port: %d\n", ch_desc->lane0port); - printf(" Lane 1 Port: %d\n", ch_desc->lane1port); - printf(" Lane 2 Port: %d\n", ch_desc->lane2port); - printf(" Lane 3 Port: %d\n\n", ch_desc->lane3port); - index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE; - } - } - while ( index_data < record->header.len ){ - /*Warning: For gcc version between 4.0 and 4.3 this code doesnt work*/ - unsigned int data[2]; - struct fru_picmgext_amc_link_desc_record *link_desc; - data[0] = record->data[index_data] | - (record->data[index_data + 1] << 8) | - (record->data[index_data + 2] << 16) | - (record->data[index_data + 3] << 24); - data[1] = record->data[index_data + 4]; - - link_desc = (struct fru_picmgext_amc_link_desc_record *) &data[0]; - - printf(" AMC Link Descriptor:\n" ); - - printf("\t- Link Type: %s \n", - val2str (link_desc->type, ipmi_ekanalyzer_link_type)); - switch ( link_desc->type ) { - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE: - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1: - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2: - printf("\t- Link Type extension: %s\n", - val2str (link_desc->type_ext, ipmi_ekanalyzer_extension_PCIE)); - printf("\t- Link Group ID: %d\n ", link_desc->group_id ); - printf("\t- Link Asym. Match: %d - %s\n", - link_desc->asym_match, - val2str (link_desc->asym_match, ipmi_ekanalyzer_asym_PCIE)); - break; - case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET: - printf("\t- Link Type extension: %s\n", - val2str (link_desc->type_ext, - ipmi_ekanalyzer_extension_ETHERNET)); - printf("\t- Link Group ID: %d \n", link_desc->group_id ); - printf("\t- Link Asym. Match: %d - %s\n", - link_desc->asym_match, - val2str (link_desc->asym_match, ipmi_ekanalyzer_asym_PCIE)); - break; - case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE: - printf("\t- Link Type extension: %s\n", - val2str (link_desc->type_ext, - ipmi_ekanalyzer_extension_STORAGE)); - printf("\t- Link Group ID: %d \n", link_desc->group_id ); - printf("\t- Link Asym. Match: %d - %s\n", - link_desc->asym_match, - val2str (link_desc->asym_match, ipmi_ekanalyzer_asym_STORAGE)); - break; - default: - printf("\t- Link Type extension: %i (Unknown)\n", link_desc->type_ext ); - printf("\t- Link Group ID: %d \n", link_desc->group_id ); - printf("\t- Link Asym. Match: %i\n", link_desc->asym_match); - break; - } - printf("\t- AMC Link Designator:\n"); - printf("\t Channel ID: %i\n", link_desc->channel_id); - printf("\t\t Lane 0: %s\n", (link_desc->port_flag_0)?"enable":"disable"); - printf("\t\t Lane 1: %s\n", (link_desc->port_flag_1)?"enable":"disable"); - printf("\t\t Lane 2: %s\n", (link_desc->port_flag_2)?"enable":"disable"); - printf("\t\t Lane 3: %s\n", (link_desc->port_flag_3)?"enable":"disable"); - index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE; - } + int index_data = START_DATA_OFFSET; + int oem_count = 0; + int ch_count = 0; + int index=0; + + oem_count = record->data[index_data++]; + printf("OEM GUID count: %02x\n", oem_count); + if (oem_count > 0) { + while (oem_count > 0) { + printf("OEM GUID: "); + for (index = 1; index <= SIZE_OF_GUID; index++) { + printf("%02x", record->data[index_data++]); + /* For a better look, display a "-" character + * after each 5 bytes of OEM GUID + */ + if (!(index % 5)) { + printf("-"); + } + } + printf("\n"); + oem_count--; + } + } + if ((record->data[index_data] & AMC_MODULE) == AMC_MODULE) { + printf("AMC module connection\n"); + } else { + printf("On-Carrier Device %02x h\n", + (record->data[index_data] & 0x0f)); + } + index_data ++; + ch_count = record->data[index_data++]; + printf("AMC Channel Descriptor count: %02x h\n", ch_count); + + if (ch_count > 0) { + for (index = 0; index < ch_count; index++) { + unsigned int data; + struct fru_picmgext_amc_channel_desc_record *ch_desc; + printf(" AMC Channel Descriptor {%02x%02x%02x}\n", + record->data[index_data+2], + record->data[index_data+1], + record->data[index_data]); + data = record->data[index_data] + | (record->data[index_data + 1] << 8) + | (record->data[index_data + 2] << 16); + ch_desc = (struct fru_picmgext_amc_channel_desc_record *)&data; + printf(" Lane 0 Port: %d\n", ch_desc->lane0port); + printf(" Lane 1 Port: %d\n", ch_desc->lane1port); + printf(" Lane 2 Port: %d\n", ch_desc->lane2port); + printf(" Lane 3 Port: %d\n\n", ch_desc->lane3port); + index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE; + } + } + while (index_data < record->header.len) { + /* Warning: This code doesn't work with gcc version + * between 4.0 and 4.3 + */ + unsigned int data[2]; + struct fru_picmgext_amc_link_desc_record *link_desc; + data[0] = record->data[index_data] + | (record->data[index_data + 1] << 8) + | (record->data[index_data + 2] << 16) + | (record->data[index_data + 3] << 24); + data[1] = record->data[index_data + 4]; + + link_desc = (struct fru_picmgext_amc_link_desc_record *)&data[0]; + printf(" AMC Link Descriptor:\n"); + printf("\t- Link Type: %s \n", + val2str(link_desc->type, ipmi_ekanalyzer_link_type)); + switch (link_desc->type) { + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE: + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1: + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2: + printf("\t- Link Type extension: %s\n", + val2str(link_desc->type_ext, + ipmi_ekanalyzer_extension_PCIE)); + printf("\t- Link Group ID: %d\n ", + link_desc->group_id); + printf("\t- Link Asym. Match: %d - %s\n", + link_desc->asym_match, + val2str(link_desc->asym_match, + ipmi_ekanalyzer_asym_PCIE)); + break; + case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET: + printf("\t- Link Type extension: %s\n", + val2str (link_desc->type_ext, + ipmi_ekanalyzer_extension_ETHERNET)); + printf("\t- Link Group ID: %d \n", + link_desc->group_id); + printf("\t- Link Asym. Match: %d - %s\n", + link_desc->asym_match, + val2str(link_desc->asym_match, + ipmi_ekanalyzer_asym_PCIE)); + break; + case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE: + printf("\t- Link Type extension: %s\n", + val2str (link_desc->type_ext, + ipmi_ekanalyzer_extension_STORAGE)); + printf("\t- Link Group ID: %d \n", + link_desc->group_id); + printf("\t- Link Asym. Match: %d - %s\n", + link_desc->asym_match, + val2str(link_desc->asym_match, + ipmi_ekanalyzer_asym_STORAGE)); + break; + default: + printf("\t- Link Type extension: %i (Unknown)\n", + link_desc->type_ext); + printf("\t- Link Group ID: %d \n", + link_desc->group_id); + printf("\t- Link Asym. Match: %i\n", + link_desc->asym_match); + break; + } + printf("\t- AMC Link Designator:\n"); + printf("\t Channel ID: %i\n", link_desc->channel_id); + printf("\t\t Lane 0: %s\n", + (link_desc->port_flag_0) ? "enable" : "disable"); + printf("\t\t Lane 1: %s\n", + (link_desc->port_flag_1) ? "enable" : "disable"); + printf("\t\t Lane 2: %s\n", + (link_desc->port_flag_2) ? "enable" : "disable"); + printf("\t\t Lane 3: %s\n", + (link_desc->port_flag_3) ? "enable" : "disable"); + index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE; + } } /************************************************************************** @@ -3807,26 +3788,25 @@ ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static void -ipmi_ek_display_amc_carrier_info_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_amc_carrier_info_record(struct ipmi_ek_multi_header *record) { - unsigned char extVersion; - unsigned char siteCount; - int offset = START_DATA_OFFSET; - - extVersion = record->data[offset++]; - siteCount = record->data[offset++]; - - printf(" AMC.0 extension version: R%d.%d\n", (extVersion >> 0)& 0x0F, - (extVersion >> 4)& 0x0F ); - printf(" Carrier Sie Number Count: %d\n", siteCount); - - while (siteCount > 0){ - printf("\tSite ID (%d): %s \n", record->data[offset], - val2str(record->data[offset], ipmi_ekanalyzer_module_type) ); - offset++; - siteCount--; - } - printf("\n"); + unsigned char extVersion; + unsigned char siteCount; + int offset = START_DATA_OFFSET; + + extVersion = record->data[offset++]; + siteCount = record->data[offset++]; + printf(" AMC.0 extension version: R%d.%d\n", + (extVersion >> 0) & 0x0F, + (extVersion >> 4) & 0x0F); + printf(" Carrier Sie Number Count: %d\n", siteCount); + while (siteCount > 0) { + printf("\tSite ID (%d): %s \n", record->data[offset], + val2str(record->data[offset], ipmi_ekanalyzer_module_type)); + offset++; + siteCount--; + } + printf("\n"); } /************************************************************************** @@ -3849,63 +3829,58 @@ ipmi_ek_display_amc_carrier_info_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static void -ipmi_ek_display_clock_carrier_p2p_record( - struct ipmi_ek_multi_header * record ) +ipmi_ek_display_clock_carrier_p2p_record(struct ipmi_ek_multi_header *record) { - unsigned char desc_count; - int i,j; - int offset = START_DATA_OFFSET; - - desc_count = record->data[offset++]; - - for(i=0; i<desc_count; i++){ - unsigned char resource_id; - unsigned char channel_count; - - resource_id = record->data[offset++]; - channel_count = record->data[offset++]; - - printf(" Clock Resource ID: 0x%02x\n", resource_id); - printf(" Type: "); - if((resource_id & 0xC0)>>6 == 0) { - printf("On-Carrier-Device\n"); - } - else if((resource_id & 0xC0)>>6 == 1) { - printf("AMC slot\n"); - } - else if((resource_id & 0xC0)>>6 == 2) { - printf("Backplane\n"); - } - else{ - printf("reserved\n"); - } - printf(" Channel Count: 0x%02x\n", channel_count); - - for(j=0; j<channel_count; j++){ - unsigned char loc_channel, rem_channel, rem_resource; - - loc_channel = record->data[offset++]; - rem_channel = record->data[offset++]; - rem_resource = record->data[offset++]; - - printf("\tCLK-ID: 0x%02x ---> ", loc_channel); - printf(" remote CLKID: 0x%02x ", rem_channel); - if((rem_resource & 0xC0)>>6 == 0) { - printf("[ Carrier-Dev"); - } - else if((rem_resource & 0xC0)>>6 == 1) { - printf("[ AMC slot "); - } - else if((rem_resource & 0xC0)>>6 == 2) { - printf("[ Backplane "); - } - else{ - printf("reserved "); - } - printf(" 0x%02x ]\n", rem_resource&0xF); - } - } - printf("\n"); + unsigned char desc_count; + int i; + int j; + int offset = START_DATA_OFFSET; + + desc_count = record->data[offset++]; + for(i = 0; i < desc_count; i++) { + unsigned char resource_id; + unsigned char channel_count; + + resource_id = record->data[offset++]; + channel_count = record->data[offset++]; + + printf(" Clock Resource ID: 0x%02x\n", resource_id); + printf(" Type: "); + if ((resource_id & 0xC0) >> 6 == 0) { + printf("On-Carrier-Device\n"); + } else if ((resource_id & 0xC0) >> 6 == 1) { + printf("AMC slot\n"); + } else if ((resource_id & 0xC0) >> 6 == 2) { + printf("Backplane\n"); + } else{ + printf("reserved\n"); + } + printf(" Channel Count: 0x%02x\n", channel_count); + + for (j = 0; j < channel_count; j++) { + unsigned char loc_channel; + unsigned char rem_channel; + unsigned char rem_resource; + + loc_channel = record->data[offset++]; + rem_channel = record->data[offset++]; + rem_resource = record->data[offset++]; + + printf("\tCLK-ID: 0x%02x ---> ", loc_channel); + printf(" remote CLKID: 0x%02x ", rem_channel); + if ((rem_resource & 0xC0) >> 6 == 0) { + printf("[ Carrier-Dev"); + } else if ((rem_resource & 0xC0) >> 6 == 1) { + printf("[ AMC slot "); + } else if ((rem_resource & 0xC0) >> 6 == 2) { + printf("[ Backplane "); + } else { + printf("reserved "); + } + printf(" 0x%02x ]\n", rem_resource & 0xF); + } + } + printf("\n"); } /************************************************************************** @@ -3927,79 +3902,88 @@ ipmi_ek_display_clock_carrier_p2p_record( * ***************************************************************************/ void -ipmi_ek_display_clock_config_record( struct ipmi_ek_multi_header * record ) +ipmi_ek_display_clock_config_record(struct ipmi_ek_multi_header *record) { - unsigned char resource_id, descr_count; - int i; - int offset = START_DATA_OFFSET; - - resource_id = record->data[offset++]; - descr_count = record->data[offset++]; - printf(" Clock Resource ID: 0x%02x\n", resource_id); - printf(" Clock Configuration Descriptor Count: 0x%02x\n", descr_count); - - for(i=0; i<descr_count; i++){ - unsigned char channel_id, control; - unsigned char indirect_cnt, direct_cnt; - int j=0; - - channel_id = record->data[offset++]; - control = record->data[offset++]; - printf("\tCLK-ID: 0x%02x - ", channel_id); - printf("CTRL 0x%02x [ %12s ]\n", control, - ((control&0x1)==0)?"Carrier IPMC":"Application"); - - indirect_cnt = record->data[offset++]; - direct_cnt = record->data[offset++]; - printf("\t Count: Indirect 0x%02x / Direct 0x%02x\n", indirect_cnt, - direct_cnt ); - - /* indirect desc */ - for(j=0; j<indirect_cnt; j++){ - unsigned char feature; - unsigned char dep_chn_id; - - feature = record->data[offset++]; - dep_chn_id = record->data[offset++]; - printf("\t\tFeature: 0x%02x [%8s] - ", feature, - (feature&0x1)==1?"Source":"Receiver"); - printf(" Dep. CLK-ID: 0x%02x\n", dep_chn_id); - } - - /* direct desc */ - for(j=0; j<direct_cnt; j++){ - unsigned char feature, family, accuracy; - unsigned long freq, min_freq, max_freq; - - feature = record->data[offset++]; - family = record->data[offset++]; - accuracy = record->data[offset++]; - freq = (record->data[offset+0] << 0 ) - | (record->data[offset+1] << 8 ) - | (record->data[offset+2] << 16) - | (record->data[offset+3] << 24); - offset += 4; - min_freq = (record->data[offset+0] << 0 ) - | (record->data[offset+1] << 8 ) - | (record->data[offset+2] << 16) - | (record->data[offset+3] << 24); - offset += 4; - max_freq = (record->data[offset+0] << 0 ) - | (record->data[offset+1] << 8 ) - | (record->data[offset+2] << 16) - | (record->data[offset+3] << 24); - offset += 4; - - printf("\t- Feature: 0x%02x - PLL: %x / Asym: %s\n", - feature, - (feature > 1) & 1, - (feature&1)?"Source":"Receiver"); - printf("\tFamily: 0x%02x - AccLVL: 0x%02x\n", family, accuracy); - printf("\tFRQ: %-9ld - min: %-9ld - max: %-9ld\n", - freq, min_freq, max_freq); - } - printf("\n"); - } + unsigned char resource_id; + unsigned char descr_count; + int i; + int offset = START_DATA_OFFSET; + + resource_id = record->data[offset++]; + descr_count = record->data[offset++]; + printf(" Clock Resource ID: 0x%02x\n", resource_id); + printf(" Clock Configuration Descriptor Count: 0x%02x\n", descr_count); + + for (i = 0; i < descr_count; i++) { + int j = 0; + unsigned char channel_id; + unsigned char control; + unsigned char indirect_cnt; + unsigned char direct_cnt; + + channel_id = record->data[offset++]; + control = record->data[offset++]; + printf("\tCLK-ID: 0x%02x - ", channel_id); + printf("CTRL 0x%02x [ %12s ]\n", control, + ((control & 0x1) == 0) ? "Carrier IPMC" : "Application"); + + indirect_cnt = record->data[offset++]; + direct_cnt = record->data[offset++]; + printf("\t Count: Indirect 0x%02x / Direct 0x%02x\n", + indirect_cnt, + direct_cnt); + + /* indirect desc */ + for (j = 0; j < indirect_cnt; j++) { + unsigned char feature; + unsigned char dep_chn_id; + + feature = record->data[offset++]; + dep_chn_id = record->data[offset++]; + printf("\t\tFeature: 0x%02x [%8s] - ", + feature, + (feature & 0x1) == 1 ? "Source" : "Receiver"); + printf(" Dep. CLK-ID: 0x%02x\n", dep_chn_id); + } + /* direct desc */ + for (j = 0; j < direct_cnt; j++) { + unsigned char feature; + unsigned char family; + unsigned char accuracy; + unsigned long freq; + unsigned long min_freq; + unsigned long max_freq; + + feature = record->data[offset++]; + family = record->data[offset++]; + accuracy = record->data[offset++]; + freq = (record->data[offset+0] << 0) + | (record->data[offset+1] << 8) + | (record->data[offset+2] << 16) + | (record->data[offset+3] << 24); + offset += 4; + min_freq = (record->data[offset+0] << 0) + | (record->data[offset+1] << 8) + | (record->data[offset+2] << 16) + | (record->data[offset+3] << 24); + offset += 4; + max_freq = (record->data[offset+0] << 0) + | (record->data[offset+1] << 8) + | (record->data[offset+2] << 16) + | (record->data[offset+3] << 24); + offset += 4; + + printf("\t- Feature: 0x%02x - PLL: %x / Asym: %s\n", + feature, + (feature > 1) & 1, + (feature & 1) ? "Source" : "Receiver"); + printf("\tFamily: 0x%02x - AccLVL: 0x%02x\n", + family, accuracy); + printf("\tFRQ: %-9ld - min: %-9ld - max: %-9ld\n", + freq, min_freq, max_freq); + } + printf("\n"); + } } /************************************************************************** @@ -4022,12 +4006,12 @@ ipmi_ek_display_clock_config_record( struct ipmi_ek_multi_header * record ) * ***************************************************************************/ static int -ipmi_ekanalyzer_fru_file2structure(char * filename, - struct ipmi_ek_multi_header ** list_head, - struct ipmi_ek_multi_header ** list_record, - struct ipmi_ek_multi_header ** list_last) +ipmi_ekanalyzer_fru_file2structure(char *filename, + struct ipmi_ek_multi_header **list_head, + struct ipmi_ek_multi_header **list_record, + struct ipmi_ek_multi_header **list_last) { - FILE * input_file; + FILE *input_file; unsigned char data; unsigned char last_record = 0; unsigned int multi_offset = 0; @@ -4050,21 +4034,23 @@ ipmi_ekanalyzer_fru_file2structure(char * filename, } if (data == 0) { lprintf(LOG_ERR, "There is no multi record in the file '%s'", - filename); + filename); fclose(input_file); return ERROR_STATUS; } /* the offset value is in multiple of 8 bytes. */ multi_offset = data * 8; lprintf(LOG_DEBUG, "start multi offset = 0x%02x", - multi_offset ); + multi_offset); fseek(input_file, multi_offset, SEEK_SET); while (!feof(input_file)) { + /* TODO - check malloc() */ *list_record = malloc(sizeof(struct ipmi_ek_multi_header)); ret = fread(&(*list_record)->header, START_DATA_OFFSET, 1, input_file); if ((ret != 1) || ferror(input_file)) { + /* TODO - no free?! */ lprintf(LOG_ERR, "Invalid Header!"); fclose(input_file); return ERROR_STATUS; @@ -4115,7 +4101,6 @@ ipmi_ekanalyzer_fru_file2structure(char * filename, return OK_STATUS; } - /************************************************************************** * * Function name: ipmi_ek_add_record2list @@ -4135,24 +4120,25 @@ ipmi_ekanalyzer_fru_file2structure(char * filename, * ***************************************************************************/ static void -ipmi_ek_add_record2list( struct ipmi_ek_multi_header ** record, - struct ipmi_ek_multi_header ** list_head, - struct ipmi_ek_multi_header ** list_last ) +ipmi_ek_add_record2list(struct ipmi_ek_multi_header **record, + struct ipmi_ek_multi_header **list_head, + struct ipmi_ek_multi_header **list_last) { - if (*list_head == NULL) { - *list_head = *record; - (*record)->prev = NULL; - if (verbose > 2) - printf("Adding first record to list\n"); - } - else { - (*list_last)->next = *record; - (*record)->prev = *list_last; - if (verbose > 2) - printf("Add 1 record to list\n"); - } - *list_last = *record; - (*record)->next = NULL; + if (*list_head == NULL) { + *list_head = *record; + (*record)->prev = NULL; + if (verbose > 2) { + printf("Adding first record to list\n"); + } + } else { + (*list_last)->next = *record; + (*record)->prev = *list_last; + if (verbose > 2) { + printf("Add 1 record to list\n"); + } + } + *list_last = *record; + (*record)->next = NULL; } /************************************************************************** @@ -4174,22 +4160,20 @@ ipmi_ek_add_record2list( struct ipmi_ek_multi_header ** record, * ***************************************************************************/ static void -ipmi_ek_remove_record_from_list( struct ipmi_ek_multi_header * record, - struct ipmi_ek_multi_header ** list_head, - struct ipmi_ek_multi_header ** list_last ) +ipmi_ek_remove_record_from_list(struct ipmi_ek_multi_header *record, + struct ipmi_ek_multi_header **list_head, + struct ipmi_ek_multi_header **list_last) { - if (record->prev == NULL) - *list_head = record->next; - else - record->prev->next = record->next; - if ( record->next == NULL ) - (*list_last) = record->prev; - else - record->next->prev = record->prev; - free(record); - record = NULL; + if (record->prev == NULL) { + *list_head = record->next; + } else { + record->prev->next = record->next; + } + if (record->next == NULL) { + (*list_last) = record->prev; + } else { + record->next->prev = record->prev; + } + free(record); + record = NULL; } - - - - |