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"
23 static uint8_t mapper_fld_zeros[16] = { 0 };
25 static uint8_t mapper_fld_ones[16] = {
26 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
27 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
30 static uint8_t mapper_fld_one[16] = {
31 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
32 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
36 ulp_mapper_tmpl_name_str(enum bnxt_ulp_template_type tmpl_type)
39 case BNXT_ULP_TEMPLATE_TYPE_CLASS:
41 case BNXT_ULP_TEMPLATE_TYPE_ACTION:
44 return "invalid template type";
48 static struct bnxt_ulp_glb_resource_info *
49 ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
53 *num_entries = BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
54 return ulp_glb_resource_tbl;
58 * Read the global resource from the mapper global resource list
60 * The regval is always returned in big-endian.
62 * returns 0 on success
65 ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
71 if (!mapper_data || !regval || !shared ||
72 dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_RF_IDX_LAST)
75 *regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
76 *shared = mapper_data->glb_res_tbl[dir][idx].shared;
81 * Write a global resource to the mapper global resource list
83 * The regval value must be in big-endian.
85 * return 0 on success.
88 ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
89 struct bnxt_ulp_glb_resource_info *res,
90 uint64_t regval, bool shared)
92 struct bnxt_ulp_mapper_glb_resource_entry *ent;
94 /* validate the arguments */
95 if (!data || res->direction >= TF_DIR_MAX ||
96 res->glb_regfile_index >= BNXT_ULP_GLB_RF_IDX_LAST)
99 /* write to the mapper data */
100 ent = &data->glb_res_tbl[res->direction][res->glb_regfile_index];
101 ent->resource_func = res->resource_func;
102 ent->resource_type = res->resource_type;
103 ent->resource_hndl = regval;
104 ent->shared = shared;
109 * Internal function to allocate identity resource and store it in mapper data.
111 * returns 0 on success
114 ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
115 struct bnxt_ulp_mapper_data *mapper_data,
116 struct bnxt_ulp_glb_resource_info *glb_res)
118 struct tf_alloc_identifier_parms iparms = { 0 };
119 struct tf_free_identifier_parms fparms;
124 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
128 iparms.ident_type = glb_res->resource_type;
129 iparms.dir = glb_res->direction;
131 /* Allocate the Identifier using tf api */
132 rc = tf_alloc_identifier(tfp, &iparms);
134 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
135 tf_dir_2_str(iparms.dir),
140 /* entries are stored as big-endian format */
141 regval = tfp_cpu_to_be_64((uint64_t)iparms.id);
143 * write to the mapper global resource
144 * Shared resources are never allocated through this method, so the
145 * shared flag is always false.
147 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
149 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
150 /* Free the identifier when update failed */
151 fparms.dir = iparms.dir;
152 fparms.ident_type = iparms.ident_type;
153 fparms.id = iparms.id;
154 tf_free_identifier(tfp, &fparms);
161 * Internal function to allocate index tbl resource and store it in mapper data.
163 * returns 0 on success
166 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
167 struct bnxt_ulp_mapper_data *mapper_data,
168 struct bnxt_ulp_glb_resource_info *glb_res)
170 struct tf_alloc_tbl_entry_parms aparms = { 0 };
171 struct tf_free_tbl_entry_parms free_parms = { 0 };
174 uint32_t tbl_scope_id;
177 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
181 /* Get the scope id */
182 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &tbl_scope_id);
184 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
188 aparms.type = glb_res->resource_type;
189 aparms.dir = glb_res->direction;
190 aparms.search_enable = 0;
191 aparms.tbl_scope_id = tbl_scope_id;
193 /* Allocate the index tbl using tf api */
194 rc = tf_alloc_tbl_entry(tfp, &aparms);
196 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
197 tf_dir_2_str(aparms.dir), aparms.type);
201 /* entries are stored as big-endian format */
202 regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
204 * write to the mapper global resource
205 * Shared resources are never allocated through this method, so the
206 * shared flag is always false.
208 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
210 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
211 /* Free the identifier when update failed */
212 free_parms.dir = aparms.dir;
213 free_parms.type = aparms.type;
214 free_parms.idx = aparms.idx;
215 tf_free_tbl_entry(tfp, &free_parms);
222 ulp_mapper_glb_field_tbl_get(struct bnxt_ulp_mapper_parms *parms,
228 t_idx = parms->app_id << (BNXT_ULP_APP_ID_SHIFT +
229 BNXT_ULP_HDR_SIG_ID_SHIFT +
230 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
231 t_idx += parms->class_tid << (BNXT_ULP_HDR_SIG_ID_SHIFT +
232 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
233 t_idx += ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_HDR_SIG_ID) <<
234 BNXT_ULP_GLB_FIELD_TBL_SHIFT;
237 if (t_idx >= BNXT_ULP_GLB_FIELD_TBL_SIZE) {
238 BNXT_TF_DBG(ERR, "Invalid hdr field index %x:%x:%x\n",
239 parms->class_tid, t_idx, operand);
241 return -EINVAL; /* error */
243 *val = ulp_glb_field_tbl[t_idx];
248 * Get the size of the action property for a given index.
250 * idx [in] The index for the action property
252 * returns the size of the action property.
255 ulp_mapper_act_prop_size_get(uint32_t idx)
257 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
259 return ulp_act_prop_map_table[idx];
262 static struct bnxt_ulp_mapper_cond_info *
263 ulp_mapper_tmpl_reject_list_get(struct bnxt_ulp_mapper_parms *mparms,
266 enum bnxt_ulp_cond_list_opc *opc)
269 const struct bnxt_ulp_template_device_tbls *dev_tbls;
271 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
272 *num_tbls = dev_tbls->tmpl_list[tid].reject_info.cond_nums;
273 *opc = dev_tbls->tmpl_list[tid].reject_info.cond_list_opcode;
274 idx = dev_tbls->tmpl_list[tid].reject_info.cond_start_idx;
276 return &dev_tbls->cond_list[idx];
279 static struct bnxt_ulp_mapper_cond_info *
280 ulp_mapper_tbl_execute_list_get(struct bnxt_ulp_mapper_parms *mparms,
281 struct bnxt_ulp_mapper_tbl_info *tbl,
283 enum bnxt_ulp_cond_list_opc *opc)
286 const struct bnxt_ulp_template_device_tbls *dev_tbls;
288 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
289 *num_tbls = tbl->execute_info.cond_nums;
290 *opc = tbl->execute_info.cond_list_opcode;
291 idx = tbl->execute_info.cond_start_idx;
293 return &dev_tbls->cond_list[idx];
297 * Get a list of classifier tables that implement the flow
298 * Gets a device dependent list of tables that implement the class template id
300 * mparms [in] The mappers parms with data related to the flow.
302 * tid [in] The template id that matches the flow
304 * num_tbls [out] The number of classifier tables in the returned array
306 * returns An array of classifier tables to implement the flow, or NULL on
309 static struct bnxt_ulp_mapper_tbl_info *
310 ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
315 const struct bnxt_ulp_template_device_tbls *dev_tbls;
317 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
319 idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
320 *num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
322 return &dev_tbls->tbl_list[idx];
326 * Get the list of key fields that implement the flow.
328 * mparms [in] The mapper parms with information about the flow
330 * tbl [in] A single table instance to get the key fields from
332 * num_flds [out] The number of key fields in the returned array
334 * Returns array of Key fields, or NULL on error.
336 static struct bnxt_ulp_mapper_key_info *
337 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
338 struct bnxt_ulp_mapper_tbl_info *tbl,
342 const struct bnxt_ulp_template_device_tbls *dev_tbls;
344 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
345 if (!dev_tbls->key_info_list) {
350 idx = tbl->key_start_idx;
351 *num_flds = tbl->key_num_fields;
353 return &dev_tbls->key_info_list[idx];
357 * Get the list of data fields that implement the flow.
359 * mparms [in] The mapper parms with information about the flow
361 * tbl [in] A single table instance to get the data fields from
363 * num_flds [out] The number of data fields in the returned array.
365 * num_encap_flds [out] The number of encap fields in the returned array.
367 * Returns array of data fields, or NULL on error.
369 static struct bnxt_ulp_mapper_field_info *
370 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
371 struct bnxt_ulp_mapper_tbl_info *tbl,
373 uint32_t *num_encap_flds)
376 const struct bnxt_ulp_template_device_tbls *dev_tbls;
378 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
379 if (!dev_tbls->result_field_list) {
385 idx = tbl->result_start_idx;
386 *num_flds = tbl->result_num_fields;
387 *num_encap_flds = tbl->encap_num_fields;
389 return &dev_tbls->result_field_list[idx];
393 * Get the list of ident fields that implement the flow
395 * tbl [in] A single table instance to get the ident fields from
397 * num_flds [out] The number of ident fields in the returned array
399 * returns array of ident fields, or NULL on error
401 static struct bnxt_ulp_mapper_ident_info *
402 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
403 struct bnxt_ulp_mapper_tbl_info *tbl,
407 const struct bnxt_ulp_template_device_tbls *dev_tbls;
409 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
410 if (!dev_tbls->ident_list) {
415 idx = tbl->ident_start_idx;
416 *num_flds = tbl->ident_nums;
418 return &dev_tbls->ident_list[idx];
421 static inline int32_t
422 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp __rte_unused,
424 struct ulp_flow_db_res_params *res)
426 struct tf_free_tcam_entry_parms fparms = {
427 .dir = res->direction,
428 .tcam_tbl_type = res->resource_type,
429 .idx = (uint16_t)res->resource_hndl
432 return tf_free_tcam_entry(tfp, &fparms);
435 static inline int32_t
436 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
438 struct ulp_flow_db_res_params *res)
440 struct tf_free_tbl_entry_parms fparms = {
441 .dir = res->direction,
442 .type = res->resource_type,
443 .idx = (uint32_t)res->resource_hndl
447 * Just get the table scope, it will be ignored if not necessary
448 * by the tf_free_tbl_entry
450 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
452 return tf_free_tbl_entry(tfp, &fparms);
455 static inline int32_t
456 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
458 struct ulp_flow_db_res_params *res)
460 struct tf_delete_em_entry_parms fparms = { 0 };
463 fparms.dir = res->direction;
464 fparms.flow_handle = res->resource_hndl;
466 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
468 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
472 return tf_delete_em_entry(tfp, &fparms);
475 static inline int32_t
476 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
478 struct ulp_flow_db_res_params *res)
480 struct tf_free_identifier_parms fparms = {
481 .dir = res->direction,
482 .ident_type = res->resource_type,
483 .id = (uint16_t)res->resource_hndl
486 return tf_free_identifier(tfp, &fparms);
489 static inline int32_t
490 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
491 struct ulp_flow_db_res_params *res)
493 return ulp_mark_db_mark_del(ulp,
498 static inline int32_t
499 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
501 struct ulp_flow_db_res_params *res)
503 uint32_t idx, child_fid = 0, parent_idx;
504 struct bnxt_ulp_flow_db *flow_db;
506 parent_idx = (uint32_t)res->resource_hndl;
508 /* check the validity of the parent fid */
509 if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
511 BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
515 /* Clear all the child flows parent index */
516 flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
517 while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
519 /* update the child flows resource handle */
520 if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
522 BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
528 /* free the parent entry in the parent table flow */
529 if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
530 BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
536 static inline int32_t
537 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
539 struct ulp_flow_db_res_params *res)
543 parent_fid = (uint32_t)res->resource_hndl;
545 return 0; /* Already freed - orphan child*/
547 /* reset the child flow bitset*/
548 if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
549 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
550 parent_fid, child_fid);
557 * Process the flow database opcode alloc action.
558 * returns 0 on success
561 ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
562 struct bnxt_ulp_mapper_tbl_info *tbl)
568 /* allocate a new fid */
569 rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
570 BNXT_ULP_FDB_TYPE_RID,
574 "Unable to allocate flow table entry\n");
577 /* Store the allocated fid in regfile*/
579 rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
580 tfp_cpu_to_be_64(val64));
582 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
584 ulp_flow_db_fid_free(parms->ulp_ctx,
585 BNXT_ULP_FDB_TYPE_RID, rid);
592 * Process the flow database opcode action.
593 * returns 0 on success.
596 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
597 struct bnxt_ulp_mapper_tbl_info *tbl,
598 struct ulp_flow_db_res_params *fid_parms)
602 enum bnxt_ulp_fdb_type flow_type;
605 switch (tbl->fdb_opcode) {
606 case BNXT_ULP_FDB_OPC_PUSH_FID:
607 push_fid = parms->fid;
608 flow_type = parms->flow_type;
610 case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
611 /* get the fid from the regfile */
612 rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
615 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
619 /* Use the extracted fid to update the flow resource */
620 push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
621 flow_type = BNXT_ULP_FDB_TYPE_RID;
624 return rc; /* Nothing to be done */
627 /* Add the resource to the flow database */
628 rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
629 push_fid, fid_parms);
631 BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
637 * Process the flow database opcode action.
638 * returns 0 on success.
641 ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms,
642 struct bnxt_ulp_mapper_tbl_info *tbl,
647 switch (tbl->pri_opcode) {
648 case BNXT_ULP_PRI_OPC_NOT_USED:
651 case BNXT_ULP_PRI_OPC_CONST:
652 *priority = tbl->pri_operand;
654 case BNXT_ULP_PRI_OPC_APP_PRI:
655 *priority = parms->app_priority;
658 BNXT_TF_DBG(ERR, "Priority opcode not supported %d\n",
667 * Process the identifier list in the given table.
668 * Extract the ident from the table entry and
669 * write it to the reg file.
670 * returns 0 on success.
673 ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
674 struct bnxt_ulp_mapper_tbl_info *tbl,
676 uint32_t byte_data_size,
677 enum bnxt_ulp_byte_order byte_order)
679 struct bnxt_ulp_mapper_ident_info *idents;
680 uint32_t i, num_idents = 0;
683 /* validate the null arguments */
685 BNXT_TF_DBG(ERR, "invalid argument\n");
689 /* Get the ident list and process each one */
690 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
692 for (i = 0; i < num_idents; i++) {
693 /* check the size of the buffer for validation */
694 if ((idents[i].ident_bit_pos + idents[i].ident_bit_size) >
695 ULP_BYTE_2_BITS(byte_data_size) ||
696 idents[i].ident_bit_size > ULP_BYTE_2_BITS(sizeof(val64))) {
697 BNXT_TF_DBG(ERR, "invalid offset or length %x:%x:%x\n",
698 idents[i].ident_bit_pos,
699 idents[i].ident_bit_size,
704 if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
705 ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
707 idents[i].ident_bit_pos,
708 idents[i].ident_bit_size);
710 ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
711 idents[i].ident_bit_pos,
712 idents[i].ident_bit_size);
714 /* Write it to the regfile, val64 is already in big-endian*/
715 if (ulp_regfile_write(parms->regfile,
716 idents[i].regfile_idx, val64)) {
717 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
718 idents[i].regfile_idx);
726 * Process the identifier instruction and either store it in the flow database
727 * or return it in the val (if not NULL) on success. If val is NULL, the
728 * identifier is to be stored in the flow database.
731 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
732 struct bnxt_ulp_mapper_tbl_info *tbl,
733 struct bnxt_ulp_mapper_ident_info *ident,
736 struct ulp_flow_db_res_params fid_parms;
739 struct tf_alloc_identifier_parms iparms = { 0 };
740 struct tf_free_identifier_parms free_parms = { 0 };
744 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
746 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
750 idx = ident->regfile_idx;
752 iparms.ident_type = ident->ident_type;
753 iparms.dir = tbl->direction;
755 rc = tf_alloc_identifier(tfp, &iparms);
757 BNXT_TF_DBG(ERR, "Alloc ident %s:%s failed.\n",
758 tf_dir_2_str(iparms.dir),
759 tf_ident_2_str(iparms.ident_type));
763 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
764 if (ulp_regfile_write(parms->regfile, idx, id)) {
765 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
767 /* Need to free the identifier, so goto error */
771 /* Link the resource to the flow in the flow db */
773 memset(&fid_parms, 0, sizeof(fid_parms));
774 fid_parms.direction = tbl->direction;
775 fid_parms.resource_func = ident->resource_func;
776 fid_parms.resource_type = ident->ident_type;
777 fid_parms.resource_hndl = iparms.id;
778 fid_parms.critical_resource = tbl->critical_resource;
780 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
782 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
784 /* Need to free the identifier, so goto error */
793 /* Need to free the identifier */
794 free_parms.dir = tbl->direction;
795 free_parms.ident_type = ident->ident_type;
796 free_parms.id = iparms.id;
798 (void)tf_free_identifier(tfp, &free_parms);
800 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
802 tf_dir_2_str(tbl->direction));
807 * Process the identifier instruction and extract it from result blob.
808 * Increment the identifier reference count and store it in the flow database.
811 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
812 struct bnxt_ulp_mapper_tbl_info *tbl,
813 struct bnxt_ulp_mapper_ident_info *ident,
814 struct ulp_blob *res_blob)
816 struct ulp_flow_db_res_params fid_parms;
819 struct tf_search_identifier_parms sparms = { 0 };
820 struct tf_free_identifier_parms free_parms = { 0 };
824 /* Get the tfp from ulp context */
825 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
827 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
831 /* Extract the index from the result blob */
832 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
833 ident->ident_bit_pos, ident->ident_bit_size);
835 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
839 /* populate the search params and search identifier shadow table */
840 sparms.ident_type = ident->ident_type;
841 sparms.dir = tbl->direction;
842 /* convert the idx into cpu format */
843 sparms.search_id = tfp_be_to_cpu_32(idx);
845 /* Search identifier also increase the reference count */
846 rc = tf_search_identifier(tfp, &sparms);
848 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
849 tf_dir_2_str(sparms.dir),
850 tf_ident_2_str(sparms.ident_type),
855 /* Write it to the regfile */
856 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
857 if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
858 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
860 /* Need to free the identifier, so goto error */
864 /* Link the resource to the flow in the flow db */
865 memset(&fid_parms, 0, sizeof(fid_parms));
866 fid_parms.direction = tbl->direction;
867 fid_parms.resource_func = ident->resource_func;
868 fid_parms.resource_type = ident->ident_type;
869 fid_parms.resource_hndl = sparms.search_id;
870 fid_parms.critical_resource = tbl->critical_resource;
871 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
873 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
875 /* Need to free the identifier, so goto error */
882 /* Need to free the identifier */
883 free_parms.dir = tbl->direction;
884 free_parms.ident_type = ident->ident_type;
885 free_parms.id = sparms.search_id;
886 (void)tf_free_identifier(tfp, &free_parms);
887 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
889 tf_dir_2_str(tbl->direction), sparms.search_id);
894 ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
899 enum bnxt_ulp_port_table port_data = val16;
902 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
903 if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
905 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
909 case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
910 if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
912 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
916 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
917 if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
919 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
924 BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
931 ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
932 enum bnxt_ulp_field_src field_src,
941 struct bnxt_ulp_mapper_data *m;
943 uint32_t port_id, val_size, field_size;
944 uint16_t idx, size_idx, offset;
945 uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
952 /* Perform the action */
954 case BNXT_ULP_FIELD_SRC_ZERO:
955 *val = mapper_fld_zeros;
957 case BNXT_ULP_FIELD_SRC_CONST:
960 case BNXT_ULP_FIELD_SRC_ONES:
961 *val = mapper_fld_ones;
964 case BNXT_ULP_FIELD_SRC_CF:
965 if (!ulp_operand_read(field_opr,
966 (uint8_t *)&idx, sizeof(uint16_t))) {
967 BNXT_TF_DBG(ERR, "CF operand read failed\n");
970 idx = tfp_be_to_cpu_16(idx);
971 if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint32_t)) {
972 BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
976 buffer = (uint8_t *)&parms->comp_fld[idx];
977 *val = &buffer[sizeof(uint32_t) - bytelen];
978 *value = ULP_COMP_FLD_IDX_RD(parms, idx);
980 case BNXT_ULP_FIELD_SRC_RF:
981 if (!ulp_operand_read(field_opr,
982 (uint8_t *)&idx, sizeof(uint16_t))) {
983 BNXT_TF_DBG(ERR, "RF operand read failed\n");
987 idx = tfp_be_to_cpu_16(idx);
988 /* Uninitialized regfile entries return 0 */
989 if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
990 sizeof(uint64_t) < bytelen) {
991 BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
995 buffer = (uint8_t *)&parms->regfile->entry[idx].data;
996 *val = &buffer[sizeof(uint64_t) - bytelen];
997 *value = tfp_be_to_cpu_64(lregval);
999 case BNXT_ULP_FIELD_SRC_ACT_PROP:
1000 if (!ulp_operand_read(field_opr,
1001 (uint8_t *)&idx, sizeof(uint16_t))) {
1002 BNXT_TF_DBG(ERR, "Action operand read failed\n");
1005 idx = tfp_be_to_cpu_16(idx);
1006 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1007 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
1010 buffer = &parms->act_prop->act_details[idx];
1011 field_size = ulp_mapper_act_prop_size_get(idx);
1012 if (bytelen > field_size) {
1013 BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
1017 *val = &buffer[field_size - bytelen];
1019 case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
1020 if (!ulp_operand_read(field_opr,
1021 (uint8_t *)&idx, sizeof(uint16_t))) {
1022 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1025 idx = tfp_be_to_cpu_16(idx);
1027 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1028 BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
1031 *val = &parms->act_prop->act_details[idx];
1033 /* get the size index next */
1034 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1035 (uint8_t *)&size_idx, sizeof(uint16_t))) {
1036 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1039 size_idx = tfp_be_to_cpu_16(size_idx);
1040 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1041 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
1044 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
1046 val_size = tfp_be_to_cpu_32(val_size);
1047 *val_len = ULP_BYTE_2_BITS(val_size);
1049 case BNXT_ULP_FIELD_SRC_GLB_RF:
1050 if (!ulp_operand_read(field_opr,
1051 (uint8_t *)&idx, sizeof(uint16_t))) {
1052 BNXT_TF_DBG(ERR, "Global regfile read failed\n");
1055 idx = tfp_be_to_cpu_16(idx);
1056 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1057 dir, idx, &lregval, &shared) ||
1058 sizeof(uint64_t) < bytelen) {
1059 BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
1063 m = parms->mapper_data;
1064 buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
1065 *val = &buffer[sizeof(uint64_t) - bytelen];
1066 *value = tfp_be_to_cpu_64(lregval);
1068 case BNXT_ULP_FIELD_SRC_HF:
1069 case BNXT_ULP_FIELD_SRC_SUB_HF:
1070 if (!ulp_operand_read(field_opr,
1071 (uint8_t *)&idx, sizeof(uint16_t))) {
1072 BNXT_TF_DBG(ERR, "Header field read failed\n");
1075 idx = tfp_be_to_cpu_16(idx);
1076 /* get the index from the global field list */
1077 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1078 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1083 buffer = parms->hdr_field[bit].spec;
1085 buffer = parms->hdr_field[bit].mask;
1087 field_size = parms->hdr_field[bit].size;
1088 if (bytelen > field_size) {
1089 BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
1093 if (field_src == BNXT_ULP_FIELD_SRC_HF) {
1094 *val = &buffer[field_size - bytelen];
1096 /* get the offset next */
1097 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1099 sizeof(uint16_t))) {
1100 BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
1103 offset = tfp_be_to_cpu_16(offset);
1104 offset = ULP_BITS_2_BYTE_NR(offset);
1105 if ((offset + bytelen) > field_size) {
1106 BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
1109 *val = &buffer[offset];
1112 case BNXT_ULP_FIELD_SRC_HDR_BIT:
1113 if (!ulp_operand_read(field_opr,
1114 (uint8_t *)&lregval, sizeof(uint64_t))) {
1115 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1118 lregval = tfp_be_to_cpu_64(lregval);
1119 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
1120 *val = mapper_fld_one;
1123 *val = mapper_fld_zeros;
1126 case BNXT_ULP_FIELD_SRC_ACT_BIT:
1127 if (!ulp_operand_read(field_opr,
1128 (uint8_t *)&lregval, sizeof(uint64_t))) {
1129 BNXT_TF_DBG(ERR, "Action bit read failed\n");
1132 lregval = tfp_be_to_cpu_64(lregval);
1133 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
1134 *val = mapper_fld_one;
1137 *val = mapper_fld_zeros;
1140 case BNXT_ULP_FIELD_SRC_FIELD_BIT:
1141 if (!ulp_operand_read(field_opr,
1142 (uint8_t *)&idx, sizeof(uint16_t))) {
1143 BNXT_TF_DBG(ERR, "Field bit read failed\n");
1146 idx = tfp_be_to_cpu_16(idx);
1147 /* get the index from the global field list */
1148 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1149 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1153 if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
1154 *val = mapper_fld_one;
1157 *val = mapper_fld_zeros;
1160 case BNXT_ULP_FIELD_SRC_PORT_TABLE:
1161 /* The port id is present in the comp field list */
1162 port_id = ULP_COMP_FLD_IDX_RD(parms,
1163 BNXT_ULP_CF_IDX_DEV_PORT_ID);
1164 /* get the port table enum */
1165 if (!ulp_operand_read(field_opr,
1166 (uint8_t *)&idx, sizeof(uint16_t))) {
1167 BNXT_TF_DBG(ERR, "Port table enum read failed\n");
1170 idx = tfp_be_to_cpu_16(idx);
1171 if (ulp_mapper_field_port_db_process(parms, port_id, idx,
1173 BNXT_TF_DBG(ERR, "field port table failed\n");
1176 case BNXT_ULP_FIELD_SRC_SKIP:
1179 case BNXT_ULP_FIELD_SRC_REJECT:
1182 BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
1188 static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
1196 bytelen = ULP_BITS_2_BYTE(bitlen);
1197 if (bytelen == sizeof(uint8_t)) {
1198 *output = *((uint8_t *)buffer);
1199 } else if (bytelen == sizeof(uint16_t)) {
1200 val_16 = *((uint16_t *)buffer);
1201 *output = tfp_be_to_cpu_16(val_16);
1202 } else if (bytelen == sizeof(uint32_t)) {
1203 val_32 = *((uint32_t *)buffer);
1204 *output = tfp_be_to_cpu_32(val_32);
1205 } else if (bytelen == sizeof(val_64)) {
1206 val_64 = *((uint64_t *)buffer);
1207 *output = tfp_be_to_cpu_64(val_64);
1215 static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
1216 struct ulp_blob *blob,
1221 if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
1222 if (ulp_blob_pad_push(blob, val_len) < 0) {
1223 BNXT_TF_DBG(ERR, "too large for blob\n");
1226 } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
1227 if (ulp_blob_push_encap(blob, val, val_len) < 0) {
1228 BNXT_TF_DBG(ERR, "encap blob push failed\n");
1232 if (!ulp_blob_push(blob, val, val_len)) {
1233 BNXT_TF_DBG(ERR, "push of val1 failed\n");
1242 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
1244 struct bnxt_ulp_mapper_field_info *fld,
1245 struct ulp_blob *blob,
1249 uint16_t write_idx = blob->write_idx;
1250 uint8_t *val = NULL, *val1, *val2, *val3;
1251 uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
1252 uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
1253 uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
1254 uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
1255 uint64_t value1 = 0, value2 = 0, value3 = 0;
1258 /* prepare the field source and values */
1259 switch (fld->field_opc) {
1260 case BNXT_ULP_FIELD_OPC_SRC1:
1263 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1266 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1267 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1275 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1276 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1277 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1278 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1279 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1280 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1290 /* process the src1 opcode */
1292 if (ulp_mapper_field_src_process(parms, fld->field_src1,
1293 fld->field_opr1, dir, is_key,
1294 fld->field_bit_size, &val1,
1295 &val1_len, &value1)) {
1296 BNXT_TF_DBG(ERR, "fld src1 process failed\n");
1300 if (ulp_mapper_field_buffer_eval(val1, val1_len,
1302 BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
1308 /* for "if then clause" set the correct process */
1309 if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
1316 /* process src2 opcode */
1318 if (ulp_mapper_field_src_process(parms, fld->field_src2,
1319 fld->field_opr2, dir, is_key,
1320 fld->field_bit_size, &val2,
1321 &val2_len, &value2)) {
1322 BNXT_TF_DBG(ERR, "fld src2 process failed\n");
1326 if (ulp_mapper_field_buffer_eval(val2, val2_len,
1328 BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
1334 /* process src3 opcode */
1336 if (ulp_mapper_field_src_process(parms, fld->field_src3,
1337 fld->field_opr3, dir, is_key,
1338 fld->field_bit_size, &val3,
1339 &val3_len, &value3)) {
1340 BNXT_TF_DBG(ERR, "fld src3 process failed\n");
1344 if (ulp_mapper_field_buffer_eval(val3, val3_len,
1346 BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
1352 val_len = fld->field_bit_size;
1353 /* process the field opcodes */
1354 switch (fld->field_opc) {
1355 case BNXT_ULP_FIELD_OPC_SRC1:
1356 rc = ulp_mapper_field_blob_write(fld->field_src1,
1357 blob, val1, val1_len, &val);
1360 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1362 rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
1363 val2, val2_len, &val);
1366 rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
1367 val3, val3_len, &val);
1371 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1372 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1373 val_int = val1_int + val2_int;
1374 val_int = tfp_cpu_to_be_64(val_int);
1375 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1379 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1380 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1381 val_int = val1_int - val2_int;
1382 val_int = tfp_cpu_to_be_64(val_int);
1383 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1387 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1388 val_int = val1_int | val2_int;
1389 val_int = tfp_cpu_to_be_64(val_int);
1390 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1394 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1395 val_int = val1_int | val2_int | val3_int;
1396 val_int = tfp_cpu_to_be_64(val_int);
1397 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1401 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1402 val_int = val1_int & val2_int;
1403 val_int = tfp_cpu_to_be_64(val_int);
1404 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1408 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1409 val_int = val1_int & (val2_int | val3_int);
1410 val_int = tfp_cpu_to_be_64(val_int);
1411 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1415 case BNXT_ULP_FIELD_OPC_SKIP:
1418 BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
1425 BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
1426 fld->description, (val) ? write_idx : 0, val_len);
1431 * Result table process and fill the result blob.
1432 * data [out] - the result blob data
1435 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
1436 struct bnxt_ulp_mapper_tbl_info *tbl,
1437 struct ulp_blob *data,
1440 struct bnxt_ulp_mapper_field_info *dflds;
1441 uint32_t i, num_flds = 0, encap_flds = 0;
1444 /* Get the result field list */
1445 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
1448 /* validate the result field list counts */
1449 if ((tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1450 (!num_flds && !encap_flds)) || !dflds ||
1451 (tbl->resource_func != BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1452 (!num_flds || encap_flds))) {
1453 BNXT_TF_DBG(ERR, "Failed to get data fields %x:%x\n",
1454 num_flds, encap_flds);
1458 /* process the result fields, loop through them */
1459 for (i = 0; i < (num_flds + encap_flds); i++) {
1460 /* set the swap index if encap swap bit is enabled */
1461 if (parms->device_params->encap_byte_swap && encap_flds &&
1463 ulp_blob_encap_swap_idx_set(data);
1465 /* Process the result fields */
1466 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1467 &dflds[i], data, 0, name);
1469 BNXT_TF_DBG(ERR, "data field failed\n");
1474 /* if encap bit swap is enabled perform the bit swap */
1475 if (parms->device_params->encap_byte_swap && encap_flds)
1476 ulp_blob_perform_encap_swap(data);
1482 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1483 struct bnxt_ulp_mapper_tbl_info *tbl,
1486 struct ulp_flow_db_res_params fid_parms;
1487 uint32_t mark, gfid, mark_flag;
1488 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1491 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1492 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1493 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1494 BNXT_ULP_ACT_BIT_MARK)))
1495 return rc; /* no need to perform gfid process */
1497 /* Get the mark id details from action property */
1498 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1500 mark = tfp_be_to_cpu_32(mark);
1502 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1503 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1505 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1508 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1511 fid_parms.direction = tbl->direction;
1512 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1513 fid_parms.critical_resource = tbl->critical_resource;
1514 fid_parms.resource_type = mark_flag;
1515 fid_parms.resource_hndl = gfid;
1516 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1518 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1523 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1524 struct bnxt_ulp_mapper_tbl_info *tbl)
1526 struct ulp_flow_db_res_params fid_parms;
1527 uint32_t act_idx, mark, mark_flag;
1529 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1532 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1533 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1534 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1535 BNXT_ULP_ACT_BIT_MARK)))
1536 return rc; /* no need to perform mark action process */
1538 /* Get the mark id details from action property */
1539 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1541 mark = tfp_be_to_cpu_32(mark);
1543 if (!ulp_regfile_read(parms->regfile,
1544 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1546 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1549 act_idx = tfp_be_to_cpu_64(val64);
1550 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1551 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1554 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1557 fid_parms.direction = tbl->direction;
1558 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1559 fid_parms.critical_resource = tbl->critical_resource;
1560 fid_parms.resource_type = mark_flag;
1561 fid_parms.resource_hndl = act_idx;
1562 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1564 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1569 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1570 struct bnxt_ulp_mapper_tbl_info *tbl)
1572 struct ulp_flow_db_res_params fid_parms;
1573 uint32_t act_idx, mark, mark_flag;
1575 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1578 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1579 mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
1580 return rc; /* no need to perform mark action process */
1582 /* Get the mark id details from the computed field of dev port id */
1583 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1585 /* Get the main action pointer */
1586 if (!ulp_regfile_read(parms->regfile,
1587 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1589 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1592 act_idx = tfp_be_to_cpu_64(val64);
1594 /* Set the mark flag to local fid and vfr flag */
1595 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1597 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1600 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1603 fid_parms.direction = tbl->direction;
1604 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1605 fid_parms.critical_resource = tbl->critical_resource;
1606 fid_parms.resource_type = mark_flag;
1607 fid_parms.resource_hndl = act_idx;
1608 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1610 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1614 /* Tcam table scan the identifier list and allocate each identifier */
1616 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1617 struct bnxt_ulp_mapper_tbl_info *tbl)
1619 struct bnxt_ulp_mapper_ident_info *idents;
1620 uint32_t num_idents;
1623 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1624 for (i = 0; i < num_idents; i++) {
1625 if (ulp_mapper_ident_process(parms, tbl,
1633 * Tcam table scan the identifier list and extract the identifier from
1637 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1638 struct bnxt_ulp_mapper_tbl_info *tbl,
1639 struct ulp_blob *data)
1641 struct bnxt_ulp_mapper_ident_info *idents;
1642 uint32_t num_idents = 0, i;
1646 * Extract the listed identifiers from the result field,
1647 * no need to allocate them.
1649 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1650 for (i = 0; i < num_idents; i++) {
1651 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1653 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1660 /* Internal function to write the tcam entry */
1662 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1663 struct bnxt_ulp_mapper_tbl_info *tbl,
1664 struct ulp_blob *key,
1665 struct ulp_blob *mask,
1666 struct ulp_blob *data,
1669 struct tf_set_tcam_entry_parms sparms = { 0 };
1674 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1676 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1680 sparms.dir = tbl->direction;
1681 sparms.tcam_tbl_type = tbl->resource_type;
1683 sparms.key = ulp_blob_data_get(key, &tmplen);
1684 sparms.key_sz_in_bits = tmplen;
1685 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1686 sparms.result = ulp_blob_data_get(data, &tmplen);
1687 sparms.result_sz_in_bits = tmplen;
1688 if (tf_set_tcam_entry(tfp, &sparms)) {
1689 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1690 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1691 tf_dir_2_str(sparms.dir), sparms.idx);
1696 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1698 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1706 * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
1708 * parms [in] The mappers parms with data related to the flow.
1710 * key [in] The original key to be transformed
1712 * mask [in] The original mask to be transformed
1714 * tkey [in/out] The transformed key
1716 * tmask [in/out] The transformed mask
1718 * returns zero on success, non-zero on failure
1721 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
1722 struct ulp_blob *key,
1723 struct ulp_blob *mask,
1724 struct ulp_blob *tkey,
1725 struct ulp_blob *tmask)
1727 uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
1728 uint32_t cword, i, rc;
1732 slice_width = dparms->wc_slice_width;
1733 clen = dparms->wc_ctl_size_bits;
1734 max_slices = dparms->wc_max_slices;
1735 blen = ulp_blob_data_len_get(key);
1737 /* Get the length of the key based on number of slices and width */
1740 while (tlen < blen &&
1741 num_slices <= max_slices) {
1742 num_slices = num_slices << 1;
1746 if (num_slices > max_slices) {
1747 BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
1751 /* The key/mask may not be on a natural slice boundary, pad it */
1753 if (ulp_blob_pad_push(key, pad) < 0 ||
1754 ulp_blob_pad_push(mask, pad) < 0) {
1755 BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
1759 /* The new length accounts for the ctrl word length and num slices */
1760 tlen = tlen + clen * num_slices;
1761 if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
1762 !ulp_blob_init(tmask, tlen, mask->byte_order)) {
1763 BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
1767 /* Build the transformed key/mask */
1768 cword = dparms->wc_mode_list[num_slices - 1];
1769 cword = tfp_cpu_to_be_32(cword);
1771 for (i = 0; i < num_slices; i++) {
1772 val = ulp_blob_push_32(tkey, &cword, clen);
1774 BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
1777 val = ulp_blob_push_32(tmask, &cword, clen);
1779 BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
1782 rc = ulp_blob_append(tkey, key, offset, slice_width);
1784 BNXT_TF_DBG(ERR, "Key blob append failed\n");
1787 rc = ulp_blob_append(tmask, mask, offset, slice_width);
1789 BNXT_TF_DBG(ERR, "Mask blob append failed\n");
1792 offset += slice_width;
1795 /* The key/mask are byte reversed on every 4 byte chunk */
1796 ulp_blob_perform_byte_reverse(tkey, 4);
1797 ulp_blob_perform_byte_reverse(tmask, 4);
1802 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1803 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
1805 ulp_blob_perform_64B_word_swap(blob);
1806 ulp_blob_perform_64B_byte_swap(blob);
1810 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1811 struct bnxt_ulp_mapper_tbl_info *tbl)
1813 struct bnxt_ulp_mapper_key_info *kflds;
1814 struct ulp_blob okey, omask, data, update_data;
1815 struct ulp_blob tkey, tmask; /* transform key and mask */
1816 struct ulp_blob *key, *mask;
1817 uint32_t i, num_kflds;
1820 struct bnxt_ulp_device_params *dparms = parms->device_params;
1821 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1822 struct tf_search_tcam_entry_parms searchparms = { 0 };
1823 struct ulp_flow_db_res_params fid_parms = { 0 };
1824 struct tf_free_tcam_entry_parms free_parms = { 0 };
1826 uint16_t tmplen = 0;
1829 /* Set the key and mask to the original key and mask. */
1833 /* Skip this if table opcode is NOP */
1834 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
1835 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
1836 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
1841 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1843 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1847 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1848 if (!kflds || !num_kflds) {
1849 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1853 if (!ulp_blob_init(key, tbl->blob_key_bit_size, tbl->byte_order) ||
1854 !ulp_blob_init(mask, tbl->blob_key_bit_size, tbl->byte_order) ||
1855 !ulp_blob_init(&data, tbl->result_bit_size, dparms->byte_order) ||
1856 !ulp_blob_init(&update_data, tbl->result_bit_size,
1857 dparms->byte_order)) {
1858 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1862 /* create the key/mask */
1864 * NOTE: The WC table will require some kind of flag to handle the
1865 * mode bits within the key/mask
1867 for (i = 0; i < num_kflds; i++) {
1869 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1870 &kflds[i].field_info_spec,
1871 key, 1, "TCAM Key");
1873 BNXT_TF_DBG(ERR, "Key field set failed %s\n",
1874 kflds[i].field_info_spec.description);
1878 /* Setup the mask */
1879 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1880 &kflds[i].field_info_mask,
1881 mask, 0, "TCAM Mask");
1883 BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
1884 kflds[i].field_info_mask.description);
1889 /* For wild card tcam perform the post process to swap the blob */
1890 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
1891 if (dparms->dynamic_pad_en) {
1892 /* Sets up the slices for writing to the WC TCAM */
1893 rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
1899 "Failed to post proc WC entry.\n");
1902 /* Now need to use the transform Key/Mask */
1906 ulp_mapper_wc_tcam_tbl_post_process(key);
1907 ulp_mapper_wc_tcam_tbl_post_process(mask);
1912 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1913 /* allocate the tcam index */
1914 aparms.dir = tbl->direction;
1915 aparms.tcam_tbl_type = tbl->resource_type;
1916 aparms.key = ulp_blob_data_get(key, &tmplen);
1917 aparms.key_sz_in_bits = tmplen;
1918 aparms.mask = ulp_blob_data_get(mask, &tmplen);
1920 /* calculate the entry priority */
1921 rc = ulp_mapper_priority_opc_process(parms, tbl,
1924 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1928 rc = tf_alloc_tcam_entry(tfp, &aparms);
1930 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1937 * Searching before allocation to see if we already have an
1938 * entry. This allows re-use of a constrained resource.
1940 searchparms.dir = tbl->direction;
1941 searchparms.tcam_tbl_type = tbl->resource_type;
1942 searchparms.key = ulp_blob_data_get(key, &tmplen);
1943 searchparms.key_sz_in_bits = tbl->key_bit_size;
1944 searchparms.mask = ulp_blob_data_get(mask, &tmplen);
1945 searchparms.alloc = 1;
1946 searchparms.result = ulp_blob_data_get(&data, &tmplen);
1947 searchparms.result_sz_in_bits = tbl->result_bit_size;
1949 /* calculate the entry priority */
1950 rc = ulp_mapper_priority_opc_process(parms, tbl,
1951 &searchparms.priority);
1953 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1957 rc = tf_search_tcam_entry(tfp, &searchparms);
1959 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
1963 /* Successful search, check the result */
1964 if (searchparms.search_status == REJECT) {
1965 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
1968 idx = searchparms.idx;
1969 hit = searchparms.hit;
1972 /* Write the tcam index into the regfile*/
1973 if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
1974 (uint64_t)tfp_cpu_to_be_64(idx))) {
1975 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
1978 /* Need to free the tcam idx, so goto error */
1982 /* if it is miss then it is same as no search before alloc */
1983 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1984 /*Scan identifier list, allocate identifier and update regfile*/
1985 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
1986 /* Create the result blob */
1988 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
1990 /* write the tcam entry */
1992 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
1995 /*Scan identifier list, extract identifier and update regfile*/
1996 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
2001 /* Add the tcam index to the flow database */
2002 fid_parms.direction = tbl->direction;
2003 fid_parms.resource_func = tbl->resource_func;
2004 fid_parms.resource_type = tbl->resource_type;
2005 fid_parms.critical_resource = tbl->critical_resource;
2006 fid_parms.resource_hndl = idx;
2007 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2009 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2011 /* Need to free the identifier, so goto error */
2017 free_parms.dir = tbl->direction;
2018 free_parms.tcam_tbl_type = tbl->resource_type;
2019 free_parms.idx = idx;
2020 trc = tf_free_tcam_entry(tfp, &free_parms);
2022 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
2023 tbl->resource_type, tbl->direction, idx);
2028 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2029 struct bnxt_ulp_mapper_tbl_info *tbl)
2031 struct bnxt_ulp_mapper_key_info *kflds;
2032 struct ulp_blob key, data;
2033 uint32_t i, num_kflds;
2035 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2036 struct ulp_flow_db_res_params fid_parms = { 0 };
2037 struct tf_insert_em_entry_parms iparms = { 0 };
2038 struct tf_delete_em_entry_parms free_parms = { 0 };
2039 enum bnxt_ulp_flow_mem_type mtype;
2040 struct bnxt_ulp_device_params *dparms = parms->device_params;
2045 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2047 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
2051 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2052 if (!kflds || !num_kflds) {
2053 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2057 /* Initialize the key/result blobs */
2058 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
2060 !ulp_blob_init(&data, tbl->result_bit_size,
2062 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2066 /* create the key */
2067 for (i = 0; i < num_kflds; i++) {
2069 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2070 &kflds[i].field_info_spec,
2073 BNXT_TF_DBG(ERR, "Key field set failed.\n");
2078 /* if dynamic padding is enabled then add padding to result data */
2079 if (dparms->dynamic_pad_en) {
2080 /* add padding to make sure key is at byte boundary */
2081 ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
2084 pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
2086 BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
2089 ulp_blob_pad_push(&data, (uint32_t)pad);
2092 /* Create the result data blob */
2093 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
2095 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2098 if (dparms->dynamic_pad_en) {
2099 uint32_t abits = dparms->em_blk_align_bits;
2101 /* when dynamic padding is enabled merge result + key */
2102 rc = ulp_blob_block_merge(&data, &key, abits, pad);
2104 BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
2108 /* add padding to make sure merged result is at slice boundary*/
2109 ulp_blob_pad_align(&data, abits);
2111 ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
2114 /* do the transpose for the internal EM keys */
2115 if (tbl->resource_type == TF_MEM_INTERNAL) {
2116 if (dparms->em_key_align_bytes) {
2117 int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
2119 tmplen = ulp_blob_data_len_get(&key);
2120 ulp_blob_pad_push(&key, b - tmplen);
2122 tmplen = ulp_blob_data_len_get(&key);
2123 ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
2126 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
2127 &iparms.tbl_scope_id);
2129 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2134 * NOTE: the actual blob size will differ from the size in the tbl
2135 * entry due to the padding.
2137 iparms.dup_check = 0;
2138 iparms.dir = tbl->direction;
2139 iparms.mem = tbl->resource_type;
2140 iparms.key = ulp_blob_data_get(&key, &tmplen);
2141 iparms.key_sz_in_bits = tbl->key_bit_size;
2142 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
2143 if (tbl->result_bit_size)
2144 iparms.em_record_sz_in_bits = tbl->result_bit_size;
2146 iparms.em_record_sz_in_bits = tmplen;
2148 rc = tf_insert_em_entry(tfp, &iparms);
2150 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
2154 /* Mark action process */
2155 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
2156 tbl->resource_type == TF_MEM_EXTERNAL)
2157 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
2158 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
2159 tbl->resource_type == TF_MEM_INTERNAL)
2160 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
2162 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
2166 /* Link the EM resource to the flow in the flow db */
2167 memset(&fid_parms, 0, sizeof(fid_parms));
2168 fid_parms.direction = tbl->direction;
2169 fid_parms.resource_func = tbl->resource_func;
2170 fid_parms.resource_type = tbl->resource_type;
2171 fid_parms.critical_resource = tbl->critical_resource;
2172 fid_parms.resource_hndl = iparms.flow_handle;
2174 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2176 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
2178 /* Need to free the identifier, so goto error */
2184 free_parms.dir = iparms.dir;
2185 free_parms.mem = iparms.mem;
2186 free_parms.tbl_scope_id = iparms.tbl_scope_id;
2187 free_parms.flow_handle = iparms.flow_handle;
2189 trc = tf_delete_em_entry(tfp, &free_parms);
2191 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
2197 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2198 struct bnxt_ulp_mapper_tbl_info *tbl)
2200 struct ulp_flow_db_res_params fid_parms;
2201 struct ulp_blob data;
2202 uint64_t regval = 0;
2205 int32_t rc = 0, trc = 0;
2206 struct tf_alloc_tbl_entry_parms aparms = { 0 };
2207 struct tf_set_tbl_entry_parms sparms = { 0 };
2208 struct tf_get_tbl_entry_parms gparms = { 0 };
2209 struct tf_free_tbl_entry_parms free_parms = { 0 };
2210 uint32_t tbl_scope_id;
2211 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2212 struct bnxt_ulp_glb_resource_info glb_res;
2216 bool global = false;
2217 uint64_t act_rec_size;
2218 bool shared = false;
2220 /* use the max size if encap is enabled */
2221 if (tbl->encap_num_fields)
2222 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
2224 bit_size = tbl->result_bit_size;
2226 /* Initialize the blob data */
2227 if (!ulp_blob_init(&data, bit_size,
2228 parms->device_params->byte_order)) {
2229 BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
2233 /* Get the scope id first */
2234 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
2236 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2240 switch (tbl->tbl_opcode) {
2241 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
2244 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
2246 * Build the entry, alloc an index, write the table, and store
2247 * the data in the regfile.
2252 case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
2254 * get the index to write to from the regfile and then write
2257 if (!ulp_regfile_read(parms->regfile,
2261 "Failed to get tbl idx from regfile[%d].\n",
2265 index = tfp_be_to_cpu_64(regval);
2266 /* For external, we need to reverse shift */
2267 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2268 index = TF_ACT_REC_PTR_2_OFFSET(index);
2272 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
2274 * Build the entry, alloc an index, write the table, and store
2275 * the data in the global regfile.
2280 glb_res.direction = tbl->direction;
2281 glb_res.resource_func = tbl->resource_func;
2282 glb_res.resource_type = tbl->resource_type;
2283 glb_res.glb_regfile_index = tbl->tbl_operand;
2285 case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
2286 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2287 BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
2291 * get the index to write to from the global regfile and then
2294 if (ulp_mapper_glb_resource_read(parms->mapper_data,
2297 ®val, &shared)) {
2299 "Failed to get tbl idx from Glb RF[%d].\n",
2303 index = tfp_be_to_cpu_64(regval);
2304 /* For external, we need to reverse shift */
2305 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2306 index = TF_ACT_REC_PTR_2_OFFSET(index);
2309 case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
2311 * The read is different from the rest and can be handled here
2312 * instead of trying to use common code. Simply read the table
2313 * with the index from the regfile, scan and store the
2314 * identifiers, and return.
2316 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2317 /* Not currently supporting with EXT */
2319 "Ext Table Read Opcode not supported.\n");
2322 if (!ulp_regfile_read(parms->regfile,
2323 tbl->tbl_operand, ®val)) {
2325 "Failed to get tbl idx from regfile[%d]\n",
2329 index = tfp_be_to_cpu_64(regval);
2330 gparms.dir = tbl->direction;
2331 gparms.type = tbl->resource_type;
2332 gparms.data = ulp_blob_data_get(&data, &tmplen);
2333 gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tbl->result_bit_size);
2335 rc = tf_get_tbl_entry(tfp, &gparms);
2337 BNXT_TF_DBG(ERR, "Failed to read the tbl entry %d:%d\n",
2338 tbl->resource_type, index);
2342 * Scan the fields in the entry and push them into the regfile.
2344 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2346 gparms.data_sz_in_bytes,
2350 "Failed to get flds on tbl read rc=%d\n",
2356 BNXT_TF_DBG(ERR, "Invalid index table opcode %d\n",
2362 /* Get the result fields list */
2363 rc = ulp_mapper_tbl_result_build(parms,
2368 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2374 aparms.dir = tbl->direction;
2375 aparms.type = tbl->resource_type;
2376 aparms.tbl_scope_id = tbl_scope_id;
2378 /* All failures after the alloc succeeds require a free */
2379 rc = tf_alloc_tbl_entry(tfp, &aparms);
2381 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2382 tf_tbl_type_2_str(tbl->resource_type),
2383 tf_dir_2_str(tbl->direction), rc);
2389 * Store the index in the regfile since we either allocated it
2392 * Calculate the idx for the result record, for external EM the
2393 * offset needs to be shifted accordingly.
2394 * If external non-inline table types are used then need to
2395 * revisit this logic.
2397 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2398 regval = TF_ACT_REC_OFFSET_2_PTR(index);
2401 regval = tfp_cpu_to_be_64(regval);
2405 * Shared resources are never allocated through this
2406 * method, so the shared flag is always false.
2408 rc = ulp_mapper_glb_resource_write(parms->mapper_data,
2412 rc = ulp_regfile_write(parms->regfile,
2413 tbl->tbl_operand, regval);
2417 "Failed to write %s regfile[%d] rc=%d\n",
2418 (global) ? "global" : "reg",
2419 tbl->tbl_operand, rc);
2425 sparms.dir = tbl->direction;
2426 sparms.type = tbl->resource_type;
2427 sparms.data = ulp_blob_data_get(&data, &tmplen);
2428 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2430 sparms.tbl_scope_id = tbl_scope_id;
2432 tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
2433 rc = tf_set_tbl_entry(tfp, &sparms);
2436 "Index table[%s][%s][%x] write fail rc=%d\n",
2437 tf_tbl_type_2_str(sparms.type),
2438 tf_dir_2_str(sparms.dir),
2443 /* Calculate action record size */
2444 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2445 act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
2447 if (ulp_regfile_write(parms->regfile,
2448 BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
2449 tfp_cpu_to_be_64(act_rec_size)))
2451 "Failed write the act rec size\n");
2455 /* Link the resource to the flow in the flow db */
2456 memset(&fid_parms, 0, sizeof(fid_parms));
2457 fid_parms.direction = tbl->direction;
2458 fid_parms.resource_func = tbl->resource_func;
2459 fid_parms.resource_type = tbl->resource_type;
2460 fid_parms.resource_sub_type = tbl->resource_sub_type;
2461 fid_parms.resource_hndl = index;
2462 fid_parms.critical_resource = tbl->critical_resource;
2464 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2466 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2471 /* Perform the VF rep action */
2472 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2474 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2479 /* Shared resources are not freed */
2483 * Free the allocated resource since we failed to either
2484 * write to the entry or link the flow
2486 free_parms.dir = tbl->direction;
2487 free_parms.type = tbl->resource_type;
2488 free_parms.idx = index;
2489 free_parms.tbl_scope_id = tbl_scope_id;
2491 trc = tf_free_tbl_entry(tfp, &free_parms);
2493 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2499 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2500 struct bnxt_ulp_mapper_tbl_info *tbl)
2502 struct ulp_blob data, res_blob;
2506 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2507 struct tf_get_if_tbl_entry_parms get_parms = { 0 };
2508 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2509 enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
2512 /* Initialize the blob data */
2513 if (!ulp_blob_init(&data, tbl->result_bit_size,
2514 parms->device_params->byte_order)) {
2515 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2519 /* create the result blob */
2520 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
2522 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2526 /* Get the index details */
2528 case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
2529 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2531 case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
2532 if (!ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx)) {
2533 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
2537 idx = tfp_be_to_cpu_64(idx);
2539 case BNXT_ULP_IF_TBL_OPC_WR_CONST:
2540 idx = tbl->tbl_operand;
2542 case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
2543 /* Initialize the result blob */
2544 if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
2545 parms->device_params->byte_order)) {
2546 BNXT_TF_DBG(ERR, "Failed initial result blob\n");
2550 /* read the interface table */
2551 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2552 res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
2553 get_parms.dir = tbl->direction;
2554 get_parms.type = tbl->resource_type;
2555 get_parms.idx = idx;
2556 get_parms.data = ulp_blob_data_get(&res_blob, &tmplen);
2557 get_parms.data_sz_in_bytes = res_size;
2559 rc = tf_get_if_tbl_entry(tfp, &get_parms);
2561 BNXT_TF_DBG(ERR, "Get table[%d][%s][%x] failed rc=%d\n",
2563 tf_dir_2_str(get_parms.dir),
2567 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2570 res_blob.byte_order);
2572 BNXT_TF_DBG(ERR, "Scan and extract failed rc=%d\n", rc);
2574 case BNXT_ULP_IF_TBL_OPC_NOT_USED:
2575 return rc; /* skip it */
2577 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2581 /* Perform the tf table set by filling the set params */
2582 iftbl_params.dir = tbl->direction;
2583 iftbl_params.type = tbl->resource_type;
2584 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2585 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2586 iftbl_params.idx = idx;
2588 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2590 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2591 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2592 tf_dir_2_str(iftbl_params.dir),
2593 iftbl_params.idx, rc);
2598 * TBD: Need to look at the need to store idx in flow db for restore
2599 * the table to its original state on deletion of this entry.
2605 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2606 struct bnxt_ulp_mapper_tbl_info *tbl)
2608 struct ulp_mapper_gen_tbl_list *gen_tbl_list;
2609 struct bnxt_ulp_mapper_key_info *kflds;
2610 struct ulp_flow_db_res_params fid_parms;
2611 struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
2612 struct ulp_gen_hash_entry_params hash_entry;
2614 struct ulp_blob key, data;
2617 uint32_t i, num_kflds = 0, key_index = 0;
2618 uint32_t gen_tbl_miss = 1, fdb_write = 0;
2622 /* Get the key fields list and build the key. */
2623 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2624 if (!kflds || !num_kflds) {
2625 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2629 if (!ulp_blob_init(&key, tbl->key_bit_size,
2630 parms->device_params->byte_order)) {
2631 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2634 for (i = 0; i < num_kflds; i++) {
2636 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2637 &kflds[i].field_info_spec,
2638 &key, 1, "Gen Tbl Key");
2641 "Failed to create key for Gen tbl rc=%d\n",
2647 /* Calculate the table index for the generic table*/
2648 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2651 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2652 tbl->resource_sub_type, tbl->direction);
2656 /* The_key is a byte array convert it to a search index */
2657 cache_key = ulp_blob_data_get(&key, &tmplen);
2658 /* get the generic table */
2659 gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
2661 /* Check if generic hash table */
2662 if (gen_tbl_list->hash_tbl) {
2663 if (tbl->gen_tbl_lkup_type !=
2664 BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
2665 BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
2666 gen_tbl_list->gen_tbl_name);
2669 hash_entry.key_data = cache_key;
2670 hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
2671 rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
2674 BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
2675 gen_tbl_list->gen_tbl_name);
2678 if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
2679 key_index = hash_entry.key_idx;
2680 /* Get the generic table entry */
2681 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
2685 /* store the hash index in the fdb */
2686 key_index = hash_entry.hash_index;
2689 /* convert key to index directly */
2690 memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
2691 /* Get the generic table entry */
2692 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
2696 switch (tbl->tbl_opcode) {
2697 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2698 if (gen_tbl_list->hash_tbl) {
2699 if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
2700 break; /* nothing to be done , no entry */
2703 /* check the reference count */
2704 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2706 /* Scan ident list and create the result blob*/
2707 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2713 "Failed to scan ident list\n");
2716 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2717 /* increment the reference count */
2718 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2726 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
2727 if (gen_tbl_list->hash_tbl) {
2728 rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
2733 /* store the hash index in the fdb */
2734 key_index = hash_entry.hash_index;
2736 /* check the reference count */
2737 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2738 /* a hit then error */
2739 BNXT_TF_DBG(ERR, "generic entry already present\n");
2740 return -EINVAL; /* success */
2743 /* Initialize the blob data */
2744 if (!ulp_blob_init(&data, tbl->result_bit_size,
2745 gen_tbl_ent.byte_order)) {
2746 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2750 /* Get the result fields list */
2751 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2754 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2757 byte_data = ulp_blob_data_get(&data, &tmplen);
2758 rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
2760 ULP_BITS_2_BYTE(tmplen));
2762 BNXT_TF_DBG(ERR, "Failed to write generic table\n");
2766 /* increment the reference count */
2767 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2769 parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
2772 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
2776 /* Set the generic entry hit */
2777 rc = ulp_regfile_write(parms->regfile,
2778 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
2779 tfp_cpu_to_be_64(gen_tbl_miss));
2781 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2782 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
2786 /* add the entry to the flow database */
2788 memset(&fid_parms, 0, sizeof(fid_parms));
2789 fid_parms.direction = tbl->direction;
2790 fid_parms.resource_func = tbl->resource_func;
2791 fid_parms.resource_sub_type = tbl->resource_sub_type;
2792 fid_parms.resource_hndl = key_index;
2793 fid_parms.critical_resource = tbl->critical_resource;
2794 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2796 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
2802 ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2803 struct bnxt_ulp_mapper_tbl_info *tbl)
2807 /* process the fdb opcode for alloc push */
2808 if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
2809 rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
2811 BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
2819 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2820 struct bnxt_ulp_mapper_data *mapper_data)
2822 struct bnxt_ulp_glb_resource_info *glb_res;
2823 uint32_t num_glb_res_ids, idx, dev_id;
2827 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
2828 if (!glb_res || !num_glb_res_ids) {
2829 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2833 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2835 BNXT_TF_DBG(ERR, "Failed to get device id for glb init (%d)\n",
2840 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2842 BNXT_TF_DBG(ERR, "Failed to get app id for glb init (%d)\n",
2847 /* Iterate the global resources and process each one */
2848 for (idx = 0; idx < num_glb_res_ids; idx++) {
2849 if (dev_id != glb_res[idx].device_id ||
2850 glb_res[idx].app_id != app_id)
2852 switch (glb_res[idx].resource_func) {
2853 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2854 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
2858 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2859 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2864 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2865 glb_res[idx].resource_func);
2876 * Iterate over the shared resources assigned during tf_open_session and store
2877 * them in the global regfile with the shared flag.
2880 ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2881 struct bnxt_ulp_mapper_data *mapper_data)
2883 struct bnxt_ulp_glb_resource_info *glb_res;
2884 struct tf_get_session_info_parms sparms;
2885 uint32_t num_entries, i, dev_id, res;
2886 struct tf_resource_info *res_info;
2893 memset(&sparms, 0, sizeof(sparms));
2895 glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
2896 if (!glb_res || !num_entries) {
2897 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2901 tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
2903 BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
2907 * Retrieve the resources that were assigned during the shared session
2910 rc = tf_get_session_info(tfp, &sparms);
2912 BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
2916 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2918 BNXT_TF_DBG(ERR, "Failed to get the app id in glb init (%d).\n",
2923 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2925 BNXT_TF_DBG(ERR, "Failed to get dev id for app glb init (%d)\n",
2930 /* Store all the app global resources */
2931 for (i = 0; i < num_entries; i++) {
2932 if (dev_id != glb_res[i].device_id ||
2933 app_id != glb_res[i].app_id)
2935 dir = glb_res[i].direction;
2936 res = glb_res[i].resource_type;
2938 switch (glb_res[i].resource_func) {
2939 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2940 res_info = &sparms.session_info.ident[dir].info[res];
2942 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2943 res_info = &sparms.session_info.tbl[dir].info[res];
2945 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2946 res_info = &sparms.session_info.tcam[dir].info[res];
2948 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
2949 res_info = &sparms.session_info.em[dir].info[res];
2952 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
2953 glb_res[i].resource_func);
2957 regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
2961 * All resources written to the global regfile are shared for
2964 rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
2974 * Common conditional opcode process routine that is used for both the template
2975 * rejection and table conditional execution.
2978 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
2979 enum bnxt_ulp_cond_opc opc,
2983 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
2989 case BNXT_ULP_COND_OPC_CF_IS_SET:
2990 if (operand < BNXT_ULP_CF_IDX_LAST) {
2991 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
2993 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
2998 case BNXT_ULP_COND_OPC_CF_NOT_SET:
2999 if (operand < BNXT_ULP_CF_IDX_LAST) {
3000 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
3002 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3007 case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
3008 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3009 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3012 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3017 case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
3018 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3019 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3022 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3027 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
3028 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3029 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3032 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3037 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
3038 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3039 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3042 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3047 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
3048 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3050 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3054 *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3056 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
3057 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3059 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3063 *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3065 case BNXT_ULP_COND_OPC_RF_IS_SET:
3066 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3067 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3072 case BNXT_ULP_COND_OPC_RF_NOT_SET:
3073 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3074 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3079 case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
3080 if (parms->flow_pattern_id == operand) {
3081 BNXT_TF_DBG(ERR, "field pattern match failed %x\n",
3082 parms->flow_pattern_id);
3086 case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
3087 if (parms->act_pattern_id == operand) {
3088 BNXT_TF_DBG(ERR, "act pattern match failed %x\n",
3089 parms->act_pattern_id);
3093 case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
3094 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3095 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3098 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
3100 case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
3101 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3102 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3105 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
3108 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
3116 ulp_mapper_cc_upd_opr_compute(struct bnxt_ulp_mapper_parms *parms,
3118 enum bnxt_ulp_cc_upd_src cc_src,
3127 case BNXT_ULP_CC_UPD_SRC_COMP_FIELD:
3128 if (cc_opr >= BNXT_ULP_CF_IDX_LAST) {
3129 BNXT_TF_DBG(ERR, "invalid index %u\n", cc_opr);
3132 *result = (uint64_t)ULP_COMP_FLD_IDX_RD(parms, cc_opr);
3134 case BNXT_ULP_CC_UPD_SRC_REGFILE:
3135 if (!ulp_regfile_read(parms->regfile, cc_opr, ®val)) {
3136 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", cc_opr);
3139 *result = tfp_be_to_cpu_64(regval);
3141 case BNXT_ULP_CC_UPD_SRC_GLB_REGFILE:
3142 if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
3143 cc_opr, ®val, &shared)) {
3144 BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
3148 *result = tfp_be_to_cpu_64(regval);
3150 case BNXT_ULP_CC_UPD_SRC_CONST:
3154 BNXT_TF_DBG(ERR, "invalid src code %u\n", cc_src);
3161 ulp_mapper_cc_upd_info_process(struct bnxt_ulp_mapper_parms *parms,
3162 struct bnxt_ulp_mapper_tbl_info *tbl)
3164 struct bnxt_ulp_mapper_cc_upd_info *cc_upd = &tbl->cc_upd_info;
3165 uint64_t res = 0, res1, res2;
3168 if (cc_upd->cc_opc == BNXT_ULP_CC_UPD_OPC_NOP)
3171 rc = ulp_mapper_cc_upd_opr_compute(parms, tbl->direction,
3173 cc_upd->cc_opr1, &res1);
3177 rc = ulp_mapper_cc_upd_opr_compute(parms, tbl->direction,
3179 cc_upd->cc_opr2, &res2);
3183 switch (cc_upd->cc_opc) {
3184 case BNXT_ULP_CC_UPD_OPC_NOP:
3187 case BNXT_ULP_CC_UPD_OPC_EQ:
3191 case BNXT_ULP_CC_UPD_OPC_NE:
3195 case BNXT_ULP_CC_UPD_OPC_GE:
3199 case BNXT_ULP_CC_UPD_OPC_GT:
3203 case BNXT_ULP_CC_UPD_OPC_LE:
3207 case BNXT_ULP_CC_UPD_OPC_LT:
3211 case BNXT_ULP_CC_UPD_OPC_LAST:
3212 BNXT_TF_DBG(ERR, "invalid code %u\n", cc_upd->cc_opc);
3215 if (ulp_regfile_write(parms->regfile, cc_upd->cc_dst_opr,
3216 tfp_cpu_to_be_64(res))) {
3217 BNXT_TF_DBG(ERR, "Failed write the cc_opc %u\n",
3218 cc_upd->cc_dst_opr);
3227 * Processes a list of conditions and returns both a status and result of the
3228 * list. The status must be checked prior to verifying the result.
3230 * returns 0 for success, negative on failure
3231 * returns res = 1 for true, res = 0 for false.
3234 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
3235 enum bnxt_ulp_cond_list_opc list_opc,
3236 struct bnxt_ulp_mapper_cond_info *list,
3241 int32_t rc = 0, trc = 0;
3244 case BNXT_ULP_COND_LIST_OPC_AND:
3245 /* AND Defaults to true. */
3248 case BNXT_ULP_COND_LIST_OPC_OR:
3249 /* OR Defaults to false. */
3252 case BNXT_ULP_COND_LIST_OPC_TRUE:
3255 case BNXT_ULP_COND_LIST_OPC_FALSE:
3259 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
3265 for (i = 0; i < num; i++) {
3266 rc = ulp_mapper_cond_opc_process(parms,
3267 list[i].cond_opcode,
3268 list[i].cond_operand,
3273 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
3274 /* early return if result is ever zero */
3280 /* early return if result is ever non-zero */
3292 * Processes conflict resolution and returns both a status and result.
3293 * The status must be checked prior to verifying the result.
3295 * returns 0 for success, negative on failure
3296 * returns res = 1 for true, res = 0 for false.
3299 ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
3300 struct bnxt_ulp_mapper_tbl_info *tbl,
3305 uint64_t comp_sig_id;
3308 switch (tbl->accept_opcode) {
3309 case BNXT_ULP_ACCEPT_OPC_ALWAYS:
3312 case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
3313 /* perform the signature validation*/
3314 if (tbl->resource_func ==
3315 BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
3316 /* Perform the check that generic table is hit or not */
3317 if (!ulp_regfile_read(parms->regfile,
3318 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3320 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3321 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3325 /* not a hit so no need to check flow sign*/
3330 /* compare the new flow signature against stored one */
3331 if (!ulp_regfile_read(parms->regfile,
3332 BNXT_ULP_RF_IDX_FLOW_SIG_ID,
3334 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3335 BNXT_ULP_RF_IDX_FLOW_SIG_ID);
3338 comp_sig_id = ULP_COMP_FLD_IDX_RD(parms,
3339 BNXT_ULP_CF_IDX_FLOW_SIG_ID);
3340 regval = tfp_be_to_cpu_64(regval);
3341 if (comp_sig_id == regval)
3344 BNXT_TF_DBG(ERR, "failed signature match %x:%x\n",
3345 (uint32_t)comp_sig_id, (uint32_t)regval);
3348 BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
3349 tbl->accept_opcode);
3356 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
3358 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
3359 enum bnxt_ulp_cond_list_opc cond_opc;
3360 struct bnxt_ulp_mapper_tbl_info *tbls;
3361 struct bnxt_ulp_mapper_tbl_info *tbl;
3362 uint32_t num_tbls, tbl_idx, num_cond_tbls;
3363 int32_t rc = -EINVAL, cond_rc = 0;
3364 int32_t cond_goto = 1;
3366 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
3370 * Process the reject list if exists, otherwise assume that the
3371 * template is allowed.
3373 if (cond_tbls && num_cond_tbls) {
3374 rc = ulp_mapper_cond_opc_list_process(parms,
3382 /* Reject the template if True */
3384 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
3385 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3391 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
3392 if (!tbls || !num_tbls) {
3393 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
3394 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3395 parms->dev_id, tid);
3399 for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
3400 tbl = &tbls[tbl_idx];
3401 /* Process the conditional code update opcodes */
3402 if (ulp_mapper_cc_upd_info_process(parms, tbl)) {
3403 BNXT_TF_DBG(ERR, "Failed to process cond update\n");
3408 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
3411 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
3412 cond_tbls, num_cond_tbls,
3415 BNXT_TF_DBG(ERR, "Failed to proc cond opc list (%d)\n",
3419 /* Skip the table if False */
3421 cond_goto = tbl->execute_info.cond_false_goto;
3422 goto next_iteration;
3425 switch (tbl->resource_func) {
3426 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3427 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
3429 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3430 rc = ulp_mapper_em_tbl_process(parms, tbl);
3432 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3433 rc = ulp_mapper_index_tbl_process(parms, tbl);
3435 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
3436 rc = ulp_mapper_if_tbl_process(parms, tbl);
3438 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3439 rc = ulp_mapper_gen_tbl_process(parms, tbl);
3441 case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
3442 rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
3444 case BNXT_ULP_RESOURCE_FUNC_INVALID:
3448 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
3449 tbl->resource_func);
3455 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
3456 tbl->resource_func);
3460 /* perform the post table process */
3461 rc = ulp_mapper_conflict_resolution_process(parms, tbl,
3463 if (rc || !cond_rc) {
3464 BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
3469 if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
3470 BNXT_TF_DBG(ERR, "reject the flow\n");
3473 } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
3477 /* least significant 16 bits from reg_file index */
3478 rf_idx = (uint32_t)(cond_goto & 0xFFFF);
3479 if (!ulp_regfile_read(parms->regfile, rf_idx,
3481 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3486 cond_goto = (int32_t)regval;
3489 if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
3490 BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
3494 tbl_idx += cond_goto;
3499 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
3500 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3501 parms->dev_id, tid);
3506 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
3508 struct ulp_flow_db_res_params *res)
3514 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
3518 tfp = bnxt_ulp_cntxt_tfp_get(ulp);
3520 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
3524 switch (res->resource_func) {
3525 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3526 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
3528 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3529 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
3531 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3532 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
3534 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3535 rc = ulp_mapper_ident_free(ulp, tfp, res);
3537 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
3538 rc = ulp_mapper_mark_free(ulp, res);
3540 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
3541 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
3543 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
3544 rc = ulp_mapper_child_flow_free(ulp, fid, res);
3546 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3547 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
3557 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
3558 enum bnxt_ulp_fdb_type flow_type,
3561 struct ulp_flow_db_res_params res_parms = { 0 };
3565 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3570 * Set the critical resource on the first resource del, then iterate
3571 * while status is good
3573 if (flow_type != BNXT_ULP_FDB_TYPE_RID)
3574 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
3576 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
3580 * This is unexpected on the first call to resource del.
3581 * It likely means that the flow did not exist in the flow db.
3583 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
3584 flow_type, fid, rc);
3589 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
3592 * On fail, we still need to attempt to free the
3593 * remaining resources. Don't return
3596 "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
3597 "] failed rc=%d.\n",
3598 flow_type, fid, res_parms.resource_func,
3599 res_parms.resource_hndl, trc);
3601 /* All subsequent call require the non-critical_resource */
3602 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
3604 rc = ulp_flow_db_resource_del(ulp_ctx,
3610 /* Free the Flow ID since we've removed all resources */
3611 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
3617 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
3618 struct bnxt_ulp_mapper_data *mapper_data)
3620 struct bnxt_ulp_mapper_glb_resource_entry *ent;
3621 struct ulp_flow_db_res_params res;
3624 /* Iterate the global resources and process each one */
3625 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
3626 for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
3627 ent = &mapper_data->glb_res_tbl[dir][idx];
3628 if (ent->resource_func ==
3629 BNXT_ULP_RESOURCE_FUNC_INVALID ||
3632 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
3633 res.resource_func = ent->resource_func;
3634 res.direction = dir;
3635 res.resource_type = ent->resource_type;
3636 /*convert it from BE to cpu */
3638 tfp_be_to_cpu_64(ent->resource_hndl);
3639 ulp_mapper_resource_free(ulp_ctx, 0, &res);
3645 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
3646 enum bnxt_ulp_fdb_type flow_type,
3652 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3656 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
3660 /* Function to handle the mapping of the Flow to be compatible
3661 * with the underlying hardware.
3664 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
3665 struct bnxt_ulp_mapper_create_parms *cparms)
3667 struct bnxt_ulp_mapper_parms parms;
3668 struct ulp_regfile regfile;
3669 int32_t rc = 0, trc;
3671 if (!ulp_ctx || !cparms)
3674 /* Initialize the parms structure */
3675 memset(&parms, 0, sizeof(parms));
3676 parms.act_prop = cparms->act_prop;
3677 parms.act_bitmap = cparms->act;
3678 parms.hdr_bitmap = cparms->hdr_bitmap;
3679 parms.regfile = ®file;
3680 parms.hdr_field = cparms->hdr_field;
3681 parms.fld_bitmap = cparms->fld_bitmap;
3682 parms.comp_fld = cparms->comp_fld;
3683 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3684 parms.ulp_ctx = ulp_ctx;
3685 parms.act_tid = cparms->act_tid;
3686 parms.class_tid = cparms->class_tid;
3687 parms.flow_type = cparms->flow_type;
3688 parms.parent_flow = cparms->parent_flow;
3689 parms.parent_fid = cparms->parent_fid;
3690 parms.fid = cparms->flow_id;
3691 parms.tun_idx = cparms->tun_idx;
3692 parms.app_priority = cparms->app_priority;
3693 parms.flow_pattern_id = cparms->flow_pattern_id;
3694 parms.act_pattern_id = cparms->act_pattern_id;
3695 parms.app_id = cparms->app_id;
3697 /* Get the device id from the ulp context */
3698 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
3699 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
3703 /* Get the device params, it will be used in later processing */
3704 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
3705 if (!parms.device_params) {
3706 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
3712 * Get the mapper data for dynamic mapper data such as default
3715 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
3716 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3717 if (!parms.mapper_data) {
3718 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
3722 /* initialize the registry file for further processing */
3723 if (!ulp_regfile_init(parms.regfile)) {
3724 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
3728 /* Process the action template list from the selected action table*/
3729 if (parms.act_tid) {
3730 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
3731 /* Process the action template tables */
3732 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
3735 cparms->shared_hndl = parms.shared_hndl;
3738 if (parms.class_tid) {
3739 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
3741 /* Process the class template tables.*/
3742 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
3747 /* setup the parent-child details */
3748 if (parms.parent_flow) {
3749 /* create a parent flow details */
3750 rc = ulp_flow_db_parent_flow_create(&parms);
3753 } else if (parms.parent_fid) {
3754 /* create a child flow details */
3755 rc = ulp_flow_db_child_flow_create(&parms);
3763 /* Free all resources that were allocated during flow creation */
3764 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
3767 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
3773 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
3775 struct bnxt_ulp_mapper_data *data;
3782 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3786 data = rte_zmalloc("ulp_mapper_data",
3787 sizeof(struct bnxt_ulp_mapper_data), 0);
3789 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
3793 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
3794 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
3795 /* Don't call deinit since the prof_func wasn't allocated. */
3800 /* Allocate the global resource ids */
3801 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
3803 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
3808 * Only initialize the app global resources if a shared session was
3811 if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
3812 rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
3814 BNXT_TF_DBG(ERR, "Failed to init app glb resources\n");
3819 /* Allocate the generic table list */
3820 rc = ulp_mapper_generic_tbl_list_init(data);
3822 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
3828 /* Ignore the return code in favor of returning the original error. */
3829 ulp_mapper_deinit(ulp_ctx);
3834 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
3836 struct bnxt_ulp_mapper_data *data;
3841 "Failed to acquire ulp context, so data may not be released.\n");
3845 data = (struct bnxt_ulp_mapper_data *)
3846 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3848 /* Go ahead and return since there is no allocated data. */
3849 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
3853 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3855 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
3856 /* Free the mapper data regardless of errors. */
3857 goto free_mapper_data;
3860 /* Free the global resource info table entries */
3861 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
3864 /* Free the generic table */
3865 (void)ulp_mapper_generic_tbl_list_deinit(data);
3868 /* Reset the data pointer within the ulp_ctx. */
3869 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);