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

stk.c (5925B)


      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  * Stacking CLI commands
      8  */
      9 
     10 #include <appl/diag/shell.h>
     11 #include <appl/diag/system.h>
     12 #include <appl/diag/parse.h>
     13 #include <appl/diag/dport.h>
     14 #include <shared/bsl.h>
     15 #include <bcm/vlan.h>
     16 #include <bcm/stack.h>
     17 #include <bcm/error.h>
     18 
     19 #ifdef BCM_DFE_SUPPORT
     20 #include <soc/dfe/cmn/dfe_drv.h>
     21 #endif
     22 
     23 #ifdef BCM_DNXF_SUPPORT
     24 #include <soc/dnxf/cmn/dnxf_drv.h>
     25 #endif
     26 
     27 char cmd_stkmode_usage[] =
     28 "Parameters:\n"
     29 "	Modid=<m>		Set the module identifier\n"
     30 "	ModPortClear=[T|F]	Clear modport table\n"
     31 "	SLCount=<n>		Set SL Simplex hop count\n"
     32 "	Cascade=[T|F]		Enable/disable Higig/SL Cascade\n"
     33 "	SimplexPorts=<pbmp>	SL Simplex mode stack ports\n"
     34 "	DuplexPorts=<pbmp>	SL Duplex mode stack ports\n"
     35 "If no parameters, show current state\n";
     36 
     37 cmd_result_t
     38 cmd_stkmode(int unit, args_t *a)
     39 {
     40     parse_table_t	pt;
     41     int			rv, modcount;
     42     int			modid, modportclear, slmode, slcount;
     43     int enable=-1;
     44     bcm_pbmp_t		stkp_simplex, stkp_duplex;
     45     uint32              flags = 0;
     46 
     47     if (!sh_check_attached(ARG_CMD(a), unit)) {
     48 	return CMD_FAIL;
     49     }
     50 
     51     if (ARG_CNT(a) == 0) {	/* show current state */
     52     	rv = bcm_stk_modid_get(unit, &modid);
     53     	if (rv < 0) {
     54     	    cli_out("%s: ERROR: bcm_stk_modid_get: %s\n",
     55                     ARG_CMD(a), bcm_errmsg(rv));
     56     	    return CMD_FAIL;
     57     	}
     58 #ifdef BCM_DFE_SUPPORT
     59         if(SOC_IS_DFE(unit)) {
     60              cli_out("unit %d: module id %d\n", unit, modid);
     61              return CMD_OK;
     62         }
     63 #endif
     64 #ifdef BCM_DNXF_SUPPORT
     65         if(SOC_IS_DNXF(unit)) {
     66              cli_out("unit %d: module id %d\n", unit, modid);
     67              return CMD_OK;
     68         }
     69 #endif
     70     	if (bcm_stk_modid_count(unit, &modcount) < 0) {
     71     	    modcount = 1;
     72     	}
     73             rv = bcm_stk_mode_get(unit, &flags);
     74             if (rv < 0) {
     75                 cli_out("ERROR: bcm_stk_mode_get returns %s\n", bcm_errmsg(rv));
     76                 return CMD_FAIL;
     77             }
     78     	slmode = (flags & BCM_STK_SL) ? 1 : 0;
     79     	slcount = 0;
     80     	if (modcount != 1) {
     81     	    cli_out("%s: unit %d: module id %d (uses %d module ids)\n",
     82                     ARG_CMD(a), unit, modid, modcount);
     83     	} else {
     84     	    cli_out("%s: unit %d: module id %d\n",
     85                     ARG_CMD(a), unit, modid);
     86     	}
     87     	if (slmode || slcount) {
     88             /* coverity[dead_error_line] */
     89     	    cli_out("%s: unit %d: SL mode %s, simplex hop count %d, "
     90                     "Higig/SL\n",
     91                     ARG_CMD(a), unit,
     92                     slmode ? "on" : "off",
     93                     slcount);
     94     	}
     95     #if 0 
     96         char                pfmt[SOC_PBMP_FMT_LEN];
     97         char                pstr[FORMAT_PBMP_MAX];
     98     
     99     	if (bcm_stk_pbmp_get(unit, &stkp_simplex, &stkp_duplex) >= 0) {
    100     	    if (BCM_PBMP_NOT_NULL(stkp_simplex)) {
    101     		format_pbmp(unit, pstr, sizeof(pstr), stkp_simplex);
    102     		cli_out("%s: unit %d: SL simplex stack ports %s %s\n",
    103                         ARG_CMD(a), unit,
    104                         SOC_PBMP_FMT(stkp_simplex, pfmt), pstr);
    105     	    }
    106     	    if (BCM_PBMP_NOT_NULL(stkp_duplex)) {
    107     		format_pbmp(unit, pstr, sizeof(pstr), stkp_duplex);
    108     		cli_out("%s: unit %d: SL duplex  stack ports %s %s\n",
    109                         ARG_CMD(a), unit,
    110                         SOC_PBMP_FMT(stkp_duplex, pfmt), pstr);
    111     	    }
    112     	}
    113     #endif
    114     	return CMD_OK;
    115     }
    116 
    117     modid = slcount = -1;
    118     modportclear = -1;
    119     BCM_PBMP_CLEAR(stkp_simplex);
    120     BCM_PBMP_CLEAR(stkp_duplex);
    121 
    122     parse_table_init(unit, &pt);
    123     parse_table_add(&pt, "Modid", PQ_INT|PQ_DFL,
    124 		    0, &modid, NULL);
    125 #ifdef BCM_DFE_SUPPORT
    126     if(SOC_IS_DFE(unit)) {
    127         parse_table_add(&pt, "ENable", PQ_BOOL|PQ_DFL,
    128         0, &enable, NULL);
    129     } 
    130     else
    131 #endif
    132 #ifdef BCM_DNXF_SUPPORT
    133     if(SOC_IS_DNXF(unit)) {
    134         parse_table_add(&pt, "ENable", PQ_BOOL|PQ_DFL,
    135         0, &enable, NULL);
    136     }
    137     else
    138 #endif
    139 {
    140     parse_table_add(&pt, "ModPortClear", PQ_BOOL|PQ_DFL,
    141 		    0, &modportclear, NULL);
    142     parse_table_add(&pt, "SLCount", PQ_INT|PQ_DFL,
    143 		    0, &slcount, NULL);
    144     parse_table_add(&pt, "SimplexPorts", PQ_PBMP|PQ_BCM|PQ_DFL,
    145 		    0, &stkp_simplex, NULL);
    146     parse_table_add(&pt, "DuplexPorts", PQ_PBMP|PQ_BCM|PQ_DFL,
    147 		    0, &stkp_duplex, NULL);
    148 }
    149     if (parse_arg_eq(a, &pt) < 0) {
    150     	cli_out("%s: Invalid argument: %s\n", ARG_CMD(a), ARG_CUR(a));
    151     	parse_arg_eq_done(&pt);
    152     	return CMD_FAIL;
    153     }
    154     parse_arg_eq_done(&pt);
    155 
    156     if (modid >= 0) {
    157     	rv = bcm_stk_modid_set(unit, modid);
    158     	if (rv < 0) {
    159     	    cli_out("%s: ERROR: bcm_stk_modid_set: %s\n",
    160                     ARG_CMD(a), bcm_errmsg(rv));
    161     	    return CMD_FAIL;
    162     	}
    163     }
    164 
    165     /* coverity[dead_error_begin] */
    166     if (enable >= 0) {
    167     	rv = bcm_stk_module_enable(unit, modid, -1, enable);
    168     	if (rv < 0) {
    169     	    cli_out("%s: ERROR: bcm_stk_module_enable: %s\n",
    170                     ARG_CMD(a), bcm_errmsg(rv));
    171     	    return CMD_FAIL;
    172     	}
    173     }
    174     /* coverity[dead_error_begin] */
    175 
    176     if (modportclear > 0) {
    177 	rv = bcm_stk_modport_clear_all(unit);
    178 	if (rv < 0) {
    179 	    cli_out("%s: ERROR: bcm_stk_modport_clear_all: %s\n",
    180                     ARG_CMD(a), bcm_errmsg(rv));
    181 	    return CMD_FAIL;
    182 	}
    183     }
    184 #if 0 
    185     if (BCM_PBMP_NOT_NULL(stkp_simplex) || BCM_PBMP_NOT_NULL(stkp_duplex)) {
    186 	rv = bcm_stk_pbmp_get(unit, stkp_simplex, stkp_duplex);
    187 	if (rv < 0) {
    188 	    cli_out("%s: ERROR: bcm_stk_port_add: %s\n",
    189                     ARG_CMD(a), bcm_errmsg(rv));
    190 	    return CMD_FAIL;
    191 	}
    192     }
    193 #endif
    194     if (slcount >= 0) {
    195 	/* bcm_stk_sl_simplex_count_set is deprecated */
    196 	cli_out("%s: ERROR: bcm_stk_sl_simplex_count_set: %s\n",
    197                 ARG_CMD(a), bcm_errmsg(BCM_E_UNAVAIL));
    198 	return CMD_FAIL;
    199     }
    200     return CMD_OK;
    201 }
    202 
    203