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

failover.c (40675B)


      1 
      2 /*
      3  * 
      4  *
      5  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      6  * 
      7  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      8  *
      9  * ESW failover API
     10  */
     11 
     12 #include <soc/drv.h>
     13 #include <soc/mem.h>
     14 #include <soc/util.h>
     15 #include <soc/debug.h>
     16 #include <bcm/types.h>
     17 #include <bcm/error.h>
     18 #include <bcm_int/esw/mbcm.h>
     19 #include <bcm/extender.h>
     20 #include <bcm_int/esw/failover.h>
     21 #include <bcm_int/esw_dispatch.h>
     22 #if defined(BCM_TRIUMPH2_SUPPORT)
     23 #include <bcm_int/esw/field.h>
     24 #include <bcm_int/esw/triumph2.h>
     25 #endif /* BCM_TRIUMPH2_SUPPORT */
     26 #include <bcm_int/esw/failover.h>
     27 #include <bcm/failover.h>
     28 #if defined(BCM_TRIUMPH3_SUPPORT)
     29 #include <bcm_int/esw/triumph3.h>
     30 #endif /* BCM_TRIUMPH3_SUPPORT */
     31 #if defined(BCM_KATANA2_SUPPORT)
     32 #include <bcm_int/esw/katana2.h>
     33 #endif /* BCM_KATANA2_SUPPORT */
     34 #if defined(BCM_SABER2_SUPPORT)
     35 #include <bcm_int/esw/saber2.h>
     36 #endif /* BCM_SABER2_SUPPORT */
     37 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
     38 #include <bcm_int/esw/trident2plus.h>
     39 #endif /* BCM_TRIDENT2PLUS_SUPPORT */
     40 #if defined(BCM_TOMAHAWK2_SUPPORT)
     41 #include <bcm_int/esw/tomahawk2.h>
     42 #endif /* defined(BCM_TOMAHAWK2_SUPPORT) */
     43 #if defined(BCM_TRIDENT3_SUPPORT)
     44 #include <bcm_int/esw/trident3.h>
     45 #endif /* BCM_TRIDENT3_SUPPORT */
     46 #if defined(BCM_TOMAHAWK3_SUPPORT)
     47 #include <bcm_int/esw/tomahawk3.h>
     48 #endif /* BCM_TOMAHAWK3_SUPPORT */
     49 
     50 #ifdef INCLUDE_L3
     51 
     52 
     53 _bcm_failover_bookkeeping_t  _bcm_failover_bk_info[BCM_MAX_NUM_UNITS] = {{ 0 }};
     54 
     55 #ifdef BCM_WARM_BOOT_SUPPORT
     56 /*
     57  * Function:
     58  *      _bcm_esw_failover_sync
     59  * Purpose:
     60  *      Record failover module persisitent info for Level 2 Warm Boot.
     61  * Parameters:
     62  *      unit - StrataSwitch unit number.
     63  * Returns:
     64  *      BCM_E_XXX
     65  */
     66 int
     67 bcm_esw_failover_sync(int unit)
     68 {
     69 #if defined(BCM_SABER2_SUPPORT)
     70     if (SOC_IS_SABER2(unit)) {
     71         BCM_IF_ERROR_RETURN(bcm_sb2_failover_sync(unit));
     72     }
     73 #endif
     74 #if defined(BCM_TRIUMPH3_SUPPORT)
     75     if (SOC_IS_TRIUMPH3(unit)) {
     76         BCM_IF_ERROR_RETURN(bcm_tr2_failover_sync(unit));
     77     }
     78 #endif
     79 #ifdef BCM_TRIDENT2PLUS_SUPPORT
     80     if (soc_feature(unit, soc_feature_hierarchical_protection)) {
     81         BCM_IF_ERROR_RETURN(bcmi_failover_sync(unit));
     82     }
     83 #endif
     84 #ifdef BCM_TOMAHAWK2_SUPPORT
     85     if (SOC_IS_TOMAHAWK2(unit)) {
     86         BCM_IF_ERROR_RETURN(_bcm_th2_failover_sync(unit));
     87     }
     88 #endif
     89 #ifdef BCM_TRIDENT3_SUPPORT
     90     if (SOC_IS_TRIDENT3X(unit)) {
     91         BCM_IF_ERROR_RETURN(bcm_td3_failover_sync(unit));
     92     }
     93 #endif
     94     return BCM_E_NONE;
     95 }
     96 #endif /* BCM_WARM_BOOT_SUPPORT */
     97 
     98 /*
     99  * Function:
    100  *		bcm_esw_failover_init
    101  * Purpose:
    102  *		Init  failover module
    103  * Parameters:
    104  *		IN :  unit
    105  * Returns:
    106  *		BCM_E_XXX
    107  */
    108 
    109 int
    110 bcm_esw_failover_init(int unit)
    111 {
    112 #ifdef BCM_TRIUMPH2_SUPPORT
    113 #if defined(BCM_TOMAHAWK3_SUPPORT)
    114     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset) && SOC_IS_TOMAHAWK3(unit)) {
    115         return bcm_th3_failover_init(unit);
    116     } else
    117 #endif
    118 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    119     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    120         return bcm_td2p_failover_init(unit);
    121     } else
    122 #endif
    123     if (soc_feature(unit, soc_feature_failover)) {
    124 #if defined(BCM_TOMAHAWK2_SUPPORT)
    125         if (SOC_IS_TOMAHAWK2(unit)) {
    126             return bcm_th2_failover_init(unit);
    127         } else
    128 #endif
    129         {
    130             BCM_IF_ERROR_RETURN (bcm_tr2_failover_init(unit));
    131 #if defined(BCM_SABER2_SUPPORT)
    132             if (SOC_IS_SABER2(unit)) {
    133                 BCM_IF_ERROR_RETURN(bcm_sb2_failover_init(unit));
    134             }
    135 #endif
    136             return BCM_E_NONE;
    137         }
    138     }
    139 #endif
    140     return BCM_E_UNAVAIL;
    141 }
    142 
    143 
    144  /* Function:
    145  *      bcm_failover_cleanup
    146  * Purpose:
    147  *      Detach the failover module, clear all HW states
    148  * Parameters:
    149  *      unit     - Device Number
    150  * Returns:
    151  *      BCM_E_XXXX
    152  */
    153 
    154 int
    155 bcm_esw_failover_cleanup(int unit)
    156 {
    157 #ifdef BCM_TRIUMPH2_SUPPORT
    158 #if defined(BCM_TOMAHAWK3_SUPPORT)
    159     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset) && SOC_IS_TOMAHAWK3(unit)) {
    160         return bcm_th3_failover_cleanup(unit);
    161     } else
    162 #endif
    163 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    164     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    165         return bcm_td2p_failover_cleanup(unit);
    166     } else
    167 #endif
    168     if (soc_feature(unit, soc_feature_failover)) {
    169 #if defined(BCM_TOMAHAWK2_SUPPORT)
    170         if (SOC_IS_TOMAHAWK2(unit)) {
    171             return bcm_th2_failover_cleanup(unit);
    172         } else
    173 #endif
    174         {
    175 #if defined(BCM_SABER2_SUPPORT)
    176             if (SOC_IS_SABER2(unit)) {
    177                 BCM_IF_ERROR_RETURN(bcm_sb2_failover_cleanup(unit));
    178             }
    179 #endif 
    180             return bcm_tr2_failover_cleanup(unit);
    181         }
    182     }
    183 #endif
    184     return BCM_E_UNAVAIL;
    185 }
    186 
    187 
    188 /*
    189  * Function:
    190  *		bcm_esw_failover_create
    191  * Purpose:
    192  *		Create a failover object
    193  * Parameters:
    194  *		IN :  unit
    195  *           IN :  flags
    196  *           OUT :  failover_id
    197  * Returns:
    198  *		BCM_E_XXX
    199  */
    200 
    201 int 
    202 bcm_esw_failover_create(int unit, uint32 flags, bcm_failover_t *failover_id)
    203 {
    204     int rv = BCM_E_UNAVAIL;
    205 #ifdef BCM_TRIUMPH2_SUPPORT
    206 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    207     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    208         rv = bcm_td2p_failover_lock(unit);
    209         if (rv == BCM_E_NONE) {
    210             rv = bcm_td2p_failover_create(unit, flags, failover_id);
    211             bcm_td2p_failover_unlock(unit);
    212         }
    213         return rv;
    214     } else
    215 #endif
    216     if (soc_feature(unit, soc_feature_failover)) {
    217 #if defined(BCM_TOMAHAWK2_SUPPORT)
    218         if (SOC_IS_TOMAHAWK2(unit)) {
    219             rv = bcm_th2_failover_lock(unit);
    220             if (rv == BCM_E_NONE) {
    221                 rv = bcm_th2_failover_create(unit, flags, failover_id);
    222                 bcm_th2_failover_unlock(unit);
    223             }
    224             return rv;
    225         } else
    226 #endif
    227         {
    228             rv = bcm_tr2_failover_lock (unit);
    229             if ( rv == BCM_E_NONE ) {
    230                 rv = bcm_tr2_failover_create(unit, flags, failover_id);
    231                 bcm_tr2_failover_unlock (unit);
    232             }
    233             return rv;
    234         }
    235     }
    236 #endif
    237     return rv;
    238 }
    239 
    240 /*
    241  * Function:
    242  *		bcm_esw_failover_destroy
    243  * Purpose:
    244  *		Destroy a failover object
    245  * Parameters:
    246  *		IN :  unit
    247  *           IN :  failover_id
    248  * Returns:
    249  *		BCM_E_XXX
    250  */
    251 
    252 int 
    253 bcm_esw_failover_destroy(int unit, bcm_failover_t failover_id)
    254 {
    255     int rv = BCM_E_UNAVAIL;
    256 #if defined(BCM_SABER2_SUPPORT)
    257     int type;
    258 #endif
    259 #ifdef BCM_TRIUMPH2_SUPPORT
    260 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    261     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    262         rv = bcm_td2p_failover_lock(unit);
    263         if (rv == BCM_E_NONE) {
    264             rv = bcm_td2p_failover_destroy(unit, failover_id);
    265             bcm_td2p_failover_unlock(unit);
    266         }
    267         return rv;
    268     } else
    269 #endif
    270     if (soc_feature(unit, soc_feature_failover)) {
    271 #if defined(BCM_TOMAHAWK2_SUPPORT)
    272         if (SOC_IS_TOMAHAWK2(unit)) {
    273             rv = bcm_th2_failover_lock(unit);
    274             if (rv == BCM_E_NONE) {
    275                 rv = bcm_th2_failover_destroy(unit, failover_id);
    276                 bcm_th2_failover_unlock(unit);
    277             }
    278             return rv;
    279         } else
    280 #endif
    281         {
    282             rv = bcm_tr2_failover_lock (unit);
    283             if (  rv == BCM_E_NONE ) {
    284 #if defined(BCM_SABER2_SUPPORT)
    285                 _BCM_GET_FAILOVER_TYPE(failover_id, type);
    286                 if (type & _BCM_FAILOVER_1_1_MC_PROTECTION_MODE) {
    287                     rv = bcm_tr2_mmu_failover_destroy(unit, failover_id);
    288                     bcm_tr2_failover_unlock (unit);
    289                 } else
    290 #endif
    291                 {
    292                     rv = bcm_tr2_failover_id_validate ( unit, failover_id );
    293                     if (  rv == BCM_E_NONE ) {
    294                         rv = bcm_tr2_failover_destroy(unit, failover_id);
    295                     }
    296                     bcm_tr2_failover_unlock (unit);
    297                 }
    298             }
    299             return rv;
    300         }
    301     }
    302 #endif
    303     return rv;
    304 }
    305 
    306 /*
    307  * Function:
    308  *		bcm_esw_failover_set
    309  * Purpose:
    310  *		Set a failover object to enable or disable (note that failover object
    311  *            0 is reserved
    312  * Parameters:
    313  *		IN :  unit
    314  *           IN :  failover_id
    315  *           IN :  value
    316  * Returns:
    317  *		BCM_E_XXX
    318  */
    319 
    320 
    321 int 
    322 bcm_esw_failover_set(int unit, bcm_failover_t failover_id, int value)
    323 {
    324     int rv = BCM_E_UNAVAIL;
    325 #if defined(BCM_SABER2_SUPPORT)
    326     int type = 0;
    327 #endif
    328 #if defined(BCM_TRIDENT2PLUS_SUPPORT) || defined(BCM_TOMAHAWK2_SUPPORT)
    329     int failover_type=_BCM_FAILOVER_DEFAULT_MODE;
    330     int local_failover_id=0;
    331 #endif
    332 #if defined(BCM_KATANA2_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    333     bcm_failover_element_t failover;
    334 #endif
    335 
    336 #if defined(BCM_KATANA2_SUPPORT)
    337     if (soc_feature(unit, soc_feature_failover) && SOC_IS_KATANA2(unit)) {
    338         bcm_failover_element_t_init (&failover);
    339         failover.failover_id = failover_id;
    340         rv = bcm_tr2_failover_lock (unit);
    341 #if defined(BCM_SABER2_SUPPORT)
    342         if ((type & _BCM_FAILOVER_1_1_MC_PROTECTION_MODE) &&
    343                 (SOC_IS_SABER2(unit))) {
    344             if ( rv == BCM_E_NONE ) {
    345                 rv = bcm_sb2_failover_status_set(unit, &failover, value);
    346                 bcm_tr2_failover_unlock (unit);
    347             }
    348         } else
    349 #endif
    350         {
    351             if ( rv == BCM_E_NONE ) {
    352                 rv = bcm_kt2_failover_status_set(unit, &failover, value);
    353                 bcm_tr2_failover_unlock (unit);
    354             }
    355         }
    356         return rv;
    357     }
    358 #endif
    359 
    360 #ifdef BCM_TRIUMPH3_SUPPORT
    361     if (soc_feature(unit, soc_feature_failover) && SOC_IS_TRIUMPH3(unit)) {
    362          bcm_failover_element_t_init (&failover);
    363          failover.failover_id = failover_id;
    364          rv = bcm_tr2_failover_lock (unit);
    365          if ( rv == BCM_E_NONE ) {
    366                rv = bcm_tr3_failover_status_set(unit, &failover, value);
    367                bcm_tr2_failover_unlock (unit);
    368          }
    369          return rv;
    370     }
    371 #endif
    372 #ifdef BCM_TRIUMPH2_SUPPORT
    373 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    374     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    375         bcm_failover_element_t_init(&failover);
    376         _BCM_GET_FAILOVER_TYPE(failover_id, failover_type);
    377         if ((failover_type & _BCM_FAILOVER_INGRESS) ||
    378             (failover_type & _BCM_FAILOVER_1_1_MC_PROTECTION_MODE)) {
    379             local_failover_id = failover_id;
    380             _BCM_GET_FAILOVER_ID(local_failover_id);
    381             if (failover_type & _BCM_FAILOVER_INGRESS) {
    382                 failover.flags = BCM_FAILOVER_INGRESS;
    383             } else {
    384                 failover.flags = BCM_FAILOVER_ENCAP;
    385             }
    386             failover.failover_id = local_failover_id;
    387         } else {
    388             failover.failover_id = failover_id;
    389         }
    390         rv = bcm_td2p_failover_lock(unit);
    391         if (rv == BCM_E_NONE) {
    392             rv = bcm_td2p_failover_status_set(unit, &failover, value);
    393             bcm_td2p_failover_unlock(unit);
    394         }
    395         return rv;
    396     } else
    397 #endif
    398 
    399     if (soc_feature(unit, soc_feature_failover)) {
    400 #if defined(BCM_TOMAHAWK2_SUPPORT)
    401         if (SOC_IS_TOMAHAWK2(unit)) {
    402             bcm_failover_element_t_init(&failover);
    403             _BCM_GET_FAILOVER_TYPE(failover_id, failover_type);
    404             if (failover_type & _BCM_FAILOVER_INGRESS) {
    405                 local_failover_id = failover_id;
    406                 _BCM_GET_FAILOVER_ID(local_failover_id);
    407                 failover.flags = BCM_FAILOVER_INGRESS;
    408             } else {
    409                 local_failover_id = failover_id;
    410             }
    411             failover.failover_id = local_failover_id;
    412             rv = bcm_th2_failover_lock(unit);
    413             if (rv == BCM_E_NONE) {
    414                 if (failover_type & _BCM_FAILOVER_1_1_MC_PROTECTION_MODE) {
    415                     bcm_th2_failover_unlock(unit);
    416                     return BCM_E_PARAM;
    417                 }
    418                 rv = bcm_th2_failover_status_set(unit, &failover, value);
    419                 bcm_th2_failover_unlock(unit);
    420             }
    421             return rv;
    422         } else
    423 #endif
    424         {
    425             rv = bcm_tr2_failover_lock (unit);
    426             if ( rv == BCM_E_NONE ) {
    427                 rv = bcm_tr2_failover_set(unit, failover_id, value);
    428                 bcm_tr2_failover_unlock (unit);
    429             }
    430             return rv;
    431         }
    432     }
    433 #endif
    434     return rv;
    435 }
    436 
    437 /*
    438  * Function:
    439  *		bcm_esw_failover_get
    440  * Purpose:
    441  *		Get the enable status of a failover object
    442  * Parameters:
    443  *		IN :  unit
    444  *           IN :  failover_id
    445  *           OUT :  value
    446  * Returns:
    447  *		BCM_E_XXX
    448  */
    449 
    450 
    451 int 
    452 bcm_esw_failover_get(int unit, bcm_failover_t failover_id, int *value)
    453 {
    454     int rv = BCM_E_UNAVAIL;
    455 #if defined(BCM_SABER2_SUPPORT)
    456     int type = 0;
    457 #endif
    458 #if defined(BCM_KATANA2_SUPPORT) || defined(BCM_TRIUMPH3_SUPPORT)
    459         bcm_failover_element_t failover;
    460 #endif
    461     
    462 #if defined(BCM_KATANA2_SUPPORT)
    463     if (soc_feature(unit, soc_feature_failover) && SOC_IS_KATANA2(unit)) {
    464         bcm_failover_element_t_init (&failover);
    465         failover.failover_id = failover_id;
    466         rv = bcm_tr2_failover_lock (unit);
    467 #if defined(BCM_SABER2_SUPPORT)
    468         _BCM_GET_FAILOVER_TYPE(failover_id, type);
    469         if ((type & _BCM_FAILOVER_1_1_MC_PROTECTION_MODE) &&
    470                 (SOC_IS_SABER2(unit))) {
    471             if ( rv == BCM_E_NONE ) {
    472                 rv = bcm_sb2_failover_status_get(unit, &failover, value);
    473                 bcm_tr2_failover_unlock (unit);
    474             }
    475         } else
    476 #endif
    477         {
    478         if ( rv == BCM_E_NONE ) {
    479             rv = bcm_kt2_failover_status_get(unit, &failover, value);
    480             bcm_tr2_failover_unlock (unit);
    481         }
    482         }
    483         return rv;
    484     }
    485 #endif
    486     
    487 #ifdef BCM_TRIUMPH3_SUPPORT
    488     if (soc_feature(unit, soc_feature_failover) && SOC_IS_TRIUMPH3(unit)) {
    489          bcm_failover_element_t_init (&failover);
    490          failover.failover_id = failover_id;
    491          rv = bcm_tr2_failover_lock (unit);
    492          if ( rv == BCM_E_NONE ) {
    493                rv = bcm_tr3_failover_status_get(unit, &failover, value);
    494                bcm_tr2_failover_unlock (unit);
    495          }
    496          return rv;
    497     }
    498 #endif
    499 #ifdef BCM_TRIUMPH2_SUPPORT
    500 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    501     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    502         int failover_type     = _BCM_FAILOVER_DEFAULT_MODE;
    503         int local_failover_id = 0;
    504         bcm_failover_element_t_init (&failover);
    505         _BCM_GET_FAILOVER_TYPE(failover_id, failover_type);
    506         if ((failover_type & _BCM_FAILOVER_INGRESS) ||
    507             (failover_type & _BCM_FAILOVER_1_1_MC_PROTECTION_MODE)) {
    508             local_failover_id = failover_id;
    509             _BCM_GET_FAILOVER_ID(local_failover_id);
    510             if (failover_type & _BCM_FAILOVER_INGRESS) {
    511                 failover.flags = BCM_FAILOVER_INGRESS;
    512             } else {
    513                 failover.flags = BCM_FAILOVER_ENCAP;
    514             }
    515             failover.failover_id = local_failover_id;
    516         } else {
    517             failover.failover_id = failover_id;
    518         }
    519         rv = bcm_td2p_failover_lock(unit);
    520         if (rv == BCM_E_NONE) {
    521             rv = bcm_td2p_failover_status_get(unit, &failover, value);
    522             bcm_td2p_failover_unlock(unit);
    523         }
    524         return rv;
    525     } else
    526 #endif
    527 
    528     if (soc_feature(unit, soc_feature_failover)) {
    529 #if defined(BCM_TOMAHAWK2_SUPPORT)
    530         if (SOC_IS_TOMAHAWK2(unit)) {
    531             int failover_type     = _BCM_FAILOVER_DEFAULT_MODE;
    532             int local_failover_id = 0;            
    533             bcm_failover_element_t_init (&failover);
    534             _BCM_GET_FAILOVER_TYPE(failover_id, failover_type);
    535             if (failover_type & _BCM_FAILOVER_INGRESS) {
    536                 local_failover_id = failover_id;
    537                 _BCM_GET_FAILOVER_ID(local_failover_id);
    538                 failover.flags = BCM_FAILOVER_INGRESS;
    539             } else {
    540                 local_failover_id = failover_id;
    541             }
    542             failover.failover_id = local_failover_id;
    543             rv = bcm_th2_failover_lock(unit);
    544             if (rv == BCM_E_NONE) {
    545                 rv = bcm_th2_failover_status_get(unit, &failover, value);
    546                 bcm_th2_failover_unlock(unit);
    547             }
    548             return rv;
    549         } else
    550 #endif
    551         {
    552             rv = bcm_tr2_failover_lock (unit);
    553             if ( rv == BCM_E_NONE ) {
    554                 rv = bcm_tr2_failover_get(unit, failover_id, value);
    555                 bcm_tr2_failover_unlock (unit);
    556             }
    557             return rv;
    558         }
    559     }
    560 #endif
    561     return rv;
    562 }
    563 
    564 /*
    565  * Function:
    566  *		bcm_esw_failover_status_set
    567  * Purpose:
    568  *		Set a failover object to enable or disable (note that failover object
    569  *            0 is reserved
    570  * Parameters:
    571  *		IN :  unit
    572  *           IN :  failover
    573  *           IN :  value
    574  * Returns:
    575  *		BCM_E_XXX
    576  */
    577 
    578 
    579 int 
    580 bcm_esw_failover_status_set(int unit,
    581                                       bcm_failover_element_t *failover,
    582                                       int enable)
    583 {
    584     int rv = BCM_E_UNAVAIL;
    585 #ifdef BCM_KATANA2_SUPPORT
    586     if (soc_feature(unit, soc_feature_failover) && SOC_IS_KATANA2(unit)) {
    587         rv = bcm_tr2_failover_lock (unit);
    588 #if defined(BCM_SABER2_SUPPORT)
    589         if ((failover->flags & BCM_FAILOVER_ENCAP) &&
    590                 (SOC_IS_SABER2(unit))) {
    591             if ( rv == BCM_E_NONE ) {
    592                 rv = bcm_sb2_failover_status_set(unit, failover, enable);
    593                 bcm_tr2_failover_unlock (unit);
    594             }
    595         } else  
    596 #endif
    597         {
    598             if ( rv == BCM_E_NONE ) {
    599                 rv = bcm_kt2_failover_status_set(unit, failover, enable);
    600                 bcm_tr2_failover_unlock (unit);
    601             }
    602         }
    603         return rv;
    604     }
    605 #endif
    606 
    607 #ifdef BCM_TRIUMPH3_SUPPORT
    608     if (soc_feature(unit, soc_feature_failover) && SOC_IS_TRIUMPH3(unit)) {
    609          rv = bcm_tr2_failover_lock (unit);
    610          if ( rv == BCM_E_NONE ) {
    611                rv = bcm_tr3_failover_status_set(unit, failover, enable);
    612                bcm_tr2_failover_unlock (unit);
    613          }
    614          return rv;
    615     }
    616 #endif
    617 #ifdef BCM_TRIUMPH2_SUPPORT
    618 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    619     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    620         rv = bcm_td2p_failover_lock(unit);
    621         if (rv == BCM_E_NONE) {
    622             rv = bcm_td2p_failover_status_set(unit, failover, enable);
    623             bcm_td2p_failover_unlock(unit);
    624         }
    625         return rv;
    626     } else
    627 #endif
    628     if (soc_feature(unit, soc_feature_failover)) {
    629 #if defined(BCM_TOMAHAWK2_SUPPORT)
    630         if (SOC_IS_TOMAHAWK2(unit)) {
    631             rv = bcm_th2_failover_lock(unit);
    632             if (rv == BCM_E_NONE) {
    633                 rv = bcm_th2_failover_status_set(unit, failover, enable);
    634                 bcm_th2_failover_unlock(unit);
    635             }
    636             return rv;
    637         } else
    638 #endif
    639         {
    640             rv = bcm_tr2_failover_lock (unit);
    641             if ( rv == BCM_E_NONE ) {
    642                 rv = bcm_tr2_failover_set(unit, failover->failover_id, enable);
    643                 bcm_tr2_failover_unlock (unit);
    644             }
    645             return rv;
    646         }
    647     }
    648 #endif
    649     return rv;
    650 }
    651 
    652 /*
    653  * Function:
    654  *		bcm_esw_failover_status_get
    655  * Purpose:
    656  *		Get the enable status of a failover object
    657  * Parameters:
    658  *		IN :  unit
    659  *           IN :  failover
    660  *           OUT :  value
    661  * Returns:
    662  *		BCM_E_XXX
    663  */
    664 
    665 
    666 int 
    667 bcm_esw_failover_status_get(int unit,
    668                                       bcm_failover_element_t *failover,
    669                                       int *value)
    670 {
    671     int rv = BCM_E_UNAVAIL;
    672 #ifdef BCM_KATANA2_SUPPORT
    673     if (soc_feature(unit, soc_feature_failover) && SOC_IS_KATANA2(unit)) {
    674         rv = bcm_tr2_failover_lock (unit);
    675 #if defined(BCM_SABER2_SUPPORT)
    676         if ((failover->flags & BCM_FAILOVER_ENCAP) &&
    677                 (SOC_IS_SABER2(unit))) {
    678             if ( rv == BCM_E_NONE ) {
    679                 rv = bcm_sb2_failover_status_get(unit, failover, value);
    680                 bcm_tr2_failover_unlock (unit);
    681             }
    682         } else  
    683 #endif
    684         if ( rv == BCM_E_NONE ) {
    685             rv = bcm_kt2_failover_status_get(unit, failover, value);
    686             bcm_tr2_failover_unlock (unit);
    687         }
    688         return rv;
    689     }
    690 #endif
    691 
    692 #ifdef BCM_TRIUMPH3_SUPPORT
    693     if (soc_feature(unit, soc_feature_failover) && SOC_IS_TRIUMPH3(unit)) {
    694          rv = bcm_tr2_failover_lock (unit);
    695          if ( rv == BCM_E_NONE ) {
    696               rv = bcm_tr3_failover_status_get(unit, failover, value);
    697               bcm_tr2_failover_unlock (unit);
    698          }
    699          return rv;
    700     }
    701 #endif
    702 #ifdef BCM_TRIUMPH2_SUPPORT
    703 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    704     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
    705         rv = bcm_td2p_failover_lock(unit);
    706         if (rv == BCM_E_NONE) {
    707             rv = bcm_td2p_failover_status_get(unit, failover, value);
    708             bcm_td2p_failover_unlock(unit);
    709         }
    710         return rv;
    711     } else
    712 #endif
    713 
    714     if (soc_feature(unit, soc_feature_failover)) {
    715 #if defined(BCM_TOMAHAWK2_SUPPORT)
    716         if (SOC_IS_TOMAHAWK2(unit)) {
    717             rv = bcm_th2_failover_lock(unit);
    718             if (rv == BCM_E_NONE) {
    719                 rv = bcm_th2_failover_status_get(unit, failover, value);
    720                 bcm_th2_failover_unlock(unit);
    721             }
    722             return rv;
    723         } else
    724 #endif
    725         {
    726             rv = bcm_tr2_failover_lock (unit);
    727             if ( rv == BCM_E_NONE ) {
    728                 rv = bcm_tr2_failover_get(unit, failover->failover_id, value);
    729                 bcm_tr2_failover_unlock (unit);
    730             }
    731             return rv;
    732         }
    733     }
    734 #endif
    735     return rv;
    736 }
    737 
    738 /*
    739  * Function:
    740  *    _bcm_esw_failover_id_check
    741  * Purpose:
    742  *    Check Failover identifier
    743  * Parameters:
    744  *    IN :  unit
    745  *    IN :  failover_id
    746  * Returns:
    747  *    BCM_E_XXX
    748  */
    749 int
    750 _bcm_esw_failover_id_check(int unit, bcm_failover_t failover_id)
    751 {
    752     int rv = BCM_E_UNAVAIL;
    753 #ifdef BCM_TRIUMPH2_SUPPORT
    754     if (soc_feature(unit, soc_feature_failover)) {
    755         rv = bcm_tr2_failover_id_check(unit, failover_id);
    756     }
    757 #endif
    758     return rv;
    759 }
    760 
    761 /*
    762  * Function:
    763  *		_bcm_esw_failover_mpls_check
    764  * Purpose:
    765  *		Check Failover for MPLS Port
    766  * Parameters:
    767  *		IN :  unit
    768  *           IN :  mpls_port
    769  * Returns:
    770  *		BCM_E_XXX
    771  */
    772 
    773 
    774 int
    775 _bcm_esw_failover_mpls_check(int unit, bcm_mpls_port_t  *mpls_port)
    776 {
    777     int rv = BCM_E_UNAVAIL;
    778 
    779 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_KATANA2_SUPPORT)
    780     if (soc_feature(unit, soc_feature_failover) &&
    781         (SOC_IS_TRIUMPH3(unit) || SOC_IS_KATANA2(unit) ||
    782          SOC_IS_TRIDENT2PLUS(unit) || (SOC_IS_APACHE(unit)) ||
    783          soc_feature(unit,soc_feature_failover_mpls_check))) {
    784          rv = bcm_tr3_failover_mpls_check (unit, mpls_port);
    785          return rv;
    786     }
    787 #endif
    788 
    789 #ifdef BCM_TRIUMPH2_SUPPORT
    790     if (soc_feature(unit, soc_feature_failover)) {
    791          rv = bcm_tr2_failover_mpls_check (unit, mpls_port);
    792          return rv;
    793     }
    794 #endif
    795     return rv;
    796 }
    797 
    798 /*
    799  * Function:
    800  *		_bcm_esw_failover_egr_check
    801  * Purpose:
    802  *		Check Failover for Egress Object
    803  * Parameters:
    804  *		IN :  unit
    805  *           IN :  Egress Object
    806  * Returns:
    807  *		BCM_E_XXX
    808  */
    809 
    810 
    811 int
    812 _bcm_esw_failover_egr_check(int unit, bcm_l3_egress_t  *egr)
    813 {
    814     int rv = BCM_E_UNAVAIL;
    815 
    816 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_KATANA2_SUPPORT)
    817     if (soc_feature(unit, soc_feature_failover) &&
    818         (SOC_IS_TRIUMPH3(unit) || SOC_IS_KATANA2(unit) ||
    819          SOC_IS_TRIDENT2PLUS(unit) ||
    820              soc_feature(unit, soc_feature_egress_failover))) {
    821          rv = bcm_tr3_failover_egr_check (unit, egr);
    822          return rv;
    823     }
    824 #endif
    825 
    826 #ifdef BCM_TRIUMPH2_SUPPORT
    827     if (soc_feature(unit, soc_feature_failover)) {
    828          rv = bcm_tr2_failover_egr_check (unit, egr);
    829          return rv;
    830     }
    831 #endif
    832     return rv;
    833 }
    834 
    835 /*
    836  * Function:
    837  *      _bcm_esw_failover_extender_check
    838  * Purpose:
    839  *      Check Failover for EXTENDER Port
    840  * Parameters:
    841  *      IN :  unit
    842  *      IN :  extender_port
    843  * Returns:
    844  *      BCM_E_XXX
    845  */
    846 
    847 
    848 int
    849 _bcm_esw_failover_extender_check(int unit, 
    850                                  bcm_extender_port_t *extender_port)
    851 {
    852     int rv = BCM_E_UNAVAIL;
    853 
    854 #if defined(BCM_TRIUMPH3_SUPPORT)
    855     if (soc_feature(unit, soc_feature_failover) &&
    856         (SOC_IS_TRIUMPH3(unit) || SOC_IS_TD2_TT2(unit))) {
    857         rv = bcm_tr3_failover_extender_check(unit, extender_port);
    858         return rv;
    859     }
    860 #endif
    861 
    862     return rv;
    863 }
    864 
    865 /*
    866  * Function:
    867  *      _bcm_esw_failover_prot_nhi_create
    868  * Purpose:
    869  *      Create Protection next_hop
    870  * Parameters:
    871  *      IN :  unit
    872   *          IN :  Next_Hop_Index
    873  *           IN :  Egress Object
    874  * Returns:
    875  *      BCM_E_XXX
    876  */
    877 int
    878 bcmi_esw_failover_multi_level_prot_nhi_create(int unit, int index, int prot_nh_index,
    879                                      bcm_multicast_t mc_group,
    880                                      bcm_failover_t failover_id)
    881 {
    882     int rv = BCM_E_UNAVAIL;
    883 
    884     if (!(soc_feature(unit, soc_feature_hierarchical_protection))) {
    885 	    return rv;
    886     }
    887 #if defined(BCM_MULTI_LEVEL_FAILOVER_SUPPORT)
    888         BCM_IF_ERROR_RETURN(bcmi_failover_multi_level_prot_nhi_create(unit, index));
    889         rv = bcmi_failover_multi_level_prot_nhi_set(unit, index,
    890                 prot_nh_index, mc_group, failover_id );
    891         return rv;
    892 #endif
    893     return BCM_E_NONE;
    894 }
    895 
    896 int
    897 bcmi_esw_failover_multi_level_prot_nhi_get(int unit, int nh_index,
    898         bcm_failover_t  *failover_id, int  *prot_nh_index,
    899         bcm_multicast_t  *mc_group)
    900 {
    901     int rv = BCM_E_UNAVAIL;
    902 
    903     if (!(soc_feature(unit, soc_feature_hierarchical_protection))) {
    904         return rv;
    905     }
    906 
    907 #if defined(BCM_MULTI_LEVEL_FAILOVER_SUPPORT)
    908         rv = bcmi_failover_multi_level_prot_nhi_get(unit, nh_index,
    909                 failover_id, prot_nh_index,  mc_group);
    910 #endif
    911     return rv;
    912 }
    913 
    914 int
    915 bcmi_esw_failover_multi_level_prot_nhi_cleanup (int unit, int nh_index)
    916 {
    917 
    918     int rv = BCM_E_UNAVAIL;
    919 
    920     if (!(soc_feature(unit, soc_feature_hierarchical_protection))) {
    921         return rv;
    922     }
    923 #if defined(BCM_MULTI_LEVEL_FAILOVER_SUPPORT)
    924         rv = bcmi_failover_multi_level_prot_nhi_cleanup(unit, nh_index);
    925 #endif
    926 
    927     return rv;
    928 }
    929 
    930 
    931 /*
    932  * Function:
    933  *		_bcm_esw_failover_prot_nhi_create
    934  * Purpose:
    935  *		Create Protection next_hop
    936  * Parameters:
    937  *		IN :  unit
    938   *          IN :  Next_Hop_Index
    939  *           IN :  Egress Object
    940  * Returns:
    941  *		BCM_E_XXX
    942  */
    943 
    944 
    945 int
    946 _bcm_esw_failover_prot_nhi_create(int unit, uint32 flags,
    947                                               int nh_index, int prot_nh_index,
    948                                               bcm_multicast_t mc_group,
    949                                               bcm_failover_t failover_id)
    950 {
    951     int rv = BCM_E_UNAVAIL;
    952 #if defined(BCM_SABER2_SUPPORT)
    953     int type;
    954     bcm_failover_element_t failover;
    955 #endif
    956 
    957 #ifdef BCM_MULTI_LEVEL_FAILOVER_SUPPORT
    958     if(soc_feature(unit, soc_feature_hierarchical_protection)) {
    959         if (_BCM_FAILOVER_IS_MULTI_LEVEL(failover_id)) {
    960             rv = bcmi_esw_failover_multi_level_prot_nhi_create(unit, nh_index,
    961                      prot_nh_index, mc_group, failover_id);
    962             return rv;
    963         }
    964     }
    965 #endif
    966 
    967 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_KATANA2_SUPPORT)
    968     if (soc_feature(unit, soc_feature_failover) &&
    969         (SOC_IS_TRIUMPH3(unit) || SOC_IS_KATANA2(unit))) {
    970 #if defined(BCM_SABER2_SUPPORT)
    971         _BCM_GET_FAILOVER_TYPE(failover_id, type);
    972         if ((type & _BCM_FAILOVER_1_1_MC_PROTECTION_MODE) &&
    973                 SOC_IS_SABER2(unit)) {
    974             _BCM_GET_FAILOVER_ID(failover_id);
    975             rv = bcm_sb2_failover_prot_nhi_set(unit, flags, nh_index, 
    976                     prot_nh_index, mc_group, failover_id );
    977                 bcm_failover_element_t_init (&failover);
    978                 failover.failover_id = failover_id;
    979                 rv = bcm_tr2_failover_lock (unit);
    980                 if ( rv == BCM_E_NONE ) {
    981                     rv = bcm_sb2_failover_status_set(unit, &failover, FALSE);
    982                     bcm_tr2_failover_unlock (unit);
    983                 }
    984             return rv;
    985         } else
    986 #endif
    987         {
    988 
    989             BCM_IF_ERROR_RETURN(bcm_tr2_failover_prot_nhi_create( unit, nh_index ));
    990             rv = bcm_tr3_failover_prot_nhi_set(unit, flags, nh_index, 
    991                     prot_nh_index, mc_group, failover_id );
    992             return rv;
    993         }
    994     }
    995 #endif
    996 
    997 #ifdef BCM_TRIUMPH2_SUPPORT
    998 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
    999     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
   1000         BCM_IF_ERROR_RETURN(bcm_tr2_failover_prot_nhi_create(unit, nh_index));
   1001         rv = bcm_td2p_failover_prot_nhi_set(unit, flags, nh_index, 
   1002                 prot_nh_index, mc_group, failover_id );
   1003         return rv;
   1004     } else
   1005 #endif
   1006     if (soc_feature(unit, soc_feature_failover)) {
   1007         BCM_IF_ERROR_RETURN(bcm_tr2_failover_prot_nhi_create( unit, nh_index ));
   1008         rv = bcm_tr2_failover_prot_nhi_set(unit, nh_index,
   1009                          prot_nh_index, failover_id );
   1010         return rv;
   1011     }
   1012 #endif
   1013     return rv;
   1014 }
   1015 
   1016 /*
   1017  * Function:
   1018  *		_bcm_esw_failover_prot_nhi_cleanup
   1019  * Purpose:
   1020  *		Cleanup protection Next_hop
   1021  * Parameters:
   1022  *		IN :  unit
   1023   *          IN :  Next_Hop_Index
   1024  * Returns:
   1025  *		BCM_E_XXX
   1026  */
   1027 
   1028 
   1029 int
   1030 _bcm_esw_failover_prot_nhi_cleanup(int unit, int nh_index)
   1031 {
   1032     int rv = BCM_E_UNAVAIL;
   1033 
   1034 #ifdef BCM_MULTI_LEVEL_FAILOVER_SUPPORT
   1035     if(soc_feature(unit, soc_feature_hierarchical_protection)) {
   1036         bcm_failover_t failoverid;
   1037         _BCM_FAILOVER_MULTI_LEVEL_FAILOVER_ID_GET(unit, nh_index, failoverid);
   1038         if (_BCM_FAILOVER_IS_MULTI_LEVEL(failoverid)) {
   1039             rv = bcmi_esw_failover_multi_level_prot_nhi_cleanup(unit, nh_index);
   1040 
   1041             return rv;
   1042         } else if (bcmi_l3_nh_multi_count_get(unit, (nh_index - 1)) > 1) {
   1043             return BCM_E_NONE;
   1044         }
   1045     }
   1046 #endif
   1047 
   1048 #ifdef BCM_KATANA2_SUPPORT
   1049     if (soc_feature(unit, soc_feature_failover) && SOC_IS_KATANA2(unit)) {
   1050         rv = bcm_kt2_failover_prot_nhi_cleanup  (unit, nh_index);
   1051         return rv;
   1052     }
   1053 #endif
   1054 
   1055 #ifdef BCM_TRIUMPH3_SUPPORT
   1056     if (soc_feature(unit, soc_feature_failover) && SOC_IS_TRIUMPH3(unit)) {
   1057          rv = bcm_tr3_failover_prot_nhi_cleanup  (unit, nh_index);
   1058          return rv;
   1059     }
   1060 #endif
   1061 
   1062 #ifdef BCM_TRIUMPH2_SUPPORT
   1063 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
   1064     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
   1065         rv = bcm_td2p_failover_prot_nhi_cleanup(unit, nh_index);
   1066         return rv;
   1067     } else
   1068 #endif
   1069     if (soc_feature(unit, soc_feature_failover)) {
   1070          rv = bcm_tr2_failover_prot_nhi_cleanup  (unit, nh_index);
   1071          return rv;
   1072     }
   1073 #endif
   1074     return rv;
   1075 }
   1076 
   1077 /*
   1078  * Function:
   1079  *		_bcm_esw_failover_prot_nhi_get
   1080  * Purpose:
   1081  *		Cleanup protection Next_hop
   1082  * Parameters:
   1083  *		IN :  unit
   1084   *          IN :  Next_Hop_Index
   1085  * Returns:
   1086  *		BCM_E_XXX
   1087  */
   1088 
   1089 int
   1090 _bcm_esw_failover_prot_nhi_get (int unit, int nh_index,
   1091          bcm_failover_t *failover_id, int *prot_nh_index, int *multicast_group)
   1092 {
   1093     int rv = BCM_E_UNAVAIL;
   1094 
   1095 #ifdef BCM_MULTI_LEVEL_FAILOVER_SUPPORT
   1096     if(soc_feature(unit, soc_feature_hierarchical_protection)) {
   1097         bcm_failover_t failoverid;
   1098         if (nh_index > 0) {
   1099             _BCM_FAILOVER_MULTI_LEVEL_FAILOVER_ID_GET(
   1100                 unit, nh_index, failoverid);
   1101             if (_BCM_FAILOVER_IS_MULTI_LEVEL(failoverid)) {
   1102 			    rv = bcmi_esw_failover_multi_level_prot_nhi_get
   1103                     (unit, nh_index, failover_id, prot_nh_index,
   1104                     multicast_group);
   1105                 return rv;
   1106             } else {
   1107                if (bcmi_l3_nh_multi_count_get(unit, (nh_index - 1)) > 1) {
   1108                    return BCM_E_NONE;
   1109                }
   1110             }
   1111         }
   1112     }
   1113 #endif
   1114 
   1115 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_KATANA2_SUPPORT)
   1116     if (soc_feature(unit, soc_feature_failover) &&
   1117         (SOC_IS_TRIUMPH3(unit) || SOC_IS_KATANA2(unit))) {
   1118          rv = bcm_tr3_failover_prot_nhi_get (unit, nh_index, 
   1119                         failover_id, prot_nh_index, multicast_group);
   1120          return rv;
   1121     }
   1122 #endif
   1123 
   1124 #ifdef BCM_TRIUMPH2_SUPPORT
   1125 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
   1126     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
   1127         rv = bcm_td2p_failover_prot_nhi_get(unit, nh_index, 
   1128                 failover_id, prot_nh_index, multicast_group);
   1129         return rv;
   1130     } else
   1131 #endif
   1132     if (soc_feature(unit, soc_feature_failover)) {
   1133          rv = bcm_tr2_failover_prot_nhi_get  (unit, nh_index, 
   1134                         failover_id, prot_nh_index);
   1135          return rv;
   1136     }
   1137 #endif
   1138     return rv;
   1139 }
   1140 
   1141 /*
   1142  * Function:
   1143  *		_bcm_esw_failover_prot_nhi_update
   1144  * Purpose:
   1145  *		Update protection Next_hop
   1146  * Parameters:
   1147  *		IN :  unit
   1148   *          IN :  Next_Hop_Index
   1149  * Returns:
   1150  *		BCM_E_XXX
   1151  */
   1152 
   1153 int
   1154 _bcm_esw_failover_prot_nhi_update (int unit,
   1155                                                 int old_nh_index,
   1156                                                 int new_nh_index)
   1157 
   1158 {
   1159     int rv = BCM_E_UNAVAIL;
   1160 
   1161 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_KATANA2_SUPPORT)
   1162     if (soc_feature(unit, soc_feature_failover) &&
   1163         (SOC_IS_TRIUMPH3(unit) || SOC_IS_KATANA2(unit))) {
   1164         rv = bcm_tr3_failover_prot_nhi_update (unit,
   1165                 old_nh_index, new_nh_index);
   1166         return rv;
   1167     }
   1168 #endif
   1169 
   1170 #ifdef BCM_TRIUMPH2_SUPPORT
   1171 #if defined(BCM_TRIDENT2PLUS_SUPPORT)
   1172     if (soc_feature(unit, soc_feature_td2p_mpls_linear_protection)) {
   1173         rv = bcm_td2p_failover_prot_nhi_update(unit,
   1174                 old_nh_index, new_nh_index);
   1175         return rv;
   1176     } else
   1177 #endif
   1178     if (soc_feature(unit, soc_feature_failover)) {
   1179         rv = bcm_tr2_failover_prot_nhi_update (unit,
   1180                 old_nh_index, new_nh_index);
   1181         return rv;
   1182     }
   1183 #endif
   1184     return rv;
   1185 }
   1186 
   1187 /*
   1188  * Function:
   1189  *    _bcm_esw_failover_ecmp_prot_nhi_create
   1190  * Purpose:
   1191  *    Create Protection next_hop for a ecmp member
   1192  * Parameters:
   1193  *    IN :  unit
   1194  *    IN :  ecmp index /dvp group pointer
   1195  *    IN :  member offset from base ptr
   1196  *    IN :  Next_Hop_Index
   1197  *    IN :  failover identifier
   1198  *    IN :  Protect Object
   1199  * Returns:
   1200  *    BCM_E_XXX
   1201  */
   1202 
   1203 int
   1204 _bcm_esw_failover_ecmp_prot_nhi_create(int unit, int ecmp, int index,
   1205                                        int nh_index, bcm_failover_t failover_id,
   1206                                        int prot_nh_index)
   1207 {
   1208     int rv = BCM_E_UNAVAIL;
   1209 
   1210 #ifdef BCM_TRIUMPH2_SUPPORT
   1211     if (soc_feature(unit, soc_feature_ecmp_failover)) {
   1212         rv = bcm_tr2_failover_ecmp_prot_nhi_set(unit, ecmp, index, nh_index,
   1213                                                 failover_id, prot_nh_index);
   1214     }
   1215 #endif
   1216 
   1217     return rv;
   1218 }
   1219 
   1220 /*
   1221  * Function:
   1222  *   _bcm_esw_failover_ecmp_prot_nhi_cleanup
   1223  * Purpose:
   1224  *    Cleanup protection Next_hop  for a ecmp member
   1225  * Parameters:
   1226  *    IN :  unit
   1227  *    IN :  ecmp index /dvp group pointer
   1228  *    IN :  member offset from base ptr
   1229  *    IN :  Next_Hop_Index
   1230  * Returns:
   1231  *    BCM_E_XXX
   1232  */
   1233 
   1234 int
   1235 _bcm_esw_failover_ecmp_prot_nhi_cleanup(int unit, int ecmp, int index, 
   1236                                         int nh_index)
   1237 {
   1238     int rv = BCM_E_UNAVAIL;
   1239 
   1240 #ifdef BCM_TRIUMPH2_SUPPORT
   1241     if (soc_feature(unit, soc_feature_ecmp_failover)) {
   1242         rv = bcm_tr2_failover_ecmp_prot_nhi_cleanup(unit, ecmp, index, 
   1243                                                     nh_index);
   1244     }
   1245 #endif
   1246 
   1247     return rv;
   1248 }
   1249 
   1250 /*
   1251  * Function:
   1252  *    _bcm_esw_failover_ecmp_prot_nhi_get
   1253  * Purpose:
   1254  *    Cleanup protection Next_hop  for a ecmp member
   1255  * Parameters:
   1256  *    IN :  unit
   1257  *    IN :  ecmp index /dvp group pointer
   1258  *    IN :  member offset from base ptr
   1259  *    IN :  Next_Hop_Index
   1260  *    OUT :  failover identifier
   1261  *    OUT :  Protect Object
   1262  * Returns:
   1263  *    BCM_E_XXX
   1264  */
   1265 
   1266 int
   1267 _bcm_esw_failover_ecmp_prot_nhi_get(int unit, int ecmp, int index, 
   1268                                     int nh_index, bcm_failover_t *failover_id, 
   1269                                     int *prot_nh_index)
   1270 {
   1271     int rv = BCM_E_UNAVAIL;
   1272 
   1273 #ifdef BCM_TRIUMPH2_SUPPORT
   1274     if (soc_feature(unit, soc_feature_ecmp_failover)) {
   1275         rv = bcm_tr2_failover_ecmp_prot_nhi_get(unit, ecmp, index, nh_index, 
   1276                                                 failover_id, prot_nh_index);
   1277     }
   1278 #endif
   1279 
   1280     return rv;
   1281 }
   1282 
   1283 /*
   1284  * Function:
   1285  *    _bcm_esw_failover_ecmp_prot_nhi_update
   1286  * Purpose:
   1287  *    Update protection Next_hop  for a ecmp member
   1288  * Parameters:
   1289  *    IN :  unit
   1290  *    IN :  ecmp index /dvp group pointer
   1291  *    IN :  Next_Hop_Index
   1292  * Returns:
   1293  *    BCM_E_XXX
   1294  */
   1295 
   1296 int
   1297 _bcm_esw_failover_ecmp_prot_nhi_update(int unit, int ecmp, int index, 
   1298                                        int old_nh_index, int new_nh_index)
   1299 {
   1300     int rv = BCM_E_UNAVAIL;
   1301 
   1302 #ifdef BCM_TRIUMPH2_SUPPORT
   1303     if (soc_feature(unit, soc_feature_ecmp_failover)) {
   1304         rv = bcm_tr2_failover_ecmp_prot_nhi_set(unit, ecmp, index,
   1305                                                 old_nh_index, 
   1306                                                 BCM_FAILOVER_INVALID, 
   1307                                                 new_nh_index);
   1308     }
   1309 #endif
   1310 
   1311     return rv;
   1312 }
   1313 
   1314 /*
   1315  * Function:
   1316  *    bcm_esw_failover_multi_level_attach
   1317  * Purpose:
   1318  *    Attaches multiple levels of failover together.
   1319  * Parameters:
   1320  *    unit                 - (IN)bcm device id
   1321  *    multi_level_failover - (IN)iformation strcut to attch multiple levels.
   1322  * Returns:
   1323  *    BCM_E_XXX
   1324  */
   1325 int
   1326 bcm_esw_failover_multi_level_attach(
   1327     int unit,
   1328     bcm_failover_multi_level_t multi_level_failover)
   1329 {
   1330     int rv = BCM_E_UNAVAIL;
   1331 
   1332 #ifdef BCM_MULTI_LEVEL_FAILOVER_SUPPORT
   1333     rv = bcm_td2p_failover_lock(unit);
   1334     if (rv == BCM_E_NONE) {
   1335         rv = bcmi_failover_multi_level_attach(unit, multi_level_failover);
   1336         bcm_td2p_failover_unlock(unit);
   1337     }
   1338 #endif
   1339 
   1340     return rv;
   1341 }
   1342 /*
   1343  * Function:
   1344  *    bcmi_esw_failover_dependent_free_resources
   1345  * Purpose:
   1346  *    frees l3 dependednt resources from other modules.
   1347  * Parameters:
   1348  *    unit                 - (IN)bcm device id
   1349  * Returns:
   1350  *    NONE
   1351  */
   1352 void
   1353 bcmi_esw_failover_dependent_free_resources(int unit)
   1354 {
   1355 #ifdef BCM_TRIDENT2PLUS_SUPPORT
   1356     bcmi_failover_dependent_free_resources(unit);
   1357 #endif
   1358 }
   1359 
   1360 /* Failover with Fixed NH Offset */
   1361 int
   1362 bcm_esw_failover_egress_set(int unit, bcm_if_t intf,
   1363                             bcm_l3_egress_t *failover_egr)
   1364 {
   1365     int rv = BCM_E_UNAVAIL;
   1366 
   1367 #if defined(BCM_TOMAHAWK3_SUPPORT)
   1368     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset) && SOC_IS_TOMAHAWK3(unit)) {
   1369          return bcm_th3_failover_egress_set(unit, intf, failover_egr);
   1370     }
   1371 #endif
   1372 
   1373     return rv;
   1374 }
   1375 
   1376 int
   1377 bcm_esw_failover_egress_get(int unit, bcm_if_t intf,
   1378                             bcm_l3_egress_t *failover_egr)
   1379 {
   1380     int rv = BCM_E_UNAVAIL;
   1381 
   1382 #if defined(BCM_TOMAHAWK3_SUPPORT)
   1383     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset) && SOC_IS_TOMAHAWK3(unit)) {
   1384          return bcm_th3_failover_egress_get(unit, intf, failover_egr);
   1385     }
   1386 #endif
   1387 
   1388     return rv;
   1389 }
   1390 
   1391 int
   1392 bcm_esw_failover_egress_clear(int unit, bcm_if_t intf)
   1393 {
   1394     int rv = BCM_E_UNAVAIL;
   1395 
   1396 #if defined(BCM_TOMAHAWK3_SUPPORT)
   1397     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset) && SOC_IS_TOMAHAWK3(unit)) {
   1398          return bcm_th3_failover_egress_clear(unit, intf);
   1399     }
   1400 #endif
   1401 
   1402     return rv;
   1403 }
   1404 
   1405 int
   1406 bcm_esw_failover_egress_status_set(int unit, bcm_if_t intf, int enable)
   1407 {
   1408     int rv = BCM_E_UNAVAIL;
   1409 
   1410 #if defined(BCM_TOMAHAWK3_SUPPORT)
   1411     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset) && SOC_IS_TOMAHAWK3(unit)) {
   1412          return bcm_th3_failover_egress_status_set(unit, intf, enable);
   1413     }
   1414 #endif
   1415 
   1416     return rv;
   1417 }
   1418 
   1419 int
   1420 bcm_esw_failover_egress_status_get(int unit, bcm_if_t intf, int *enable)
   1421 {
   1422     int rv = BCM_E_UNAVAIL;
   1423 
   1424 #if defined(BCM_TOMAHAWK3_SUPPORT)
   1425     if (soc_feature(unit, soc_feature_failover_fixed_nh_offset) && SOC_IS_TOMAHAWK3(unit)) {
   1426          return bcm_th3_failover_egress_status_get(unit, intf, enable);
   1427     }
   1428 #endif
   1429 
   1430     return rv;
   1431 }
   1432 
   1433 #else   /* INCLUDE_L3 */
   1434 int bcm_esw_failover_not_empty;
   1435 #endif  /* INCLUDE_L3 */
   1436 
   1437 int
   1438 bcm_esw_failover_ring_config_get(int unit,
   1439                                              bcm_failover_ring_t *failover_ring)
   1440 {
   1441     int rv = BCM_E_UNAVAIL;
   1442 
   1443 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_KATANA2_SUPPORT)
   1444     if (soc_feature(unit, soc_feature_failover) &&
   1445         (SOC_IS_TRIUMPH3(unit) || SOC_IS_KATANA2(unit))) {
   1446          return bcm_tr3_failover_ring_config_get(unit, failover_ring);
   1447     }
   1448 #endif
   1449 
   1450     return rv;
   1451 }
   1452 
   1453 int
   1454 bcm_esw_failover_ring_config_set(int unit,
   1455                                             bcm_failover_ring_t *failover_ring)
   1456 {
   1457     int rv = BCM_E_UNAVAIL;
   1458 
   1459 #if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_KATANA2_SUPPORT)
   1460 
   1461     if (soc_feature(unit, soc_feature_failover) &&
   1462         (SOC_IS_TRIUMPH3(unit) || SOC_IS_KATANA2(unit))) {
   1463          return bcm_tr3_failover_ring_config_set(unit, failover_ring);
   1464     }
   1465 #endif
   1466 
   1467     return rv;
   1468 }
   1469