1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2014-2023 Broadcom 3 * All rights reserved. 4 */ 5 6 #ifndef _ULP_MAPPER_H_ 7 #define _ULP_MAPPER_H_ 8 9 /* TBD: it is added Thor2 testing */ 10 /* #define ULP_MAPPER_TFC_TEST 1 */ 11 12 #include <rte_log.h> 13 #include <rte_flow.h> 14 #include <rte_flow_driver.h> 15 #include "tf_core.h" 16 #include "ulp_template_db_enum.h" 17 #include "ulp_template_struct.h" 18 #include "bnxt_ulp.h" 19 #include "ulp_utils.h" 20 #include "ulp_gen_tbl.h" 21 #include "tfc_em.h" 22 #include "bitalloc.h" 23 #include "ulp_alloc_tbl.h" 24 25 #define ULP_IDENTS_INVALID ((uint16_t)0xffff) 26 27 struct bnxt_ulp_mapper_glb_resource_entry { 28 enum bnxt_ulp_resource_func resource_func; 29 uint32_t resource_type; /* TF_ enum type */ 30 uint64_t resource_hndl; 31 bool shared; 32 }; 33 34 #define BNXT_ULP_KEY_RECIPE_MAX_FLDS 128 35 struct bnxt_ulp_key_recipe_entry { 36 uint32_t cnt; 37 struct bnxt_ulp_mapper_key_info flds[BNXT_ULP_KEY_RECIPE_MAX_FLDS]; 38 }; 39 40 #define ULP_RECIPE_TYPE_MAX (BNXT_ULP_RESOURCE_SUB_TYPE_KEY_RECIPE_TABLE_WM + 1) 41 struct bnxt_ulp_key_recipe_info { 42 uint32_t num_recipes; 43 uint8_t max_fields; 44 struct bnxt_ulp_key_recipe_entry **recipes[BNXT_ULP_DIRECTION_LAST][ULP_RECIPE_TYPE_MAX]; 45 struct bitalloc *recipe_ba[BNXT_ULP_DIRECTION_LAST][ULP_RECIPE_TYPE_MAX]; 46 }; 47 48 struct ulp_mapper_core_ops; 49 50 struct bnxt_ulp_mapper_data { 51 const struct ulp_mapper_core_ops *mapper_oper; 52 struct bnxt_ulp_mapper_glb_resource_entry 53 glb_res_tbl[TF_DIR_MAX][BNXT_ULP_GLB_RF_IDX_LAST]; 54 struct ulp_mapper_gen_tbl_list gen_tbl_list[BNXT_ULP_GEN_TBL_MAX_SZ]; 55 struct bnxt_ulp_key_recipe_info key_recipe_info; 56 struct ulp_allocator_tbl_entry alloc_tbl[BNXT_ULP_ALLOCATOR_TBL_MAX_SZ]; 57 }; 58 59 /* Internal Structure for passing the arguments around */ 60 struct bnxt_ulp_mapper_parms { 61 enum bnxt_ulp_template_type tmpl_type; 62 uint32_t dev_id; 63 uint32_t act_tid; 64 uint32_t class_tid; 65 struct ulp_rte_act_prop *act_prop; 66 struct ulp_rte_act_bitmap *act_bitmap; 67 struct ulp_rte_hdr_bitmap *hdr_bitmap; 68 struct ulp_rte_hdr_bitmap *enc_hdr_bitmap; 69 struct ulp_rte_hdr_field *hdr_field; 70 struct ulp_rte_hdr_field *enc_field; 71 struct ulp_rte_field_bitmap *fld_bitmap; 72 uint64_t *comp_fld; 73 struct ulp_regfile *regfile; 74 struct bnxt_ulp_context *ulp_ctx; 75 uint32_t flow_id; 76 uint16_t func_id; 77 uint32_t rid; 78 enum bnxt_ulp_fdb_type flow_type; 79 struct bnxt_ulp_mapper_data *mapper_data; 80 struct bnxt_ulp_device_params *device_params; 81 uint32_t child_flow; 82 uint32_t parent_flow; 83 uint8_t tun_idx; 84 uint32_t app_priority; 85 uint64_t shared_hndl; 86 uint32_t flow_pattern_id; 87 uint32_t act_pattern_id; 88 uint8_t app_id; 89 uint16_t port_id; 90 uint16_t fw_fid; 91 uint64_t cf_bitmap; 92 uint64_t wc_field_bitmap; 93 uint64_t exclude_field_bitmap; 94 struct tfc_mpc_batch_info_t batch_info; 95 }; 96 97 /* Function to initialize any dynamic mapper data. */ 98 struct ulp_mapper_core_ops { 99 int32_t 100 (*ulp_mapper_core_tcam_tbl_process)(struct bnxt_ulp_mapper_parms *parms, 101 struct bnxt_ulp_mapper_tbl_info *t); 102 int32_t 103 (*ulp_mapper_core_tcam_entry_free)(struct bnxt_ulp_context *ulp_ctx, 104 struct ulp_flow_db_res_params *res); 105 int32_t 106 (*ulp_mapper_core_em_tbl_process)(struct bnxt_ulp_mapper_parms *parms, 107 struct bnxt_ulp_mapper_tbl_info *t, 108 void *error); 109 int32_t 110 (*ulp_mapper_core_em_entry_free)(struct bnxt_ulp_context *ulp, 111 struct ulp_flow_db_res_params *res, 112 void *error); 113 114 int32_t 115 (*ulp_mapper_core_index_tbl_process)(struct bnxt_ulp_mapper_parms *parm, 116 struct bnxt_ulp_mapper_tbl_info 117 *t); 118 int32_t 119 (*ulp_mapper_core_index_entry_free)(struct bnxt_ulp_context *ulp, 120 struct ulp_flow_db_res_params *res); 121 int32_t 122 (*ulp_mapper_core_cmm_tbl_process)(struct bnxt_ulp_mapper_parms *parm, 123 struct bnxt_ulp_mapper_tbl_info *t, 124 void *error); 125 int32_t 126 (*ulp_mapper_core_cmm_entry_free)(struct bnxt_ulp_context *ulp, 127 struct ulp_flow_db_res_params *res, 128 void *error); 129 int32_t 130 (*ulp_mapper_core_if_tbl_process)(struct bnxt_ulp_mapper_parms *parms, 131 struct bnxt_ulp_mapper_tbl_info *t); 132 133 int32_t 134 (*ulp_mapper_core_ident_alloc_process)(struct bnxt_ulp_context *ulp_ctx, 135 uint32_t session_type, 136 uint16_t ident_type, 137 uint8_t direction, 138 enum cfa_track_type tt, 139 uint64_t *identifier_id); 140 141 int32_t 142 (*ulp_mapper_core_index_tbl_alloc_process)(struct bnxt_ulp_context *ulp, 143 uint32_t session_type, 144 uint16_t table_type, 145 uint8_t direction, 146 uint64_t *index); 147 int32_t 148 (*ulp_mapper_core_ident_free)(struct bnxt_ulp_context *ulp_ctx, 149 struct ulp_flow_db_res_params *res); 150 uint32_t 151 (*ulp_mapper_core_dyn_tbl_type_get)(struct bnxt_ulp_mapper_parms *parms, 152 struct bnxt_ulp_mapper_tbl_info *t, 153 uint16_t blob_len, 154 uint16_t *out_len); 155 int32_t 156 (*ulp_mapper_core_app_glb_res_info_init)(struct bnxt_ulp_context *ulp_ctx, 157 struct bnxt_ulp_mapper_data *mapper_data); 158 159 int32_t 160 (*ulp_mapper_core_handle_to_offset)(struct bnxt_ulp_mapper_parms *parms, 161 uint64_t handle, 162 uint32_t offset, 163 uint64_t *result); 164 int 165 (*ulp_mapper_mpc_batch_start)(struct tfc_mpc_batch_info_t *batch_info); 166 167 bool 168 (*ulp_mapper_mpc_batch_started)(struct tfc_mpc_batch_info_t *batch_info); 169 170 int 171 (*ulp_mapper_mpc_batch_end)(struct tfc *tfcp, 172 struct tfc_mpc_batch_info_t *batch_info); 173 }; 174 175 extern const struct ulp_mapper_core_ops ulp_mapper_tf_core_ops; 176 extern const struct ulp_mapper_core_ops ulp_mapper_tfc_core_ops; 177 178 int32_t 179 ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data, 180 enum tf_dir dir, 181 uint16_t idx, 182 uint64_t *regval, 183 bool *shared); 184 185 int32_t 186 ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data, 187 struct bnxt_ulp_glb_resource_info *res, 188 uint64_t regval, bool shared); 189 190 int32_t 191 ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx, 192 struct bnxt_ulp_mapper_data *mapper_data, 193 struct bnxt_ulp_glb_resource_info *glb_res, 194 bool shared); 195 196 int32_t 197 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx, 198 struct bnxt_ulp_mapper_data *mapper_data, 199 struct bnxt_ulp_glb_resource_info *glb_res, 200 bool shared); 201 202 struct bnxt_ulp_mapper_key_info * 203 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms, 204 struct bnxt_ulp_mapper_tbl_info *tbl, 205 uint32_t *num_flds); 206 207 uint32_t 208 ulp_mapper_partial_key_fields_get(struct bnxt_ulp_mapper_parms *mparms, 209 struct bnxt_ulp_mapper_tbl_info *tbl); 210 211 int32_t 212 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms, 213 struct bnxt_ulp_mapper_tbl_info *tbl, 214 struct ulp_flow_db_res_params *fid_parms); 215 216 int32_t 217 ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms, 218 struct bnxt_ulp_mapper_tbl_info *tbl, 219 uint32_t *priority); 220 221 int32_t 222 ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms, 223 struct bnxt_ulp_mapper_tbl_info *tbl, 224 uint8_t *byte_data, 225 uint32_t byte_data_size, 226 enum bnxt_ulp_byte_order byte_order); 227 228 int32_t 229 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms, 230 enum tf_dir dir, 231 struct bnxt_ulp_mapper_field_info *fld, 232 struct ulp_blob *blob, 233 uint8_t is_key, 234 const char *name); 235 236 int32_t 237 ulp_mapper_key_recipe_field_opc_process(struct bnxt_ulp_mapper_parms *parms, 238 uint8_t dir, 239 struct bnxt_ulp_mapper_field_info *fld, 240 uint8_t is_key, 241 const char *name, 242 bool *written, 243 struct bnxt_ulp_mapper_field_info *ofld); 244 245 int32_t 246 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms, 247 struct bnxt_ulp_mapper_tbl_info *tbl, 248 struct ulp_blob *data, 249 const char *name); 250 251 int32_t 252 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms, 253 struct bnxt_ulp_mapper_tbl_info *tbl, 254 uint64_t flow_id); 255 256 int32_t 257 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms, 258 struct bnxt_ulp_mapper_tbl_info *tbl); 259 260 int32_t 261 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms, 262 struct bnxt_ulp_mapper_tbl_info *tbl); 263 264 int32_t 265 ulp_mapper_tcam_tbl_ident_alloc(struct bnxt_ulp_mapper_parms *parms, 266 struct bnxt_ulp_mapper_tbl_info *tbl); 267 268 uint32_t 269 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms, 270 struct ulp_blob *key, 271 struct ulp_blob *mask, 272 struct ulp_blob *tkey, 273 struct ulp_blob *tmask); 274 275 void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob); 276 277 int32_t 278 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx, 279 enum bnxt_ulp_fdb_type flow_type, 280 uint32_t fid, 281 void *error); 282 283 int32_t 284 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, 285 enum bnxt_ulp_fdb_type flow_type, 286 uint32_t fid, 287 void *error); 288 289 int32_t 290 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx, 291 struct bnxt_ulp_mapper_parms *parms, 292 void *error); 293 294 struct bnxt_ulp_mapper_key_info * 295 ulp_mapper_key_recipe_fields_get(struct bnxt_ulp_mapper_parms *parms, 296 struct bnxt_ulp_mapper_tbl_info *tbl, 297 uint32_t *num_flds); 298 299 int32_t 300 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx); 301 302 void 303 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx); 304 305 #ifdef TF_FLOW_SCALE_QUERY 306 int32_t 307 ulp_resc_usage_sync(struct bnxt_ulp_context *ulp_ctx); 308 #endif /* TF_FLOW_SCALE_QUERY */ 309 310 #endif /* _ULP_MAPPER_H_ */ 311