1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2021 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 /* Structure to pass the generic table values across APIs */ 20 struct ulp_mapper_gen_tbl_entry { 21 uint32_t *ref_count; 22 uint32_t byte_data_size; 23 uint8_t *byte_data; 24 enum bnxt_ulp_byte_order byte_order; 25 }; 26 27 /* 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. 31 */ 32 struct ulp_mapper_gen_tbl_cont { 33 uint32_t num_elem; 34 uint32_t byte_data_size; 35 enum bnxt_ulp_byte_order byte_order; 36 /* Reference count to track number of users*/ 37 uint32_t *ref_count; 38 /* First 4 bytes is either tcam_idx or fid and rest are identities */ 39 uint8_t *byte_data; 40 }; 41 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; 47 uint8_t *mem_data; 48 struct ulp_gen_hash_tbl *hash_tbl; 49 }; 50 51 /* Forward declaration */ 52 struct bnxt_ulp_mapper_data; 53 struct ulp_flow_db_res_params; 54 55 /* 56 * Initialize the generic table list 57 * 58 * mapper_data [in] Pointer to the mapper data and the generic table is 59 * part of it 60 * 61 * returns 0 on success 62 */ 63 int32_t 64 ulp_mapper_generic_tbl_list_init(struct bnxt_ulp_mapper_data *mapper_data); 65 66 /* 67 * Free the generic table list 68 * 69 * mapper_data [in] Pointer to the mapper data and the generic table is 70 * part of it 71 * 72 * returns 0 on success 73 */ 74 int32_t 75 ulp_mapper_generic_tbl_list_deinit(struct bnxt_ulp_mapper_data *mapper_data); 76 77 /* 78 * Get the generic table list entry 79 * 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 83 * 84 * returns 0 on success. 85 */ 86 int32_t 87 ulp_mapper_gen_tbl_entry_get(struct ulp_mapper_gen_tbl_list *tbl_list, 88 uint32_t key, 89 struct ulp_mapper_gen_tbl_entry *entry); 90 91 /* 92 * utility function to calculate the table idx 93 * 94 * res_sub_type [in] - Resource sub type 95 * dir [in] - direction 96 * 97 * returns None 98 */ 99 int32_t 100 ulp_mapper_gen_tbl_idx_calculate(uint32_t res_sub_type, uint32_t dir); 101 102 /* 103 * Set the data in the generic table entry 104 * 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. 109 * 110 * returns 0 on success 111 */ 112 int32_t 113 ulp_mapper_gen_tbl_entry_data_set(struct ulp_mapper_gen_tbl_entry *entry, 114 uint32_t len, uint8_t *data, 115 uint32_t data_size); 116 117 /* 118 * Get the data in the generic table entry 119 * 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 125 * 126 * returns 0 on success 127 */ 128 int32_t 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, 131 uint32_t data_size); 132 133 /* 134 * Free the generic table list resource 135 * 136 * ulp_ctx [in] - Pointer to the ulp context 137 * res [in] - Pointer to flow db resource entry 138 * 139 * returns 0 on success 140 */ 141 int32_t 142 ulp_mapper_gen_tbl_res_free(struct bnxt_ulp_context *ulp_ctx, 143 struct ulp_flow_db_res_params *res); 144 145 /* Free the generic table list entry 146 * 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 150 * 151 * returns 0 on success 152 */ 153 int32_t 154 ulp_mapper_gen_tbl_entry_free(struct bnxt_ulp_context *ulp_ctx, 155 uint32_t tbl_idx, uint32_t ckey); 156 157 /* 158 * Write the generic table list hash entry 159 * 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 163 * 164 * returns 0 on success. 165 */ 166 int32_t 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); 170 171 #endif /* _ULP_EN_TBL_H_ */ 172