📄 klconflib.c
字号:
static intcomponent_serial_number_get(lboard_t *board, klconf_off_t mfg_nic_offset, char *serial_number, char *key_pattern){ char *mfg_nic_string; char *serial_string,*str; int i; char *serial_pattern = "Serial:"; /* We have an error on a null mfg nic offset */ if (!mfg_nic_offset) return(1); /* Get the hub's manufacturing nic information * which is in the form of a pre-formatted string */ mfg_nic_string = (char *)NODE_OFFSET_TO_K0(NASID_GET(board), mfg_nic_offset); /* There is no manufacturing nic info */ if (!mfg_nic_string) return(1); str = mfg_nic_string; /* Look for the key pattern first (if it is specified) * and then print the serial number corresponding to that. */ if (strcmp(key_pattern,"") && !(str = strstr(mfg_nic_string,key_pattern))) return(1); /* There is no serial number info in the manufacturing * nic info */ if (!(serial_string = strstr(str,serial_pattern))) return(1); serial_string = serial_string + strlen(serial_pattern); /* Copy the serial number information from the klconfig */ i = 0; while (serial_string[i] != ';') { serial_number[i] = serial_string[i]; i++; } serial_number[i] = 0; return(0);}/* * Get the serial number of a board * Returns 0 if a valid serial number is found * 1 otherwise. */intboard_serial_number_get(lboard_t *board,char *serial_number){ ASSERT(board && serial_number); if (!board || !serial_number) return(1); strcpy(serial_number,""); switch(KLCLASS(board->brd_type)) { case KLCLASS_CPU: { /* Node board */ klhub_t *hub; if (board->brd_type == KLTYPE_TIO) { printk("*****board_serial_number_get: Need to support TIO.*****\n"); strcpy(serial_number,""); return(0); } /* Get the hub component information */ hub = (klhub_t *)find_first_component(board, KLSTRUCT_HUB); /* If we don't have a hub component on an IP27 * then we have a weird klconfig. */ if (!hub) return(1); /* Get the serial number information from * the hub's manufacturing nic info */ if (component_serial_number_get(board, hub->hub_mfg_nic, serial_number, "IP37")) return(1); break; } case KLCLASS_IO: { /* IO board */ if (KLTYPE(board->brd_type) == KLTYPE_TPU) { /* Special case for TPU boards */ kltpu_t *tpu; /* Get the tpu component information */ tpu = (kltpu_t *)find_first_component(board, KLSTRUCT_TPU); /* If we don't have a tpu component on a tpu board * then we have a weird klconfig. */ if (!tpu) return(1); /* Get the serial number information from * the tpu's manufacturing nic info */ if (component_serial_number_get(board, tpu->tpu_mfg_nic, serial_number, "")) return(1); break; } else if ((KLTYPE(board->brd_type) == KLTYPE_GSN_A) || (KLTYPE(board->brd_type) == KLTYPE_GSN_B)) { /* Special case for GSN boards */ klgsn_t *gsn; /* Get the gsn component information */ gsn = (klgsn_t *)find_first_component(board, ((KLTYPE(board->brd_type) == KLTYPE_GSN_A) ? KLSTRUCT_GSN_A : KLSTRUCT_GSN_B)); /* If we don't have a gsn component on a gsn board * then we have a weird klconfig. */ if (!gsn) return(1); /* Get the serial number information from * the gsn's manufacturing nic info */ if (component_serial_number_get(board, gsn->gsn_mfg_nic, serial_number, "")) return(1); break; } else { klbri_t *bridge; /* Get the bridge component information */ bridge = (klbri_t *)find_first_component(board, KLSTRUCT_BRI); /* If we don't have a bridge component on an IO board * then we have a weird klconfig. */ if (!bridge) return(1); /* Get the serial number information from * the bridge's manufacturing nic info */ if (component_serial_number_get(board, bridge->bri_mfg_nic, serial_number, "")) return(1); break; } } case KLCLASS_ROUTER: { /* Router board */ klrou_t *router; /* Get the router component information */ router = (klrou_t *)find_first_component(board, KLSTRUCT_ROU); /* If we don't have a router component on a router board * then we have a weird klconfig. */ if (!router) return(1); /* Get the serial number information from * the router's manufacturing nic info */ if (component_serial_number_get(board, router->rou_mfg_nic, serial_number, "")) return(1); break; } case KLCLASS_GFX: { /* Gfx board */ klgfx_t *graphics; /* Get the graphics component information */ graphics = (klgfx_t *)find_first_component(board, KLSTRUCT_GFX); /* If we don't have a gfx component on a gfx board * then we have a weird klconfig. */ if (!graphics) return(1); /* Get the serial number information from * the graphics's manufacturing nic info */ if (component_serial_number_get(board, graphics->gfx_mfg_nic, serial_number, "")) return(1); break; } default: strcpy(serial_number,""); break; } return(0);}#include "asm/sn/sn_private.h"/* * Format a module id for printing. */voidformat_module_id(char *buffer, moduleid_t m, int fmt){ int rack, position; char brickchar; rack = MODULE_GET_RACK(m); ASSERT(MODULE_GET_BTYPE(m) < MAX_BRICK_TYPES); brickchar = MODULE_GET_BTCHAR(m); position = MODULE_GET_BPOS(m); if (fmt == MODULE_FORMAT_BRIEF) { /* Brief module number format, eg. 002c15 */ /* Decompress the rack number */ *buffer++ = '0' + RACK_GET_CLASS(rack); *buffer++ = '0' + RACK_GET_GROUP(rack); *buffer++ = '0' + RACK_GET_NUM(rack); /* Add the brick type */ *buffer++ = brickchar; } else if (fmt == MODULE_FORMAT_LONG) { /* Fuller hwgraph format, eg. rack/002/bay/15 */ strcpy(buffer, EDGE_LBL_RACK "/"); buffer += strlen(buffer); *buffer++ = '0' + RACK_GET_CLASS(rack); *buffer++ = '0' + RACK_GET_GROUP(rack); *buffer++ = '0' + RACK_GET_NUM(rack); strcpy(buffer, "/" EDGE_LBL_RPOS "/"); buffer += strlen(buffer); } /* Add the bay position, using at least two digits */ if (position < 10) *buffer++ = '0'; sprintf(buffer, "%d", position);}/* * Parse a module id, in either brief or long form. * Returns < 0 on error. * The long form does not include a brick type, so it defaults to 0 (CBrick) */intparse_module_id(char *buffer){ unsigned int v, rack, bay, type, form; moduleid_t m; char c; if (strstr(buffer, EDGE_LBL_RACK "/") == buffer) { form = MODULE_FORMAT_LONG; buffer += strlen(EDGE_LBL_RACK "/"); /* A long module ID must be exactly 5 non-template chars. */ if (strlen(buffer) != strlen("/" EDGE_LBL_RPOS "/") + 5) return -1; } else { form = MODULE_FORMAT_BRIEF; /* A brief module id must be exactly 6 characters */ if (strlen(buffer) != 6) return -2; } /* The rack number must be exactly 3 digits */ if (!(isdigit(buffer[0]) && isdigit(buffer[1]) && isdigit(buffer[2]))) return -3; rack = 0; v = *buffer++ - '0'; if (v > RACK_CLASS_MASK(rack) >> RACK_CLASS_SHFT(rack)) return -4; RACK_ADD_CLASS(rack, v); v = *buffer++ - '0'; if (v > RACK_GROUP_MASK(rack) >> RACK_GROUP_SHFT(rack)) return -5; RACK_ADD_GROUP(rack, v); v = *buffer++ - '0'; /* rack numbers are 1-based */ if (v-1 > RACK_NUM_MASK(rack) >> RACK_NUM_SHFT(rack)) return -6; RACK_ADD_NUM(rack, v); if (form == MODULE_FORMAT_BRIEF) { /* Next should be a module type character. Accept ucase or lcase. */ c = *buffer++; if (!isalpha(c)) return -7; /* strchr() returns a pointer into brick_types[], or NULL */ type = (unsigned int)(strchr(brick_types, tolower(c)) - brick_types); if (type > MODULE_BTYPE_MASK >> MODULE_BTYPE_SHFT) return -8; } else { /* Hardcode the module type, and skip over the boilerplate */ type = MODULE_CBRICK; if (strstr(buffer, "/" EDGE_LBL_RPOS "/") != buffer) return -9; buffer += strlen("/" EDGE_LBL_RPOS "/"); } /* The bay number is last. Make sure it's exactly two digits */ if (!(isdigit(buffer[0]) && isdigit(buffer[1]) && !buffer[2])) return -10; bay = 10 * (buffer[0] - '0') + (buffer[1] - '0'); if (bay > MODULE_BPOS_MASK >> MODULE_BPOS_SHFT) return -11; m = RBT_TO_MODULE(rack, bay, type); /* avoid sign extending the moduleid_t */ return (int)(unsigned short)m;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -