1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
7 #include <rte_malloc.h>
9 #include "ulp_template_db_enum.h"
10 #include "ulp_template_struct.h"
11 #include "bnxt_tf_common.h"
12 #include "ulp_utils.h"
15 #include "tf_ext_flow_handle.h"
16 #include "ulp_mark_mgr.h"
17 #include "ulp_mapper.h"
18 #include "ulp_flow_db.h"
20 #include "ulp_template_db_tbl.h"
21 #include "ulp_port_db.h"
22 #include "ulp_ha_mgr.h"
23 #include "bnxt_tf_pmd_shim.h"
25 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
26 #include "ulp_template_debug_proto.h"
27 #include "ulp_tf_debug.h"
30 static uint8_t mapper_fld_zeros[16] = { 0 };
32 static uint8_t mapper_fld_ones[16] = {
33 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
34 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
37 static uint8_t mapper_fld_one[16] = {
38 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
39 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
43 ulp_mapper_tmpl_name_str(enum bnxt_ulp_template_type tmpl_type)
46 case BNXT_ULP_TEMPLATE_TYPE_CLASS:
48 case BNXT_ULP_TEMPLATE_TYPE_ACTION:
51 return "invalid template type";
55 static struct bnxt_ulp_glb_resource_info *
56 ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
60 *num_entries = BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
61 return ulp_glb_resource_tbl;
65 * Read the global resource from the mapper global resource list
67 * The regval is always returned in big-endian.
69 * returns 0 on success
72 ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
78 if (!mapper_data || !regval || !shared ||
79 dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_RF_IDX_LAST)
82 *regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
83 *shared = mapper_data->glb_res_tbl[dir][idx].shared;
88 * Write a global resource to the mapper global resource list
90 * The regval value must be in big-endian.
92 * return 0 on success.
95 ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
96 struct bnxt_ulp_glb_resource_info *res,
97 uint64_t regval, bool shared)
99 struct bnxt_ulp_mapper_glb_resource_entry *ent;
101 /* validate the arguments */
102 if (!data || res->direction >= TF_DIR_MAX ||
103 res->glb_regfile_index >= BNXT_ULP_GLB_RF_IDX_LAST)
106 /* write to the mapper data */
107 ent = &data->glb_res_tbl[res->direction][res->glb_regfile_index];
108 ent->resource_func = res->resource_func;
109 ent->resource_type = res->resource_type;
110 ent->resource_hndl = regval;
111 ent->shared = shared;
116 * Internal function to allocate identity resource and store it in mapper data.
118 * returns 0 on success
121 ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
122 struct bnxt_ulp_mapper_data *mapper_data,
123 struct bnxt_ulp_glb_resource_info *glb_res)
125 struct tf_alloc_identifier_parms iparms = { 0 };
126 struct tf_free_identifier_parms fparms;
131 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
135 iparms.ident_type = glb_res->resource_type;
136 iparms.dir = glb_res->direction;
138 /* Allocate the Identifier using tf api */
139 rc = tf_alloc_identifier(tfp, &iparms);
141 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
142 tf_dir_2_str(iparms.dir),
147 /* entries are stored as big-endian format */
148 regval = tfp_cpu_to_be_64((uint64_t)iparms.id);
150 * write to the mapper global resource
151 * Shared resources are never allocated through this method, so the
152 * shared flag is always false.
154 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
156 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
157 /* Free the identifier when update failed */
158 fparms.dir = iparms.dir;
159 fparms.ident_type = iparms.ident_type;
160 fparms.id = iparms.id;
161 tf_free_identifier(tfp, &fparms);
164 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
165 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
166 BNXT_TF_DBG(DEBUG, "Allocated Glb Res Ident [%s][%d][%d] = 0x%04x\n",
167 tf_dir_2_str(iparms.dir),
168 glb_res->glb_regfile_index, iparms.ident_type, iparms.id);
175 * Internal function to allocate index tbl resource and store it in mapper data.
177 * returns 0 on success
180 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
181 struct bnxt_ulp_mapper_data *mapper_data,
182 struct bnxt_ulp_glb_resource_info *glb_res)
184 struct tf_alloc_tbl_entry_parms aparms = { 0 };
185 struct tf_free_tbl_entry_parms free_parms = { 0 };
188 uint32_t tbl_scope_id;
191 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
195 /* Get the scope id */
196 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &tbl_scope_id);
198 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
202 aparms.type = glb_res->resource_type;
203 aparms.dir = glb_res->direction;
204 aparms.tbl_scope_id = tbl_scope_id;
206 /* Allocate the index tbl using tf api */
207 rc = tf_alloc_tbl_entry(tfp, &aparms);
209 BNXT_TF_DBG(ERR, "Failed to alloc index table [%s][%d]\n",
210 tf_dir_2_str(aparms.dir), aparms.type);
214 /* entries are stored as big-endian format */
215 regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
217 * write to the mapper global resource
218 * Shared resources are never allocated through this method, so the
219 * shared flag is always false.
221 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
223 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
224 /* Free the identifier when update failed */
225 free_parms.dir = aparms.dir;
226 free_parms.type = aparms.type;
227 free_parms.idx = aparms.idx;
228 tf_free_tbl_entry(tfp, &free_parms);
231 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
232 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
233 BNXT_TF_DBG(DEBUG, "Allocated Glb Res Index [%s][%d][%d] = 0x%04x\n",
234 tf_dir_2_str(aparms.dir),
235 glb_res->glb_regfile_index, aparms.type, aparms.idx);
242 ulp_mapper_glb_field_tbl_get(struct bnxt_ulp_mapper_parms *parms,
248 t_idx = parms->app_id << (BNXT_ULP_APP_ID_SHIFT +
249 BNXT_ULP_HDR_SIG_ID_SHIFT +
250 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
251 t_idx += parms->class_tid << (BNXT_ULP_HDR_SIG_ID_SHIFT +
252 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
253 t_idx += ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_HDR_SIG_ID) <<
254 BNXT_ULP_GLB_FIELD_TBL_SHIFT;
257 if (t_idx >= BNXT_ULP_GLB_FIELD_TBL_SIZE) {
258 BNXT_TF_DBG(ERR, "Invalid hdr field index %x:%x:%x\n",
259 parms->class_tid, t_idx, operand);
261 return -EINVAL; /* error */
263 *val = ulp_glb_field_tbl[t_idx];
268 * Get the size of the action property for a given index.
270 * idx [in] The index for the action property
272 * returns the size of the action property.
275 ulp_mapper_act_prop_size_get(uint32_t idx)
277 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
279 return ulp_act_prop_map_table[idx];
282 static struct bnxt_ulp_mapper_cond_info *
283 ulp_mapper_tmpl_reject_list_get(struct bnxt_ulp_mapper_parms *mparms,
286 enum bnxt_ulp_cond_list_opc *opc)
289 const struct bnxt_ulp_template_device_tbls *dev_tbls;
291 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
292 *num_tbls = dev_tbls->tmpl_list[tid].reject_info.cond_nums;
293 *opc = dev_tbls->tmpl_list[tid].reject_info.cond_list_opcode;
294 idx = dev_tbls->tmpl_list[tid].reject_info.cond_start_idx;
296 return &dev_tbls->cond_list[idx];
299 static struct bnxt_ulp_mapper_cond_info *
300 ulp_mapper_tbl_execute_list_get(struct bnxt_ulp_mapper_parms *mparms,
301 struct bnxt_ulp_mapper_tbl_info *tbl,
303 enum bnxt_ulp_cond_list_opc *opc)
306 const struct bnxt_ulp_template_device_tbls *dev_tbls;
308 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
309 *num_tbls = tbl->execute_info.cond_nums;
310 *opc = tbl->execute_info.cond_list_opcode;
311 idx = tbl->execute_info.cond_start_idx;
313 return &dev_tbls->cond_list[idx];
317 * Get a list of classifier tables that implement the flow
318 * Gets a device dependent list of tables that implement the class template id
320 * mparms [in] The mappers parms with data related to the flow.
322 * tid [in] The template id that matches the flow
324 * num_tbls [out] The number of classifier tables in the returned array
326 * returns An array of classifier tables to implement the flow, or NULL on
329 static struct bnxt_ulp_mapper_tbl_info *
330 ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
335 const struct bnxt_ulp_template_device_tbls *dev_tbls;
337 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
339 idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
340 *num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
342 return &dev_tbls->tbl_list[idx];
346 * Get the list of key fields that implement the flow.
348 * mparms [in] The mapper parms with information about the flow
350 * tbl [in] A single table instance to get the key fields from
352 * num_flds [out] The number of key fields in the returned array
354 * Returns array of Key fields, or NULL on error.
356 static struct bnxt_ulp_mapper_key_info *
357 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
358 struct bnxt_ulp_mapper_tbl_info *tbl,
362 const struct bnxt_ulp_template_device_tbls *dev_tbls;
364 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
365 if (!dev_tbls->key_info_list) {
370 idx = tbl->key_start_idx;
371 *num_flds = tbl->key_num_fields;
373 return &dev_tbls->key_info_list[idx];
377 * Get the list of data fields that implement the flow.
379 * mparms [in] The mapper parms with information about the flow
381 * tbl [in] A single table instance to get the data fields from
383 * num_flds [out] The number of data fields in the returned array.
385 * num_encap_flds [out] The number of encap fields in the returned array.
387 * Returns array of data fields, or NULL on error.
389 static struct bnxt_ulp_mapper_field_info *
390 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
391 struct bnxt_ulp_mapper_tbl_info *tbl,
393 uint32_t *num_encap_flds)
396 const struct bnxt_ulp_template_device_tbls *dev_tbls;
398 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
399 if (!dev_tbls->result_field_list) {
405 idx = tbl->result_start_idx;
406 *num_flds = tbl->result_num_fields;
407 *num_encap_flds = tbl->encap_num_fields;
409 return &dev_tbls->result_field_list[idx];
413 * Get the list of ident fields that implement the flow
415 * tbl [in] A single table instance to get the ident fields from
417 * num_flds [out] The number of ident fields in the returned array
419 * returns array of ident fields, or NULL on error
421 static struct bnxt_ulp_mapper_ident_info *
422 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
423 struct bnxt_ulp_mapper_tbl_info *tbl,
427 const struct bnxt_ulp_template_device_tbls *dev_tbls;
429 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
430 if (!dev_tbls->ident_list) {
435 idx = tbl->ident_start_idx;
436 *num_flds = tbl->ident_nums;
438 return &dev_tbls->ident_list[idx];
441 static enum tf_tbl_type
442 ulp_mapper_dyn_tbl_type_get(struct bnxt_ulp_mapper_parms *mparms,
443 struct bnxt_ulp_mapper_tbl_info *tbl,
444 struct ulp_blob *bdata,
447 struct bnxt_ulp_device_params *d_params = mparms->device_params;
448 uint16_t blob_len = ulp_blob_data_len_get(bdata);
449 struct bnxt_ulp_dyn_size_map *size_map;
452 if (d_params->dynamic_sram_en) {
453 switch (tbl->resource_type) {
454 case TF_TBL_TYPE_ACT_ENCAP_8B:
455 case TF_TBL_TYPE_ACT_ENCAP_16B:
456 case TF_TBL_TYPE_ACT_ENCAP_32B:
457 case TF_TBL_TYPE_ACT_ENCAP_64B:
458 size_map = d_params->dyn_encap_sizes;
459 for (i = 0; i < d_params->dyn_encap_list_size; i++) {
460 if (blob_len <= size_map[i].slab_size) {
461 *out_len = size_map[i].slab_size;
462 return size_map[i].tbl_type;
466 case TF_TBL_TYPE_ACT_MODIFY_8B:
467 case TF_TBL_TYPE_ACT_MODIFY_16B:
468 case TF_TBL_TYPE_ACT_MODIFY_32B:
469 case TF_TBL_TYPE_ACT_MODIFY_64B:
470 size_map = d_params->dyn_modify_sizes;
471 for (i = 0; i < d_params->dyn_modify_list_size; i++) {
472 if (blob_len <= size_map[i].slab_size) {
473 *out_len = size_map[i].slab_size;
474 return size_map[i].tbl_type;
482 return tbl->resource_type;
486 ulp_mapper_dyn_blob_size_get(struct bnxt_ulp_mapper_parms *mparms,
487 struct bnxt_ulp_mapper_tbl_info *tbl)
489 struct bnxt_ulp_device_params *d_params = mparms->device_params;
491 if (d_params->dynamic_sram_en) {
492 switch (tbl->resource_type) {
493 case TF_TBL_TYPE_ACT_ENCAP_8B:
494 case TF_TBL_TYPE_ACT_ENCAP_16B:
495 case TF_TBL_TYPE_ACT_ENCAP_32B:
496 case TF_TBL_TYPE_ACT_ENCAP_64B:
497 case TF_TBL_TYPE_ACT_MODIFY_8B:
498 case TF_TBL_TYPE_ACT_MODIFY_16B:
499 case TF_TBL_TYPE_ACT_MODIFY_32B:
500 case TF_TBL_TYPE_ACT_MODIFY_64B:
501 /* return max size */
502 return BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
506 } else if (tbl->encap_num_fields) {
507 return BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
509 return tbl->result_bit_size;
512 static inline int32_t
513 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp,
515 struct ulp_flow_db_res_params *res)
517 struct tf_free_tcam_entry_parms fparms = {
518 .dir = res->direction,
519 .tcam_tbl_type = res->resource_type,
520 .idx = (uint16_t)res->resource_hndl
523 /* If HA is enabled, we may have to remap the TF Type */
524 if (bnxt_ulp_cntxt_ha_enabled(ulp)) {
525 enum ulp_ha_mgr_region region;
528 switch (res->resource_type) {
529 case TF_TCAM_TBL_TYPE_WC_TCAM_HIGH:
530 case TF_TCAM_TBL_TYPE_WC_TCAM_LOW:
531 rc = ulp_ha_mgr_region_get(ulp, ®ion);
533 /* Log this, but assume region is correct */
535 "Unable to get HA region (%d)\n",
538 fparms.tcam_tbl_type =
539 (region == ULP_HA_REGION_LOW) ?
540 TF_TCAM_TBL_TYPE_WC_TCAM_LOW :
541 TF_TCAM_TBL_TYPE_WC_TCAM_HIGH;
547 return tf_free_tcam_entry(tfp, &fparms);
550 static inline int32_t
551 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
553 struct ulp_flow_db_res_params *res)
555 struct tf_free_tbl_entry_parms fparms = {
556 .dir = res->direction,
557 .type = res->resource_type,
558 .idx = (uint32_t)res->resource_hndl
562 * Just get the table scope, it will be ignored if not necessary
563 * by the tf_free_tbl_entry
565 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
567 return tf_free_tbl_entry(tfp, &fparms);
570 static inline int32_t
571 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
573 struct ulp_flow_db_res_params *res)
575 struct tf_delete_em_entry_parms fparms = { 0 };
578 fparms.dir = res->direction;
579 fparms.flow_handle = res->resource_hndl;
581 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
583 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
587 return tf_delete_em_entry(tfp, &fparms);
590 static inline int32_t
591 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
593 struct ulp_flow_db_res_params *res)
595 struct tf_free_identifier_parms fparms = {
596 .dir = res->direction,
597 .ident_type = res->resource_type,
598 .id = (uint16_t)res->resource_hndl
601 return tf_free_identifier(tfp, &fparms);
604 static inline int32_t
605 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
606 struct ulp_flow_db_res_params *res)
608 return ulp_mark_db_mark_del(ulp,
613 static inline int32_t
614 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
616 struct ulp_flow_db_res_params *res)
620 pc_idx = (uint32_t)res->resource_hndl;
622 /* reset the child flow bitset*/
623 if (ulp_flow_db_pc_db_parent_flow_set(ulp, pc_idx, parent_fid, 0)) {
624 BNXT_TF_DBG(ERR, "error in reset parent flow bitset %x:%x\n",
631 static inline int32_t
632 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
634 struct ulp_flow_db_res_params *res)
638 pc_idx = (uint32_t)res->resource_hndl;
640 /* reset the child flow bitset*/
641 if (ulp_flow_db_pc_db_child_flow_set(ulp, pc_idx, child_fid, 0)) {
642 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
650 * Process the flow database opcode alloc action.
651 * returns 0 on success
654 ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
655 struct bnxt_ulp_mapper_tbl_info *tbl)
661 /* allocate a new fid */
662 rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
663 BNXT_ULP_FDB_TYPE_RID,
667 "Unable to allocate flow table entry\n");
670 /* Store the allocated fid in regfile*/
672 rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
673 tfp_cpu_to_be_64(val64));
675 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
677 ulp_flow_db_fid_free(parms->ulp_ctx,
678 BNXT_ULP_FDB_TYPE_RID, rid);
685 * Process the flow database opcode action.
686 * returns 0 on success.
689 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
690 struct bnxt_ulp_mapper_tbl_info *tbl,
691 struct ulp_flow_db_res_params *fid_parms)
695 enum bnxt_ulp_fdb_type flow_type;
698 switch (tbl->fdb_opcode) {
699 case BNXT_ULP_FDB_OPC_PUSH_FID:
700 push_fid = parms->fid;
701 flow_type = parms->flow_type;
703 case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
704 /* get the fid from the regfile */
705 rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
708 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
712 /* Use the extracted fid to update the flow resource */
713 push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
714 flow_type = BNXT_ULP_FDB_TYPE_RID;
717 return rc; /* Nothing to be done */
720 /* Add the resource to the flow database */
721 rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
722 push_fid, fid_parms);
724 BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
730 * Process the flow database opcode action.
731 * returns 0 on success.
734 ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms,
735 struct bnxt_ulp_mapper_tbl_info *tbl,
740 switch (tbl->pri_opcode) {
741 case BNXT_ULP_PRI_OPC_NOT_USED:
744 case BNXT_ULP_PRI_OPC_CONST:
745 *priority = tbl->pri_operand;
747 case BNXT_ULP_PRI_OPC_APP_PRI:
748 *priority = parms->app_priority;
751 BNXT_TF_DBG(ERR, "Priority opcode not supported %d\n",
760 * Process the identifier list in the given table.
761 * Extract the ident from the table entry and
762 * write it to the reg file.
763 * returns 0 on success.
766 ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
767 struct bnxt_ulp_mapper_tbl_info *tbl,
769 uint32_t byte_data_size,
770 enum bnxt_ulp_byte_order byte_order)
772 struct bnxt_ulp_mapper_ident_info *idents;
773 uint32_t i, num_idents = 0;
776 /* validate the null arguments */
778 BNXT_TF_DBG(ERR, "invalid argument\n");
782 /* Get the ident list and process each one */
783 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
785 for (i = 0; i < num_idents; i++) {
786 /* check the size of the buffer for validation */
787 if ((idents[i].ident_bit_pos + idents[i].ident_bit_size) >
788 ULP_BYTE_2_BITS(byte_data_size) ||
789 idents[i].ident_bit_size > ULP_BYTE_2_BITS(sizeof(val64))) {
790 BNXT_TF_DBG(ERR, "invalid offset or length %x:%x:%x\n",
791 idents[i].ident_bit_pos,
792 idents[i].ident_bit_size,
797 if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
798 ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
800 idents[i].ident_bit_pos,
801 idents[i].ident_bit_size);
803 ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
804 idents[i].ident_bit_pos,
805 idents[i].ident_bit_size);
807 /* Write it to the regfile, val64 is already in big-endian*/
808 if (ulp_regfile_write(parms->regfile,
809 idents[i].regfile_idx, val64)) {
810 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
811 idents[i].regfile_idx);
819 * Process the identifier instruction and either store it in the flow database
820 * or return it in the val (if not NULL) on success. If val is NULL, the
821 * identifier is to be stored in the flow database.
824 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
825 struct bnxt_ulp_mapper_tbl_info *tbl,
826 struct bnxt_ulp_mapper_ident_info *ident,
829 struct ulp_flow_db_res_params fid_parms;
832 struct tf_alloc_identifier_parms iparms = { 0 };
833 struct tf_free_identifier_parms free_parms = { 0 };
837 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
839 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
843 idx = ident->regfile_idx;
845 iparms.ident_type = ident->ident_type;
846 iparms.dir = tbl->direction;
848 rc = tf_alloc_identifier(tfp, &iparms);
850 BNXT_TF_DBG(ERR, "Alloc ident %s:%s failed.\n",
851 tf_dir_2_str(iparms.dir),
852 tf_ident_2_str(iparms.ident_type));
855 BNXT_TF_INF("Alloc ident %s:%s.success.\n",
856 tf_dir_2_str(iparms.dir),
857 tf_ident_2_str(iparms.ident_type));
859 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
860 if (ulp_regfile_write(parms->regfile, idx, id)) {
861 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
863 /* Need to free the identifier, so goto error */
867 /* Link the resource to the flow in the flow db */
869 memset(&fid_parms, 0, sizeof(fid_parms));
870 fid_parms.direction = tbl->direction;
871 fid_parms.resource_func = ident->resource_func;
872 fid_parms.resource_type = ident->ident_type;
873 fid_parms.resource_hndl = iparms.id;
874 fid_parms.critical_resource = tbl->critical_resource;
875 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
877 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
879 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
881 /* Need to free the identifier, so goto error */
887 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
888 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
889 ulp_mapper_ident_field_dump("Ident", ident, tbl, iparms.id);
895 /* Need to free the identifier */
896 free_parms.dir = tbl->direction;
897 free_parms.ident_type = ident->ident_type;
898 free_parms.id = iparms.id;
900 (void)tf_free_identifier(tfp, &free_parms);
902 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
904 tf_dir_2_str(tbl->direction));
909 * Process the identifier instruction and extract it from result blob.
910 * Increment the identifier reference count and store it in the flow database.
913 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
914 struct bnxt_ulp_mapper_tbl_info *tbl,
915 struct bnxt_ulp_mapper_ident_info *ident,
916 struct ulp_blob *res_blob)
918 struct ulp_flow_db_res_params fid_parms;
921 struct tf_search_identifier_parms sparms = { 0 };
922 struct tf_free_identifier_parms free_parms = { 0 };
926 /* Get the tfp from ulp context */
927 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
929 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
933 /* Extract the index from the result blob */
934 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
935 ident->ident_bit_pos, ident->ident_bit_size);
937 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
941 /* populate the search params and search identifier shadow table */
942 sparms.ident_type = ident->ident_type;
943 sparms.dir = tbl->direction;
944 /* convert the idx into cpu format */
945 sparms.search_id = tfp_be_to_cpu_32(idx);
947 /* Search identifier also increase the reference count */
948 rc = tf_search_identifier(tfp, &sparms);
950 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
951 tf_dir_2_str(sparms.dir),
952 tf_ident_2_str(sparms.ident_type),
956 BNXT_TF_INF("Search ident %s:%s:%x.success.\n",
957 tf_dir_2_str(sparms.dir),
958 tf_tbl_type_2_str(sparms.ident_type),
961 /* Write it to the regfile */
962 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
963 if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
964 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
966 /* Need to free the identifier, so goto error */
970 /* Link the resource to the flow in the flow db */
971 memset(&fid_parms, 0, sizeof(fid_parms));
972 fid_parms.direction = tbl->direction;
973 fid_parms.resource_func = ident->resource_func;
974 fid_parms.resource_type = ident->ident_type;
975 fid_parms.resource_hndl = sparms.search_id;
976 fid_parms.critical_resource = tbl->critical_resource;
977 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
979 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
981 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
983 /* Need to free the identifier, so goto error */
987 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
988 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
989 ulp_mapper_ident_field_dump("Ident", ident, tbl, sparms.search_id);
995 /* Need to free the identifier */
996 free_parms.dir = tbl->direction;
997 free_parms.ident_type = ident->ident_type;
998 free_parms.id = sparms.search_id;
999 (void)tf_free_identifier(tfp, &free_parms);
1000 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
1002 tf_dir_2_str(tbl->direction), sparms.search_id);
1007 ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
1012 enum bnxt_ulp_port_table port_data = val16;
1014 switch (port_data) {
1015 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
1016 if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
1018 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
1022 case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
1023 if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
1025 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
1029 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
1030 if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
1032 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
1037 BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
1044 ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
1045 enum bnxt_ulp_field_src field_src,
1054 struct bnxt_ulp_mapper_data *m;
1056 uint32_t port_id, val_size, field_size;
1057 uint16_t idx, size_idx, offset;
1058 uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
1065 /* Perform the action */
1066 switch (field_src) {
1067 case BNXT_ULP_FIELD_SRC_ZERO:
1068 *val = mapper_fld_zeros;
1070 case BNXT_ULP_FIELD_SRC_CONST:
1073 case BNXT_ULP_FIELD_SRC_ONES:
1074 *val = mapper_fld_ones;
1077 case BNXT_ULP_FIELD_SRC_CF:
1078 if (!ulp_operand_read(field_opr,
1079 (uint8_t *)&idx, sizeof(uint16_t))) {
1080 BNXT_TF_DBG(ERR, "CF operand read failed\n");
1083 idx = tfp_be_to_cpu_16(idx);
1084 if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t)) {
1085 BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
1089 buffer = (uint8_t *)&parms->comp_fld[idx];
1090 *val = &buffer[sizeof(uint64_t) - bytelen];
1091 *value = ULP_COMP_FLD_IDX_RD(parms, idx);
1093 case BNXT_ULP_FIELD_SRC_RF:
1094 if (!ulp_operand_read(field_opr,
1095 (uint8_t *)&idx, sizeof(uint16_t))) {
1096 BNXT_TF_DBG(ERR, "RF operand read failed\n");
1100 idx = tfp_be_to_cpu_16(idx);
1101 /* Uninitialized regfile entries return 0 */
1102 if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
1103 sizeof(uint64_t) < bytelen) {
1104 BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
1108 buffer = (uint8_t *)&parms->regfile->entry[idx].data;
1109 *val = &buffer[sizeof(uint64_t) - bytelen];
1110 *value = tfp_be_to_cpu_64(lregval);
1112 case BNXT_ULP_FIELD_SRC_ACT_PROP:
1113 if (!ulp_operand_read(field_opr,
1114 (uint8_t *)&idx, sizeof(uint16_t))) {
1115 BNXT_TF_DBG(ERR, "Action operand read failed\n");
1118 idx = tfp_be_to_cpu_16(idx);
1119 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1120 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
1123 buffer = &parms->act_prop->act_details[idx];
1124 field_size = ulp_mapper_act_prop_size_get(idx);
1125 if (bytelen > field_size) {
1126 BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
1130 *val = &buffer[field_size - bytelen];
1132 case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
1133 if (!ulp_operand_read(field_opr,
1134 (uint8_t *)&idx, sizeof(uint16_t))) {
1135 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1138 idx = tfp_be_to_cpu_16(idx);
1140 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1141 BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
1144 *val = &parms->act_prop->act_details[idx];
1146 /* get the size index next */
1147 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1148 (uint8_t *)&size_idx, sizeof(uint16_t))) {
1149 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1152 size_idx = tfp_be_to_cpu_16(size_idx);
1153 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1154 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
1157 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
1159 val_size = tfp_be_to_cpu_32(val_size);
1160 *val_len = ULP_BYTE_2_BITS(val_size);
1162 case BNXT_ULP_FIELD_SRC_GLB_RF:
1163 if (!ulp_operand_read(field_opr,
1164 (uint8_t *)&idx, sizeof(uint16_t))) {
1165 BNXT_TF_DBG(ERR, "Global regfile read failed\n");
1168 idx = tfp_be_to_cpu_16(idx);
1169 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1170 dir, idx, &lregval, &shared) ||
1171 sizeof(uint64_t) < bytelen) {
1172 BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
1176 m = parms->mapper_data;
1177 buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
1178 *val = &buffer[sizeof(uint64_t) - bytelen];
1179 *value = tfp_be_to_cpu_64(lregval);
1181 case BNXT_ULP_FIELD_SRC_HF:
1182 case BNXT_ULP_FIELD_SRC_SUB_HF:
1183 if (!ulp_operand_read(field_opr,
1184 (uint8_t *)&idx, sizeof(uint16_t))) {
1185 BNXT_TF_DBG(ERR, "Header field read failed\n");
1188 idx = tfp_be_to_cpu_16(idx);
1189 /* get the index from the global field list */
1190 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1191 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1196 buffer = parms->hdr_field[bit].spec;
1198 buffer = parms->hdr_field[bit].mask;
1200 field_size = parms->hdr_field[bit].size;
1201 if (bytelen > field_size) {
1202 BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
1206 if (field_src == BNXT_ULP_FIELD_SRC_HF) {
1207 *val = &buffer[field_size - bytelen];
1209 /* get the offset next */
1210 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1212 sizeof(uint16_t))) {
1213 BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
1216 offset = tfp_be_to_cpu_16(offset);
1217 offset = ULP_BITS_2_BYTE_NR(offset);
1218 if ((offset + bytelen) > field_size) {
1219 BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
1222 *val = &buffer[offset];
1225 case BNXT_ULP_FIELD_SRC_HDR_BIT:
1226 if (!ulp_operand_read(field_opr,
1227 (uint8_t *)&lregval, sizeof(uint64_t))) {
1228 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1231 lregval = tfp_be_to_cpu_64(lregval);
1232 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
1233 *val = mapper_fld_one;
1236 *val = mapper_fld_zeros;
1239 case BNXT_ULP_FIELD_SRC_ACT_BIT:
1240 if (!ulp_operand_read(field_opr,
1241 (uint8_t *)&lregval, sizeof(uint64_t))) {
1242 BNXT_TF_DBG(ERR, "Action bit read failed\n");
1245 lregval = tfp_be_to_cpu_64(lregval);
1246 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
1247 *val = mapper_fld_one;
1250 *val = mapper_fld_zeros;
1253 case BNXT_ULP_FIELD_SRC_FIELD_BIT:
1254 if (!ulp_operand_read(field_opr,
1255 (uint8_t *)&idx, sizeof(uint16_t))) {
1256 BNXT_TF_DBG(ERR, "Field bit read failed\n");
1259 idx = tfp_be_to_cpu_16(idx);
1260 /* get the index from the global field list */
1261 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1262 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1266 if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
1267 *val = mapper_fld_one;
1270 *val = mapper_fld_zeros;
1273 case BNXT_ULP_FIELD_SRC_PORT_TABLE:
1274 /* The port id is present in the comp field list */
1275 port_id = ULP_COMP_FLD_IDX_RD(parms,
1276 BNXT_ULP_CF_IDX_DEV_PORT_ID);
1277 /* get the port table enum */
1278 if (!ulp_operand_read(field_opr,
1279 (uint8_t *)&idx, sizeof(uint16_t))) {
1280 BNXT_TF_DBG(ERR, "Port table enum read failed\n");
1283 idx = tfp_be_to_cpu_16(idx);
1284 if (ulp_mapper_field_port_db_process(parms, port_id, idx,
1286 BNXT_TF_DBG(ERR, "field port table failed\n");
1290 case BNXT_ULP_FIELD_SRC_ENC_HDR_BIT:
1291 if (!ulp_operand_read(field_opr,
1292 (uint8_t *)&lregval, sizeof(uint64_t))) {
1293 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1296 lregval = tfp_be_to_cpu_64(lregval);
1297 if (ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits, lregval)) {
1298 *val = mapper_fld_one;
1301 *val = mapper_fld_zeros;
1304 case BNXT_ULP_FIELD_SRC_ENC_FIELD:
1305 if (!ulp_operand_read(field_opr,
1306 (uint8_t *)&idx, sizeof(uint16_t))) {
1307 BNXT_TF_DBG(ERR, "Header field read failed\n");
1310 idx = tfp_be_to_cpu_16(idx);
1311 /* get the index from the global field list */
1312 if (idx >= BNXT_ULP_ENC_FIELD_LAST) {
1313 BNXT_TF_DBG(ERR, "invalid encap field tbl idx %d\n",
1317 buffer = parms->enc_field[idx].spec;
1318 field_size = parms->enc_field[idx].size;
1319 if (bytelen > field_size) {
1320 BNXT_TF_DBG(ERR, "Encap field[%d] size small %u\n",
1324 *val = &buffer[field_size - bytelen];
1326 case BNXT_ULP_FIELD_SRC_SKIP:
1328 *val = mapper_fld_zeros;
1331 case BNXT_ULP_FIELD_SRC_REJECT:
1334 BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
1340 static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
1348 bytelen = ULP_BITS_2_BYTE(bitlen);
1349 if (bytelen == sizeof(uint8_t)) {
1350 *output = *((uint8_t *)buffer);
1351 } else if (bytelen == sizeof(uint16_t)) {
1352 val_16 = *((uint16_t *)buffer);
1353 *output = tfp_be_to_cpu_16(val_16);
1354 } else if (bytelen == sizeof(uint32_t)) {
1355 val_32 = *((uint32_t *)buffer);
1356 *output = tfp_be_to_cpu_32(val_32);
1357 } else if (bytelen == sizeof(val_64)) {
1358 val_64 = *((uint64_t *)buffer);
1359 *output = tfp_be_to_cpu_64(val_64);
1367 static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
1368 struct ulp_blob *blob,
1373 if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
1374 if (ulp_blob_pad_push(blob, val_len) < 0) {
1375 BNXT_TF_DBG(ERR, "too large for blob\n");
1378 } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
1379 if (ulp_blob_push_encap(blob, val, val_len) < 0) {
1380 BNXT_TF_DBG(ERR, "encap blob push failed\n");
1383 } else if (fld_src == BNXT_ULP_FIELD_SRC_SKIP) {
1386 if (!ulp_blob_push(blob, val, val_len)) {
1387 BNXT_TF_DBG(ERR, "push of val1 failed\n");
1396 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
1398 struct bnxt_ulp_mapper_field_info *fld,
1399 struct ulp_blob *blob,
1403 uint16_t write_idx = blob->write_idx;
1404 uint8_t *val = NULL, *val1, *val2, *val3;
1405 uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
1406 uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
1407 uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
1408 uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
1409 uint64_t value1 = 0, value2 = 0, value3 = 0;
1412 /* prepare the field source and values */
1413 switch (fld->field_opc) {
1414 case BNXT_ULP_FIELD_OPC_SRC1:
1417 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1420 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1421 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1429 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1430 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1431 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1432 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1433 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1434 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1444 /* process the src1 opcode */
1446 if (ulp_mapper_field_src_process(parms, fld->field_src1,
1447 fld->field_opr1, dir, is_key,
1448 fld->field_bit_size, &val1,
1449 &val1_len, &value1)) {
1450 BNXT_TF_DBG(ERR, "fld src1 process failed\n");
1454 if (ulp_mapper_field_buffer_eval(val1, val1_len,
1456 BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
1462 /* for "if then clause" set the correct process */
1463 if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
1470 /* process src2 opcode */
1472 if (ulp_mapper_field_src_process(parms, fld->field_src2,
1473 fld->field_opr2, dir, is_key,
1474 fld->field_bit_size, &val2,
1475 &val2_len, &value2)) {
1476 BNXT_TF_DBG(ERR, "fld src2 process failed\n");
1480 if (ulp_mapper_field_buffer_eval(val2, val2_len,
1482 BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
1488 /* process src3 opcode */
1490 if (ulp_mapper_field_src_process(parms, fld->field_src3,
1491 fld->field_opr3, dir, is_key,
1492 fld->field_bit_size, &val3,
1493 &val3_len, &value3)) {
1494 BNXT_TF_DBG(ERR, "fld src3 process failed\n");
1498 if (ulp_mapper_field_buffer_eval(val3, val3_len,
1500 BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
1506 val_len = fld->field_bit_size;
1507 /* process the field opcodes */
1508 switch (fld->field_opc) {
1509 case BNXT_ULP_FIELD_OPC_SRC1:
1510 rc = ulp_mapper_field_blob_write(fld->field_src1,
1511 blob, val1, val1_len, &val);
1514 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1516 rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
1517 val2, val2_len, &val);
1520 rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
1521 val3, val3_len, &val);
1525 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1526 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1527 val_int = val1_int + val2_int;
1528 val_int = tfp_cpu_to_be_64(val_int);
1529 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1533 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1534 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1535 val_int = val1_int - val2_int;
1536 val_int = tfp_cpu_to_be_64(val_int);
1537 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1541 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1542 val_int = val1_int | val2_int;
1543 val_int = tfp_cpu_to_be_64(val_int);
1544 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1548 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1549 val_int = val1_int | val2_int | val3_int;
1550 val_int = tfp_cpu_to_be_64(val_int);
1551 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1555 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1556 val_int = val1_int & val2_int;
1557 val_int = tfp_cpu_to_be_64(val_int);
1558 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1562 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1563 val_int = val1_int & (val2_int | val3_int);
1564 val_int = tfp_cpu_to_be_64(val_int);
1565 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1569 case BNXT_ULP_FIELD_OPC_SKIP:
1572 BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
1578 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1579 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
1580 if (fld->field_src1 != BNXT_ULP_FIELD_SRC_ZERO && val_len)
1581 ulp_mapper_field_dump(name, fld, blob, write_idx, val,
1588 BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
1589 fld->description, (val) ? write_idx : 0, val_len);
1594 * Result table process and fill the result blob.
1595 * data [out] - the result blob data
1598 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
1599 struct bnxt_ulp_mapper_tbl_info *tbl,
1600 struct ulp_blob *data,
1603 struct bnxt_ulp_mapper_field_info *dflds;
1604 uint32_t i = 0, num_flds = 0, encap_flds = 0;
1605 struct ulp_blob encap_blob;
1608 /* Get the result field list */
1609 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
1612 /* validate the result field list counts */
1613 if ((tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1614 (!num_flds && !encap_flds)) || !dflds ||
1615 (tbl->resource_func != BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1616 (!num_flds || encap_flds))) {
1617 BNXT_TF_DBG(ERR, "Failed to get data fields %x:%x\n",
1618 num_flds, encap_flds);
1622 /* process the result fields */
1623 for (i = 0; i < num_flds; i++) {
1624 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1625 &dflds[i], data, 0, name);
1627 BNXT_TF_DBG(ERR, "result field processing failed\n");
1632 /* process encap fields if any */
1635 /* Initialize the encap blob */
1636 if (!tbl->record_size &&
1637 !parms->device_params->dynamic_sram_en) {
1638 BNXT_TF_DBG(ERR, "Encap tbl record size incorrect\n");
1641 if (!ulp_blob_init(&encap_blob,
1642 ULP_BYTE_2_BITS(tbl->record_size),
1643 parms->device_params->encap_byte_order)) {
1644 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1647 for (; i < encap_flds; i++) {
1648 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1650 &encap_blob, 0, name);
1653 "encap field processing failed\n");
1657 /* add the dynamic pad push */
1658 if (parms->device_params->dynamic_sram_en) {
1659 uint16_t rec_s = ULP_BYTE_2_BITS(tbl->record_size);
1661 (void)ulp_mapper_dyn_tbl_type_get(parms, tbl,
1662 &encap_blob, &rec_s);
1663 pad = rec_s - ulp_blob_data_len_get(&encap_blob);
1665 pad = ULP_BYTE_2_BITS(tbl->record_size) -
1666 ulp_blob_data_len_get(&encap_blob);
1668 if (ulp_blob_pad_push(&encap_blob, pad) < 0) {
1669 BNXT_TF_DBG(ERR, "encap buffer padding failed\n");
1674 /* perform the 64 bit byte swap */
1675 ulp_blob_perform_64B_byte_swap(&encap_blob);
1676 /* Append encap blob to the result blob */
1677 rc = ulp_blob_buffer_copy(data, &encap_blob);
1679 BNXT_TF_DBG(ERR, "encap buffer copy failed\n");
1683 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1684 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
1685 BNXT_TF_DBG(DEBUG, "Result dump\n");
1686 ulp_mapper_blob_dump(data);
1693 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1694 struct bnxt_ulp_mapper_tbl_info *tbl,
1697 struct ulp_flow_db_res_params fid_parms;
1698 uint32_t mark, gfid, mark_flag;
1699 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1702 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1703 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1704 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1705 BNXT_ULP_ACT_BIT_MARK)))
1706 return rc; /* no need to perform gfid process */
1708 /* Get the mark id details from action property */
1709 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1711 mark = tfp_be_to_cpu_32(mark);
1713 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1714 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1716 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1719 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1722 fid_parms.direction = tbl->direction;
1723 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1724 fid_parms.critical_resource = tbl->critical_resource;
1725 fid_parms.resource_type = mark_flag;
1726 fid_parms.resource_hndl = gfid;
1727 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1729 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1731 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1736 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1737 struct bnxt_ulp_mapper_tbl_info *tbl)
1739 struct ulp_flow_db_res_params fid_parms;
1740 uint32_t act_idx, mark, mark_flag;
1742 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1745 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1746 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1747 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1748 BNXT_ULP_ACT_BIT_MARK)))
1749 return rc; /* no need to perform mark action process */
1751 /* Get the mark id details from action property */
1752 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1754 mark = tfp_be_to_cpu_32(mark);
1756 if (!ulp_regfile_read(parms->regfile,
1757 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1759 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1762 act_idx = tfp_be_to_cpu_64(val64);
1763 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1764 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1767 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1770 fid_parms.direction = tbl->direction;
1771 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1772 fid_parms.critical_resource = tbl->critical_resource;
1773 fid_parms.resource_type = mark_flag;
1774 fid_parms.resource_hndl = act_idx;
1775 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1777 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1779 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1784 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1785 struct bnxt_ulp_mapper_tbl_info *tbl)
1787 struct ulp_flow_db_res_params fid_parms;
1788 uint32_t act_idx, mark, mark_flag;
1790 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1793 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1794 mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
1795 return rc; /* no need to perform mark action process */
1797 /* Get the mark id details from the computed field of dev port id */
1798 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1800 /* Get the main action pointer */
1801 if (!ulp_regfile_read(parms->regfile,
1802 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1804 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1807 act_idx = tfp_be_to_cpu_64(val64);
1809 /* Set the mark flag to local fid and vfr flag */
1810 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1812 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1815 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1818 fid_parms.direction = tbl->direction;
1819 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1820 fid_parms.critical_resource = tbl->critical_resource;
1821 fid_parms.resource_type = mark_flag;
1822 fid_parms.resource_hndl = act_idx;
1823 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1825 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1827 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1831 /* Tcam table scan the identifier list and allocate each identifier */
1833 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1834 struct bnxt_ulp_mapper_tbl_info *tbl)
1836 struct bnxt_ulp_mapper_ident_info *idents;
1837 uint32_t num_idents;
1840 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1841 for (i = 0; i < num_idents; i++) {
1842 if (ulp_mapper_ident_process(parms, tbl,
1850 * Tcam table scan the identifier list and extract the identifier from
1854 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1855 struct bnxt_ulp_mapper_tbl_info *tbl,
1856 struct ulp_blob *data)
1858 struct bnxt_ulp_mapper_ident_info *idents;
1859 uint32_t num_idents = 0, i;
1863 * Extract the listed identifiers from the result field,
1864 * no need to allocate them.
1866 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1867 for (i = 0; i < num_idents; i++) {
1868 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1870 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1877 /* Internal function to write the tcam entry */
1879 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1880 struct bnxt_ulp_mapper_tbl_info *tbl,
1881 struct ulp_blob *key,
1882 struct ulp_blob *mask,
1883 struct ulp_blob *data,
1886 struct tf_set_tcam_entry_parms sparms = { 0 };
1891 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1893 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1897 sparms.dir = tbl->direction;
1898 sparms.tcam_tbl_type = tbl->resource_type;
1900 sparms.key = ulp_blob_data_get(key, &tmplen);
1901 sparms.key_sz_in_bits = tmplen;
1902 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1903 sparms.result = ulp_blob_data_get(data, &tmplen);
1904 sparms.result_sz_in_bits = tmplen;
1905 if (tf_set_tcam_entry(tfp, &sparms)) {
1906 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1907 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1908 tf_dir_2_str(sparms.dir), sparms.idx);
1911 BNXT_TF_INF("tcam[%s][%s][%x] write success.\n",
1912 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1913 tf_dir_2_str(sparms.dir), sparms.idx);
1916 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1918 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1922 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1923 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
1924 ulp_mapper_tcam_entry_dump("TCAM", idx, tbl, key, mask, data);
1931 * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
1933 * parms [in] The mappers parms with data related to the flow.
1935 * key [in] The original key to be transformed
1937 * mask [in] The original mask to be transformed
1939 * tkey [in/out] The transformed key
1941 * tmask [in/out] The transformed mask
1943 * returns zero on success, non-zero on failure
1946 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
1947 struct ulp_blob *key,
1948 struct ulp_blob *mask,
1949 struct ulp_blob *tkey,
1950 struct ulp_blob *tmask)
1952 uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
1953 uint32_t cword, i, rc;
1957 slice_width = dparms->wc_slice_width;
1958 clen = dparms->wc_ctl_size_bits;
1959 max_slices = dparms->wc_max_slices;
1960 blen = ulp_blob_data_len_get(key);
1962 /* Get the length of the key based on number of slices and width */
1965 while (tlen < blen &&
1966 num_slices <= max_slices) {
1967 num_slices = num_slices << 1;
1971 if (num_slices > max_slices) {
1972 BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
1976 /* The key/mask may not be on a natural slice boundary, pad it */
1978 if (ulp_blob_pad_push(key, pad) < 0 ||
1979 ulp_blob_pad_push(mask, pad) < 0) {
1980 BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
1984 /* The new length accounts for the ctrl word length and num slices */
1985 tlen = tlen + clen * num_slices;
1986 if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
1987 !ulp_blob_init(tmask, tlen, mask->byte_order)) {
1988 BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
1992 /* Build the transformed key/mask */
1993 cword = dparms->wc_mode_list[num_slices - 1];
1994 cword = tfp_cpu_to_be_32(cword);
1996 for (i = 0; i < num_slices; i++) {
1997 val = ulp_blob_push_32(tkey, &cword, clen);
1999 BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
2002 val = ulp_blob_push_32(tmask, &cword, clen);
2004 BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
2007 rc = ulp_blob_append(tkey, key, offset, slice_width);
2009 BNXT_TF_DBG(ERR, "Key blob append failed\n");
2012 rc = ulp_blob_append(tmask, mask, offset, slice_width);
2014 BNXT_TF_DBG(ERR, "Mask blob append failed\n");
2017 offset += slice_width;
2020 /* The key/mask are byte reversed on every 4 byte chunk */
2021 ulp_blob_perform_byte_reverse(tkey, 4);
2022 ulp_blob_perform_byte_reverse(tmask, 4);
2027 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
2028 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
2030 ulp_blob_perform_64B_word_swap(blob);
2031 ulp_blob_perform_64B_byte_swap(blob);
2032 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2033 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2034 BNXT_TF_DBG(INFO, "Dump after wc tcam post process\n");
2035 ulp_mapper_blob_dump(blob);
2040 static int32_t ulp_mapper_tcam_is_wc_tcam(struct bnxt_ulp_mapper_tbl_info *tbl)
2042 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM ||
2043 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_HIGH ||
2044 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_LOW)
2050 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2051 struct bnxt_ulp_mapper_tbl_info *tbl)
2053 struct bnxt_ulp_mapper_key_info *kflds;
2054 struct ulp_blob okey, omask, data, update_data;
2055 struct ulp_blob tkey, tmask; /* transform key and mask */
2056 struct ulp_blob *key, *mask;
2057 uint32_t i, num_kflds;
2060 struct bnxt_ulp_device_params *dparms = parms->device_params;
2061 struct tf_alloc_tcam_entry_parms aparms = { 0 };
2062 struct tf_search_tcam_entry_parms searchparms = { 0 };
2063 struct ulp_flow_db_res_params fid_parms = { 0 };
2064 struct tf_free_tcam_entry_parms free_parms = { 0 };
2066 uint16_t tmplen = 0;
2068 enum bnxt_ulp_byte_order key_byte_order;
2070 /* Set the key and mask to the original key and mask. */
2074 /* Skip this if table opcode is NOP */
2075 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
2076 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
2077 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
2082 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2084 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
2088 /* If only allocation of identifier then perform and exit */
2089 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_IDENT) {
2090 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
2094 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2095 if (!kflds || !num_kflds) {
2096 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2100 if (ulp_mapper_tcam_is_wc_tcam(tbl))
2101 key_byte_order = dparms->wc_key_byte_order;
2103 key_byte_order = dparms->key_byte_order;
2105 if (!ulp_blob_init(key, tbl->blob_key_bit_size, key_byte_order) ||
2106 !ulp_blob_init(mask, tbl->blob_key_bit_size, key_byte_order) ||
2107 !ulp_blob_init(&data, tbl->result_bit_size,
2108 dparms->result_byte_order) ||
2109 !ulp_blob_init(&update_data, tbl->result_bit_size,
2110 dparms->result_byte_order)) {
2111 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2115 /* create the key/mask */
2117 * NOTE: The WC table will require some kind of flag to handle the
2118 * mode bits within the key/mask
2120 for (i = 0; i < num_kflds; i++) {
2122 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2123 &kflds[i].field_info_spec,
2124 key, 1, "TCAM Key");
2126 BNXT_TF_DBG(ERR, "Key field set failed %s\n",
2127 kflds[i].field_info_spec.description);
2131 /* Setup the mask */
2132 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2133 &kflds[i].field_info_mask,
2134 mask, 0, "TCAM Mask");
2136 BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
2137 kflds[i].field_info_mask.description);
2142 /* For wild card tcam perform the post process to swap the blob */
2143 if (ulp_mapper_tcam_is_wc_tcam(tbl)) {
2144 if (dparms->dynamic_pad_en) {
2145 /* Sets up the slices for writing to the WC TCAM */
2146 rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
2152 "Failed to post proc WC entry.\n");
2155 /* Now need to use the transform Key/Mask */
2159 ulp_mapper_wc_tcam_tbl_post_process(key);
2160 ulp_mapper_wc_tcam_tbl_post_process(mask);
2165 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
2166 /* allocate the tcam index */
2167 aparms.dir = tbl->direction;
2168 aparms.tcam_tbl_type = tbl->resource_type;
2169 aparms.key = ulp_blob_data_get(key, &tmplen);
2170 aparms.key_sz_in_bits = tmplen;
2171 aparms.mask = ulp_blob_data_get(mask, &tmplen);
2173 /* calculate the entry priority */
2174 rc = ulp_mapper_priority_opc_process(parms, tbl,
2177 BNXT_TF_DBG(ERR, "entry priority process failed\n");
2181 rc = tf_alloc_tcam_entry(tfp, &aparms);
2183 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
2190 * Searching before allocation to see if we already have an
2191 * entry. This allows re-use of a constrained resource.
2193 searchparms.dir = tbl->direction;
2194 searchparms.tcam_tbl_type = tbl->resource_type;
2195 searchparms.key = ulp_blob_data_get(key, &tmplen);
2196 searchparms.key_sz_in_bits = tbl->key_bit_size;
2197 searchparms.mask = ulp_blob_data_get(mask, &tmplen);
2198 searchparms.alloc = 1;
2199 searchparms.result = ulp_blob_data_get(&data, &tmplen);
2200 searchparms.result_sz_in_bits = tbl->result_bit_size;
2202 /* calculate the entry priority */
2203 rc = ulp_mapper_priority_opc_process(parms, tbl,
2204 &searchparms.priority);
2206 BNXT_TF_DBG(ERR, "entry priority process failed\n");
2210 rc = tf_search_tcam_entry(tfp, &searchparms);
2212 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
2216 /* Successful search, check the result */
2217 if (searchparms.search_status == REJECT) {
2218 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
2221 idx = searchparms.idx;
2222 hit = searchparms.hit;
2225 /* Write the tcam index into the regfile*/
2226 if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
2227 (uint64_t)tfp_cpu_to_be_64(idx))) {
2228 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
2231 /* Need to free the tcam idx, so goto error */
2235 /* if it is miss then it is same as no search before alloc */
2236 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
2237 /*Scan identifier list, allocate identifier and update regfile*/
2238 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
2239 /* Create the result blob */
2241 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2243 /* write the tcam entry */
2245 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
2248 /*Scan identifier list, extract identifier and update regfile*/
2249 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
2254 /* Add the tcam index to the flow database */
2255 fid_parms.direction = tbl->direction;
2256 fid_parms.resource_func = tbl->resource_func;
2257 fid_parms.resource_type = tbl->resource_type;
2258 fid_parms.critical_resource = tbl->critical_resource;
2259 fid_parms.resource_hndl = idx;
2260 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2262 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2264 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2266 /* Need to free the identifier, so goto error */
2272 free_parms.dir = tbl->direction;
2273 free_parms.tcam_tbl_type = tbl->resource_type;
2274 free_parms.idx = idx;
2275 trc = tf_free_tcam_entry(tfp, &free_parms);
2277 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
2278 tbl->resource_type, tbl->direction, idx);
2283 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2284 struct bnxt_ulp_mapper_tbl_info *tbl)
2286 struct bnxt_ulp_mapper_key_info *kflds;
2287 struct ulp_blob key, data;
2288 uint32_t i, num_kflds;
2291 struct ulp_flow_db_res_params fid_parms = { 0 };
2292 struct tf_insert_em_entry_parms iparms = { 0 };
2293 struct tf_delete_em_entry_parms free_parms = { 0 };
2294 enum bnxt_ulp_flow_mem_type mtype;
2295 struct bnxt_ulp_device_params *dparms = parms->device_params;
2299 enum bnxt_ulp_byte_order key_order, res_order;
2301 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2302 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2304 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
2308 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2309 if (!kflds || !num_kflds) {
2310 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2314 key_order = dparms->em_byte_order;
2315 res_order = dparms->em_byte_order;
2317 /* Initialize the key/result blobs */
2318 if (!ulp_blob_init(&key, tbl->blob_key_bit_size, key_order) ||
2319 !ulp_blob_init(&data, tbl->result_bit_size, res_order)) {
2320 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2324 /* create the key */
2325 for (i = 0; i < num_kflds; i++) {
2327 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2328 &kflds[i].field_info_spec,
2331 BNXT_TF_DBG(ERR, "Key field set failed.\n");
2336 /* if dynamic padding is enabled then add padding to result data */
2337 if (dparms->dynamic_pad_en) {
2338 /* add padding to make sure key is at byte boundary */
2339 ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
2342 pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
2344 BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
2347 ulp_blob_pad_push(&data, (uint32_t)pad);
2350 /* Create the result data blob */
2351 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
2353 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2356 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2357 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2358 ulp_mapper_result_dump("EM Result", tbl, &data);
2361 if (dparms->dynamic_pad_en) {
2362 uint32_t abits = dparms->em_blk_align_bits;
2364 /* when dynamic padding is enabled merge result + key */
2365 rc = ulp_blob_block_merge(&data, &key, abits, pad);
2367 BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
2371 /* add padding to make sure merged result is at slice boundary*/
2372 ulp_blob_pad_align(&data, abits);
2374 ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
2375 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2376 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2377 ulp_mapper_result_dump("EM Merged Result", tbl, &data);
2382 /* do the transpose for the internal EM keys */
2383 if (tbl->resource_type == TF_MEM_INTERNAL) {
2384 if (dparms->em_key_align_bytes) {
2385 int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
2387 tmplen = ulp_blob_data_len_get(&key);
2388 ulp_blob_pad_push(&key, b - tmplen);
2390 tmplen = ulp_blob_data_len_get(&key);
2391 ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
2392 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2393 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2394 ulp_mapper_result_dump("EM Key Transpose", tbl, &key);
2399 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
2400 &iparms.tbl_scope_id);
2402 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2407 * NOTE: the actual blob size will differ from the size in the tbl
2408 * entry due to the padding.
2410 iparms.dup_check = 0;
2411 iparms.dir = tbl->direction;
2412 iparms.mem = tbl->resource_type;
2413 iparms.key = ulp_blob_data_get(&key, &tmplen);
2414 iparms.key_sz_in_bits = tbl->key_bit_size;
2415 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
2416 if (tbl->result_bit_size)
2417 iparms.em_record_sz_in_bits = tbl->result_bit_size;
2419 iparms.em_record_sz_in_bits = tmplen;
2421 rc = tf_insert_em_entry(tfp, &iparms);
2423 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
2427 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2428 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2429 ulp_mapper_em_dump("EM", &key, &data, &iparms);
2430 /* tf_dump_tables(tfp, iparms.tbl_scope_id); */
2433 /* Mark action process */
2434 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
2435 tbl->resource_type == TF_MEM_EXTERNAL)
2436 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
2437 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
2438 tbl->resource_type == TF_MEM_INTERNAL)
2439 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
2441 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
2445 /* Link the EM resource to the flow in the flow db */
2446 memset(&fid_parms, 0, sizeof(fid_parms));
2447 fid_parms.direction = tbl->direction;
2448 fid_parms.resource_func = tbl->resource_func;
2449 fid_parms.resource_type = tbl->resource_type;
2450 fid_parms.critical_resource = tbl->critical_resource;
2451 fid_parms.resource_hndl = iparms.flow_handle;
2453 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2455 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
2457 /* Need to free the identifier, so goto error */
2463 free_parms.dir = iparms.dir;
2464 free_parms.mem = iparms.mem;
2465 free_parms.tbl_scope_id = iparms.tbl_scope_id;
2466 free_parms.flow_handle = iparms.flow_handle;
2468 trc = tf_delete_em_entry(tfp, &free_parms);
2470 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
2476 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2477 struct bnxt_ulp_mapper_tbl_info *tbl)
2479 struct ulp_flow_db_res_params fid_parms;
2480 struct ulp_blob data;
2481 uint64_t regval = 0;
2484 int32_t rc = 0, trc = 0;
2485 struct tf_alloc_tbl_entry_parms aparms = { 0 };
2486 struct tf_set_tbl_entry_parms sparms = { 0 };
2487 struct tf_get_tbl_entry_parms gparms = { 0 };
2488 struct tf_free_tbl_entry_parms free_parms = { 0 };
2489 uint32_t tbl_scope_id;
2491 struct bnxt_ulp_glb_resource_info glb_res = { 0 };
2495 bool global = false;
2496 uint64_t act_rec_size;
2497 bool shared = false;
2498 enum tf_tbl_type tbl_type = tbl->resource_type;
2500 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2501 /* compute the blob size */
2502 bit_size = ulp_mapper_dyn_blob_size_get(parms, tbl);
2504 /* Initialize the blob data */
2505 if (!ulp_blob_init(&data, bit_size,
2506 parms->device_params->result_byte_order)) {
2507 BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
2511 /* Get the scope id first */
2512 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
2514 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2518 switch (tbl->tbl_opcode) {
2519 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
2522 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
2524 * Build the entry, alloc an index, write the table, and store
2525 * the data in the regfile.
2530 case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
2532 * get the index to write to from the regfile and then write
2535 if (!ulp_regfile_read(parms->regfile,
2539 "Failed to get tbl idx from regfile[%d].\n",
2543 index = tfp_be_to_cpu_64(regval);
2544 /* For external, we need to reverse shift */
2545 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2546 index = TF_ACT_REC_PTR_2_OFFSET(index);
2550 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
2552 * Build the entry, alloc an index, write the table, and store
2553 * the data in the global regfile.
2558 glb_res.direction = tbl->direction;
2559 glb_res.resource_func = tbl->resource_func;
2560 glb_res.resource_type = tbl->resource_type;
2561 glb_res.glb_regfile_index = tbl->tbl_operand;
2563 case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
2564 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2565 BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
2569 * get the index to write to from the global regfile and then
2572 if (ulp_mapper_glb_resource_read(parms->mapper_data,
2575 ®val, &shared)) {
2577 "Failed to get tbl idx from Glb RF[%d].\n",
2581 index = tfp_be_to_cpu_64(regval);
2582 /* For external, we need to reverse shift */
2583 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2584 index = TF_ACT_REC_PTR_2_OFFSET(index);
2587 case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
2589 * The read is different from the rest and can be handled here
2590 * instead of trying to use common code. Simply read the table
2591 * with the index from the regfile, scan and store the
2592 * identifiers, and return.
2594 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2595 /* Not currently supporting with EXT */
2597 "Ext Table Read Opcode not supported.\n");
2600 if (!ulp_regfile_read(parms->regfile,
2601 tbl->tbl_operand, ®val)) {
2603 "Failed to get tbl idx from regfile[%d]\n",
2607 index = tfp_be_to_cpu_64(regval);
2608 gparms.dir = tbl->direction;
2609 gparms.type = tbl->resource_type;
2610 gparms.data = ulp_blob_data_get(&data, &tmplen);
2611 gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2613 rc = tf_get_tbl_entry(tfp, &gparms);
2615 BNXT_TF_DBG(ERR, "Failed to read the tbl entry %d:%d\n",
2616 tbl->resource_type, index);
2620 * Scan the fields in the entry and push them into the regfile.
2622 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2624 gparms.data_sz_in_bytes,
2628 "Failed to get flds on tbl read rc=%d\n",
2634 BNXT_TF_DBG(ERR, "Invalid index table opcode %d\n",
2640 /* Get the result fields list */
2641 rc = ulp_mapper_tbl_result_build(parms,
2646 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2652 aparms.dir = tbl->direction;
2653 tbl_type = ulp_mapper_dyn_tbl_type_get(parms, tbl,
2655 aparms.type = tbl_type;
2656 aparms.tbl_scope_id = tbl_scope_id;
2658 /* All failures after the alloc succeeds require a free */
2659 rc = tf_alloc_tbl_entry(tfp, &aparms);
2661 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2662 tf_tbl_type_2_str(aparms.type),
2663 tf_dir_2_str(tbl->direction), rc);
2669 * Store the index in the regfile since we either allocated it
2672 * Calculate the idx for the result record, for external EM the
2673 * offset needs to be shifted accordingly.
2674 * If external non-inline table types are used then need to
2675 * revisit this logic.
2677 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2678 regval = TF_ACT_REC_OFFSET_2_PTR(index);
2681 regval = tfp_cpu_to_be_64(regval);
2685 * Shared resources are never allocated through this
2686 * method, so the shared flag is always false.
2688 rc = ulp_mapper_glb_resource_write(parms->mapper_data,
2692 rc = ulp_regfile_write(parms->regfile,
2693 tbl->tbl_operand, regval);
2697 "Failed to write %s regfile[%d] rc=%d\n",
2698 (global) ? "global" : "reg",
2699 tbl->tbl_operand, rc);
2705 sparms.dir = tbl->direction;
2706 sparms.data = ulp_blob_data_get(&data, &tmplen);
2707 tbl_type = ulp_mapper_dyn_tbl_type_get(parms, tbl, &data,
2709 sparms.type = tbl_type;
2710 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2712 sparms.tbl_scope_id = tbl_scope_id;
2714 tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
2715 rc = tf_set_tbl_entry(tfp, &sparms);
2718 "Index table[%s][%s][%x] write fail rc=%d\n",
2719 tf_tbl_type_2_str(sparms.type),
2720 tf_dir_2_str(sparms.dir),
2724 BNXT_TF_INF("Index table[%s][%s][%x] write successful.\n",
2725 tf_tbl_type_2_str(sparms.type),
2726 tf_dir_2_str(sparms.dir), sparms.idx);
2728 /* Calculate action record size */
2729 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2730 act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
2732 if (ulp_regfile_write(parms->regfile,
2733 BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
2734 tfp_cpu_to_be_64(act_rec_size)))
2736 "Failed write the act rec size\n");
2740 /* Link the resource to the flow in the flow db */
2741 memset(&fid_parms, 0, sizeof(fid_parms));
2742 fid_parms.direction = tbl->direction;
2743 fid_parms.resource_func = tbl->resource_func;
2744 fid_parms.resource_type = tbl_type;
2745 fid_parms.resource_sub_type = tbl->resource_sub_type;
2746 fid_parms.resource_hndl = index;
2747 fid_parms.critical_resource = tbl->critical_resource;
2748 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2750 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2752 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2757 /* Perform the VF rep action */
2758 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2760 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2765 /* Shared resources are not freed */
2769 * Free the allocated resource since we failed to either
2770 * write to the entry or link the flow
2772 free_parms.dir = tbl->direction;
2773 free_parms.type = tbl_type;
2774 free_parms.idx = index;
2775 free_parms.tbl_scope_id = tbl_scope_id;
2777 trc = tf_free_tbl_entry(tfp, &free_parms);
2779 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2785 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2786 struct bnxt_ulp_mapper_tbl_info *tbl)
2788 struct ulp_blob data, res_blob;
2792 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2793 struct tf_get_if_tbl_entry_parms get_parms = { 0 };
2795 enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
2798 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2799 /* Initialize the blob data */
2800 if (!ulp_blob_init(&data, tbl->result_bit_size,
2801 parms->device_params->result_byte_order)) {
2802 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2806 /* create the result blob */
2807 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
2809 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2813 /* Get the index details */
2815 case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
2816 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2818 case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
2819 if (!ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx)) {
2820 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
2824 idx = tfp_be_to_cpu_64(idx);
2826 case BNXT_ULP_IF_TBL_OPC_WR_CONST:
2827 idx = tbl->tbl_operand;
2829 case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
2830 /* Initialize the result blob */
2831 if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
2832 parms->device_params->result_byte_order)) {
2833 BNXT_TF_DBG(ERR, "Failed initial result blob\n");
2837 /* read the interface table */
2838 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2839 res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
2840 get_parms.dir = tbl->direction;
2841 get_parms.type = tbl->resource_type;
2842 get_parms.idx = idx;
2843 get_parms.data = ulp_blob_data_get(&res_blob, &tmplen);
2844 get_parms.data_sz_in_bytes = res_size;
2846 rc = tf_get_if_tbl_entry(tfp, &get_parms);
2848 BNXT_TF_DBG(ERR, "Get table[%d][%s][%x] failed rc=%d\n",
2850 tf_dir_2_str(get_parms.dir),
2854 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2857 res_blob.byte_order);
2859 BNXT_TF_DBG(ERR, "Scan and extract failed rc=%d\n", rc);
2861 case BNXT_ULP_IF_TBL_OPC_NOT_USED:
2862 return rc; /* skip it */
2864 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2868 /* Perform the tf table set by filling the set params */
2869 iftbl_params.dir = tbl->direction;
2870 iftbl_params.type = tbl->resource_type;
2871 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2872 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2873 iftbl_params.idx = idx;
2875 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2877 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2878 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2879 tf_dir_2_str(iftbl_params.dir),
2880 iftbl_params.idx, rc);
2883 BNXT_TF_INF("Set table[%s][%s][%x] success.\n",
2884 tf_if_tbl_2_str(iftbl_params.type),
2885 tf_dir_2_str(iftbl_params.dir),
2889 * TBD: Need to look at the need to store idx in flow db for restore
2890 * the table to its original state on deletion of this entry.
2896 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2897 struct bnxt_ulp_mapper_tbl_info *tbl)
2899 struct ulp_mapper_gen_tbl_list *gen_tbl_list;
2900 struct bnxt_ulp_mapper_key_info *kflds;
2901 struct ulp_flow_db_res_params fid_parms;
2902 struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
2903 struct ulp_gen_hash_entry_params hash_entry;
2904 uint16_t tmplen = 0;
2905 struct ulp_blob key, data;
2908 uint32_t i, num_kflds = 0, key_index = 0;
2909 uint32_t gen_tbl_miss = 1, fdb_write = 0;
2913 /* Get the key fields list and build the key. */
2914 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2915 if (!kflds || !num_kflds) {
2916 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2920 if (!ulp_blob_init(&key, tbl->key_bit_size,
2921 parms->device_params->key_byte_order)) {
2922 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2925 for (i = 0; i < num_kflds; i++) {
2927 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2928 &kflds[i].field_info_spec,
2929 &key, 1, "Gen Tbl Key");
2932 "Failed to create key for Gen tbl rc=%d\n",
2938 /* Calculate the table index for the generic table*/
2939 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2942 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2943 tbl->resource_sub_type, tbl->direction);
2947 /* The_key is a byte array convert it to a search index */
2948 cache_key = ulp_blob_data_get(&key, &tmplen);
2949 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2950 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2951 ulp_mapper_gen_tbl_dump(tbl->resource_sub_type, tbl->direction, &key);
2954 /* get the generic table */
2955 gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
2957 /* Check if generic hash table */
2958 if (gen_tbl_list->hash_tbl) {
2959 if (tbl->gen_tbl_lkup_type !=
2960 BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
2961 BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
2962 gen_tbl_list->gen_tbl_name);
2965 hash_entry.key_data = cache_key;
2966 hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
2967 rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
2970 BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
2971 gen_tbl_list->gen_tbl_name);
2974 if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
2975 key_index = hash_entry.key_idx;
2976 /* Get the generic table entry */
2977 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
2981 /* store the hash index in the fdb */
2982 key_index = hash_entry.hash_index;
2985 /* convert key to index directly */
2986 if (ULP_BITS_2_BYTE(tmplen) > (int32_t)sizeof(key_index)) {
2987 BNXT_TF_DBG(ERR, "%s: keysize is bigger then 4 bytes\n",
2988 gen_tbl_list->gen_tbl_name);
2991 memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
2992 /* Get the generic table entry */
2993 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
2997 switch (tbl->tbl_opcode) {
2998 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2999 if (gen_tbl_list->hash_tbl) {
3000 if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
3001 break; /* nothing to be done , no entry */
3004 /* check the reference count */
3005 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
3007 /* Scan ident list and create the result blob*/
3008 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
3014 "Failed to scan ident list\n");
3017 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
3018 /* increment the reference count */
3019 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
3027 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
3028 if (gen_tbl_list->hash_tbl) {
3029 rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
3034 /* store the hash index in the fdb */
3035 key_index = hash_entry.hash_index;
3037 /* check the reference count */
3038 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
3039 /* a hit then error */
3040 BNXT_TF_DBG(ERR, "generic entry already present\n");
3041 return -EINVAL; /* success */
3044 /* Initialize the blob data */
3045 if (!ulp_blob_init(&data, tbl->result_bit_size,
3046 gen_tbl_ent.byte_order)) {
3047 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
3051 /* Get the result fields list */
3052 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
3055 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
3058 byte_data = ulp_blob_data_get(&data, &tmplen);
3059 rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
3061 ULP_BITS_2_BYTE(tmplen));
3063 BNXT_TF_DBG(ERR, "Failed to write generic table\n");
3067 /* increment the reference count */
3068 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
3070 parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
3073 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
3077 /* Set the generic entry hit */
3078 rc = ulp_regfile_write(parms->regfile,
3079 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3080 tfp_cpu_to_be_64(gen_tbl_miss));
3082 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
3083 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3087 /* add the entry to the flow database */
3089 memset(&fid_parms, 0, sizeof(fid_parms));
3090 fid_parms.direction = tbl->direction;
3091 fid_parms.resource_func = tbl->resource_func;
3092 fid_parms.resource_sub_type = tbl->resource_sub_type;
3093 fid_parms.resource_hndl = key_index;
3094 fid_parms.critical_resource = tbl->critical_resource;
3095 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
3097 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
3099 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
3105 ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
3106 struct bnxt_ulp_mapper_tbl_info *tbl)
3110 /* process the fdb opcode for alloc push */
3111 if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
3112 rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
3114 BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
3122 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
3123 struct bnxt_ulp_mapper_data *mapper_data)
3125 struct bnxt_ulp_glb_resource_info *glb_res;
3126 uint32_t num_glb_res_ids, idx, dev_id;
3130 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
3131 if (!glb_res || !num_glb_res_ids) {
3132 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
3136 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
3138 BNXT_TF_DBG(ERR, "Failed to get device id for glb init (%d)\n",
3143 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
3145 BNXT_TF_DBG(ERR, "Failed to get app id for glb init (%d)\n",
3150 /* Iterate the global resources and process each one */
3151 for (idx = 0; idx < num_glb_res_ids; idx++) {
3152 if (dev_id != glb_res[idx].device_id ||
3153 glb_res[idx].app_id != app_id)
3155 switch (glb_res[idx].resource_func) {
3156 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3157 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
3161 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3162 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
3167 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
3168 glb_res[idx].resource_func);
3179 * Iterate over the shared resources assigned during tf_open_session and store
3180 * them in the global regfile with the shared flag.
3183 ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
3184 struct bnxt_ulp_mapper_data *mapper_data)
3186 struct tf_get_shared_tbl_increment_parms iparms;
3187 struct bnxt_ulp_glb_resource_info *glb_res;
3188 struct tf_get_session_info_parms sparms;
3189 uint32_t num_entries, i, dev_id, res;
3190 struct tf_resource_info *res_info;
3198 memset(&sparms, 0, sizeof(sparms));
3199 glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
3200 if (!glb_res || !num_entries) {
3201 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
3204 tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
3206 BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
3210 * Retrieve the resources that were assigned during the shared session
3213 rc = tf_get_session_info(tfp, &sparms);
3215 BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
3219 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
3221 BNXT_TF_DBG(ERR, "Failed to get the app id in glb init (%d).\n",
3226 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
3228 BNXT_TF_DBG(ERR, "Failed to get dev id for app glb init (%d)\n",
3233 /* Store all the app global resources */
3234 for (i = 0; i < num_entries; i++) {
3235 if (dev_id != glb_res[i].device_id ||
3236 app_id != glb_res[i].app_id)
3238 dir = glb_res[i].direction;
3239 res = glb_res[i].resource_type;
3242 switch (glb_res[i].resource_func) {
3243 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3244 res_info = &sparms.session_info.ident[dir].info[res];
3246 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3248 * Tables may have various strides for the allocations.
3251 memset(&iparms, 0, sizeof(iparms));
3254 rc = tf_get_shared_tbl_increment(tfp, &iparms);
3257 "Failed to get addend for %s[%s] rc=(%d)\n",
3258 tf_tbl_type_2_str(res),
3259 tf_dir_2_str(dir), rc);
3262 addend = iparms.increment_cnt;
3263 res_info = &sparms.session_info.tbl[dir].info[res];
3265 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3266 res_info = &sparms.session_info.tcam[dir].info[res];
3268 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3269 res_info = &sparms.session_info.em[dir].info[res];
3272 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
3273 glb_res[i].resource_func);
3276 regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
3277 res_info->start += addend;
3279 * All resources written to the global regfile are shared for
3282 rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
3292 * Common conditional opcode process routine that is used for both the template
3293 * rejection and table conditional execution.
3296 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
3297 enum bnxt_ulp_cond_opc opc,
3301 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
3307 case BNXT_ULP_COND_OPC_CF_IS_SET:
3308 if (operand < BNXT_ULP_CF_IDX_LAST) {
3309 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
3311 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3316 case BNXT_ULP_COND_OPC_CF_NOT_SET:
3317 if (operand < BNXT_ULP_CF_IDX_LAST) {
3318 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
3320 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3325 case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
3326 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3327 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3330 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3335 case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
3336 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3337 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3340 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3345 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
3346 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3347 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3350 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3355 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
3356 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3357 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3360 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3365 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
3366 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3368 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3372 *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3374 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
3375 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3377 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3381 *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3383 case BNXT_ULP_COND_OPC_RF_IS_SET:
3384 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3385 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3390 case BNXT_ULP_COND_OPC_RF_NOT_SET:
3391 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3392 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3397 case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
3398 *res = parms->flow_pattern_id == operand;
3400 case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
3401 *res = parms->act_pattern_id == operand;
3403 case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
3404 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3405 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3408 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
3410 case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
3411 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3412 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3415 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
3417 case BNXT_ULP_COND_OPC_ENC_HDR_BIT_IS_SET:
3418 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3419 *res = ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
3422 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3427 case BNXT_ULP_COND_OPC_ENC_HDR_BIT_NOT_SET:
3428 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3429 *res = !ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
3432 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3438 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
3446 ulp_mapper_func_opr_compute(struct bnxt_ulp_mapper_parms *parms,
3448 enum bnxt_ulp_func_src func_src,
3457 case BNXT_ULP_FUNC_SRC_COMP_FIELD:
3458 if (func_opr >= BNXT_ULP_CF_IDX_LAST) {
3459 BNXT_TF_DBG(ERR, "invalid index %u\n", func_opr);
3462 *result = ULP_COMP_FLD_IDX_RD(parms, func_opr);
3464 case BNXT_ULP_FUNC_SRC_REGFILE:
3465 if (!ulp_regfile_read(parms->regfile, func_opr, ®val)) {
3466 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", func_opr);
3469 *result = tfp_be_to_cpu_64(regval);
3471 case BNXT_ULP_FUNC_SRC_GLB_REGFILE:
3472 if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
3473 func_opr, ®val, &shared)) {
3474 BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
3478 *result = tfp_be_to_cpu_64(regval);
3480 case BNXT_ULP_FUNC_SRC_CONST:
3484 BNXT_TF_DBG(ERR, "invalid src code %u\n", func_src);
3491 ulp_mapper_func_info_process(struct bnxt_ulp_mapper_parms *parms,
3492 struct bnxt_ulp_mapper_tbl_info *tbl)
3494 struct bnxt_ulp_mapper_func_info *func_info = &tbl->func_info;
3495 uint64_t res = 0, res1 = 0, res2 = 0;
3497 uint32_t process_src1 = 0, process_src2 = 0;
3499 /* determine which functional operands to compute */
3500 switch (func_info->func_opc) {
3501 case BNXT_ULP_FUNC_OPC_NOP:
3503 case BNXT_ULP_FUNC_OPC_EQ:
3504 case BNXT_ULP_FUNC_OPC_NE:
3505 case BNXT_ULP_FUNC_OPC_GE:
3506 case BNXT_ULP_FUNC_OPC_GT:
3507 case BNXT_ULP_FUNC_OPC_LE:
3508 case BNXT_ULP_FUNC_OPC_LT:
3512 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3520 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3521 func_info->func_src1,
3522 func_info->func_opr1, &res1);
3528 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3529 func_info->func_src2,
3530 func_info->func_opr2, &res2);
3535 /* perform the functional opcode operations */
3536 switch (func_info->func_opc) {
3537 case BNXT_ULP_FUNC_OPC_EQ:
3541 case BNXT_ULP_FUNC_OPC_NE:
3545 case BNXT_ULP_FUNC_OPC_GE:
3549 case BNXT_ULP_FUNC_OPC_GT:
3553 case BNXT_ULP_FUNC_OPC_LE:
3557 case BNXT_ULP_FUNC_OPC_LT:
3561 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3564 case BNXT_ULP_FUNC_OPC_RSS_CONFIG:
3565 /* apply the rss config using pmd method */
3566 return bnxt_rss_config_action_apply(parms);
3567 case BNXT_ULP_FUNC_OPC_GET_PARENT_MAC_ADDR:
3568 rc = bnxt_pmd_get_parent_mac_addr(parms, (uint8_t *)&res);
3571 res = tfp_be_to_cpu_64(res);
3574 BNXT_TF_DBG(ERR, "invalid func code %u\n", func_info->func_opc);
3577 if (ulp_regfile_write(parms->regfile, func_info->func_dst_opr,
3578 tfp_cpu_to_be_64(res))) {
3579 BNXT_TF_DBG(ERR, "Failed write the func_opc %u\n",
3580 func_info->func_dst_opr);
3588 * Processes a list of conditions and returns both a status and result of the
3589 * list. The status must be checked prior to verifying the result.
3591 * returns 0 for success, negative on failure
3592 * returns res = 1 for true, res = 0 for false.
3595 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
3596 enum bnxt_ulp_cond_list_opc list_opc,
3597 struct bnxt_ulp_mapper_cond_info *list,
3602 int32_t rc = 0, trc = 0;
3605 case BNXT_ULP_COND_LIST_OPC_AND:
3606 /* AND Defaults to true. */
3609 case BNXT_ULP_COND_LIST_OPC_OR:
3610 /* OR Defaults to false. */
3613 case BNXT_ULP_COND_LIST_OPC_TRUE:
3616 case BNXT_ULP_COND_LIST_OPC_FALSE:
3620 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
3626 for (i = 0; i < num; i++) {
3627 rc = ulp_mapper_cond_opc_process(parms,
3628 list[i].cond_opcode,
3629 list[i].cond_operand,
3634 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
3635 /* early return if result is ever zero */
3641 /* early return if result is ever non-zero */
3653 * Processes conflict resolution and returns both a status and result.
3654 * The status must be checked prior to verifying the result.
3656 * returns 0 for success, negative on failure
3657 * returns res = 1 for true, res = 0 for false.
3660 ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
3661 struct bnxt_ulp_mapper_tbl_info *tbl,
3669 switch (tbl->accept_opcode) {
3670 case BNXT_ULP_ACCEPT_OPC_ALWAYS:
3673 case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
3674 /* perform the signature validation*/
3675 if (tbl->resource_func ==
3676 BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
3677 /* Perform the check that generic table is hit or not */
3678 if (!ulp_regfile_read(parms->regfile,
3679 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3681 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3682 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3686 /* not a hit so no need to check flow sign*/
3691 /* compare the new flow signature against stored one */
3692 if (!ulp_regfile_read(parms->regfile,
3693 BNXT_ULP_RF_IDX_FLOW_SIG_ID,
3695 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3696 BNXT_ULP_RF_IDX_FLOW_SIG_ID);
3699 comp_sig = ULP_COMP_FLD_IDX_RD(parms,
3700 BNXT_ULP_CF_IDX_FLOW_SIG_ID);
3701 regval = tfp_be_to_cpu_64(regval);
3702 if (comp_sig == regval)
3705 BNXT_TF_DBG(ERR, "failed signature match 0x%016"
3706 PRIX64 ":%x\n", comp_sig, (uint32_t)regval);
3709 BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
3710 tbl->accept_opcode);
3717 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
3719 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
3720 enum bnxt_ulp_cond_list_opc cond_opc;
3721 struct bnxt_ulp_mapper_tbl_info *tbls;
3722 struct bnxt_ulp_mapper_tbl_info *tbl;
3723 uint32_t num_tbls, tbl_idx, num_cond_tbls;
3724 int32_t rc = -EINVAL, cond_rc = 0;
3725 int32_t cond_goto = 1;
3727 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
3731 * Process the reject list if exists, otherwise assume that the
3732 * template is allowed.
3734 if (cond_tbls && num_cond_tbls) {
3735 rc = ulp_mapper_cond_opc_list_process(parms,
3743 /* Reject the template if True */
3745 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
3746 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3752 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
3753 if (!tbls || !num_tbls) {
3754 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
3755 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3756 parms->dev_id, tid);
3760 for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
3761 tbl = &tbls[tbl_idx];
3762 cond_goto = tbl->execute_info.cond_true_goto;
3763 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
3764 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
3765 ulp_mapper_table_dump(tbl, tbl_idx);
3768 /* Process the conditional func code opcodes */
3769 if (ulp_mapper_func_info_process(parms, tbl)) {
3770 BNXT_TF_DBG(ERR, "Failed to process cond update\n");
3775 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
3778 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
3779 cond_tbls, num_cond_tbls,
3782 BNXT_TF_DBG(ERR, "Failed to proc cond opc list (%d)\n",
3786 /* Skip the table if False */
3788 cond_goto = tbl->execute_info.cond_false_goto;
3789 goto next_iteration;
3792 switch (tbl->resource_func) {
3793 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3794 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
3796 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3797 rc = ulp_mapper_em_tbl_process(parms, tbl);
3799 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3800 rc = ulp_mapper_index_tbl_process(parms, tbl);
3802 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
3803 rc = ulp_mapper_if_tbl_process(parms, tbl);
3805 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3806 rc = ulp_mapper_gen_tbl_process(parms, tbl);
3808 case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
3809 rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
3811 case BNXT_ULP_RESOURCE_FUNC_INVALID:
3815 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
3816 tbl->resource_func);
3822 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
3823 tbl->resource_func);
3827 /* perform the post table process */
3828 rc = ulp_mapper_conflict_resolution_process(parms, tbl,
3830 if (rc || !cond_rc) {
3831 BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
3836 if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
3837 BNXT_TF_DBG(ERR, "reject the flow\n");
3840 } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
3844 /* least significant 16 bits from reg_file index */
3845 rf_idx = (uint32_t)(cond_goto & 0xFFFF);
3846 if (!ulp_regfile_read(parms->regfile, rf_idx,
3848 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3853 cond_goto = (int32_t)regval;
3856 if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
3857 BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
3861 tbl_idx += cond_goto;
3866 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
3867 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3868 parms->dev_id, tid);
3873 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
3875 struct ulp_flow_db_res_params *res)
3881 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
3884 if (res->fdb_flags & ULP_FDB_FLAG_SHARED_SESSION)
3885 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_YES);
3887 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_NO);
3889 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
3893 switch (res->resource_func) {
3894 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3895 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
3897 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3898 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
3900 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3901 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
3903 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3904 rc = ulp_mapper_ident_free(ulp, tfp, res);
3906 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
3907 rc = ulp_mapper_mark_free(ulp, res);
3909 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
3910 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
3912 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
3913 rc = ulp_mapper_child_flow_free(ulp, fid, res);
3915 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3916 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
3926 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
3927 enum bnxt_ulp_fdb_type flow_type,
3930 struct ulp_flow_db_res_params res_parms = { 0 };
3934 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3939 * Set the critical resource on the first resource del, then iterate
3940 * while status is good
3942 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
3944 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
3948 * This is unexpected on the first call to resource del.
3949 * It likely means that the flow did not exist in the flow db.
3951 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
3952 flow_type, fid, rc);
3957 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
3960 * On fail, we still need to attempt to free the
3961 * remaining resources. Don't return
3964 "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
3965 "] failed rc=%d.\n",
3966 flow_type, fid, res_parms.resource_func,
3967 res_parms.resource_hndl, trc);
3969 /* All subsequent call require the non-critical_resource */
3970 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
3972 rc = ulp_flow_db_resource_del(ulp_ctx,
3978 /* Free the Flow ID since we've removed all resources */
3979 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
3985 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
3986 struct bnxt_ulp_mapper_data *mapper_data)
3988 struct bnxt_ulp_mapper_glb_resource_entry *ent;
3989 struct ulp_flow_db_res_params res;
3992 /* Iterate the global resources and process each one */
3993 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
3994 for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
3995 ent = &mapper_data->glb_res_tbl[dir][idx];
3996 if (ent->resource_func ==
3997 BNXT_ULP_RESOURCE_FUNC_INVALID ||
4000 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
4001 res.resource_func = ent->resource_func;
4002 res.direction = dir;
4003 res.resource_type = ent->resource_type;
4004 /*convert it from BE to cpu */
4006 tfp_be_to_cpu_64(ent->resource_hndl);
4007 ulp_mapper_resource_free(ulp_ctx, 0, &res);
4013 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
4014 enum bnxt_ulp_fdb_type flow_type,
4020 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
4024 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
4028 /* Function to handle the mapping of the Flow to be compatible
4029 * with the underlying hardware.
4032 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
4033 struct bnxt_ulp_mapper_create_parms *cparms)
4035 struct bnxt_ulp_mapper_parms parms;
4036 struct ulp_regfile regfile;
4037 int32_t rc = 0, trc;
4039 if (!ulp_ctx || !cparms)
4042 /* Initialize the parms structure */
4043 memset(&parms, 0, sizeof(parms));
4044 parms.act_prop = cparms->act_prop;
4045 parms.act_bitmap = cparms->act;
4046 parms.hdr_bitmap = cparms->hdr_bitmap;
4047 parms.enc_hdr_bitmap = cparms->enc_hdr_bitmap;
4048 parms.regfile = ®file;
4049 parms.hdr_field = cparms->hdr_field;
4050 parms.enc_field = cparms->enc_field;
4051 parms.fld_bitmap = cparms->fld_bitmap;
4052 parms.comp_fld = cparms->comp_fld;
4053 parms.ulp_ctx = ulp_ctx;
4054 parms.act_tid = cparms->act_tid;
4055 parms.class_tid = cparms->class_tid;
4056 parms.flow_type = cparms->flow_type;
4057 parms.parent_flow = cparms->parent_flow;
4058 parms.child_flow = cparms->child_flow;
4059 parms.fid = cparms->flow_id;
4060 parms.tun_idx = cparms->tun_idx;
4061 parms.app_priority = cparms->app_priority;
4062 parms.flow_pattern_id = cparms->flow_pattern_id;
4063 parms.act_pattern_id = cparms->act_pattern_id;
4064 parms.app_id = cparms->app_id;
4065 parms.port_id = cparms->port_id;
4067 /* Get the device id from the ulp context */
4068 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
4069 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
4073 /* Get the device params, it will be used in later processing */
4074 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
4075 if (!parms.device_params) {
4076 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
4082 * Get the mapper data for dynamic mapper data such as default
4085 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
4086 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
4087 if (!parms.mapper_data) {
4088 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
4092 /* initialize the registry file for further processing */
4093 if (!ulp_regfile_init(parms.regfile)) {
4094 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
4098 /* Process the action template list from the selected action table*/
4099 if (parms.act_tid) {
4100 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
4101 /* Process the action template tables */
4102 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
4105 cparms->shared_hndl = parms.shared_hndl;
4108 if (parms.class_tid) {
4109 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
4111 /* Process the class template tables.*/
4112 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
4117 /* setup the parent-child details */
4118 if (parms.parent_flow) {
4119 /* create a parent flow details */
4120 rc = ulp_flow_db_parent_flow_create(&parms);
4123 } else if (parms.child_flow) {
4124 /* create a child flow details */
4125 rc = ulp_flow_db_child_flow_create(&parms);
4133 /* Free all resources that were allocated during flow creation */
4134 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
4137 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
4143 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
4145 struct bnxt_ulp_mapper_data *data;
4152 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
4156 data = rte_zmalloc("ulp_mapper_data",
4157 sizeof(struct bnxt_ulp_mapper_data), 0);
4159 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
4163 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
4164 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
4165 /* Don't call deinit since the prof_func wasn't allocated. */
4170 /* Allocate the global resource ids */
4171 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
4173 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
4178 * Only initialize the app global resources if a shared session was
4181 if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
4182 rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
4184 BNXT_TF_DBG(ERR, "Failed to init app glb resources\n");
4189 /* Allocate the generic table list */
4190 rc = ulp_mapper_generic_tbl_list_init(data);
4192 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
4198 /* Ignore the return code in favor of returning the original error. */
4199 ulp_mapper_deinit(ulp_ctx);
4204 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
4206 struct bnxt_ulp_mapper_data *data;
4211 "Failed to acquire ulp context, so data may not be released.\n");
4215 data = (struct bnxt_ulp_mapper_data *)
4216 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
4218 /* Go ahead and return since there is no allocated data. */
4219 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
4223 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
4225 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
4226 /* Free the mapper data regardless of errors. */
4227 goto free_mapper_data;
4230 /* Free the global resource info table entries */
4231 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
4234 /* Free the generic table */
4235 (void)ulp_mapper_generic_tbl_list_deinit(data);
4238 /* Reset the data pointer within the ulp_ctx. */
4239 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);