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

dev.c (4744B)


      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  * device CLI commands
      8  */
      9 
     10 #include <appl/diag/system.h>
     11 #include <appl/diag/parse.h>
     12 #include <appl/diag/dport.h>
     13 #include <appl/diag/sysconf.h>
     14 #include <shared/bsl.h>
     15 #include <soc/debug.h>
     16 #include <soc/hash.h>
     17 #include <soc/cmext.h>
     18 
     19 #include <bcm/error.h>
     20 #include <bcm/init.h>
     21 #include <bcm/tunnel.h>
     22 #include <bcm/ipmc.h>
     23 #include <bcm/debug.h>
     24 #include <ibde.h>
     25 
     26 
     27 /*
     28  * Function:
     29  *      _device_cmd_detach
     30  * Description:
     31  * 	    Service routine used to remove bcm device.
     32  * Parameters:
     33  *      unit      - (IN) Device number.
     34  *      a         - (IN) Command arguments. 
     35  * Returns:
     36  *      CMD_XXX
     37  */
     38 STATIC cmd_result_t
     39 _device_cmd_detach(int unit, args_t *a) 
     40 {
     41     parse_table_t   pt;
     42     int             rv = BCM_E_NONE;
     43     cmd_result_t    retCode;
     44     int             dunit = unit;
     45 
     46     parse_table_init(unit, &pt);
     47 
     48     parse_table_add(&pt, "Unit",    PQ_DFL | PQ_INT,  0, (void *)&dunit, 0);
     49     if (!parseEndOk(a, &pt, &retCode)) {
     50         return retCode;
     51     }
     52     if (!soc_attached(dunit)) {
     53         cli_out("%s: unit %d already detached\n", 
     54                 ARG_CMD(a), dunit);
     55         return (CMD_FAIL);
     56     }
     57 
     58     rv = sysconf_detach(dunit);
     59 
     60     if (BCM_FAILURE(rv)) {
     61         cli_out("%s: detach unit %d error : %s\n", 
     62                 ARG_CMD(a), dunit, bcm_errmsg(rv));
     63         return (CMD_FAIL);
     64     }
     65 
     66     return (CMD_OK);
     67 
     68 }
     69 
     70 /*
     71  * Function:
     72  *      _device_cmd_attach
     73  * Description:
     74  * 	    Service routine used to add and initialize bcm device.
     75  * Parameters:
     76  *      unit      - (IN) Device number.
     77  *      a         - (IN) Command arguments. 
     78  * Returns:
     79  *      CMD_XXX
     80  */
     81 STATIC cmd_result_t
     82 _device_cmd_attach(int unit, args_t *a) 
     83 {
     84     parse_table_t   pt;
     85     int             rv;
     86     cmd_result_t    retCode;
     87     int             dunit = unit;
     88     int             dev_idx, found = 0;
     89 
     90     parse_table_init(unit, &pt);
     91 
     92     parse_table_add(&pt, "Unit",    PQ_DFL | PQ_INT,  0, (void *)&dunit, 0);
     93     if (!parseEndOk(a, &pt, &retCode)) {
     94         return retCode;
     95     }
     96 
     97     rv = sysconf_probe();
     98 
     99     if (BCM_FAILURE(rv)) {
    100         cli_out("%s: sysconf_probe error\n", 
    101                 ARG_CMD(a));
    102         return (CMD_FAIL);
    103     }
    104     for(dev_idx = 0; dev_idx < soc_ndev ; ++dev_idx) {
    105         if(SOC_NDEV_IDX2DEV(dev_idx) == dunit) {
    106             found = 1;
    107             break;
    108         }
    109     }
    110     
    111     if (!found) {
    112         cli_out("%s: Error: Unit number out of range (%d - %d)\n",
    113                 ARG_CMD(a), 0, soc_ndev - 1);
    114         return(CMD_FAIL);
    115     } else if (soc_attached(dunit)) {
    116         cli_out("%s: Error: Unit already attached: %d\n", ARG_CMD(a), dunit);
    117         return(CMD_FAIL);
    118     } else if (sysconf_attach(dunit) < 0) {
    119         cli_out("%s: Error: Could not sysconf_attach unit: %d\n", ARG_CMD(a), dunit);
    120         return(CMD_FAIL);
    121     }
    122 
    123 #if defined(BCM_ESW_SUPPORT)
    124     if (SOC_IS_ESW(dunit)) {    
    125 
    126         rv = soc_init(dunit);
    127         if (BCM_FAILURE(rv)) {
    128             cli_out("%s: soc_init error : %s\n", 
    129                     ARG_CMD(a), bcm_errmsg(rv));
    130             return (CMD_FAIL);
    131         }
    132         
    133         rv = soc_misc_init(dunit);
    134         if (BCM_FAILURE(rv)) {
    135             cli_out("%s: soc_misc_init error : %s\n", 
    136                     ARG_CMD(a), bcm_errmsg(rv));
    137             return (CMD_FAIL);
    138         }
    139         
    140         rv = soc_mmu_init(dunit);
    141         if (BCM_FAILURE(rv)) {
    142             cli_out("%s: soc_mmu_init error : %s\n", 
    143                     ARG_CMD(a), bcm_errmsg(rv));
    144             return (CMD_FAIL);
    145         }
    146 #if defined(BCM_TOMAHAWK3_SUPPORT)
    147         if (SOC_IS_TOMAHAWK3(dunit)) {
    148             rv = bcm_attach(dunit, "tomahawk3", NULL, 0);
    149         } else
    150 #endif
    151         {
    152             rv = bcm_attach(dunit, "esw", NULL, 0);
    153         }
    154     } else 
    155 #endif
    156 
    157     if (BCM_FAILURE(rv)) {
    158         cli_out("%s: bcm_attach error : %s\n", 
    159                 ARG_CMD(a), bcm_errmsg(rv));
    160         return (CMD_FAIL);
    161     }
    162     return (CMD_OK);
    163 }
    164 
    165 char cmd_device_usage[] =
    166     "Usages:\n\t"
    167 #ifdef COMPILER_STRING_CONST_LIMIT
    168     "  device <option> [args...]\n"
    169 #else
    170     "  device attach [<unit>=<id>]\n\t"
    171     "  device detach [<unit>=<id>]\n"
    172 #endif
    173     ;
    174 cmd_result_t
    175 cmd_device(int unit, args_t *a)
    176 {
    177     char           *table;
    178 
    179     if ((table = ARG_GET(a)) == NULL) {
    180         return CMD_USAGE;
    181     }
    182 
    183     /* Device create*/
    184     if (sal_strcasecmp(table, "attach") == 0) {
    185          return _device_cmd_attach(unit, a); 
    186     }
    187     if (sal_strcasecmp(table, "detach") == 0) {
    188          return _device_cmd_detach(unit, a); 
    189     }
    190     return CMD_USAGE;
    191 }