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 (3986B)


      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  * TD3 failover API
      8  */
      9 
     10 #include <soc/defs.h>
     11 #include <sal/core/libc.h>
     12 
     13 #if defined(BCM_TRIDENT3_SUPPORT) &&  defined(INCLUDE_L3)
     14 
     15 #include <soc/drv.h>
     16 #include <soc/mem.h>
     17 #include <soc/util.h>
     18 #include <soc/debug.h>
     19 #include <bcm/types.h>
     20 #include <bcm/error.h>
     21 #include <bcm_int/esw/mbcm.h>
     22 #include <bcm_int/esw_dispatch.h>
     23 #include <bcm_int/esw/field.h>
     24 #include <bcm_int/esw/failover.h>
     25 #include <bcm/failover.h>
     26 #ifdef BCM_WARM_BOOT_SUPPORT
     27 #include <bcm_int/esw/switch.h>
     28 #include <soc/scache.h>
     29 #endif /* BCM_WARM_BOOT_SUPPORT */
     30 
     31 #ifdef BCM_WARM_BOOT_SUPPORT
     32 
     33 #define BCM_WB_VERSION_1_0                SOC_SCACHE_VERSION(1,0)
     34 #define BCM_WB_DEFAULT_VERSION            BCM_WB_VERSION_1_0
     35 
     36 
     37 /*
     38  * Function:
     39  *     bcm_td3_failover_alloc
     40  * Purpose:
     41  *     Alloc scache for warm boot.
     42  * Parameters:
     43  *      unit    : (IN) Device Unit Number
     44  * Returns:
     45  *      BCM_E_XXX
     46  */
     47 int
     48 bcm_td3_failover_alloc(int unit)
     49 {
     50     soc_scache_handle_t scache_handle;
     51     uint8 *scache_ptr;
     52     int rv, alloc_size, prot_grp_idx_count;
     53 
     54     prot_grp_idx_count = soc_mem_index_count(unit, TX_INITIAL_PROT_GROUP_TABLEm);
     55     alloc_size = SHR_BITALLOCSIZE(prot_grp_idx_count);
     56     SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_FAILOVER, 0);
     57     rv = _bcm_esw_scache_ptr_get(unit, scache_handle, TRUE, alloc_size,
     58                                  &scache_ptr, BCM_WB_DEFAULT_VERSION, NULL);
     59     if (rv == BCM_E_NOT_FOUND) {
     60         rv = BCM_E_NONE;
     61     }
     62 
     63     return rv;
     64 }
     65 
     66 /*
     67  * Function:
     68  *     bcm_td3_failover_reinit
     69  * Purpose:
     70  *     Scache recovery for warm boot.
     71  * Parameters:
     72  *      unit    : (IN) Device Unit Number
     73  * Returns:
     74  *      BCM_E_XXX
     75  */
     76 int
     77 bcm_td3_failover_reinit(int unit)
     78 {
     79     soc_scache_handle_t scache_handle;
     80     uint8 *scache_ptr, *ptr;
     81     int rv, prot_grp_idx_count;
     82     uint16 recovered_ver;
     83 
     84     SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_FAILOVER, 0);
     85     rv = _bcm_esw_scache_ptr_get(unit, scache_handle, FALSE, 0,
     86                                  &scache_ptr, BCM_WB_DEFAULT_VERSION, &recovered_ver);
     87 
     88     if (BCM_E_NOT_FOUND == rv) {
     89         /* Upgrading from SDK release that does not have warmboot state,
     90            Alloc scache for now on */
     91         rv = bcm_td3_failover_alloc(unit);
     92         if (BCM_FAILURE(rv)) {
     93             return rv;
     94         }
     95         return BCM_E_NOT_FOUND;
     96     } else if (BCM_FAILURE(rv)) {
     97         return rv;
     98     }
     99 
    100     /* SCACHE Hande found, recover from SCAHE */
    101     prot_grp_idx_count = soc_mem_index_count(unit, TX_INITIAL_PROT_GROUP_TABLEm);
    102     ptr = scache_ptr;
    103 
    104     /* Recover PROT_GROUP_MAP */
    105     sal_memcpy(BCM_FAILOVER_PROT_GROUP_MAP(unit), ptr,
    106                SHR_BITALLOCSIZE(prot_grp_idx_count));
    107     ptr += SHR_BITALLOCSIZE(prot_grp_idx_count);
    108 
    109     return BCM_E_NONE;
    110 }
    111 
    112 
    113 /*
    114  * Function:
    115  *     bcm_td3_failover_sync
    116  * Purpose:
    117  *     Sync scache for warm boot.
    118  * Parameters:
    119  *      unit    : (IN) Device Unit Number
    120  * Returns:
    121  *      BCM_E_XXX
    122  */
    123 int
    124 bcm_td3_failover_sync(int unit)
    125 {   
    126     soc_scache_handle_t scache_handle;
    127     uint8 *scache_ptr, *ptr;
    128     int prot_grp_idx_count;
    129     int rv;
    130 
    131     SOC_SCACHE_HANDLE_SET(scache_handle, unit, BCM_MODULE_FAILOVER, 0);
    132     rv = _bcm_esw_scache_ptr_get(unit, scache_handle, FALSE, 0,
    133                                  &scache_ptr, BCM_WB_DEFAULT_VERSION, NULL);
    134     if (BCM_FAILURE(rv)) {
    135         if (rv == BCM_E_NOT_FOUND) {
    136             return BCM_E_NONE;
    137         }
    138         return rv;
    139     }
    140 
    141     ptr = scache_ptr;
    142     prot_grp_idx_count = soc_mem_index_count(unit, TX_INITIAL_PROT_GROUP_TABLEm);
    143 
    144     /* Sync PROT_GROUP_MAP */
    145     sal_memcpy(ptr, BCM_FAILOVER_PROT_GROUP_MAP(unit),
    146                SHR_BITALLOCSIZE(prot_grp_idx_count));
    147     ptr += SHR_BITALLOCSIZE(prot_grp_idx_count);
    148 
    149     return BCM_E_NONE;
    150 }
    151 
    152 
    153 #endif
    154 #endif