STATIC cmd_result_t bcmx_lp_parse(int unit, args_t *args) { bcmx_lplist_t list; char *c; bcmx_lport_t lport; int count; cmd_result_t cmd_rv = CMD_OK; int lp_cnt; if ((c = ARG_GET(args)) == NULL) { return CMD_USAGE; } bcmx_lplist_init(&list, 0, 0); if (bcmx_lplist_parse(&list, c)) { cmd_rv = CMD_FAIL; } else { sal_printf("List contains %d port%s; allocated %d\n", list.lp_last + 1, (list.lp_last == 0) ? "" : "s", list.lp_alloc); lp_cnt = 0; BCMX_LPLIST_ITER(list, lport, count) { _bcmx_sys_info_lport_display(lport, lp_cnt++); } if (lp_cnt != list.lp_last + 1) { sal_printf("WARNING: Port count mismatch\n"); } sal_printf("\n"); }
static int sal_config_get_rvalue(char *str, sc_t *sc) { char *begin; char *end; if ((begin = strchr(str, '=')) == NULL) { return FALSE; } begin++; /* Move past '=' */ while (isspace((unsigned)*begin)) { begin++; /* Trim leading whitespace */ } for (end = begin + strlen(begin) - 1; isspace((unsigned)*end); end--) *end = '\0'; /* Trim trailing whitespace */ sc->sc_value = sal_alloc(end - begin + 2, "config value"); if (sc->sc_value == NULL) { sal_printf("sal_config_parse: Memory allocation failed\n"); FREE_SC(sc); return FALSE; } sal_strncpy(sc->sc_value, begin, end - begin + 1); sc->sc_value[end - begin + 1] = '\0'; return TRUE; }
cmd_result_t cmd_setfanspeed(int unit, args_t *a) { char *d = ARG_GET(a); char *s = ARG_GET(a); int devno = -1, speed = -1; int retv; if (!sh_check_attached(ARG_CMD(a), unit)) return CMD_FAIL; if (d) { devno = parse_integer(d); } if (s) { speed = parse_integer(s); } if ((devno < 0) || (devno > 7) || (speed < 0) || (speed > 15)) { return CMD_USAGE; } retv = soc_bsc_max6653_set(unit, devno, speed); if (retv) { sal_printf("%s failed\n", FUNCTION_NAME()); return CMD_FAIL; } return CMD_OK; }
STATIC int _bcmx_sys_info_lport_display(bcmx_lport_t lport, int lp_cnt) { int bcm_unit, modid; bcm_port_t bcm_port, modport; uint32 flags; int rv; rv = bcmx_lport_to_unit_port(lport, &bcm_unit, &bcm_port); if (BCM_SUCCESS(rv)) { rv = bcmx_lport_to_modid_port(lport, &modid, &modport); } if (lp_cnt == 0) { sal_printf("%6s%8s%-10s%10s.%4s%10s.%4s%8s%s\n", "Uport", "", "Lport", "Unit", "Port", "ModID","Port", "", "Flags"); } if (BCM_SUCCESS(rv)) { flags = BCMX_LPORT_FLAGS(lport); sal_printf("%6s%8s0x%8.8x%10d.%-4d%10d.%-4d%8s%s%s%s%s%s%s%s\n", bcmx_lport_to_uport_str(lport), "", lport, bcm_unit, bcm_port, modid, modport, "", flags & BCMX_PORT_F_STACK_INT ? "Int-Stk " : "", flags & BCMX_PORT_F_STACK_EXT ? "Ext-Stk " : "", flags & BCMX_PORT_F_CPU ? "CPU " : "", flags & BCMX_PORT_F_HG ? "HG " : "", flags & BCMX_PORT_F_FE ? "FE " : "", flags & BCMX_PORT_F_GE ? "GE " : "", flags & BCMX_PORT_F_XE ? "XE " : ""); } else { /* Error obtaining information */ sal_printf("%6s%8s0x%8.8x (%s)\n", bcmx_lport_to_uport_str(lport), "", lport, bcm_errmsg(rv)); } return rv; }
void sal_config_show(void) { sc_t *sc; int i; for (i = 0; i < MAX_CONFIG_HASH_COUNT; i++) { for (sc = sal_config_list[i]; sc != NULL; sc = sc->sc_next) { sal_printf("\t%s=%s\n", sc->sc_name, sc->sc_value); } } }
/* * These stubs are here for legacy compatability reasons. * They are used only by the diag/test code, not the driver, * so they are really not that important. */ void pci_print_all(void) { int device; sal_printf("Scanning function 0 of devices 0-%d\n", bde->num_devices(BDE_SWITCH_DEVICES) - 1); sal_printf( "device fn venID devID class rev MBAR0 MBAR1 IPIN ILINE\n"); for (device = 0; device < bde->num_devices(BDE_SWITCH_DEVICES); device++) { uint32 vendorID, deviceID, class, revID; uint32 MBAR0, MBAR1, ipin, iline; vendorID = (bde->pci_conf_read(device, PCI_CONF_VENDOR_ID) & 0x0000ffff); if (vendorID == 0) continue; #define CONFIG(offset) bde->pci_conf_read(device, (offset)) deviceID = (CONFIG(PCI_CONF_VENDOR_ID) & 0xffff0000) >> 16; class = (CONFIG(PCI_CONF_REVISION_ID) & 0xffffff00) >> 8; revID = (CONFIG(PCI_CONF_REVISION_ID) & 0x000000ff) >> 0; MBAR0 = (CONFIG(PCI_CONF_BAR0) & 0xffffffff) >> 0; MBAR1 = (CONFIG(PCI_CONF_BAR1) & 0xffffffff) >> 0; iline = (CONFIG(PCI_CONF_INTERRUPT_LINE) & 0x000000ff) >> 0; ipin = (CONFIG(PCI_CONF_INTERRUPT_LINE) & 0x0000ff00) >> 8; #undef CONFIG sal_printf("%02x %02x %04x %04x " "%06x %02x %08x %08x %02x %02x\n", device, 0, vendorID, deviceID, class, revID, MBAR0, MBAR1, ipin, iline); } }
int sal_config_save(char *fname, char *pat, int append) { int rv = 0; #ifndef SAL_CONFIG_FILE_DISABLE FILE *new_fp; sc_t *sc; int pat_len = 0; int i; if (fname == NULL) { return 0; /* No config file */ } if(append) { new_fp = sal_fopen(fname, "a"); } else { new_fp = sal_fopen(fname, "w"); } if (new_fp == NULL) { rv = -1; goto done; } if (pat) { pat_len = strlen(pat); } /* Write out the current values */ for (i = 0; i < MAX_CONFIG_HASH_COUNT; i++) { for (sc = sal_config_list[i]; sc != NULL; sc = sc->sc_next) { if ((pat == NULL) || (sal_strncasecmp(sc->sc_name, pat, pat_len) == 0)) { sal_fprintf(new_fp, "%s=%s\n", sc->sc_name, sc->sc_value); } } } sal_fclose(new_fp); done: if (rv < 0) { sal_printf("sal_config_flush: variables not saved\n"); } #endif /* SAL_CONFIG_FILE_DISABLE */ return rv; }
uint32 pli_getreg_service(pcid_info_t * pcid_info, int unit, uint32 type, uint32 regnum) { char buffer[35]; uint32 value, rv; uint32 data[SOC_MAX_MEM_WORDS]; PCID_MEM_LOCK(pcid_info); pcid_type_name(buffer, type); if ((regnum & 3) && type != SOC_INTERNAL) { sal_printf("pli_getreg_service: unaligned access, " "type=0x%x addr=0x%x\n", type, regnum); regnum &= ~3; } value = 0xffffffff; /* Default value */ memset (data,0xff,sizeof(data)); #ifdef BCM_CMICM_SUPPORT if (pcid_info->cmicm >= CMC0) { pli_cmicm_getreg_service(pcid_info, unit, type, regnum, data); value = data[0]; } else #endif { pli_cmice_getreg_service(pcid_info, unit, type, regnum, data); value = data[0]; } if (pcid_info->opt_pli_verbose) { LOG_VERBOSE(BSL_LS_SOC_COMMON, (BSL_META_U(unit, "%s READ @0x%x => 0x%x\n"), buffer, regnum, value)); } rv = soc_internal_endian_swap(pcid_info, value, MF_ES_PIO); PCID_MEM_UNLOCK(pcid_info); return rv; }
STATIC cmd_result_t bcmx_cmd_sys_info(int unit, args_t *args) { int lp_cnt; bcmx_lport_t lport; lp_cnt = 0; /* Iterate over 'lport' */ BCMX_FOREACH_LPORT(lport) { _bcmx_sys_info_lport_display(lport, lp_cnt++); } if (bcmx_unit_count != 0 || lp_cnt != 0) { sal_printf("BCMX has %d unit%s registered with %d valid lports\n", bcmx_unit_count, bcmx_unit_count == 1 ? "" : "s", lp_cnt); } return CMD_OK; }
int sal_config_flush(void) { int rv = 0; #ifndef SAL_CONFIG_FILE_DISABLE FILE *old_fp, *new_fp; sc_t *sc, *new_sc; char str[SAL_CONFIG_STR_MAX], *c; int line = 0; char *fname, *tname; int i; fname = (sal_config_file_name != NULL ? sal_config_file_name : SAL_CONFIG_FILE); if (fname[0] == 0) { return 0; /* No config file */ } tname = (sal_config_temp_name != NULL ? sal_config_temp_name : SAL_CONFIG_TEMP); assert(tname != NULL && tname[0] != 0); /* Attempt to create temp file */ if ((new_fp = sal_fopen(tname, "w")) == NULL) { rv = -1; goto done; } /* old_fp can be NULL if creating config file for first time */ old_fp = sal_fopen(fname, "r"); /* Initialize the "flushed" flag */ for (i = 0; i < MAX_CONFIG_HASH_COUNT; i++) { for (sc = sal_config_list[i]; sc != NULL; sc = sc->sc_next) { sc->sc_flag = SC_NOT_FLUSHED; } } /* Read the entire file - parsing as we go */ while (old_fp != NULL && sal_fgets(str, sizeof(str), old_fp)) { char *s; line++; /* Strip trailing newline/blanks */ c = str + strlen(str); while (c > str && isspace((unsigned) c[-1])) { c--; } *c = '\0'; /* * Transfer blank lines and comment lines, but NOT commented-out * variable settings (yet) */ if (str[0] == 0 || (str[0] == '#' && strchr(str, '=') == NULL)) { sal_fprintf(new_fp, "%s\n", str); continue; } s = str; if (*s == '#') { s++; } if ((sc = sal_config_parse(s)) == NULL) { sal_printf("sal_config_flush: format error " "in %s on line %d (removed)\n", fname, line); continue; } /* Write new value (or comment) for this entry */ if ((new_sc = sal_config_find(sc->sc_name)) == NULL || new_sc->sc_flag == SC_FLUSHED) { /* Not found or a dup, write out commented assignment */ sal_fprintf(new_fp, "#%s=%s\n", sc->sc_name, sc->sc_value); } else { sal_fprintf(new_fp, "%s=%s\n", new_sc->sc_name, new_sc->sc_value); new_sc->sc_flag = SC_FLUSHED; } FREE_SC(sc); } /* Write out the current values that were not in the old_fp file */ for (i = 0; i < MAX_CONFIG_HASH_COUNT; i++) { for (sc = sal_config_list[i]; sc != NULL; sc = sc->sc_next) { if (sc->sc_flag == SC_NOT_FLUSHED) { sal_fprintf(new_fp, "%s=%s\n", sc->sc_name, sc->sc_value); } } } sal_fclose(new_fp); if (old_fp != NULL) { sal_fclose(old_fp); } if (rv == 0) { /* No error, rename file */ rv = sal_rename(tname, fname); } if (rv != 0) { /* Error, remove temp file */ (void)sal_remove(tname); } done: if (rv < 0) { sal_printf("sal_config_flush: variables not saved\n"); } #endif /* SAL_CONFIG_FILE_DISABLE */ return rv; }
/* * Function: * sal_config_refresh * Purpose: * Refresh default (compiled-in) configuration. * Refresh the memory image from the configuration file, * clobbering default values (if the config file exists). * Parameters: * None * Returns: * 0 - success * -1 - failed. */ int sal_config_refresh(void) { sc_t *sc, *sc_tmp; int i; #ifndef SAL_CONFIG_FILE_DISABLE FILE *fp; sc_t *found_sc; char str[SAL_CONFIG_STR_MAX], *c; int line = 0; char *fname; int suppress_unknown_warnings = 0; #endif /* Clear all previous state */ for (i = 0; i < MAX_CONFIG_HASH_COUNT; i++) { sc = sal_config_list[i]; sal_config_list[i] = NULL; while (sc != NULL) { sc_tmp = sc->sc_next; FREE_SC(sc); sc = sc_tmp; } } /* load precompiled values from platform_defines.c */ sal_config_init_defaults(); #ifndef SAL_CONFIG_FILE_DISABLE fname = (sal_config_file_name != NULL ? sal_config_file_name : SAL_CONFIG_FILE); if (fname[0] == 0) { return 0; /* No config file */ } /* Try to load config file ... */ if ((fp = sal_fopen(fname, "r")) == NULL) { #if defined(BROADCOM_DEBUG) sal_printf("sal_config_refresh: cannot read file: %s, " "variables not loaded\n", fname); #endif /* BROADCOM_DEBUG */ return -1; } /* * Add new file-based variables, superseding any matching compiled * variables. Find end-of-list, and initialize the default-or-file * flag. */ for (i = 0; i < MAX_CONFIG_HASH_COUNT; i++) { for (sc = sal_config_list[i]; sc != NULL; sc = sc->sc_next) { sc->sc_flag = SC_COMPILE_VALUE; } } /* Read the entire file - parsing as we go */ while (sal_fgets(str, sizeof(str), fp)) { line++; /* Skip comment lines */ if (str[0] == '#') { continue; } /* Strip trailing newline/blanks */ c = str + strlen(str); while (c > str && isspace((unsigned) c[-1])) { c--; } *c = '\0'; /* Skip blank lines */ if (str[0] == 0) { continue; } if ((sc = sal_config_parse(str)) == NULL) { sal_printf("sal_config_refresh: format error " "in %s on line %d (ignored)\n", fname, line); continue; } /* Check for pre-existing default or duplicates in the file */ found_sc = sal_config_list[sc->sc_hash]; while (found_sc != NULL) { if (sal_strcmp(found_sc->sc_name, sc->sc_name) == 0) { break; } found_sc = found_sc->sc_next; } if (found_sc != NULL) { if (found_sc->sc_flag != SC_COMPILE_VALUE) { sal_printf("sal_config_refresh: ignoring duplicate entry " "\"%s\"\n" " %s line %d " "(first defined on line %d)\n", sc->sc_name, fname, line, found_sc->sc_flag); } else { /* Clobber the compiled-in default value */ char *temp = sc->sc_value; /* New value */ sc->sc_value = found_sc->sc_value; /* Old, to be freed */ found_sc->sc_value = temp; found_sc->sc_flag = line; /* Line # of 1st definition */ } FREE_SC(sc); continue; } /* * Scan for "suppress_unknown_prop_warnings" directly as we go * instead of sal_config_find() because it's much faster */ if (sal_strcasecmp("suppress_unknown_prop_warnings", sc->sc_name) == 0) { suppress_unknown_warnings = _shr_ctoi(sc->sc_value); } if (!suppress_unknown_warnings) { if (sal_config_prop_is_known(sc) == FALSE) { sal_printf("sal_config_refresh: unknown entry \"%s\"" " on %s line %d\n", sc->sc_name, fname, line); } } sc->sc_flag = line; /* Line # of 1st definition */ sc->sc_next = sal_config_list[sc->sc_hash]; sal_config_list[sc->sc_hash] = sc; } /* parse config file */ sal_fclose(fp); #endif /* SAL_CONFIG_FILE_DISABLE */ return 0; }
cmd_result_t sh_config(int u, args_t *a) /* * Function: sh_config * Purpose: Configure switch management information. * Parameters: * Returns: */ { int rv, add; char *name, *value, *c = ARG_CUR(a); rv = CMD_OK; if (c == NULL || !sal_strcasecmp(c, "show")) { name = NULL; while (kconfig_get_next(&name, &value) >= 0) { sal_printf("\t%s=%s\n", name, value); } if (NULL != c) { ARG_NEXT(a); } return CMD_OK; } if (!sal_strcasecmp(c, "delete")) { ARG_NEXT(a); while ((c = ARG_GET(a)) != NULL) { if (kconfig_set(c, 0) != 0) { printk("%s: Variable not found: %s\n", ARG_CMD(a), c); rv = CMD_FAIL; } } return rv; } if (!sal_strcasecmp(c, "add")) { ARG_NEXT(a); add = 1; } else { add = 0; } if (ARG_CNT(a)) { while ((c = ARG_GET(a)) != NULL) { char *s; s = strchr(c, '='); if (s == NULL) { printk("%s: Invalid assignment: %s\n", ARG_CMD(a), c); rv = CMD_FAIL; } else { *s++ = 0; if (!add && kconfig_get(c) == NULL) { printk("%s: Must use 'add' to create new variable: %s\n", ARG_CMD(a), c); rv = CMD_FAIL; } else { if (kconfig_set(c, s) < 0) { rv = CMD_FAIL; } } } } } return rv; }
cmd_result_t bcmx_cmd_mirror(int unit, args_t *args) { parse_table_t pt; int mode; int enable = 1; /* Should ports listed have mirroring enabled or dis */ char *iport; char *eport; char *dport; bcmx_lplist_t ports; bcmx_lport_t lport; int count; cmd_result_t cmd_rv = CMD_OK; int rv; char *subcmd = NULL; int mirror_mode; bcmx_uport_t uport; static char *modeList[] = {"L2", "L3", "Off", NULL}; if ((subcmd = ARG_GET(args)) == NULL) { int first; int val; bcmx_mirror_mode_get(&mirror_mode); bcmx_mirror_to_get(&lport); if (mirror_mode == BCM_MIRROR_DISABLE) { sal_printf("Mirroring is currently disabled.\n"); } else { sal_printf("Current mirror mode is: %s.\n", mirror_mode == BCM_MIRROR_L2 ? "L2" : "L3"); if (!BCMX_LPORT_VALID(lport)) { sal_printf("Warning: mirror to port is invalid\n"); } } if (BCMX_LPORT_VALID(lport)) { sal_printf("Current mirror to uport is %s (lport 0x%x).\n", bcmx_lport_to_uport_str(lport), lport); } first = TRUE; BCMX_FOREACH_LPORT(lport) { if (bcmx_mirror_ingress_get(lport, &val) == BCM_E_NONE) { if (val) { if (first) { sal_printf(" Ingress uport: %s", bcmx_lport_to_uport_str(lport)); first = FALSE; } else { sal_printf(" %s", bcmx_lport_to_uport_str(lport)); } } } } if (!first) { sal_printf("\n"); } first = TRUE; BCMX_FOREACH_LPORT(lport) { if (bcmx_mirror_egress_get(lport, &val) == BCM_E_NONE) { if (val) { if (first) { sal_printf(" Egress uport: %s", bcmx_lport_to_uport_str(lport)); first = FALSE; } else { sal_printf(" %s", bcmx_lport_to_uport_str(lport)); } } } } if (!first) { sal_printf("\n"); } return CMD_OK; }
/* fatal error interface to lexer - abort to diag shell */ void cmd_cint_fatal_error(char *msg) { sal_printf("%s",msg); sh_ctrl_c_take(); }
cmd_result_t bcmx_cmd_stat(int unit, args_t *args) { char *cmd, *subcmd, *s; int rv, all, count; bcmx_lport_t lport; bcmx_lplist_t lplist; bcm_stat_val_t stype; uint64 sval; char *sname; char *_stat_names[] = BCM_STAT_NAME_INITIALIZER; cmd = ARG_CMD(args); subcmd = ARG_GET(args); if (subcmd == NULL) { subcmd = "show"; } if (sal_strcasecmp(subcmd, "init") == 0) { rv = bcmx_stat_init(); if (rv < 0) { sal_printf("%s: ERROR: %s failed: %s\n", cmd, subcmd, bcm_errmsg(rv)); return CMD_FAIL; } return CMD_OK; } if (sal_strcasecmp(subcmd, "show") == 0) { all = 0; s = ARG_GET(args); if (s != NULL && sal_strcasecmp(s, "all") == 0) { all = 1; s = ARG_GET(args); } if (s == NULL) { s = "*"; } if (bcmx_lplist_init(&lplist, 0, 0) < 0) { sal_printf("%s: ERROR: could not init port list\n", cmd); return CMD_FAIL; } if (bcmx_lplist_parse(&lplist, s) < 0) { sal_printf("%s: ERROR: could not parse port list: %s\n", cmd, s); return CMD_FAIL; } BCMX_LPLIST_ITER(lplist, lport, count) { sal_printf("%s: Statistics for port %s\n", cmd, bcmx_lport_to_uport_str(lport)); for (stype = (bcm_stat_val_t)0; stype < snmpValCount; stype++) { sname = _stat_names[stype]; rv = bcmx_stat_get(lport, stype, &sval); if (rv < 0) { sal_printf("\t%18s\t%s (stat %d): %s\n", "-", sname, stype, bcm_errmsg(rv)); continue; } if (all == 0 && COMPILER_64_IS_ZERO(sval)) { continue; } if (COMPILER_64_HI(sval) == 0) { sal_printf("\t%18u\t%s (stat %d)\n", COMPILER_64_LO(sval), sname, stype); } else { sal_printf("\t0x%08x%08x\t%s (stat %d)\n", COMPILER_64_HI(sval), COMPILER_64_LO(sval), sname, stype); } } }