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

mbcm.c (13131B)


      1 /*
      2 
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7  *
      8  * File:        mbcm.c
      9  * Purpose:     Implementation of bcm multiplexing
     10  */
     11 
     12 
     13 #include <soc/defs.h>
     14 #include <shared/bsl.h>
     15 #include <bcm/error.h>
     16 
     17 #include <bcm_int/esw/mbcm.h>
     18 #include <bcm_int/esw_dispatch.h>
     19 
     20 #include <bcm_int/common/family.h>
     21 
     22 mbcm_functions_t	*mbcm_driver[BCM_MAX_NUM_UNITS];
     23 
     24 #if defined(BCM_TOMAHAWK_SUPPORT)
     25 static mbcm_functions_t *mbcm_l2_latency = NULL;
     26 static mbcm_functions_t *mbcm_l3_latency = NULL;
     27 static mbcm_functions_t *mbcm_normal_latency = NULL;
     28 static uint32 mbcm_ref[3] = {0}; /* ref cnt */
     29 
     30 STATIC int
     31 _bcm_esw_mbcm_init(int unit, mbcm_functions_t **mbcm);
     32 #endif
     33 
     34 
     35 /****************************************************************
     36  *
     37  * Function:        mbcm_init
     38  * Parameters:      unit   --   unit to setup
     39  * 
     40  * Initialize the mbcm driver for the indicated unit.
     41  */
     42 int
     43 mbcm_init(int unit)
     44 {
     45 #ifdef	BCM_HERCULES15_SUPPORT
     46     if (SOC_IS_HERCULES15(unit)) {
     47         mbcm_driver[unit] = &mbcm_hercules_driver;
     48         bcm_chip_family_set(unit, BCM_FAMILY_HERCULES); /* Should become H15 */
     49 	return BCM_E_NONE;
     50     }
     51 #endif	/* BCM_HERCULES15_SUPPORT */
     52 #ifdef	BCM_ALLLAYER_SUPPORT
     53     if (SOC_IS_ALLLAYER(unit)) {
     54         mbcm_driver[unit] = &mbcm_alllayer_driver;
     55         bcm_chip_family_set(unit, BCM_FAMILY_ALLLAYER);         
     56         return BCM_E_NONE;
     57     }
     58 #endif	/* BCM_ALLLAYER_SUPPORT */
     59 #ifdef	BCM_FIREBOLT_SUPPORT
     60     if (SOC_IS_FB_FX_HX(unit)) {
     61         mbcm_driver[unit] = &mbcm_firebolt_driver;
     62         bcm_chip_family_set(unit, BCM_FAMILY_FIREBOLT); 
     63 	return BCM_E_NONE;
     64     }
     65 #endif	/* BCM_FIREBOLT_SUPPORT */
     66 #ifdef	BCM_HB_GW_SUPPORT
     67     if (SOC_IS_BRADLEY(unit)) {
     68         mbcm_driver[unit] = &mbcm_bradley_driver;
     69         bcm_chip_family_set(unit, BCM_FAMILY_BRADLEY); 
     70 	return BCM_E_NONE;
     71     }
     72 #endif	/* BCM_BRADLEY_SUPPORT */
     73 #ifdef	BCM_GOLDWING_SUPPORT
     74     if (SOC_IS_GOLDWING(unit)) {
     75         mbcm_driver[unit] = &mbcm_bradley_driver;
     76         bcm_chip_family_set(unit, BCM_FAMILY_BRADLEY); 
     77         return BCM_E_NONE;
     78     }
     79 #endif	/* BCM_GOLDWING_SUPPORT */
     80 #ifdef	BCM_HUMV_SUPPORT
     81     if (SOC_IS_HUMV(unit)) {
     82         mbcm_driver[unit] = &mbcm_humv_driver;
     83         bcm_chip_family_set(unit, BCM_FAMILY_HUMV); 
     84         return BCM_E_NONE;
     85     }
     86 #endif	/* BCM_HUMV_SUPPORT */
     87 #ifdef	BCM_TRIUMPH_SUPPORT
     88     if (SOC_IS_TRIUMPH(unit)) {
     89         mbcm_driver[unit] = &mbcm_triumph_driver;
     90         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH); 
     91         return BCM_E_NONE;
     92     }
     93 #endif	/* BCM_TRIUMPH_SUPPORT */
     94 #ifdef	BCM_VALKYRIE_SUPPORT
     95     if (SOC_IS_VALKYRIE(unit)) {
     96         mbcm_driver[unit] = &mbcm_triumph_driver;
     97         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH); 
     98         return BCM_E_NONE;
     99     }
    100 #endif	/* BCM_VALKYRIE_SUPPORT */
    101 #ifdef	BCM_SCORPION_SUPPORT
    102     if (SOC_IS_SCORPION(unit)) {
    103         mbcm_driver[unit] = &mbcm_scorpion_driver;
    104         bcm_chip_family_set(unit, BCM_FAMILY_SCORPION); 
    105 	return BCM_E_NONE;
    106     }
    107 #endif	/* BCM_SCORPION_SUPPORT */
    108 #ifdef	BCM_CONQUEROR_SUPPORT
    109     if (SOC_IS_CONQUEROR(unit)) {
    110         mbcm_driver[unit] = &mbcm_conqueror_driver;
    111         bcm_chip_family_set(unit, BCM_FAMILY_CONQUEROR); 
    112 	return BCM_E_NONE;
    113     }
    114 #endif	/* BCM_CONQUEROR_SUPPORT */
    115 #ifdef	BCM_TRIUMPH2_SUPPORT
    116     if (SOC_IS_TRIUMPH2(unit)) {
    117         mbcm_driver[unit] = &mbcm_triumph2_driver;
    118         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH2); 
    119         return BCM_E_NONE;
    120     }
    121 #endif	/* BCM_TRIUMPH2_SUPPORT */
    122 #ifdef	BCM_APOLLO_SUPPORT
    123     if (SOC_IS_APOLLO(unit)) {
    124         mbcm_driver[unit] = &mbcm_triumph2_driver;
    125         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH2); 
    126         return BCM_E_NONE;
    127     }
    128 #endif	/* BCM_APOLLO_SUPPORT */
    129 #ifdef	BCM_VALKYRIE2_SUPPORT
    130     if (SOC_IS_VALKYRIE2(unit)) {
    131         mbcm_driver[unit] = &mbcm_triumph2_driver;
    132         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH2); 
    133         return BCM_E_NONE;
    134     }
    135 #endif	/* BCM_VALKYRIE2_SUPPORT */
    136 #ifdef	BCM_ENDURO_SUPPORT
    137     if (SOC_IS_ENDURO(unit)) {
    138         mbcm_driver[unit] = &mbcm_enduro_driver;
    139         
    140         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH); 
    141         return BCM_E_NONE;
    142     }
    143 #endif	/* BCM_ENDURO_SUPPORT */
    144 #ifdef BCM_SHADOW_SUPPORT
    145     if (SOC_IS_SHADOW(unit)) {
    146         mbcm_driver[unit] = &mbcm_conqueror_driver;
    147         bcm_chip_family_set(unit, BCM_FAMILY_CONQUEROR);
    148        return BCM_E_NONE;
    149     }
    150 #endif /* BCM_SHADOW_SUPPORT */
    151 #ifdef	BCM_TRIDENT_SUPPORT
    152     if (SOC_IS_TRIDENT(unit)) {
    153         mbcm_driver[unit] = &mbcm_trident_driver;
    154         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    155         return BCM_E_NONE;
    156     }
    157     if (SOC_IS_TITAN(unit)) {
    158         mbcm_driver[unit] = &mbcm_titan_driver;
    159         bcm_chip_family_set(unit, BCM_FAMILY_TITAN);
    160         return BCM_E_NONE;
    161     }
    162 #endif	/* BCM_TRIDENT_SUPPORT */
    163 #ifdef BCM_TRIDENT2PLUS_SUPPORT
    164     if (SOC_IS_TRIDENT2PLUS(unit)) {
    165         mbcm_driver[unit] = &mbcm_trident2plus_driver;
    166         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    167         return BCM_E_NONE;
    168     }
    169     if (SOC_IS_TITAN2PLUS(unit)) {
    170         mbcm_driver[unit] = &mbcm_titan2plus_driver;
    171         bcm_chip_family_set(unit, BCM_FAMILY_TITAN);
    172         return BCM_E_NONE;
    173     }
    174 #endif /* BCM_TRIDENT2PLUS_SUPPORT */
    175 #ifdef BCM_MONTEREY_SUPPORT
    176     if (SOC_IS_MONTEREY (unit))
    177     {
    178         mbcm_driver[unit] = &mbcm_monterey_driver;
    179         bcm_chip_family_set (unit, BCM_FAMILY_TRIDENT);
    180         return BCM_E_NONE;
    181     }
    182 #endif
    183 #ifdef BCM_APACHE_SUPPORT
    184     if (SOC_IS_APACHE (unit))
    185     {
    186         mbcm_driver[unit] = &mbcm_apache_driver;
    187         bcm_chip_family_set (unit, BCM_FAMILY_TRIDENT);
    188         return BCM_E_NONE;
    189     }
    190 #endif /* BCM_APACHE_SUPPORT */
    191 #ifdef BCM_TRIDENT2_SUPPORT 
    192     if (SOC_IS_TRIDENT2(unit)) {
    193         mbcm_driver[unit] = &mbcm_trident2_driver;
    194         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    195         return BCM_E_NONE;
    196     }
    197     if (SOC_IS_TITAN2(unit)) {
    198         mbcm_driver[unit] = &mbcm_titan2_driver;
    199         bcm_chip_family_set(unit, BCM_FAMILY_TITAN);
    200         return BCM_E_NONE;
    201     }
    202 #endif	/* BCM_TRIDENT2_SUPPORT */
    203 #ifdef	BCM_HURRICANE1_SUPPORT
    204     if (SOC_IS_HURRICANE(unit)) {
    205         mbcm_driver[unit] = &mbcm_hurricane_driver;
    206         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH); 
    207         return BCM_E_NONE;
    208     }
    209 #endif	/* BCM_HURRICANE1_SUPPORT */
    210 #ifdef	BCM_HURRICANE_SUPPORT
    211     if (SOC_IS_HURRICANE2(unit)) {
    212         mbcm_driver[unit] = &mbcm_hurricane2_driver;
    213         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH);
    214         return BCM_E_NONE;
    215     }
    216 #endif	/* BCM_HURRICANE_SUPPORT */
    217 #ifdef  BCM_TRIUMPH3_SUPPORT
    218     if (SOC_IS_TRIUMPH3(unit)) {
    219         mbcm_driver[unit] = &mbcm_triumph3_driver;
    220         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    221         return BCM_E_NONE;
    222     }
    223 #endif /* BCM_TRIUMPH3_SUPPORT */
    224 #ifdef	BCM_KATANA_SUPPORT
    225     if (SOC_IS_KATANA(unit)) {
    226         mbcm_driver[unit] = &mbcm_katana_driver;
    227         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    228         return BCM_E_NONE;
    229     }
    230 #endif	/* BCM_KATANA_SUPPORT */
    231 #ifdef	BCM_KATANA2_SUPPORT
    232     if (SOC_IS_KATANA2(unit)) {
    233         mbcm_driver[unit] = &mbcm_katana2_driver;
    234         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    235         return BCM_E_NONE;
    236     }
    237 #endif	/* BCM_KATANA2_SUPPORT */
    238 #ifdef BCM_GREYHOUND_SUPPORT
    239     if (SOC_IS_GREYHOUND(unit)) {
    240         mbcm_driver[unit] = &mbcm_greyhound_driver;
    241         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH);
    242         return BCM_E_NONE;
    243     }
    244 #endif /* BCM_GREYHOUND_SUPPORT */
    245 #ifdef	BCM_TOMAHAWK_SUPPORT
    246     if (SOC_IS_TOMAHAWK(unit)) {
    247         BCM_IF_ERROR_RETURN(_bcm_esw_mbcm_init(unit, &mbcm_driver[unit]));
    248         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    249         return BCM_E_NONE;
    250     }
    251 #endif	/* BCM_TOMAHAWK_SUPPORT */
    252 
    253 #ifdef  BCM_HELIX5_SUPPORT
    254     if (SOC_IS_HELIX5(unit)) {
    255         mbcm_driver[unit] = &mbcm_helix5_driver;
    256         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    257         return BCM_E_NONE;
    258     }
    259 #endif  /* BCM_HELIX5_SUPPORT */
    260 
    261 #ifdef	BCM_TOMAHAWK3_SUPPORT
    262     if (SOC_IS_TOMAHAWK3(unit)) {
    263         mbcm_driver[unit] = &mbcm_tomahawk3_driver;
    264         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    265         return BCM_E_NONE;
    266     }
    267 #endif /* BCM_TOMAHAWK3_SUPPORT */
    268 
    269 #ifdef  BCM_TRIDENT3_SUPPORT
    270     if (SOC_IS_TRIDENT3(unit)) {
    271         mbcm_driver[unit] = &mbcm_trident3_driver;
    272         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    273         return BCM_E_NONE;
    274     }
    275 #endif  /* BCM_TRIDENT3_SUPPORT */
    276 
    277 
    278 #ifdef  BCM_MAVERICK2_SUPPORT
    279     if (SOC_IS_MAVERICK2(unit)) {
    280         mbcm_driver[unit] = &mbcm_trident3_driver;
    281         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    282         return BCM_E_NONE;
    283     }
    284 #endif  /* BCM_MAVERICK2_SUPPORT */
    285 
    286 #ifdef BCM_HURRICANE3_SUPPORT
    287     if (SOC_IS_HURRICANE3(unit)) {
    288         mbcm_driver[unit] = &mbcm_hurricane3_driver;
    289         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH);
    290         return BCM_E_NONE;
    291     }
    292 #endif /* BCM_HURRICANE3_SUPPORT */
    293 #ifdef BCM_GREYHOUND2_SUPPORT
    294     if (SOC_IS_GREYHOUND2(unit)) {
    295         mbcm_driver[unit] = &mbcm_greyhound2_driver;
    296         bcm_chip_family_set(unit, BCM_FAMILY_TRIUMPH);
    297         return BCM_E_NONE;
    298     }
    299 #endif /* BCM_GREYHOUND2_SUPPORT */
    300 #ifdef  BCM_TOMAHAWK2_SUPPORT
    301     if (SOC_IS_TOMAHAWK2(unit)) {
    302         BCM_IF_ERROR_RETURN(_bcm_esw_mbcm_init(unit, &mbcm_driver[unit]));
    303         bcm_chip_family_set(unit, BCM_FAMILY_TRIDENT);
    304         return BCM_E_NONE;
    305     }
    306 #endif  /* BCM_TOMAHAWK2_SUPPORT */
    307 
    308     LOG_CLI((BSL_META_U(unit,
    309                         "ERROR: mbcm_init unit %d: unsupported chip type\n"), unit));
    310     return BCM_E_INTERNAL;
    311 }
    312 
    313 int mbcm_deinit(int unit)
    314 {
    315 #if defined(BCM_TOMAHAWK_SUPPORT)
    316     int latency = SOC_SWITCH_BYPASS_MODE(unit);
    317     if (SOC_IS_TOMAHAWKX(unit) && latency && mbcm_driver[unit]) {
    318         if (!(--mbcm_ref[latency])) { /* ref cnt */
    319             sal_free(mbcm_driver[unit]);
    320             (latency%2) ? (mbcm_l3_latency = NULL) : (mbcm_l2_latency = NULL);
    321         }
    322     }
    323     mbcm_driver[unit] = NULL;
    324 #else
    325     mbcm_driver[unit] = NULL;
    326 #endif
    327 
    328     return BCM_E_NONE;
    329 }
    330 
    331 #if defined(BCM_TOMAHAWK_SUPPORT)
    332 STATIC int
    333 _bcm_esw_mbcm_init(int unit, mbcm_functions_t **mbcm)
    334 {
    335     if (mbcm == NULL) {
    336         return BCM_E_INTERNAL;
    337     }
    338     if (mbcm_normal_latency == NULL) {
    339         if (SOC_IS_TOMAHAWK(unit)) {
    340             mbcm_normal_latency = &mbcm_tomahawk_driver;
    341         } else
    342 #ifdef BCM_TOMAHAWK2_SUPPORT
    343         if (SOC_IS_TOMAHAWK2(unit)) {
    344             mbcm_normal_latency = &mbcm_tomahawk2_driver;
    345         } else
    346 #endif
    347         {
    348             return BCM_E_INTERNAL;
    349         }
    350     }
    351     /*
    352      * lower latency units share their mbcm variants, while
    353      * normal latency units share theirs.
    354      * this is reqd to plug different entry points for features
    355      * subject to different latencies (at later stages of init)
    356      */
    357     switch(SOC_SWITCH_BYPASS_MODE(unit)) {
    358         case SOC_SWITCH_BYPASS_MODE_NONE:
    359             *mbcm = mbcm_normal_latency; /* mbcm_tomahawk_driver */
    360             break;
    361 
    362         case SOC_SWITCH_BYPASS_MODE_BALANCED:
    363             if (!mbcm_l3_latency) {
    364                 /* one time */
    365                 if (!(mbcm_l3_latency =
    366                            sal_alloc(sizeof(mbcm_functions_t),
    367                                      "l3 latency mbcm variant"))) {
    368                     return BCM_E_MEMORY;
    369                 }
    370                 sal_memcpy(mbcm_l3_latency, mbcm_normal_latency,
    371                            sizeof(mbcm_functions_t));
    372 
    373                 /*
    374                  *  overrides for this latency mode start from here
    375                  *  this covers both the plugging and re-plugging for
    376                  *  warmboot scenario as well
    377                  */
    378             }
    379 
    380             *mbcm = mbcm_l3_latency;
    381             break;
    382 
    383         case SOC_SWITCH_BYPASS_MODE_LOW:
    384             if (!mbcm_l2_latency) {
    385                 /* one time */
    386                 if (!(mbcm_l2_latency =
    387                            sal_alloc(sizeof(mbcm_functions_t),
    388                                      "l2 latency mbcm variant"))) {
    389                     return BCM_E_MEMORY;
    390                 }
    391                 sal_memcpy(mbcm_l2_latency, mbcm_normal_latency,
    392                            sizeof(mbcm_functions_t));
    393 
    394                 /*
    395                  *  overrides for this latency mode start from here
    396                  *  this covers both the plugging and re-plugging for
    397                  *  warmboot scenario as well
    398                  */
    399 
    400                 /* reroute trunk functionality to xgs3 for Fast LAG */
    401                 mbcm_l2_latency->mbcm_trunk_modify     = bcm_xgs3_trunk_modify;
    402                 mbcm_l2_latency->mbcm_trunk_get        = bcm_xgs3_trunk_get;
    403                 mbcm_l2_latency->mbcm_trunk_destroy    = bcm_xgs3_trunk_destroy;
    404                 mbcm_l2_latency->mbcm_trunk_mcast_join = bcm_xgs3_trunk_mcast_join;
    405             }
    406 
    407             *mbcm = mbcm_l2_latency;
    408             break;
    409     }
    410 
    411     ++mbcm_ref[SOC_SWITCH_BYPASS_MODE(unit)]; /* ref cnt */
    412 
    413     return BCM_E_NONE;
    414 }
    415 #endif
    416