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

ecmp.h (9364B)


      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  * File:        ecmp.h
      8  * Purpose:     SOC ECMP functions.
      9  */
     10 
     11 #ifndef   _SOC_ESW_ECMP_H_
     12 #define   _SOC_ESW_ECMP_H_
     13 
     14 #include <soc/drv.h>
     15 
     16 #define SOC_ESW_ECMP_MAX_BANKS    0x4
     17 #define SOC_ESW_ECMP_BANK_SIZE    1024
     18 #define SOC_ESW_ECMP_MAX_GROUPS   4096
     19 
     20 
     21 #define SOC_ESW_ECMP_IF_ERR_EXIT(rv)        \
     22     do {                                    \
     23         if (rv < 0) {                       \
     24             goto err_exit;                  \
     25         }                                   \
     26     } while(0)
     27 
     28 typedef enum soc_esw_ecmp_bank_lkup_level_e {
     29     socEswEcmpBankLkupLevelInvalid  = 0,
     30     socEswEcmpBankLkupLevelUnderlay = 1,
     31     socEswEcmpBankLkupLevelOverlay  = 2,
     32     socEswEcmpBankLkupLevelReserved = 3
     33 } soc_esw_ecmp_bank_lkup_level_t;
     34 
     35 typedef struct soc_esw_ecmp_init_info_s {
     36     int num_levels;       /* Ecmp lookup levels. */
     37     int num_banks;        /* Number of banks in ecmp member table. */
     38     int bank_size;        /* Size of each ecmp member bank. */
     39     int lkup1_size;       /* Ecmp first lookup size. */
     40     int lkup2_size;       /* Ecmp second lookup size. */
     41     int ecmp_if_offset;  /* Ecmp interface min offset.  */
     42 #ifdef BCM_WARM_BOOT_SUPPORT
     43     soc_scache_handle_t scache_handle;
     44 #endif /* BCM_WARM_BOOT_SUPPORT */
     45 } soc_esw_ecmp_init_info_t;
     46 
     47 typedef struct soc_esw_ecmp_group_info_s {
     48     int ecmp_grp;         /* ECMP Group Index. */
     49     int ecmp_member_base; /* Ecmp member base. */
     50     int max_paths;        /* Number of ECMP paths in group. */
     51     int vp_lag;           /* Update for VP Lags */
     52     uint32 flags;         /* Ecmp group flags. */
     53 } soc_esw_ecmp_group_info_t;
     54 
     55 typedef struct soc_esw_ecmp_member_info_s {
     56     uint32 dvp;
     57     uint32 nh;
     58     uint32 prot_grp;
     59     uint32 prot_nh;
     60 } soc_esw_ecmp_member_info_t;
     61 
     62 typedef struct soc_esw_ecmp_bank_state_s {
     63     int protected_write_disabled;
     64     soc_esw_ecmp_bank_lkup_level_t level;
     65     int idx_min;
     66     int idx_max;
     67     int tbl_offset;
     68     int bank_size;
     69     SHR_BITDCL idx_used[_SHR_BITDCLSIZE(SOC_ESW_ECMP_BANK_SIZE)];
     70 } soc_esw_ecmp_bank_state_t;
     71 
     72 typedef struct soc_esw_ecmp_group_state_s {
     73     int count;
     74     int base;
     75     int bank;
     76 } soc_esw_ecmp_group_state_t;
     77 
     78 typedef struct soc_esw_ecmp_state_s {
     79     sal_mutex_t       soc_esw_ecmp_lock;       /* SOC ECMP lock */
     80 #ifdef BCM_WARM_BOOT_SUPPORT
     81     soc_scache_handle_t scache_handle;
     82 #endif /* BCM_WARM_BOOT_SUPPORT */
     83 
     84 
     85     int ecmp_member_banks;
     86     int ecmp_members_per_banks;
     87     int ecmp_grp_if_offset;
     88 
     89     soc_esw_ecmp_bank_state_t ecmp_member_bank_info[SOC_ESW_ECMP_MAX_BANKS];
     90     soc_esw_ecmp_group_state_t ecmp_group_info[SOC_ESW_ECMP_MAX_GROUPS];
     91 
     92     int ecmp_spare_bank_idx;
     93 } soc_esw_ecmp_state_t;
     94 
     95 
     96 extern soc_esw_ecmp_state_t *soc_esw_ecmp_state[SOC_MAX_NUM_DEVICES];
     97 
     98 #define SOC_ESW_ECMP_STATE(_u_) \
     99     (soc_esw_ecmp_state[unit])
    100 
    101 #define SOC_ESW_ECMP_GROUP_INFO(_u_, _gix_) \
    102     &(SOC_ESW_ECMP_STATE(unit)->ecmp_group_info[_gix_])
    103 
    104 #define SOC_ESW_ECMP_BANK_INFO(_u_, _bix_) \
    105     &(SOC_ESW_ECMP_STATE(unit)->ecmp_member_bank_info[_bix_])
    106 
    107 #define SOC_ESW_ECMP_BANK_PROTECTED_ACCESS(_u_, _bix_) \
    108     ((SOC_ESW_ECMP_STATE(unit)->ecmp_member_bank_info[_bix_].protected_write_disabled) == 0)
    109 
    110 #define SOC_ESW_ECMP_BANK_RSVD_GET(_u_) \
    111     ((SOC_ESW_ECMP_STATE(unit)->ecmp_spare_bank_idx))
    112 
    113 #define SOC_ESW_ECMP_LOCK(unit)    soc_esw_ecmp_state_lock(unit)
    114 #define SOC_ESW_ECMP_UNLOCK(unit)  soc_esw_ecmp_state_unlock(unit)
    115 
    116 
    117 #if 0
    118 #define SOC_ESW_ECMP_LOCK(unit)                      \
    119     do {                                             \
    120         int _rv1;                                    \
    121         _rv1 = soc_esw_ecmp_state_lock(unit);        \
    122         SOC_IF_ERROR_RETURN(_rv1);                   \
    123     } while(0)
    124 
    125 #define SOC_ESW_ECMP_UNLOCK(unit)                    \
    126     do {                                             \
    127         int _rv1;                                    \
    128         _rv1 = soc_esw_ecmp_state_unlock(unit);      \
    129         SOC_IF_ERROR_RETURN(_rv1);                   \
    130     } while(0)
    131 #endif
    132 
    133 extern void
    134 soc_esw_ecmp_init_info_t_init(soc_esw_ecmp_init_info_t *info);
    135 
    136 extern void
    137 soc_esw_ecmp_group_info_t_init(soc_esw_ecmp_group_info_t *info);
    138 
    139 
    140 /*
    141  * Function:
    142  *      soc_esw_ecmp_protected_init
    143  * Purpose:
    144  *      Initialize state for ecmp protected accesses
    145  * Parameters:
    146  *      unit            - (IN)SOC unit number.
    147  *      init_info       - (IN)ECMP init info.
    148  * Returns:
    149  *      SOC_E_XXX
    150  */
    151 extern int
    152 soc_esw_ecmp_protected_init(int unit,
    153                             soc_esw_ecmp_init_info_t *init_info);
    154 
    155 /*
    156  * Function:
    157  *      soc_esw_ecmp_protected_detach
    158  * Purpose:
    159  *      De-Initialize state for ecmp protected accesses
    160  * Parameters:
    161  *      unit       - (IN)SOC unit number.
    162  * Returns:
    163  *      SOC_E_XXX
    164  */
    165 extern int
    166 soc_esw_ecmp_protected_detach(int unit);
    167 
    168 
    169 
    170 extern int
    171 soc_esw_ecmp_state_lock(int unit);
    172 
    173 extern int
    174 soc_esw_ecmp_state_unlock(int unit);
    175 
    176 /*
    177  * Function:
    178  *      soc_esw_ecmp_protected_enabled
    179  * Purpose:
    180  *      Checks whether protected ecmp is required or not.
    181  * Parameters:
    182  *      unit       - (IN)SOC unit number.
    183  * Returns:
    184  *      TRUE: Protected ECMP access routines should be used
    185  *      FALSE: Protected ECMP access routines are not required
    186  */
    187 extern int
    188 soc_esw_ecmp_protected_enabled(int unit);
    189 
    190 
    191 extern int
    192 soc_esw_ecmp_protected_banks_get(int unit,
    193                                  soc_esw_ecmp_bank_lkup_level_t lvl,
    194                                  uint32 *bank_bitmap);
    195 
    196 extern int
    197 soc_esw_ecmp_protected_idx_free_get(int unit,
    198                                     int bix,
    199                                     int count,
    200                                     int *free_idx);
    201 /*
    202  * Function:
    203  *      soc_esw_ecmp_protected_bank_defragment
    204  * Purpose:
    205  *      Defragment an ecmp bank to fill up holes in
    206  *      the middle of the ecmp member table and compress.
    207  * Parameters:
    208  *      unit            - (IN)  SOC unit number.
    209  *      bank_idx        - (IN)  bank idx to compress.
    210  *      grp_idx_move    - (IN)  ecmp group id to write.
    211  *      free_count      - (OUT) Free count in bank after compression.
    212  * Returns:
    213  *      SOC_E_XXX
    214  */
    215 extern int
    216 soc_esw_ecmp_protected_bank_defragment(int unit,
    217                                        int bank_idx,
    218                                        int grp_idx_move,
    219                                        int *free_count);
    220 
    221 
    222 /*
    223  * Function:
    224  *      soc_esw_ecmp_protected_ser_update
    225  * Purpose:
    226  *      Free the bank corresponding to index of errored ECMP memory.
    227  * Parameters:
    228  *      unit            - (IN)  SOC unit number.
    229  *      mem             - (IN)  SOC memory.
    230  *      ecmp_idx        - (IN)  ECMP memory index.
    231  * Returns:
    232  *      SOC_E_XXX
    233  */
    234 extern int
    235 soc_esw_ecmp_protected_ser_update(int unit,
    236                                   soc_mem_t mem,
    237                                   int ecmp_idx);
    238 
    239 /*
    240  * Function:
    241  *      soc_esw_ecmp_bank_free_count_get
    242  * Purpose:
    243  *      Get the number of free entries in this bank.
    244  * Parameters:
    245  *      unit            - (IN)  SOC unit number.
    246  *      bank_idx        - (IN)  Bank index.
    247  *      count           - (OUT) Free entry count.
    248  * Returns:
    249  *      SOC_E_XXX
    250  */
    251 extern int
    252 soc_esw_ecmp_bank_free_count_get(int unit, int bank_idx, int *count);
    253 
    254 /*
    255  * Function:
    256  *      soc_esw_ecmp_protected_grp_add
    257  * Purpose:
    258  *      Add ecmp group next hop members, or reset ecmp group entry.
    259  *      NOTE: Function only updates the INITIAL_L3_ECMP and L3_ECMP tables only.
    260  *            Group tables and other associated tables are updated by the callee.
    261  *            Function may update group tables of other groups as part of this API though.
    262  * Parameters:
    263  *      unit       - (IN)SOC unit number.
    264  *      grp_info   - (IN)ecmp group id to write.
    265  *      nh_list    - (IN)Next hop indexes or NULL for entry reset.
    266  * Returns:
    267  *      SOC_E_XXX
    268  */
    269 extern int
    270 soc_esw_ecmp_protected_grp_add(int unit,
    271                                soc_esw_ecmp_group_info_t *grp_info,
    272                                void *nh_list);
    273 
    274 /*
    275  * Function:
    276  *      soc_esw_ecmp_protected_grp_delete
    277  * Purpose:
    278  *      Delete ECMP members
    279  *      NOTE: Function does not update the INITIAL_L3_ECMP and L3_ECMP tables.
    280  *            Group tables need to be updated to reflect group delete.
    281  * Parameters:
    282  *      unit       - (IN)SOC unit number.
    283  *      grp_info   - (IN)ecmp group id to write.
    284  * Returns:
    285  *      SOC_E_XXX
    286  */
    287 extern int
    288 soc_esw_ecmp_protected_grp_delete(int unit,
    289                                   soc_esw_ecmp_group_info_t *grp_info);
    290 
    291 
    292 /*
    293  * Function:
    294  *      soc_esw_ecmp_protected_grp_get
    295  * Purpose:
    296  *      Fetch ecmp members info for a given group
    297  * Parameters:
    298  *      unit       - (IN)SOC unit number.
    299  *      grp_info   - (IN)ecmp group id to write.
    300  *      nh_list    - (OUT)Next hop indexes or NULL for entry reset.
    301  * Returns:
    302  *      SOC_E_XXX
    303  */
    304 extern int
    305 soc_esw_ecmp_protected_grp_get(int unit,
    306                                soc_esw_ecmp_group_info_t *grp_info,
    307                                void *nh_list);
    308 
    309 #ifdef BCM_WARM_BOOT_SUPPORT
    310 extern int
    311 soc_esw_ecmp_protected_state_warmboot_sync(int unit);
    312 #endif /* BCM_WARM_BOOT_SUPPORT */
    313 
    314 #endif /* _SOC_ESW_ECMP_H_ */