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

index_table_mgmt.h (13570B)


      1 /*! \file index_table_mgmt.h
      2  *
      3  * Index-based table management header file.
      4  * This file contains the header information of index-based table.
      5  */
      6 /*
      7  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      8  * 
      9  * Copyright 2007-2020 Broadcom Inc. All rights reserved.
     10  */
     11 
     12 #ifndef BCMI_LTSW_IDX_TBL_MGMT_H
     13 #define BCMI_LTSW_IDX_TBL_MGMT_H
     14 
     15 #include <sal/sal_mutex.h>
     16 #include <shr/shr_bitop.h>
     17 
     18 /*! Only allocate a new slot. */
     19 #define BCMI_LTSW_IDX_TBL_OP_MATCH_DISABLE        0x00000001
     20 /*! Do not update LT table. */
     21 #define BCMI_LTSW_IDX_TBL_OP_WRITE_DISABLE        0x00000002
     22 /*! With ID. */
     23 #define BCMI_LTSW_IDX_TBL_OP_WITH_ID              0x00000004
     24 /*! Replace. */
     25 #define BCMI_LTSW_IDX_TBL_OP_REPLACE              0x00000008
     26 /*! Skip entry 0. */
     27 #define BCMI_LTSW_IDX_TBL_OP_SKIP_INDEX_ZERO      0x00000010
     28 
     29 typedef int (*entry_func_hash) (int unit, void *entry, uint16_t *hash);
     30 typedef int (*entry_func_cmp) (int unit, int index, void *entry, int *result);
     31 typedef int (*entry_func_insert) (int unit, uint32_t flags,
     32                                   int index, void *entry);
     33 typedef int (*entry_func_del) (int unit, int index);
     34 
     35 typedef enum bcmi_ltsw_idx_tbl_id_e {
     36     /*! Egress L3 tunnel initiator table. */
     37     BCMI_LTSW_IDX_TBL_ID_EGR_L3_TNL = 0,
     38 
     39     /*! Multicast aggregate list member remap table. */
     40     BCMI_LTSW_IDX_TBL_ID_TM_MC_AGG_LIST_MEMBER_REMAP = 1,
     41 
     42     /*! EGR_MPLS_VPN table. */
     43     BCMI_LTSW_IDX_TBL_ID_EGR_MPLS_VPN = 2,
     44 
     45     /*! Egress L3 tunnel initiator IPv6 table. */
     46     BCMI_LTSW_IDX_TBL_ID_EGR_L3_IP6_TNL = 3,
     47 
     48     /*! Egress MPLS tunnel initiator table. */
     49     BCMI_LTSW_IDX_TBL_ID_TNL_MPLS_ENCAP = 4,
     50 
     51     /*! L2_MC_GROUP table. */
     52     BCMI_LTSW_IDX_TBL_ID_L2_MC_GROUP = 5,
     53 
     54     /*! INT action profile table. */
     55     BCMI_LTSW_IDX_TBL_ID_INT_ACTION_PROFILE = 5,
     56 
     57     /*! INT opaque data profile table. */
     58     BCMI_LTSW_IDX_TBL_ID_INT_OPAQUE_DATA_PROFILE = 6,
     59 
     60     /*! INT metadata profile table. */
     61     BCMI_LTSW_IDX_TBL_ID_INT_METADATA_PROFILE = 7,
     62 
     63     /*! INT metadata select profile table. */
     64     BCMI_LTSW_IDX_TBL_ID_INT_METADATA_SELECT_PROFILE = 8,
     65 
     66     /*! INT metadata construct profile table. */
     67     BCMI_LTSW_IDX_TBL_ID_INT_METADATA_CONSTRUCT_PROFILE = 9,
     68 
     69     /*! Always at last. */
     70     BCMI_LTSW_IDX_TBL_ID_CNT
     71 } bcmi_ltsw_idx_tbl_id_t;
     72 
     73 typedef enum bcmi_ltsw_idx_tbl_egr_l3_tnl_user_id {
     74     /*! IP tunnel. */
     75     BCMI_EGR_L3_TNL_USER_ID_IP_TNL = 0,
     76 
     77     /*! MPLS. */
     78     BCMI_EGR_L3_TNL_USER_ID_MPLS = 1,
     79 
     80     /*! Flex flow. */
     81     BCMI_EGR_L3_TNL_USER_ID_FLEX_FLOW = 2,
     82 
     83     /*! Always at last. */
     84     BCMI_EGR_L3_TNL_USER_ID_CNT
     85 } bcmi_ltsw_idx_tbl_egr_l3_tnl_user_id;
     86 
     87 typedef enum bcmi_ltsw_idx_tbl_tm_mc_agg_list_member_remap_user_id {
     88     /*! Multicast. */
     89     BCMI_TM_MC_AGG_LIST_MEMBER_REMAP_USER_ID_MC = 0,
     90 
     91     /*! Always at last. */
     92     BCMI_TM_MC_AGG_LIST_MEMBER_REMAP_USER_ID_CNT
     93 } bcmi_ltsw_idx_tbl_tm_mc_agg_list_member_remap_user_id;
     94 
     95 typedef enum bcmi_ltsw_idx_tbl_egr_mpls_vpn_user_id {
     96     /*!MPLS. */
     97     BCMI_EGR_MPLS_VPN_USER_ID_MPLS = 0,
     98 
     99     /*! INT. */
    100     BCMI_EGR_MPLS_VPN_USER_ID_INT = 1,
    101 
    102     /*! Always at last. */
    103     BCMI_EGR_MPLS_VPN_USER_ID_CNT
    104 } bcmi_ltsw_idx_tbl_egr_mpls_vpn_user_id;
    105 
    106 typedef enum bcmi_ltsw_idx_tbl_egr_l3_ip6_tnl_user_id {
    107     /*! IP tunnel for IPv6. */
    108     BCMI_EGR_L3_IP6_TNL_USER_ID_IP6_TNL = 0,
    109 
    110     /*! Flex flow. */
    111     BCMI_EGR_L3_IP6_TNL_USER_ID_FLEX_FLOW = 1,
    112 
    113     /*! Always at last. */
    114     BCMI_EGR_L3_IP6_TNL_USER_ID_CNT
    115 } bcmi_ltsw_idx_tbl_egr_l3_ip6_tnl_user_id;
    116 
    117 typedef enum bcmi_ltsw_idx_tbl_tnl_mpls_encap_user_id {
    118     /*! MPLS tunnel. */
    119     BCMI_TNL_MPLS_ENCAP_USER_ID_MPLS = 0,
    120 
    121     /*! Always at last. */
    122     BCMI_TNL_MPLS_ENCAP_USER_ID_CNT
    123 } bcmi_ltsw_idx_tbl_tnl_mpls_encap_user_id;
    124 
    125 typedef enum bcmi_ltsw_idx_tbl_l2_mc_group_user_id {
    126     /*! VLAN. */
    127     BCMI_L2_MC_GROUP_USER_ID_VLAN = 0,
    128 
    129     /*! Always at last. */
    130     BCMI_L2_MC_GROUP_USER_ID_CNT
    131 } bcmi_ltsw_idx_tbl_l2_mc_group_user_id;
    132 
    133 typedef enum bcmi_ltsw_idx_tbl_int_action_profile_user_id {
    134     /*! IFA action profile. */
    135     BCMI_INT_ACTION_PROFILE_USER_ID_IFA = 0,
    136 
    137     /*! IOAM action profile. */
    138     BCMI_INT_ACTION_PROFILE_USER_ID_IOAM = 1,
    139 
    140     /*! INT-DP action profile. */
    141     BCMI_INT_ACTION_PROFILE_USER_ID_INT_DP = 2,
    142 
    143     /*! Always at last. */
    144     BCMI_INT_ACTION_PROFILE_USER_ID_CNT
    145 } bcmi_ltsw_idx_tbl_int_match_user_id;
    146 
    147 typedef enum bcmi_ltsw_idx_tbl_int_opaque_data_profile_user_id {
    148     /*! INT. */
    149     BCMI_INT_OPAQUE_DATA_PROFILE_USER_ID_INT = 0,
    150 
    151     /*! Always at last. */
    152     BCMI_INT_OPAQUE_DATA_PROFILE_USER_ID_CNT
    153 } bcmi_ltsw_idx_tbl_int_opaque_data_profile_user_id;
    154 
    155 typedef enum bcmi_ltsw_idx_tbl_int_metadata_select_profile_user_id {
    156     /*! INT. */
    157     BCMI_INT_METADATA_SELECT_PROFILE_USER_ID_INT = 0,
    158 
    159     /*! Always at last. */
    160     BCMI_INT_METADATA_SELECT_PROFILE_USER_ID_CNT
    161 } bcmi_ltsw_idx_tbl_int_metadata_select_profile_user_id;
    162 
    163 typedef enum bcmi_ltsw_idx_tbl_int_metadata_construct_profile_user_id {
    164     /*! INT. */
    165     BCMI_INT_METADATA_CONSTRUCT_PROFILE_USER_ID_INT = 0,
    166 
    167     /*! Always at last. */
    168     BCMI_INT_METADATA_CONSTRUCT_PROFILE_USER_ID_CNT
    169 } bcmi_ltsw_idx_tbl_int_metadata_construct_profile_user_id;
    170 
    171 typedef enum bcmi_ltsw_idx_tbl_int_metadata_profile_user_id {
    172     /*! INT. */
    173     BCMI_INT_METADATA_PROFILE_USER_ID_INT = 0,
    174 
    175     /*! Always at last. */
    176     BCMI_INT_METADATA_PROFILE_USER_ID_CNT
    177 } bcmi_ltsw_idx_tbl_int_metadata_profile_user_id;
    178 
    179 /*
    180  * Information of corresponding LT tables.
    181  */
    182 typedef struct bcmi_ltsw_idx_tbl_lt_info_s {
    183     /*! Max number of user of a given table. */
    184     uint8_t user_cnt;
    185 
    186     /*! LT name. */
    187     const char *tbl_name;
    188 
    189     /*! Field of LT to get index range. */
    190     const char *idx_field;
    191 } bcmi_ltsw_idx_tbl_lt_info_t;
    192 
    193 typedef struct bcmi_ltsw_idx_tbl_entry_info_s {
    194     /*! Reference count. */
    195     uint32_t ref_cnt;
    196 
    197     /*! Entry digest. */
    198     uint16_t hash;
    199 
    200     /*! ID of user of this entry. */
    201     int user_id;
    202 } bcmi_ltsw_idx_tbl_entry_info_t;
    203 
    204 typedef struct bcmi_ltsw_idx_tbl_user_info_s {
    205     /*! User information valid. */
    206     bool valid;
    207 
    208     /*! Hash function. */
    209     entry_func_hash func_hash;
    210 
    211     /*! Comparison function. */
    212     entry_func_cmp func_cmp;
    213 
    214     /*! Insertion function. */
    215     entry_func_insert func_insert;
    216 
    217     /*! Deletion function. */
    218     entry_func_del func_del;
    219 
    220     /*! First table index. */
    221     uint32_t idx_min;
    222 
    223     /*! Last table index. */
    224     uint32_t idx_max;
    225 
    226     /*! Max used entry index. */
    227     uint32_t idx_maxused;
    228 } bcmi_ltsw_idx_tbl_user_info_t;
    229 
    230 /*!
    231  * \brief Index-based table management module initialization.
    232  *
    233  * \param [in] unit           Unit number.
    234  *
    235  * \retval SHR_E_NONE         No errors.
    236  * \retval !SHR_E_NONE        Failure.
    237  */
    238 extern int bcmi_ltsw_idx_tbl_mgmt_init(int unit);
    239 
    240 /*!
    241  * \brief Table management module deinit.
    242  *
    243  * \param [in] unit           Unit number.
    244  *
    245  * \retval SHR_E_NONE         No errors.
    246  * \retval !SHR_E_NONE        Failure.
    247  */
    248 extern int bcmi_ltsw_idx_tbl_mgmt_deinit(int unit);
    249 
    250 /*!
    251  * \brief Register a table user to manage the specific table.
    252  *
    253  * This function is used to register a table user to manage the specific table.
    254  *
    255  * \param [in] unit           Unit number.
    256  * \param [in] tbl_id         Id of the specific table.
    257  * \param [in] user_id        User Id.
    258  * \param [in] lt_info        LT information.
    259  * \param [in] user_info      User information.
    260  *
    261  * \retval SHR_E_NONE         No errors.
    262  * \retval !SHR_E_NONE        Failure.
    263  */
    264 extern int
    265 bcmi_ltsw_idx_tbl_register(int unit, bcmi_ltsw_idx_tbl_id_t tbl_id,
    266                            int user_id,
    267                            bcmi_ltsw_idx_tbl_lt_info_t *lt_info,
    268                            bcmi_ltsw_idx_tbl_user_info_t *user_info);
    269 
    270 /*!
    271  * \brief Unregister a user from the specific index table.
    272  *
    273  * This function is used to unregister a user from the specific table.
    274  *
    275  * \param [in] unit           Unit number.
    276  * \param [in] tbl_id         Id of the specific table.
    277  * \param [in] user_id        User ID, -1 means all users.
    278  *
    279  * \retval SHR_E_NONE         No errors.
    280  * \retval !SHR_E_NONE        Failure.
    281  */
    282 extern int bcmi_ltsw_idx_tbl_unregister(int unit, bcmi_ltsw_idx_tbl_id_t tbl_id,
    283                                         int user_id);
    284 
    285 /*!
    286  * \brief Allocate an entry from specific table.
    287  *
    288  * This function is used to request for a slot from specific table.
    289  *
    290  * \param [in] unit           Unit number.
    291  * \param [in] flags          Operation flags.
    292  * \param [in] tbl_id         Id of the specific table.
    293  * \param [in] user_id        User Id.
    294  * \param [in] entry          Content of entry.
    295  * \param [in/out] index      Entry index.
    296  *
    297  * \retval SHR_E_NONE         No errors.
    298  * \retval !SHR_E_NONE        Failure.
    299  */
    300 extern int
    301 bcmi_ltsw_idx_tbl_entry_alloc(int unit, uint32_t flags,
    302                               bcmi_ltsw_idx_tbl_id_t tbl_id, int user_id,
    303                               void *entry, int *index);
    304 
    305 /*!
    306  * \brief Free an entry from specific table.
    307  *
    308  * This function is used to free an entry from specific table.
    309  *
    310  * \param [in] unit           Unit number.
    311  * \param [in] flags          Operation flags.
    312  * \param [in] tbl_id         Id of the specific table.
    313  * \param [in] user_id        User Id.
    314  * \param [in] index          Entry index.
    315  *
    316  * \retval SHR_E_NONE         No errors.
    317  * \retval !SHR_E_NONE        Failure.
    318  */
    319 extern int
    320 bcmi_ltsw_idx_tbl_entry_free(int unit, uint32_t flags,
    321                              bcmi_ltsw_idx_tbl_id_t tbl_id, int user_id,
    322                              int index);
    323 
    324 /*!
    325  * \brief Find an entry from specific table.
    326  *
    327  * This function is used to find an entry from specific table. If multiple
    328  * identical entries exist, only the first entry's index will be returned.
    329  * Note: if any LT operation is potentially involved (i.e. LT read/write) within
    330  * this function, it is assumed that the LT is properly protected by associated
    331  * lock before invoking this function.
    332  *
    333  * \param [in] unit           Unit number.
    334  * \param [in] flags          Operation flags.
    335  * \param [in] tbl_id         Id of the specific table.
    336  * \param [in] user_id        User Id.
    337  * \param [in] entry          Content of entry.
    338  * \param [out] index         Index of found entry.
    339  *
    340  * \retval SHR_E_NONE         No errors.
    341  * \retval !SHR_E_NONE        Failure.
    342  */
    343 int
    344 bcmi_ltsw_idx_tbl_entry_find(int unit, uint32_t flags,
    345                              bcmi_ltsw_idx_tbl_id_t tbl_id, int user_id,
    346                              void *entry, int *index);
    347 
    348 /*!
    349  * \brief Check if an entry exists in specific index.
    350  *
    351  * This function is used to check if an entry exists in specific index. If
    352  * multiple identical entries exist, only the first entry's index will be
    353  * returned.
    354  * Note: if any LT operation is potentially involved (i.e. LT read/write) within
    355  * this function, it is assumed that the LT is properly protected by associated
    356  * lock before invoking this function.
    357  *
    358  * \param [in] unit           Unit number.
    359  * \param [in] flags          Operation flags.
    360  * \param [in] tbl_id         Id of the specific table.
    361  * \param [in] user_id        User Id.
    362  * \param [in] entry          Content of entry returned (Currently unused).
    363  * \param [out] index         Index of found entry.
    364  *
    365  * \retval SHR_E_NONE         No errors.
    366  * \retval !SHR_E_NONE        Failure.
    367  */
    368 int
    369 bcmi_ltsw_idx_tbl_entry_get_by_idx(int unit, uint32_t flags,
    370                                    bcmi_ltsw_idx_tbl_id_t tbl_id,
    371                                    int user_id,
    372                                    void *entry, int index);
    373 
    374 /*!
    375  * \brief Increase reference count for an specific entry.
    376  *
    377  * This function is used to increase reference count for an specific entry.
    378  *
    379  * \param [in] unit           Unit number.
    380  * \param [in] tbl_id         Id of the specific table.
    381  * \param [in] user_id        User Id.
    382  * \param [in] index          Entry index.
    383  *
    384  * \retval SHR_E_NONE         No errors.
    385  * \retval !SHR_E_NONE        Failure.
    386  */
    387 extern int
    388 bcmi_ltsw_idx_tbl_entry_ref_increase(int unit, bcmi_ltsw_idx_tbl_id_t tbl_id,
    389                                      int user_id,
    390                                      uint32_t index);
    391 
    392 /*!
    393  * \brief Get reference count for an specific entry.
    394  *
    395  * This function is used to get reference count for an specific entry.
    396  *
    397  * \param [in] unit           Unit number.
    398  * \param [in] tbl_id         Id of the specific table.
    399  * \param [in] user_id        User Id.
    400  * \param [in] index          Entry index.
    401  * \param [out] ref_cnt       Reference count.
    402  *
    403  * \retval SHR_E_NONE         No errors.
    404  * \retval !SHR_E_NONE        Failure.
    405  */
    406 extern int
    407 bcmi_ltsw_idx_tbl_entry_ref_get(int unit, bcmi_ltsw_idx_tbl_id_t tbl_id,
    408                                 int user_id, uint32_t index,
    409                                 uint32_t *ref_cnt);
    410 
    411 /*!
    412  * \brief Update hash data for specific entry.
    413  *
    414  * This function is used to update hash data for specific entry.
    415  *
    416  * \param [in] unit           Unit number.
    417  * \param [in] tbl_id         Id of the specific table.
    418  * \param [in] user_id        User Id.
    419  * \param [in] entry          Entry information.
    420  * \param [in] index          Entry index.
    421  *
    422  * \retval SHR_E_NONE         No errors.
    423  * \retval !SHR_E_NONE        Failure.
    424  */
    425 extern int
    426 bcmi_ltsw_idx_tbl_entry_hash_update(int unit, bcmi_ltsw_idx_tbl_id_t tbl_id,
    427                                     int user_id, void *entry,
    428                                     uint32_t index);
    429 
    430 #endif /* BCMI_LTSW_IDX_TBE_MGMT */