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 inline int32_t
442 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp,
444 struct ulp_flow_db_res_params *res)
446 struct tf_free_tcam_entry_parms fparms = {
447 .dir = res->direction,
448 .tcam_tbl_type = res->resource_type,
449 .idx = (uint16_t)res->resource_hndl
452 /* If HA is enabled, we may have to remap the TF Type */
453 if (bnxt_ulp_cntxt_ha_enabled(ulp)) {
454 enum ulp_ha_mgr_region region;
457 switch (res->resource_type) {
458 case TF_TCAM_TBL_TYPE_WC_TCAM_HIGH:
459 case TF_TCAM_TBL_TYPE_WC_TCAM_LOW:
460 rc = ulp_ha_mgr_region_get(ulp, ®ion);
462 /* Log this, but assume region is correct */
464 "Unable to get HA region (%d)\n",
467 fparms.tcam_tbl_type =
468 (region == ULP_HA_REGION_LOW) ?
469 TF_TCAM_TBL_TYPE_WC_TCAM_LOW :
470 TF_TCAM_TBL_TYPE_WC_TCAM_HIGH;
476 return tf_free_tcam_entry(tfp, &fparms);
479 static inline int32_t
480 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
482 struct ulp_flow_db_res_params *res)
484 struct tf_free_tbl_entry_parms fparms = {
485 .dir = res->direction,
486 .type = res->resource_type,
487 .idx = (uint32_t)res->resource_hndl
491 * Just get the table scope, it will be ignored if not necessary
492 * by the tf_free_tbl_entry
494 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
496 return tf_free_tbl_entry(tfp, &fparms);
499 static inline int32_t
500 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
502 struct ulp_flow_db_res_params *res)
504 struct tf_delete_em_entry_parms fparms = { 0 };
507 fparms.dir = res->direction;
508 fparms.flow_handle = res->resource_hndl;
510 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
512 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
516 return tf_delete_em_entry(tfp, &fparms);
519 static inline int32_t
520 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
522 struct ulp_flow_db_res_params *res)
524 struct tf_free_identifier_parms fparms = {
525 .dir = res->direction,
526 .ident_type = res->resource_type,
527 .id = (uint16_t)res->resource_hndl
530 return tf_free_identifier(tfp, &fparms);
533 static inline int32_t
534 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
535 struct ulp_flow_db_res_params *res)
537 return ulp_mark_db_mark_del(ulp,
542 static inline int32_t
543 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
545 struct ulp_flow_db_res_params *res)
549 pc_idx = (uint32_t)res->resource_hndl;
551 /* reset the child flow bitset*/
552 if (ulp_flow_db_pc_db_parent_flow_set(ulp, pc_idx, parent_fid, 0)) {
553 BNXT_TF_DBG(ERR, "error in reset parent flow bitset %x:%x\n",
560 static inline int32_t
561 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
563 struct ulp_flow_db_res_params *res)
567 pc_idx = (uint32_t)res->resource_hndl;
569 /* reset the child flow bitset*/
570 if (ulp_flow_db_pc_db_child_flow_set(ulp, pc_idx, child_fid, 0)) {
571 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
579 * Process the flow database opcode alloc action.
580 * returns 0 on success
583 ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
584 struct bnxt_ulp_mapper_tbl_info *tbl)
590 /* allocate a new fid */
591 rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
592 BNXT_ULP_FDB_TYPE_RID,
596 "Unable to allocate flow table entry\n");
599 /* Store the allocated fid in regfile*/
601 rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
602 tfp_cpu_to_be_64(val64));
604 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
606 ulp_flow_db_fid_free(parms->ulp_ctx,
607 BNXT_ULP_FDB_TYPE_RID, rid);
614 * Process the flow database opcode action.
615 * returns 0 on success.
618 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
619 struct bnxt_ulp_mapper_tbl_info *tbl,
620 struct ulp_flow_db_res_params *fid_parms)
624 enum bnxt_ulp_fdb_type flow_type;
627 switch (tbl->fdb_opcode) {
628 case BNXT_ULP_FDB_OPC_PUSH_FID:
629 push_fid = parms->fid;
630 flow_type = parms->flow_type;
632 case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
633 /* get the fid from the regfile */
634 rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
637 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
641 /* Use the extracted fid to update the flow resource */
642 push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
643 flow_type = BNXT_ULP_FDB_TYPE_RID;
646 return rc; /* Nothing to be done */
649 /* Add the resource to the flow database */
650 rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
651 push_fid, fid_parms);
653 BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
659 * Process the flow database opcode action.
660 * returns 0 on success.
663 ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms,
664 struct bnxt_ulp_mapper_tbl_info *tbl,
669 switch (tbl->pri_opcode) {
670 case BNXT_ULP_PRI_OPC_NOT_USED:
673 case BNXT_ULP_PRI_OPC_CONST:
674 *priority = tbl->pri_operand;
676 case BNXT_ULP_PRI_OPC_APP_PRI:
677 *priority = parms->app_priority;
680 BNXT_TF_DBG(ERR, "Priority opcode not supported %d\n",
689 * Process the identifier list in the given table.
690 * Extract the ident from the table entry and
691 * write it to the reg file.
692 * returns 0 on success.
695 ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
696 struct bnxt_ulp_mapper_tbl_info *tbl,
698 uint32_t byte_data_size,
699 enum bnxt_ulp_byte_order byte_order)
701 struct bnxt_ulp_mapper_ident_info *idents;
702 uint32_t i, num_idents = 0;
705 /* validate the null arguments */
707 BNXT_TF_DBG(ERR, "invalid argument\n");
711 /* Get the ident list and process each one */
712 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
714 for (i = 0; i < num_idents; i++) {
715 /* check the size of the buffer for validation */
716 if ((idents[i].ident_bit_pos + idents[i].ident_bit_size) >
717 ULP_BYTE_2_BITS(byte_data_size) ||
718 idents[i].ident_bit_size > ULP_BYTE_2_BITS(sizeof(val64))) {
719 BNXT_TF_DBG(ERR, "invalid offset or length %x:%x:%x\n",
720 idents[i].ident_bit_pos,
721 idents[i].ident_bit_size,
726 if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
727 ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
729 idents[i].ident_bit_pos,
730 idents[i].ident_bit_size);
732 ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
733 idents[i].ident_bit_pos,
734 idents[i].ident_bit_size);
736 /* Write it to the regfile, val64 is already in big-endian*/
737 if (ulp_regfile_write(parms->regfile,
738 idents[i].regfile_idx, val64)) {
739 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
740 idents[i].regfile_idx);
748 * Process the identifier instruction and either store it in the flow database
749 * or return it in the val (if not NULL) on success. If val is NULL, the
750 * identifier is to be stored in the flow database.
753 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
754 struct bnxt_ulp_mapper_tbl_info *tbl,
755 struct bnxt_ulp_mapper_ident_info *ident,
758 struct ulp_flow_db_res_params fid_parms;
761 struct tf_alloc_identifier_parms iparms = { 0 };
762 struct tf_free_identifier_parms free_parms = { 0 };
766 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
768 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
772 idx = ident->regfile_idx;
774 iparms.ident_type = ident->ident_type;
775 iparms.dir = tbl->direction;
777 rc = tf_alloc_identifier(tfp, &iparms);
779 BNXT_TF_DBG(ERR, "Alloc ident %s:%s failed.\n",
780 tf_dir_2_str(iparms.dir),
781 tf_ident_2_str(iparms.ident_type));
784 BNXT_TF_INF("Alloc ident %s:%s.success.\n",
785 tf_dir_2_str(iparms.dir),
786 tf_ident_2_str(iparms.ident_type));
788 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
789 if (ulp_regfile_write(parms->regfile, idx, id)) {
790 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
792 /* Need to free the identifier, so goto error */
796 /* Link the resource to the flow in the flow db */
798 memset(&fid_parms, 0, sizeof(fid_parms));
799 fid_parms.direction = tbl->direction;
800 fid_parms.resource_func = ident->resource_func;
801 fid_parms.resource_type = ident->ident_type;
802 fid_parms.resource_hndl = iparms.id;
803 fid_parms.critical_resource = tbl->critical_resource;
804 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
806 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
808 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
810 /* Need to free the identifier, so goto error */
816 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
817 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
818 ulp_mapper_ident_field_dump("Ident", ident, tbl, iparms.id);
824 /* Need to free the identifier */
825 free_parms.dir = tbl->direction;
826 free_parms.ident_type = ident->ident_type;
827 free_parms.id = iparms.id;
829 (void)tf_free_identifier(tfp, &free_parms);
831 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
833 tf_dir_2_str(tbl->direction));
838 * Process the identifier instruction and extract it from result blob.
839 * Increment the identifier reference count and store it in the flow database.
842 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
843 struct bnxt_ulp_mapper_tbl_info *tbl,
844 struct bnxt_ulp_mapper_ident_info *ident,
845 struct ulp_blob *res_blob)
847 struct ulp_flow_db_res_params fid_parms;
850 struct tf_search_identifier_parms sparms = { 0 };
851 struct tf_free_identifier_parms free_parms = { 0 };
855 /* Get the tfp from ulp context */
856 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
858 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
862 /* Extract the index from the result blob */
863 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
864 ident->ident_bit_pos, ident->ident_bit_size);
866 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
870 /* populate the search params and search identifier shadow table */
871 sparms.ident_type = ident->ident_type;
872 sparms.dir = tbl->direction;
873 /* convert the idx into cpu format */
874 sparms.search_id = tfp_be_to_cpu_32(idx);
876 /* Search identifier also increase the reference count */
877 rc = tf_search_identifier(tfp, &sparms);
879 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
880 tf_dir_2_str(sparms.dir),
881 tf_ident_2_str(sparms.ident_type),
885 BNXT_TF_INF("Search ident %s:%s:%x.success.\n",
886 tf_dir_2_str(sparms.dir),
887 tf_tbl_type_2_str(sparms.ident_type),
890 /* Write it to the regfile */
891 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
892 if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
893 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
895 /* Need to free the identifier, so goto error */
899 /* Link the resource to the flow in the flow db */
900 memset(&fid_parms, 0, sizeof(fid_parms));
901 fid_parms.direction = tbl->direction;
902 fid_parms.resource_func = ident->resource_func;
903 fid_parms.resource_type = ident->ident_type;
904 fid_parms.resource_hndl = sparms.search_id;
905 fid_parms.critical_resource = tbl->critical_resource;
906 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
908 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
910 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
912 /* Need to free the identifier, so goto error */
916 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
917 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
918 ulp_mapper_ident_field_dump("Ident", ident, tbl, sparms.search_id);
924 /* Need to free the identifier */
925 free_parms.dir = tbl->direction;
926 free_parms.ident_type = ident->ident_type;
927 free_parms.id = sparms.search_id;
928 (void)tf_free_identifier(tfp, &free_parms);
929 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
931 tf_dir_2_str(tbl->direction), sparms.search_id);
936 ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
941 enum bnxt_ulp_port_table port_data = val16;
944 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
945 if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
947 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
951 case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
952 if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
954 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
958 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
959 if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
961 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
966 BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
973 ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
974 enum bnxt_ulp_field_src field_src,
983 struct bnxt_ulp_mapper_data *m;
985 uint32_t port_id, val_size, field_size;
986 uint16_t idx, size_idx, offset;
987 uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
994 /* Perform the action */
996 case BNXT_ULP_FIELD_SRC_ZERO:
997 *val = mapper_fld_zeros;
999 case BNXT_ULP_FIELD_SRC_CONST:
1002 case BNXT_ULP_FIELD_SRC_ONES:
1003 *val = mapper_fld_ones;
1006 case BNXT_ULP_FIELD_SRC_CF:
1007 if (!ulp_operand_read(field_opr,
1008 (uint8_t *)&idx, sizeof(uint16_t))) {
1009 BNXT_TF_DBG(ERR, "CF operand read failed\n");
1012 idx = tfp_be_to_cpu_16(idx);
1013 if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t)) {
1014 BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
1018 buffer = (uint8_t *)&parms->comp_fld[idx];
1019 *val = &buffer[sizeof(uint64_t) - bytelen];
1020 *value = ULP_COMP_FLD_IDX_RD(parms, idx);
1022 case BNXT_ULP_FIELD_SRC_RF:
1023 if (!ulp_operand_read(field_opr,
1024 (uint8_t *)&idx, sizeof(uint16_t))) {
1025 BNXT_TF_DBG(ERR, "RF operand read failed\n");
1029 idx = tfp_be_to_cpu_16(idx);
1030 /* Uninitialized regfile entries return 0 */
1031 if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
1032 sizeof(uint64_t) < bytelen) {
1033 BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
1037 buffer = (uint8_t *)&parms->regfile->entry[idx].data;
1038 *val = &buffer[sizeof(uint64_t) - bytelen];
1039 *value = tfp_be_to_cpu_64(lregval);
1041 case BNXT_ULP_FIELD_SRC_ACT_PROP:
1042 if (!ulp_operand_read(field_opr,
1043 (uint8_t *)&idx, sizeof(uint16_t))) {
1044 BNXT_TF_DBG(ERR, "Action operand read failed\n");
1047 idx = tfp_be_to_cpu_16(idx);
1048 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1049 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
1052 buffer = &parms->act_prop->act_details[idx];
1053 field_size = ulp_mapper_act_prop_size_get(idx);
1054 if (bytelen > field_size) {
1055 BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
1059 *val = &buffer[field_size - bytelen];
1061 case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
1062 if (!ulp_operand_read(field_opr,
1063 (uint8_t *)&idx, sizeof(uint16_t))) {
1064 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1067 idx = tfp_be_to_cpu_16(idx);
1069 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1070 BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
1073 *val = &parms->act_prop->act_details[idx];
1075 /* get the size index next */
1076 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1077 (uint8_t *)&size_idx, sizeof(uint16_t))) {
1078 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1081 size_idx = tfp_be_to_cpu_16(size_idx);
1082 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1083 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
1086 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
1088 val_size = tfp_be_to_cpu_32(val_size);
1089 *val_len = ULP_BYTE_2_BITS(val_size);
1091 case BNXT_ULP_FIELD_SRC_GLB_RF:
1092 if (!ulp_operand_read(field_opr,
1093 (uint8_t *)&idx, sizeof(uint16_t))) {
1094 BNXT_TF_DBG(ERR, "Global regfile read failed\n");
1097 idx = tfp_be_to_cpu_16(idx);
1098 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1099 dir, idx, &lregval, &shared) ||
1100 sizeof(uint64_t) < bytelen) {
1101 BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
1105 m = parms->mapper_data;
1106 buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
1107 *val = &buffer[sizeof(uint64_t) - bytelen];
1108 *value = tfp_be_to_cpu_64(lregval);
1110 case BNXT_ULP_FIELD_SRC_HF:
1111 case BNXT_ULP_FIELD_SRC_SUB_HF:
1112 if (!ulp_operand_read(field_opr,
1113 (uint8_t *)&idx, sizeof(uint16_t))) {
1114 BNXT_TF_DBG(ERR, "Header field read failed\n");
1117 idx = tfp_be_to_cpu_16(idx);
1118 /* get the index from the global field list */
1119 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1120 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1125 buffer = parms->hdr_field[bit].spec;
1127 buffer = parms->hdr_field[bit].mask;
1129 field_size = parms->hdr_field[bit].size;
1130 if (bytelen > field_size) {
1131 BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
1135 if (field_src == BNXT_ULP_FIELD_SRC_HF) {
1136 *val = &buffer[field_size - bytelen];
1138 /* get the offset next */
1139 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1141 sizeof(uint16_t))) {
1142 BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
1145 offset = tfp_be_to_cpu_16(offset);
1146 offset = ULP_BITS_2_BYTE_NR(offset);
1147 if ((offset + bytelen) > field_size) {
1148 BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
1151 *val = &buffer[offset];
1154 case BNXT_ULP_FIELD_SRC_HDR_BIT:
1155 if (!ulp_operand_read(field_opr,
1156 (uint8_t *)&lregval, sizeof(uint64_t))) {
1157 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1160 lregval = tfp_be_to_cpu_64(lregval);
1161 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
1162 *val = mapper_fld_one;
1165 *val = mapper_fld_zeros;
1168 case BNXT_ULP_FIELD_SRC_ACT_BIT:
1169 if (!ulp_operand_read(field_opr,
1170 (uint8_t *)&lregval, sizeof(uint64_t))) {
1171 BNXT_TF_DBG(ERR, "Action bit read failed\n");
1174 lregval = tfp_be_to_cpu_64(lregval);
1175 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
1176 *val = mapper_fld_one;
1179 *val = mapper_fld_zeros;
1182 case BNXT_ULP_FIELD_SRC_FIELD_BIT:
1183 if (!ulp_operand_read(field_opr,
1184 (uint8_t *)&idx, sizeof(uint16_t))) {
1185 BNXT_TF_DBG(ERR, "Field bit 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",
1195 if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
1196 *val = mapper_fld_one;
1199 *val = mapper_fld_zeros;
1202 case BNXT_ULP_FIELD_SRC_PORT_TABLE:
1203 /* The port id is present in the comp field list */
1204 port_id = ULP_COMP_FLD_IDX_RD(parms,
1205 BNXT_ULP_CF_IDX_DEV_PORT_ID);
1206 /* get the port table enum */
1207 if (!ulp_operand_read(field_opr,
1208 (uint8_t *)&idx, sizeof(uint16_t))) {
1209 BNXT_TF_DBG(ERR, "Port table enum read failed\n");
1212 idx = tfp_be_to_cpu_16(idx);
1213 if (ulp_mapper_field_port_db_process(parms, port_id, idx,
1215 BNXT_TF_DBG(ERR, "field port table failed\n");
1219 case BNXT_ULP_FIELD_SRC_ENC_HDR_BIT:
1220 if (!ulp_operand_read(field_opr,
1221 (uint8_t *)&lregval, sizeof(uint64_t))) {
1222 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1225 lregval = tfp_be_to_cpu_64(lregval);
1226 if (ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits, lregval)) {
1227 *val = mapper_fld_one;
1230 *val = mapper_fld_zeros;
1233 case BNXT_ULP_FIELD_SRC_ENC_FIELD:
1234 if (!ulp_operand_read(field_opr,
1235 (uint8_t *)&idx, sizeof(uint16_t))) {
1236 BNXT_TF_DBG(ERR, "Header field read failed\n");
1239 idx = tfp_be_to_cpu_16(idx);
1240 /* get the index from the global field list */
1241 if (idx >= BNXT_ULP_ENC_FIELD_LAST) {
1242 BNXT_TF_DBG(ERR, "invalid encap field tbl idx %d\n",
1246 buffer = parms->enc_field[idx].spec;
1247 field_size = parms->enc_field[idx].size;
1248 if (bytelen > field_size) {
1249 BNXT_TF_DBG(ERR, "Encap field[%d] size small %u\n",
1253 *val = &buffer[field_size - bytelen];
1255 case BNXT_ULP_FIELD_SRC_SKIP:
1257 *val = mapper_fld_zeros;
1260 case BNXT_ULP_FIELD_SRC_REJECT:
1263 BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
1269 static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
1277 bytelen = ULP_BITS_2_BYTE(bitlen);
1278 if (bytelen == sizeof(uint8_t)) {
1279 *output = *((uint8_t *)buffer);
1280 } else if (bytelen == sizeof(uint16_t)) {
1281 val_16 = *((uint16_t *)buffer);
1282 *output = tfp_be_to_cpu_16(val_16);
1283 } else if (bytelen == sizeof(uint32_t)) {
1284 val_32 = *((uint32_t *)buffer);
1285 *output = tfp_be_to_cpu_32(val_32);
1286 } else if (bytelen == sizeof(val_64)) {
1287 val_64 = *((uint64_t *)buffer);
1288 *output = tfp_be_to_cpu_64(val_64);
1296 static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
1297 struct ulp_blob *blob,
1302 if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
1303 if (ulp_blob_pad_push(blob, val_len) < 0) {
1304 BNXT_TF_DBG(ERR, "too large for blob\n");
1307 } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
1308 if (ulp_blob_push_encap(blob, val, val_len) < 0) {
1309 BNXT_TF_DBG(ERR, "encap blob push failed\n");
1312 } else if (fld_src == BNXT_ULP_FIELD_SRC_SKIP) {
1315 if (!ulp_blob_push(blob, val, val_len)) {
1316 BNXT_TF_DBG(ERR, "push of val1 failed\n");
1325 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
1327 struct bnxt_ulp_mapper_field_info *fld,
1328 struct ulp_blob *blob,
1332 uint16_t write_idx = blob->write_idx;
1333 uint8_t *val = NULL, *val1, *val2, *val3;
1334 uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
1335 uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
1336 uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
1337 uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
1338 uint64_t value1 = 0, value2 = 0, value3 = 0;
1341 /* prepare the field source and values */
1342 switch (fld->field_opc) {
1343 case BNXT_ULP_FIELD_OPC_SRC1:
1346 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1349 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1350 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1358 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1359 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1360 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1361 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1362 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1363 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1373 /* process the src1 opcode */
1375 if (ulp_mapper_field_src_process(parms, fld->field_src1,
1376 fld->field_opr1, dir, is_key,
1377 fld->field_bit_size, &val1,
1378 &val1_len, &value1)) {
1379 BNXT_TF_DBG(ERR, "fld src1 process failed\n");
1383 if (ulp_mapper_field_buffer_eval(val1, val1_len,
1385 BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
1391 /* for "if then clause" set the correct process */
1392 if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
1399 /* process src2 opcode */
1401 if (ulp_mapper_field_src_process(parms, fld->field_src2,
1402 fld->field_opr2, dir, is_key,
1403 fld->field_bit_size, &val2,
1404 &val2_len, &value2)) {
1405 BNXT_TF_DBG(ERR, "fld src2 process failed\n");
1409 if (ulp_mapper_field_buffer_eval(val2, val2_len,
1411 BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
1417 /* process src3 opcode */
1419 if (ulp_mapper_field_src_process(parms, fld->field_src3,
1420 fld->field_opr3, dir, is_key,
1421 fld->field_bit_size, &val3,
1422 &val3_len, &value3)) {
1423 BNXT_TF_DBG(ERR, "fld src3 process failed\n");
1427 if (ulp_mapper_field_buffer_eval(val3, val3_len,
1429 BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
1435 val_len = fld->field_bit_size;
1436 /* process the field opcodes */
1437 switch (fld->field_opc) {
1438 case BNXT_ULP_FIELD_OPC_SRC1:
1439 rc = ulp_mapper_field_blob_write(fld->field_src1,
1440 blob, val1, val1_len, &val);
1443 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1445 rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
1446 val2, val2_len, &val);
1449 rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
1450 val3, val3_len, &val);
1454 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1455 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1456 val_int = val1_int + val2_int;
1457 val_int = tfp_cpu_to_be_64(val_int);
1458 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1462 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1463 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1464 val_int = val1_int - val2_int;
1465 val_int = tfp_cpu_to_be_64(val_int);
1466 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1470 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1471 val_int = val1_int | val2_int;
1472 val_int = tfp_cpu_to_be_64(val_int);
1473 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1477 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1478 val_int = val1_int | val2_int | val3_int;
1479 val_int = tfp_cpu_to_be_64(val_int);
1480 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1484 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1485 val_int = val1_int & val2_int;
1486 val_int = tfp_cpu_to_be_64(val_int);
1487 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1491 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1492 val_int = val1_int & (val2_int | val3_int);
1493 val_int = tfp_cpu_to_be_64(val_int);
1494 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1498 case BNXT_ULP_FIELD_OPC_SKIP:
1501 BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
1507 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1508 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
1509 if (fld->field_src1 != BNXT_ULP_FIELD_SRC_ZERO && val_len)
1510 ulp_mapper_field_dump(name, fld, blob, write_idx, val,
1517 BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
1518 fld->description, (val) ? write_idx : 0, val_len);
1523 * Result table process and fill the result blob.
1524 * data [out] - the result blob data
1527 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
1528 struct bnxt_ulp_mapper_tbl_info *tbl,
1529 struct ulp_blob *data,
1532 struct bnxt_ulp_mapper_field_info *dflds;
1533 uint32_t i = 0, num_flds = 0, encap_flds = 0;
1534 struct ulp_blob encap_blob;
1537 /* Get the result field list */
1538 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
1541 /* validate the result field list counts */
1542 if ((tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1543 (!num_flds && !encap_flds)) || !dflds ||
1544 (tbl->resource_func != BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1545 (!num_flds || encap_flds))) {
1546 BNXT_TF_DBG(ERR, "Failed to get data fields %x:%x\n",
1547 num_flds, encap_flds);
1551 /* process the result fields */
1552 for (i = 0; i < num_flds; i++) {
1553 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1554 &dflds[i], data, 0, name);
1556 BNXT_TF_DBG(ERR, "result field processing failed\n");
1561 /* process encap fields if any */
1564 /* Initialize the encap blob */
1565 if (!tbl->record_size) {
1566 BNXT_TF_DBG(ERR, "Encap tbl record size incorrect\n");
1569 if (!ulp_blob_init(&encap_blob,
1570 ULP_BYTE_2_BITS(tbl->record_size),
1571 parms->device_params->encap_byte_order)) {
1572 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1575 for (; i < encap_flds; i++) {
1576 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1578 &encap_blob, 0, name);
1581 "encap field processing failed\n");
1585 /* add the dynamic pad push */
1586 pad = ULP_BYTE_2_BITS(tbl->record_size) -
1587 ulp_blob_data_len_get(&encap_blob);
1588 ulp_blob_pad_push(&encap_blob, pad);
1590 /* perform the 64 bit byte swap */
1591 ulp_blob_perform_64B_byte_swap(&encap_blob);
1592 /* Append encap blob to the result blob */
1593 rc = ulp_blob_buffer_copy(data, &encap_blob);
1595 BNXT_TF_DBG(ERR, "encap buffer copy failed\n");
1599 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1600 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
1601 BNXT_TF_DBG(DEBUG, "Result dump\n");
1602 ulp_mapper_blob_dump(data);
1609 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1610 struct bnxt_ulp_mapper_tbl_info *tbl,
1613 struct ulp_flow_db_res_params fid_parms;
1614 uint32_t mark, gfid, mark_flag;
1615 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1618 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1619 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1620 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1621 BNXT_ULP_ACT_BIT_MARK)))
1622 return rc; /* no need to perform gfid process */
1624 /* Get the mark id details from action property */
1625 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1627 mark = tfp_be_to_cpu_32(mark);
1629 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1630 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1632 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1635 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1638 fid_parms.direction = tbl->direction;
1639 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1640 fid_parms.critical_resource = tbl->critical_resource;
1641 fid_parms.resource_type = mark_flag;
1642 fid_parms.resource_hndl = gfid;
1643 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1645 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1647 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1652 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1653 struct bnxt_ulp_mapper_tbl_info *tbl)
1655 struct ulp_flow_db_res_params fid_parms;
1656 uint32_t act_idx, mark, mark_flag;
1658 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1661 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1662 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1663 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1664 BNXT_ULP_ACT_BIT_MARK)))
1665 return rc; /* no need to perform mark action process */
1667 /* Get the mark id details from action property */
1668 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1670 mark = tfp_be_to_cpu_32(mark);
1672 if (!ulp_regfile_read(parms->regfile,
1673 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1675 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1678 act_idx = tfp_be_to_cpu_64(val64);
1679 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1680 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1683 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1686 fid_parms.direction = tbl->direction;
1687 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1688 fid_parms.critical_resource = tbl->critical_resource;
1689 fid_parms.resource_type = mark_flag;
1690 fid_parms.resource_hndl = act_idx;
1691 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1693 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1695 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1700 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1701 struct bnxt_ulp_mapper_tbl_info *tbl)
1703 struct ulp_flow_db_res_params fid_parms;
1704 uint32_t act_idx, mark, mark_flag;
1706 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1709 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1710 mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
1711 return rc; /* no need to perform mark action process */
1713 /* Get the mark id details from the computed field of dev port id */
1714 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1716 /* Get the main action pointer */
1717 if (!ulp_regfile_read(parms->regfile,
1718 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1720 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1723 act_idx = tfp_be_to_cpu_64(val64);
1725 /* Set the mark flag to local fid and vfr flag */
1726 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1728 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1731 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1734 fid_parms.direction = tbl->direction;
1735 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1736 fid_parms.critical_resource = tbl->critical_resource;
1737 fid_parms.resource_type = mark_flag;
1738 fid_parms.resource_hndl = act_idx;
1739 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1741 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1743 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1747 /* Tcam table scan the identifier list and allocate each identifier */
1749 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1750 struct bnxt_ulp_mapper_tbl_info *tbl)
1752 struct bnxt_ulp_mapper_ident_info *idents;
1753 uint32_t num_idents;
1756 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1757 for (i = 0; i < num_idents; i++) {
1758 if (ulp_mapper_ident_process(parms, tbl,
1766 * Tcam table scan the identifier list and extract the identifier from
1770 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1771 struct bnxt_ulp_mapper_tbl_info *tbl,
1772 struct ulp_blob *data)
1774 struct bnxt_ulp_mapper_ident_info *idents;
1775 uint32_t num_idents = 0, i;
1779 * Extract the listed identifiers from the result field,
1780 * no need to allocate them.
1782 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1783 for (i = 0; i < num_idents; i++) {
1784 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1786 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1793 /* Internal function to write the tcam entry */
1795 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1796 struct bnxt_ulp_mapper_tbl_info *tbl,
1797 struct ulp_blob *key,
1798 struct ulp_blob *mask,
1799 struct ulp_blob *data,
1802 struct tf_set_tcam_entry_parms sparms = { 0 };
1807 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1809 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1813 sparms.dir = tbl->direction;
1814 sparms.tcam_tbl_type = tbl->resource_type;
1816 sparms.key = ulp_blob_data_get(key, &tmplen);
1817 sparms.key_sz_in_bits = tmplen;
1818 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1819 sparms.result = ulp_blob_data_get(data, &tmplen);
1820 sparms.result_sz_in_bits = tmplen;
1821 if (tf_set_tcam_entry(tfp, &sparms)) {
1822 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1823 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1824 tf_dir_2_str(sparms.dir), sparms.idx);
1827 BNXT_TF_INF("tcam[%s][%s][%x] write success.\n",
1828 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1829 tf_dir_2_str(sparms.dir), sparms.idx);
1832 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1834 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1838 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1839 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
1840 ulp_mapper_tcam_entry_dump("TCAM", idx, tbl, key, mask, data);
1847 * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
1849 * parms [in] The mappers parms with data related to the flow.
1851 * key [in] The original key to be transformed
1853 * mask [in] The original mask to be transformed
1855 * tkey [in/out] The transformed key
1857 * tmask [in/out] The transformed mask
1859 * returns zero on success, non-zero on failure
1862 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
1863 struct ulp_blob *key,
1864 struct ulp_blob *mask,
1865 struct ulp_blob *tkey,
1866 struct ulp_blob *tmask)
1868 uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
1869 uint32_t cword, i, rc;
1873 slice_width = dparms->wc_slice_width;
1874 clen = dparms->wc_ctl_size_bits;
1875 max_slices = dparms->wc_max_slices;
1876 blen = ulp_blob_data_len_get(key);
1878 /* Get the length of the key based on number of slices and width */
1881 while (tlen < blen &&
1882 num_slices <= max_slices) {
1883 num_slices = num_slices << 1;
1887 if (num_slices > max_slices) {
1888 BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
1892 /* The key/mask may not be on a natural slice boundary, pad it */
1894 if (ulp_blob_pad_push(key, pad) < 0 ||
1895 ulp_blob_pad_push(mask, pad) < 0) {
1896 BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
1900 /* The new length accounts for the ctrl word length and num slices */
1901 tlen = tlen + clen * num_slices;
1902 if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
1903 !ulp_blob_init(tmask, tlen, mask->byte_order)) {
1904 BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
1908 /* Build the transformed key/mask */
1909 cword = dparms->wc_mode_list[num_slices - 1];
1910 cword = tfp_cpu_to_be_32(cword);
1912 for (i = 0; i < num_slices; i++) {
1913 val = ulp_blob_push_32(tkey, &cword, clen);
1915 BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
1918 val = ulp_blob_push_32(tmask, &cword, clen);
1920 BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
1923 rc = ulp_blob_append(tkey, key, offset, slice_width);
1925 BNXT_TF_DBG(ERR, "Key blob append failed\n");
1928 rc = ulp_blob_append(tmask, mask, offset, slice_width);
1930 BNXT_TF_DBG(ERR, "Mask blob append failed\n");
1933 offset += slice_width;
1936 /* The key/mask are byte reversed on every 4 byte chunk */
1937 ulp_blob_perform_byte_reverse(tkey, 4);
1938 ulp_blob_perform_byte_reverse(tmask, 4);
1943 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1944 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
1946 ulp_blob_perform_64B_word_swap(blob);
1947 ulp_blob_perform_64B_byte_swap(blob);
1948 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1949 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
1950 BNXT_TF_DBG(INFO, "Dump after wc tcam post process\n");
1951 ulp_mapper_blob_dump(blob);
1956 static int32_t ulp_mapper_tcam_is_wc_tcam(struct bnxt_ulp_mapper_tbl_info *tbl)
1958 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM ||
1959 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_HIGH ||
1960 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_LOW)
1966 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1967 struct bnxt_ulp_mapper_tbl_info *tbl)
1969 struct bnxt_ulp_mapper_key_info *kflds;
1970 struct ulp_blob okey, omask, data, update_data;
1971 struct ulp_blob tkey, tmask; /* transform key and mask */
1972 struct ulp_blob *key, *mask;
1973 uint32_t i, num_kflds;
1976 struct bnxt_ulp_device_params *dparms = parms->device_params;
1977 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1978 struct tf_search_tcam_entry_parms searchparms = { 0 };
1979 struct ulp_flow_db_res_params fid_parms = { 0 };
1980 struct tf_free_tcam_entry_parms free_parms = { 0 };
1982 uint16_t tmplen = 0;
1984 enum bnxt_ulp_byte_order key_byte_order;
1986 /* Set the key and mask to the original key and mask. */
1990 /* Skip this if table opcode is NOP */
1991 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
1992 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
1993 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
1998 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2000 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
2004 /* If only allocation of identifier then perform and exit */
2005 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_IDENT) {
2006 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
2010 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2011 if (!kflds || !num_kflds) {
2012 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2016 if (ulp_mapper_tcam_is_wc_tcam(tbl))
2017 key_byte_order = dparms->wc_key_byte_order;
2019 key_byte_order = dparms->key_byte_order;
2021 if (!ulp_blob_init(key, tbl->blob_key_bit_size, key_byte_order) ||
2022 !ulp_blob_init(mask, tbl->blob_key_bit_size, key_byte_order) ||
2023 !ulp_blob_init(&data, tbl->result_bit_size,
2024 dparms->result_byte_order) ||
2025 !ulp_blob_init(&update_data, tbl->result_bit_size,
2026 dparms->result_byte_order)) {
2027 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2031 /* create the key/mask */
2033 * NOTE: The WC table will require some kind of flag to handle the
2034 * mode bits within the key/mask
2036 for (i = 0; i < num_kflds; i++) {
2038 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2039 &kflds[i].field_info_spec,
2040 key, 1, "TCAM Key");
2042 BNXT_TF_DBG(ERR, "Key field set failed %s\n",
2043 kflds[i].field_info_spec.description);
2047 /* Setup the mask */
2048 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2049 &kflds[i].field_info_mask,
2050 mask, 0, "TCAM Mask");
2052 BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
2053 kflds[i].field_info_mask.description);
2058 /* For wild card tcam perform the post process to swap the blob */
2059 if (ulp_mapper_tcam_is_wc_tcam(tbl)) {
2060 if (dparms->dynamic_pad_en) {
2061 /* Sets up the slices for writing to the WC TCAM */
2062 rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
2068 "Failed to post proc WC entry.\n");
2071 /* Now need to use the transform Key/Mask */
2075 ulp_mapper_wc_tcam_tbl_post_process(key);
2076 ulp_mapper_wc_tcam_tbl_post_process(mask);
2081 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
2082 /* allocate the tcam index */
2083 aparms.dir = tbl->direction;
2084 aparms.tcam_tbl_type = tbl->resource_type;
2085 aparms.key = ulp_blob_data_get(key, &tmplen);
2086 aparms.key_sz_in_bits = tmplen;
2087 aparms.mask = ulp_blob_data_get(mask, &tmplen);
2089 /* calculate the entry priority */
2090 rc = ulp_mapper_priority_opc_process(parms, tbl,
2093 BNXT_TF_DBG(ERR, "entry priority process failed\n");
2097 rc = tf_alloc_tcam_entry(tfp, &aparms);
2099 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
2106 * Searching before allocation to see if we already have an
2107 * entry. This allows re-use of a constrained resource.
2109 searchparms.dir = tbl->direction;
2110 searchparms.tcam_tbl_type = tbl->resource_type;
2111 searchparms.key = ulp_blob_data_get(key, &tmplen);
2112 searchparms.key_sz_in_bits = tbl->key_bit_size;
2113 searchparms.mask = ulp_blob_data_get(mask, &tmplen);
2114 searchparms.alloc = 1;
2115 searchparms.result = ulp_blob_data_get(&data, &tmplen);
2116 searchparms.result_sz_in_bits = tbl->result_bit_size;
2118 /* calculate the entry priority */
2119 rc = ulp_mapper_priority_opc_process(parms, tbl,
2120 &searchparms.priority);
2122 BNXT_TF_DBG(ERR, "entry priority process failed\n");
2126 rc = tf_search_tcam_entry(tfp, &searchparms);
2128 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
2132 /* Successful search, check the result */
2133 if (searchparms.search_status == REJECT) {
2134 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
2137 idx = searchparms.idx;
2138 hit = searchparms.hit;
2141 /* Write the tcam index into the regfile*/
2142 if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
2143 (uint64_t)tfp_cpu_to_be_64(idx))) {
2144 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
2147 /* Need to free the tcam idx, so goto error */
2151 /* if it is miss then it is same as no search before alloc */
2152 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
2153 /*Scan identifier list, allocate identifier and update regfile*/
2154 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
2155 /* Create the result blob */
2157 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2159 /* write the tcam entry */
2161 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
2164 /*Scan identifier list, extract identifier and update regfile*/
2165 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
2170 /* Add the tcam index to the flow database */
2171 fid_parms.direction = tbl->direction;
2172 fid_parms.resource_func = tbl->resource_func;
2173 fid_parms.resource_type = tbl->resource_type;
2174 fid_parms.critical_resource = tbl->critical_resource;
2175 fid_parms.resource_hndl = idx;
2176 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2178 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2180 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2182 /* Need to free the identifier, so goto error */
2188 free_parms.dir = tbl->direction;
2189 free_parms.tcam_tbl_type = tbl->resource_type;
2190 free_parms.idx = idx;
2191 trc = tf_free_tcam_entry(tfp, &free_parms);
2193 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
2194 tbl->resource_type, tbl->direction, idx);
2199 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2200 struct bnxt_ulp_mapper_tbl_info *tbl)
2202 struct bnxt_ulp_mapper_key_info *kflds;
2203 struct ulp_blob key, data;
2204 uint32_t i, num_kflds;
2207 struct ulp_flow_db_res_params fid_parms = { 0 };
2208 struct tf_insert_em_entry_parms iparms = { 0 };
2209 struct tf_delete_em_entry_parms free_parms = { 0 };
2210 enum bnxt_ulp_flow_mem_type mtype;
2211 struct bnxt_ulp_device_params *dparms = parms->device_params;
2216 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2217 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2219 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
2223 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2224 if (!kflds || !num_kflds) {
2225 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2229 /* Initialize the key/result blobs */
2230 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
2231 dparms->key_byte_order) ||
2232 !ulp_blob_init(&data, tbl->result_bit_size,
2233 dparms->result_byte_order)) {
2234 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2238 /* create the key */
2239 for (i = 0; i < num_kflds; i++) {
2241 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2242 &kflds[i].field_info_spec,
2245 BNXT_TF_DBG(ERR, "Key field set failed.\n");
2250 /* if dynamic padding is enabled then add padding to result data */
2251 if (dparms->dynamic_pad_en) {
2252 /* add padding to make sure key is at byte boundary */
2253 ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
2256 pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
2258 BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
2261 ulp_blob_pad_push(&data, (uint32_t)pad);
2264 /* Create the result data blob */
2265 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
2267 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2270 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2271 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2272 ulp_mapper_result_dump("EM Result", tbl, &data);
2275 if (dparms->dynamic_pad_en) {
2276 uint32_t abits = dparms->em_blk_align_bits;
2278 /* when dynamic padding is enabled merge result + key */
2279 rc = ulp_blob_block_merge(&data, &key, abits, pad);
2281 BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
2285 /* add padding to make sure merged result is at slice boundary*/
2286 ulp_blob_pad_align(&data, abits);
2288 ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
2289 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2290 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2291 ulp_mapper_result_dump("EM Merged Result", tbl, &data);
2296 /* do the transpose for the internal EM keys */
2297 if (tbl->resource_type == TF_MEM_INTERNAL) {
2298 if (dparms->em_key_align_bytes) {
2299 int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
2301 tmplen = ulp_blob_data_len_get(&key);
2302 ulp_blob_pad_push(&key, b - tmplen);
2304 tmplen = ulp_blob_data_len_get(&key);
2305 ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
2306 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2307 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2308 ulp_mapper_result_dump("EM Key Transpose", tbl, &key);
2313 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
2314 &iparms.tbl_scope_id);
2316 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2321 * NOTE: the actual blob size will differ from the size in the tbl
2322 * entry due to the padding.
2324 iparms.dup_check = 0;
2325 iparms.dir = tbl->direction;
2326 iparms.mem = tbl->resource_type;
2327 iparms.key = ulp_blob_data_get(&key, &tmplen);
2328 iparms.key_sz_in_bits = tbl->key_bit_size;
2329 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
2330 if (tbl->result_bit_size)
2331 iparms.em_record_sz_in_bits = tbl->result_bit_size;
2333 iparms.em_record_sz_in_bits = tmplen;
2335 rc = tf_insert_em_entry(tfp, &iparms);
2337 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
2341 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2342 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2343 ulp_mapper_em_dump("EM", &key, &data, &iparms);
2344 /* tf_dump_tables(tfp, iparms.tbl_scope_id); */
2347 /* Mark action process */
2348 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
2349 tbl->resource_type == TF_MEM_EXTERNAL)
2350 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
2351 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
2352 tbl->resource_type == TF_MEM_INTERNAL)
2353 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
2355 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
2359 /* Link the EM resource to the flow in the flow db */
2360 memset(&fid_parms, 0, sizeof(fid_parms));
2361 fid_parms.direction = tbl->direction;
2362 fid_parms.resource_func = tbl->resource_func;
2363 fid_parms.resource_type = tbl->resource_type;
2364 fid_parms.critical_resource = tbl->critical_resource;
2365 fid_parms.resource_hndl = iparms.flow_handle;
2367 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2369 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
2371 /* Need to free the identifier, so goto error */
2377 free_parms.dir = iparms.dir;
2378 free_parms.mem = iparms.mem;
2379 free_parms.tbl_scope_id = iparms.tbl_scope_id;
2380 free_parms.flow_handle = iparms.flow_handle;
2382 trc = tf_delete_em_entry(tfp, &free_parms);
2384 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
2390 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2391 struct bnxt_ulp_mapper_tbl_info *tbl)
2393 struct ulp_flow_db_res_params fid_parms;
2394 struct ulp_blob data;
2395 uint64_t regval = 0;
2398 int32_t rc = 0, trc = 0;
2399 struct tf_alloc_tbl_entry_parms aparms = { 0 };
2400 struct tf_set_tbl_entry_parms sparms = { 0 };
2401 struct tf_get_tbl_entry_parms gparms = { 0 };
2402 struct tf_free_tbl_entry_parms free_parms = { 0 };
2403 uint32_t tbl_scope_id;
2405 struct bnxt_ulp_glb_resource_info glb_res = { 0 };
2409 bool global = false;
2410 uint64_t act_rec_size;
2411 bool shared = false;
2413 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2414 /* use the max size if encap is enabled */
2415 if (tbl->encap_num_fields)
2416 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
2418 bit_size = tbl->result_bit_size;
2420 /* Initialize the blob data */
2421 if (!ulp_blob_init(&data, bit_size,
2422 parms->device_params->result_byte_order)) {
2423 BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
2427 /* Get the scope id first */
2428 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
2430 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2434 switch (tbl->tbl_opcode) {
2435 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
2438 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
2440 * Build the entry, alloc an index, write the table, and store
2441 * the data in the regfile.
2446 case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
2448 * get the index to write to from the regfile and then write
2451 if (!ulp_regfile_read(parms->regfile,
2455 "Failed to get tbl idx from regfile[%d].\n",
2459 index = tfp_be_to_cpu_64(regval);
2460 /* For external, we need to reverse shift */
2461 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2462 index = TF_ACT_REC_PTR_2_OFFSET(index);
2466 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
2468 * Build the entry, alloc an index, write the table, and store
2469 * the data in the global regfile.
2474 glb_res.direction = tbl->direction;
2475 glb_res.resource_func = tbl->resource_func;
2476 glb_res.resource_type = tbl->resource_type;
2477 glb_res.glb_regfile_index = tbl->tbl_operand;
2479 case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
2480 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2481 BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
2485 * get the index to write to from the global regfile and then
2488 if (ulp_mapper_glb_resource_read(parms->mapper_data,
2491 ®val, &shared)) {
2493 "Failed to get tbl idx from Glb RF[%d].\n",
2497 index = tfp_be_to_cpu_64(regval);
2498 /* For external, we need to reverse shift */
2499 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2500 index = TF_ACT_REC_PTR_2_OFFSET(index);
2503 case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
2505 * The read is different from the rest and can be handled here
2506 * instead of trying to use common code. Simply read the table
2507 * with the index from the regfile, scan and store the
2508 * identifiers, and return.
2510 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2511 /* Not currently supporting with EXT */
2513 "Ext Table Read Opcode not supported.\n");
2516 if (!ulp_regfile_read(parms->regfile,
2517 tbl->tbl_operand, ®val)) {
2519 "Failed to get tbl idx from regfile[%d]\n",
2523 index = tfp_be_to_cpu_64(regval);
2524 gparms.dir = tbl->direction;
2525 gparms.type = tbl->resource_type;
2526 gparms.data = ulp_blob_data_get(&data, &tmplen);
2527 gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tbl->result_bit_size);
2529 rc = tf_get_tbl_entry(tfp, &gparms);
2531 BNXT_TF_DBG(ERR, "Failed to read the tbl entry %d:%d\n",
2532 tbl->resource_type, index);
2536 * Scan the fields in the entry and push them into the regfile.
2538 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2540 gparms.data_sz_in_bytes,
2544 "Failed to get flds on tbl read rc=%d\n",
2550 BNXT_TF_DBG(ERR, "Invalid index table opcode %d\n",
2556 /* Get the result fields list */
2557 rc = ulp_mapper_tbl_result_build(parms,
2562 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2568 aparms.dir = tbl->direction;
2569 aparms.type = tbl->resource_type;
2570 aparms.tbl_scope_id = tbl_scope_id;
2572 /* All failures after the alloc succeeds require a free */
2573 rc = tf_alloc_tbl_entry(tfp, &aparms);
2575 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2576 tf_tbl_type_2_str(tbl->resource_type),
2577 tf_dir_2_str(tbl->direction), rc);
2583 * Store the index in the regfile since we either allocated it
2586 * Calculate the idx for the result record, for external EM the
2587 * offset needs to be shifted accordingly.
2588 * If external non-inline table types are used then need to
2589 * revisit this logic.
2591 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2592 regval = TF_ACT_REC_OFFSET_2_PTR(index);
2595 regval = tfp_cpu_to_be_64(regval);
2599 * Shared resources are never allocated through this
2600 * method, so the shared flag is always false.
2602 rc = ulp_mapper_glb_resource_write(parms->mapper_data,
2606 rc = ulp_regfile_write(parms->regfile,
2607 tbl->tbl_operand, regval);
2611 "Failed to write %s regfile[%d] rc=%d\n",
2612 (global) ? "global" : "reg",
2613 tbl->tbl_operand, rc);
2619 sparms.dir = tbl->direction;
2620 sparms.type = tbl->resource_type;
2621 sparms.data = ulp_blob_data_get(&data, &tmplen);
2622 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2624 sparms.tbl_scope_id = tbl_scope_id;
2626 tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
2627 rc = tf_set_tbl_entry(tfp, &sparms);
2630 "Index table[%s][%s][%x] write fail rc=%d\n",
2631 tf_tbl_type_2_str(sparms.type),
2632 tf_dir_2_str(sparms.dir),
2636 BNXT_TF_INF("Index table[%s][%s][%x] write successful.\n",
2637 tf_tbl_type_2_str(sparms.type),
2638 tf_dir_2_str(sparms.dir), sparms.idx);
2640 /* Calculate action record size */
2641 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2642 act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
2644 if (ulp_regfile_write(parms->regfile,
2645 BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
2646 tfp_cpu_to_be_64(act_rec_size)))
2648 "Failed write the act rec size\n");
2652 /* Link the resource to the flow in the flow db */
2653 memset(&fid_parms, 0, sizeof(fid_parms));
2654 fid_parms.direction = tbl->direction;
2655 fid_parms.resource_func = tbl->resource_func;
2656 fid_parms.resource_type = tbl->resource_type;
2657 fid_parms.resource_sub_type = tbl->resource_sub_type;
2658 fid_parms.resource_hndl = index;
2659 fid_parms.critical_resource = tbl->critical_resource;
2660 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2662 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2664 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2669 /* Perform the VF rep action */
2670 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2672 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2677 /* Shared resources are not freed */
2681 * Free the allocated resource since we failed to either
2682 * write to the entry or link the flow
2684 free_parms.dir = tbl->direction;
2685 free_parms.type = tbl->resource_type;
2686 free_parms.idx = index;
2687 free_parms.tbl_scope_id = tbl_scope_id;
2689 trc = tf_free_tbl_entry(tfp, &free_parms);
2691 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2697 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2698 struct bnxt_ulp_mapper_tbl_info *tbl)
2700 struct ulp_blob data, res_blob;
2704 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2705 struct tf_get_if_tbl_entry_parms get_parms = { 0 };
2707 enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
2710 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2711 /* Initialize the blob data */
2712 if (!ulp_blob_init(&data, tbl->result_bit_size,
2713 parms->device_params->result_byte_order)) {
2714 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2718 /* create the result blob */
2719 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
2721 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2725 /* Get the index details */
2727 case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
2728 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2730 case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
2731 if (!ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx)) {
2732 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
2736 idx = tfp_be_to_cpu_64(idx);
2738 case BNXT_ULP_IF_TBL_OPC_WR_CONST:
2739 idx = tbl->tbl_operand;
2741 case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
2742 /* Initialize the result blob */
2743 if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
2744 parms->device_params->result_byte_order)) {
2745 BNXT_TF_DBG(ERR, "Failed initial result blob\n");
2749 /* read the interface table */
2750 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2751 res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
2752 get_parms.dir = tbl->direction;
2753 get_parms.type = tbl->resource_type;
2754 get_parms.idx = idx;
2755 get_parms.data = ulp_blob_data_get(&res_blob, &tmplen);
2756 get_parms.data_sz_in_bytes = res_size;
2758 rc = tf_get_if_tbl_entry(tfp, &get_parms);
2760 BNXT_TF_DBG(ERR, "Get table[%d][%s][%x] failed rc=%d\n",
2762 tf_dir_2_str(get_parms.dir),
2766 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2769 res_blob.byte_order);
2771 BNXT_TF_DBG(ERR, "Scan and extract failed rc=%d\n", rc);
2773 case BNXT_ULP_IF_TBL_OPC_NOT_USED:
2774 return rc; /* skip it */
2776 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2780 /* Perform the tf table set by filling the set params */
2781 iftbl_params.dir = tbl->direction;
2782 iftbl_params.type = tbl->resource_type;
2783 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2784 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2785 iftbl_params.idx = idx;
2787 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2789 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2790 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2791 tf_dir_2_str(iftbl_params.dir),
2792 iftbl_params.idx, rc);
2795 BNXT_TF_INF("Set table[%s][%s][%x] success.\n",
2796 tf_if_tbl_2_str(iftbl_params.type),
2797 tf_dir_2_str(iftbl_params.dir),
2801 * TBD: Need to look at the need to store idx in flow db for restore
2802 * the table to its original state on deletion of this entry.
2808 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2809 struct bnxt_ulp_mapper_tbl_info *tbl)
2811 struct ulp_mapper_gen_tbl_list *gen_tbl_list;
2812 struct bnxt_ulp_mapper_key_info *kflds;
2813 struct ulp_flow_db_res_params fid_parms;
2814 struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
2815 struct ulp_gen_hash_entry_params hash_entry;
2816 uint16_t tmplen = 0;
2817 struct ulp_blob key, data;
2820 uint32_t i, num_kflds = 0, key_index = 0;
2821 uint32_t gen_tbl_miss = 1, fdb_write = 0;
2825 /* Get the key fields list and build the key. */
2826 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2827 if (!kflds || !num_kflds) {
2828 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2832 if (!ulp_blob_init(&key, tbl->key_bit_size,
2833 parms->device_params->key_byte_order)) {
2834 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2837 for (i = 0; i < num_kflds; i++) {
2839 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2840 &kflds[i].field_info_spec,
2841 &key, 1, "Gen Tbl Key");
2844 "Failed to create key for Gen tbl rc=%d\n",
2850 /* Calculate the table index for the generic table*/
2851 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2854 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2855 tbl->resource_sub_type, tbl->direction);
2859 /* The_key is a byte array convert it to a search index */
2860 cache_key = ulp_blob_data_get(&key, &tmplen);
2861 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
2862 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
2863 BNXT_TF_DBG(DEBUG, "The gen_tbl[%u] key\n", tbl_idx);
2864 ulp_mapper_blob_dump(&key);
2867 /* get the generic table */
2868 gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
2870 /* Check if generic hash table */
2871 if (gen_tbl_list->hash_tbl) {
2872 if (tbl->gen_tbl_lkup_type !=
2873 BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
2874 BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
2875 gen_tbl_list->gen_tbl_name);
2878 hash_entry.key_data = cache_key;
2879 hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
2880 rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
2883 BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
2884 gen_tbl_list->gen_tbl_name);
2887 if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
2888 key_index = hash_entry.key_idx;
2889 /* Get the generic table entry */
2890 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
2894 /* store the hash index in the fdb */
2895 key_index = hash_entry.hash_index;
2898 /* convert key to index directly */
2899 if (ULP_BITS_2_BYTE(tmplen) > (int32_t)sizeof(key_index)) {
2900 BNXT_TF_DBG(ERR, "%s: keysize is bigger then 4 bytes\n",
2901 gen_tbl_list->gen_tbl_name);
2904 memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
2905 /* Get the generic table entry */
2906 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
2910 switch (tbl->tbl_opcode) {
2911 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2912 if (gen_tbl_list->hash_tbl) {
2913 if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
2914 break; /* nothing to be done , no entry */
2917 /* check the reference count */
2918 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2920 /* Scan ident list and create the result blob*/
2921 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2927 "Failed to scan ident list\n");
2930 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2931 /* increment the reference count */
2932 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2940 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
2941 if (gen_tbl_list->hash_tbl) {
2942 rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
2947 /* store the hash index in the fdb */
2948 key_index = hash_entry.hash_index;
2950 /* check the reference count */
2951 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2952 /* a hit then error */
2953 BNXT_TF_DBG(ERR, "generic entry already present\n");
2954 return -EINVAL; /* success */
2957 /* Initialize the blob data */
2958 if (!ulp_blob_init(&data, tbl->result_bit_size,
2959 gen_tbl_ent.byte_order)) {
2960 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2964 /* Get the result fields list */
2965 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2968 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2971 byte_data = ulp_blob_data_get(&data, &tmplen);
2972 rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
2974 ULP_BITS_2_BYTE(tmplen));
2976 BNXT_TF_DBG(ERR, "Failed to write generic table\n");
2980 /* increment the reference count */
2981 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2983 parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
2986 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
2990 /* Set the generic entry hit */
2991 rc = ulp_regfile_write(parms->regfile,
2992 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
2993 tfp_cpu_to_be_64(gen_tbl_miss));
2995 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2996 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3000 /* add the entry to the flow database */
3002 memset(&fid_parms, 0, sizeof(fid_parms));
3003 fid_parms.direction = tbl->direction;
3004 fid_parms.resource_func = tbl->resource_func;
3005 fid_parms.resource_sub_type = tbl->resource_sub_type;
3006 fid_parms.resource_hndl = key_index;
3007 fid_parms.critical_resource = tbl->critical_resource;
3008 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
3010 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
3012 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
3018 ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
3019 struct bnxt_ulp_mapper_tbl_info *tbl)
3023 /* process the fdb opcode for alloc push */
3024 if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
3025 rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
3027 BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
3035 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
3036 struct bnxt_ulp_mapper_data *mapper_data)
3038 struct bnxt_ulp_glb_resource_info *glb_res;
3039 uint32_t num_glb_res_ids, idx, dev_id;
3043 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
3044 if (!glb_res || !num_glb_res_ids) {
3045 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
3049 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
3051 BNXT_TF_DBG(ERR, "Failed to get device id for glb init (%d)\n",
3056 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
3058 BNXT_TF_DBG(ERR, "Failed to get app id for glb init (%d)\n",
3063 /* Iterate the global resources and process each one */
3064 for (idx = 0; idx < num_glb_res_ids; idx++) {
3065 if (dev_id != glb_res[idx].device_id ||
3066 glb_res[idx].app_id != app_id)
3068 switch (glb_res[idx].resource_func) {
3069 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3070 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
3074 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3075 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
3080 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
3081 glb_res[idx].resource_func);
3092 * Iterate over the shared resources assigned during tf_open_session and store
3093 * them in the global regfile with the shared flag.
3096 ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
3097 struct bnxt_ulp_mapper_data *mapper_data)
3099 struct tf_get_shared_tbl_increment_parms iparms;
3100 struct bnxt_ulp_glb_resource_info *glb_res;
3101 struct tf_get_session_info_parms sparms;
3102 uint32_t num_entries, i, dev_id, res;
3103 struct tf_resource_info *res_info;
3111 memset(&sparms, 0, sizeof(sparms));
3112 glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
3113 if (!glb_res || !num_entries) {
3114 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
3117 tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
3119 BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
3123 * Retrieve the resources that were assigned during the shared session
3126 rc = tf_get_session_info(tfp, &sparms);
3128 BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
3132 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
3134 BNXT_TF_DBG(ERR, "Failed to get the app id in glb init (%d).\n",
3139 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
3141 BNXT_TF_DBG(ERR, "Failed to get dev id for app glb init (%d)\n",
3146 /* Store all the app global resources */
3147 for (i = 0; i < num_entries; i++) {
3148 if (dev_id != glb_res[i].device_id ||
3149 app_id != glb_res[i].app_id)
3151 dir = glb_res[i].direction;
3152 res = glb_res[i].resource_type;
3155 switch (glb_res[i].resource_func) {
3156 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3157 res_info = &sparms.session_info.ident[dir].info[res];
3159 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3161 * Tables may have various strides for the allocations.
3164 memset(&iparms, 0, sizeof(iparms));
3167 rc = tf_get_shared_tbl_increment(tfp, &iparms);
3170 "Failed to get addend for %s[%s] rc=(%d)\n",
3171 tf_tbl_type_2_str(res),
3172 tf_dir_2_str(dir), rc);
3175 addend = iparms.increment_cnt;
3176 res_info = &sparms.session_info.tbl[dir].info[res];
3178 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3179 res_info = &sparms.session_info.tcam[dir].info[res];
3181 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3182 res_info = &sparms.session_info.em[dir].info[res];
3185 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
3186 glb_res[i].resource_func);
3189 regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
3190 res_info->start += addend;
3192 * All resources written to the global regfile are shared for
3195 rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
3205 * Common conditional opcode process routine that is used for both the template
3206 * rejection and table conditional execution.
3209 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
3210 enum bnxt_ulp_cond_opc opc,
3214 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
3220 case BNXT_ULP_COND_OPC_CF_IS_SET:
3221 if (operand < BNXT_ULP_CF_IDX_LAST) {
3222 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
3224 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3229 case BNXT_ULP_COND_OPC_CF_NOT_SET:
3230 if (operand < BNXT_ULP_CF_IDX_LAST) {
3231 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
3233 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3238 case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
3239 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3240 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3243 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3248 case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
3249 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3250 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3253 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3258 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
3259 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3260 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3263 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3268 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
3269 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3270 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3273 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3278 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
3279 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3281 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3285 *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3287 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
3288 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3290 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3294 *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3296 case BNXT_ULP_COND_OPC_RF_IS_SET:
3297 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3298 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3303 case BNXT_ULP_COND_OPC_RF_NOT_SET:
3304 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3305 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3310 case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
3311 if (parms->flow_pattern_id == operand) {
3312 BNXT_TF_DBG(ERR, "field pattern match failed %x\n",
3313 parms->flow_pattern_id);
3317 case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
3318 if (parms->act_pattern_id == operand) {
3319 BNXT_TF_DBG(ERR, "act pattern match failed %x\n",
3320 parms->act_pattern_id);
3324 case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
3325 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3326 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3329 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
3331 case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
3332 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3333 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3336 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
3338 case BNXT_ULP_COND_OPC_ENC_HDR_BIT_IS_SET:
3339 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3340 *res = ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
3343 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3348 case BNXT_ULP_COND_OPC_ENC_HDR_BIT_NOT_SET:
3349 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3350 *res = !ULP_BITMAP_ISSET(parms->enc_hdr_bitmap->bits,
3353 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3359 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
3367 ulp_mapper_func_opr_compute(struct bnxt_ulp_mapper_parms *parms,
3369 enum bnxt_ulp_func_src func_src,
3378 case BNXT_ULP_FUNC_SRC_COMP_FIELD:
3379 if (func_opr >= BNXT_ULP_CF_IDX_LAST) {
3380 BNXT_TF_DBG(ERR, "invalid index %u\n", func_opr);
3383 *result = ULP_COMP_FLD_IDX_RD(parms, func_opr);
3385 case BNXT_ULP_FUNC_SRC_REGFILE:
3386 if (!ulp_regfile_read(parms->regfile, func_opr, ®val)) {
3387 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", func_opr);
3390 *result = tfp_be_to_cpu_64(regval);
3392 case BNXT_ULP_FUNC_SRC_GLB_REGFILE:
3393 if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
3394 func_opr, ®val, &shared)) {
3395 BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
3399 *result = tfp_be_to_cpu_64(regval);
3401 case BNXT_ULP_FUNC_SRC_CONST:
3405 BNXT_TF_DBG(ERR, "invalid src code %u\n", func_src);
3412 ulp_mapper_func_info_process(struct bnxt_ulp_mapper_parms *parms,
3413 struct bnxt_ulp_mapper_tbl_info *tbl)
3415 struct bnxt_ulp_mapper_func_info *func_info = &tbl->func_info;
3416 uint64_t res = 0, res1 = 0, res2 = 0;
3418 uint32_t process_src1 = 0, process_src2 = 0;
3420 /* determine which functional operands to compute */
3421 switch (func_info->func_opc) {
3422 case BNXT_ULP_FUNC_OPC_NOP:
3424 case BNXT_ULP_FUNC_OPC_EQ:
3425 case BNXT_ULP_FUNC_OPC_NE:
3426 case BNXT_ULP_FUNC_OPC_GE:
3427 case BNXT_ULP_FUNC_OPC_GT:
3428 case BNXT_ULP_FUNC_OPC_LE:
3429 case BNXT_ULP_FUNC_OPC_LT:
3433 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3441 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3442 func_info->func_src1,
3443 func_info->func_opr1, &res1);
3449 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3450 func_info->func_src2,
3451 func_info->func_opr2, &res2);
3456 /* perform the functional opcode operations */
3457 switch (func_info->func_opc) {
3458 case BNXT_ULP_FUNC_OPC_EQ:
3462 case BNXT_ULP_FUNC_OPC_NE:
3466 case BNXT_ULP_FUNC_OPC_GE:
3470 case BNXT_ULP_FUNC_OPC_GT:
3474 case BNXT_ULP_FUNC_OPC_LE:
3478 case BNXT_ULP_FUNC_OPC_LT:
3482 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3485 case BNXT_ULP_FUNC_OPC_RSS_CONFIG:
3486 /* apply the rss config using pmd method */
3487 return bnxt_rss_config_action_apply(parms);
3488 case BNXT_ULP_FUNC_OPC_GET_PARENT_MAC_ADDR:
3489 rc = bnxt_pmd_get_parent_mac_addr(parms, (uint8_t *)&res);
3492 res = tfp_be_to_cpu_64(res);
3495 BNXT_TF_DBG(ERR, "invalid func code %u\n", func_info->func_opc);
3498 if (ulp_regfile_write(parms->regfile, func_info->func_dst_opr,
3499 tfp_cpu_to_be_64(res))) {
3500 BNXT_TF_DBG(ERR, "Failed write the func_opc %u\n",
3501 func_info->func_dst_opr);
3510 * Processes a list of conditions and returns both a status and result of the
3511 * list. The status must be checked prior to verifying the result.
3513 * returns 0 for success, negative on failure
3514 * returns res = 1 for true, res = 0 for false.
3517 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
3518 enum bnxt_ulp_cond_list_opc list_opc,
3519 struct bnxt_ulp_mapper_cond_info *list,
3524 int32_t rc = 0, trc = 0;
3527 case BNXT_ULP_COND_LIST_OPC_AND:
3528 /* AND Defaults to true. */
3531 case BNXT_ULP_COND_LIST_OPC_OR:
3532 /* OR Defaults to false. */
3535 case BNXT_ULP_COND_LIST_OPC_TRUE:
3538 case BNXT_ULP_COND_LIST_OPC_FALSE:
3542 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
3548 for (i = 0; i < num; i++) {
3549 rc = ulp_mapper_cond_opc_process(parms,
3550 list[i].cond_opcode,
3551 list[i].cond_operand,
3556 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
3557 /* early return if result is ever zero */
3563 /* early return if result is ever non-zero */
3575 * Processes conflict resolution and returns both a status and result.
3576 * The status must be checked prior to verifying the result.
3578 * returns 0 for success, negative on failure
3579 * returns res = 1 for true, res = 0 for false.
3582 ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
3583 struct bnxt_ulp_mapper_tbl_info *tbl,
3591 switch (tbl->accept_opcode) {
3592 case BNXT_ULP_ACCEPT_OPC_ALWAYS:
3595 case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
3596 /* perform the signature validation*/
3597 if (tbl->resource_func ==
3598 BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
3599 /* Perform the check that generic table is hit or not */
3600 if (!ulp_regfile_read(parms->regfile,
3601 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3603 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3604 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3608 /* not a hit so no need to check flow sign*/
3613 /* compare the new flow signature against stored one */
3614 if (!ulp_regfile_read(parms->regfile,
3615 BNXT_ULP_RF_IDX_FLOW_SIG_ID,
3617 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3618 BNXT_ULP_RF_IDX_FLOW_SIG_ID);
3621 comp_sig = ULP_COMP_FLD_IDX_RD(parms,
3622 BNXT_ULP_CF_IDX_FLOW_SIG_ID);
3623 regval = tfp_be_to_cpu_64(regval);
3624 if (comp_sig == regval)
3627 BNXT_TF_DBG(ERR, "failed signature match 0x%016"
3628 PRIX64 ":%x\n", comp_sig, (uint32_t)regval);
3631 BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
3632 tbl->accept_opcode);
3639 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
3641 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
3642 enum bnxt_ulp_cond_list_opc cond_opc;
3643 struct bnxt_ulp_mapper_tbl_info *tbls;
3644 struct bnxt_ulp_mapper_tbl_info *tbl;
3645 uint32_t num_tbls, tbl_idx, num_cond_tbls;
3646 int32_t rc = -EINVAL, cond_rc = 0;
3647 int32_t cond_goto = 1;
3649 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
3653 * Process the reject list if exists, otherwise assume that the
3654 * template is allowed.
3656 if (cond_tbls && num_cond_tbls) {
3657 rc = ulp_mapper_cond_opc_list_process(parms,
3665 /* Reject the template if True */
3667 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
3668 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3674 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
3675 if (!tbls || !num_tbls) {
3676 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
3677 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3678 parms->dev_id, tid);
3682 for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
3683 tbl = &tbls[tbl_idx];
3684 cond_goto = tbl->execute_info.cond_true_goto;
3685 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
3686 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG_MAPPER
3687 ulp_mapper_table_dump(tbl, tbl_idx);
3690 /* Process the conditional func code opcodes */
3691 if (ulp_mapper_func_info_process(parms, tbl)) {
3692 BNXT_TF_DBG(ERR, "Failed to process cond update\n");
3697 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
3700 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
3701 cond_tbls, num_cond_tbls,
3704 BNXT_TF_DBG(ERR, "Failed to proc cond opc list (%d)\n",
3708 /* Skip the table if False */
3710 cond_goto = tbl->execute_info.cond_false_goto;
3711 goto next_iteration;
3714 switch (tbl->resource_func) {
3715 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3716 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
3718 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3719 rc = ulp_mapper_em_tbl_process(parms, tbl);
3721 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3722 rc = ulp_mapper_index_tbl_process(parms, tbl);
3724 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
3725 rc = ulp_mapper_if_tbl_process(parms, tbl);
3727 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3728 rc = ulp_mapper_gen_tbl_process(parms, tbl);
3730 case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
3731 rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
3733 case BNXT_ULP_RESOURCE_FUNC_INVALID:
3737 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
3738 tbl->resource_func);
3744 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
3745 tbl->resource_func);
3749 /* perform the post table process */
3750 rc = ulp_mapper_conflict_resolution_process(parms, tbl,
3752 if (rc || !cond_rc) {
3753 BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
3758 if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
3759 BNXT_TF_DBG(ERR, "reject the flow\n");
3762 } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
3766 /* least significant 16 bits from reg_file index */
3767 rf_idx = (uint32_t)(cond_goto & 0xFFFF);
3768 if (!ulp_regfile_read(parms->regfile, rf_idx,
3770 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3775 cond_goto = (int32_t)regval;
3778 if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
3779 BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
3783 tbl_idx += cond_goto;
3788 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
3789 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3790 parms->dev_id, tid);
3795 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
3797 struct ulp_flow_db_res_params *res)
3803 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
3806 if (res->fdb_flags & ULP_FDB_FLAG_SHARED_SESSION)
3807 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_YES);
3809 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_NO);
3811 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
3815 switch (res->resource_func) {
3816 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3817 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
3819 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3820 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
3822 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3823 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
3825 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3826 rc = ulp_mapper_ident_free(ulp, tfp, res);
3828 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
3829 rc = ulp_mapper_mark_free(ulp, res);
3831 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
3832 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
3834 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
3835 rc = ulp_mapper_child_flow_free(ulp, fid, res);
3837 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3838 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
3848 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
3849 enum bnxt_ulp_fdb_type flow_type,
3852 struct ulp_flow_db_res_params res_parms = { 0 };
3856 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3861 * Set the critical resource on the first resource del, then iterate
3862 * while status is good
3864 if (flow_type != BNXT_ULP_FDB_TYPE_RID)
3865 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
3867 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
3871 * This is unexpected on the first call to resource del.
3872 * It likely means that the flow did not exist in the flow db.
3874 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
3875 flow_type, fid, rc);
3880 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
3883 * On fail, we still need to attempt to free the
3884 * remaining resources. Don't return
3887 "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
3888 "] failed rc=%d.\n",
3889 flow_type, fid, res_parms.resource_func,
3890 res_parms.resource_hndl, trc);
3892 /* All subsequent call require the non-critical_resource */
3893 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
3895 rc = ulp_flow_db_resource_del(ulp_ctx,
3901 /* Free the Flow ID since we've removed all resources */
3902 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
3908 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
3909 struct bnxt_ulp_mapper_data *mapper_data)
3911 struct bnxt_ulp_mapper_glb_resource_entry *ent;
3912 struct ulp_flow_db_res_params res;
3915 /* Iterate the global resources and process each one */
3916 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
3917 for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
3918 ent = &mapper_data->glb_res_tbl[dir][idx];
3919 if (ent->resource_func ==
3920 BNXT_ULP_RESOURCE_FUNC_INVALID ||
3923 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
3924 res.resource_func = ent->resource_func;
3925 res.direction = dir;
3926 res.resource_type = ent->resource_type;
3927 /*convert it from BE to cpu */
3929 tfp_be_to_cpu_64(ent->resource_hndl);
3930 ulp_mapper_resource_free(ulp_ctx, 0, &res);
3936 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
3937 enum bnxt_ulp_fdb_type flow_type,
3943 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3947 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
3951 /* Function to handle the mapping of the Flow to be compatible
3952 * with the underlying hardware.
3955 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
3956 struct bnxt_ulp_mapper_create_parms *cparms)
3958 struct bnxt_ulp_mapper_parms parms;
3959 struct ulp_regfile regfile;
3960 int32_t rc = 0, trc;
3962 if (!ulp_ctx || !cparms)
3965 /* Initialize the parms structure */
3966 memset(&parms, 0, sizeof(parms));
3967 parms.act_prop = cparms->act_prop;
3968 parms.act_bitmap = cparms->act;
3969 parms.hdr_bitmap = cparms->hdr_bitmap;
3970 parms.enc_hdr_bitmap = cparms->enc_hdr_bitmap;
3971 parms.regfile = ®file;
3972 parms.hdr_field = cparms->hdr_field;
3973 parms.enc_field = cparms->enc_field;
3974 parms.fld_bitmap = cparms->fld_bitmap;
3975 parms.comp_fld = cparms->comp_fld;
3976 parms.ulp_ctx = ulp_ctx;
3977 parms.act_tid = cparms->act_tid;
3978 parms.class_tid = cparms->class_tid;
3979 parms.flow_type = cparms->flow_type;
3980 parms.parent_flow = cparms->parent_flow;
3981 parms.child_flow = cparms->child_flow;
3982 parms.fid = cparms->flow_id;
3983 parms.tun_idx = cparms->tun_idx;
3984 parms.app_priority = cparms->app_priority;
3985 parms.flow_pattern_id = cparms->flow_pattern_id;
3986 parms.act_pattern_id = cparms->act_pattern_id;
3987 parms.app_id = cparms->app_id;
3988 parms.port_id = cparms->port_id;
3990 /* Get the device id from the ulp context */
3991 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
3992 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
3996 /* Get the device params, it will be used in later processing */
3997 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
3998 if (!parms.device_params) {
3999 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
4005 * Get the mapper data for dynamic mapper data such as default
4008 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
4009 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
4010 if (!parms.mapper_data) {
4011 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
4015 /* initialize the registry file for further processing */
4016 if (!ulp_regfile_init(parms.regfile)) {
4017 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
4021 /* Process the action template list from the selected action table*/
4022 if (parms.act_tid) {
4023 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
4024 /* Process the action template tables */
4025 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
4028 cparms->shared_hndl = parms.shared_hndl;
4031 if (parms.class_tid) {
4032 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
4034 /* Process the class template tables.*/
4035 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
4040 /* setup the parent-child details */
4041 if (parms.parent_flow) {
4042 /* create a parent flow details */
4043 rc = ulp_flow_db_parent_flow_create(&parms);
4046 } else if (parms.child_flow) {
4047 /* create a child flow details */
4048 rc = ulp_flow_db_child_flow_create(&parms);
4056 /* Free all resources that were allocated during flow creation */
4057 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
4060 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
4066 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
4068 struct bnxt_ulp_mapper_data *data;
4075 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
4079 data = rte_zmalloc("ulp_mapper_data",
4080 sizeof(struct bnxt_ulp_mapper_data), 0);
4082 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
4086 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
4087 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
4088 /* Don't call deinit since the prof_func wasn't allocated. */
4093 /* Allocate the global resource ids */
4094 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
4096 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
4101 * Only initialize the app global resources if a shared session was
4104 if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
4105 rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
4107 BNXT_TF_DBG(ERR, "Failed to init app glb resources\n");
4112 /* Allocate the generic table list */
4113 rc = ulp_mapper_generic_tbl_list_init(data);
4115 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
4121 /* Ignore the return code in favor of returning the original error. */
4122 ulp_mapper_deinit(ulp_ctx);
4127 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
4129 struct bnxt_ulp_mapper_data *data;
4134 "Failed to acquire ulp context, so data may not be released.\n");
4138 data = (struct bnxt_ulp_mapper_data *)
4139 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
4141 /* Go ahead and return since there is no allocated data. */
4142 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
4146 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
4148 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
4149 /* Free the mapper data regardless of errors. */
4150 goto free_mapper_data;
4153 /* Free the global resource info table entries */
4154 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
4157 /* Free the generic table */
4158 (void)ulp_mapper_generic_tbl_list_deinit(data);
4161 /* Reset the data pointer within the ulp_ctx. */
4162 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);