1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2023 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _ULP_GEN_TBL_H_ 7 #define _ULP_GEN_TBL_H_ 8 9 #include "ulp_gen_hash.h" 10 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) 15 16 #define ULP_GEN_TBL_FID_OFFSET 0 17 #define ULP_GEN_TBL_FID_SIZE_BITS 32 18 19 enum ulp_gen_list_search_flag { 20 ULP_GEN_LIST_SEARCH_MISSED = 1, 21 ULP_GEN_LIST_SEARCH_FOUND = 2, 22 ULP_GEN_LIST_SEARCH_FOUND_SUBSET = 3, 23 ULP_GEN_LIST_SEARCH_FOUND_SUPERSET = 4, 24 ULP_GEN_LIST_SEARCH_FULL = 5 25 }; 26 27 /* Structure to pass the generic table values across APIs */ 28 struct ulp_mapper_gen_tbl_entry { 29 uint32_t *ref_count; 30 uint32_t byte_data_size; 31 uint8_t *byte_data; 32 enum bnxt_ulp_byte_order byte_order; 33 uint32_t byte_key_size; 34 uint8_t *byte_key; 35 }; 36 37 /* 38 * Structure to store the generic tbl container 39 * The ref count and byte data contain list of "num_elem" elements. 40 * The size of each entry in byte_data is of size byte_data_size. 41 */ 42 struct ulp_mapper_gen_tbl_cont { 43 uint32_t num_elem; 44 uint32_t byte_data_size; 45 enum bnxt_ulp_byte_order byte_order; 46 /* Reference count to track number of users*/ 47 uint32_t *ref_count; 48 /* First 4 bytes is either tcam_idx or fid and rest are identities */ 49 uint8_t *byte_data; 50 uint8_t *byte_key; 51 uint32_t byte_key_ex_size;/* exact match size */ 52 uint32_t byte_key_par_size; /*partial match */ 53 uint32_t seq_cnt; 54 }; 55 56 /* Structure to store the generic tbl container */ 57 struct ulp_mapper_gen_tbl_list { 58 const char *gen_tbl_name; 59 enum bnxt_ulp_gen_tbl_type tbl_type; 60 struct ulp_mapper_gen_tbl_cont container; 61 uint32_t mem_data_size; 62 uint8_t *mem_data; 63 struct ulp_gen_hash_tbl *hash_tbl; 64 }; 65 66 /* Forward declaration */ 67 struct bnxt_ulp_mapper_data; 68 struct ulp_flow_db_res_params; 69 70 /* 71 * Initialize the generic table list 72 * 73 * ulp_ctx [in] - Pointer to the ulp context 74 * mapper_data [in] Pointer to the mapper data and the generic table is 75 * part of it 76 * 77 * returns 0 on success 78 */ 79 int32_t 80 ulp_mapper_generic_tbl_list_init(struct bnxt_ulp_context *ulp_ctx, 81 struct bnxt_ulp_mapper_data *mapper_data); 82 83 /* 84 * Free the generic table list 85 * 86 * mapper_data [in] Pointer to the mapper data and the generic table is 87 * part of it 88 * 89 * returns 0 on success 90 */ 91 int32_t 92 ulp_mapper_generic_tbl_list_deinit(struct bnxt_ulp_mapper_data *mapper_data); 93 94 /* 95 * Get the generic table list entry 96 * 97 * tbl_list [in] - Ptr to generic table 98 * key [in] - Key index to the table 99 * entry [out] - output will include the entry if found 100 * 101 * returns 0 on success. 102 */ 103 int32_t 104 ulp_mapper_gen_tbl_entry_get(struct ulp_mapper_gen_tbl_list *tbl_list, 105 uint32_t key, 106 struct ulp_mapper_gen_tbl_entry *entry); 107 108 /* 109 * utility function to calculate the table idx 110 * 111 * res_sub_type [in] - Resource sub type 112 * dir [in] - direction 113 * 114 * returns None 115 */ 116 int32_t 117 ulp_mapper_gen_tbl_idx_calculate(uint32_t res_sub_type, uint32_t dir); 118 119 /* 120 * Set the data in the generic table entry, Data is in Big endian format 121 * 122 * entry [in] - generic table entry 123 * key [in] - pointer to the key to be used for setting the value. 124 * key_size [in] - The length of the key in bytess to be set 125 * data [in] - pointer to the data to be used for setting the value. 126 * data_size [in] - length of the data pointer in bytes. 127 * 128 * returns 0 on success 129 */ 130 int32_t 131 ulp_mapper_gen_tbl_entry_data_set(struct ulp_mapper_gen_tbl_list *tbl_list, 132 struct ulp_mapper_gen_tbl_entry *entry, 133 uint8_t *key, uint32_t key_size, 134 uint8_t *data, uint32_t data_size); 135 136 /* 137 * Get the data in the generic table entry 138 * 139 * entry [in] - generic table entry 140 * offset [in] - The offset in bits where the data has to get 141 * len [in] - The length of the data in bits to be get 142 * data [out] - pointer to the data to be used for setting the value. 143 * data_size [in] - The size of data in bytes 144 * 145 * returns 0 on success 146 */ 147 int32_t 148 ulp_mapper_gen_tbl_entry_data_get(struct ulp_mapper_gen_tbl_entry *entry, 149 uint32_t offset, uint32_t len, uint8_t *data, 150 uint32_t data_size); 151 152 /* 153 * Free the generic table list resource 154 * 155 * ulp_ctx [in] - Pointer to the ulp context 156 * fid [in] - The fid the generic table is associated with 157 * res [in] - Pointer to flow db resource entry 158 * 159 * returns 0 on success 160 */ 161 int32_t 162 ulp_mapper_gen_tbl_res_free(struct bnxt_ulp_context *ulp_ctx, 163 uint32_t fid, 164 struct ulp_flow_db_res_params *res); 165 166 /* Free the generic table list entry 167 * 168 * ulp_ctx [in] - Pointer to the ulp context 169 * tbl_idx [in] - Index of the generic table 170 * ckey [in] - Key for the entry in the table 171 * 172 * returns 0 on success 173 */ 174 int32_t 175 ulp_mapper_gen_tbl_entry_free(struct bnxt_ulp_context *ulp_ctx, 176 uint32_t tbl_idx, uint32_t ckey); 177 178 /* 179 * Write the generic table list hash entry 180 * 181 * tbl_list [in] - pointer to the generic table list 182 * hash_entry [in] - Hash table entry 183 * gen_tbl_ent [out] - generic table entry 184 * 185 * returns 0 on success. 186 */ 187 int32_t 188 ulp_mapper_gen_tbl_hash_entry_add(struct ulp_mapper_gen_tbl_list *tbl_list, 189 struct ulp_gen_hash_entry_params *hash_entry, 190 struct ulp_mapper_gen_tbl_entry *gen_tbl_ent); 191 192 /* 193 * Perform add entry in the simple list 194 * 195 * tbl_list [in] - pointer to the generic table list 196 * key [in] - Key added as index 197 * data [in] - data added as result 198 * key_index [out] - index to the entry 199 * gen_tbl_ent [out] - write the output to the entry 200 * 201 * returns 0 on success. 202 */ 203 int32_t 204 ulp_gen_tbl_simple_list_add_entry(struct ulp_mapper_gen_tbl_list *tbl_list, 205 uint8_t *key, 206 uint8_t *data, 207 uint32_t *key_index, 208 struct ulp_mapper_gen_tbl_entry *ent); 209 /* 210 * Perform simple list search 211 * 212 * tbl_list [in] - pointer to the generic table list 213 * match_key [in] - Key data that needs to be matched 214 * key_idx [out] - returns key index . 215 * 216 * returns 0 on success. 217 */ 218 uint32_t 219 ulp_gen_tbl_simple_list_search(struct ulp_mapper_gen_tbl_list *tbl_list, 220 uint8_t *match_key, 221 uint32_t *key_idx); 222 #endif /* _ULP_EN_TBL_H_ */ 223