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

init.c (49871B)


      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  * BCM Library Initialization
      8  *
      9  *   This module calls the initialization routine of each BCM module.
     10  *
     11  * Initial System Configuration
     12  *
     13  *   Each module should initialize itself without reference to other BCM
     14  *   library modules to avoid a chicken-and-the-egg problem.  To do
     15  *   this, each module should initialize its respective internal state
     16  *   and hardware tables to match the Initial System Configuration.  The
     17  *   Initial System Configuration is:
     18  *
     19  *   STG 1 containing VLAN 1
     20  *   STG 1 all ports in the DISABLED state
     21  *   VLAN 1 with
     22  *	PBMP = all switching Ethernet ports (non-fabric) and the CPU.
     23  *	UBMP = all switching Ethernet ports (non-fabric).
     24  *   No trunks configured
     25  *   No mirroring configured
     26  *   All L2 and L3 tables empty
     27  *   Ingress VLAN filtering disabled
     28  *   BPDU reception enabled
     29  */
     30 
     31 #include <sal/types.h>
     32 #include <sal/core/time.h>
     33 #include <sal/core/boot.h>
     34 #include <shared/bsl.h>
     35 #include <soc/cmext.h>
     36 #include <soc/counter.h>
     37 #include <soc/l2x.h>
     38 #include <soc/mem.h>
     39 #include <soc/debug.h>
     40 #include <soc/phyctrl.h>
     41 
     42 #include <bcm/init.h>
     43 #include <bcm/error.h>
     44 #include <bcm/rx.h>
     45 #include <bcm/pkt.h>
     46 #include <bcm/ipfix.h>
     47 
     48 #ifdef SW_AUTONEG_SUPPORT
     49 #include <bcm_int/common/sw_an.h>
     50 #endif 
     51  
     52 #include <bcm_int/api_xlate_port.h>
     53 #include <bcm_int/control.h>
     54 #include <bcm_int/common/lock.h>
     55 #ifdef BCM_RCPU_SUPPORT
     56 #include <bcm_int/esw/rcpu.h>
     57 #endif
     58 #include <bcm_int/esw/mirror.h>
     59 #include <bcm_int/esw/stat.h>
     60 #include <bcm_int/esw/mcast.h>
     61 #include <bcm_int/esw/range.h>
     62 
     63 #include <bcm_int/esw/mbcm.h>
     64 #include <bcm_int/esw/ipfix.h>
     65 #include <bcm_int/esw/mirror.h>
     66 #include <bcm_int/esw/stack.h>
     67 #include <bcm_int/esw_dispatch.h>
     68 #include <bcm_int/esw/stg.h>
     69 #include <bcm_int/esw/switch.h>
     70 #include <bcm_int/esw/vlan.h>
     71 #include <bcm_int/esw/cosq.h>
     72 #include <bcm_int/esw/rx.h>
     73 #include <bcm_int/esw/rate.h>
     74 #ifdef BCM_INSTRUMENTATION_SUPPORT
     75 #include <bcm_int/esw/instrumentation.h>
     76 #endif /* BCM_INSTRUMENTATION_SUPPORT */
     77 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
     78 #include <bcm_int/esw/policer.h>
     79 #endif
     80 #ifdef BCM_TRX_SUPPORT
     81 #include <bcm_int/esw/trx.h>
     82 #endif /* BCM_TRX_SUPPORT */
     83 
     84 #if defined(BCM_TOMAHAWK3_SUPPORT)
     85 #include <bcm_int/tomahawk3_dispatch.h>
     86 #include <bcm_int/esw/tomahawk3.h>
     87 #endif /* BCM_TOMAHAWK3_SUPPORT  */
     88 
     89 #ifdef BCM_WARM_BOOT_SUPPORT
     90 #include <bcm_int/esw/vlan.h>
     91 #include <bcm_int/esw/trunk.h>
     92 #include <bcm_int/esw/field.h>
     93 #include <bcm_int/esw/l3.h>
     94 #include <bcm_int/esw/mcast.h>
     95 #include <bcm_int/esw/port.h>
     96 #include <bcm_int/esw/latency_monitor.h>
     97 #endif
     98 
     99 #ifdef INCLUDE_MACSEC
    100 #include <bcm_int/common/macsec_cmn.h>
    101 #endif /* INCLUDE_MACSEC */
    102 
    103 #ifdef INCLUDE_FCMAP
    104 #include <bcm_int/common/fcmap_cmn.h>
    105 #endif /* INCLUDE_FCMAP */
    106 
    107 #ifdef BCM_TOMAHAWK_SUPPORT
    108 #include <soc/tomahawk.h>
    109 #include <bcm_int/esw/tomahawk.h>
    110 #endif
    111 
    112 #include <bcm_int/esw_dispatch.h>
    113 #include <shared/shr_bprof.h>
    114 
    115 #define BCM_CHECK_ERROR_RETURN(rv, dispname)                         \
    116     if ((rv < 0) && (rv != BCM_E_UNAVAIL)) {                         \
    117         LOG_WARN(BSL_LS_BCM_INIT,                                    \
    118                     (BSL_META_U(unit, "bcm_init failed in %s\n"),    \
    119                  shr_bprof_stats_name(dispname)));                   \
    120         return (rv);                                                 \
    121     }
    122 
    123 #if defined(BCM_TOMAHAWK_SUPPORT)
    124 extern int soc_ctr_evict_start(int unit, uint32 flags, sal_usecs_t interval);
    125 #endif
    126 #if defined(BCM_TRIUMPH3_SUPPORT)
    127 extern int _bcm_esw_tr3_port_lanes_init(int unit);
    128 #endif
    129 
    130 
    131 #if defined(BCM_TIMESYNC_TIME_CAPTURE_SUPPORT)
    132 extern int bcm_esw_time_capture_ts_init(int unit);
    133 extern int bcm_esw_time_capture_ts_deinit(int unit);
    134 #endif /* BCM_TIMESYNC_TIME_CAPTURE_SUPPORT */
    135 
    136 /*
    137  * Function:
    138  *	_bcm_lock_init
    139  * Purpose:
    140  *	Allocate BCM_LOCK.
    141  */
    142 
    143 STATIC int
    144 _bcm_th3_lock_init(int unit)
    145 {
    146     if (_bcm_lock[unit] == NULL) {
    147 	_bcm_lock[unit] = sal_mutex_create("bcm_config_lock");
    148     }
    149 
    150     if (_bcm_lock[unit] == NULL) {
    151 	return BCM_E_MEMORY;
    152     }
    153 
    154     return BCM_E_NONE;
    155 }
    156 
    157 /*
    158  * Function:
    159  *	_bcm_lock_deinit
    160  * Purpose:
    161  *	De-allocate BCM_LOCK.
    162  */
    163 
    164 STATIC int
    165 _bcm_th3_lock_deinit(int unit)
    166 {
    167     if (_bcm_lock[unit] != NULL) {
    168         sal_mutex_destroy(_bcm_lock[unit]);
    169         _bcm_lock[unit] = NULL;
    170     }
    171     return BCM_E_NONE;
    172 }
    173 
    174 #define _DEINIT_INFO_VERB(_mod) \
    175     LOG_VERBOSE(BSL_LS_BCM_COMMON, \
    176                 (BSL_META_U(unit, \
    177                             "bcm_detach: Deinitializing %s...\n"),   \
    178                  _mod));
    179 
    180 #define _DEINIT_CHECK_ERR(_rv, _mod) \
    181     if (_rv != BCM_E_NONE && _rv != BCM_E_UNAVAIL) { \
    182         LOG_WARN(BSL_LS_BCM_INIT, \
    183                  (BSL_META_U(unit, \
    184                              "Warning: Deinitializing %s returned %d\n"), \
    185                   _mod, _rv)); \
    186     }
    187 
    188 /*
    189  * Function:
    190  *	   _bcm_th3_modules_deinit
    191  * Purpose:
    192  *     bcm_detach_late_txrx() will deinit all modules except TX and RX.
    193  *     A regular bcm_detach() must follow to detach the remaining modules.
    194  *	   De-initialize bcm modules
    195  * Parameters:
    196  *     unit - (IN) BCM device number.
    197  * Returns:
    198  *     BCM_E_XXX
    199  */
    200 STATIC int
    201 _bcm_th3_modules_deinit(int unit)
    202 {
    203     int rv;    /* Operation return status. */
    204     /* Only TX/RX deinit should be done here */
    205     if (BCM_CONTROL(unit)->attach_state == _bcmControlStateDeinitAll) {
    206         _DEINIT_INFO_VERB("rx");
    207         rv = bcm_esw_rx_deinit(unit);
    208         /* There is no tx deinit defined currently */
    209         BCM_UNLOCK(unit);
    210         _bcm_th3_lock_deinit(unit);
    211         return rv;
    212     }
    213 #ifdef INCLUDE_BFD
    214     if (soc_feature(unit, soc_feature_bfd)) {
    215         _DEINIT_INFO_VERB("bfd");
    216         rv =  bcm_esw_bfd_detach(unit);
    217         _DEINIT_CHECK_ERR(rv, "bfd");
    218     }
    219 #endif
    220 #ifdef INCLUDE_PTP
    221     if (soc_feature(unit, soc_feature_ptp)) {
    222         _DEINIT_INFO_VERB("ptp");
    223 	    rv =  bcm_esw_ptp_detach(unit);
    224         _DEINIT_CHECK_ERR(rv, "ptp");
    225     }
    226 #endif
    227 
    228 #ifdef INCLUDE_L3
    229     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset))
    230     {
    231         _DEINIT_INFO_VERB("failover");
    232         rv = bcm_esw_failover_cleanup(unit);
    233         _DEINIT_CHECK_ERR(rv, "failover");
    234     }
    235 #endif
    236 
    237     if (soc_feature(unit, soc_feature_time_support))
    238     {
    239         _DEINIT_INFO_VERB("time");
    240         rv = bcm_esw_time_deinit(unit);
    241         _DEINIT_CHECK_ERR(rv, "time");
    242     }
    243 
    244     _DEINIT_INFO_VERB("udf");
    245     rv = bcm_esw_udf_detach(unit);
    246     _DEINIT_CHECK_ERR(rv, "udf");
    247 
    248 #ifdef BCM_FIELD_SUPPORT
    249     _DEINIT_INFO_VERB("auth");
    250     rv = bcm_esw_auth_detach(unit);
    251     _DEINIT_CHECK_ERR(rv, "auth");
    252 
    253     _DEINIT_INFO_VERB("field");
    254     rv = bcm_esw_field_detach(unit);
    255     _DEINIT_CHECK_ERR(rv, "field");
    256 #ifdef BCM_TOMAHAWK_SUPPORT
    257     if (SOC_IS_TOMAHAWKX(unit)) {
    258         if (SOC_MEM_IS_VALID(unit, IFP_RANGE_CHECKm)) {
    259             _DEINIT_INFO_VERB("range");
    260             rv = bcm_esw_range_detach(unit);
    261             _DEINIT_CHECK_ERR(rv, "range");
    262         }
    263     }
    264 #endif
    265 #endif /* BCM_FIELD_SUPPORT */
    266 
    267 #ifdef INCLUDE_L3
    268     _DEINIT_INFO_VERB("proxy");
    269     rv = bcm_esw_proxy_cleanup(unit);
    270     _DEINIT_CHECK_ERR(rv, "proxy");
    271 
    272     _DEINIT_INFO_VERB("multicast");
    273     rv = bcm_esw_multicast_detach(unit);
    274     _DEINIT_CHECK_ERR(rv, "multicast");
    275 
    276     if (soc_feature(unit, soc_feature_port_extension)) {
    277         _DEINIT_INFO_VERB("extender");
    278         rv =  bcm_esw_extender_cleanup(unit);
    279         _DEINIT_CHECK_ERR(rv, "extender");
    280     }
    281 
    282 #ifdef BCM_MPLS_SUPPORT
    283     _DEINIT_INFO_VERB("mpls");
    284     rv = bcm_esw_mpls_cleanup(unit);
    285     _DEINIT_CHECK_ERR(rv, "mpls");
    286 #endif /* BCM_MPLS_SUPPORT */
    287 
    288     _DEINIT_INFO_VERB("ipmc");
    289     rv = bcm_esw_ipmc_detach(unit);
    290     _DEINIT_CHECK_ERR(rv, "ipmc");
    291 
    292     _DEINIT_INFO_VERB("l3");
    293     /*
    294      * COVERITY
    295      *
    296      * Coverity reports a call chain of depth greater than 20, but well
    297      * before the stack overflows, it calls bcm_esw_switch_control_get
    298      * with one control selection, then follows another control's path
    299      * to find more levels of stack.  This is spurious.
    300      */
    301     /* coverity[stack_use_overflow : FALSE] */
    302     rv = bcm_esw_l3_cleanup(unit);
    303     _DEINIT_CHECK_ERR(rv, "l3");
    304 #endif /* INCLUDE_L3 */
    305 
    306     /* Delaying RX deinit so the CPU can stil receive packets
    307      * even when other modules are deinitialized. */
    308     if (!(BCM_CONTROL(unit)->attach_state == _bcmControlStateDeinitLateTxRx)) {
    309         _DEINIT_INFO_VERB("rx");
    310         rv = bcm_esw_rx_deinit(unit);
    311         _DEINIT_CHECK_ERR(rv, "rx");
    312     }
    313 
    314 #if 0
    315     _DEINIT_INFO_VERB("tx");
    316     rv = bcm_esw_tx_deinit(unit);
    317     _DEINIT_CHECK_ERR(rv, "tx");
    318 #endif 
    319 
    320     _DEINIT_INFO_VERB("mirror");
    321     rv = bcm_esw_mirror_deinit(unit);
    322     _DEINIT_CHECK_ERR(rv, "mirror");
    323 
    324 #ifdef INCLUDE_KNET
    325     _DEINIT_INFO_VERB("knet");
    326     rv = bcm_esw_knet_cleanup(unit);
    327     _DEINIT_CHECK_ERR(rv, "knet");
    328 #endif
    329 
    330 #if defined(BCM_TOMAHAWK3_SUPPORT)
    331     if (soc_feature(unit, soc_feature_latency_monitor)) {
    332         _DEINIT_INFO_VERB("latency_monitor");
    333         rv =  bcm_tomahawk3_latency_monitor_detach(unit);
    334         _DEINIT_CHECK_ERR(rv, "latency_monitor");
    335     }
    336 #endif
    337 
    338     _DEINIT_INFO_VERB("stats");
    339     rv = _bcm_esw_stat_detach(unit);
    340     _DEINIT_CHECK_ERR(rv, "stats");
    341 
    342     _DEINIT_INFO_VERB("linkscan");
    343     rv = bcm_esw_linkscan_detach(unit);
    344     _DEINIT_CHECK_ERR(rv, "linkscan");
    345 
    346 #ifdef SW_AUTONEG_SUPPORT
    347     if (soc_feature(unit, soc_feature_sw_autoneg)) {
    348         _DEINIT_INFO_VERB("SW_AN");
    349         rv = bcm_sw_an_module_deinit(unit);
    350         _DEINIT_CHECK_ERR(rv, "SW_AN");
    351     }
    352 #endif    
    353 
    354     _DEINIT_INFO_VERB("mcast");
    355     rv = _bcm_esw_mcast_detach(unit);
    356     _DEINIT_CHECK_ERR(rv, "mcast");
    357 
    358     _DEINIT_INFO_VERB("cosq");
    359     rv = bcm_esw_cosq_deinit(unit);
    360     _DEINIT_CHECK_ERR(rv, "cosq");
    361 
    362     _DEINIT_INFO_VERB("trunk");
    363     rv = bcm_esw_trunk_detach(unit);
    364     _DEINIT_CHECK_ERR(rv, "trunk");
    365 
    366     _DEINIT_INFO_VERB("vlan");
    367     rv = bcm_tomahawk3_vlan_detach(unit);
    368     _DEINIT_CHECK_ERR(rv, "vlan");
    369 
    370     _DEINIT_INFO_VERB("stg");
    371     rv = bcm_esw_stg_detach(unit);
    372     _DEINIT_CHECK_ERR(rv, "stg");
    373 
    374     _DEINIT_INFO_VERB("l2");
    375     rv = bcm_esw_l2_detach(unit);
    376     _DEINIT_CHECK_ERR(rv, "l2");
    377 
    378     _DEINIT_INFO_VERB("port");
    379     rv = _bcm_esw_port_deinit(unit);
    380     _DEINIT_CHECK_ERR(rv, "port");
    381 
    382     _DEINIT_INFO_VERB("ipfix");
    383     rv = _bcm_esw_ipfix_deinit(unit);
    384     _DEINIT_CHECK_ERR(rv, "ipfix");
    385 
    386     _DEINIT_INFO_VERB("mbcm");
    387     rv = mbcm_deinit(unit);
    388     _DEINIT_CHECK_ERR(rv, "mbcm");
    389 
    390     _DEINIT_INFO_VERB("qos");
    391     rv = bcm_esw_qos_detach(unit);
    392     _DEINIT_CHECK_ERR(rv, "qos");
    393 
    394     _DEINIT_INFO_VERB("switch");
    395     rv = _bcm_esw_switch_detach(unit);
    396     _DEINIT_CHECK_ERR(rv, "switch");
    397 
    398 #if defined(BCM_TSN_SUPPORT)
    399     if (soc_feature(unit, soc_feature_tsn)){
    400         _DEINIT_INFO_VERB("tsn");
    401         rv = bcm_esw_tsn_detach(unit);
    402         _DEINIT_CHECK_ERR(rv, "tsn");
    403     }
    404 #endif /* BCM_TSN_SUPPORT */
    405 
    406 #ifdef BCM_TRX_SUPPORT
    407     if (soc_feature(unit, soc_feature_virtual_switching) ||
    408         soc_feature(unit, soc_feature_int_common_init)) {
    409         _DEINIT_INFO_VERB("common");
    410         rv = _bcm_common_cleanup(unit);
    411         _DEINIT_CHECK_ERR(rv, "common");
    412     }
    413 #endif /* BCM_TRX_SUPPORT */
    414 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    415     /* Service meter */
    416     if (soc_feature(unit, soc_feature_global_meter)) {
    417         _DEINIT_INFO_VERB("gmeter");
    418         rv = _bcm_esw_global_meter_cleanup(unit);
    419         _DEINIT_CHECK_ERR(rv, "gmeter");
    420     }
    421 #endif /*BCM_KATANA_SUPPORT or BCM_TRIUMPH3_SUPPORT */
    422 
    423 #if defined(BCM_RCPU_SUPPORT) && defined(BCM_XGS3_SWITCH_SUPPORT)
    424     _DEINIT_INFO_VERB("rcpu");
    425     rv = _bcm_esw_rcpu_deinit(unit);
    426     _DEINIT_CHECK_ERR(rv, "rcpu");
    427 #endif /* BCM_RCPU_SUPPORT && BCM_XGS3_SWITCH_SUPPORT */
    428 
    429 #if defined(BCM_TOMAHAWK_SUPPORT)
    430     _DEINIT_INFO_VERB("latency");
    431     rv = bcm_esw_switch_latency_deinit(unit);
    432     _DEINIT_CHECK_ERR(rv, "latency");
    433 #endif
    434 
    435     _DEINIT_INFO_VERB("flowtracker");
    436     rv =  bcm_tomahawk3_flowtracker_init(unit);
    437     _DEINIT_CHECK_ERR(rv, "flowtracker");
    438 
    439 #if defined (INCLUDE_INT)
    440     if (soc_feature(unit, soc_feature_uc_int_turnaround)) {
    441         _DEINIT_INFO_VERB("int");
    442         rv = bcm_tomahawk3_int_detach(unit);
    443         _DEINIT_CHECK_ERR(rv, "int");
    444     }
    445 #endif /* INCLUDE_INT */
    446 
    447 #if defined (INCLUDE_SUM)
    448     if (soc_feature(unit, soc_feature_sum)) {
    449         _DEINIT_INFO_VERB("sum");
    450         rv = bcm_tomahawk3_sum_detach(unit);
    451         _DEINIT_CHECK_ERR(rv, "sum");
    452     }
    453 #endif /* INCLUDE_SUM */
    454 
    455 #if defined(BCM_TIMESYNC_TIME_CAPTURE_SUPPORT)
    456     BCM_IF_ERROR_RETURN(bcm_esw_time_capture_ts_deinit(unit));
    457 #endif /* BCM_TIMESYNC_TIME_CAPTURE_SUPPORT */
    458 
    459     LOG_VERBOSE(BSL_LS_BCM_COMMON,
    460                 (BSL_META_U(unit,
    461                             "bcm_detach: All modules deinitialized.\n")));
    462     
    463     BCM_UNLOCK(unit);
    464       /* LOCK deinit should not be performed only during the final detach */
    465     if (!(BCM_CONTROL(unit)->attach_state == _bcmControlStateDeinitLateTxRx)) {
    466         _bcm_th3_lock_deinit(unit);
    467     }
    468 
    469     return rv;
    470 }
    471 
    472 #define _THREAD_STOP_CHECK_ERR(_rv, _mod) \
    473     if (_rv != BCM_E_NONE && _rv != BCM_E_UNAVAIL) { \
    474         LOG_WARN(BSL_LS_BCM_INIT, \
    475                  (BSL_META_U(unit, \
    476                              "Warning: Stopping %s thread returned %d\n"), \
    477                   _mod, _rv)); \
    478     }
    479 
    480 /*
    481  * Function:
    482  *      _bcm_th3_threads_shutdown
    483  * Purpose:
    484  *      Terminate all the spawned threads for specific unit. 
    485  * Parameters:
    486  *      unit - unit being detached
    487  * Returns:
    488  *	BCM_E_XXX
    489  */
    490 STATIC int
    491 _bcm_th3_threads_shutdown(int unit)
    492 {
    493     int rv;     /* Operation return status. */
    494 
    495     rv = _bcm_esw_port_mon_stop(unit);
    496     _THREAD_STOP_CHECK_ERR(rv, "portmon");
    497     rv = bcm_esw_linkscan_enable_set(unit, 0);
    498     _THREAD_STOP_CHECK_ERR(rv, "linkscan");
    499 
    500 #ifdef SW_AUTONEG_SUPPORT
    501     if (soc_feature(unit, soc_feature_sw_autoneg))  {
    502         rv = bcm_sw_an_enable_set(unit, 0);
    503         _THREAD_STOP_CHECK_ERR(rv, "SW_AN");
    504     }    
    505 #endif
    506     
    507 #ifdef BCM_XGS_SWITCH_SUPPORT
    508     rv = soc_l2x_stop(unit);
    509     _THREAD_STOP_CHECK_ERR(rv, "l2x");
    510 
    511     /* Stop L2 learning and aging threads */
    512     rv = soc_th3_l2_learn_thread_stop(unit);
    513     _THREAD_STOP_CHECK_ERR(rv, "l2lrn");
    514 
    515     rv = soc_th3_l2_age_stop(unit);
    516     _THREAD_STOP_CHECK_ERR(rv, "l2age");
    517 #endif /* BCM_XGS3_SWITCH_SUPPORT */
    518     rv = soc_counter_detach(unit);
    519     _THREAD_STOP_CHECK_ERR(rv, "counter");
    520 
    521     return BCM_E_NONE;
    522 }
    523 
    524 #ifdef INCLUDE_TCL
    525 #define _BCM_MOD_INIT_CER(unit, rtn, dispname, init) {                      \
    526     if (init) {                                                             \
    527         sal_usecs_t stime, etime;                                           \
    528         int         rv;                                                     \
    529         LOG_VERBOSE(BSL_LS_BCM_COMMON,                                      \
    530                     (BSL_META_U(unit,                                       \
    531                                 "bcm_init: (%s)\n"),                        \
    532                                 shr_bprof_stats_name(dispname)));           \
    533         stime = sal_time_usecs();                                           \
    534         SHR_BPROF_STATS_TIME(dispname) {                                    \
    535             rv = rtn(unit);                                                 \
    536             BCM_CHECK_ERROR_RETURN(rv, dispname);                           \
    537         }                                                                   \
    538         etime = sal_time_usecs();                                           \
    539         if (SOC_WARM_BOOT(unit)) {                                          \
    540             LOG_CLI((BSL_META_U(unit,                                       \
    541                                 "bcm_init: %8s   took %10d usec\n"),        \
    542                      shr_bprof_stats_name(dispname),                        \
    543                      SAL_USECS_SUB(etime, stime)));                         \
    544             _bcm_th3_modules_init_time += SAL_USECS_SUB(etime, stime);      \
    545         } else {                                                            \
    546             LOG_VERBOSE(BSL_LS_BCM_COMMON,                                  \
    547                         (BSL_META_U(unit,                                   \
    548                                     "bcm_init: %8s   took %10d usec\n"),    \
    549                          shr_bprof_stats_name(dispname),                    \
    550                          SAL_USECS_SUB(etime, stime)));                     \
    551             _bcm_th3_modules_init_time += SAL_USECS_SUB(etime, stime);      \
    552         }                                                                   \
    553     } else {                                                                \
    554         LOG_WARN(BSL_LS_BCM_INIT,                                           \
    555                  (BSL_META_U(unit,                                          \
    556                              "bcm_init: skipped %s init\n"),                \
    557                              shr_bprof_stats_name(dispname)));              \
    558     }                                                                       \
    559 }
    560 #else
    561 #define _BCM_MOD_INIT_CER(unit, rtn, dispname, init) {                      \
    562     if (init) {                                                             \
    563         sal_usecs_t stime, etime;                                           \
    564         int         rv;                                                     \
    565         LOG_VERBOSE(BSL_LS_BCM_COMMON,                                      \
    566                     (BSL_META_U(unit,                                       \
    567                                 "bcm_init: (%s)\n"),                        \
    568                                 shr_bprof_stats_name(dispname)));           \
    569         stime = sal_time_usecs();                                           \
    570         SHR_BPROF_STATS_TIME(dispname) {                                    \
    571             rv = rtn(unit);                                                 \
    572             BCM_CHECK_ERROR_RETURN(rv, dispname);                           \
    573         }                                                                   \
    574         etime = sal_time_usecs();                                           \
    575         LOG_VERBOSE(BSL_LS_BCM_COMMON,                                      \
    576                     (BSL_META_U(unit,                                       \
    577                                 "bcm_init: %8s   took %10d usec\n"),        \
    578                                 shr_bprof_stats_name(dispname),             \
    579                      SAL_USECS_SUB(etime, stime)));                         \
    580             _bcm_th3_modules_init_time += SAL_USECS_SUB(etime, stime);      \
    581     } else {                                                                \
    582         LOG_WARN(BSL_LS_BCM_INIT,                                           \
    583                  (BSL_META_U(unit,                                          \
    584                              "bcm_init: skipped %s init\n"),                \
    585                              shr_bprof_stats_name(dispname)));              \
    586     }                                                                       \
    587 }
    588 #endif
    589 
    590 #ifdef INCLUDE_TCL
    591 #define _BCM_MOD_INIT_IER(unit, rtn, dispname, init) {                      \
    592     if (init) {                                                             \
    593         sal_usecs_t stime, etime;                                           \
    594         int         rv;                                                     \
    595         LOG_VERBOSE(BSL_LS_BCM_COMMON,                                      \
    596                     (BSL_META_U(unit,                                       \
    597                                 "bcm_init: (%s)\n"),                        \
    598                                 shr_bprof_stats_name(dispname)));           \
    599         stime = sal_time_usecs();                                           \
    600         SHR_BPROF_STATS_TIME(dispname) {                                    \
    601             rv = rtn(unit);                                                 \
    602             BCM_IF_ERROR_RETURN(rv);                                        \
    603         }                                                                   \
    604         etime = sal_time_usecs();                                           \
    605         if (SOC_WARM_BOOT(unit)) {                                          \
    606             LOG_CLI((BSL_META_U(unit,                                       \
    607                                 "bcm_init: %8s   took %10d usec\n"),        \
    608                      shr_bprof_stats_name(dispname),                        \
    609                      SAL_USECS_SUB(etime, stime)));                         \
    610             _bcm_th3_modules_init_time += SAL_USECS_SUB(etime, stime);      \
    611         } else {                                                            \
    612             LOG_VERBOSE(BSL_LS_BCM_COMMON,                                  \
    613                         (BSL_META_U(unit,                                   \
    614                                     "bcm_init: %8s   took %10d usec\n"),    \
    615                          shr_bprof_stats_name(dispname),                    \
    616                          SAL_USECS_SUB(etime, stime)));                     \
    617             _bcm_th3_modules_init_time += SAL_USECS_SUB(etime, stime);      \
    618         }                                                                   \
    619     } else {                                                                \
    620         LOG_WARN(BSL_LS_BCM_INIT,                                           \
    621                  (BSL_META_U(unit,                                          \
    622                              "bcm_init: skipped %s init\n"),                \
    623                              shr_bprof_stats_name(dispname)));              \
    624     }                                                                       \
    625 }
    626 #else
    627 #define _BCM_MOD_INIT_IER(unit, rtn, dispname, init) {                      \
    628     if (init) {                                                             \
    629         sal_usecs_t stime, etime;                                           \
    630         int         rv;                                                     \
    631         LOG_VERBOSE(BSL_LS_BCM_COMMON,                                      \
    632                     (BSL_META_U(unit,                                       \
    633                                 "bcm_init: (%s)\n"),                        \
    634                                 shr_bprof_stats_name(dispname)));           \
    635         stime = sal_time_usecs();                                           \
    636         SHR_BPROF_STATS_TIME(dispname) {                                    \
    637             rv = rtn(unit);                                                 \
    638             BCM_IF_ERROR_RETURN(rv);                                        \
    639         }                                                                   \
    640         etime = sal_time_usecs();                                           \
    641         LOG_VERBOSE(BSL_LS_BCM_COMMON,                                      \
    642                     (BSL_META_U(unit,                                       \
    643                                 "bcm_init: %8s   took %10d usec\n"),        \
    644                                 shr_bprof_stats_name(dispname),             \
    645                      SAL_USECS_SUB(etime, stime)));                         \
    646             _bcm_th3_modules_init_time += SAL_USECS_SUB(etime, stime);      \
    647     } else {                                                                \
    648         LOG_WARN(BSL_LS_BCM_INIT,                                           \
    649                  (BSL_META_U(unit,                                          \
    650                              "bcm_init: skipped %s init\n"),                \
    651                              shr_bprof_stats_name(dispname)));              \
    652     }                                                                       \
    653 }
    654 #endif
    655 
    656 /*
    657  * Function:
    658  *	_bcm_modules_init
    659  * Purpose:
    660  * 	Initialize bcm modules
    661  * Parameters:
    662  *	unit - StrataSwitch unit #.
    663  *      flags - Combination of bit selectors (see init.h)
    664  * Returns:
    665  *	BCM_E_XXX
    666  */
    667 
    668 STATIC int
    669 _bcm_th3_modules_init(int unit)
    670 {
    671     int init_cond, init_cond2; /* init condition */
    672     bcm_port_t port_iter;
    673     sal_usecs_t _bcm_th3_modules_init_time = 0;
    674 
    675     SHR_BPROF_STATS_DECL;
    676     /*
    677      * Initialize each bcm module
    678      */
    679 
    680     if (!SOC_UNIT_VALID(unit)) {
    681 	return BCM_E_UNIT;
    682     }
    683 
    684     /* Only Tx and Rx modules will be initialized if attaching early
    685      * during warmboot to minimize CPU TX/RX inactivity time.
    686      */
    687     if (BCM_CONTROL(unit)->attach_state == _bcmControlStateTxRxInit) {
    688 #ifdef INCLUDE_KNET
    689         _BCM_MOD_INIT_CER(unit, bcm_esw_knet_init, SHR_BPROF_BCM_KNET, TRUE);
    690 #endif
    691         _BCM_MOD_INIT_CER(unit, bcm_esw_tx_init, SHR_BPROF_BCM_TX, TRUE);
    692         _BCM_MOD_INIT_CER(unit, bcm_esw_rx_init, SHR_BPROF_BCM_RX, TRUE);
    693 
    694         return BCM_E_NONE;
    695     }
    696 
    697     /* Must call mbcm init first to ensure driver properly installed */
    698     BCM_IF_ERROR_RETURN(mbcm_init(unit));
    699 
    700 #if defined(BCM_WARM_BOOT_SUPPORT)    
    701     if (SOC_WARM_BOOT(unit) && !SOC_IS_XGS12_FABRIC(unit)) {
    702         /* Init local module id. */
    703         BCM_IF_ERROR_RETURN(bcm_esw_reload_stk_my_modid_get(unit));
    704     }
    705 #endif /* BCM_WARM_BOOT_SUPPORT */
    706 
    707     /* When adding new modules, double check init condition 
    708      *  TRUE      - init the module always
    709      *  init_cond - Conditional init based on boot flags/soc properties
    710      */
    711 #ifdef BCM_TRIUMPH_SUPPORT
    712     if (soc_feature(unit, soc_feature_virtual_switching) ||
    713         soc_feature(unit, soc_feature_gport_service_counters) ||
    714         soc_feature(unit, soc_feature_fast_init) ||
    715         soc_feature(unit, soc_feature_int_common_init)){
    716         /* Initialize the common data module here to avoid multiple
    717          * initializations in the required modules. */
    718         _BCM_MOD_INIT_CER(unit, _bcm_common_init, SHR_BPROF_BCM_COMMON, TRUE);
    719     }
    720 #endif /* BCM_TRIUMPH_SUPPORT */
    721 
    722     _BCM_MOD_INIT_CER(unit, bcm_esw_port_init, SHR_BPROF_BCM_PORT, TRUE);
    723 
    724     /* If we're in fast reboot, we warmbooted up until this point. Cold boot
    725      * as much as we can from this point on */
    726     if (SOC_FAST_REBOOT(unit)) {
    727         SOC_WARM_BOOT_DONE(unit);
    728 
    729         /* Disable traffic and drain MMU */
    730         PBMP_PORT_ITER(unit, port_iter) {
    731             BCM_IF_ERROR_RETURN(bcm_esw_port_control_set(unit, port_iter,
    732                         bcmPortControlMmuTrafficEnable, FALSE));
    733             /* In TH3, MMU is drained when queuing is disabled. No need to do
    734              * bcmPortControlMmuDrain, BUT PROBABLY NEED TO IN OTHER DEVICES! */
    735         }
    736 
    737         BCM_IF_ERROR_RETURN(soc_mmu_init(unit));
    738     }
    739 
    740     /* switch to default miim intr mode from polling mode after port init done */
    741     SOC_CONTROL(unit)->miimIntrEnb = soc_property_get(unit,
    742             spn_MIIM_INTR_ENABLE, 1);
    743     init_cond = (!(SAL_BOOT_SIMULATION &&
    744                    soc_property_get(unit, spn_SKIP_L2_VLAN_INIT, 0)));
    745 
    746     _BCM_MOD_INIT_CER(unit, bcm_esw_stg_init, SHR_BPROF_BCM_STG, TRUE);
    747 
    748     _BCM_MOD_INIT_CER(
    749         unit, bcm_tomahawk3_l2_init, SHR_BPROF_BCM_L2, init_cond);
    750 
    751 
    752     _BCM_MOD_INIT_CER(
    753         unit, bcm_tomahawk3_vlan_init, SHR_BPROF_BCM_VLAN, init_cond);
    754     init_cond = (!(SAL_BOOT_SIMULATION &&
    755                    soc_property_get(unit, "skip_trunk_init", 0)));
    756     _BCM_MOD_INIT_CER(unit, bcm_esw_trunk_init, SHR_BPROF_BCM_TRUNK, init_cond);
    757 
    758     init_cond  = soc_property_get(unit, "init_all_modules",
    759                                   (SAL_BOOT_BCMSIM) || (!SAL_BOOT_SIMULATION));
    760     init_cond2 = init_cond || (soc_property_get(unit, "skip_cosq_init",
    761                                                 0) ? FALSE : TRUE);
    762     _BCM_MOD_INIT_CER(unit, bcm_esw_cosq_init, SHR_BPROF_BCM_COSQ, init_cond2);
    763 
    764     init_cond2 = init_cond || (!soc_property_get(unit, "skip_mcast_init", 0));
    765     _BCM_MOD_INIT_CER(unit, bcm_esw_mcast_init, SHR_BPROF_BCM_MCAST, init_cond2);
    766 
    767     _BCM_MOD_INIT_CER(unit, bcm_esw_linkscan_init, SHR_BPROF_BCM_LINKSCAN, TRUE);
    768 
    769 #ifdef SW_AUTONEG_SUPPORT
    770     if (soc_feature(unit, soc_feature_sw_autoneg)) {
    771         _BCM_MOD_INIT_CER(unit, bcm_sw_an_module_init, SHR_BPROF_BCM_SW_AN, TRUE);
    772     }
    773 #endif
    774 
    775     _BCM_MOD_INIT_CER(unit, bcm_esw_stat_init, SHR_BPROF_BCM_STAT, TRUE);
    776 #ifdef INCLUDE_KNET
    777     /* KNET module already initialized during early attach */
    778     if (BCM_CONTROL(unit)->attach_state != _bcmControlStateTxRxInited) {
    779         _BCM_MOD_INIT_CER(unit, bcm_esw_knet_init, SHR_BPROF_BCM_KNET, init_cond);
    780     }
    781 #endif
    782     if (SOC_MEM_IS_VALID(unit, FP_UDF_TCAMm)) {
    783         _BCM_MOD_INIT_CER(unit, bcm_esw_udf_init, SHR_BPROF_BCM_UDF, TRUE);
    784     }
    785 #ifdef BCM_FIELD_SUPPORT
    786     if (SOC_MEM_IS_VALID(unit, IFP_RANGE_CHECKm)) {
    787         _BCM_MOD_INIT_IER(unit, bcm_esw_range_init, SHR_BPROF_BCM_RANGE, TRUE);
    788     }
    789 
    790     init_cond2 = init_cond && (!soc_property_get(unit, "skip_field_init", 0));
    791     if (soc_feature(unit, soc_feature_field)) {
    792         _BCM_MOD_INIT_IER(unit, bcm_esw_field_init, SHR_BPROF_BCM_FIELD,
    793                           TRUE);
    794     }
    795 #endif
    796     init_cond2 = init_cond || (soc_property_get(unit, "skip_mirror_init", 
    797                                                 0) ? FALSE : TRUE);
    798     _BCM_MOD_INIT_CER(unit, bcm_esw_mirror_init, SHR_BPROF_BCM_MIRROR, init_cond2);
    799     /* TX module already initialized during early attach */
    800     if (BCM_CONTROL(unit)->attach_state != _bcmControlStateTxRxInited) {
    801         _BCM_MOD_INIT_CER(unit, bcm_esw_tx_init, SHR_BPROF_BCM_TX, TRUE);
    802     }
    803 
    804     /* RX init is done in phases during early attach */
    805     _BCM_MOD_INIT_CER(unit, bcm_esw_rx_init, SHR_BPROF_BCM_RX, TRUE);
    806 
    807 #ifdef INCLUDE_L3
    808     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset)) {
    809         _BCM_MOD_INIT_IER(unit, bcm_esw_failover_init, SHR_BPROF_BCM_FAILOVER, TRUE);
    810     }
    811 
    812     if (soc_feature(unit, soc_feature_l3) && soc_property_get(unit, spn_L3_ENABLE, 1)) {
    813         init_cond2 = init_cond || (!soc_property_get(unit, "skip_l3_init", 0));
    814         _BCM_MOD_INIT_IER(unit, bcm_esw_l3_init, SHR_BPROF_BCM_L3, init_cond2);
    815     }
    816     if (soc_feature(unit, soc_feature_ip_mcast)) {
    817         init_cond2 = init_cond || (!soc_property_get(unit, "skip_ipmc_init", 0));
    818         _BCM_MOD_INIT_IER(unit, bcm_esw_ipmc_init, SHR_BPROF_BCM_IPMC, init_cond2);
    819     }
    820 
    821 #endif
    822 
    823 #if defined(BCM_MPLS_SUPPORT) && defined(INCLUDE_L3)
    824     if (soc_feature(unit, soc_feature_mpls)) {
    825         init_cond2 = init_cond || (!soc_property_get(unit, "skip_mpls_init", 0));
    826         _BCM_MOD_INIT_IER(unit, bcm_esw_mpls_init, SHR_BPROF_BCM_MPLS, init_cond2);
    827     }
    828 #endif
    829 
    830     if (soc_feature(unit, soc_feature_qos_profile)) {
    831         init_cond2 = init_cond || (!soc_property_get(unit, "skip_qos_init", 0));
    832         _BCM_MOD_INIT_IER(unit, bcm_esw_qos_init, SHR_BPROF_BCM_QOS, init_cond2);
    833     }
    834 #ifdef INCLUDE_L3
    835     if (soc_feature(unit, soc_feature_flex_flow)) {
    836         _BCM_MOD_INIT_IER(unit, bcm_esw_flow_init, SHR_BPROF_BCM_FLOW, init_cond);
    837     }
    838     if (soc_feature(unit, soc_feature_port_extension)) {
    839         _BCM_MOD_INIT_IER(unit, bcm_esw_extender_init, SHR_BPROF_BCM_EXTENDER, init_cond);
    840     }
    841 
    842     /* This must be after the modules upon which it is build, in order
    843      * for Warm Boot to operate correctly. */
    844     _BCM_MOD_INIT_IER(unit, bcm_esw_multicast_init, SHR_BPROF_BCM_MULTICAST, TRUE);
    845 
    846 #endif
    847 
    848 #ifdef BCM_FIELD_SUPPORT
    849     if (soc_feature(unit, soc_feature_field)) {
    850          init_cond2 = init_cond && (!soc_property_get(unit, "skip_auth_init", 0));
    851         _BCM_MOD_INIT_IER(unit, bcm_esw_auth_init, SHR_BPROF_BCM_AUTH, init_cond2);
    852     }
    853 #endif
    854 #ifdef INCLUDE_REGEX
    855     if (soc_feature(unit, soc_feature_regex)) {
    856         _BCM_MOD_INIT_IER(unit, bcm_esw_regex_init, SHR_BPROF_BCM_REGEX, init_cond);
    857     }
    858 #endif
    859     if (soc_feature(unit, soc_feature_time_support)) {
    860         _BCM_MOD_INIT_IER(unit, bcm_esw_time_init, SHR_BPROF_BCM_TIME, TRUE);
    861     }
    862 
    863 #ifdef BCM_INSTRUMENTATION_SUPPORT
    864     if (soc_feature(unit, soc_feature_visibility)) {
    865         BCM_IF_ERROR_RETURN(bcm_esw_pkt_trace_init(unit));
    866     }
    867 #endif
    868 #ifdef INCLUDE_PTP
    869     if (soc_feature(unit, soc_feature_ptp)) {
    870 	_BCM_MOD_INIT_IER(unit, bcm_esw_ptp_init, SHR_BPROF_BCM_PTP, init_cond);
    871     }
    872 #endif
    873 #ifdef INCLUDE_BFD
    874     if (soc_feature(unit, soc_feature_bfd)) {
    875 	_BCM_MOD_INIT_IER(unit, bcm_esw_bfd_init, SHR_BPROF_BCM_BFD, init_cond);
    876     }
    877 #endif
    878 #if defined(BCM_KATANA_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    879     /* Service meter */
    880     if (soc_feature(unit, soc_feature_global_meter)) {
    881         _BCM_MOD_INIT_IER(unit, bcm_esw_global_meter_init,
    882                           SHR_BPROF_BCM_GLB_METER, init_cond);
    883     }
    884 #endif /* BCM_KATANA_SUPPORT  or BCM_TRIUMPH3_SUPPORT */
    885 #if defined(BCM_TSN_SUPPORT)
    886     if (soc_feature(unit, soc_feature_tsn)){
    887         _BCM_MOD_INIT_CER(unit, bcm_esw_tsn_init, SHR_BPROF_BCM_TSN, TRUE);
    888     }
    889 #endif /* BCM_TSN_SUPPORT */
    890 
    891     BCM_IF_ERROR_RETURN(bcm_th_phy_lb_set(unit));
    892 
    893     if (soc_feature(unit, soc_feature_latency_monitor)) {
    894         _BCM_MOD_INIT_IER(unit, bcm_tomahawk3_latency_monitor_init,
    895                           SHR_BPROF_BCM_LATENCY_MONITOR, TRUE);
    896     }
    897 
    898     if (soc_feature(unit, soc_feature_hw_etrap)) {
    899         _BCM_MOD_INIT_IER(unit, bcm_tomahawk3_flowtracker_init,
    900                           SHR_BPROF_BCM_FT, TRUE);
    901     }
    902 
    903 #if defined(BCM_COLLECTOR_SUPPORT)
    904     if (soc_feature(unit, soc_feature_collector)) {
    905         _BCM_MOD_INIT_IER(unit, bcm_esw_collector_init, SHR_BPROF_BCM_COLLECTOR,
    906                           TRUE);
    907     }
    908 #endif
    909 
    910 #ifdef INCLUDE_INT
    911     if (soc_feature(unit, soc_feature_uc_int_turnaround)) {
    912         _BCM_MOD_INIT_IER(unit, bcm_tomahawk3_int_init, SHR_BPROF_BCM_INT, TRUE);
    913     }
    914 #endif
    915 
    916 #ifdef INCLUDE_SUM
    917     if (soc_feature(unit, soc_feature_sum)) {
    918         _BCM_MOD_INIT_IER(unit, bcm_tomahawk3_sum_init, SHR_BPROF_BCM_SUM, TRUE);
    919     }
    920 #endif
    921 
    922 #if defined(BCM_TIMESYNC_TIME_CAPTURE_SUPPORT)
    923     BCM_IF_ERROR_RETURN(bcm_esw_time_capture_ts_init(unit));
    924 #endif /* BCM_TIMESYNC_TIME_CAPTURE_SUPPORT */
    925 
    926     if (SOC_WARM_BOOT(unit) || SOC_FAST_REBOOT(unit)) {
    927         LOG_CLI((BSL_META_U(unit,
    928                  "bcm_init all modules took %10d usec\n"),
    929                  _bcm_th3_modules_init_time));
    930     } else {
    931         LOG_VERBOSE(BSL_LS_BCM_COMMON, (BSL_META_U(unit,
    932                     "bcm_init all modules took %10d usec\n"),
    933                     _bcm_th3_modules_init_time));
    934     }
    935 
    936     if (SOC_FAST_REBOOT(unit)) {
    937         /* Re-enable traffic to the MMU after it has been reset */
    938         PBMP_PORT_ITER(unit, port_iter) {
    939             BCM_IF_ERROR_RETURN(bcm_esw_port_control_set(unit, port_iter,
    940                         bcmPortControlMmuTrafficEnable, TRUE));
    941             /* In TH3, MMU is drained when queuing is disabled. No need to do
    942              * bcmPortControlMmuDrain, BUT PROBABLY NEED TO IN OTHER DEVICES! */
    943         }
    944     }
    945 
    946     return BCM_E_NONE;
    947 }
    948 
    949 #if defined(BCM_XGS3_SWITCH_SUPPORT)
    950 #ifdef BCM_WARM_BOOT_SUPPORT
    951 
    952 STATIC int
    953 _bcm_th3_mem_scache_init(int unit)
    954 {
    955     SOC_IF_ERROR_RETURN(soc_mem_cache_scache_init(unit));
    956     return BCM_E_NONE;
    957 }
    958 
    959 STATIC int 
    960 _bcm_th3_switch_control_scache_init(int unit)
    961 {
    962     return soc_switch_control_scache_init(unit);
    963 }
    964 
    965 #endif /* BCM_WARM_BOOT_SUPPORT */
    966 #endif /* defined(BCM_XGS3_SWITCH_SUPPORT) */
    967 
    968 /*
    969  * Function:
    970  *	_bcm_th3_init
    971  * Purpose:
    972  * 	Initialize the BCM API layer only, without resetting the switch chip.
    973  * Parameters:
    974  *	unit - StrataSwitch unit #.
    975  * Returns:
    976  *	BCM_E_XXX
    977  */
    978 
    979 STATIC int
    980 _bcm_th3_init(int unit)
    981 {
    982 
    983     int warmboot_post_config = FALSE;
    984 
    985     BCM_IF_ERROR_RETURN(_bcm_th3_lock_init(unit));
    986 
    987     /* Skip rest of the initialization if early attaching */
    988     if (BCM_CONTROL(unit)->attach_state == _bcmControlStateTxRxInit) {
    989         if(SOC_WARM_BOOT(unit)) {
    990             return (_bcm_th3_modules_init(unit));
    991         } else {
    992             /* Not supported if not warm booting */
    993             return BCM_E_CONFIG;
    994         }
    995     }
    996 
    997     SOC_CONTROL(unit)->soc_flags &= ~SOC_F_ALL_MODULES_INITED;
    998 
    999     /* If linkscan is running, disable it. */
   1000     bcm_esw_linkscan_enable_set(unit, 0);
   1001 
   1002 #ifdef INCLUDE_MACSEC
   1003     BCM_IF_ERROR_RETURN(_bcm_common_macsec_init(unit)); 
   1004 #endif /* INCLUDE_MACSEC */
   1005 
   1006 #ifdef INCLUDE_FCMAP
   1007     BCM_IF_ERROR_RETURN(_bcm_common_fcmap_init(unit)); 
   1008 #endif /* INCLUDE_FCMAP */
   1009 
   1010 #if defined(BCM_XGS3_SWITCH_SUPPORT)
   1011 #ifdef BCM_WARM_BOOT_SUPPORT
   1012     /* switch global warmboot state init/reinit */
   1013     BCM_IF_ERROR_RETURN(_bcm_th3_switch_control_scache_init(unit));
   1014 
   1015     /* mem cache warmboot state init/reinit */
   1016     BCM_IF_ERROR_RETURN(_bcm_th3_mem_scache_init(unit));
   1017 
   1018 
   1019 #endif /* BCM_WARM_BOOT_SUPPORT */
   1020 #endif /* defined(BCM_XGS3_SWITCH_SUPPORT) */
   1021 
   1022     BCM_IF_ERROR_RETURN(_bcm_th3_modules_init(unit));
   1023 
   1024 #ifdef BCM_XGS3_SWITCH_SUPPORT
   1025     BCM_IF_ERROR_RETURN(_bcm_esw_switch_init(unit));
   1026 #endif
   1027 
   1028     if (SOC_WARM_BOOT(unit)) {
   1029         warmboot_post_config = TRUE;
   1030         SOC_WARM_BOOT_DONE(unit);
   1031     }
   1032 
   1033     if (SOC_FAST_REBOOT(unit)) {
   1034         SOC_FAST_REBOOT_DONE(unit);
   1035     }
   1036 
   1037     if (warmboot_post_config == TRUE) {
   1038         /* To avoid acctidently reconfigure hardware, write to register is
   1039            bypassed during the warm boot until SOC_WARM_BOOT_DONE */
   1040         /* for the cases that we do need to reconfigure hardware, we do it here */
   1041 #if defined(BCM_TOMAHAWK_SUPPORT)
   1042         if (SOC_IS_TOMAHAWKX(unit)) { 
   1043             if (soc_property_get(unit, "ctr_evict_enable", 1) &&
   1044                 (SOC_CONTROL(unit)->counter_interval > 0)) {
   1045                 /* Clear all previously accumulated counter value in SW */
   1046                 soc_counter_ctr_reset_to_zero(unit);
   1047                 /* WB done. Set counter to Evition mode */
   1048                 SOC_IF_ERROR_RETURN
   1049                     (soc_ctr_evict_start(unit, 0,
   1050                                          SOC_CONTROL(unit)->counter_interval));
   1051             }
   1052         }
   1053 #endif
   1054 
   1055 #ifdef BCM_WARM_BOOT_SUPPORT
   1056 #if defined(BCM_TOMAHAWK3_SUPPORT)
   1057         if ((SOC_IS_TOMAHAWK3(unit)) && 
   1058             (soc_feature(unit, soc_feature_latency_monitor))) {
   1059             SOC_IF_ERROR_RETURN(_bcm_th3_latency_monitor_wb_post_init(unit));
   1060         }
   1061 #endif /* BCM_TOMAHAWK3_SUPPORT */
   1062 #endif /* BCM_WARM_BOOT_SUPPORT */
   1063     }
   1064 
   1065 #if defined(BCM_RCPU_SUPPORT) && defined(BCM_XGS3_SWITCH_SUPPORT)
   1066     BCM_IF_ERROR_RETURN(_bcm_esw_rcpu_init(unit)); 
   1067 #endif /* BCM_RCPU_SUPPORT && BCM_XGS3_SWITCH_SUPPORT */
   1068 
   1069     SOC_CONTROL(unit)->soc_flags |= SOC_F_ALL_MODULES_INITED;
   1070     if (SOC_HW_RESET(unit)) {
   1071         SOC_HW_RESET_DONE(unit);
   1072     }
   1073 
   1074     return BCM_E_NONE;
   1075 }    
   1076 
   1077 /*
   1078  * Function:
   1079  *	bcm_tomahawk3_init
   1080  * Purpose:
   1081  * 	Initialize the BCM API layer only, without resetting the switch chip.
   1082  * Parameters:
   1083  *	unit - StrataSwitch unit #.
   1084  * Returns:
   1085  *	BCM_E_XXX
   1086  */
   1087 
   1088 int
   1089 bcm_tomahawk3_init(int unit)
   1090 {
   1091     if (0 == SOC_UNIT_VALID(unit)) {
   1092         return BCM_E_UNIT;
   1093     }
   1094     return _bcm_th3_init(unit);
   1095 }    
   1096 
   1097 /*      _bcm_th3_attach
   1098  * Purpose:
   1099  *      Attach and initialize bcm device
   1100  * Parameters:
   1101  *      unit - unit being detached
   1102  * Returns:
   1103  *    BCM_E_XXX
   1104  */
   1105 int
   1106 _bcm_th3_attach(int unit, char *subtype)
   1107 {
   1108     int  dunit;
   1109     int  rv;
   1110 
   1111     COMPILER_REFERENCE(subtype);
   1112 
   1113     BCM_CONTROL(unit)->capability |= BCM_CAPA_LOCAL;
   1114     dunit = BCM_CONTROL(unit)->unit;
   1115 
   1116     /* Initialize soc layer */
   1117     if ((NULL == SOC_CONTROL(dunit)) || 
   1118         (0 == (SOC_CONTROL(dunit)->soc_flags & SOC_F_ATTACHED))) {
   1119         return (BCM_E_INIT);
   1120     }
   1121     
   1122     if (SAL_THREAD_ERROR == SOC_CONTROL(dunit)->counter_pid) {
   1123         rv = soc_counter_attach(unit);
   1124         BCM_IF_ERROR_RETURN(rv);
   1125     }
   1126 
   1127     /* Initialize bcm layer */
   1128     BCM_CONTROL(unit)->chip_vendor = SOC_PCI_VENDOR(dunit);
   1129     BCM_CONTROL(unit)->chip_device = SOC_PCI_DEVICE(dunit);
   1130     BCM_CONTROL(unit)->chip_revision = SOC_PCI_REVISION(dunit);
   1131     if (SOC_IS_XGS_SWITCH(dunit)) {
   1132         BCM_CONTROL(unit)->capability |= BCM_CAPA_SWITCH;
   1133     }
   1134     if (SOC_IS_XGS_FABRIC(dunit)) {
   1135         BCM_CONTROL(unit)->capability |= BCM_CAPA_FABRIC;
   1136     }
   1137     if (soc_feature(dunit, soc_feature_l3)) {
   1138         BCM_CONTROL(unit)->capability |= BCM_CAPA_L3;
   1139     }
   1140     if (soc_feature(dunit, soc_feature_ip_mcast)) {
   1141         BCM_CONTROL(unit)->capability |=
   1142             BCM_CAPA_IPMC;
   1143     }
   1144 
   1145     /* Initialize port mappings */
   1146     _bcm_api_xlate_port_init(unit);
   1147 
   1148     rv = _bcm_th3_init(unit);
   1149     return (rv);
   1150 }
   1151 
   1152 int
   1153 _bcm_tomahawk3_attach(int unit, char *subtype)
   1154 {
   1155     return _bcm_th3_attach(unit, subtype);
   1156 }
   1157 
   1158 /*      _bcm_th3_match
   1159  * Purpose:
   1160  *      match BCM control subtype strings for ESW types 
   1161  * Parameters:
   1162  *      unit - unit being detached
   1163  * Returns:
   1164  *    0 match
   1165  *    !0 no match
   1166  */
   1167 int
   1168 _bcm_th3_match(int unit, char *subtype_a, char *subtype_b)
   1169 {
   1170     COMPILER_REFERENCE(unit);
   1171     return sal_strcmp(subtype_a, subtype_b);
   1172 }
   1173 
   1174 
   1175 int
   1176 _bcm_tomahawk3_match(int unit, char *subtype_a, char *subtype_b)
   1177 {
   1178     return _bcm_th3_match(unit, subtype_a, subtype_b);
   1179 }
   1180 /*
   1181  * Function:
   1182  *	bcm_th3_init_selective
   1183  * Purpose:
   1184  * 	Initialize specific bcm modules as desired.
   1185  * Parameters:
   1186  *	unit - StrataSwitch unit #.
   1187  *    module_number - Indicate module number
   1188  * Returns:
   1189  *	BCM_E_XXX
   1190  */
   1191 
   1192 int
   1193 bcm_th3_init_selective(int unit, uint32 module_number)
   1194 {
   1195     switch (module_number) {
   1196          case BCM_MODULE_PORT     :
   1197                    BCM_IF_ERROR_RETURN(bcm_esw_port_init(unit));
   1198                    break;
   1199          case BCM_MODULE_L2       :
   1200                    BCM_IF_ERROR_RETURN(bcm_esw_l2_init(unit));
   1201                    break;
   1202          case BCM_MODULE_VLAN     :   
   1203                    BCM_IF_ERROR_RETURN(bcm_esw_vlan_init(unit));
   1204                    break;
   1205          case BCM_MODULE_TRUNK    :
   1206                    BCM_IF_ERROR_RETURN(bcm_esw_trunk_init(unit));
   1207                    break;
   1208          case BCM_MODULE_COSQ     :
   1209                    BCM_IF_ERROR_RETURN(bcm_esw_cosq_init(unit));
   1210                    break;
   1211          case BCM_MODULE_MCAST        :
   1212                    BCM_IF_ERROR_RETURN(bcm_esw_mcast_init(unit));
   1213                    break;
   1214          case BCM_MODULE_LINKSCAN  :
   1215                    BCM_IF_ERROR_RETURN(bcm_esw_linkscan_init(unit));
   1216                    break;
   1217          case BCM_MODULE_STAT     :
   1218                    BCM_IF_ERROR_RETURN(bcm_esw_stat_init(unit));
   1219                    break;
   1220          case BCM_MODULE_MIRROR   :
   1221                    BCM_IF_ERROR_RETURN(bcm_esw_mirror_init(unit));
   1222                    break;
   1223 #ifdef INCLUDE_L3
   1224          case BCM_MODULE_L3       :
   1225                    BCM_IF_ERROR_RETURN(bcm_esw_l3_init(unit));
   1226                    break;
   1227          case BCM_MODULE_IPMC 	:
   1228                    BCM_IF_ERROR_RETURN(bcm_esw_ipmc_init(unit));
   1229                    break;
   1230 #ifdef BCM_MPLS_SUPPORT
   1231          case BCM_MODULE_MPLS	 :
   1232                    BCM_IF_ERROR_RETURN(bcm_esw_mpls_init(unit));
   1233                    break;
   1234 #endif /* BCM_MPLS_SUPPORT */
   1235          case BCM_MODULE_SUBPORT	:
   1236                    BCM_IF_ERROR_RETURN(bcm_esw_subport_init(unit));
   1237                    break;
   1238 #endif /* INCLUDE_L3 */
   1239          case BCM_MODULE_QOS		:
   1240                    BCM_IF_ERROR_RETURN(bcm_esw_qos_init(unit));
   1241                    break;
   1242          case BCM_MODULE_STG      :
   1243                    BCM_IF_ERROR_RETURN(bcm_esw_stg_init(unit));
   1244                    break;
   1245          case BCM_MODULE_TX       :
   1246                    BCM_IF_ERROR_RETURN(bcm_esw_tx_init(unit));
   1247                    break;
   1248 #ifdef BCM_FIELD_SUPPORT
   1249          case BCM_MODULE_AUTH     :
   1250                    BCM_IF_ERROR_RETURN(bcm_esw_auth_init(unit));
   1251                    break;
   1252 #endif
   1253          case BCM_MODULE_RX       :
   1254                    BCM_IF_ERROR_RETURN(bcm_esw_rx_init(unit));
   1255                    break;
   1256          case BCM_MODULE_UDF    :
   1257                    BCM_IF_ERROR_RETURN(bcm_esw_udf_init(unit));
   1258                    break;
   1259 #ifdef BCM_FIELD_SUPPORT
   1260          case BCM_MODULE_FIELD    :
   1261                    BCM_IF_ERROR_RETURN(bcm_esw_field_init(unit));
   1262                    break;
   1263 #endif /* BCM_FIELD_SUPPORT */
   1264          case BCM_MODULE_TIME     :
   1265                    BCM_IF_ERROR_RETURN(bcm_esw_time_init(unit));
   1266                    break;
   1267          case BCM_MODULE_POLICER  :
   1268                    break;
   1269 #ifdef  INCLUDE_L3
   1270          case BCM_MODULE_FAILOVER :
   1271                    BCM_IF_ERROR_RETURN(bcm_esw_failover_init(unit));
   1272                    break;
   1273 #endif
   1274          case BCM_MODULE_VSWITCH  :
   1275                    break;
   1276 #ifdef  INCLUDE_L3
   1277          case BCM_MODULE_MULTICAST:
   1278                    BCM_IF_ERROR_RETURN(bcm_esw_multicast_init(unit));
   1279                    break;
   1280          case BCM_MODULE_EXTENDER :
   1281                    BCM_IF_ERROR_RETURN(bcm_esw_extender_init(unit));
   1282                    break;
   1283          case BCM_MODULE_FLOW :
   1284                    BCM_IF_ERROR_RETURN(bcm_esw_flow_init(unit));
   1285                    break;
   1286 #endif
   1287 #ifdef INCLUDE_PTP
   1288          case BCM_MODULE_PTP:
   1289                    BCM_IF_ERROR_RETURN(bcm_esw_ptp_init(unit));
   1290                    break;
   1291 #endif 
   1292 #ifdef INCLUDE_BFD
   1293          case BCM_MODULE_BFD:
   1294                    BCM_IF_ERROR_RETURN(bcm_esw_bfd_init(unit));
   1295                    break;
   1296 #endif 
   1297 #ifdef INCLUDE_REGEX
   1298          case BCM_MODULE_REGEX :
   1299                    BCM_IF_ERROR_RETURN(bcm_esw_regex_init(unit));
   1300                    break;
   1301 #endif /* BCM_MPLS_SUPPORT */
   1302 #ifdef BCM_TSN_SUPPORT
   1303          case BCM_MODULE_TSN:
   1304                    BCM_IF_ERROR_RETURN(bcm_esw_tsn_init(unit));
   1305                    break;
   1306 #endif /* BCM_TSN_SUPPORT */
   1307          case BCM_MODULE_FLOWTRACKER:
   1308                    BCM_IF_ERROR_RETURN(bcm_tomahawk3_flowtracker_init(unit));
   1309                    break;
   1310 #ifdef INCLUDE_INT
   1311          case BCM_MODULE_INT:
   1312                    if (soc_feature(unit, soc_feature_uc_int_turnaround)) {
   1313                        BCM_IF_ERROR_RETURN(bcm_tomahawk3_int_init(unit));
   1314                    } else {
   1315                        return BCM_E_UNAVAIL;
   1316                    }
   1317                    break;
   1318 #endif /* BCM_INT_SUPPORT */
   1319 #ifdef INCLUDE_SUM
   1320          case BCM_MODULE_SUM:
   1321                    if (soc_feature(unit, soc_feature_sum)) {
   1322                        BCM_IF_ERROR_RETURN(bcm_tomahawk3_sum_init(unit));
   1323                    } else {
   1324                        return BCM_E_UNAVAIL;
   1325                    }
   1326                    break;
   1327 #endif /* INCLUDE_SUM */
   1328          case BCM_MODULE_LATENCY_MONITOR:
   1329                    BCM_IF_ERROR_RETURN(bcm_tomahawk3_latency_monitor_init(unit));
   1330                    break;
   1331          default:
   1332                    return BCM_E_UNAVAIL;
   1333     }
   1334     return BCM_E_NONE;
   1335 }
   1336 
   1337 /*
   1338  * ************* Deprecated API ************
   1339  * Function:
   1340  *	bcm_esw_init_check
   1341  * Purpose:
   1342  *	Return TRUE if bcm_esw_init_bcm has already been called and succeeded
   1343  * Parameters:
   1344  *	unit- StrataSwitch unit #.
   1345  * Returns:
   1346  *	TRUE or FALSE
   1347  */
   1348 int
   1349 bcm_th3_init_check(int unit)
   1350 {
   1351     return BCM_E_UNAVAIL;
   1352 }
   1353 
   1354 
   1355 /*
   1356  * Function:
   1357  *      _bcm_esw_detach
   1358  * Purpose:
   1359  *      Clean up bcm layer when unit is detached
   1360  * Parameters:
   1361  *      unit - unit being detached
   1362  * Returns:
   1363  *	BCM_E_XXX
   1364  */
   1365 int
   1366 _bcm_th3_detach(int unit)
   1367 {
   1368     int rv;                    /* Operation return status. */
   1369 
   1370     /* Shut down all the spawned threads. */
   1371     /* Threads should have been killed during the initial detach */
   1372     if (!(BCM_CONTROL(unit)->attach_state == _bcmControlStateDeinitAll)) {
   1373         rv = _bcm_th3_threads_shutdown(unit);
   1374         BCM_IF_ERROR_NOT_UNAVAIL_RETURN(rv);
   1375     }
   1376 
   1377     /* 
   1378      *  Don't move up, holding lock or disabling hw operations 
   1379      *  might prevent theads clean exit.
   1380      */
   1381     BCM_LOCK(unit);
   1382 
   1383     rv = _bcm_th3_modules_deinit(unit);
   1384 
   1385     BCM_IF_ERROR_NOT_UNAVAIL_RETURN(rv);
   1386 
   1387     return rv;
   1388 }
   1389 
   1390 int
   1391 _bcm_tomahawk3_detach(int unit)
   1392 {
   1393     return _bcm_th3_detach(unit);
   1394 }
   1395 /*
   1396  * Function:
   1397  *	bcm_esw_info_get
   1398  * Purpose:
   1399  *	Provide unit information to caller
   1400  * Parameters:
   1401  *	unit	- switch device
   1402  *	info	- (OUT) bcm unit info structure
   1403  * Returns:
   1404  *	BCM_E_XXX
   1405  */
   1406 int
   1407 bcm_th3_info_get(int unit, bcm_info_t *info)
   1408 {
   1409     uint16 dev_id = 0;
   1410     uint8 rev_id = 0;
   1411 
   1412     if (!SOC_UNIT_VALID(unit)) {
   1413 	return BCM_E_UNIT;
   1414     }
   1415     if (info == NULL) {
   1416 	return BCM_E_PARAM;
   1417     }
   1418     soc_cm_get_id(unit, &dev_id, &rev_id);
   1419     info->vendor = SOC_PCI_VENDOR(unit);
   1420     info->device = dev_id;
   1421     info->revision = rev_id;
   1422     info->capability = 0;
   1423     if (SOC_IS_XGS_FABRIC(unit) || SOC_IS_XGS_FABRIC_TITAN(unit)) {
   1424 	info->capability |= BCM_INFO_FABRIC;
   1425     } else {
   1426 	info->capability |= BCM_INFO_SWITCH;
   1427     }
   1428     if (soc_feature(unit, soc_feature_l3)) {
   1429 	info->capability |= BCM_INFO_L3;
   1430     }
   1431     if (soc_feature(unit, soc_feature_ip_mcast)) {
   1432 	info->capability |= BCM_INFO_IPMC;
   1433     }
   1434     info->num_pipes = NUM_PIPE(unit);
   1435     return BCM_E_NONE;
   1436 }
   1437 
   1438 
   1439 /* ASSUMES unit PARAMETER which is not in macro's list. */
   1440 #define CLEAR_CALL(_rtn, _name) {                                       \
   1441         int rv;                                                         \
   1442         rv = (_rtn)(unit);                                              \
   1443         if (rv < 0 && rv != BCM_E_UNAVAIL) {                            \
   1444             LOG_ERROR(BSL_LS_BCM_INIT, \
   1445                       (BSL_META_U(unit, \
   1446                                   "bcm_clear %d: %s failed %d. %s\n"),    \
   1447                                   unit, _name, rv, bcm_errmsg(rv)));              \
   1448             return rv;                                                  \
   1449         }                                                               \
   1450 }
   1451 
   1452 /*
   1453  * Function:
   1454  *      bcm_tomahawk3_clear
   1455  * Purpose:
   1456  *      Initialize a device without a full reset
   1457  * Parameters:
   1458  *      unit        - The unit number of the device to clear
   1459  * Returns:
   1460  *      BCM_E_XXX
   1461  * Notes:
   1462  *      For each module, call the underlying init/clear operation
   1463 */
   1464 int
   1465 bcm_tomahawk3_clear(int unit)
   1466 {
   1467     return _bcm_th3_init(unit);
   1468 }