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->class_tid << (BNXT_ULP_HDR_SIG_ID_SHIFT +
229 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
230 t_idx += ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_HDR_SIG_ID) <<
231 BNXT_ULP_GLB_FIELD_TBL_SHIFT;
234 if (t_idx >= BNXT_ULP_GLB_FIELD_TBL_SIZE) {
235 BNXT_TF_DBG(ERR, "Invalid hdr field index %x:%x:%x\n",
236 parms->class_tid, t_idx, operand);
238 return -EINVAL; /* error */
240 *val = ulp_glb_field_tbl[t_idx];
245 * Get the size of the action property for a given index.
247 * idx [in] The index for the action property
249 * returns the size of the action property.
252 ulp_mapper_act_prop_size_get(uint32_t idx)
254 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
256 return ulp_act_prop_map_table[idx];
259 static struct bnxt_ulp_mapper_cond_info *
260 ulp_mapper_tmpl_reject_list_get(struct bnxt_ulp_mapper_parms *mparms,
263 enum bnxt_ulp_cond_list_opc *opc)
266 const struct bnxt_ulp_template_device_tbls *dev_tbls;
268 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
269 *num_tbls = dev_tbls->tmpl_list[tid].reject_info.cond_nums;
270 *opc = dev_tbls->tmpl_list[tid].reject_info.cond_list_opcode;
271 idx = dev_tbls->tmpl_list[tid].reject_info.cond_start_idx;
273 return &dev_tbls->cond_list[idx];
276 static struct bnxt_ulp_mapper_cond_info *
277 ulp_mapper_tbl_execute_list_get(struct bnxt_ulp_mapper_parms *mparms,
278 struct bnxt_ulp_mapper_tbl_info *tbl,
280 enum bnxt_ulp_cond_list_opc *opc)
283 const struct bnxt_ulp_template_device_tbls *dev_tbls;
285 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
286 *num_tbls = tbl->execute_info.cond_nums;
287 *opc = tbl->execute_info.cond_list_opcode;
288 idx = tbl->execute_info.cond_start_idx;
290 return &dev_tbls->cond_list[idx];
294 * Get a list of classifier tables that implement the flow
295 * Gets a device dependent list of tables that implement the class template id
297 * mparms [in] The mappers parms with data related to the flow.
299 * tid [in] The template id that matches the flow
301 * num_tbls [out] The number of classifier tables in the returned array
303 * returns An array of classifier tables to implement the flow, or NULL on
306 static struct bnxt_ulp_mapper_tbl_info *
307 ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
312 const struct bnxt_ulp_template_device_tbls *dev_tbls;
314 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
316 idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
317 *num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
319 return &dev_tbls->tbl_list[idx];
323 * Get the list of key fields that implement the flow.
325 * mparms [in] The mapper parms with information about the flow
327 * tbl [in] A single table instance to get the key fields from
329 * num_flds [out] The number of key fields in the returned array
331 * Returns array of Key fields, or NULL on error.
333 static struct bnxt_ulp_mapper_key_info *
334 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
335 struct bnxt_ulp_mapper_tbl_info *tbl,
339 const struct bnxt_ulp_template_device_tbls *dev_tbls;
341 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
342 if (!dev_tbls->key_info_list) {
347 idx = tbl->key_start_idx;
348 *num_flds = tbl->key_num_fields;
350 return &dev_tbls->key_info_list[idx];
354 * Get the list of data fields that implement the flow.
356 * mparms [in] The mapper parms with information about the flow
358 * tbl [in] A single table instance to get the data fields from
360 * num_flds [out] The number of data fields in the returned array.
362 * num_encap_flds [out] The number of encap fields in the returned array.
364 * Returns array of data fields, or NULL on error.
366 static struct bnxt_ulp_mapper_field_info *
367 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
368 struct bnxt_ulp_mapper_tbl_info *tbl,
370 uint32_t *num_encap_flds)
373 const struct bnxt_ulp_template_device_tbls *dev_tbls;
375 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
376 if (!dev_tbls->result_field_list) {
382 idx = tbl->result_start_idx;
383 *num_flds = tbl->result_num_fields;
384 *num_encap_flds = tbl->encap_num_fields;
386 return &dev_tbls->result_field_list[idx];
390 * Get the list of ident fields that implement the flow
392 * tbl [in] A single table instance to get the ident fields from
394 * num_flds [out] The number of ident fields in the returned array
396 * returns array of ident fields, or NULL on error
398 static struct bnxt_ulp_mapper_ident_info *
399 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
400 struct bnxt_ulp_mapper_tbl_info *tbl,
404 const struct bnxt_ulp_template_device_tbls *dev_tbls;
406 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
407 if (!dev_tbls->ident_list) {
412 idx = tbl->ident_start_idx;
413 *num_flds = tbl->ident_nums;
415 return &dev_tbls->ident_list[idx];
418 static inline int32_t
419 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp __rte_unused,
421 struct ulp_flow_db_res_params *res)
423 struct tf_free_tcam_entry_parms fparms = {
424 .dir = res->direction,
425 .tcam_tbl_type = res->resource_type,
426 .idx = (uint16_t)res->resource_hndl
429 return tf_free_tcam_entry(tfp, &fparms);
432 static inline int32_t
433 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
435 struct ulp_flow_db_res_params *res)
437 struct tf_free_tbl_entry_parms fparms = {
438 .dir = res->direction,
439 .type = res->resource_type,
440 .idx = (uint32_t)res->resource_hndl
444 * Just get the table scope, it will be ignored if not necessary
445 * by the tf_free_tbl_entry
447 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
449 return tf_free_tbl_entry(tfp, &fparms);
452 static inline int32_t
453 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
455 struct ulp_flow_db_res_params *res)
457 struct tf_delete_em_entry_parms fparms = { 0 };
460 fparms.dir = res->direction;
461 fparms.flow_handle = res->resource_hndl;
463 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
465 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
469 return tf_delete_em_entry(tfp, &fparms);
472 static inline int32_t
473 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
475 struct ulp_flow_db_res_params *res)
477 struct tf_free_identifier_parms fparms = {
478 .dir = res->direction,
479 .ident_type = res->resource_type,
480 .id = (uint16_t)res->resource_hndl
483 return tf_free_identifier(tfp, &fparms);
486 static inline int32_t
487 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
488 struct ulp_flow_db_res_params *res)
490 return ulp_mark_db_mark_del(ulp,
495 static inline int32_t
496 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
498 struct ulp_flow_db_res_params *res)
500 uint32_t idx, child_fid = 0, parent_idx;
501 struct bnxt_ulp_flow_db *flow_db;
503 parent_idx = (uint32_t)res->resource_hndl;
505 /* check the validity of the parent fid */
506 if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
508 BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
512 /* Clear all the child flows parent index */
513 flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
514 while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
516 /* update the child flows resource handle */
517 if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
519 BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
525 /* free the parent entry in the parent table flow */
526 if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
527 BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
533 static inline int32_t
534 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
536 struct ulp_flow_db_res_params *res)
540 parent_fid = (uint32_t)res->resource_hndl;
542 return 0; /* Already freed - orphan child*/
544 /* reset the child flow bitset*/
545 if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
546 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
547 parent_fid, child_fid);
554 * Process the flow database opcode alloc action.
555 * returns 0 on success
558 ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
559 struct bnxt_ulp_mapper_tbl_info *tbl)
565 /* allocate a new fid */
566 rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
567 BNXT_ULP_FDB_TYPE_RID,
571 "Unable to allocate flow table entry\n");
574 /* Store the allocated fid in regfile*/
576 rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
577 tfp_cpu_to_be_64(val64));
579 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
581 ulp_flow_db_fid_free(parms->ulp_ctx,
582 BNXT_ULP_FDB_TYPE_RID, rid);
589 * Process the flow database opcode action.
590 * returns 0 on success.
593 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
594 struct bnxt_ulp_mapper_tbl_info *tbl,
595 struct ulp_flow_db_res_params *fid_parms)
599 enum bnxt_ulp_fdb_type flow_type;
602 switch (tbl->fdb_opcode) {
603 case BNXT_ULP_FDB_OPC_PUSH_FID:
604 push_fid = parms->fid;
605 flow_type = parms->flow_type;
607 case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
608 /* get the fid from the regfile */
609 rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
612 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
616 /* Use the extracted fid to update the flow resource */
617 push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
618 flow_type = BNXT_ULP_FDB_TYPE_RID;
621 return rc; /* Nothing to be done */
624 /* Add the resource to the flow database */
625 rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
626 push_fid, fid_parms);
628 BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
634 * Process the flow database opcode action.
635 * returns 0 on success.
638 ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms,
639 struct bnxt_ulp_mapper_tbl_info *tbl,
644 switch (tbl->pri_opcode) {
645 case BNXT_ULP_PRI_OPC_NOT_USED:
648 case BNXT_ULP_PRI_OPC_CONST:
649 *priority = tbl->pri_operand;
651 case BNXT_ULP_PRI_OPC_APP_PRI:
652 *priority = parms->app_priority;
655 BNXT_TF_DBG(ERR, "Priority opcode not supported %d\n",
664 * Process the identifier list in the given table.
665 * Extract the ident from the table entry and
666 * write it to the reg file.
667 * returns 0 on success.
670 ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
671 struct bnxt_ulp_mapper_tbl_info *tbl,
673 uint32_t byte_data_size,
674 enum bnxt_ulp_byte_order byte_order)
676 struct bnxt_ulp_mapper_ident_info *idents;
677 uint32_t i, num_idents = 0;
680 /* validate the null arguments */
682 BNXT_TF_DBG(ERR, "invalid argument\n");
686 /* Get the ident list and process each one */
687 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
689 for (i = 0; i < num_idents; i++) {
690 /* check the size of the buffer for validation */
691 if ((idents[i].ident_bit_pos + idents[i].ident_bit_size) >
692 ULP_BYTE_2_BITS(byte_data_size) ||
693 idents[i].ident_bit_size > ULP_BYTE_2_BITS(sizeof(val64))) {
694 BNXT_TF_DBG(ERR, "invalid offset or length %x:%x:%x\n",
695 idents[i].ident_bit_pos,
696 idents[i].ident_bit_size,
701 if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
702 ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
704 idents[i].ident_bit_pos,
705 idents[i].ident_bit_size);
707 ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
708 idents[i].ident_bit_pos,
709 idents[i].ident_bit_size);
711 /* Write it to the regfile, val64 is already in big-endian*/
712 if (ulp_regfile_write(parms->regfile,
713 idents[i].regfile_idx, val64)) {
714 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
715 idents[i].regfile_idx);
723 * Process the identifier instruction and either store it in the flow database
724 * or return it in the val (if not NULL) on success. If val is NULL, the
725 * identifier is to be stored in the flow database.
728 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
729 struct bnxt_ulp_mapper_tbl_info *tbl,
730 struct bnxt_ulp_mapper_ident_info *ident,
733 struct ulp_flow_db_res_params fid_parms;
736 struct tf_alloc_identifier_parms iparms = { 0 };
737 struct tf_free_identifier_parms free_parms = { 0 };
741 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
743 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
747 idx = ident->regfile_idx;
749 iparms.ident_type = ident->ident_type;
750 iparms.dir = tbl->direction;
752 rc = tf_alloc_identifier(tfp, &iparms);
754 BNXT_TF_DBG(ERR, "Alloc ident %s:%s failed.\n",
755 tf_dir_2_str(iparms.dir),
756 tf_ident_2_str(iparms.ident_type));
760 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
761 if (ulp_regfile_write(parms->regfile, idx, id)) {
762 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
764 /* Need to free the identifier, so goto error */
768 /* Link the resource to the flow in the flow db */
770 memset(&fid_parms, 0, sizeof(fid_parms));
771 fid_parms.direction = tbl->direction;
772 fid_parms.resource_func = ident->resource_func;
773 fid_parms.resource_type = ident->ident_type;
774 fid_parms.resource_hndl = iparms.id;
775 fid_parms.critical_resource = tbl->critical_resource;
777 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
779 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
781 /* Need to free the identifier, so goto error */
790 /* Need to free the identifier */
791 free_parms.dir = tbl->direction;
792 free_parms.ident_type = ident->ident_type;
793 free_parms.id = iparms.id;
795 (void)tf_free_identifier(tfp, &free_parms);
797 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
799 tf_dir_2_str(tbl->direction));
804 * Process the identifier instruction and extract it from result blob.
805 * Increment the identifier reference count and store it in the flow database.
808 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
809 struct bnxt_ulp_mapper_tbl_info *tbl,
810 struct bnxt_ulp_mapper_ident_info *ident,
811 struct ulp_blob *res_blob)
813 struct ulp_flow_db_res_params fid_parms;
816 struct tf_search_identifier_parms sparms = { 0 };
817 struct tf_free_identifier_parms free_parms = { 0 };
821 /* Get the tfp from ulp context */
822 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
824 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
828 /* Extract the index from the result blob */
829 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
830 ident->ident_bit_pos, ident->ident_bit_size);
832 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
836 /* populate the search params and search identifier shadow table */
837 sparms.ident_type = ident->ident_type;
838 sparms.dir = tbl->direction;
839 /* convert the idx into cpu format */
840 sparms.search_id = tfp_be_to_cpu_32(idx);
842 /* Search identifier also increase the reference count */
843 rc = tf_search_identifier(tfp, &sparms);
845 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
846 tf_dir_2_str(sparms.dir),
847 tf_ident_2_str(sparms.ident_type),
852 /* Write it to the regfile */
853 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
854 if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
855 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
857 /* Need to free the identifier, so goto error */
861 /* Link the resource to the flow in the flow db */
862 memset(&fid_parms, 0, sizeof(fid_parms));
863 fid_parms.direction = tbl->direction;
864 fid_parms.resource_func = ident->resource_func;
865 fid_parms.resource_type = ident->ident_type;
866 fid_parms.resource_hndl = sparms.search_id;
867 fid_parms.critical_resource = tbl->critical_resource;
868 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
870 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
872 /* Need to free the identifier, so goto error */
879 /* Need to free the identifier */
880 free_parms.dir = tbl->direction;
881 free_parms.ident_type = ident->ident_type;
882 free_parms.id = sparms.search_id;
883 (void)tf_free_identifier(tfp, &free_parms);
884 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
886 tf_dir_2_str(tbl->direction), sparms.search_id);
891 ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
896 enum bnxt_ulp_port_table port_data = val16;
899 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
900 if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
902 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
906 case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
907 if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
909 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
913 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
914 if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
916 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
921 BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
928 ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
929 enum bnxt_ulp_field_src field_src,
938 struct bnxt_ulp_mapper_data *m;
940 uint32_t port_id, val_size, field_size;
941 uint16_t idx, size_idx, offset;
942 uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
949 /* Perform the action */
951 case BNXT_ULP_FIELD_SRC_ZERO:
952 *val = mapper_fld_zeros;
954 case BNXT_ULP_FIELD_SRC_CONST:
957 case BNXT_ULP_FIELD_SRC_ONES:
958 *val = mapper_fld_ones;
961 case BNXT_ULP_FIELD_SRC_CF:
962 if (!ulp_operand_read(field_opr,
963 (uint8_t *)&idx, sizeof(uint16_t))) {
964 BNXT_TF_DBG(ERR, "CF operand read failed\n");
967 idx = tfp_be_to_cpu_16(idx);
968 if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint32_t)) {
969 BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
973 buffer = (uint8_t *)&parms->comp_fld[idx];
974 *val = &buffer[sizeof(uint32_t) - bytelen];
975 *value = ULP_COMP_FLD_IDX_RD(parms, idx);
977 case BNXT_ULP_FIELD_SRC_RF:
978 if (!ulp_operand_read(field_opr,
979 (uint8_t *)&idx, sizeof(uint16_t))) {
980 BNXT_TF_DBG(ERR, "RF operand read failed\n");
984 idx = tfp_be_to_cpu_16(idx);
985 /* Uninitialized regfile entries return 0 */
986 if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
987 sizeof(uint64_t) < bytelen) {
988 BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
992 buffer = (uint8_t *)&parms->regfile->entry[idx].data;
993 *val = &buffer[sizeof(uint64_t) - bytelen];
994 *value = tfp_be_to_cpu_64(lregval);
996 case BNXT_ULP_FIELD_SRC_ACT_PROP:
997 if (!ulp_operand_read(field_opr,
998 (uint8_t *)&idx, sizeof(uint16_t))) {
999 BNXT_TF_DBG(ERR, "Action operand read failed\n");
1002 idx = tfp_be_to_cpu_16(idx);
1003 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1004 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
1007 buffer = &parms->act_prop->act_details[idx];
1008 field_size = ulp_mapper_act_prop_size_get(idx);
1009 if (bytelen > field_size) {
1010 BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
1014 *val = &buffer[field_size - bytelen];
1016 case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
1017 if (!ulp_operand_read(field_opr,
1018 (uint8_t *)&idx, sizeof(uint16_t))) {
1019 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1022 idx = tfp_be_to_cpu_16(idx);
1024 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1025 BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
1028 *val = &parms->act_prop->act_details[idx];
1030 /* get the size index next */
1031 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1032 (uint8_t *)&size_idx, sizeof(uint16_t))) {
1033 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1036 size_idx = tfp_be_to_cpu_16(size_idx);
1037 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1038 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
1041 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
1043 val_size = tfp_be_to_cpu_32(val_size);
1044 *val_len = ULP_BYTE_2_BITS(val_size);
1046 case BNXT_ULP_FIELD_SRC_GLB_RF:
1047 if (!ulp_operand_read(field_opr,
1048 (uint8_t *)&idx, sizeof(uint16_t))) {
1049 BNXT_TF_DBG(ERR, "Global regfile read failed\n");
1052 idx = tfp_be_to_cpu_16(idx);
1053 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1054 dir, idx, &lregval, &shared) ||
1055 sizeof(uint64_t) < bytelen) {
1056 BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
1060 m = parms->mapper_data;
1061 buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
1062 *val = &buffer[sizeof(uint64_t) - bytelen];
1063 *value = tfp_be_to_cpu_64(lregval);
1065 case BNXT_ULP_FIELD_SRC_HF:
1066 case BNXT_ULP_FIELD_SRC_SUB_HF:
1067 if (!ulp_operand_read(field_opr,
1068 (uint8_t *)&idx, sizeof(uint16_t))) {
1069 BNXT_TF_DBG(ERR, "Header field read failed\n");
1072 idx = tfp_be_to_cpu_16(idx);
1073 /* get the index from the global field list */
1074 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1075 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1080 buffer = parms->hdr_field[bit].spec;
1082 buffer = parms->hdr_field[bit].mask;
1084 field_size = parms->hdr_field[bit].size;
1085 if (bytelen > field_size) {
1086 BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
1090 if (field_src == BNXT_ULP_FIELD_SRC_HF) {
1091 *val = &buffer[field_size - bytelen];
1093 /* get the offset next */
1094 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1096 sizeof(uint16_t))) {
1097 BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
1100 offset = tfp_be_to_cpu_16(offset);
1101 offset = ULP_BITS_2_BYTE_NR(offset);
1102 if ((offset + bytelen) > field_size) {
1103 BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
1106 *val = &buffer[offset];
1109 case BNXT_ULP_FIELD_SRC_HDR_BIT:
1110 if (!ulp_operand_read(field_opr,
1111 (uint8_t *)&lregval, sizeof(uint64_t))) {
1112 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1115 lregval = tfp_be_to_cpu_64(lregval);
1116 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
1117 *val = mapper_fld_one;
1120 *val = mapper_fld_zeros;
1123 case BNXT_ULP_FIELD_SRC_ACT_BIT:
1124 if (!ulp_operand_read(field_opr,
1125 (uint8_t *)&lregval, sizeof(uint64_t))) {
1126 BNXT_TF_DBG(ERR, "Action bit read failed\n");
1129 lregval = tfp_be_to_cpu_64(lregval);
1130 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
1131 *val = mapper_fld_one;
1134 *val = mapper_fld_zeros;
1137 case BNXT_ULP_FIELD_SRC_FIELD_BIT:
1138 if (!ulp_operand_read(field_opr,
1139 (uint8_t *)&idx, sizeof(uint16_t))) {
1140 BNXT_TF_DBG(ERR, "Field bit read failed\n");
1143 idx = tfp_be_to_cpu_16(idx);
1144 /* get the index from the global field list */
1145 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1146 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1150 if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
1151 *val = mapper_fld_one;
1154 *val = mapper_fld_zeros;
1157 case BNXT_ULP_FIELD_SRC_PORT_TABLE:
1158 /* The port id is present in the comp field list */
1159 port_id = ULP_COMP_FLD_IDX_RD(parms,
1160 BNXT_ULP_CF_IDX_DEV_PORT_ID);
1161 /* get the port table enum */
1162 if (!ulp_operand_read(field_opr,
1163 (uint8_t *)&idx, sizeof(uint16_t))) {
1164 BNXT_TF_DBG(ERR, "Port table enum read failed\n");
1167 idx = tfp_be_to_cpu_16(idx);
1168 if (ulp_mapper_field_port_db_process(parms, port_id, idx,
1170 BNXT_TF_DBG(ERR, "field port table failed\n");
1173 case BNXT_ULP_FIELD_SRC_SKIP:
1176 case BNXT_ULP_FIELD_SRC_REJECT:
1179 BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
1185 static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
1193 bytelen = ULP_BITS_2_BYTE(bitlen);
1194 if (bytelen == sizeof(uint8_t)) {
1195 *output = *((uint8_t *)buffer);
1196 } else if (bytelen == sizeof(uint16_t)) {
1197 val_16 = *((uint16_t *)buffer);
1198 *output = tfp_be_to_cpu_16(val_16);
1199 } else if (bytelen == sizeof(uint32_t)) {
1200 val_32 = *((uint32_t *)buffer);
1201 *output = tfp_be_to_cpu_32(val_32);
1202 } else if (bytelen == sizeof(val_64)) {
1203 val_64 = *((uint64_t *)buffer);
1204 *output = tfp_be_to_cpu_64(val_64);
1212 static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
1213 struct ulp_blob *blob,
1218 if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
1219 if (ulp_blob_pad_push(blob, val_len) < 0) {
1220 BNXT_TF_DBG(ERR, "too large for blob\n");
1223 } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
1224 if (ulp_blob_push_encap(blob, val, val_len) < 0) {
1225 BNXT_TF_DBG(ERR, "encap blob push failed\n");
1229 if (!ulp_blob_push(blob, val, val_len)) {
1230 BNXT_TF_DBG(ERR, "push of val1 failed\n");
1239 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
1241 struct bnxt_ulp_mapper_field_info *fld,
1242 struct ulp_blob *blob,
1246 uint16_t write_idx = blob->write_idx;
1247 uint8_t *val = NULL, *val1, *val2, *val3;
1248 uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
1249 uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
1250 uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
1251 uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
1252 uint64_t value1 = 0, value2 = 0, value3 = 0;
1255 /* prepare the field source and values */
1256 switch (fld->field_opc) {
1257 case BNXT_ULP_FIELD_OPC_SRC1:
1260 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1263 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1264 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1272 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1273 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1274 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1275 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1276 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1277 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1287 /* process the src1 opcode */
1289 if (ulp_mapper_field_src_process(parms, fld->field_src1,
1290 fld->field_opr1, dir, is_key,
1291 fld->field_bit_size, &val1,
1292 &val1_len, &value1)) {
1293 BNXT_TF_DBG(ERR, "fld src1 process failed\n");
1297 if (ulp_mapper_field_buffer_eval(val1, val1_len,
1299 BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
1305 /* for "if then clause" set the correct process */
1306 if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
1313 /* process src2 opcode */
1315 if (ulp_mapper_field_src_process(parms, fld->field_src2,
1316 fld->field_opr2, dir, is_key,
1317 fld->field_bit_size, &val2,
1318 &val2_len, &value2)) {
1319 BNXT_TF_DBG(ERR, "fld src2 process failed\n");
1323 if (ulp_mapper_field_buffer_eval(val2, val2_len,
1325 BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
1331 /* process src3 opcode */
1333 if (ulp_mapper_field_src_process(parms, fld->field_src3,
1334 fld->field_opr3, dir, is_key,
1335 fld->field_bit_size, &val3,
1336 &val3_len, &value3)) {
1337 BNXT_TF_DBG(ERR, "fld src3 process failed\n");
1341 if (ulp_mapper_field_buffer_eval(val3, val3_len,
1343 BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
1349 val_len = fld->field_bit_size;
1350 /* process the field opcodes */
1351 switch (fld->field_opc) {
1352 case BNXT_ULP_FIELD_OPC_SRC1:
1353 if (ulp_mapper_field_blob_write(fld->field_src1,
1354 blob, val1, val1_len, &val))
1358 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1360 if (ulp_mapper_field_blob_write(fld->field_src2, blob,
1361 val2, val2_len, &val))
1365 if (ulp_mapper_field_blob_write(fld->field_src3, blob,
1366 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);
1377 BNXT_TF_DBG(ERR, "push to blob failed\n");
1381 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1382 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1383 val_int = val1_int - val2_int;
1384 val_int = tfp_cpu_to_be_64(val_int);
1385 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1387 BNXT_TF_DBG(ERR, "push to blob failed\n");
1391 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1392 val_int = val1_int | val2_int;
1393 val_int = tfp_cpu_to_be_64(val_int);
1394 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1396 BNXT_TF_DBG(ERR, "push to blob failed\n");
1400 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1401 val_int = val1_int | val2_int | val3_int;
1402 val_int = tfp_cpu_to_be_64(val_int);
1403 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1405 BNXT_TF_DBG(ERR, "push to blob failed\n");
1409 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1410 val_int = val1_int & val2_int;
1411 val_int = tfp_cpu_to_be_64(val_int);
1412 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1414 BNXT_TF_DBG(ERR, "push to blob failed\n");
1418 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1419 val_int = val1_int & (val2_int | val3_int);
1420 val_int = tfp_cpu_to_be_64(val_int);
1421 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1423 BNXT_TF_DBG(ERR, "push to blob failed\n");
1427 case BNXT_ULP_FIELD_OPC_SKIP:
1435 BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
1436 fld->description, (val) ? write_idx : 0, val_len);
1441 * Result table process and fill the result blob.
1442 * data [out] - the result blob data
1445 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
1446 struct bnxt_ulp_mapper_tbl_info *tbl,
1447 struct ulp_blob *data,
1450 struct bnxt_ulp_mapper_field_info *dflds;
1451 uint32_t i, num_flds = 0, encap_flds = 0;
1454 /* Get the result field list */
1455 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
1458 /* validate the result field list counts */
1459 if ((tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1460 (!num_flds && !encap_flds)) || !dflds ||
1461 (tbl->resource_func != BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1462 (!num_flds || encap_flds))) {
1463 BNXT_TF_DBG(ERR, "Failed to get data fields %x:%x\n",
1464 num_flds, encap_flds);
1468 /* process the result fields, loop through them */
1469 for (i = 0; i < (num_flds + encap_flds); i++) {
1470 /* set the swap index if encap swap bit is enabled */
1471 if (parms->device_params->encap_byte_swap && encap_flds &&
1473 ulp_blob_encap_swap_idx_set(data);
1475 /* Process the result fields */
1476 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1477 &dflds[i], data, 0, name);
1479 BNXT_TF_DBG(ERR, "data field failed\n");
1484 /* if encap bit swap is enabled perform the bit swap */
1485 if (parms->device_params->encap_byte_swap && encap_flds)
1486 ulp_blob_perform_encap_swap(data);
1492 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1493 struct bnxt_ulp_mapper_tbl_info *tbl,
1496 struct ulp_flow_db_res_params fid_parms;
1497 uint32_t mark, gfid, mark_flag;
1498 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1501 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1502 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1503 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1504 BNXT_ULP_ACT_BIT_MARK)))
1505 return rc; /* no need to perform gfid process */
1507 /* Get the mark id details from action property */
1508 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1510 mark = tfp_be_to_cpu_32(mark);
1512 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1513 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1515 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1518 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1521 fid_parms.direction = tbl->direction;
1522 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1523 fid_parms.critical_resource = tbl->critical_resource;
1524 fid_parms.resource_type = mark_flag;
1525 fid_parms.resource_hndl = gfid;
1526 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1528 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1533 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1534 struct bnxt_ulp_mapper_tbl_info *tbl)
1536 struct ulp_flow_db_res_params fid_parms;
1537 uint32_t act_idx, mark, mark_flag;
1539 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1542 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1543 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1544 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1545 BNXT_ULP_ACT_BIT_MARK)))
1546 return rc; /* no need to perform mark action process */
1548 /* Get the mark id details from action property */
1549 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1551 mark = tfp_be_to_cpu_32(mark);
1553 if (!ulp_regfile_read(parms->regfile,
1554 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1556 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1559 act_idx = tfp_be_to_cpu_64(val64);
1560 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1561 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1564 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1567 fid_parms.direction = tbl->direction;
1568 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1569 fid_parms.critical_resource = tbl->critical_resource;
1570 fid_parms.resource_type = mark_flag;
1571 fid_parms.resource_hndl = act_idx;
1572 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1574 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1579 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1580 struct bnxt_ulp_mapper_tbl_info *tbl)
1582 struct ulp_flow_db_res_params fid_parms;
1583 uint32_t act_idx, mark, mark_flag;
1585 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1588 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1589 mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
1590 return rc; /* no need to perform mark action process */
1592 /* Get the mark id details from the computed field of dev port id */
1593 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1595 /* Get the main action pointer */
1596 if (!ulp_regfile_read(parms->regfile,
1597 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1599 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1602 act_idx = tfp_be_to_cpu_64(val64);
1604 /* Set the mark flag to local fid and vfr flag */
1605 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1607 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1610 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1613 fid_parms.direction = tbl->direction;
1614 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1615 fid_parms.critical_resource = tbl->critical_resource;
1616 fid_parms.resource_type = mark_flag;
1617 fid_parms.resource_hndl = act_idx;
1618 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1620 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1624 /* Tcam table scan the identifier list and allocate each identifier */
1626 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1627 struct bnxt_ulp_mapper_tbl_info *tbl)
1629 struct bnxt_ulp_mapper_ident_info *idents;
1630 uint32_t num_idents;
1633 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1634 for (i = 0; i < num_idents; i++) {
1635 if (ulp_mapper_ident_process(parms, tbl,
1643 * Tcam table scan the identifier list and extract the identifier from
1647 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1648 struct bnxt_ulp_mapper_tbl_info *tbl,
1649 struct ulp_blob *data)
1651 struct bnxt_ulp_mapper_ident_info *idents;
1652 uint32_t num_idents = 0, i;
1656 * Extract the listed identifiers from the result field,
1657 * no need to allocate them.
1659 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1660 for (i = 0; i < num_idents; i++) {
1661 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1663 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1670 /* Internal function to write the tcam entry */
1672 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1673 struct bnxt_ulp_mapper_tbl_info *tbl,
1674 struct ulp_blob *key,
1675 struct ulp_blob *mask,
1676 struct ulp_blob *data,
1679 struct tf_set_tcam_entry_parms sparms = { 0 };
1684 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1686 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1690 sparms.dir = tbl->direction;
1691 sparms.tcam_tbl_type = tbl->resource_type;
1693 sparms.key = ulp_blob_data_get(key, &tmplen);
1694 sparms.key_sz_in_bits = tmplen;
1695 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1696 sparms.result = ulp_blob_data_get(data, &tmplen);
1697 sparms.result_sz_in_bits = tmplen;
1698 if (tf_set_tcam_entry(tfp, &sparms)) {
1699 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1700 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1701 tf_dir_2_str(sparms.dir), sparms.idx);
1706 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1708 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1716 * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
1718 * parms [in] The mappers parms with data related to the flow.
1720 * key [in] The original key to be transformed
1722 * mask [in] The original mask to be transformed
1724 * tkey [in/out] The transformed key
1726 * tmask [in/out] The transformed mask
1728 * returns zero on success, non-zero on failure
1731 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
1732 struct ulp_blob *key,
1733 struct ulp_blob *mask,
1734 struct ulp_blob *tkey,
1735 struct ulp_blob *tmask)
1737 uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
1738 uint32_t cword, i, rc;
1742 slice_width = dparms->wc_slice_width;
1743 clen = dparms->wc_ctl_size_bits;
1744 max_slices = dparms->wc_max_slices;
1745 blen = ulp_blob_data_len_get(key);
1747 /* Get the length of the key based on number of slices and width */
1750 while (tlen < blen &&
1751 num_slices <= max_slices) {
1752 num_slices = num_slices << 1;
1756 if (num_slices > max_slices) {
1757 BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
1761 /* The key/mask may not be on a natural slice boundary, pad it */
1763 if (ulp_blob_pad_push(key, pad) < 0 ||
1764 ulp_blob_pad_push(mask, pad) < 0) {
1765 BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
1769 /* The new length accounts for the ctrl word length and num slices */
1770 tlen = tlen + clen * num_slices;
1771 if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
1772 !ulp_blob_init(tmask, tlen, mask->byte_order)) {
1773 BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
1777 /* Build the transformed key/mask */
1778 cword = dparms->wc_mode_list[num_slices - 1];
1779 cword = tfp_cpu_to_be_32(cword);
1781 for (i = 0; i < num_slices; i++) {
1782 val = ulp_blob_push_32(tkey, &cword, clen);
1784 BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
1787 val = ulp_blob_push_32(tmask, &cword, clen);
1789 BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
1792 rc = ulp_blob_append(tkey, key, offset, slice_width);
1794 BNXT_TF_DBG(ERR, "Key blob append failed\n");
1797 rc = ulp_blob_append(tmask, mask, offset, slice_width);
1799 BNXT_TF_DBG(ERR, "Mask blob append failed\n");
1802 offset += slice_width;
1805 /* The key/mask are byte reversed on every 4 byte chunk */
1806 ulp_blob_perform_byte_reverse(tkey, 4);
1807 ulp_blob_perform_byte_reverse(tmask, 4);
1812 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1813 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
1815 ulp_blob_perform_64B_word_swap(blob);
1816 ulp_blob_perform_64B_byte_swap(blob);
1820 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1821 struct bnxt_ulp_mapper_tbl_info *tbl)
1823 struct bnxt_ulp_mapper_key_info *kflds;
1824 struct ulp_blob okey, omask, data, update_data;
1825 struct ulp_blob tkey, tmask; /* transform key and mask */
1826 struct ulp_blob *key, *mask;
1827 uint32_t i, num_kflds;
1830 struct bnxt_ulp_device_params *dparms = parms->device_params;
1831 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1832 struct tf_search_tcam_entry_parms searchparms = { 0 };
1833 struct ulp_flow_db_res_params fid_parms = { 0 };
1834 struct tf_free_tcam_entry_parms free_parms = { 0 };
1836 uint16_t tmplen = 0;
1839 /* Set the key and mask to the original key and mask. */
1843 /* Skip this if table opcode is NOP */
1844 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
1845 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
1846 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
1851 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1853 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1857 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1858 if (!kflds || !num_kflds) {
1859 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1863 if (!ulp_blob_init(key, tbl->blob_key_bit_size, tbl->byte_order) ||
1864 !ulp_blob_init(mask, tbl->blob_key_bit_size, tbl->byte_order) ||
1865 !ulp_blob_init(&data, tbl->result_bit_size, dparms->byte_order) ||
1866 !ulp_blob_init(&update_data, tbl->result_bit_size,
1867 dparms->byte_order)) {
1868 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1872 /* create the key/mask */
1874 * NOTE: The WC table will require some kind of flag to handle the
1875 * mode bits within the key/mask
1877 for (i = 0; i < num_kflds; i++) {
1879 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1880 &kflds[i].field_info_spec,
1881 key, 1, "TCAM Key");
1883 BNXT_TF_DBG(ERR, "Key field set failed %s\n",
1884 kflds[i].field_info_spec.description);
1888 /* Setup the mask */
1889 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1890 &kflds[i].field_info_mask,
1891 mask, 0, "TCAM Mask");
1893 BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
1894 kflds[i].field_info_mask.description);
1899 /* For wild card tcam perform the post process to swap the blob */
1900 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
1901 if (dparms->dynamic_pad_en) {
1902 /* Sets up the slices for writing to the WC TCAM */
1903 rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
1909 "Failed to post proc WC entry.\n");
1912 /* Now need to use the transform Key/Mask */
1916 ulp_mapper_wc_tcam_tbl_post_process(key);
1917 ulp_mapper_wc_tcam_tbl_post_process(mask);
1922 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1923 /* allocate the tcam index */
1924 aparms.dir = tbl->direction;
1925 aparms.tcam_tbl_type = tbl->resource_type;
1926 aparms.key = ulp_blob_data_get(key, &tmplen);
1927 aparms.key_sz_in_bits = tmplen;
1928 aparms.mask = ulp_blob_data_get(mask, &tmplen);
1930 /* calculate the entry priority */
1931 rc = ulp_mapper_priority_opc_process(parms, tbl,
1934 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1938 rc = tf_alloc_tcam_entry(tfp, &aparms);
1940 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1947 * Searching before allocation to see if we already have an
1948 * entry. This allows re-use of a constrained resource.
1950 searchparms.dir = tbl->direction;
1951 searchparms.tcam_tbl_type = tbl->resource_type;
1952 searchparms.key = ulp_blob_data_get(key, &tmplen);
1953 searchparms.key_sz_in_bits = tbl->key_bit_size;
1954 searchparms.mask = ulp_blob_data_get(mask, &tmplen);
1955 searchparms.alloc = 1;
1956 searchparms.result = ulp_blob_data_get(&data, &tmplen);
1957 searchparms.result_sz_in_bits = tbl->result_bit_size;
1959 /* calculate the entry priority */
1960 rc = ulp_mapper_priority_opc_process(parms, tbl,
1961 &searchparms.priority);
1963 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1967 rc = tf_search_tcam_entry(tfp, &searchparms);
1969 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
1973 /* Successful search, check the result */
1974 if (searchparms.search_status == REJECT) {
1975 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
1978 idx = searchparms.idx;
1979 hit = searchparms.hit;
1982 /* Write the tcam index into the regfile*/
1983 if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
1984 (uint64_t)tfp_cpu_to_be_64(idx))) {
1985 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
1988 /* Need to free the tcam idx, so goto error */
1992 /* if it is miss then it is same as no search before alloc */
1993 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1994 /*Scan identifier list, allocate identifier and update regfile*/
1995 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
1996 /* Create the result blob */
1998 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2000 /* write the tcam entry */
2002 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
2005 /*Scan identifier list, extract identifier and update regfile*/
2006 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
2011 /* Add the tcam index to the flow database */
2012 fid_parms.direction = tbl->direction;
2013 fid_parms.resource_func = tbl->resource_func;
2014 fid_parms.resource_type = tbl->resource_type;
2015 fid_parms.critical_resource = tbl->critical_resource;
2016 fid_parms.resource_hndl = idx;
2017 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2019 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2021 /* Need to free the identifier, so goto error */
2027 free_parms.dir = tbl->direction;
2028 free_parms.tcam_tbl_type = tbl->resource_type;
2029 free_parms.idx = idx;
2030 trc = tf_free_tcam_entry(tfp, &free_parms);
2032 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
2033 tbl->resource_type, tbl->direction, idx);
2038 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2039 struct bnxt_ulp_mapper_tbl_info *tbl)
2041 struct bnxt_ulp_mapper_key_info *kflds;
2042 struct ulp_blob key, data;
2043 uint32_t i, num_kflds;
2045 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2046 struct ulp_flow_db_res_params fid_parms = { 0 };
2047 struct tf_insert_em_entry_parms iparms = { 0 };
2048 struct tf_delete_em_entry_parms free_parms = { 0 };
2049 enum bnxt_ulp_flow_mem_type mtype;
2050 struct bnxt_ulp_device_params *dparms = parms->device_params;
2055 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2057 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
2061 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2062 if (!kflds || !num_kflds) {
2063 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2067 /* Initialize the key/result blobs */
2068 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
2070 !ulp_blob_init(&data, tbl->result_bit_size,
2072 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2076 /* create the key */
2077 for (i = 0; i < num_kflds; i++) {
2079 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2080 &kflds[i].field_info_spec,
2083 BNXT_TF_DBG(ERR, "Key field set failed.\n");
2088 /* if dynamic padding is enabled then add padding to result data */
2089 if (dparms->dynamic_pad_en) {
2090 /* add padding to make sure key is at byte boundary */
2091 ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
2094 pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
2096 BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
2099 ulp_blob_pad_push(&data, (uint32_t)pad);
2102 /* Create the result data blob */
2103 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
2105 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2108 if (dparms->dynamic_pad_en) {
2109 uint32_t abits = dparms->em_blk_align_bits;
2111 /* when dynamic padding is enabled merge result + key */
2112 rc = ulp_blob_block_merge(&data, &key, abits, pad);
2114 BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
2118 /* add padding to make sure merged result is at slice boundary*/
2119 ulp_blob_pad_align(&data, abits);
2121 ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
2124 /* do the transpose for the internal EM keys */
2125 if (tbl->resource_type == TF_MEM_INTERNAL) {
2126 if (dparms->em_key_align_bytes) {
2127 int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
2129 tmplen = ulp_blob_data_len_get(&key);
2130 ulp_blob_pad_push(&key, b - tmplen);
2132 tmplen = ulp_blob_data_len_get(&key);
2133 ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
2136 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
2137 &iparms.tbl_scope_id);
2139 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2144 * NOTE: the actual blob size will differ from the size in the tbl
2145 * entry due to the padding.
2147 iparms.dup_check = 0;
2148 iparms.dir = tbl->direction;
2149 iparms.mem = tbl->resource_type;
2150 iparms.key = ulp_blob_data_get(&key, &tmplen);
2151 iparms.key_sz_in_bits = tbl->key_bit_size;
2152 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
2153 if (tbl->result_bit_size)
2154 iparms.em_record_sz_in_bits = tbl->result_bit_size;
2156 iparms.em_record_sz_in_bits = tmplen;
2158 rc = tf_insert_em_entry(tfp, &iparms);
2160 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
2164 /* Mark action process */
2165 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
2166 tbl->resource_type == TF_MEM_EXTERNAL)
2167 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
2168 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
2169 tbl->resource_type == TF_MEM_INTERNAL)
2170 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
2172 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
2176 /* Link the EM resource to the flow in the flow db */
2177 memset(&fid_parms, 0, sizeof(fid_parms));
2178 fid_parms.direction = tbl->direction;
2179 fid_parms.resource_func = tbl->resource_func;
2180 fid_parms.resource_type = tbl->resource_type;
2181 fid_parms.critical_resource = tbl->critical_resource;
2182 fid_parms.resource_hndl = iparms.flow_handle;
2184 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2186 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
2188 /* Need to free the identifier, so goto error */
2194 free_parms.dir = iparms.dir;
2195 free_parms.mem = iparms.mem;
2196 free_parms.tbl_scope_id = iparms.tbl_scope_id;
2197 free_parms.flow_handle = iparms.flow_handle;
2199 trc = tf_delete_em_entry(tfp, &free_parms);
2201 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
2207 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2208 struct bnxt_ulp_mapper_tbl_info *tbl)
2210 struct ulp_flow_db_res_params fid_parms;
2211 struct ulp_blob data;
2212 uint64_t regval = 0;
2215 int32_t rc = 0, trc = 0;
2216 struct tf_alloc_tbl_entry_parms aparms = { 0 };
2217 struct tf_set_tbl_entry_parms sparms = { 0 };
2218 struct tf_get_tbl_entry_parms gparms = { 0 };
2219 struct tf_free_tbl_entry_parms free_parms = { 0 };
2220 uint32_t tbl_scope_id;
2221 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2222 struct bnxt_ulp_glb_resource_info glb_res;
2226 bool global = false;
2227 uint64_t act_rec_size;
2228 bool shared = false;
2230 /* use the max size if encap is enabled */
2231 if (tbl->encap_num_fields)
2232 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
2234 bit_size = tbl->result_bit_size;
2236 /* Initialize the blob data */
2237 if (!ulp_blob_init(&data, bit_size,
2238 parms->device_params->byte_order)) {
2239 BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
2243 /* Get the scope id first */
2244 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
2246 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2250 switch (tbl->tbl_opcode) {
2251 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
2254 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
2256 * Build the entry, alloc an index, write the table, and store
2257 * the data in the regfile.
2262 case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
2264 * get the index to write to from the regfile and then write
2267 if (!ulp_regfile_read(parms->regfile,
2271 "Failed to get tbl idx from regfile[%d].\n",
2275 index = tfp_be_to_cpu_64(regval);
2276 /* For external, we need to reverse shift */
2277 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2278 index = TF_ACT_REC_PTR_2_OFFSET(index);
2282 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
2284 * Build the entry, alloc an index, write the table, and store
2285 * the data in the global regfile.
2290 glb_res.direction = tbl->direction;
2291 glb_res.resource_func = tbl->resource_func;
2292 glb_res.resource_type = tbl->resource_type;
2293 glb_res.glb_regfile_index = tbl->tbl_operand;
2295 case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
2296 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2297 BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
2301 * get the index to write to from the global regfile and then
2304 if (ulp_mapper_glb_resource_read(parms->mapper_data,
2307 ®val, &shared)) {
2309 "Failed to get tbl idx from Global "
2314 index = tfp_be_to_cpu_64(regval);
2315 /* For external, we need to reverse shift */
2316 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2317 index = TF_ACT_REC_PTR_2_OFFSET(index);
2320 case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
2322 * The read is different from the rest and can be handled here
2323 * instead of trying to use common code. Simply read the table
2324 * with the index from the regfile, scan and store the
2325 * identifiers, and return.
2327 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2328 /* Not currently supporting with EXT */
2330 "Ext Table Read Opcode not supported.\n");
2333 if (!ulp_regfile_read(parms->regfile,
2334 tbl->tbl_operand, ®val)) {
2336 "Failed to get tbl idx from regfile[%d]\n",
2340 index = tfp_be_to_cpu_64(regval);
2341 gparms.dir = tbl->direction;
2342 gparms.type = tbl->resource_type;
2343 gparms.data = ulp_blob_data_get(&data, &tmplen);
2344 gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tbl->result_bit_size);
2346 rc = tf_get_tbl_entry(tfp, &gparms);
2348 BNXT_TF_DBG(ERR, "Failed to read the tbl entry %d:%d\n",
2349 tbl->resource_type, index);
2353 * Scan the fields in the entry and push them into the regfile.
2355 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2357 gparms.data_sz_in_bytes,
2360 BNXT_TF_DBG(ERR, "Failed to read fields on tbl read "
2366 BNXT_TF_DBG(ERR, "Invalid index table opcode %d\n",
2372 /* Get the result fields list */
2373 rc = ulp_mapper_tbl_result_build(parms,
2378 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2384 aparms.dir = tbl->direction;
2385 aparms.type = tbl->resource_type;
2386 aparms.tbl_scope_id = tbl_scope_id;
2388 /* All failures after the alloc succeeds require a free */
2389 rc = tf_alloc_tbl_entry(tfp, &aparms);
2391 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2392 tf_tbl_type_2_str(tbl->resource_type),
2393 tf_dir_2_str(tbl->direction), rc);
2399 * Store the index in the regfile since we either allocated it
2402 * Calculate the idx for the result record, for external EM the
2403 * offset needs to be shifted accordingly.
2404 * If external non-inline table types are used then need to
2405 * revisit this logic.
2407 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2408 regval = TF_ACT_REC_OFFSET_2_PTR(index);
2411 regval = tfp_cpu_to_be_64(regval);
2415 * Shared resources are never allocated through this
2416 * method, so the shared flag is always false.
2418 rc = ulp_mapper_glb_resource_write(parms->mapper_data,
2422 rc = ulp_regfile_write(parms->regfile,
2423 tbl->tbl_operand, regval);
2427 "Failed to write %s regfile[%d] rc=%d\n",
2428 (global) ? "global" : "reg",
2429 tbl->tbl_operand, rc);
2435 sparms.dir = tbl->direction;
2436 sparms.type = tbl->resource_type;
2437 sparms.data = ulp_blob_data_get(&data, &tmplen);
2438 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2440 sparms.tbl_scope_id = tbl_scope_id;
2442 tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
2443 rc = tf_set_tbl_entry(tfp, &sparms);
2446 "Index table[%s][%s][%x] write failed "
2448 tf_tbl_type_2_str(sparms.type),
2449 tf_dir_2_str(sparms.dir),
2454 /* Calculate action record size */
2455 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2456 act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
2458 if (ulp_regfile_write(parms->regfile,
2459 BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
2460 tfp_cpu_to_be_64(act_rec_size)))
2462 "Failed write the act rec size\n");
2466 /* Link the resource to the flow in the flow db */
2467 memset(&fid_parms, 0, sizeof(fid_parms));
2468 fid_parms.direction = tbl->direction;
2469 fid_parms.resource_func = tbl->resource_func;
2470 fid_parms.resource_type = tbl->resource_type;
2471 fid_parms.resource_sub_type = tbl->resource_sub_type;
2472 fid_parms.resource_hndl = index;
2473 fid_parms.critical_resource = tbl->critical_resource;
2475 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2477 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2482 /* Perform the VF rep action */
2483 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2485 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2490 /* Shared resources are not freed */
2494 * Free the allocated resource since we failed to either
2495 * write to the entry or link the flow
2497 free_parms.dir = tbl->direction;
2498 free_parms.type = tbl->resource_type;
2499 free_parms.idx = index;
2500 free_parms.tbl_scope_id = tbl_scope_id;
2502 trc = tf_free_tbl_entry(tfp, &free_parms);
2504 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2510 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2511 struct bnxt_ulp_mapper_tbl_info *tbl)
2513 struct ulp_blob data, res_blob;
2517 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2518 struct tf_get_if_tbl_entry_parms get_parms = { 0 };
2519 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2520 enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
2523 /* Initialize the blob data */
2524 if (!ulp_blob_init(&data, tbl->result_bit_size,
2525 parms->device_params->byte_order)) {
2526 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2530 /* create the result blob */
2531 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
2533 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2537 /* Get the index details */
2539 case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
2540 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2542 case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
2543 if (!ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx)) {
2544 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
2548 idx = tfp_be_to_cpu_64(idx);
2550 case BNXT_ULP_IF_TBL_OPC_WR_CONST:
2551 idx = tbl->tbl_operand;
2553 case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
2554 /* Initialize the result blob */
2555 if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
2556 parms->device_params->byte_order)) {
2557 BNXT_TF_DBG(ERR, "Failed initial result blob\n");
2561 /* read the interface table */
2562 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2563 res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
2564 get_parms.dir = tbl->direction;
2565 get_parms.type = tbl->resource_type;
2566 get_parms.idx = idx;
2567 get_parms.data = ulp_blob_data_get(&res_blob, &tmplen);
2568 get_parms.data_sz_in_bytes = res_size;
2570 rc = tf_get_if_tbl_entry(tfp, &get_parms);
2572 BNXT_TF_DBG(ERR, "Get table[%d][%s][%x] failed rc=%d\n",
2574 tf_dir_2_str(get_parms.dir),
2578 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2581 res_blob.byte_order);
2583 BNXT_TF_DBG(ERR, "Scan and extract failed rc=%d\n", rc);
2585 case BNXT_ULP_IF_TBL_OPC_NOT_USED:
2586 return rc; /* skip it */
2588 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2592 /* Perform the tf table set by filling the set params */
2593 iftbl_params.dir = tbl->direction;
2594 iftbl_params.type = tbl->resource_type;
2595 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2596 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2597 iftbl_params.idx = idx;
2599 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2601 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2602 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2603 tf_dir_2_str(iftbl_params.dir),
2604 iftbl_params.idx, rc);
2609 * TBD: Need to look at the need to store idx in flow db for restore
2610 * the table to its original state on deletion of this entry.
2616 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2617 struct bnxt_ulp_mapper_tbl_info *tbl)
2619 struct ulp_mapper_gen_tbl_list *gen_tbl_list;
2620 struct bnxt_ulp_mapper_key_info *kflds;
2621 struct ulp_flow_db_res_params fid_parms;
2622 struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
2623 struct ulp_gen_hash_entry_params hash_entry;
2625 struct ulp_blob key, data;
2628 uint32_t i, num_kflds = 0, key_index = 0;
2629 uint32_t gen_tbl_miss = 1, fdb_write = 0;
2633 /* Get the key fields list and build the key. */
2634 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2635 if (!kflds || !num_kflds) {
2636 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2640 if (!ulp_blob_init(&key, tbl->key_bit_size,
2641 parms->device_params->byte_order)) {
2642 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2645 for (i = 0; i < num_kflds; i++) {
2647 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2648 &kflds[i].field_info_spec,
2649 &key, 1, "Gen Tbl Key");
2652 "Failed to create key for Gen tbl rc=%d\n",
2658 /* Calculate the table index for the generic table*/
2659 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2662 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2663 tbl->resource_sub_type, tbl->direction);
2667 /* The_key is a byte array convert it to a search index */
2668 cache_key = ulp_blob_data_get(&key, &tmplen);
2669 /* get the generic table */
2670 gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
2672 /* Check if generic hash table */
2673 if (gen_tbl_list->hash_tbl) {
2674 if (tbl->gen_tbl_lkup_type !=
2675 BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
2676 BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
2677 gen_tbl_list->gen_tbl_name);
2680 hash_entry.key_data = cache_key;
2681 hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
2682 rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
2685 BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
2686 gen_tbl_list->gen_tbl_name);
2689 if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
2690 key_index = hash_entry.key_idx;
2691 /* Get the generic table entry */
2692 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
2696 /* store the hash index in the fdb */
2697 key_index = hash_entry.hash_index;
2700 /* convert key to index directly */
2701 memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
2702 /* Get the generic table entry */
2703 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
2707 switch (tbl->tbl_opcode) {
2708 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2709 if (gen_tbl_list->hash_tbl) {
2710 if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
2711 break; /* nothing to be done , no entry */
2714 /* check the reference count */
2715 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2717 /* Scan ident list and create the result blob*/
2718 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2724 "Failed to scan ident list\n");
2727 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2728 /* increment the reference count */
2729 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2737 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
2738 if (gen_tbl_list->hash_tbl) {
2739 rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
2744 /* store the hash index in the fdb */
2745 key_index = hash_entry.hash_index;
2747 /* check the reference count */
2748 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2749 /* a hit then error */
2750 BNXT_TF_DBG(ERR, "generic entry already present\n");
2751 return -EINVAL; /* success */
2754 /* Initialize the blob data */
2755 if (!ulp_blob_init(&data, tbl->result_bit_size,
2756 gen_tbl_ent.byte_order)) {
2757 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2761 /* Get the result fields list */
2762 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2765 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2768 byte_data = ulp_blob_data_get(&data, &tmplen);
2769 rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
2771 ULP_BITS_2_BYTE(tmplen));
2773 BNXT_TF_DBG(ERR, "Failed to write generic table\n");
2777 /* increment the reference count */
2778 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2780 parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
2783 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
2787 /* Set the generic entry hit */
2788 rc = ulp_regfile_write(parms->regfile,
2789 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
2790 tfp_cpu_to_be_64(gen_tbl_miss));
2792 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2793 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
2797 /* add the entry to the flow database */
2799 memset(&fid_parms, 0, sizeof(fid_parms));
2800 fid_parms.direction = tbl->direction;
2801 fid_parms.resource_func = tbl->resource_func;
2802 fid_parms.resource_sub_type = tbl->resource_sub_type;
2803 fid_parms.resource_hndl = key_index;
2804 fid_parms.critical_resource = tbl->critical_resource;
2805 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2807 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
2813 ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2814 struct bnxt_ulp_mapper_tbl_info *tbl)
2818 /* process the fdb opcode for alloc push */
2819 if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
2820 rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
2822 BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
2830 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2831 struct bnxt_ulp_mapper_data *mapper_data)
2833 struct bnxt_ulp_glb_resource_info *glb_res;
2834 uint32_t num_glb_res_ids, idx, dev_id;
2838 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
2839 if (!glb_res || !num_glb_res_ids) {
2840 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2844 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2846 BNXT_TF_DBG(ERR, "Failed to get device id for "
2847 "global init (%d)\n", rc);
2851 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2853 BNXT_TF_DBG(ERR, "Failed to get app id for "
2854 "global init (%d)\n", rc);
2858 /* Iterate the global resources and process each one */
2859 for (idx = 0; idx < num_glb_res_ids; idx++) {
2860 if (dev_id != glb_res[idx].device_id ||
2861 glb_res[idx].app_id != app_id)
2863 switch (glb_res[idx].resource_func) {
2864 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2865 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
2869 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2870 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2875 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2876 glb_res[idx].resource_func);
2887 * Iterate over the shared resources assigned during tf_open_session and store
2888 * them in the global regfile with the shared flag.
2891 ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2892 struct bnxt_ulp_mapper_data *mapper_data)
2894 struct bnxt_ulp_glb_resource_info *glb_res;
2895 struct tf_get_session_info_parms sparms;
2896 uint32_t num_entries, i, dev_id, res;
2897 struct tf_resource_info *res_info;
2904 memset(&sparms, 0, sizeof(sparms));
2906 glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
2907 if (!glb_res || !num_entries) {
2908 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2912 tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
2914 BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
2918 * Retrieve the resources that were assigned during the shared session
2921 rc = tf_get_session_info(tfp, &sparms);
2923 BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
2927 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2929 BNXT_TF_DBG(ERR, "Failed to get the app id in global init "
2934 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2936 BNXT_TF_DBG(ERR, "Failed to get device id for app "
2937 "global init (%d)\n", rc);
2941 /* Store all the app global resources */
2942 for (i = 0; i < num_entries; i++) {
2943 if (dev_id != glb_res[i].device_id ||
2944 app_id != glb_res[i].app_id)
2946 dir = glb_res[i].direction;
2947 res = glb_res[i].resource_type;
2949 switch (glb_res[i].resource_func) {
2950 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2951 res_info = &sparms.session_info.ident[dir].info[res];
2953 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2954 res_info = &sparms.session_info.tbl[dir].info[res];
2956 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2957 res_info = &sparms.session_info.tcam[dir].info[res];
2959 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
2960 res_info = &sparms.session_info.em[dir].info[res];
2963 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
2964 glb_res[i].resource_func);
2968 regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
2972 * All resources written to the global regfile are shared for
2975 rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
2985 * Common conditional opcode process routine that is used for both the template
2986 * rejection and table conditional execution.
2989 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
2990 enum bnxt_ulp_cond_opc opc,
2994 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
3000 case BNXT_ULP_COND_OPC_CF_IS_SET:
3001 if (operand < BNXT_ULP_CF_IDX_LAST) {
3002 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
3004 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3009 case BNXT_ULP_COND_OPC_CF_NOT_SET:
3010 if (operand < BNXT_ULP_CF_IDX_LAST) {
3011 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
3013 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3018 case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
3019 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3020 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3023 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3028 case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
3029 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3030 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3033 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3038 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
3039 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3040 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3043 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3048 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
3049 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3050 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3053 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3058 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
3059 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3061 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3065 *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3067 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
3068 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3070 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3074 *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3076 case BNXT_ULP_COND_OPC_RF_IS_SET:
3077 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3078 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3083 case BNXT_ULP_COND_OPC_RF_NOT_SET:
3084 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3085 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3090 case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
3091 if (parms->flow_pattern_id == operand) {
3092 BNXT_TF_DBG(ERR, "field pattern match failed %x\n",
3093 parms->flow_pattern_id);
3097 case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
3098 if (parms->act_pattern_id == operand) {
3099 BNXT_TF_DBG(ERR, "act pattern match failed %x\n",
3100 parms->act_pattern_id);
3104 case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
3105 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3106 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3109 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
3111 case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
3112 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3113 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3116 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
3119 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
3127 ulp_mapper_cc_upd_opr_compute(struct bnxt_ulp_mapper_parms *parms,
3129 enum bnxt_ulp_cc_upd_src cc_src,
3138 case BNXT_ULP_CC_UPD_SRC_COMP_FIELD:
3139 if (cc_opr >= BNXT_ULP_CF_IDX_LAST) {
3140 BNXT_TF_DBG(ERR, "invalid index %u\n", cc_opr);
3143 *result = (uint64_t)ULP_COMP_FLD_IDX_RD(parms, cc_opr);
3145 case BNXT_ULP_CC_UPD_SRC_REGFILE:
3146 if (!ulp_regfile_read(parms->regfile, cc_opr, ®val)) {
3147 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", cc_opr);
3150 *result = tfp_be_to_cpu_64(regval);
3152 case BNXT_ULP_CC_UPD_SRC_GLB_REGFILE:
3153 if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
3154 cc_opr, ®val, &shared)) {
3155 BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
3159 *result = tfp_be_to_cpu_64(regval);
3161 case BNXT_ULP_CC_UPD_SRC_CONST:
3165 BNXT_TF_DBG(ERR, "invalid src code %u\n", cc_src);
3172 ulp_mapper_cc_upd_info_process(struct bnxt_ulp_mapper_parms *parms,
3173 struct bnxt_ulp_mapper_tbl_info *tbl)
3175 struct bnxt_ulp_mapper_cc_upd_info *cc_upd = &tbl->cc_upd_info;
3176 uint64_t res = 0, res1, res2;
3179 if (cc_upd->cc_opc == BNXT_ULP_CC_UPD_OPC_NOP)
3182 rc = ulp_mapper_cc_upd_opr_compute(parms, tbl->direction,
3184 cc_upd->cc_opr1, &res1);
3188 rc = ulp_mapper_cc_upd_opr_compute(parms, tbl->direction,
3190 cc_upd->cc_opr2, &res2);
3194 switch (cc_upd->cc_opc) {
3195 case BNXT_ULP_CC_UPD_OPC_NOP:
3198 case BNXT_ULP_CC_UPD_OPC_EQ:
3202 case BNXT_ULP_CC_UPD_OPC_NE:
3206 case BNXT_ULP_CC_UPD_OPC_GE:
3210 case BNXT_ULP_CC_UPD_OPC_GT:
3214 case BNXT_ULP_CC_UPD_OPC_LE:
3218 case BNXT_ULP_CC_UPD_OPC_LT:
3222 case BNXT_ULP_CC_UPD_OPC_LAST:
3223 BNXT_TF_DBG(ERR, "invalid code %u\n", cc_upd->cc_opc);
3226 if (ulp_regfile_write(parms->regfile, cc_upd->cc_dst_opr,
3227 tfp_cpu_to_be_64(res))) {
3228 BNXT_TF_DBG(ERR, "Failed write the cc_opc %u\n",
3229 cc_upd->cc_dst_opr);
3238 * Processes a list of conditions and returns both a status and result of the
3239 * list. The status must be checked prior to verifying the result.
3241 * returns 0 for success, negative on failure
3242 * returns res = 1 for true, res = 0 for false.
3245 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
3246 enum bnxt_ulp_cond_list_opc list_opc,
3247 struct bnxt_ulp_mapper_cond_info *list,
3252 int32_t rc = 0, trc = 0;
3255 case BNXT_ULP_COND_LIST_OPC_AND:
3256 /* AND Defaults to true. */
3259 case BNXT_ULP_COND_LIST_OPC_OR:
3260 /* OR Defaults to false. */
3263 case BNXT_ULP_COND_LIST_OPC_TRUE:
3266 case BNXT_ULP_COND_LIST_OPC_FALSE:
3270 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
3276 for (i = 0; i < num; i++) {
3277 rc = ulp_mapper_cond_opc_process(parms,
3278 list[i].cond_opcode,
3279 list[i].cond_operand,
3284 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
3285 /* early return if result is ever zero */
3291 /* early return if result is ever non-zero */
3303 * Processes conflict resolution and returns both a status and result.
3304 * The status must be checked prior to verifying the result.
3306 * returns 0 for success, negative on failure
3307 * returns res = 1 for true, res = 0 for false.
3310 ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
3311 struct bnxt_ulp_mapper_tbl_info *tbl,
3316 uint64_t comp_sig_id;
3319 switch (tbl->accept_opcode) {
3320 case BNXT_ULP_ACCEPT_OPC_ALWAYS:
3323 case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
3324 /* perform the signature validation*/
3325 if (tbl->resource_func ==
3326 BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
3327 /* Perform the check that generic table is hit or not */
3328 if (!ulp_regfile_read(parms->regfile,
3329 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3331 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3332 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3336 /* not a hit so no need to check flow sign*/
3341 /* compare the new flow signature against stored one */
3342 if (!ulp_regfile_read(parms->regfile,
3343 BNXT_ULP_RF_IDX_FLOW_SIG_ID,
3345 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3346 BNXT_ULP_RF_IDX_FLOW_SIG_ID);
3349 comp_sig_id = ULP_COMP_FLD_IDX_RD(parms,
3350 BNXT_ULP_CF_IDX_FLOW_SIG_ID);
3351 regval = tfp_be_to_cpu_64(regval);
3352 if (comp_sig_id == regval)
3355 BNXT_TF_DBG(ERR, "failed signature match %x:%x\n",
3356 (uint32_t)comp_sig_id, (uint32_t)regval);
3359 BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
3360 tbl->accept_opcode);
3367 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
3369 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
3370 enum bnxt_ulp_cond_list_opc cond_opc;
3371 struct bnxt_ulp_mapper_tbl_info *tbls;
3372 struct bnxt_ulp_mapper_tbl_info *tbl;
3373 uint32_t num_tbls, tbl_idx, num_cond_tbls;
3374 int32_t rc = -EINVAL, cond_rc = 0;
3375 int32_t cond_goto = 1;
3377 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
3381 * Process the reject list if exists, otherwise assume that the
3382 * template is allowed.
3384 if (cond_tbls && num_cond_tbls) {
3385 rc = ulp_mapper_cond_opc_list_process(parms,
3393 /* Reject the template if True */
3395 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
3396 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3402 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
3403 if (!tbls || !num_tbls) {
3404 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
3405 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3406 parms->dev_id, tid);
3410 for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
3411 tbl = &tbls[tbl_idx];
3412 /* Process the conditional code update opcodes */
3413 if (ulp_mapper_cc_upd_info_process(parms, tbl)) {
3414 BNXT_TF_DBG(ERR, "Failed to process cond update\n");
3419 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
3422 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
3423 cond_tbls, num_cond_tbls,
3426 BNXT_TF_DBG(ERR, "Failed to process cond opc list "
3430 /* Skip the table if False */
3432 cond_goto = tbl->execute_info.cond_false_goto;
3433 goto next_iteration;
3436 switch (tbl->resource_func) {
3437 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3438 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
3440 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3441 rc = ulp_mapper_em_tbl_process(parms, tbl);
3443 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3444 rc = ulp_mapper_index_tbl_process(parms, tbl);
3446 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
3447 rc = ulp_mapper_if_tbl_process(parms, tbl);
3449 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3450 rc = ulp_mapper_gen_tbl_process(parms, tbl);
3452 case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
3453 rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
3455 case BNXT_ULP_RESOURCE_FUNC_INVALID:
3459 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
3460 tbl->resource_func);
3466 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
3467 tbl->resource_func);
3471 /* perform the post table process */
3472 rc = ulp_mapper_conflict_resolution_process(parms, tbl,
3474 if (rc || !cond_rc) {
3475 BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
3480 if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
3481 BNXT_TF_DBG(ERR, "reject the flow\n");
3484 } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
3488 /* least significant 16 bits from reg_file index */
3489 rf_idx = (uint32_t)(cond_goto & 0xFFFF);
3490 if (!ulp_regfile_read(parms->regfile, rf_idx,
3492 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3497 cond_goto = (int32_t)regval;
3500 if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
3501 BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
3505 tbl_idx += cond_goto;
3510 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
3511 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3512 parms->dev_id, tid);
3517 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
3519 struct ulp_flow_db_res_params *res)
3525 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
3529 tfp = bnxt_ulp_cntxt_tfp_get(ulp);
3531 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
3535 switch (res->resource_func) {
3536 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3537 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
3539 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3540 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
3542 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3543 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
3545 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3546 rc = ulp_mapper_ident_free(ulp, tfp, res);
3548 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
3549 rc = ulp_mapper_mark_free(ulp, res);
3551 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
3552 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
3554 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
3555 rc = ulp_mapper_child_flow_free(ulp, fid, res);
3557 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3558 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
3568 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
3569 enum bnxt_ulp_fdb_type flow_type,
3572 struct ulp_flow_db_res_params res_parms = { 0 };
3576 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3581 * Set the critical resource on the first resource del, then iterate
3582 * while status is good
3584 if (flow_type != BNXT_ULP_FDB_TYPE_RID)
3585 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
3587 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
3591 * This is unexpected on the first call to resource del.
3592 * It likely means that the flow did not exist in the flow db.
3594 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
3595 flow_type, fid, rc);
3600 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
3603 * On fail, we still need to attempt to free the
3604 * remaining resources. Don't return
3607 "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
3608 "] failed rc=%d.\n",
3609 flow_type, fid, res_parms.resource_func,
3610 res_parms.resource_hndl, trc);
3612 /* All subsequent call require the non-critical_resource */
3613 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
3615 rc = ulp_flow_db_resource_del(ulp_ctx,
3621 /* Free the Flow ID since we've removed all resources */
3622 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
3628 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
3629 struct bnxt_ulp_mapper_data *mapper_data)
3631 struct bnxt_ulp_mapper_glb_resource_entry *ent;
3632 struct ulp_flow_db_res_params res;
3635 /* Iterate the global resources and process each one */
3636 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
3637 for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
3638 ent = &mapper_data->glb_res_tbl[dir][idx];
3639 if (ent->resource_func ==
3640 BNXT_ULP_RESOURCE_FUNC_INVALID ||
3643 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
3644 res.resource_func = ent->resource_func;
3645 res.direction = dir;
3646 res.resource_type = ent->resource_type;
3647 /*convert it from BE to cpu */
3649 tfp_be_to_cpu_64(ent->resource_hndl);
3650 ulp_mapper_resource_free(ulp_ctx, 0, &res);
3656 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
3657 enum bnxt_ulp_fdb_type flow_type,
3663 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3667 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
3671 /* Function to handle the mapping of the Flow to be compatible
3672 * with the underlying hardware.
3675 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
3676 struct bnxt_ulp_mapper_create_parms *cparms)
3678 struct bnxt_ulp_mapper_parms parms;
3679 struct ulp_regfile regfile;
3680 int32_t rc = 0, trc;
3682 if (!ulp_ctx || !cparms)
3685 /* Initialize the parms structure */
3686 memset(&parms, 0, sizeof(parms));
3687 parms.act_prop = cparms->act_prop;
3688 parms.act_bitmap = cparms->act;
3689 parms.hdr_bitmap = cparms->hdr_bitmap;
3690 parms.regfile = ®file;
3691 parms.hdr_field = cparms->hdr_field;
3692 parms.fld_bitmap = cparms->fld_bitmap;
3693 parms.comp_fld = cparms->comp_fld;
3694 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3695 parms.ulp_ctx = ulp_ctx;
3696 parms.act_tid = cparms->act_tid;
3697 parms.class_tid = cparms->class_tid;
3698 parms.flow_type = cparms->flow_type;
3699 parms.parent_flow = cparms->parent_flow;
3700 parms.parent_fid = cparms->parent_fid;
3701 parms.fid = cparms->flow_id;
3702 parms.tun_idx = cparms->tun_idx;
3703 parms.app_priority = cparms->app_priority;
3704 parms.flow_pattern_id = cparms->flow_pattern_id;
3705 parms.act_pattern_id = cparms->act_pattern_id;
3707 /* Get the device id from the ulp context */
3708 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
3709 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
3713 /* Get the device params, it will be used in later processing */
3714 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
3715 if (!parms.device_params) {
3716 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
3722 * Get the mapper data for dynamic mapper data such as default
3725 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
3726 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3727 if (!parms.mapper_data) {
3728 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
3732 /* initialize the registry file for further processing */
3733 if (!ulp_regfile_init(parms.regfile)) {
3734 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
3738 /* Process the action template list from the selected action table*/
3739 if (parms.act_tid) {
3740 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
3741 /* Process the action template tables */
3742 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
3745 cparms->shared_hndl = parms.shared_hndl;
3748 if (parms.class_tid) {
3749 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
3751 /* Process the class template tables.*/
3752 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
3757 /* setup the parent-child details */
3758 if (parms.parent_flow) {
3759 /* create a parent flow details */
3760 rc = ulp_flow_db_parent_flow_create(&parms);
3763 } else if (parms.parent_fid) {
3764 /* create a child flow details */
3765 rc = ulp_flow_db_child_flow_create(&parms);
3773 /* Free all resources that were allocated during flow creation */
3774 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
3777 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
3783 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
3785 struct bnxt_ulp_mapper_data *data;
3792 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3796 data = rte_zmalloc("ulp_mapper_data",
3797 sizeof(struct bnxt_ulp_mapper_data), 0);
3799 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
3803 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
3804 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
3805 /* Don't call deinit since the prof_func wasn't allocated. */
3810 /* Allocate the global resource ids */
3811 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
3813 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
3818 * Only initialize the app global resources if a shared session was
3821 if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
3822 rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
3824 BNXT_TF_DBG(ERR, "Failed to initialize app "
3825 "global resources\n");
3830 /* Allocate the generic table list */
3831 rc = ulp_mapper_generic_tbl_list_init(data);
3833 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
3839 /* Ignore the return code in favor of returning the original error. */
3840 ulp_mapper_deinit(ulp_ctx);
3845 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
3847 struct bnxt_ulp_mapper_data *data;
3852 "Failed to acquire ulp context, so data may "
3853 "not be released.\n");
3857 data = (struct bnxt_ulp_mapper_data *)
3858 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3860 /* Go ahead and return since there is no allocated data. */
3861 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
3865 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3867 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
3868 /* Free the mapper data regardless of errors. */
3869 goto free_mapper_data;
3872 /* Free the global resource info table entries */
3873 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
3876 /* Free the generic table */
3877 (void)ulp_mapper_generic_tbl_list_deinit(data);
3880 /* Reset the data pointer within the ulp_ctx. */
3881 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);