openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

system.c (67010B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  */
      7 
      8 #include <shared/bsl.h>
      9 
     10 #ifndef __KERNEL__
     11 #include <sys/types.h>
     12 #include <netinet/in.h>
     13 #include <signal.h>
     14 #include <setjmp.h>
     15 #endif
     16 
     17 #define SAL_ALLOC(x) sal_alloc(x, __FILE__)
     18 
     19 #include <sal/core/libc.h>
     20 #include <appl/diag/sysconf.h>
     21 #include <appl/diag/bslmgmt.h>
     22 #include <appl/diag/system.h>
     23 
     24 #if (defined(BROADCOM_DEBUG) && defined(SW_STATE_MEM_MONITOR))
     25 #include <shared/swstate/sw_state.h>
     26 #else
     27 #define DISPLAY_SW_STATE_MEM
     28 #endif /* (defined(BROADCOM_DEBUG) && defined(SW_STATE_MEM_MONITOR)) */
     29 
     30 #if defined(BCM_SAND_SUPPORT)
     31 #include <shared/bslenum.h>
     32 #include <appl/diag/bsldnx.h>
     33 #endif /* BCM_SAND_SUPPORT */
     34 #if defined(VXWORKS)
     35 #include <vxWorks.h>
     36 #include <sysLib.h>
     37 #include <version.h>
     38 #include <tyLib.h>
     39 
     40 #ifndef VXWORKS_NETWORK_STACK_6_5 
     41 #include <ifLib.h>
     42 #endif
     43 
     44 #include <hostLib.h>
     45 #include <netShow.h>
     46 #include <pingLib.h>
     47 #endif /* VXWORKS */
     48 
     49 
     50 #if defined(MOUSSE) || defined(BMW) || defined(IDTRP334) || defined(GTO) || \
     51     defined(MBZ) || defined(IDT438) || defined(NSX) ||  \
     52     defined(METROCORE) || defined(KEYSTONE)
     53 #if defined(VXWORKS)
     54 #include <config.h>      /* For INCLUDE_XXX */
     55 #endif /* VXWORKS */
     56 #endif
     57 
     58 /* #define INCLUDE_NFS 12345678*/
     59 
     60 #if defined(VXWORKS)
     61 #ifdef INCLUDE_NFS  /* VxWorks only - from config.h or configAll.h */
     62 #if VX_VERSION == 62 || VX_VERSION == 64 || VX_VERSION == 65 || \
     63     VX_VERSION == 66 || VX_VERSION == 68 || VX_VERSION == 69
     64 #ifndef MAX_GRPS
     65 #define MAX_GRPS                20
     66 #endif
     67 extern STATUS   nfsExportShow (char *hostName);
     68 extern void     nfsAuthUnixGet (char *machname, int *pUid, int *pGid,
     69                                 int *pNgids, int *gids);
     70 extern void     nfsAuthUnixSet (char *machname, int uid, int gid,
     71                                 int ngids, int *aup_gids);
     72 extern STATUS   nfsMount (const char *host, const char *fileSystem, 
     73                           const char *localName);
     74 extern void     nfsDevShow (void);
     75 extern STATUS   nfsUnmount (const char *localName);
     76 
     77 #else
     78 #include <nfsLib.h>
     79 #include <nfsDrv.h>
     80 #endif /* !VX_VERSION == 62  && !VX_VERSION == 64 */
     81 #endif /* INCLUDE_NFS */
     82 
     83 #ifdef INCLUDE_TELNET   /* VxWorks only - from Makefile.vxworks-<PLAT> */
     84 #include <taskLib.h>
     85 #include "../src/sal/appl/vxworks/telnetLib.h"
     86 #endif /* INCLUDE_TELNET */
     87 #else
     88 /* Undefine these VxWorks only features if they were requested */
     89 #ifdef INCLUDE_NFS
     90 #undef INCLUDE_NFS
     91 #endif /* INCLUDE_NFS */
     92 #ifdef INCLUDE_TELNET
     93 #undef INCLUDE_TELNET
     94 #endif /* INCLUDE_TELNET */
     95 #endif /* VXWORKS */
     96 
     97 #include <sal/appl/pci.h>
     98 #include <sal/appl/config.h>
     99 #include <sal/core/boot.h>
    100 #include <soc/memtune.h>
    101 #include <soc/devids.h>
    102 #include <soc/debug.h>
    103 #include <soc/drv.h>
    104 #include <soc/scache.h>
    105 
    106 #ifdef ADAPTER_SERVER_MODE
    107 #include <soc/dnx/adapter/adapter_reg_access.h>
    108 #endif
    109 #include <soc/l2x.h>
    110 #if defined(BCM_ESW_SUPPORT) || defined(BCM_SAND_SUPPORT)
    111 #include <soc/mcm/driver.h>
    112 #endif
    113 
    114 #include <bcm/error.h>
    115 #include <bcm/init.h>
    116 #include <bcm/stat.h>
    117 #include <bcm/link.h>
    118 #include <bcm/port.h>
    119 #include <bcm/rx.h>
    120 #include <bcm_int/control.h>
    121 
    122 #if defined(PLISIM)
    123 #include <bde/pli/verinet.h>
    124 #endif
    125 
    126 #include <appl/diag/diag.h>
    127 #include <appl/diag/dport.h>
    128 #ifdef BCM_WARM_BOOT_SUPPORT
    129 #include <appl/diag/warmboot.h>
    130 #endif /* BCM_WARM_BOOT_SUPPORT */
    131 
    132 #include <shared/shr_bprof.h>
    133 
    134 #ifdef CANCUN_SUPPORT
    135 #include <soc/esw/cancun.h>
    136 #endif
    137 
    138 /*
    139  * Global variable for currently attached unit in system.
    140  */
    141 
    142 #ifdef INCLUDE_TCL
    143 static char bootdir[256];
    144 #endif
    145 
    146 #ifndef NO_SAL_APPL
    147 static char *soc_init_rc[SOC_MAX_NUM_DEVICES];
    148 #endif
    149 
    150 #if defined(BCM_ESW_SUPPORT)
    151 extern void mem_watch_counter_init(int unit);
    152 extern void mem_watch_start(int unit);
    153 #endif
    154 
    155 #ifdef BMW
    156 extern int sysIsCFM(void);
    157 extern int sysSlotIdGet(void);
    158 #endif
    159 #ifdef MBZ
    160 extern int sysIsLM();
    161 extern int sysSlotIdGet();
    162 #endif /* MBZ */
    163 
    164 /*
    165  * Routine to set useful global variables for script files to use.
    166  */
    167 #if ((defined(__DUNE_GTO_BCM_CPU__) || defined(__DUNE_WRX_BCM_CPU__)) && !defined(PLISIM) && defined(BCM_PETRA_SUPPORT))
    168 
    169 #include <soc/i2c.h>
    170 #include <soc/dcmn/dcmn_utils_eeprom.h>
    171 #include <appl/diag/dcmn/bsp_cards_consts.h>
    172 extern int cpu_i2c_read_extended(int chip, int addr, CPU_I2C_BUS_LEN alen, int* p_val, int donot_print_errors);
    173 
    174 int sys_board_type_mng_get(void) {
    175 #ifndef __KERNEL__
    176     int val = 0;
    177 
    178     /* Do not report an error if the I2C read fails */
    179     if (cpu_i2c_read_extended(0x42, 0x11, CPU_I2C_ALEN_LONG_DLEN_LONG, &val, 1)) {
    180         /* Error: sal_printf("sysSlotIdGet: Failed reading Mng slot_id, Setting to 0\n"); */
    181         return 0;
    182     }
    183 
    184     if ((val & 0x3f) == 0x2f) {
    185         return 1;
    186     } else {
    187         return 0;
    188     }
    189 #endif /* __KERNEL__ */
    190     sal_printf("This function is unavailable in Kernel mode\n");
    191     return 0;
    192 }
    193 
    194 int sysBoardTypeGfaBiGet(void) {
    195       int val = 0;
    196 
    197     if (eeprom_read(NEGEV_CHASSIS_CARD_TYPE, NEGEV_CHASSIS_EEPROM_ADRESS_BOARD_TYPE, NEGEV_CHASSIS_EEPROM_BYTE_SIZE_BOARD_TYPE, &val)) {
    198         /* Error */
    199         sal_printf("sysBoardTypeGfaBiGet: Failed reading board_type, Setting to 0. val=%d\n", val);
    200         return 0;
    201     }
    202     
    203       if (val == LINE_CARD_GFA_PETRA_B_INTERLAKEN) {
    204             return 1;
    205       } else {
    206             return 0;
    207       }
    208 }
    209 
    210 int sysBoardTypeGfaBi2Get(void) {
    211     int val = 0;
    212 
    213     if (eeprom_read(NEGEV_CHASSIS_CARD_TYPE, NEGEV_CHASSIS_EEPROM_ADRESS_BOARD_TYPE, NEGEV_CHASSIS_EEPROM_BYTE_SIZE_BOARD_TYPE, &val)) {
    214         /* Error */
    215         /* sal_printf("sysBoardTypeGfaBi2Get: Failed reading board_type, Setting to 0. val=%d\n", val); */
    216         return 0;
    217     }
    218     
    219     if (val == LINE_CARD_GFA_PETRA_B_INTERLAKEN_2) {
    220         return 1;
    221     } else {
    222         return 0;
    223     }
    224 }
    225 
    226 int sysBoardTypeAradCardGet(void) {
    227     int val = 0;
    228 
    229     if (eeprom_read(NEGEV_CHASSIS_CARD_TYPE, NEGEV_CHASSIS_EEPROM_ADRESS_BOARD_TYPE, NEGEV_CHASSIS_EEPROM_BYTE_SIZE_BOARD_TYPE, &val)) {
    230         /* Error */
    231         /* sal_printf("sysBoardTypeGfaBi2Get: Failed reading board_type, Setting to 0. val=%d\n", val); */
    232         return 0;
    233     }
    234     
    235     if ((val == LINE_CARD_ARAD) || (LINE_CARD_ARAD_NOACP)) {
    236         return 1;
    237     } else {
    238         return 0;
    239     }
    240 }
    241 
    242 int sysSlotIdGet(void) {
    243 #ifndef __KERNEL__
    244     int val;
    245 
    246     if (sys_board_type_mng_get()) {
    247         return -1;
    248     }else if (sysBoardTypeGfaBiGet()) {
    249         if (cpu_i2c_read_extended(0x4d, 0x58, CPU_I2C_ALEN_BYTE_DLEN_BYTE, &val, 1)) {
    250             /* Error: sal_printf("sysSlotIdGet: Failed reading gfa-bi slot_id, Setting to 0\n"); */
    251             return -1;
    252         }
    253         return ((val & 0xf0) == 0x80) ? 0 : 1;
    254     } else if (sysBoardTypeGfaBi2Get()) {
    255         if (cpu_i2c_read_extended(0x4d, 0x58, CPU_I2C_ALEN_BYTE_DLEN_BYTE, &val, 1)) {
    256             /* Error: sal_printf("sysSlotIdGet: Failed reading gfa-bi2 slot_id, Setting to 0\n"); */
    257             return -1;
    258         }
    259         return ((val & 0xc0) == 0x0)  ? 0 : 1;
    260     } else if (sysBoardTypeAradCardGet()) {
    261         /* Do not report an error if the I2C read fails */
    262         if (cpu_i2c_read_extended(0x20, 0x0, CPU_I2C_ALEN_BYTE_DLEN_BYTE, &val, 1)) {
    263             /* Error: sal_printf("sysSlotIdGet: Failed reading arad-card slot_id, Setting to 0\n"); */
    264             return -1;
    265         }
    266         return ((val & 0x06) == 0x0)  ? 0 : 1;
    267     } else {
    268         return -1;
    269     }
    270 #endif /* __KERNEL__ */
    271     sal_printf("This function is unavailable in Kernel mode\n");
    272     return -1;
    273 }
    274 #endif /* (__DUNE_GTO_BCM_CPU__ || __DUNE_WRX_BCM_CPU__) && !PLISIM && BCM_PETRA_SUPPORT */
    275 
    276 static void
    277 gvar_init(void)
    278 {
    279 #ifndef NO_SAL_APPL
    280 
    281     char    path[256];
    282 
    283     /*
    284      * Path (default is current directory followed by home directory)
    285      */
    286 
    287     sal_strncpy(path, ". ", 3);
    288     sal_homedir_get(path + 2, sizeof (path) - 2);
    289     var_set("path", path, TRUE, FALSE);
    290 
    291 #ifdef INCLUDE_TCL
    292     var_set("bootdir", bootdir, TRUE, FALSE);
    293 #endif
    294 
    295 #endif /* NO_SAL_APPL */
    296 
    297     /*
    298      * Boot flags
    299      */
    300 
    301     if (SAL_BOOT_QUICKTURN) {
    302     var_set_integer("quickturn", 1, 0, 0);
    303     }
    304 
    305     if (SAL_BOOT_PLISIM) {
    306     var_set_integer("plisim", 1, 0, 0);
    307     }
    308 
    309 #ifdef ADAPTER_SERVER_MODE
    310     var_set_integer("cmodel", 1, 0, 0);
    311 #endif /* ADAPTER_SERVER_MODE */
    312 
    313     /*
    314      * Included packages
    315      */
    316 
    317 #ifdef INCLUDE_TCL
    318     var_set_integer("tcl", 1, 0, 0);
    319 #endif
    320 
    321 #ifdef INCLUDE_I2C
    322     var_set_integer("i2c", 1, 0, 0);
    323 #endif
    324 
    325 #ifdef INCLUDE_MACSEC
    326     var_set_integer("macsec", 1, 0, 0);
    327 #endif
    328 
    329 
    330     /*
    331      * Host type
    332      */
    333 
    334 #ifdef UNIX
    335     var_set_integer("unix", 1, 0, 0);
    336 #endif
    337 
    338 #ifdef BMW
    339     var_set_integer("bmw", 1, 0, 0);
    340     var_set("cpu", "bmw", FALSE, FALSE);
    341     if (sysIsCFM()) {
    342         char tmp[8];
    343         sal_sprintf(tmp, "cfm%d", sysSlotIdGet());
    344         var_set_integer(tmp, 1, 0, 0);
    345         var_set_integer("slot", sysSlotIdGet(), 0, 0);
    346         var_set_integer("cfm", 1, 0, 0);
    347     }
    348 #endif
    349 
    350 #ifdef MOUSSE
    351     var_set_integer("mousse", 1, 0, 0);
    352     var_set("cpu", "mousse", FALSE, FALSE);
    353 #endif
    354 
    355 #ifdef IDTRP334
    356     var_set_integer("idtrp334", 1, 0, 0);
    357     var_set("cpu", "idtrp334", FALSE, FALSE);
    358 #endif
    359 
    360 #ifdef IDT438
    361     var_set_integer("idt438", 1, 0, 0);
    362     var_set("cpu", "idt438", FALSE, FALSE);
    363 #endif
    364 
    365 #ifdef NSX
    366     var_set_integer("nsx", 1, 0, 0);
    367     var_set("cpu", "nsx", FALSE, FALSE);
    368 #endif
    369 
    370 #ifdef METROCORE
    371     var_set_integer("metrocore", 1, 0, 0);
    372     var_set("cpu", "metrocore", FALSE, FALSE);
    373 #endif
    374 
    375 #ifdef BCM_ICS
    376     var_set_integer("ics", 1, 0, 0);
    377     var_set("cpu", "ics", FALSE, FALSE);
    378 #endif
    379 
    380 #ifdef WR8548
    381     var_set_integer("wrsbc8548", 1, 0, 0);
    382     var_set("cpu", "wrsbc8548", FALSE, FALSE);
    383 #endif   
    384 
    385 #ifdef GTO 
    386     var_set_integer("gto", 1, 0, 0);
    387     var_set("cpu", "gto", FALSE, FALSE);
    388 #endif
    389 
    390 #if ((defined(__DUNE_GTO_BCM_CPU__) || defined(__DUNE_WRX_BCM_CPU__)) && !defined(PLISIM) && defined(BCM_PETRA_SUPPORT))
    391     {
    392         int mng_cpu;
    393         int slot;
    394         int val = 0;
    395 
    396         if (eeprom_read(NEGEV_CHASSIS_CARD_TYPE, NEGEV_CHASSIS_EEPROM_ADRESS_BOARD_TYPE,
    397                         NEGEV_CHASSIS_EEPROM_BYTE_SIZE_BOARD_TYPE, &val)==0){
    398             slot = sysSlotIdGet();
    399             if (slot >= 0) {
    400                 var_set_integer("slot", slot, 0, 0);
    401             }
    402             var_set_integer("board_type_GFA_BI", sysBoardTypeGfaBiGet(), 0, 0);
    403             var_set_integer("board_type_GFA_BI_2", sysBoardTypeGfaBi2Get(), 0, 0);
    404 
    405             /* managment card */
    406             mng_cpu = sys_board_type_mng_get();
    407             if (mng_cpu) {
    408                 var_set_integer("mng_cpu", mng_cpu, 0, 0);
    409             }
    410         }
    411     }
    412 
    413 #endif
    414 #ifdef KEYSTONE 
    415     var_set_integer("keystone", 1, 0, 0);
    416     var_set("cpu", "keystone", FALSE, FALSE);
    417 #endif
    418 
    419 #ifdef MBZ
    420     var_set_integer("mbz", 1, 0, 0);
    421     var_set("cpu", "mbz", FALSE, FALSE);
    422     if (sysIsLM()) {
    423         char tmp[8];
    424         sal_sprintf(tmp, "lm%d", sysSlotIdGet());
    425         var_set_integer(tmp, 1, 0, 0);
    426         var_set_integer("lm", 1, 0, 0);
    427         var_set_integer("slot", sysSlotIdGet(), 0, 0);
    428     }
    429 #endif
    430 }
    431 
    432 /*
    433  * Assertion routine with recovery for diag shell (see assert.h)
    434  */
    435 
    436 void
    437 _diag_assert(const char *expr, const char *file, int line)
    438 {
    439 
    440 #ifdef NO_SAL_APPL
    441 
    442     cli_out("ERROR: Assertion failed: (%s) at %s:%d\n", expr, file, line); 
    443     cli_out("DIAG SHELL HAS HALTED\n"); 
    444     for(;;); 
    445 
    446 #else
    447 
    448 #ifdef VXWORKS
    449     extern void sysReboot(void);
    450 # if defined(MOUSSE) || defined(BMW) || defined(GTO)
    451     extern void sysBacktracePpc(char *pfx, char *sfx, int direct);
    452 # elif defined(ZT6501)
    453     extern void sysBacktraceX86(char *pfx, char *sfx, int direct);
    454 # elif defined(IDTRP334) || defined(MBZ) || defined(IDT438) || defined(NSX) || defined(METROCORE) || defined(KEYSTONE)
    455     extern void sysBacktraceMips(char *pfx, char *sfx, int direct);
    456 # elif defined(IPROC)
    457     extern void sysBacktraceArm(char *pfx, char *sfx, int direct);
    458 # endif
    459     int         int_ctxt;
    460 #endif
    461     char        buf[80];
    462 
    463     cli_out("ERROR: Assertion failed: (%s) at %s:%d\n", expr, file, line);
    464 
    465 #ifdef UNIX
    466     /*
    467      * You can have assertion failures call abort() when you're in GDB
    468      * by adding the following to your ~/.gdbinit: set environment GDB 1
    469      */
    470 
    471     if (getenv("GDB")) {
    472     abort();
    473     }
    474 #endif
    475 
    476 #ifdef VXWORKS
    477     int_ctxt = sal_int_context();
    478 # if defined(MOUSSE) || defined(BMW) || defined(GTO)
    479     sysBacktracePpc("ERROR: Stack trace follows\n", "", int_ctxt);
    480 # elif defined(ZT6501)
    481     sysBacktraceX86("ERROR: Stack trace follows\n", "", int_ctxt);
    482 # elif defined(IDTRP334) || defined(MBZ) || defined(IDT438) || defined(NSX) || defined(METROCORE) || defined(KEYSTONE)
    483     sysBacktraceMips("ERROR: Stack trace follows\n", "", int_ctxt);
    484 # elif defined(IPROC)
    485     sysBacktraceArm("ERROR: Stack trace follows\n", "", int_ctxt);
    486 # endif
    487     if (int_ctxt) {
    488     sysReboot();
    489     }
    490 #endif /* VXWORKS */
    491 
    492     if (sal_thread_self() != sal_thread_main_get()) {
    493 #ifdef __KERNEL__
    494         sal_thread_exit(3);
    495 #else
    496     sal_abort();
    497 #endif
    498     }
    499 
    500 #ifdef NO_CTRL_C
    501     sal_readline("Press Enter if you wish to continue anyway ",
    502                  buf, sizeof (buf), NULL);
    503 #else
    504     /*
    505      * Allow user to continue or return to command prompt.
    506      */
    507 
    508     if (sal_readline("ERROR: Continue or quit (c/q)? ",
    509              buf, sizeof (buf), "q") == NULL ||
    510     toupper((int)buf[0]) != 'C') {
    511     sh_ctrl_c_take();
    512     } else
    513 #endif
    514     cli_out("WARNING: Correct behavior no longer guaranteed\n");
    515 
    516 #endif /* NO_SAL_APPL */
    517 }
    518 
    519 char cmd_assert_usage[] =
    520     "Parameters: None\n";
    521 
    522 cmd_result_t
    523 cmd_assert(int unit, args_t *a)
    524 {
    525 
    526     sal_assert_set(_diag_assert);
    527 
    528     assert((1 == 2));
    529 
    530     return CMD_OK;
    531 }
    532 
    533 
    534 #ifdef INCLUDE_TELNET
    535 
    536 int telnet_initted = 0;
    537 extern int sal_telnet_active;
    538 
    539 #define TELNET_SERVICE          23      /* telnet port number */
    540 
    541 /*
    542  * Note: assumes console is ttys0, you can use "sh & vx devs" cmds to
    543  * show
    544  */
    545 
    546 #define SYSLOG_CONSOLE(msg) {           \
    547     int _fd = open("/tyCo/0", O_RDWR, 0644);    \
    548     write(_fd, msg, sal_strlen(msg));       \
    549     close(_fd);                 \
    550 }
    551 
    552 extern BOOT_PARAMS  sysBootParams;  /* login parameters from boot line */
    553 
    554 
    555 /*
    556  * Workaround to set the STDIO file descriptors for all tasks equal to
    557  * that of the calling task.
    558  */
    559 
    560 #define TASKS_MAX       100
    561 
    562 void
    563 stdio_update(void)
    564 {
    565     int         tid_list[TASKS_MAX];
    566     int         std_in, std_out, std_err;
    567     int         i, count;
    568 
    569     count = taskIdListGet(tid_list, TASKS_MAX);
    570 
    571     std_in = ioTaskStdGet(0, STD_IN);
    572     std_out = ioTaskStdGet(0, STD_OUT);
    573     std_err = ioTaskStdGet(0, STD_ERR);
    574 
    575     for (i = 0; i < count; i++) {
    576     ioTaskStdSet(tid_list[i], STD_IN, std_in);
    577     ioTaskStdSet(tid_list[i], STD_OUT, std_out);
    578     ioTaskStdSet(tid_list[i], STD_ERR, std_err);
    579     }
    580 }
    581 
    582 /*
    583  * When the telnet service has completed, resume shell
    584  * processing on last used unit.
    585  */
    586 void
    587 diag_shell_restart(void)
    588 {
    589     SYSLOG_CONSOLE("Console unlocked\n");
    590 
    591     while (1) {
    592     sal_thread_main_set(sal_thread_self());
    593     stdio_update();
    594     sh_process(-1, "BCM", TRUE);
    595 #ifdef VXWORKS
    596     cli_out("Top level (use reset to reboot)\n");
    597 #else
    598     sal_reboot();
    599 #endif
    600     }
    601 }
    602 
    603 STATIC char *
    604 rdiag_readline(char *buf, int buf_size, int echo_off)
    605 {
    606     int ioOptions, savedOptions;
    607     int ptyFd = ioTaskStdGet(0,STD_IN);
    608     char *s;
    609 
    610     fflush(stdout);
    611 
    612     ioOptions = ioctl(ptyFd, FIOGETOPTIONS, 0);
    613     savedOptions = ioOptions;
    614     if (echo_off) {
    615     ioOptions &= ~OPT_ECHO;
    616     }
    617     ioOptions |= OPT_CRMOD;
    618     ioOptions &= ~OPT_TANDEM;
    619     ioOptions &= ~OPT_ABORT;    /* Will cause Interrupt even before login */
    620 
    621     (void)ioctl(ptyFd, FIOSETOPTIONS, ioOptions);
    622     s = fgets(buf, buf_size - 1, stdin);
    623     (void)ioctl(ptyFd, FIOSETOPTIONS, savedOptions);
    624 
    625     if (s == NULL) {
    626     return NULL;
    627     }
    628 
    629     buf[buf_size - 1] = 0;
    630 
    631     if ((s = sal_strchr(buf, '\n')) != NULL) {
    632     *s = 0;
    633     }
    634 
    635     return buf;
    636 }
    637 
    638 /*
    639  * When an inbound connection is established on either the onboard
    640  * ethernet or (if the socend driver is loaded) the front panel ports,
    641  * the telnet service will spawn this task.  This task will redirect
    642  * I/O to use the socket file descriptors, and then launch a new
    643  * diagnostics shell.  First, we query the user for username and
    644  * password and if this matches that set at the bootrom, it shuts down
    645  * the console while a remote connection is in progress by terminating
    646  * the first instance of the shell launched at startup.  It then
    647  * restarts the shell processing on the last attached unit.
    648  */
    649 STATUS
    650 rdiag_init(int interpConnArg,
    651        int slaveFd,
    652        int exitArg,
    653        int *disconnArg,
    654        char *msg)
    655 {
    656     char user[BOOT_USR_LEN];
    657     char pass[BOOT_PASSWORD_LEN];
    658 
    659 #ifdef MBZ
    660     if (sysIsLM()) {
    661     goto allow;
    662     }
    663 #endif
    664 
    665     if (sysBootParams.usr == NULL ||
    666     sysBootParams.passwd == NULL) {
    667     SYSLOG_CONSOLE("NOTICE: username and password not set.\n");
    668     goto allow;
    669     }
    670 
    671     printf("Broadcom StrataSwitch SDK\n");
    672     printf("%s VxWorks %s.\n", sysModel(), vxWorksVersion);
    673     /* Read and discard first line - telnet options */
    674     if (rdiag_readline(user, sizeof (user), FALSE) == NULL) {
    675     goto deny;
    676     }
    677     printf("\nlogin: ");
    678     if (rdiag_readline(user, sizeof (user), FALSE) == NULL) {
    679     goto deny;
    680     }
    681     printf("Password: ");
    682     if (rdiag_readline(pass, sizeof (pass), TRUE) == NULL) {
    683     goto deny;
    684     }
    685 
    686     if (!sal_strcmp(sysBootParams.usr, user) &&
    687     !sal_strcmp(sysBootParams.passwd, pass)) {
    688     SYSLOG_CONSOLE("Login succeeded for user ");
    689     SYSLOG_CONSOLE(user);
    690     SYSLOG_CONSOLE("\n");
    691     goto allow;
    692     }
    693 
    694  deny:
    695     printf("\nAccess denied.\n");
    696     fflush(stdout);
    697 
    698 #if VX_VERSION == 69
    699     telnetdExit((void *)slaveFd);
    700 #else
    701     telnetdExit(slaveFd);
    702 #endif
    703     return OK;
    704 
    705  allow:
    706     sal_telnet_active = 1;
    707     SYSLOG_CONSOLE("Console locked by remote.\n");
    708     if (taskNameToId("bcmCLI") != ERROR) {
    709     taskDeleteForce(taskNameToId("bcmCLI"));
    710     }
    711     if (taskNameToId("tShell") != ERROR) {
    712     taskDeleteForce(taskNameToId("tShell"));
    713     }
    714     printf("\nBroadcom Command Monitor (BCM) service started.\n");
    715     sal_thread_main_set(sal_thread_self());
    716     stdio_update();
    717     sal_readline_init();
    718     sh_print_version(FALSE);
    719     sh_process(-1, "BCM", TRUE);
    720 #if VX_VERSION == 69
    721     telnetdExit((void *)slaveFd);
    722 #else
    723     telnetdExit(slaveFd);
    724 #endif
    725     sal_readline_init();
    726     sal_thread_create("bcmCLI", 128 * 1024, SOC_CLI_THREAD_PRI,
    727               (VOIDFUNCPTR)diag_shell_restart, 0);
    728 
    729     return OK;
    730 }
    731 
    732 #endif /* INCLUDE_TELNET */
    733 
    734 /*
    735  * Early initialization.
    736  */
    737 
    738 void
    739 diag_init(void)
    740 {
    741     assert(sizeof (uint8) == 1);
    742     assert(sizeof (uint16) == 2);
    743     assert(sizeof (uint32) == 4);
    744     assert(sizeof (uint64) == 8);
    745 
    746     sal_assert_set(_diag_assert);
    747 
    748     sh_print_version(FALSE);
    749 
    750     init_symtab();
    751 
    752     sal_srand(1);   /* Seed random number generator: arbitrary value */
    753 
    754 #ifdef INCLUDE_TCL
    755     sal_homedir_get(bootdir, sizeof (bootdir));
    756 #endif
    757 
    758     gvar_init();
    759 
    760 #ifdef INCLUDE_TELNET
    761     /*
    762      * Load telnet server for users who may connect
    763      * from remote.
    764      */
    765     if (!telnet_initted) {
    766     /* Initialize TELNET Server */
    767     telnetInit(1); /* we allow network connections,
    768             * but not concurrently
    769             */
    770     telnetCallAdd("rBCM",
    771               TELNET_SERVICE,
    772               (FUNCPTR)rdiag_init, 0,
    773               SOC_CLI_THREAD_PRI, 0, 128 * 1024);
    774     telnet_initted++;
    775     cli_out("TELNET service started on TCP port 23.\n");
    776     }
    777 #endif /* INCLUDE_TELNET */
    778 
    779     sh_bg_init();
    780     DISPLAY_MEM ;
    781 
    782 } /* end diag_init() */
    783 
    784 /*
    785  * Function:
    786  *  parseEndOk
    787  * Purpose:
    788  *    Commonly used function used to parse up to the end of line.
    789  * Parameters:
    790  *    a     - arg type pointer
    791  *    pt    - parse table
    792  * Returns:
    793  *    TRUE -  success to parse
    794  *    FALSE - fail to parse
    795  * Notes:
    796  */
    797 
    798 int
    799 parseEndOk(args_t *a, parse_table_t *pt, cmd_result_t *retCode)
    800 {
    801     if (!ARG_CNT(a)) {  /* Display settings */
    802         cli_out("Current settings:\n");
    803         parse_eq_format(pt);
    804         parse_arg_eq_done(pt);
    805         *retCode = CMD_OK;
    806         return FALSE;
    807     }
    808 
    809     if (parse_arg_eq(a, pt) < 0 || ARG_CNT(a) > 0) {
    810         cli_out("%s: Error: Unknown option: %s\n", ARG_CMD(a), ARG_CUR(a));
    811         parse_arg_eq_done(pt);
    812         *retCode = CMD_FAIL;
    813         return FALSE;
    814     }
    815 
    816     parse_arg_eq_done(pt);
    817     *retCode = CMD_OK;
    818     return TRUE;
    819 }
    820 
    821 #ifdef PLISIM
    822 cmd_result_t
    823 cmd_txen(int unit, args_t *a)
    824 {
    825     if (SAL_BOOT_PLISIM) {
    826         if (!sh_check_attached(ARG_CMD(a), unit)) {
    827             return CMD_FAIL;
    828         }
    829 
    830         /* NOTE -- should take a portmap argument */
    831 
    832         if ((int)pli_tx_enable(unit, -1) < 0) {
    833             return CMD_FAIL;
    834         }
    835     }
    836     return CMD_OK;
    837 }
    838 
    839 cmd_result_t
    840 cmd_shutd(int unit, args_t *a)
    841 {
    842     if (SAL_BOOT_PLISIM) {
    843         if (!sh_check_attached(ARG_CMD(a), unit)) {
    844             return CMD_FAIL;
    845         }
    846 
    847         if ((int)pli_shutdown(unit) < 0) {
    848             return CMD_FAIL;
    849         }
    850     }
    851     return CMD_OK;
    852 }
    853 
    854 cmd_result_t
    855 cmd_simstart(int unit, args_t *a)
    856 {
    857     if (SAL_BOOT_PLISIM) {
    858         if (!sh_check_attached(ARG_CMD(a), unit)) {
    859             return CMD_FAIL;
    860         }
    861 
    862         if ((int)pli_sim_start(unit) < 0) {
    863             return CMD_FAIL;
    864         }
    865     }
    866     return CMD_OK;
    867 }
    868 #endif /* PLISIM */
    869 
    870 #ifdef INCLUDE_TCL
    871 /*
    872  * Run a TCL shell or TCL script
    873  */
    874 
    875 char **environ;
    876 
    877 char tcl_usage[] =
    878     "Parameters: [args ...]]\n\t"
    879     "If argument is not given, starts a TCL shell.\n\t"
    880     "Otherwise, executes a TCL with specified arguments, which may\n\t"
    881     "start with the name of a TCL script to run.\n";
    882 
    883 #define MAXENV      32
    884 
    885 cmd_result_t
    886 cmd_tcl(int unit, args_t *a)
    887 {
    888     char        **argv, **envp, **envnext, *c;
    889     char        **environ_save;
    890     char        *bootdir_asst;
    891     int         argc;
    892     extern int      tclsh(int argc, char **argv);
    893     int         rv;
    894     char        *bootFlags;
    895     const char  *bootTxt = "SOC_BOOT_FLAGS=";
    896     char        *bootFlagsVal;
    897     char        *c3SimPort;
    898     const char  *c3SimTxt = "SOC_TARGET_PORT=";
    899     char        *c3SimPortVal;
    900     char        *c3SimRunLongSystemTests;
    901     const char  *c3SimRunLongSystemTestsTxt = "RUN_LONG_SYSTEM_TESTS=";
    902     char        *c3SimRunLongSystemTestsVal;
    903 
    904     argv = sal_alloc((1 + ARG_CNT(a)) * sizeof (char *), "tcl_argv");
    905     envp = sal_alloc((1 + MAXENV    ) * sizeof (char *), "tcl_envp");
    906     bootdir_asst = sal_alloc(sal_strlen(bootdir) + 10, "tcl_bootdir");
    907     bootFlags = sal_alloc(sal_strlen(bootTxt) + 12, "tcl_bootflags");
    908     c3SimPort = sal_alloc(sal_strlen(c3SimTxt) + 8, "tcl_simPort");
    909     c3SimRunLongSystemTests  = sal_alloc(
    910             sal_strlen(c3SimRunLongSystemTestsTxt) + 8,
    911             "tcl_runLongSysTests");
    912 
    913     if (argv == NULL || envp == NULL || bootdir_asst == NULL
    914 	|| bootFlags == NULL || c3SimPort == NULL ||
    915     c3SimRunLongSystemTests == NULL) {
    916     cli_out("%s: Out of memory\n", ARG_CMD(a));
    917     rv = CMD_FAIL;
    918     goto done;
    919     }
    920 
    921     sal_sprintf(bootdir_asst, "BOOTDIR=%s", bootdir);
    922 
    923     envnext = envp;
    924     *envnext++ = "PATH=";
    925     *envnext++ = (SAL_BOOT_QUICKTURN ? "QUICKTURN=1" : "QUICKTURN=0");
    926     *envnext++ = (SAL_BOOT_PLISIM ? "PLISIM=1" : "PLISIM=0");
    927 #ifdef UNIX
    928     *envnext++ = "UNIX=1";
    929 #else
    930     *envnext++ = "UNIX=0";
    931 #endif
    932     *envnext++ = bootdir_asst;
    933 
    934 #ifdef ADAPTER_SERVER_MODE
    935     *envnext++ = "CMODEL=1";
    936 #else
    937     *envnext++ = "CMODEL=0";
    938 #endif /* ADAPTER_SERVER_MODE */
    939 
    940     bootFlagsVal = getenv("SOC_BOOT_FLAGS");
    941     if (bootFlagsVal != NULL)
    942       {
    943 	sal_sprintf(bootFlags, "%s%s", bootTxt, bootFlagsVal);
    944 	*envnext++ = bootFlags;
    945       }
    946 
    947     c3SimPortVal = getenv("SOC_TARGET_PORT");
    948     if (c3SimPortVal != NULL)
    949       {
    950 	sal_sprintf(c3SimPort, "%s%s", c3SimTxt, c3SimPortVal);
    951 	*envnext++ = c3SimPort;
    952       }
    953     c3SimPortVal = getenv("SOC_TARGET_PORT1");
    954     if (c3SimPortVal != NULL)
    955       {
    956 	sal_sprintf(c3SimPort, "%s%s", "SOC_TARGET_PORT1=", c3SimPortVal);
    957 	*envnext++ = c3SimPort;
    958       }
    959     c3SimRunLongSystemTestsVal = getenv("RUN_LONG_SYSTEM_TESTS");
    960     if (c3SimRunLongSystemTestsVal != NULL)
    961       {
    962         sal_sprintf(c3SimRunLongSystemTests, "%s%s",
    963             "RUN_LONG_SYSTEM_TESTS=", c3SimRunLongSystemTestsVal);
    964         *envnext++ = c3SimRunLongSystemTests;
    965       }
    966 
    967 #if defined(VXWORKS)
    968     {
    969         char path_str[256];
    970     extern STATUS   putenv (char *pEnvString);
    971 
    972         sal_strncpy(path_str, "TCL_LIBRARY", sal_strlen("TCL_LIBRARY") + 1);
    973         *envnext = var_get(path_str);
    974         if (*envnext != NULL) {
    975             strcat(path_str, "=");
    976             strcat(path_str, *envnext);
    977             putenv(path_str);
    978         }
    979         sal_strncpy(path_str, "TCL_PACKAGE_PATH", sal_strlen("TCL_PACKAGE_PATH") + 1);
    980         *envnext = var_get(path_str);
    981         if (*envnext != NULL) {
    982             strcat(path_str, "=");
    983             strcat(path_str, *envnext);
    984             putenv(path_str);
    985         }
    986     }
    987 #endif /* VXWORKS */
    988     *envnext = NULL;
    989 
    990     argc = 0;
    991 
    992     argv[argc++] = "./tcl";
    993 
    994     while ((c = ARG_GET(a)) != NULL) {
    995     argv[argc++] = c;
    996     }
    997 
    998     /*
    999      * Currently it is necessary to restart the environment on every TCL
   1000      * invocation.  This is because TCL may globally re-assign "environ"
   1001      * with memory it has allocated, which is freed when TCL exits.
   1002      */
   1003 
   1004     environ_save = environ;
   1005     environ = envp;
   1006 
   1007     rv = tclsh(argc, argv);
   1008      
   1009     /* Set console back to expected configuration. */
   1010 #if defined(VXWORKS)
   1011     sal_readline_init();
   1012 #endif
   1013 
   1014     environ = environ_save;
   1015 
   1016  done:
   1017     if (envp != NULL) {
   1018     sal_free(envp);
   1019     }
   1020 
   1021     if (argv != NULL) {
   1022     sal_free(argv);
   1023     }
   1024 
   1025     if (bootdir_asst != NULL) {
   1026     sal_free(bootdir_asst);
   1027     }
   1028 
   1029     if (bootFlags != NULL) {
   1030       sal_free(bootFlags);
   1031     }
   1032 
   1033     if (c3SimPort != NULL) {
   1034       sal_free(c3SimPort);
   1035     }
   1036 
   1037     if (c3SimRunLongSystemTests != NULL) {
   1038         sal_free(c3SimRunLongSystemTests);
   1039     }
   1040 
   1041 
   1042     return rv;
   1043 }
   1044 #endif /* INCLUDE_TCL */
   1045 
   1046 #if defined(MOUSSE) || defined(BMW) || defined(GTO)
   1047 /*
   1048  * System panic mode
   1049  */
   1050 
   1051 char panic_usage[] =
   1052     "Parameters: [ExcMessage=on|off] [BackTrace=on|off] [Reboot=on|off]\n\t"
   1053     "Sets VxWorks BSP panic mode.\n";
   1054 
   1055 cmd_result_t
   1056 cmd_panic(int unit, args_t *a)
   1057 {
   1058     extern int      sysToMonitorExcMessage;
   1059     extern int      sysToMonitorBacktrace;
   1060     extern int      sysToMonitorReboot;
   1061     parse_table_t   pt;
   1062 
   1063     COMPILER_REFERENCE(unit);
   1064 
   1065     if (ARG_CNT(a) == 0) {
   1066     return CMD_USAGE;
   1067     }
   1068 
   1069     parse_table_init(unit, &pt);
   1070     parse_table_add(&pt, "ExcMessage",  PQ_BOOL|PQ_DFL, 0,
   1071             &sysToMonitorExcMessage, NULL );
   1072     parse_table_add(&pt, "BackTrace",   PQ_BOOL|PQ_DFL, 0,
   1073             &sysToMonitorBacktrace, NULL );
   1074     parse_table_add(&pt, "Reboot",  PQ_BOOL|PQ_DFL, 0,
   1075             &sysToMonitorReboot, NULL );
   1076 
   1077     if (parse_arg_eq(a, &pt) < 0) {
   1078     cli_out("%s: Error: Invalid option: %s\n", ARG_CMD(a),
   1079             ARG_CUR(a) ? ARG_CUR(a) : "*");
   1080     parse_arg_eq_done(&pt);
   1081     return CMD_FAIL;
   1082     }
   1083     parse_arg_eq_done(&pt);
   1084 
   1085     return CMD_OK;
   1086 }
   1087 #endif /* MOUSSE || BMW || GTO */
   1088 
   1089 #ifdef INCLUDE_NFS
   1090 /*
   1091  * NFS Control (VxWorks only)
   1092  */
   1093 
   1094 /* Defined in sal/appl/vxworks/fileio.c */
   1095 extern int _diag_nfs_mounts;
   1096 
   1097 char cmd_nfs_usage[] =
   1098     "Parameters:\n\t"
   1099     "\texports <host> - Query a host's exported filesystems\n"
   1100     "\tauth <host> - Display authentication parameters\n"
   1101     "\tauth <host> <uid> [<gid> [<auth_gid> ...]] - Set auth parameters\n"
   1102     "\tmount <host>:<filesystem> <mountpoint> - Mount filesystem\n"
   1103     "\tunmount <mountpoint> - Unmount filesystem\n"
   1104     "\tmounts - Display currently mounted filesystems\n"
   1105     "\tNote: raw IP addresses may not work; see 'host' command to use names\n";
   1106 
   1107 cmd_result_t
   1108 cmd_nfs(int unit, args_t *a)
   1109 {
   1110     char        *subcmd;
   1111     char        *hostname, *mountpoint, *s;
   1112 
   1113     if ((subcmd = ARG_GET(a)) == NULL) {
   1114     return CMD_USAGE;
   1115     }
   1116 
   1117     if (!sal_strcasecmp(subcmd, "exports")) {
   1118     if ((hostname = ARG_GET(a)) == NULL) {
   1119         return CMD_USAGE;
   1120     }
   1121 
   1122     if (nfsExportShow(hostname) != OK) {
   1123         cli_out("nfsExportshow failed\n");
   1124         return CMD_FAIL;
   1125     }
   1126 
   1127     return CMD_OK;
   1128     }
   1129 
   1130     if (!sal_strcasecmp(subcmd, "auth")) {
   1131     int     uid, gid, ngids, i;
   1132     int     gids[MAX_GRPS];
   1133 
   1134     if ((hostname = ARG_GET(a)) == NULL) {
   1135         return CMD_USAGE;
   1136     }
   1137 
   1138     if ((s = ARG_GET(a)) == NULL) {
   1139         nfsAuthUnixGet(hostname, &uid, &gid, &ngids, gids);
   1140 
   1141         cli_out("Host:      %s\n", hostname);
   1142         cli_out("UID:       %d\n", uid);
   1143         cli_out("GID:       %d\n", gid);
   1144         cli_out("Auth GIDs:");
   1145 
   1146         for (i = 0; i < ngids; i++) {
   1147         cli_out(" %d", gids[i]);
   1148         }
   1149 
   1150         cli_out("\n");
   1151         return CMD_OK;
   1152     }
   1153 
   1154     uid = parse_integer(s);
   1155 
   1156     if ((s = ARG_GET(a)) == NULL) {
   1157         return CMD_USAGE;
   1158     }
   1159 
   1160     gid = parse_integer(s);
   1161 
   1162     ngids = 0;
   1163 
   1164     while ((s = ARG_GET(a)) != NULL) {
   1165         gids[ngids++] = parse_integer(s);
   1166     }
   1167 
   1168     nfsAuthUnixSet(hostname, uid, gid, ngids, gids);
   1169 
   1170     return CMD_OK;
   1171     }
   1172 
   1173     if (!sal_strcasecmp(subcmd, "mount")) {
   1174     char        *fs;
   1175 
   1176     if ((hostname = ARG_GET(a)) == NULL) {
   1177         return CMD_USAGE;
   1178     }
   1179 
   1180     if ((mountpoint = ARG_GET(a)) == NULL) {
   1181         return CMD_USAGE;
   1182     }
   1183 
   1184     if ((fs = sal_strchr(hostname, ':')) == NULL) {
   1185         return CMD_USAGE;
   1186     }
   1187 
   1188     *fs++ = 0;
   1189 
   1190     if (nfsMount(hostname, fs, mountpoint) != OK) {
   1191         cli_out("nfsMount failed\n");
   1192         return CMD_FAIL;
   1193     }
   1194 
   1195     _diag_nfs_mounts++;
   1196 
   1197     return CMD_OK;
   1198     }
   1199 
   1200     if (!sal_strcasecmp(subcmd, "unmount")) {
   1201     if ((mountpoint = ARG_GET(a)) == NULL) {
   1202         return CMD_USAGE;
   1203     }
   1204 
   1205     if (nfsUnmount(mountpoint) != OK) {
   1206         cli_out("nfsUnmount failed\n");
   1207         return CMD_FAIL;
   1208     }
   1209 
   1210     _diag_nfs_mounts--;
   1211 
   1212     return CMD_OK;
   1213     }
   1214 
   1215     if (!sal_strcasecmp(subcmd, "mounts")) {
   1216     nfsDevShow();
   1217     return CMD_OK;
   1218     }
   1219 
   1220     return CMD_USAGE;
   1221 }
   1222 
   1223 #endif /* INCLUDE_NFS */
   1224 
   1225 #ifdef INCLUDE_EDITLINE
   1226 /*
   1227  * Regsfile completion routines for command line editor
   1228  */
   1229 
   1230 int diag_list_possib_unit = -1;
   1231 
   1232 int
   1233 diag_list_possib(char *regpref, char ***avp)
   1234 {
   1235 #if  defined(BCM_ESW_SUPPORT)
   1236     soc_reg_t reg;
   1237     char **av;
   1238 #endif /* BCM_ESW_SUPPORT */
   1239     int ac = 0;
   1240     int unit = diag_list_possib_unit;
   1241 #if defined(BCM_ESW_SUPPORT)
   1242 #if !defined(SOC_NO_NAMES)
   1243     soc_field_t fld;
   1244 #endif /* !SOC_NO_NAMES */
   1245 #if !defined(SOC_NO_NAMES) || !defined(SOC_NO_ALIAS)
   1246     int len = sal_strlen(regpref);
   1247 #endif /* !SOC_NO_NAMES !SOC_NO_ALIAS */
   1248 #endif /* BCM_ESW_SUPPORT */
   1249 
   1250     COMPILER_REFERENCE(unit);
   1251 
   1252 #if defined(BCM_ESW_SUPPORT)
   1253 
   1254     av = SAL_ALLOC((NUM_SOC_REG + NUM_SOC_REG + NUM_SOC_FIELD) *
   1255            sizeof (char *));
   1256 
   1257     if (av == NULL) {
   1258     return 0;
   1259     }
   1260 
   1261     if (*regpref == 0 || unit < 0) {
   1262     sal_free(av);
   1263     return 0;
   1264     }
   1265 #endif  /* BCM_ESW_SUPPORT */
   1266 
   1267 #if defined(BCM_ESW_SUPPORT)
   1268     {
   1269         for (reg = 0; reg < (NUM_SOC_REG); reg++) {
   1270             if (SOC_REG_IS_VALID(unit, reg)) { /* Check name and alias */
   1271 #if !defined(SOC_NO_NAMES)
   1272                 if (!sal_strncasecmp(regpref, soc_reg_name[reg], len)) {
   1273                     av[ac++] = sal_strdup(soc_reg_name[reg]);
   1274                 }
   1275 #endif /* !SOC_NO_NAMES */
   1276     
   1277 #if !defined(SOC_NO_ALIAS)
   1278                 if (soc_reg_alias[reg] != NULL &&
   1279                     !sal_strncasecmp(regpref, soc_reg_alias[reg], len)) {
   1280                     av[ac++] = sal_strdup(soc_reg_alias[reg]);
   1281                 }
   1282 #endif /* !defined(SOC_NO_ALIAS) */
   1283             }
   1284         }
   1285 #if !defined(SOC_NO_NAMES)
   1286         for (fld = 0; fld < (NUM_SOC_FIELD); fld++) {
   1287             if (sal_strncasecmp(regpref, soc_fieldnames[fld], len) == 0) {
   1288                 av[ac++] = sal_strdup(soc_fieldnames[fld]);
   1289             }
   1290         }
   1291 #endif /* !SOC_NO_NAMES */        
   1292     }
   1293 #endif /* BCM_ESW_SUPPORT */
   1294 
   1295 #if defined(BCM_ESW_SUPPORT)
   1296     if (ac == 0) {
   1297         sal_free(av);
   1298     } else {
   1299         *avp = av;
   1300     }
   1301 #endif /* BCM_ESW_SUPPORT */
   1302 
   1303     return ac;
   1304 }
   1305 
   1306 char *
   1307 diag_complete(char *regpref, int *unique)
   1308 {
   1309     char *s;
   1310     int i, j, len, upcase, pfxlen, pfxmin;
   1311     char **av;
   1312     int ac;
   1313 
   1314     if ((ac = diag_list_possib(regpref, &av)) == 0) {
   1315     /*    coverity[leaked_storage : FALSE]    */
   1316     return 0;
   1317     }
   1318 
   1319     len = sal_strlen(regpref);
   1320     pfxmin = 0;
   1321     pfxlen = sal_strlen(av[0]);
   1322 
   1323     for (i = 1; i < ac; i++) {
   1324     /* Find length of common prefix of all matches */
   1325     for (j = 0; av[pfxmin][j] && av[i][j]; j++) {
   1326         if (av[pfxmin][j] != av[i][j]) {
   1327         break;
   1328         }
   1329     }
   1330 
   1331     if (j < pfxlen) {
   1332         pfxmin = i;
   1333         pfxlen = j;
   1334     }
   1335     }
   1336 
   1337     if (pfxlen < len) {
   1338     sal_free(av);
   1339     return 0;
   1340     }
   1341 
   1342     /* Generate completion.  Mimic case of input string. */
   1343     s = SAL_ALLOC(pfxlen - len + 1);
   1344 
   1345     if (s == NULL) {
   1346     sal_free(av);
   1347     return 0;
   1348     }
   1349 
   1350     upcase = isupper((unsigned) regpref[len - 1]);
   1351 
   1352     for (i = 0; i < pfxlen - len; i++) {
   1353     s[i] = upcase ? toupper((int)av[0][len + i]) : tolower((int)av[0][len + i]);
   1354     }
   1355 
   1356     s[i] = 0;
   1357 
   1358     *unique = (ac == 1);
   1359 
   1360     for (i = 0; i < ac; i++) {
   1361     sal_free(av[i]);
   1362     }
   1363     sal_free(av);
   1364 
   1365     return s;
   1366 }
   1367 #endif /* INCLUDE_EDITLINE */
   1368 
   1369 int diag_user_var_unit = -1;
   1370 
   1371 char *
   1372 diag_user_var_get(char *varname)
   1373 {
   1374     /* feature lookup */
   1375     if (strncmp(varname, "feature_", 8) == 0) {
   1376         soc_feature_t   f;
   1377 
   1378         if (diag_user_var_unit < 0) {
   1379             return NULL;
   1380         }
   1381 
   1382         for (f = 0; f < soc_feature_count; f++) {
   1383             if (sal_strcmp(varname + 8, soc_feature_name[f]) == 0) {
   1384                 if (soc_feature(diag_user_var_unit, f)) {
   1385                     return "1";
   1386                 }
   1387                 return NULL;
   1388             }
   1389         }
   1390         return NULL;
   1391     }
   1392 
   1393 #ifndef NO_SAL_APPL
   1394     /* config and property lookup */
   1395     if (diag_user_var_unit < 0) {
   1396         return sal_config_get(varname);
   1397     }
   1398 #endif
   1399 
   1400     return soc_property_get_str(diag_user_var_unit, varname);
   1401 }
   1402 
   1403 #if defined(INCLUDE_BCMX_DIAG)
   1404 
   1405 static void
   1406 _display_current_shell_mode(int unit)
   1407 {
   1408     char mode[5];
   1409 
   1410     switch (command_mode_get(unit)) {
   1411     case BCMX_CMD_MODE:
   1412         sal_strncpy(mode ,"BCMX", sizeof(mode));
   1413         break;
   1414     case ESW_CMD_MODE:
   1415         sal_strncpy(mode ,"ESW", sizeof(mode));
   1416         break;
   1417     }
   1418     sal_printf("Current mode is now %s\n", mode);
   1419 }
   1420 
   1421 char shell_mode_usage[] =
   1422   "\n    mode <m> where m is ESW or BCMX\n";
   1423 
   1424 /*
   1425  * Function:    if_mode
   1426  * Purpose: Set shell mode to BCM or BCMX
   1427  * Returns: CMD_USAGE/CMD_FAIL/CMD_OK.
   1428  */
   1429 cmd_result_t
   1430 cmd_mode(int unit, args_t *a)
   1431 {
   1432     char *subcmd;
   1433     int curr_mode;
   1434     int new_mode;
   1435 
   1436     if (unit < 0) {
   1437         sal_printf("Mode command failed. Invalid unit(-1) \n");
   1438         return CMD_FAIL;
   1439     }
   1440 
   1441     if ((subcmd = ARG_GET(a)) == NULL) { /* Swap modes. */
   1442 
   1443         curr_mode = command_mode_get(unit);
   1444         /*
   1445          * Cycle through modes.
   1446          *
   1447          * The following loop will go through all modes at most once
   1448          * because of the "new_mode != curr_mode" restriction below.
   1449          */
   1450         for (new_mode = curr_mode+1; new_mode != curr_mode; new_mode++) {
   1451             if (new_mode > DNXF_CMD_MODE) {
   1452                 /*
   1453                  * If the loop has gone beyond DNXF_CMD_MODE, which is
   1454                  * the last element in include/appl/diag/diag.h::
   1455                  * sh_cmd_mode_e, force it to be BCMX_CMD_MODE,
   1456                  * which is the first element in that enum.
   1457                  */
   1458                 new_mode = BCMX_CMD_MODE;
   1459             }
   1460             if (
   1461                 ((ESW_CMD_MODE == new_mode) && (!SOC_IS_ESW(unit)))) {
   1462                 /*
   1463                  * This mode is unsupported on the current device.
   1464                  * Let's try the next mode.
   1465                  */
   1466                 continue;
   1467             }
   1468             command_mode_set(unit, new_mode);
   1469             break;
   1470         }
   1471         
   1472     } else {
   1473         /* mode <m> */
   1474         if (sal_strcasecmp(subcmd, "BCMX") == 0) {
   1475             command_mode_set(unit, BCMX_CMD_MODE);
   1476         } else if ((sal_strcasecmp(subcmd, "ESW") == 0)) {
   1477             if (!SOC_IS_ESW(unit)) {
   1478                 sal_printf("ESW Mode is not supported on non-ESW devices \n");
   1479                 return CMD_USAGE;
   1480             }
   1481             command_mode_set(unit, ESW_CMD_MODE);
   1482         } else {
   1483             return CMD_USAGE;
   1484         }
   1485     }
   1486 
   1487     _display_current_shell_mode(unit);
   1488     return CMD_OK;
   1489 }
   1490 
   1491 char shell_bcmx_usage[] =
   1492   "\n    bcmx\n";
   1493 
   1494 /*
   1495  * Function:    cmd_mode_bcmx
   1496  * Purpose: Set shell mode to BCMX
   1497  * Returns: CMD_USAGE/CMD_FAIL/CMD_OK.
   1498  */
   1499 cmd_result_t
   1500 cmd_mode_bcmx(int unit, args_t *a)
   1501 {
   1502     command_mode_set(unit, BCMX_CMD_MODE);
   1503     _display_current_shell_mode(unit);
   1504     (void) a;
   1505     return CMD_OK;
   1506 }
   1507 
   1508 char shell_bcm_usage[] =
   1509   "\n    bcm\n";
   1510 
   1511 /*
   1512  * Function:    cmd_mode_bcm
   1513  * Purpose: Set shell mode to BCM
   1514  * Returns: CMD_USAGE/CMD_FAIL/CMD_OK.
   1515  */
   1516 
   1517 cmd_result_t
   1518 cmd_mode_bcm(int unit, args_t *a)
   1519 {
   1520     COMPILER_REFERENCE(a);
   1521 
   1522     if (unit < 0) {
   1523         sal_printf("Mode set failed. Invalid unit(-1) \n");
   1524         return CMD_FAIL;
   1525     }
   1526 
   1527     if (SOC_IS_ESW(unit)) {
   1528         command_mode_set(unit, ESW_CMD_MODE);
   1529     } else {
   1530         sal_printf("Unknown SOC device type\n");
   1531         return CMD_FAIL;
   1532     }
   1533     _display_current_shell_mode(unit);
   1534 
   1535     return CMD_OK;
   1536 }
   1537 
   1538 #endif
   1539 
   1540 #ifdef VXWORKS
   1541 char ping_usage[] =
   1542     "Parameters: <host> <count>\n\t"
   1543     "Pings a remote host.\n";
   1544 
   1545 cmd_result_t
   1546 cmd_ping(int u, args_t* a)
   1547 {
   1548     static  sal_mutex_t     ctrl_c_block = NULL;
   1549     static  char        *ping_host = NULL;
   1550     static  int         ping_cnt = 5;
   1551     char            *saved_host;
   1552     parse_table_t       pt;
   1553 
   1554     if (ctrl_c_block == NULL) {
   1555     ctrl_c_block = sal_mutex_create("ping");
   1556     }
   1557 
   1558     COMPILER_REFERENCE(u);
   1559 
   1560     saved_host = NULL;
   1561     if (ping_host != NULL) {
   1562     saved_host = sal_strdup(ping_host);
   1563     }
   1564     parse_table_init(u, &pt);
   1565     parse_table_add(&pt, "Host",    PQ_STRING|PQ_DFL, 0, &ping_host, 0);
   1566     parse_table_add(&pt, "Count",   PQ_INT|PQ_DFL, 0, &ping_cnt, 0);
   1567 
   1568 #ifndef VXWORKS_NETWORK_STACK_6_5
   1569     if (pingLibInit() != OK) {
   1570     cli_out("ERROR: pingLib not initialized.\n");
   1571     parse_arg_eq_done(&pt);
   1572     ping_host = saved_host;
   1573     return (CMD_FAIL);
   1574     }
   1575 #endif /* VXWORKS_NETWORK_STACK_6_5 */
   1576 
   1577     if (ARG_CNT(a) == 0) {      /* Just display */
   1578     cli_out("Current Configuration:\n");
   1579     parse_eq_format(&pt);
   1580     parse_arg_eq_done(&pt);
   1581     ping_host = saved_host;
   1582     return(CMD_OK);
   1583     }
   1584 
   1585     if (parse_arg_eq(a, &pt) < 0) {
   1586     cli_out("%s: Unknown option: %s\n", ARG_CMD(a), ARG_CUR(a));
   1587     parse_arg_eq_done(&pt);
   1588     ping_host = saved_host;
   1589     return(CMD_FAIL);
   1590     }
   1591 
   1592     if (ARG_CNT(a) > 0) {
   1593     if (ping_host != NULL) {
   1594         sal_free(ping_host);
   1595     }
   1596     ping_host = sal_strdup(ARG_GET(a));
   1597     }
   1598 
   1599     if (ping_host != NULL) {
   1600     if (saved_host != NULL) {
   1601         sal_free(saved_host);
   1602     }
   1603     saved_host = ping_host;
   1604     ping_host = NULL;
   1605     }
   1606     parse_arg_eq_done(&pt);
   1607     ping_host = saved_host;
   1608 
   1609     /*
   1610      * VxWorks ping starts a background task tPingTx<n> and then waits
   1611      * to receive up to ping_cnt packets.  If we allow Control-C, then
   1612      * the tPingTx<n> will continue to run indefinitely.  The only
   1613      * purpose of this mutex is to block Control-C.
   1614      */
   1615 
   1616     sal_mutex_take(ctrl_c_block, 1);
   1617     ping(ping_host, ping_cnt, 0);
   1618     sal_mutex_give(ctrl_c_block);
   1619 
   1620     /* Note: parse_arg_eq_done not called on static pt */
   1621 
   1622     return (CMD_OK);
   1623 }
   1624 
   1625 /* Eventually there should be a SAL interface for host tables */
   1626 
   1627 char if_host_usage[] =
   1628     "Manipulates the local host table\n"
   1629     "Parameters:\n\t"
   1630     "\tname [<host>] - Display or set current host name\n\t"
   1631     "\tshow - Display host table\n\t"
   1632     "\tadd <ip> <host> [<alias> ...] - Add entry to host table\n\t"
   1633     "\tdelete <host> <addr> - Delete entry from host table\n";
   1634 
   1635 cmd_result_t
   1636 if_host(int unit, args_t *a)
   1637 {
   1638     char           *subcmd, *hostname, *hostip, hostbuf[256];
   1639 
   1640     if ((subcmd = ARG_GET(a)) == NULL) {
   1641     return CMD_USAGE;
   1642     }
   1643 
   1644     if (! sal_strcasecmp(subcmd, "show")) {
   1645     hostShow();
   1646     return CMD_OK;
   1647     }
   1648 
   1649     if (! sal_strcasecmp(subcmd, "name")) {
   1650     if ((hostname = ARG_GET(a)) == NULL) {
   1651         gethostname(hostbuf, sizeof (hostbuf));
   1652         cli_out("%s\n", hostbuf);
   1653         return CMD_OK;
   1654     }
   1655 
   1656     if (sethostname(hostbuf, sal_strlen(hostbuf) + 1) != OK) {
   1657         cli_out("sethostname failed\n");
   1658         return CMD_FAIL;
   1659     }
   1660 
   1661     return CMD_OK;
   1662     }
   1663 
   1664     if (! sal_strcasecmp(subcmd, "add")) {
   1665     if ((hostname = ARG_GET(a)) == NULL) {
   1666         return CMD_USAGE;
   1667     }
   1668 
   1669     if ((hostip = ARG_GET(a)) == NULL) {
   1670         return CMD_USAGE;
   1671     }
   1672 
   1673     if (hostAdd(hostname, hostip) != OK) {
   1674         cli_out("hostAdd failed\n");
   1675         return CMD_FAIL;
   1676     }
   1677 
   1678     return CMD_OK;
   1679     }
   1680 
   1681     if (! sal_strcasecmp(subcmd, "delete")) {
   1682     if ((hostname = ARG_GET(a)) == NULL) {
   1683         return CMD_USAGE;
   1684     }
   1685 
   1686     if ((hostip = ARG_GET(a)) == NULL) {
   1687         return CMD_USAGE;
   1688     }
   1689 
   1690     if (hostDelete(hostname, hostip) != OK) {
   1691         cli_out("hostDelete failed\n");
   1692         return CMD_FAIL;
   1693     }
   1694 
   1695     return CMD_OK;
   1696     }
   1697 
   1698     return CMD_USAGE;
   1699 }
   1700 
   1701 #endif /* VXWORKS */
   1702 
   1703 
   1704 
   1705 /*
   1706  * API to allow overriding name of default RC script on a per-unit basis.
   1707  * Must be called before diag_shell().  If NULL is used (default), then
   1708  * default init script SOC_INIT_RC is used.  If the empty string is used,
   1709  * no script will be loaded.
   1710  */
   1711 
   1712 #ifndef NO_SAL_APPL
   1713 
   1714 void
   1715 diag_rc_set(int unit, const char *fname)
   1716 {
   1717     assert(unit >= 0 && unit < SOC_MAX_NUM_DEVICES);
   1718     if ((unit < 0) || (unit >= SOC_MAX_NUM_DEVICES)) {
   1719         return;
   1720     }
   1721 
   1722     if (soc_init_rc[unit] != NULL) {
   1723     sal_free(soc_init_rc[unit]);
   1724     soc_init_rc[unit] = NULL;
   1725     }
   1726 
   1727     if (fname != NULL) {
   1728     soc_init_rc[unit] = sal_strdup(fname);
   1729     }
   1730 }
   1731 
   1732 void
   1733 diag_rc_get(int unit, const char **fname)
   1734 {
   1735     assert(unit >= 0 && unit < SOC_MAX_NUM_DEVICES);
   1736     if ((unit < 0) || (unit >= SOC_MAX_NUM_DEVICES)) {
   1737         return;
   1738     }
   1739 
   1740     *fname = (soc_init_rc[unit] != NULL ?
   1741           soc_init_rc[unit] :
   1742           SOC_INIT_RC);
   1743 }
   1744 
   1745 int
   1746 diag_rc_load(int unit)
   1747 {
   1748     char    *script = (soc_init_rc[unit] != NULL ?
   1749                soc_init_rc[unit] : SOC_INIT_RC);
   1750 
   1751     if (script[0] == 0) {
   1752     return CMD_OK;
   1753     } else {
   1754     return sh_rcload_file(unit, NULL, script, FALSE);
   1755     }
   1756 }
   1757 #endif /* NO_SAL_APPL */
   1758 
   1759 /*
   1760  * Diagnostics shell routine.
   1761  */
   1762 
   1763 #ifdef BCM_WARM_BOOT_SUPPORT
   1764 #if defined(BCM_ESW_SUPPORT) || defined(BCM_SAND_SUPPORT)
   1765 STATIC int
   1766 scache_read_dummy_func(int unit, uint8 *buf, int offset, int nbytes)
   1767 {
   1768     return SOC_E_RESOURCE;
   1769 }
   1770 
   1771 STATIC int
   1772 scache_write_dummy_func(int unit, uint8 *buf, int offset, int nbytes)
   1773 {
   1774     return SOC_E_RESOURCE;
   1775 }
   1776 #endif /* BCM_ESW_SUPPORT || defined(BCM_SAND_SUPPORT) */
   1777 #endif /* BCM_WARM_BOOT_SUPPORT */
   1778 
   1779 void
   1780 diag_shell(void)
   1781 {
   1782     uint32  flags;
   1783 #ifndef NO_SAL_APPL
   1784     char    *script;
   1785     int     no_rc_warning = 1; 
   1786 #endif
   1787     int i; 
   1788     int         rv = BCM_E_NONE;
   1789 #ifdef BCM_WARM_BOOT_SUPPORT
   1790 #if defined(BCM_ESW_SUPPORT) || defined(BCM_SAND_SUPPORT)
   1791     int     warm_boot = FALSE;
   1792     int     stable_location = BCM_SWITCH_STABLE_NONE;
   1793     uint32  stable_flags = 0;
   1794     uint32  stable_size = 0;
   1795     char    *stable_filename = NULL;
   1796 #endif /* BCM_ESW_SUPPORT || defined(BCM_SAND_SUPPORT) */
   1797 #endif /* BCM_WARM_BOOT_SUPPORT */
   1798 #if defined(BCM_EASY_RELOAD_SUPPORT) || defined(BCM_EASY_RELOAD_WB_COMPAT_SUPPORT)
   1799 #if defined(BCM_DFE_SUPPORT) || defined(BCM_DNXF_SUPPORT)
   1800     int easy_reload = FALSE;
   1801 #endif
   1802 #endif
   1803 #ifdef INCLUDE_CUSTOMER
   1804     extern int custom_cmd(int unit);
   1805 #endif
   1806     SHR_BPROF_STATS_DECL;
   1807 
   1808     sal_thread_main_set(sal_thread_self());
   1809 
   1810 #if defined(INCLUDE_EDITLINE) 
   1811     sal_readline_config(diag_complete, diag_list_possib);
   1812 #endif /* INCLUDE_EDITLINE */
   1813 
   1814     parse_user_var_get = diag_user_var_get;
   1815 
   1816     bslmgmt_init();
   1817 
   1818     diag_init();
   1819 
   1820     sysconf_init();
   1821 
   1822     /*
   1823      * At boot time, probe for devices and attach the first one.
   1824      * In PLISIM, this is not done; the probe and attach commands
   1825      * must be given explicitly.
   1826      */
   1827     flags = sal_boot_flags_get();
   1828 
   1829     if (!(flags & BOOT_F_NO_PROBE)) {
   1830         SHR_BPROF_STATS_TIME(SHR_BPROF_SOC_PROBE) {
   1831             if ((sysconf_probe()) < 0) {
   1832                 cli_out("ERROR: PCI SOC device probe failed\n");
   1833             }
   1834         }
   1835 
   1836         var_set_integer("units", soc_ndev, FALSE, FALSE);
   1837 
   1838         if (!(flags & BOOT_F_NO_ATTACH)) {
   1839             for (i = 0; i < soc_all_ndev; i++) {
   1840                 SHR_BPROF_STATS_TIME(SHR_BPROF_SOC_ATTACH) {
   1841                     /* coverity[stack_use_callee] */
   1842                     /* coverity[stack_use_overflow] */
   1843                     rv = sysconf_attach(i);
   1844                 }
   1845 #if defined(BCM_ESW_SUPPORT)
   1846                 if (rv == 0) {
   1847                     if (SOC_IS_ESW(i)) {
   1848                         mem_watch_counter_init(i);
   1849                         mem_watch_start(i);
   1850                     }
   1851                 }
   1852 #endif /* BCM_ESW_SUPPORT */
   1853                 if (rv < 0) {
   1854                     cli_out("ERROR: SOC unit %d attach failed\n", i);
   1855                 }
   1856             } /* for */
   1857         } else {
   1858         cli_out("Boot flags: Attach NOT performed\n");
   1859     }
   1860     } else {
   1861         cli_out("Boot flags: Probe NOT performed\n");
   1862     }
   1863 
   1864     cmdlist_init();
   1865 
   1866 #if defined(BCM_EASY_RELOAD_SUPPORT) || defined(BCM_EASY_RELOAD_WB_COMPAT_SUPPORT)
   1867 #if defined(BCM_DFE_SUPPORT) || defined(BCM_DNXF_SUPPORT)
   1868     if (flags & BOOT_F_RELOAD) {
   1869       cli_out("Boot flags: Easy Reload\n");
   1870       easy_reload = TRUE;
   1871 
   1872       for (i = 0; i < soc_ndev; i++) {
   1873         SOC_RELOAD_MODE_SET(SOC_NDEV_IDX2DEV(i), TRUE);        
   1874       }
   1875     } else {
   1876       cli_out("Boot flags: regular load\n");
   1877       for (i = 0; i < soc_ndev; i++) {
   1878         SOC_RELOAD_MODE_SET(SOC_NDEV_IDX2DEV(i), FALSE);
   1879       }
   1880     }
   1881 #endif
   1882 #endif
   1883 
   1884 
   1885 #ifdef BCM_WARM_BOOT_SUPPORT
   1886 #if defined(BCM_ESW_SUPPORT) || defined(BCM_SAND_SUPPORT)
   1887 
   1888     /* For Fastboot, use warmboot, but cold boot most modules except
   1889      * pcix, cmic, port, serdes */
   1890     if (flags & BOOT_F_FAST_REBOOT) {
   1891         cli_out("Boot flags: Fast reboot\n");
   1892 
   1893         flags |= BOOT_F_WARM_BOOT;
   1894 
   1895         for (i = 0; i < soc_ndev; i++) {
   1896             SOC_FAST_REBOOT_START(SOC_NDEV_IDX2DEV(i));
   1897 #ifndef NO_SAL_APPL
   1898             diag_rc_set(SOC_NDEV_IDX2DEV(i), "freboot.soc");
   1899 #endif
   1900         }
   1901     }
   1902 
   1903     if (flags & BOOT_F_WARM_BOOT) {
   1904         cli_out("Boot flags: Warm boot\n");
   1905         warm_boot = TRUE;
   1906 
   1907         for (i = 0; i < soc_ndev; i++) {
   1908             SOC_WARM_BOOT_START(SOC_NDEV_IDX2DEV(i));
   1909 #ifndef NO_SAL_APPL
   1910             if (!SOC_FAST_REBOOT(SOC_NDEV_IDX2DEV(i))) {
   1911                 diag_rc_set(SOC_NDEV_IDX2DEV(i), "reload.soc");
   1912             }
   1913 #endif
   1914         }
   1915     } else {
   1916         cli_out("Boot flags: Cold boot\n");
   1917         for (i = 0; i < soc_ndev; i++) {
   1918             SOC_WARM_BOOT_DONE(SOC_NDEV_IDX2DEV(i));
   1919             SOC_FAST_REBOOT_DONE(SOC_NDEV_IDX2DEV(i));
   1920         }
   1921     }
   1922 
   1923     for (i = 0; i < soc_ndev; i++) {
   1924         stable_filename = soc_property_get_str(SOC_NDEV_IDX2DEV(i), spn_STABLE_FILENAME);
   1925 
   1926         if ((NULL == stable_filename) &&
   1927                    (stable_filename =
   1928                     soc_property_get_str(SOC_NDEV_IDX2DEV(i), "scache_filename"))) {
   1929             stable_location = _SHR_SWITCH_STABLE_APPLICATION;
   1930             stable_flags = 0;
   1931             stable_size = SOC_DEFAULT_LVL2_STABLE_SIZE;
   1932             if ((SOC_CONTROL(SOC_NDEV_IDX2DEV(i)) != NULL) &&
   1933                 soc_feature(SOC_NDEV_IDX2DEV(i), soc_feature_ser_parity) &&
   1934                 soc_property_get(SOC_NDEV_IDX2DEV(i), "memcache_in_scache", 0)) {
   1935                 if (SOC_IS_TD2_TT2(SOC_NDEV_IDX2DEV(i))) {
   1936                     uint16 dev_id;
   1937                     uint8  rev_id;
   1938                     soc_cm_get_id(SOC_NDEV_IDX2DEV(i), &dev_id, &rev_id);
   1939                     if (dev_id == BCM56830_DEVICE_ID) {
   1940                         stable_size *= 20;
   1941                     } else {
   1942                         stable_size *= 12;
   1943                     }
   1944                 } else if (SOC_IS_TRIUMPH3(SOC_NDEV_IDX2DEV(i))) {
   1945                     stable_size *= 30;
   1946                 } else if (SOC_IS_TD_TT(SOC_NDEV_IDX2DEV(i))) {
   1947                     stable_size *= 14;
   1948                 } else {
   1949                     stable_size *= 16;
   1950                 }
   1951             }
   1952 
   1953             if ((SOC_CONTROL(SOC_NDEV_IDX2DEV(i)) != NULL) &&
   1954                SOC_IS_TOMAHAWKX(SOC_NDEV_IDX2DEV(i))) {
   1955                stable_size = 85 * 1024 * 1024;
   1956             }
   1957 
   1958             if ((SOC_CONTROL(SOC_NDEV_IDX2DEV(i)) != NULL) &&
   1959                SOC_IS_TRIDENT3X(SOC_NDEV_IDX2DEV(i))) {
   1960                stable_size += 50 * 1024 * 1024;
   1961                if (SOC_IS_HELIX5(SOC_NDEV_IDX2DEV(i))) {
   1962                /* Add additional storage space for HX5 Broadscan */
   1963                stable_size += 5 * 1024 * 1024;
   1964                }
   1965             }
   1966 
   1967             /* Recently increased field scache size to push more data. VERSION_1_15 */
   1968             if ((SOC_CONTROL(SOC_NDEV_IDX2DEV(i)) != NULL) &&
   1969                SOC_IS_TD_TT(SOC_NDEV_IDX2DEV(i))) {
   1970 
   1971                 if (SOC_IS_APACHE(SOC_NDEV_IDX2DEV(i))) {
   1972                     /* Default scache size 7MB is needed for apache family */
   1973                     stable_size += 4 * 1024 * 1024;
   1974                 } else if (SOC_IS_TRIDENT2X(SOC_NDEV_IDX2DEV(i))) {
   1975                     /* Default scache size 16MB is needed for trident2x */
   1976                     stable_size += 13 * 1024 * 1024;
   1977                 } else {
   1978                     stable_size += 135 * 1024;
   1979                 }
   1980 
   1981             }
   1982 
   1983             if ((SOC_CONTROL(SOC_NDEV_IDX2DEV(i)) != NULL) &&
   1984                 SOC_IS_TRIUMPH3(SOC_NDEV_IDX2DEV(i))) {
   1985                 stable_size += 2 * 1024 * 1024;
   1986             }
   1987 
   1988             /* Default scache size 6MB is needed */
   1989             if ((SOC_CONTROL(SOC_NDEV_IDX2DEV(i)) != NULL) &&
   1990                 SOC_IS_GREYHOUND2(SOC_NDEV_IDX2DEV(i))) {
   1991                 stable_size += 3 * 1024 * 1024;
   1992             }
   1993         }
   1994 
   1995         stable_location = soc_property_get(SOC_NDEV_IDX2DEV(i), spn_STABLE_LOCATION,
   1996                                            stable_location);
   1997 
   1998 #if (!defined(BCM_PETRA_SUPPORT) && !defined(BCM_DNX_SUPPORT)) || defined(__KERNEL__) || (!defined (LINUX) && !defined(UNIX))
   1999         if (stable_location == _SHR_SWITCH_STABLE_SHARED_MEM) {
   2000             stable_location =  _SHR_SWITCH_STABLE_APPLICATION;
   2001             cli_out(
   2002                "Unit %d: soc property stable_location=4 is only supported with\n"
   2003 			   "    (BCM_PETRA_SUPPORT || BCM_DNX_SUPPORT) && !__KERNEL__ && (LINUX || UNIX) compilation\n "
   2004 			   "    falling back to stable_location=3\n",
   2005                SOC_NDEV_IDX2DEV(i));
   2006         }
   2007 #endif
   2008 #ifdef BCM_WARM_BOOT_API_TEST
   2009 #ifndef BCM_WARM_BOOT_API_TEST_AUTOSYNC
   2010 #if !defined(BCM_DNX_SUPPORT) && !defined(BCM_DNXF_SUPPORT)
   2011         
   2012         stable_location =  _SHR_SWITCH_STABLE_SHARED_MEM;
   2013 #endif
   2014 #endif
   2015 #endif
   2016 
   2017         if (BCM_SWITCH_STABLE_NONE != stable_location) {
   2018             /* Otherwise, nothing to do */
   2019             stable_flags = soc_property_get(SOC_NDEV_IDX2DEV(i), spn_STABLE_FLAGS,
   2020                                             stable_flags);
   2021             stable_size = soc_property_get(SOC_NDEV_IDX2DEV(i), spn_STABLE_SIZE,
   2022                                            stable_size);
   2023 
   2024             if ((BCM_SWITCH_STABLE_APPLICATION == stable_location) &&
   2025                 (NULL != stable_filename)) {
   2026 #if (defined(LINUX) && !defined(__KERNEL__)) || defined(UNIX)
   2027                 /* Try to open the scache file */
   2028                 if (appl_scache_file_open(SOC_NDEV_IDX2DEV(i), (flags & BOOT_F_WARM_BOOT) ?
   2029                                           TRUE : FALSE,
   2030                                           stable_filename) < 0) {
   2031                     cli_out("Unit %d: stable cache file not %s\n", SOC_NDEV_IDX2DEV(i),
   2032                             (flags & BOOT_F_WARM_BOOT) ?
   2033                             "recovered" : "created");
   2034 
   2035                     /* Fall back to Level 1 Warm Boot */
   2036                     stable_location = BCM_SWITCH_STABLE_NONE;
   2037                     stable_size = 0;
   2038                 }
   2039 
   2040 #else /* (defined(LINUX) && !defined(__KERNEL__)) || defined(UNIX) */
   2041                 cli_out("Build-in stable cache file not supported in this configuration\n");
   2042                 /* Use Level 1 Warm Boot instead*/
   2043                 stable_location = BCM_SWITCH_STABLE_NONE;
   2044                 stable_size = 0;
   2045 #endif /* (defined(LINUX) && !defined(__KERNEL__)) || defined(UNIX) */
   2046            }
   2047 #ifdef BCM_PETRA_SUPPORT
   2048            else if (BCM_SWITCH_STABLE_DEVICE_EXT_MEM == stable_location) {
   2049                if (appl_scache_user_buffer(SOC_NDEV_IDX2DEV(i))) {
   2050                    cli_out("Unit %d: error when initializing user buffer", SOC_NDEV_IDX2DEV(i));
   2051 
   2052                    /* Fall back to Level 1 Warm Boot */
   2053                    stable_location = BCM_SWITCH_STABLE_NONE;
   2054                    stable_size = 0;
   2055                }
   2056             }
   2057 #endif /* BCM_PETRA_SUPPORT */
   2058 
   2059             if (soc_stable_set(SOC_NDEV_IDX2DEV(i), stable_location, stable_flags) < 0) {
   2060                 cli_out("Unit %d: soc_stable_set failure\n", SOC_NDEV_IDX2DEV(i));
   2061             } else if (soc_stable_size_set(SOC_NDEV_IDX2DEV(i), stable_size) < 0) {
   2062                 cli_out("Unit %d: soc_stable_size_set failure\n", SOC_NDEV_IDX2DEV(i));
   2063             }
   2064 
   2065 #if defined(BCM_PETRA_SUPPORT) || defined(BCM_DNX_SUPPORT) || defined(BCM_DNXF_SUPPORT)
   2066             /* Verify that provided scache is from an allowed version */
   2067             if (flags & BOOT_F_WARM_BOOT &&
   2068                 (SOC_IS_ARAD(SOC_NDEV_IDX2DEV(i)) ||
   2069                      SOC_IS_DNX(SOC_NDEV_IDX2DEV(i)) ||
   2070                      SOC_IS_DNXF(SOC_NDEV_IDX2DEV(i)))) {
   2071                 if (soc_stable_size_set(SOC_NDEV_IDX2DEV(i), stable_size)) {
   2072                     cli_out("Unit %d: soc_stable_size_set failed. stable_size=%d\n", SOC_NDEV_IDX2DEV(i), stable_size);
   2073                 }                    
   2074 
   2075                 if (soc_scache_recover(SOC_NDEV_IDX2DEV(i))) {
   2076                     cli_out("Unit %d: soc_scache_recover failed\n", SOC_NDEV_IDX2DEV(i));
   2077                 }
   2078             }
   2079 #endif /* defined(BCM_PETRA_SUPPORT) || defined(BCM_DNX_SUPPORT) || defined(BCM_DNXF_SUPPORT) */
   2080 
   2081             if (1 == soc_property_get(SOC_NDEV_IDX2DEV(i),
   2082                         spn_WARMBOOT_EVENT_HANDLER_ENABLE, 0)) {
   2083                 if (soc_event_register(SOC_NDEV_IDX2DEV(i),
   2084                         appl_warm_boot_event_handler_cb, NULL) < 0) {
   2085                     cli_out("Unit %d: soc_event_register failure\n", SOC_NDEV_IDX2DEV(i));
   2086                 }
   2087             }
   2088         } else {
   2089 
   2090             
   2091             /* EMPTY SCACHE INITIALIZATION ->
   2092                in case stable_* parameters are not defined in configuration file, 
   2093                initiating scache with size 0(zero). in order that scache commits 
   2094                wont fail and cause application exit upon startup */
   2095             if (soc_switch_stable_register(SOC_NDEV_IDX2DEV(i),
   2096                                            &scache_read_dummy_func,
   2097                                            &scache_write_dummy_func,
   2098                                            NULL, NULL) < 0) {
   2099                 cli_out("Unit %d: soc_switch_stable_register failure\n", SOC_NDEV_IDX2DEV(i));
   2100             }
   2101 
   2102             stable_location = BCM_SWITCH_STABLE_NONE;
   2103             stable_size     = 0;
   2104             stable_flags    = 0;
   2105 
   2106             if (soc_stable_set(SOC_NDEV_IDX2DEV(i), stable_location, stable_flags) < 0) {
   2107                 cli_out("Unit %d: soc_stable_set failure\n", SOC_NDEV_IDX2DEV(i));
   2108             } else if (soc_stable_size_set(SOC_NDEV_IDX2DEV(i), stable_size) < 0) {
   2109                 cli_out("Unit %d: soc_stable_size_set failure\n", SOC_NDEV_IDX2DEV(i));
   2110             }
   2111             /* <- EMPTY SCACHE INITIALIZATION */
   2112 
   2113             /* Treat all virtual ports as MIM for Level 1 */
   2114             SOC_WARM_BOOT_MIM(SOC_NDEV_IDX2DEV(i));
   2115         }
   2116 
   2117 #if defined(BCM_SAND_SUPPORT)
   2118         if (SOC_IS_SAND(SOC_NDEV_IDX2DEV(i))){
   2119             if (bsldnx_mgmt_init(SOC_NDEV_IDX2DEV(i)) < 0) {
   2120                 cli_out("Unit %d: bslmgmt_dnx_init failure\n", SOC_NDEV_IDX2DEV(i));
   2121             }
   2122         }
   2123 #endif
   2124     }
   2125 #endif /* BCM_ESW_SUPPORT || BCM_SAND_SUPPORT) */
   2126 #endif /* BCM_WARM_BOOT_SUPPORT */
   2127 
   2128 #ifndef NO_SAL_APPL
   2129     /* Add backdoor for mem tuner to update system configuration */
   2130     soc_mem_config_set = sal_config_set;
   2131 
   2132     /*
   2133      * If a startup script is given in the boot parameters, attempt to
   2134      * load it.  This script is for general system configurations such
   2135      * as host table additions and NFS mounts.
   2136      */
   2137 
   2138     if ((script = sal_boot_script()) != NULL) {
   2139         if (sh_rcload_file(-1, NULL, script, FALSE) != CMD_OK) {
   2140             cli_out("ERROR loading boot init script: %s\n", script);
   2141         }
   2142         
   2143         no_rc_warning = 0;
   2144      }
   2145     
   2146     /*
   2147      * If a default init file is given, attempt to load it.
   2148      */
   2149 
   2150     if (!(flags & BOOT_F_NO_RC)) {
   2151         for (i = 0; i < soc_ndev; i++) {
   2152             if (soc_attached(SOC_NDEV_IDX2DEV(i))) {
   2153                 sh_swap_unit_vars(SOC_NDEV_IDX2DEV(i));
   2154                 if (SOC_IS_RCPU_ONLY(SOC_NDEV_IDX2DEV(i))) {
   2155                     /* Wait for master unit to establish link */
   2156                     sal_sleep(3);
   2157                 }
   2158                 if (diag_rc_load(SOC_NDEV_IDX2DEV(i)) != CMD_OK) {
   2159                     cli_out("ERROR loading rc script on unit %d\n", SOC_NDEV_IDX2DEV(i));
   2160                 }
   2161             }
   2162         }
   2163     } else if (no_rc_warning) {
   2164         cli_out("Boot flags: initialization scripts NOT loaded\n");
   2165     }
   2166 
   2167 
   2168     if (soc_ndev <= 0) {
   2169         cli_out("No attached units.\n");
   2170     }
   2171 
   2172 #endif /* NO_SAL_APPL */
   2173 
   2174 
   2175 #ifndef BCM_WARM_BOOT_API_TEST_AUTOSYNC
   2176 #ifndef BCM_WARM_BOOT_API_TEST
   2177 #ifdef BCM_WARM_BOOT_SUPPORT
   2178 #if defined(BCM_ESW_SUPPORT) || defined(BCM_SAND_SUPPORT)
   2179     if (warm_boot) {
   2180         /* Warm boot is done, clear reloading state */
   2181         for (i = 0; i < soc_ndev; i++) {
   2182             SOC_WARM_BOOT_DONE(SOC_NDEV_IDX2DEV(i));
   2183             SOC_FAST_REBOOT_DONE(SOC_NDEV_IDX2DEV(i));
   2184         }
   2185     }
   2186 #endif /* BCM_ESW_SUPPORT || defined(BCM_SAND_SUPPORT) */
   2187 #endif /* BCM_WARM_BOOT_SUPPORT */
   2188 #endif /* BCM_WARM_BOOT_API_TEST */
   2189 #else
   2190     /* If "BCM_WARM_BOOT_API_TEST_AUTOSYNC" is defined, "warm_boot" in this function
   2191      * will not be referenced, which leads to compilation warnings. Add a dummy
   2192      * referencing code below to suppress it.
   2193      */
   2194     if(warm_boot){}
   2195 #endif /* BCM_WARM_BOOT_API_TEST_AUTOSYNC */
   2196 
   2197 #if defined(BCM_EASY_RELOAD_SUPPORT) || defined(BCM_EASY_RELOAD_WB_COMPAT_SUPPORT)
   2198 #if defined(BCM_DFE_SUPPORT) || defined(BCM_DNXF_SUPPORT)
   2199     if (easy_reload) {
   2200         for (i = 0; i < soc_ndev; i++) 
   2201         {
   2202             /* reload is done, clear reloading state, if user wants to call apis
   2203                without affecting the Hw its his responsibility to set the reload mode back to true */
   2204             SOC_RELOAD_MODE_SET(SOC_NDEV_IDX2DEV(i), FALSE);        
   2205         }    
   2206     }
   2207 #endif
   2208 #endif
   2209 
   2210 #ifdef BCM_DIAG_SHELL_CUSTOM_INIT_F
   2211     {
   2212         /* Call custom init function prior to entering input loop */
   2213         extern int BCM_DIAG_SHELL_CUSTOM_INIT_F (void); 
   2214         BCM_DIAG_SHELL_CUSTOM_INIT_F (); 
   2215     }      
   2216 #endif /* BCM_DIAG_SHELL_CUSTOM_INIT_F */
   2217 
   2218 #if (defined(INCLUDE_CUSTOMER) && !defined(__KERNEL__))
   2219     /* Add custom commands */
   2220     for (i = 0; i < soc_ndev; i++)
   2221     {
   2222         (void) custom_cmd(SOC_NDEV_IDX2DEV(i));
   2223     }
   2224 #endif
   2225 
   2226     DISPLAY_MEM ;
   2227     DISPLAY_SW_STATE_MEM ;
   2228     DISPLAY_MEM_PRINTF(("%s(): Just before BCM shell\r\n",__FUNCTION__)) ;
   2229 
   2230     while (1) {
   2231     sh_process(-1, "BCM", TRUE);
   2232 #ifdef NO_SAL_APPL
   2233     return;
   2234 #else
   2235 #ifdef __KERNEL__
   2236     cli_out("Exit Diag Shell.\n");
   2237     return; 
   2238 #endif
   2239 
   2240 #ifdef VXWORKS
   2241     cli_out("Top level (use reset to reboot)\n");
   2242 #else
   2243     sal_reboot();
   2244 #endif
   2245 #endif
   2246     }
   2247 }
   2248 
   2249 #define SYSTEM_INIT_CHECK(action, description)          \
   2250     if ((rv = (action)) < 0) {              \
   2251         msg = (description);                \
   2252         goto done;                      \
   2253     }
   2254 
   2255 /*
   2256  * Function:
   2257  *  system_init
   2258  * Purpose:
   2259  *  Reset the switch chip, re-initialize, and initialize the BCM API layer.
   2260  * Parameters:
   2261  *  unit - StrataSwitch unit #.
   2262  * Returns:
   2263  *  BCM_E_XXX
   2264  * Notes:
   2265  *  After initialization, ports are in the spanning tree disabled
   2266  *  state.  Some STP implementation needs to turn them on.
   2267  */
   2268 
   2269 int
   2270 system_init(int unit)
   2271 {
   2272 
   2273 
   2274     int         rv=0;
   2275     char        *msg = NULL;
   2276 #if defined(BCM_ESW_SUPPORT) 
   2277     soc_port_t      port, dport;
   2278     sal_usecs_t     usec;
   2279     pbmp_t      pbmp;
   2280     bcm_port_config_t pcfg;
   2281 #endif
   2282 
   2283     {
   2284 #if defined(BCM_ESW_SUPPORT)
   2285         SYSTEM_INIT_CHECK(soc_reset_init(unit), "Device reset");
   2286 #if defined(CANCUN_SUPPORT) && !defined(NO_SAL_APPL)
   2287         if (soc_feature(unit, soc_feature_cancun)) {
   2288             SYSTEM_INIT_CHECK(soc_cancun_generic_load(unit, CANCUN_SOC_FILE_TYPE_CMH), "load cmh");
   2289             SYSTEM_INIT_CHECK(soc_cancun_generic_load(unit, CANCUN_SOC_FILE_TYPE_CCH), "load cch");
   2290             SYSTEM_INIT_CHECK(soc_cancun_generic_load(unit, CANCUN_SOC_FILE_TYPE_CEH), "load ceh");
   2291         }
   2292 #endif
   2293         SYSTEM_INIT_CHECK(soc_misc_init(unit), "Misc init");
   2294 #if defined(CANCUN_SUPPORT) && !defined(NO_SAL_APPL)
   2295         if (soc_feature(unit, soc_feature_cancun)) {
   2296             SYSTEM_INIT_CHECK(soc_cancun_generic_load(unit, CANCUN_SOC_FILE_TYPE_CIH), "load cih");
   2297             if (soc_feature(unit, soc_feature_flex_flow)) {
   2298                 SYSTEM_INIT_CHECK(soc_cancun_generic_load(unit, CANCUN_SOC_FILE_TYPE_CFH), "load cfh");
   2299             }
   2300         }
   2301 #endif
   2302         SYSTEM_INIT_CHECK(soc_mmu_init(unit), "MMU init");
   2303 
   2304 #ifdef  BCM_XGS_SWITCH_SUPPORT
   2305         if (soc_feature(unit, soc_feature_arl_hashed) && !SOC_IS_RCPU_ONLY(unit)) {
   2306             usec = soc_property_get(unit, spn_L2XMSG_THREAD_USEC, SOC_L2X_INTERVAL_DEFAULT);
   2307             rv = soc_l2x_start(unit, 0, usec);
   2308             if ((rv < 0) && (rv != SOC_E_UNAVAIL)) {
   2309                 msg = "L2X thread init";
   2310                 goto done;
   2311             }
   2312         }
   2313 #endif  /* BCM_XGS_SWITCH_SUPPORT */
   2314 #endif
   2315     }
   2316 #if defined(BCM_ESW_SUPPORT) 
   2317     SYSTEM_INIT_CHECK(bcm_init(unit), "BCM driver layer init");
   2318 
   2319     BCM_IF_ERROR_RETURN(bcm_port_config_get(unit, &pcfg));
   2320 
   2321     if (soc_property_get_str(unit, spn_BCM_LINKSCAN_PBMP) == NULL) {
   2322         BCM_PBMP_ASSIGN(pbmp, pcfg.port);
   2323     } else {
   2324         pbmp = soc_property_get_pbmp(unit, spn_BCM_LINKSCAN_PBMP, 0);
   2325     }
   2326 
   2327     DPORT_BCM_PBMP_ITER(unit, pbmp, dport, port) {
   2328         int autoneg;
   2329 
   2330         autoneg = soc_property_bcm_port_get(unit, port, 
   2331                                             spn_PORT_INIT_AUTONEG, TRUE);
   2332 
   2333         SYSTEM_INIT_CHECK(bcm_port_stp_set(unit, port, BCM_PORT_STP_FORWARD),
   2334                           "Port Forwarding");
   2335 #if defined(BCM_RCPU_SUPPORT)
   2336         if (SOC_IS_RCPU_ONLY(unit) && !IS_RCPU_PORT(unit, port))
   2337 #endif /* BCM_RCPU_SUPPORT */
   2338         {
   2339             SYSTEM_INIT_CHECK(bcm_port_autoneg_set(unit, port, autoneg),
   2340                               autoneg ? "Autoneg enable" : "Autoneg disable");
   2341         }
   2342             SYSTEM_INIT_CHECK(bcm_linkscan_mode_set(unit, port,
   2343                                                 SOC_IS_XGS12_FABRIC(unit) ? 
   2344                                                 BCM_LINKSCAN_MODE_HW :
   2345                                                 BCM_LINKSCAN_MODE_SW),
   2346                           "Linkscan mode set");
   2347         if (!soc_feature(unit, soc_feature_no_stat_mib)) {
   2348             SYSTEM_INIT_CHECK(bcm_stat_clear(unit, port),
   2349                               "Stat clear");
   2350         }
   2351     }
   2352 
   2353     usec = soc_property_get(unit, spn_BCM_LINKSCAN_INTERVAL,
   2354                             BCM_LINKSCAN_INTERVAL_DEFAULT);
   2355 
   2356     SYSTEM_INIT_CHECK(bcm_linkscan_enable_set(unit, usec), "Linkscan enable");
   2357 #if defined(BCM_ESW_SUPPORT)
   2358     if (SOC_IS_ESW(unit) && ((!SAL_BOOT_SIMULATION) || SAL_BOOT_BCMSIM)) {
   2359         SYSTEM_INIT_CHECK(soc_counter_sync(unit), "Counter sync");
   2360         SYSTEM_INIT_CHECK(do_resync_counters(unit, pbmp), "Resync counters");
   2361     }
   2362 #endif
   2363 #endif
   2364 
   2365 #if defined(BCM_ESW_SUPPORT)
   2366  done:
   2367 #endif
   2368 
   2369     if (msg != NULL) {
   2370         LOG_ERROR(BSL_LS_SOC_COMMON,
   2371                   (BSL_META_U(unit ,
   2372                               "system_init: %s failed: %s\n"),
   2373                    msg, soc_errmsg(rv)));
   2374     }
   2375 
   2376     if (BCM_CONTROL(unit)) {
   2377         BCM_CONTROL(unit)->system_initialized_rv = rv;
   2378     }
   2379 
   2380     return BCM_E_NONE;
   2381 }
   2382 
   2383 /*
   2384  * Function:
   2385  *  system_shutdown
   2386  * Purpose:
   2387  *  Shutdown threads that may access hardware during reset.
   2388  * Parameters:
   2389  *  unit - StrataSwitch unit #.
   2390  *  cleanup - If true, attempt to free all resources
   2391  * Returns:
   2392  *  BCM_E_XXX
   2393  * Notes:
   2394  *  Ideally this function would call _bcm_shutdown, which is
   2395  *      currently used for WARM_BOOT only.
   2396  */
   2397 
   2398 int
   2399 system_shutdown(int unit, int cleanup)
   2400 {
   2401 
   2402     if (pw_running(unit)) {
   2403         pw_stop(unit, TRUE);
   2404     }
   2405     /* Disregard the error codes on these two calls due to shutdown */
   2406     (void)bcm_linkscan_enable_set(unit, 0);
   2407     (void)bcm_rx_stop(unit, NULL);
   2408 
   2409 
   2410     if (cleanup) {
   2411         /* Clean up SOC and BCM */
   2412     }
   2413 
   2414     return BCM_E_NONE;
   2415 }
   2416 
   2417 
   2418 /*
   2419  * These implementations are provided as temporary stubs
   2420  * for builds using NO_SAL_APPL only
   2421  */
   2422 
   2423 #ifdef NO_SAL_APPL
   2424 
   2425 int 
   2426 sal_portable_printf(const char* fmt, ...)
   2427 {
   2428     va_list args; 
   2429     int rc; 
   2430 
   2431     va_start(args, fmt); 
   2432     rc = sal_portable_vprintf(fmt, args); 
   2433     va_end(args); 
   2434     return rc; 
   2435 }
   2436 
   2437 char *
   2438 sal_portable_readline_internal(char *prompt, char *buf, int bufsize, char *defl)
   2439 {
   2440     char *s, *full_prompt, *cont_prompt;
   2441     int len;
   2442 
   2443     if (bufsize == 0)
   2444         return NULL;
   2445 
   2446     cont_prompt = prompt[0] ? "? " : "";
   2447     full_prompt = sal_alloc(sal_strlen(prompt) + (defl ? sal_strlen(defl) : 0) + 8, __FILE__);
   2448     sal_strncpy(full_prompt, prompt, sal_strlen(prompt) + 1);
   2449     if (defl)
   2450     sal_sprintf(full_prompt + sal_strlen(full_prompt), "[%s] ", defl);
   2451 
   2452     s = sal_portable_readline(full_prompt, buf, bufsize); 
   2453 
   2454     if (s == 0) {                       /* Handle Control-D */
   2455         buf[0] = 0;
   2456     /* EOF */
   2457     buf = 0;
   2458     goto done;
   2459     } 
   2460 
   2461     len = 0;
   2462     if (s[0] == 0) {
   2463     if (defl && buf != defl) {
   2464             if ((len = sal_strlen(defl)) >= bufsize) {
   2465                 len = bufsize - 1;
   2466             }
   2467         sal_memcpy(buf, defl, len);
   2468     }
   2469     } else {
   2470     if ((len = sal_strlen(s)) >= bufsize) {
   2471             len = bufsize - 1;
   2472             cli_out("WARNING: input line truncated to %d chars\n", len);
   2473         }
   2474     sal_memcpy(buf, s, len);
   2475     }
   2476     buf[len] = 0;
   2477 
   2478 
   2479     /*
   2480      * If line ends in a backslash, perform a continuation prompt.
   2481      */
   2482 
   2483     s = buf + sal_strlen(buf) - 1;
   2484     if (*s == '\\' && sal_readline(cont_prompt, s, bufsize - (s - buf), 0) == 0)
   2485     buf = 0;
   2486 
   2487  done:
   2488     sal_free(full_prompt);
   2489     return buf;
   2490 }
   2491 
   2492 
   2493 #endif /* NO_SAL_APPL */