1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
6 #ifndef _ULP_GEN_TBL_H_
7 #define _ULP_GEN_TBL_H_
9 #include "ulp_gen_hash.h"
11 /* Macros for reference count manipulation */
12 #define ULP_GEN_TBL_REF_CNT_INC(entry) {*(entry)->ref_count += 1; }
13 #define ULP_GEN_TBL_REF_CNT_DEC(entry) {*(entry)->ref_count -= 1; }
14 #define ULP_GEN_TBL_REF_CNT(entry) (*(entry)->ref_count)
16 #define ULP_GEN_TBL_FID_OFFSET 0
17 #define ULP_GEN_TBL_FID_SIZE_BITS 32
19 /* Structure to pass the generic table values across APIs */
20 struct ulp_mapper_gen_tbl_entry {
22 uint32_t byte_data_size;
24 enum bnxt_ulp_byte_order byte_order;
28 * Structure to store the generic tbl container
29 * The ref count and byte data contain list of "num_elem" elements.
30 * The size of each entry in byte_data is of size byte_data_size.
32 struct ulp_mapper_gen_tbl_cont {
34 uint32_t byte_data_size;
35 enum bnxt_ulp_byte_order byte_order;
36 /* Reference count to track number of users*/
38 /* First 4 bytes is either tcam_idx or fid and rest are identities */
42 /* Structure to store the generic tbl container */
43 struct ulp_mapper_gen_tbl_list {
44 const char *gen_tbl_name;
45 struct ulp_mapper_gen_tbl_cont container;
46 uint32_t mem_data_size;
48 struct ulp_gen_hash_tbl *hash_tbl;
51 /* Forward declaration */
52 struct bnxt_ulp_mapper_data;
53 struct ulp_flow_db_res_params;
56 * Initialize the generic table list
58 * mapper_data [in] Pointer to the mapper data and the generic table is
61 * returns 0 on success
64 ulp_mapper_generic_tbl_list_init(struct bnxt_ulp_mapper_data *mapper_data);
67 * Free the generic table list
69 * mapper_data [in] Pointer to the mapper data and the generic table is
72 * returns 0 on success
75 ulp_mapper_generic_tbl_list_deinit(struct bnxt_ulp_mapper_data *mapper_data);
78 * Get the generic table list entry
80 * tbl_list [in] - Ptr to generic table
81 * key [in] - Key index to the table
82 * entry [out] - output will include the entry if found
84 * returns 0 on success.
87 ulp_mapper_gen_tbl_entry_get(struct ulp_mapper_gen_tbl_list *tbl_list,
89 struct ulp_mapper_gen_tbl_entry *entry);
92 * utility function to calculate the table idx
94 * res_sub_type [in] - Resource sub type
95 * dir [in] - direction
100 ulp_mapper_gen_tbl_idx_calculate(uint32_t res_sub_type, uint32_t dir);
103 * Set the data in the generic table entry
105 * entry [in] - generic table entry
106 * len [in] - The length of the data in bits to be set
107 * data [in] - pointer to the data to be used for setting the value.
108 * data_size [in] - length of the data pointer in bytes.
110 * returns 0 on success
113 ulp_mapper_gen_tbl_entry_data_set(struct ulp_mapper_gen_tbl_entry *entry,
114 uint32_t len, uint8_t *data,
118 * Get the data in the generic table entry
120 * entry [in] - generic table entry
121 * offset [in] - The offset in bits where the data has to get
122 * len [in] - The length of the data in bits to be get
123 * data [out] - pointer to the data to be used for setting the value.
124 * data_size [in] - The size of data in bytes
126 * returns 0 on success
129 ulp_mapper_gen_tbl_entry_data_get(struct ulp_mapper_gen_tbl_entry *entry,
130 uint32_t offset, uint32_t len, uint8_t *data,
134 * Free the generic table list resource
136 * ulp_ctx [in] - Pointer to the ulp context
137 * res [in] - Pointer to flow db resource entry
139 * returns 0 on success
142 ulp_mapper_gen_tbl_res_free(struct bnxt_ulp_context *ulp_ctx,
143 struct ulp_flow_db_res_params *res);
145 /* Free the generic table list entry
147 * ulp_ctx [in] - Pointer to the ulp context
148 * tbl_idx [in] - Index of the generic table
149 * ckey [in] - Key for the entry in the table
151 * returns 0 on success
154 ulp_mapper_gen_tbl_entry_free(struct bnxt_ulp_context *ulp_ctx,
155 uint32_t tbl_idx, uint32_t ckey);
158 * Write the generic table list hash entry
160 * tbl_list [in] - pointer to the generic table list
161 * hash_entry [in] - Hash table entry
162 * gen_tbl_ent [out] - generic table entry
164 * returns 0 on success.
167 ulp_mapper_gen_tbl_hash_entry_add(struct ulp_mapper_gen_tbl_list *tbl_list,
168 struct ulp_gen_hash_entry_params *hash_entry,
169 struct ulp_mapper_gen_tbl_entry *gen_tbl_ent);
171 #endif /* _ULP_EN_TBL_H_ */