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, BNXT_ULP_SHARED_SESSION_NO);
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, BNXT_ULP_SHARED_SESSION_NO);
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, tbl->shared_session);
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;
779 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
781 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
783 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
785 /* Need to free the identifier, so goto error */
794 /* Need to free the identifier */
795 free_parms.dir = tbl->direction;
796 free_parms.ident_type = ident->ident_type;
797 free_parms.id = iparms.id;
799 (void)tf_free_identifier(tfp, &free_parms);
801 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
803 tf_dir_2_str(tbl->direction));
808 * Process the identifier instruction and extract it from result blob.
809 * Increment the identifier reference count and store it in the flow database.
812 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
813 struct bnxt_ulp_mapper_tbl_info *tbl,
814 struct bnxt_ulp_mapper_ident_info *ident,
815 struct ulp_blob *res_blob)
817 struct ulp_flow_db_res_params fid_parms;
820 struct tf_search_identifier_parms sparms = { 0 };
821 struct tf_free_identifier_parms free_parms = { 0 };
825 /* Get the tfp from ulp context */
826 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
828 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
832 /* Extract the index from the result blob */
833 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
834 ident->ident_bit_pos, ident->ident_bit_size);
836 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
840 /* populate the search params and search identifier shadow table */
841 sparms.ident_type = ident->ident_type;
842 sparms.dir = tbl->direction;
843 /* convert the idx into cpu format */
844 sparms.search_id = tfp_be_to_cpu_32(idx);
846 /* Search identifier also increase the reference count */
847 rc = tf_search_identifier(tfp, &sparms);
849 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
850 tf_dir_2_str(sparms.dir),
851 tf_ident_2_str(sparms.ident_type),
856 /* Write it to the regfile */
857 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
858 if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
859 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
861 /* Need to free the identifier, so goto error */
865 /* Link the resource to the flow in the flow db */
866 memset(&fid_parms, 0, sizeof(fid_parms));
867 fid_parms.direction = tbl->direction;
868 fid_parms.resource_func = ident->resource_func;
869 fid_parms.resource_type = ident->ident_type;
870 fid_parms.resource_hndl = sparms.search_id;
871 fid_parms.critical_resource = tbl->critical_resource;
872 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
874 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
876 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
878 /* Need to free the identifier, so goto error */
885 /* Need to free the identifier */
886 free_parms.dir = tbl->direction;
887 free_parms.ident_type = ident->ident_type;
888 free_parms.id = sparms.search_id;
889 (void)tf_free_identifier(tfp, &free_parms);
890 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
892 tf_dir_2_str(tbl->direction), sparms.search_id);
897 ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
902 enum bnxt_ulp_port_table port_data = val16;
905 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
906 if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
908 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
912 case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
913 if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
915 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
919 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
920 if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
922 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
927 BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
934 ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
935 enum bnxt_ulp_field_src field_src,
944 struct bnxt_ulp_mapper_data *m;
946 uint32_t port_id, val_size, field_size;
947 uint16_t idx, size_idx, offset;
948 uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
955 /* Perform the action */
957 case BNXT_ULP_FIELD_SRC_ZERO:
958 *val = mapper_fld_zeros;
960 case BNXT_ULP_FIELD_SRC_CONST:
963 case BNXT_ULP_FIELD_SRC_ONES:
964 *val = mapper_fld_ones;
967 case BNXT_ULP_FIELD_SRC_CF:
968 if (!ulp_operand_read(field_opr,
969 (uint8_t *)&idx, sizeof(uint16_t))) {
970 BNXT_TF_DBG(ERR, "CF operand read failed\n");
973 idx = tfp_be_to_cpu_16(idx);
974 if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint32_t)) {
975 BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
979 buffer = (uint8_t *)&parms->comp_fld[idx];
980 *val = &buffer[sizeof(uint32_t) - bytelen];
981 *value = ULP_COMP_FLD_IDX_RD(parms, idx);
983 case BNXT_ULP_FIELD_SRC_RF:
984 if (!ulp_operand_read(field_opr,
985 (uint8_t *)&idx, sizeof(uint16_t))) {
986 BNXT_TF_DBG(ERR, "RF operand read failed\n");
990 idx = tfp_be_to_cpu_16(idx);
991 /* Uninitialized regfile entries return 0 */
992 if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
993 sizeof(uint64_t) < bytelen) {
994 BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
998 buffer = (uint8_t *)&parms->regfile->entry[idx].data;
999 *val = &buffer[sizeof(uint64_t) - bytelen];
1000 *value = tfp_be_to_cpu_64(lregval);
1002 case BNXT_ULP_FIELD_SRC_ACT_PROP:
1003 if (!ulp_operand_read(field_opr,
1004 (uint8_t *)&idx, sizeof(uint16_t))) {
1005 BNXT_TF_DBG(ERR, "Action operand read failed\n");
1008 idx = tfp_be_to_cpu_16(idx);
1009 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1010 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
1013 buffer = &parms->act_prop->act_details[idx];
1014 field_size = ulp_mapper_act_prop_size_get(idx);
1015 if (bytelen > field_size) {
1016 BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
1020 *val = &buffer[field_size - bytelen];
1022 case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
1023 if (!ulp_operand_read(field_opr,
1024 (uint8_t *)&idx, sizeof(uint16_t))) {
1025 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1028 idx = tfp_be_to_cpu_16(idx);
1030 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1031 BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
1034 *val = &parms->act_prop->act_details[idx];
1036 /* get the size index next */
1037 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1038 (uint8_t *)&size_idx, sizeof(uint16_t))) {
1039 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1042 size_idx = tfp_be_to_cpu_16(size_idx);
1043 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1044 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
1047 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
1049 val_size = tfp_be_to_cpu_32(val_size);
1050 *val_len = ULP_BYTE_2_BITS(val_size);
1052 case BNXT_ULP_FIELD_SRC_GLB_RF:
1053 if (!ulp_operand_read(field_opr,
1054 (uint8_t *)&idx, sizeof(uint16_t))) {
1055 BNXT_TF_DBG(ERR, "Global regfile read failed\n");
1058 idx = tfp_be_to_cpu_16(idx);
1059 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1060 dir, idx, &lregval, &shared) ||
1061 sizeof(uint64_t) < bytelen) {
1062 BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
1066 m = parms->mapper_data;
1067 buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
1068 *val = &buffer[sizeof(uint64_t) - bytelen];
1069 *value = tfp_be_to_cpu_64(lregval);
1071 case BNXT_ULP_FIELD_SRC_HF:
1072 case BNXT_ULP_FIELD_SRC_SUB_HF:
1073 if (!ulp_operand_read(field_opr,
1074 (uint8_t *)&idx, sizeof(uint16_t))) {
1075 BNXT_TF_DBG(ERR, "Header field read failed\n");
1078 idx = tfp_be_to_cpu_16(idx);
1079 /* get the index from the global field list */
1080 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1081 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1086 buffer = parms->hdr_field[bit].spec;
1088 buffer = parms->hdr_field[bit].mask;
1090 field_size = parms->hdr_field[bit].size;
1091 if (bytelen > field_size) {
1092 BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
1096 if (field_src == BNXT_ULP_FIELD_SRC_HF) {
1097 *val = &buffer[field_size - bytelen];
1099 /* get the offset next */
1100 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1102 sizeof(uint16_t))) {
1103 BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
1106 offset = tfp_be_to_cpu_16(offset);
1107 offset = ULP_BITS_2_BYTE_NR(offset);
1108 if ((offset + bytelen) > field_size) {
1109 BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
1112 *val = &buffer[offset];
1115 case BNXT_ULP_FIELD_SRC_HDR_BIT:
1116 if (!ulp_operand_read(field_opr,
1117 (uint8_t *)&lregval, sizeof(uint64_t))) {
1118 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1121 lregval = tfp_be_to_cpu_64(lregval);
1122 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
1123 *val = mapper_fld_one;
1126 *val = mapper_fld_zeros;
1129 case BNXT_ULP_FIELD_SRC_ACT_BIT:
1130 if (!ulp_operand_read(field_opr,
1131 (uint8_t *)&lregval, sizeof(uint64_t))) {
1132 BNXT_TF_DBG(ERR, "Action bit read failed\n");
1135 lregval = tfp_be_to_cpu_64(lregval);
1136 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
1137 *val = mapper_fld_one;
1140 *val = mapper_fld_zeros;
1143 case BNXT_ULP_FIELD_SRC_FIELD_BIT:
1144 if (!ulp_operand_read(field_opr,
1145 (uint8_t *)&idx, sizeof(uint16_t))) {
1146 BNXT_TF_DBG(ERR, "Field bit read failed\n");
1149 idx = tfp_be_to_cpu_16(idx);
1150 /* get the index from the global field list */
1151 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1152 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1156 if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
1157 *val = mapper_fld_one;
1160 *val = mapper_fld_zeros;
1163 case BNXT_ULP_FIELD_SRC_PORT_TABLE:
1164 /* The port id is present in the comp field list */
1165 port_id = ULP_COMP_FLD_IDX_RD(parms,
1166 BNXT_ULP_CF_IDX_DEV_PORT_ID);
1167 /* get the port table enum */
1168 if (!ulp_operand_read(field_opr,
1169 (uint8_t *)&idx, sizeof(uint16_t))) {
1170 BNXT_TF_DBG(ERR, "Port table enum read failed\n");
1173 idx = tfp_be_to_cpu_16(idx);
1174 if (ulp_mapper_field_port_db_process(parms, port_id, idx,
1176 BNXT_TF_DBG(ERR, "field port table failed\n");
1179 case BNXT_ULP_FIELD_SRC_SKIP:
1182 case BNXT_ULP_FIELD_SRC_REJECT:
1185 BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
1191 static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
1199 bytelen = ULP_BITS_2_BYTE(bitlen);
1200 if (bytelen == sizeof(uint8_t)) {
1201 *output = *((uint8_t *)buffer);
1202 } else if (bytelen == sizeof(uint16_t)) {
1203 val_16 = *((uint16_t *)buffer);
1204 *output = tfp_be_to_cpu_16(val_16);
1205 } else if (bytelen == sizeof(uint32_t)) {
1206 val_32 = *((uint32_t *)buffer);
1207 *output = tfp_be_to_cpu_32(val_32);
1208 } else if (bytelen == sizeof(val_64)) {
1209 val_64 = *((uint64_t *)buffer);
1210 *output = tfp_be_to_cpu_64(val_64);
1218 static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
1219 struct ulp_blob *blob,
1224 if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
1225 if (ulp_blob_pad_push(blob, val_len) < 0) {
1226 BNXT_TF_DBG(ERR, "too large for blob\n");
1229 } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
1230 if (ulp_blob_push_encap(blob, val, val_len) < 0) {
1231 BNXT_TF_DBG(ERR, "encap blob push failed\n");
1235 if (!ulp_blob_push(blob, val, val_len)) {
1236 BNXT_TF_DBG(ERR, "push of val1 failed\n");
1245 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
1247 struct bnxt_ulp_mapper_field_info *fld,
1248 struct ulp_blob *blob,
1252 uint16_t write_idx = blob->write_idx;
1253 uint8_t *val = NULL, *val1, *val2, *val3;
1254 uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
1255 uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
1256 uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
1257 uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
1258 uint64_t value1 = 0, value2 = 0, value3 = 0;
1261 /* prepare the field source and values */
1262 switch (fld->field_opc) {
1263 case BNXT_ULP_FIELD_OPC_SRC1:
1266 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1269 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1270 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1278 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1279 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1280 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1281 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1282 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1283 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1293 /* process the src1 opcode */
1295 if (ulp_mapper_field_src_process(parms, fld->field_src1,
1296 fld->field_opr1, dir, is_key,
1297 fld->field_bit_size, &val1,
1298 &val1_len, &value1)) {
1299 BNXT_TF_DBG(ERR, "fld src1 process failed\n");
1303 if (ulp_mapper_field_buffer_eval(val1, val1_len,
1305 BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
1311 /* for "if then clause" set the correct process */
1312 if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
1319 /* process src2 opcode */
1321 if (ulp_mapper_field_src_process(parms, fld->field_src2,
1322 fld->field_opr2, dir, is_key,
1323 fld->field_bit_size, &val2,
1324 &val2_len, &value2)) {
1325 BNXT_TF_DBG(ERR, "fld src2 process failed\n");
1329 if (ulp_mapper_field_buffer_eval(val2, val2_len,
1331 BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
1337 /* process src3 opcode */
1339 if (ulp_mapper_field_src_process(parms, fld->field_src3,
1340 fld->field_opr3, dir, is_key,
1341 fld->field_bit_size, &val3,
1342 &val3_len, &value3)) {
1343 BNXT_TF_DBG(ERR, "fld src3 process failed\n");
1347 if (ulp_mapper_field_buffer_eval(val3, val3_len,
1349 BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
1355 val_len = fld->field_bit_size;
1356 /* process the field opcodes */
1357 switch (fld->field_opc) {
1358 case BNXT_ULP_FIELD_OPC_SRC1:
1359 rc = ulp_mapper_field_blob_write(fld->field_src1,
1360 blob, val1, val1_len, &val);
1363 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1365 rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
1366 val2, val2_len, &val);
1369 rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
1370 val3, val3_len, &val);
1374 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1375 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1376 val_int = val1_int + val2_int;
1377 val_int = tfp_cpu_to_be_64(val_int);
1378 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1382 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1383 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1384 val_int = val1_int - val2_int;
1385 val_int = tfp_cpu_to_be_64(val_int);
1386 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1390 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1391 val_int = val1_int | val2_int;
1392 val_int = tfp_cpu_to_be_64(val_int);
1393 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1397 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1398 val_int = val1_int | val2_int | val3_int;
1399 val_int = tfp_cpu_to_be_64(val_int);
1400 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1404 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1405 val_int = val1_int & val2_int;
1406 val_int = tfp_cpu_to_be_64(val_int);
1407 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1411 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1412 val_int = val1_int & (val2_int | val3_int);
1413 val_int = tfp_cpu_to_be_64(val_int);
1414 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1418 case BNXT_ULP_FIELD_OPC_SKIP:
1421 BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
1428 BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
1429 fld->description, (val) ? write_idx : 0, val_len);
1434 * Result table process and fill the result blob.
1435 * data [out] - the result blob data
1438 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
1439 struct bnxt_ulp_mapper_tbl_info *tbl,
1440 struct ulp_blob *data,
1443 struct bnxt_ulp_mapper_field_info *dflds;
1444 uint32_t i, num_flds = 0, encap_flds = 0;
1447 /* Get the result field list */
1448 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
1451 /* validate the result field list counts */
1452 if ((tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1453 (!num_flds && !encap_flds)) || !dflds ||
1454 (tbl->resource_func != BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1455 (!num_flds || encap_flds))) {
1456 BNXT_TF_DBG(ERR, "Failed to get data fields %x:%x\n",
1457 num_flds, encap_flds);
1461 /* process the result fields, loop through them */
1462 for (i = 0; i < (num_flds + encap_flds); i++) {
1463 /* set the swap index if encap swap bit is enabled */
1464 if (parms->device_params->encap_byte_swap && encap_flds &&
1466 ulp_blob_encap_swap_idx_set(data);
1468 /* Process the result fields */
1469 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1470 &dflds[i], data, 0, name);
1472 BNXT_TF_DBG(ERR, "data field failed\n");
1477 /* if encap bit swap is enabled perform the bit swap */
1478 if (parms->device_params->encap_byte_swap && encap_flds)
1479 ulp_blob_perform_encap_swap(data);
1485 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1486 struct bnxt_ulp_mapper_tbl_info *tbl,
1489 struct ulp_flow_db_res_params fid_parms;
1490 uint32_t mark, gfid, mark_flag;
1491 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1494 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1495 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1496 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1497 BNXT_ULP_ACT_BIT_MARK)))
1498 return rc; /* no need to perform gfid process */
1500 /* Get the mark id details from action property */
1501 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1503 mark = tfp_be_to_cpu_32(mark);
1505 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1506 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1508 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1511 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1514 fid_parms.direction = tbl->direction;
1515 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1516 fid_parms.critical_resource = tbl->critical_resource;
1517 fid_parms.resource_type = mark_flag;
1518 fid_parms.resource_hndl = gfid;
1519 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1521 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1523 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1528 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1529 struct bnxt_ulp_mapper_tbl_info *tbl)
1531 struct ulp_flow_db_res_params fid_parms;
1532 uint32_t act_idx, mark, mark_flag;
1534 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1537 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1538 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1539 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1540 BNXT_ULP_ACT_BIT_MARK)))
1541 return rc; /* no need to perform mark action process */
1543 /* Get the mark id details from action property */
1544 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1546 mark = tfp_be_to_cpu_32(mark);
1548 if (!ulp_regfile_read(parms->regfile,
1549 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1551 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1554 act_idx = tfp_be_to_cpu_64(val64);
1555 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1556 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1559 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1562 fid_parms.direction = tbl->direction;
1563 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1564 fid_parms.critical_resource = tbl->critical_resource;
1565 fid_parms.resource_type = mark_flag;
1566 fid_parms.resource_hndl = act_idx;
1567 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1569 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1571 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1576 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1577 struct bnxt_ulp_mapper_tbl_info *tbl)
1579 struct ulp_flow_db_res_params fid_parms;
1580 uint32_t act_idx, mark, mark_flag;
1582 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1585 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1586 mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
1587 return rc; /* no need to perform mark action process */
1589 /* Get the mark id details from the computed field of dev port id */
1590 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1592 /* Get the main action pointer */
1593 if (!ulp_regfile_read(parms->regfile,
1594 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1596 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1599 act_idx = tfp_be_to_cpu_64(val64);
1601 /* Set the mark flag to local fid and vfr flag */
1602 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1604 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1607 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1610 fid_parms.direction = tbl->direction;
1611 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1612 fid_parms.critical_resource = tbl->critical_resource;
1613 fid_parms.resource_type = mark_flag;
1614 fid_parms.resource_hndl = act_idx;
1615 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1617 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1619 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1623 /* Tcam table scan the identifier list and allocate each identifier */
1625 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1626 struct bnxt_ulp_mapper_tbl_info *tbl)
1628 struct bnxt_ulp_mapper_ident_info *idents;
1629 uint32_t num_idents;
1632 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1633 for (i = 0; i < num_idents; i++) {
1634 if (ulp_mapper_ident_process(parms, tbl,
1642 * Tcam table scan the identifier list and extract the identifier from
1646 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1647 struct bnxt_ulp_mapper_tbl_info *tbl,
1648 struct ulp_blob *data)
1650 struct bnxt_ulp_mapper_ident_info *idents;
1651 uint32_t num_idents = 0, i;
1655 * Extract the listed identifiers from the result field,
1656 * no need to allocate them.
1658 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1659 for (i = 0; i < num_idents; i++) {
1660 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1662 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1669 /* Internal function to write the tcam entry */
1671 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1672 struct bnxt_ulp_mapper_tbl_info *tbl,
1673 struct ulp_blob *key,
1674 struct ulp_blob *mask,
1675 struct ulp_blob *data,
1678 struct tf_set_tcam_entry_parms sparms = { 0 };
1683 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1685 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1689 sparms.dir = tbl->direction;
1690 sparms.tcam_tbl_type = tbl->resource_type;
1692 sparms.key = ulp_blob_data_get(key, &tmplen);
1693 sparms.key_sz_in_bits = tmplen;
1694 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1695 sparms.result = ulp_blob_data_get(data, &tmplen);
1696 sparms.result_sz_in_bits = tmplen;
1697 if (tf_set_tcam_entry(tfp, &sparms)) {
1698 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1699 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1700 tf_dir_2_str(sparms.dir), sparms.idx);
1705 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1707 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1715 * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
1717 * parms [in] The mappers parms with data related to the flow.
1719 * key [in] The original key to be transformed
1721 * mask [in] The original mask to be transformed
1723 * tkey [in/out] The transformed key
1725 * tmask [in/out] The transformed mask
1727 * returns zero on success, non-zero on failure
1730 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
1731 struct ulp_blob *key,
1732 struct ulp_blob *mask,
1733 struct ulp_blob *tkey,
1734 struct ulp_blob *tmask)
1736 uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
1737 uint32_t cword, i, rc;
1741 slice_width = dparms->wc_slice_width;
1742 clen = dparms->wc_ctl_size_bits;
1743 max_slices = dparms->wc_max_slices;
1744 blen = ulp_blob_data_len_get(key);
1746 /* Get the length of the key based on number of slices and width */
1749 while (tlen < blen &&
1750 num_slices <= max_slices) {
1751 num_slices = num_slices << 1;
1755 if (num_slices > max_slices) {
1756 BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
1760 /* The key/mask may not be on a natural slice boundary, pad it */
1762 if (ulp_blob_pad_push(key, pad) < 0 ||
1763 ulp_blob_pad_push(mask, pad) < 0) {
1764 BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
1768 /* The new length accounts for the ctrl word length and num slices */
1769 tlen = tlen + clen * num_slices;
1770 if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
1771 !ulp_blob_init(tmask, tlen, mask->byte_order)) {
1772 BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
1776 /* Build the transformed key/mask */
1777 cword = dparms->wc_mode_list[num_slices - 1];
1778 cword = tfp_cpu_to_be_32(cword);
1780 for (i = 0; i < num_slices; i++) {
1781 val = ulp_blob_push_32(tkey, &cword, clen);
1783 BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
1786 val = ulp_blob_push_32(tmask, &cword, clen);
1788 BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
1791 rc = ulp_blob_append(tkey, key, offset, slice_width);
1793 BNXT_TF_DBG(ERR, "Key blob append failed\n");
1796 rc = ulp_blob_append(tmask, mask, offset, slice_width);
1798 BNXT_TF_DBG(ERR, "Mask blob append failed\n");
1801 offset += slice_width;
1804 /* The key/mask are byte reversed on every 4 byte chunk */
1805 ulp_blob_perform_byte_reverse(tkey, 4);
1806 ulp_blob_perform_byte_reverse(tmask, 4);
1811 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1812 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
1814 ulp_blob_perform_64B_word_swap(blob);
1815 ulp_blob_perform_64B_byte_swap(blob);
1819 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1820 struct bnxt_ulp_mapper_tbl_info *tbl)
1822 struct bnxt_ulp_mapper_key_info *kflds;
1823 struct ulp_blob okey, omask, data, update_data;
1824 struct ulp_blob tkey, tmask; /* transform key and mask */
1825 struct ulp_blob *key, *mask;
1826 uint32_t i, num_kflds;
1829 struct bnxt_ulp_device_params *dparms = parms->device_params;
1830 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1831 struct tf_search_tcam_entry_parms searchparms = { 0 };
1832 struct ulp_flow_db_res_params fid_parms = { 0 };
1833 struct tf_free_tcam_entry_parms free_parms = { 0 };
1835 uint16_t tmplen = 0;
1838 /* Set the key and mask to the original key and mask. */
1842 /* Skip this if table opcode is NOP */
1843 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
1844 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
1845 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
1850 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1852 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1856 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1857 if (!kflds || !num_kflds) {
1858 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1862 if (!ulp_blob_init(key, tbl->blob_key_bit_size, tbl->byte_order) ||
1863 !ulp_blob_init(mask, tbl->blob_key_bit_size, tbl->byte_order) ||
1864 !ulp_blob_init(&data, tbl->result_bit_size, dparms->byte_order) ||
1865 !ulp_blob_init(&update_data, tbl->result_bit_size,
1866 dparms->byte_order)) {
1867 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1871 /* create the key/mask */
1873 * NOTE: The WC table will require some kind of flag to handle the
1874 * mode bits within the key/mask
1876 for (i = 0; i < num_kflds; i++) {
1878 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1879 &kflds[i].field_info_spec,
1880 key, 1, "TCAM Key");
1882 BNXT_TF_DBG(ERR, "Key field set failed %s\n",
1883 kflds[i].field_info_spec.description);
1887 /* Setup the mask */
1888 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1889 &kflds[i].field_info_mask,
1890 mask, 0, "TCAM Mask");
1892 BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
1893 kflds[i].field_info_mask.description);
1898 /* For wild card tcam perform the post process to swap the blob */
1899 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM ||
1900 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_HIGH ||
1901 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_LOW) {
1902 if (dparms->dynamic_pad_en) {
1903 /* Sets up the slices for writing to the WC TCAM */
1904 rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
1910 "Failed to post proc WC entry.\n");
1913 /* Now need to use the transform Key/Mask */
1917 ulp_mapper_wc_tcam_tbl_post_process(key);
1918 ulp_mapper_wc_tcam_tbl_post_process(mask);
1923 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1924 /* allocate the tcam index */
1925 aparms.dir = tbl->direction;
1926 aparms.tcam_tbl_type = tbl->resource_type;
1927 aparms.key = ulp_blob_data_get(key, &tmplen);
1928 aparms.key_sz_in_bits = tmplen;
1929 aparms.mask = ulp_blob_data_get(mask, &tmplen);
1931 /* calculate the entry priority */
1932 rc = ulp_mapper_priority_opc_process(parms, tbl,
1935 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1939 rc = tf_alloc_tcam_entry(tfp, &aparms);
1941 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1948 * Searching before allocation to see if we already have an
1949 * entry. This allows re-use of a constrained resource.
1951 searchparms.dir = tbl->direction;
1952 searchparms.tcam_tbl_type = tbl->resource_type;
1953 searchparms.key = ulp_blob_data_get(key, &tmplen);
1954 searchparms.key_sz_in_bits = tbl->key_bit_size;
1955 searchparms.mask = ulp_blob_data_get(mask, &tmplen);
1956 searchparms.alloc = 1;
1957 searchparms.result = ulp_blob_data_get(&data, &tmplen);
1958 searchparms.result_sz_in_bits = tbl->result_bit_size;
1960 /* calculate the entry priority */
1961 rc = ulp_mapper_priority_opc_process(parms, tbl,
1962 &searchparms.priority);
1964 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1968 rc = tf_search_tcam_entry(tfp, &searchparms);
1970 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
1974 /* Successful search, check the result */
1975 if (searchparms.search_status == REJECT) {
1976 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
1979 idx = searchparms.idx;
1980 hit = searchparms.hit;
1983 /* Write the tcam index into the regfile*/
1984 if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
1985 (uint64_t)tfp_cpu_to_be_64(idx))) {
1986 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
1989 /* Need to free the tcam idx, so goto error */
1993 /* if it is miss then it is same as no search before alloc */
1994 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1995 /*Scan identifier list, allocate identifier and update regfile*/
1996 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
1997 /* Create the result blob */
1999 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2001 /* write the tcam entry */
2003 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
2006 /*Scan identifier list, extract identifier and update regfile*/
2007 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
2012 /* Add the tcam index to the flow database */
2013 fid_parms.direction = tbl->direction;
2014 fid_parms.resource_func = tbl->resource_func;
2015 fid_parms.resource_type = tbl->resource_type;
2016 fid_parms.critical_resource = tbl->critical_resource;
2017 fid_parms.resource_hndl = idx;
2018 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2020 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2022 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2024 /* Need to free the identifier, so goto error */
2030 free_parms.dir = tbl->direction;
2031 free_parms.tcam_tbl_type = tbl->resource_type;
2032 free_parms.idx = idx;
2033 trc = tf_free_tcam_entry(tfp, &free_parms);
2035 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
2036 tbl->resource_type, tbl->direction, idx);
2041 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2042 struct bnxt_ulp_mapper_tbl_info *tbl)
2044 struct bnxt_ulp_mapper_key_info *kflds;
2045 struct ulp_blob key, data;
2046 uint32_t i, num_kflds;
2049 struct ulp_flow_db_res_params fid_parms = { 0 };
2050 struct tf_insert_em_entry_parms iparms = { 0 };
2051 struct tf_delete_em_entry_parms free_parms = { 0 };
2052 enum bnxt_ulp_flow_mem_type mtype;
2053 struct bnxt_ulp_device_params *dparms = parms->device_params;
2058 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2059 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2061 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
2065 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2066 if (!kflds || !num_kflds) {
2067 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2071 /* Initialize the key/result blobs */
2072 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
2074 !ulp_blob_init(&data, tbl->result_bit_size,
2076 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2080 /* create the key */
2081 for (i = 0; i < num_kflds; i++) {
2083 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2084 &kflds[i].field_info_spec,
2087 BNXT_TF_DBG(ERR, "Key field set failed.\n");
2092 /* if dynamic padding is enabled then add padding to result data */
2093 if (dparms->dynamic_pad_en) {
2094 /* add padding to make sure key is at byte boundary */
2095 ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
2098 pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
2100 BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
2103 ulp_blob_pad_push(&data, (uint32_t)pad);
2106 /* Create the result data blob */
2107 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
2109 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2112 if (dparms->dynamic_pad_en) {
2113 uint32_t abits = dparms->em_blk_align_bits;
2115 /* when dynamic padding is enabled merge result + key */
2116 rc = ulp_blob_block_merge(&data, &key, abits, pad);
2118 BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
2122 /* add padding to make sure merged result is at slice boundary*/
2123 ulp_blob_pad_align(&data, abits);
2125 ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
2128 /* do the transpose for the internal EM keys */
2129 if (tbl->resource_type == TF_MEM_INTERNAL) {
2130 if (dparms->em_key_align_bytes) {
2131 int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
2133 tmplen = ulp_blob_data_len_get(&key);
2134 ulp_blob_pad_push(&key, b - tmplen);
2136 tmplen = ulp_blob_data_len_get(&key);
2137 ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
2140 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
2141 &iparms.tbl_scope_id);
2143 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2148 * NOTE: the actual blob size will differ from the size in the tbl
2149 * entry due to the padding.
2151 iparms.dup_check = 0;
2152 iparms.dir = tbl->direction;
2153 iparms.mem = tbl->resource_type;
2154 iparms.key = ulp_blob_data_get(&key, &tmplen);
2155 iparms.key_sz_in_bits = tbl->key_bit_size;
2156 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
2157 if (tbl->result_bit_size)
2158 iparms.em_record_sz_in_bits = tbl->result_bit_size;
2160 iparms.em_record_sz_in_bits = tmplen;
2162 rc = tf_insert_em_entry(tfp, &iparms);
2164 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
2168 /* Mark action process */
2169 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
2170 tbl->resource_type == TF_MEM_EXTERNAL)
2171 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
2172 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
2173 tbl->resource_type == TF_MEM_INTERNAL)
2174 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
2176 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
2180 /* Link the EM resource to the flow in the flow db */
2181 memset(&fid_parms, 0, sizeof(fid_parms));
2182 fid_parms.direction = tbl->direction;
2183 fid_parms.resource_func = tbl->resource_func;
2184 fid_parms.resource_type = tbl->resource_type;
2185 fid_parms.critical_resource = tbl->critical_resource;
2186 fid_parms.resource_hndl = iparms.flow_handle;
2188 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2190 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
2192 /* Need to free the identifier, so goto error */
2198 free_parms.dir = iparms.dir;
2199 free_parms.mem = iparms.mem;
2200 free_parms.tbl_scope_id = iparms.tbl_scope_id;
2201 free_parms.flow_handle = iparms.flow_handle;
2203 trc = tf_delete_em_entry(tfp, &free_parms);
2205 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
2211 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2212 struct bnxt_ulp_mapper_tbl_info *tbl)
2214 struct ulp_flow_db_res_params fid_parms;
2215 struct ulp_blob data;
2216 uint64_t regval = 0;
2219 int32_t rc = 0, trc = 0;
2220 struct tf_alloc_tbl_entry_parms aparms = { 0 };
2221 struct tf_set_tbl_entry_parms sparms = { 0 };
2222 struct tf_get_tbl_entry_parms gparms = { 0 };
2223 struct tf_free_tbl_entry_parms free_parms = { 0 };
2224 uint32_t tbl_scope_id;
2226 struct bnxt_ulp_glb_resource_info glb_res;
2230 bool global = false;
2231 uint64_t act_rec_size;
2232 bool shared = false;
2234 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2235 /* use the max size if encap is enabled */
2236 if (tbl->encap_num_fields)
2237 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
2239 bit_size = tbl->result_bit_size;
2241 /* Initialize the blob data */
2242 if (!ulp_blob_init(&data, bit_size,
2243 parms->device_params->byte_order)) {
2244 BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
2248 /* Get the scope id first */
2249 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
2251 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2255 switch (tbl->tbl_opcode) {
2256 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
2259 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
2261 * Build the entry, alloc an index, write the table, and store
2262 * the data in the regfile.
2267 case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
2269 * get the index to write to from the regfile and then write
2272 if (!ulp_regfile_read(parms->regfile,
2276 "Failed to get tbl idx from regfile[%d].\n",
2280 index = tfp_be_to_cpu_64(regval);
2281 /* For external, we need to reverse shift */
2282 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2283 index = TF_ACT_REC_PTR_2_OFFSET(index);
2287 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
2289 * Build the entry, alloc an index, write the table, and store
2290 * the data in the global regfile.
2295 glb_res.direction = tbl->direction;
2296 glb_res.resource_func = tbl->resource_func;
2297 glb_res.resource_type = tbl->resource_type;
2298 glb_res.glb_regfile_index = tbl->tbl_operand;
2300 case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
2301 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2302 BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
2306 * get the index to write to from the global regfile and then
2309 if (ulp_mapper_glb_resource_read(parms->mapper_data,
2312 ®val, &shared)) {
2314 "Failed to get tbl idx from Glb RF[%d].\n",
2318 index = tfp_be_to_cpu_64(regval);
2319 /* For external, we need to reverse shift */
2320 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2321 index = TF_ACT_REC_PTR_2_OFFSET(index);
2324 case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
2326 * The read is different from the rest and can be handled here
2327 * instead of trying to use common code. Simply read the table
2328 * with the index from the regfile, scan and store the
2329 * identifiers, and return.
2331 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2332 /* Not currently supporting with EXT */
2334 "Ext Table Read Opcode not supported.\n");
2337 if (!ulp_regfile_read(parms->regfile,
2338 tbl->tbl_operand, ®val)) {
2340 "Failed to get tbl idx from regfile[%d]\n",
2344 index = tfp_be_to_cpu_64(regval);
2345 gparms.dir = tbl->direction;
2346 gparms.type = tbl->resource_type;
2347 gparms.data = ulp_blob_data_get(&data, &tmplen);
2348 gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tbl->result_bit_size);
2350 rc = tf_get_tbl_entry(tfp, &gparms);
2352 BNXT_TF_DBG(ERR, "Failed to read the tbl entry %d:%d\n",
2353 tbl->resource_type, index);
2357 * Scan the fields in the entry and push them into the regfile.
2359 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2361 gparms.data_sz_in_bytes,
2365 "Failed to get flds on tbl read rc=%d\n",
2371 BNXT_TF_DBG(ERR, "Invalid index table opcode %d\n",
2377 /* Get the result fields list */
2378 rc = ulp_mapper_tbl_result_build(parms,
2383 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2389 aparms.dir = tbl->direction;
2390 aparms.type = tbl->resource_type;
2391 aparms.tbl_scope_id = tbl_scope_id;
2393 /* All failures after the alloc succeeds require a free */
2394 rc = tf_alloc_tbl_entry(tfp, &aparms);
2396 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2397 tf_tbl_type_2_str(tbl->resource_type),
2398 tf_dir_2_str(tbl->direction), rc);
2404 * Store the index in the regfile since we either allocated it
2407 * Calculate the idx for the result record, for external EM the
2408 * offset needs to be shifted accordingly.
2409 * If external non-inline table types are used then need to
2410 * revisit this logic.
2412 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2413 regval = TF_ACT_REC_OFFSET_2_PTR(index);
2416 regval = tfp_cpu_to_be_64(regval);
2420 * Shared resources are never allocated through this
2421 * method, so the shared flag is always false.
2423 rc = ulp_mapper_glb_resource_write(parms->mapper_data,
2427 rc = ulp_regfile_write(parms->regfile,
2428 tbl->tbl_operand, regval);
2432 "Failed to write %s regfile[%d] rc=%d\n",
2433 (global) ? "global" : "reg",
2434 tbl->tbl_operand, rc);
2440 sparms.dir = tbl->direction;
2441 sparms.type = tbl->resource_type;
2442 sparms.data = ulp_blob_data_get(&data, &tmplen);
2443 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2445 sparms.tbl_scope_id = tbl_scope_id;
2447 tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
2448 rc = tf_set_tbl_entry(tfp, &sparms);
2451 "Index table[%s][%s][%x] write fail rc=%d\n",
2452 tf_tbl_type_2_str(sparms.type),
2453 tf_dir_2_str(sparms.dir),
2458 /* Calculate action record size */
2459 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2460 act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
2462 if (ulp_regfile_write(parms->regfile,
2463 BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
2464 tfp_cpu_to_be_64(act_rec_size)))
2466 "Failed write the act rec size\n");
2470 /* Link the resource to the flow in the flow db */
2471 memset(&fid_parms, 0, sizeof(fid_parms));
2472 fid_parms.direction = tbl->direction;
2473 fid_parms.resource_func = tbl->resource_func;
2474 fid_parms.resource_type = tbl->resource_type;
2475 fid_parms.resource_sub_type = tbl->resource_sub_type;
2476 fid_parms.resource_hndl = index;
2477 fid_parms.critical_resource = tbl->critical_resource;
2478 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2480 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2482 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2487 /* Perform the VF rep action */
2488 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2490 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2495 /* Shared resources are not freed */
2499 * Free the allocated resource since we failed to either
2500 * write to the entry or link the flow
2502 free_parms.dir = tbl->direction;
2503 free_parms.type = tbl->resource_type;
2504 free_parms.idx = index;
2505 free_parms.tbl_scope_id = tbl_scope_id;
2507 trc = tf_free_tbl_entry(tfp, &free_parms);
2509 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2515 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2516 struct bnxt_ulp_mapper_tbl_info *tbl)
2518 struct ulp_blob data, res_blob;
2522 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2523 struct tf_get_if_tbl_entry_parms get_parms = { 0 };
2525 enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
2528 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2529 /* Initialize the blob data */
2530 if (!ulp_blob_init(&data, tbl->result_bit_size,
2531 parms->device_params->byte_order)) {
2532 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2536 /* create the result blob */
2537 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
2539 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2543 /* Get the index details */
2545 case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
2546 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2548 case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
2549 if (!ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx)) {
2550 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
2554 idx = tfp_be_to_cpu_64(idx);
2556 case BNXT_ULP_IF_TBL_OPC_WR_CONST:
2557 idx = tbl->tbl_operand;
2559 case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
2560 /* Initialize the result blob */
2561 if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
2562 parms->device_params->byte_order)) {
2563 BNXT_TF_DBG(ERR, "Failed initial result blob\n");
2567 /* read the interface table */
2568 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2569 res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
2570 get_parms.dir = tbl->direction;
2571 get_parms.type = tbl->resource_type;
2572 get_parms.idx = idx;
2573 get_parms.data = ulp_blob_data_get(&res_blob, &tmplen);
2574 get_parms.data_sz_in_bytes = res_size;
2576 rc = tf_get_if_tbl_entry(tfp, &get_parms);
2578 BNXT_TF_DBG(ERR, "Get table[%d][%s][%x] failed rc=%d\n",
2580 tf_dir_2_str(get_parms.dir),
2584 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2587 res_blob.byte_order);
2589 BNXT_TF_DBG(ERR, "Scan and extract failed rc=%d\n", rc);
2591 case BNXT_ULP_IF_TBL_OPC_NOT_USED:
2592 return rc; /* skip it */
2594 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2598 /* Perform the tf table set by filling the set params */
2599 iftbl_params.dir = tbl->direction;
2600 iftbl_params.type = tbl->resource_type;
2601 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2602 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2603 iftbl_params.idx = idx;
2605 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2607 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2608 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2609 tf_dir_2_str(iftbl_params.dir),
2610 iftbl_params.idx, rc);
2615 * TBD: Need to look at the need to store idx in flow db for restore
2616 * the table to its original state on deletion of this entry.
2622 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2623 struct bnxt_ulp_mapper_tbl_info *tbl)
2625 struct ulp_mapper_gen_tbl_list *gen_tbl_list;
2626 struct bnxt_ulp_mapper_key_info *kflds;
2627 struct ulp_flow_db_res_params fid_parms;
2628 struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
2629 struct ulp_gen_hash_entry_params hash_entry;
2630 uint16_t tmplen = 0;
2631 struct ulp_blob key, data;
2634 uint32_t i, num_kflds = 0, key_index = 0;
2635 uint32_t gen_tbl_miss = 1, fdb_write = 0;
2639 /* Get the key fields list and build the key. */
2640 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2641 if (!kflds || !num_kflds) {
2642 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2646 if (!ulp_blob_init(&key, tbl->key_bit_size,
2647 parms->device_params->byte_order)) {
2648 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2651 for (i = 0; i < num_kflds; i++) {
2653 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2654 &kflds[i].field_info_spec,
2655 &key, 1, "Gen Tbl Key");
2658 "Failed to create key for Gen tbl rc=%d\n",
2664 /* Calculate the table index for the generic table*/
2665 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2668 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2669 tbl->resource_sub_type, tbl->direction);
2673 /* The_key is a byte array convert it to a search index */
2674 cache_key = ulp_blob_data_get(&key, &tmplen);
2675 /* get the generic table */
2676 gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
2678 /* Check if generic hash table */
2679 if (gen_tbl_list->hash_tbl) {
2680 if (tbl->gen_tbl_lkup_type !=
2681 BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
2682 BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
2683 gen_tbl_list->gen_tbl_name);
2686 hash_entry.key_data = cache_key;
2687 hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
2688 rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
2691 BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
2692 gen_tbl_list->gen_tbl_name);
2695 if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
2696 key_index = hash_entry.key_idx;
2697 /* Get the generic table entry */
2698 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
2702 /* store the hash index in the fdb */
2703 key_index = hash_entry.hash_index;
2706 /* convert key to index directly */
2707 if (ULP_BITS_2_BYTE(tmplen) > (int32_t)sizeof(key_index)) {
2708 BNXT_TF_DBG(ERR, "%s: keysize is bigger then 4 bytes\n",
2709 gen_tbl_list->gen_tbl_name);
2712 memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
2713 /* Get the generic table entry */
2714 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
2718 switch (tbl->tbl_opcode) {
2719 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2720 if (gen_tbl_list->hash_tbl) {
2721 if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
2722 break; /* nothing to be done , no entry */
2725 /* check the reference count */
2726 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2728 /* Scan ident list and create the result blob*/
2729 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2735 "Failed to scan ident list\n");
2738 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2739 /* increment the reference count */
2740 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2748 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
2749 if (gen_tbl_list->hash_tbl) {
2750 rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
2755 /* store the hash index in the fdb */
2756 key_index = hash_entry.hash_index;
2758 /* check the reference count */
2759 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2760 /* a hit then error */
2761 BNXT_TF_DBG(ERR, "generic entry already present\n");
2762 return -EINVAL; /* success */
2765 /* Initialize the blob data */
2766 if (!ulp_blob_init(&data, tbl->result_bit_size,
2767 gen_tbl_ent.byte_order)) {
2768 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2772 /* Get the result fields list */
2773 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2776 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2779 byte_data = ulp_blob_data_get(&data, &tmplen);
2780 rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
2782 ULP_BITS_2_BYTE(tmplen));
2784 BNXT_TF_DBG(ERR, "Failed to write generic table\n");
2788 /* increment the reference count */
2789 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2791 parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
2794 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
2798 /* Set the generic entry hit */
2799 rc = ulp_regfile_write(parms->regfile,
2800 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
2801 tfp_cpu_to_be_64(gen_tbl_miss));
2803 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2804 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
2808 /* add the entry to the flow database */
2810 memset(&fid_parms, 0, sizeof(fid_parms));
2811 fid_parms.direction = tbl->direction;
2812 fid_parms.resource_func = tbl->resource_func;
2813 fid_parms.resource_sub_type = tbl->resource_sub_type;
2814 fid_parms.resource_hndl = key_index;
2815 fid_parms.critical_resource = tbl->critical_resource;
2816 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2818 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2820 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
2826 ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2827 struct bnxt_ulp_mapper_tbl_info *tbl)
2831 /* process the fdb opcode for alloc push */
2832 if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
2833 rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
2835 BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
2843 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2844 struct bnxt_ulp_mapper_data *mapper_data)
2846 struct bnxt_ulp_glb_resource_info *glb_res;
2847 uint32_t num_glb_res_ids, idx, dev_id;
2851 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
2852 if (!glb_res || !num_glb_res_ids) {
2853 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2857 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2859 BNXT_TF_DBG(ERR, "Failed to get device id for glb init (%d)\n",
2864 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2866 BNXT_TF_DBG(ERR, "Failed to get app id for glb init (%d)\n",
2871 /* Iterate the global resources and process each one */
2872 for (idx = 0; idx < num_glb_res_ids; idx++) {
2873 if (dev_id != glb_res[idx].device_id ||
2874 glb_res[idx].app_id != app_id)
2876 switch (glb_res[idx].resource_func) {
2877 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2878 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
2882 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2883 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2888 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2889 glb_res[idx].resource_func);
2900 * Iterate over the shared resources assigned during tf_open_session and store
2901 * them in the global regfile with the shared flag.
2904 ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2905 struct bnxt_ulp_mapper_data *mapper_data)
2907 struct bnxt_ulp_glb_resource_info *glb_res;
2908 struct tf_get_session_info_parms sparms;
2909 uint32_t num_entries, i, dev_id, res;
2910 struct tf_resource_info *res_info;
2917 memset(&sparms, 0, sizeof(sparms));
2919 glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
2920 if (!glb_res || !num_entries) {
2921 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2925 tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
2927 BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
2931 * Retrieve the resources that were assigned during the shared session
2934 rc = tf_get_session_info(tfp, &sparms);
2936 BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
2940 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2942 BNXT_TF_DBG(ERR, "Failed to get the app id in glb init (%d).\n",
2947 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2949 BNXT_TF_DBG(ERR, "Failed to get dev id for app glb init (%d)\n",
2954 /* Store all the app global resources */
2955 for (i = 0; i < num_entries; i++) {
2956 if (dev_id != glb_res[i].device_id ||
2957 app_id != glb_res[i].app_id)
2959 dir = glb_res[i].direction;
2960 res = glb_res[i].resource_type;
2962 switch (glb_res[i].resource_func) {
2963 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2964 res_info = &sparms.session_info.ident[dir].info[res];
2966 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2967 res_info = &sparms.session_info.tbl[dir].info[res];
2969 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2970 res_info = &sparms.session_info.tcam[dir].info[res];
2972 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
2973 res_info = &sparms.session_info.em[dir].info[res];
2976 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
2977 glb_res[i].resource_func);
2981 regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
2985 * All resources written to the global regfile are shared for
2988 rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
2998 * Common conditional opcode process routine that is used for both the template
2999 * rejection and table conditional execution.
3002 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
3003 enum bnxt_ulp_cond_opc opc,
3007 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
3013 case BNXT_ULP_COND_OPC_CF_IS_SET:
3014 if (operand < BNXT_ULP_CF_IDX_LAST) {
3015 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
3017 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3022 case BNXT_ULP_COND_OPC_CF_NOT_SET:
3023 if (operand < BNXT_ULP_CF_IDX_LAST) {
3024 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
3026 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3031 case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
3032 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3033 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3036 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3041 case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
3042 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3043 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3046 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3051 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
3052 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3053 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3056 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3061 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
3062 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3063 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3066 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3071 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
3072 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3074 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3078 *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3080 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
3081 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3083 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3087 *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3089 case BNXT_ULP_COND_OPC_RF_IS_SET:
3090 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3091 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3096 case BNXT_ULP_COND_OPC_RF_NOT_SET:
3097 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3098 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3103 case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
3104 if (parms->flow_pattern_id == operand) {
3105 BNXT_TF_DBG(ERR, "field pattern match failed %x\n",
3106 parms->flow_pattern_id);
3110 case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
3111 if (parms->act_pattern_id == operand) {
3112 BNXT_TF_DBG(ERR, "act pattern match failed %x\n",
3113 parms->act_pattern_id);
3117 case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
3118 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3119 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3122 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
3124 case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
3125 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3126 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3129 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
3132 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
3140 ulp_mapper_cc_upd_opr_compute(struct bnxt_ulp_mapper_parms *parms,
3142 enum bnxt_ulp_cc_upd_src cc_src,
3151 case BNXT_ULP_CC_UPD_SRC_COMP_FIELD:
3152 if (cc_opr >= BNXT_ULP_CF_IDX_LAST) {
3153 BNXT_TF_DBG(ERR, "invalid index %u\n", cc_opr);
3156 *result = (uint64_t)ULP_COMP_FLD_IDX_RD(parms, cc_opr);
3158 case BNXT_ULP_CC_UPD_SRC_REGFILE:
3159 if (!ulp_regfile_read(parms->regfile, cc_opr, ®val)) {
3160 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", cc_opr);
3163 *result = tfp_be_to_cpu_64(regval);
3165 case BNXT_ULP_CC_UPD_SRC_GLB_REGFILE:
3166 if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
3167 cc_opr, ®val, &shared)) {
3168 BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
3172 *result = tfp_be_to_cpu_64(regval);
3174 case BNXT_ULP_CC_UPD_SRC_CONST:
3178 BNXT_TF_DBG(ERR, "invalid src code %u\n", cc_src);
3185 ulp_mapper_cc_upd_info_process(struct bnxt_ulp_mapper_parms *parms,
3186 struct bnxt_ulp_mapper_tbl_info *tbl)
3188 struct bnxt_ulp_mapper_cc_upd_info *cc_upd = &tbl->cc_upd_info;
3189 uint64_t res = 0, res1, res2;
3192 if (cc_upd->cc_opc == BNXT_ULP_CC_UPD_OPC_NOP)
3195 rc = ulp_mapper_cc_upd_opr_compute(parms, tbl->direction,
3197 cc_upd->cc_opr1, &res1);
3201 rc = ulp_mapper_cc_upd_opr_compute(parms, tbl->direction,
3203 cc_upd->cc_opr2, &res2);
3207 switch (cc_upd->cc_opc) {
3208 case BNXT_ULP_CC_UPD_OPC_NOP:
3211 case BNXT_ULP_CC_UPD_OPC_EQ:
3215 case BNXT_ULP_CC_UPD_OPC_NE:
3219 case BNXT_ULP_CC_UPD_OPC_GE:
3223 case BNXT_ULP_CC_UPD_OPC_GT:
3227 case BNXT_ULP_CC_UPD_OPC_LE:
3231 case BNXT_ULP_CC_UPD_OPC_LT:
3235 case BNXT_ULP_CC_UPD_OPC_LAST:
3236 BNXT_TF_DBG(ERR, "invalid code %u\n", cc_upd->cc_opc);
3239 if (ulp_regfile_write(parms->regfile, cc_upd->cc_dst_opr,
3240 tfp_cpu_to_be_64(res))) {
3241 BNXT_TF_DBG(ERR, "Failed write the cc_opc %u\n",
3242 cc_upd->cc_dst_opr);
3251 * Processes a list of conditions and returns both a status and result of the
3252 * list. The status must be checked prior to verifying the result.
3254 * returns 0 for success, negative on failure
3255 * returns res = 1 for true, res = 0 for false.
3258 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
3259 enum bnxt_ulp_cond_list_opc list_opc,
3260 struct bnxt_ulp_mapper_cond_info *list,
3265 int32_t rc = 0, trc = 0;
3268 case BNXT_ULP_COND_LIST_OPC_AND:
3269 /* AND Defaults to true. */
3272 case BNXT_ULP_COND_LIST_OPC_OR:
3273 /* OR Defaults to false. */
3276 case BNXT_ULP_COND_LIST_OPC_TRUE:
3279 case BNXT_ULP_COND_LIST_OPC_FALSE:
3283 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
3289 for (i = 0; i < num; i++) {
3290 rc = ulp_mapper_cond_opc_process(parms,
3291 list[i].cond_opcode,
3292 list[i].cond_operand,
3297 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
3298 /* early return if result is ever zero */
3304 /* early return if result is ever non-zero */
3316 * Processes conflict resolution and returns both a status and result.
3317 * The status must be checked prior to verifying the result.
3319 * returns 0 for success, negative on failure
3320 * returns res = 1 for true, res = 0 for false.
3323 ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
3324 struct bnxt_ulp_mapper_tbl_info *tbl,
3329 uint64_t comp_sig_id;
3332 switch (tbl->accept_opcode) {
3333 case BNXT_ULP_ACCEPT_OPC_ALWAYS:
3336 case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
3337 /* perform the signature validation*/
3338 if (tbl->resource_func ==
3339 BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
3340 /* Perform the check that generic table is hit or not */
3341 if (!ulp_regfile_read(parms->regfile,
3342 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3344 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3345 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3349 /* not a hit so no need to check flow sign*/
3354 /* compare the new flow signature against stored one */
3355 if (!ulp_regfile_read(parms->regfile,
3356 BNXT_ULP_RF_IDX_FLOW_SIG_ID,
3358 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3359 BNXT_ULP_RF_IDX_FLOW_SIG_ID);
3362 comp_sig_id = ULP_COMP_FLD_IDX_RD(parms,
3363 BNXT_ULP_CF_IDX_FLOW_SIG_ID);
3364 regval = tfp_be_to_cpu_64(regval);
3365 if (comp_sig_id == regval)
3368 BNXT_TF_DBG(ERR, "failed signature match %x:%x\n",
3369 (uint32_t)comp_sig_id, (uint32_t)regval);
3372 BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
3373 tbl->accept_opcode);
3380 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
3382 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
3383 enum bnxt_ulp_cond_list_opc cond_opc;
3384 struct bnxt_ulp_mapper_tbl_info *tbls;
3385 struct bnxt_ulp_mapper_tbl_info *tbl;
3386 uint32_t num_tbls, tbl_idx, num_cond_tbls;
3387 int32_t rc = -EINVAL, cond_rc = 0;
3388 int32_t cond_goto = 1;
3390 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
3394 * Process the reject list if exists, otherwise assume that the
3395 * template is allowed.
3397 if (cond_tbls && num_cond_tbls) {
3398 rc = ulp_mapper_cond_opc_list_process(parms,
3406 /* Reject the template if True */
3408 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
3409 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3415 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
3416 if (!tbls || !num_tbls) {
3417 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
3418 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3419 parms->dev_id, tid);
3423 for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
3424 tbl = &tbls[tbl_idx];
3425 /* Process the conditional code update opcodes */
3426 if (ulp_mapper_cc_upd_info_process(parms, tbl)) {
3427 BNXT_TF_DBG(ERR, "Failed to process cond update\n");
3432 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
3435 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
3436 cond_tbls, num_cond_tbls,
3439 BNXT_TF_DBG(ERR, "Failed to proc cond opc list (%d)\n",
3443 /* Skip the table if False */
3445 cond_goto = tbl->execute_info.cond_false_goto;
3446 goto next_iteration;
3449 switch (tbl->resource_func) {
3450 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3451 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
3453 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3454 rc = ulp_mapper_em_tbl_process(parms, tbl);
3456 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3457 rc = ulp_mapper_index_tbl_process(parms, tbl);
3459 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
3460 rc = ulp_mapper_if_tbl_process(parms, tbl);
3462 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3463 rc = ulp_mapper_gen_tbl_process(parms, tbl);
3465 case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
3466 rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
3468 case BNXT_ULP_RESOURCE_FUNC_INVALID:
3472 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
3473 tbl->resource_func);
3479 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
3480 tbl->resource_func);
3484 /* perform the post table process */
3485 rc = ulp_mapper_conflict_resolution_process(parms, tbl,
3487 if (rc || !cond_rc) {
3488 BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
3493 if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
3494 BNXT_TF_DBG(ERR, "reject the flow\n");
3497 } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
3501 /* least significant 16 bits from reg_file index */
3502 rf_idx = (uint32_t)(cond_goto & 0xFFFF);
3503 if (!ulp_regfile_read(parms->regfile, rf_idx,
3505 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3510 cond_goto = (int32_t)regval;
3513 if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
3514 BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
3518 tbl_idx += cond_goto;
3523 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
3524 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3525 parms->dev_id, tid);
3530 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
3532 struct ulp_flow_db_res_params *res)
3538 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
3541 if (res->fdb_flags & ULP_FDB_FLAG_SHARED_SESSION)
3542 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_YES);
3544 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_NO);
3546 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
3550 switch (res->resource_func) {
3551 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3552 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
3554 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3555 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
3557 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3558 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
3560 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3561 rc = ulp_mapper_ident_free(ulp, tfp, res);
3563 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
3564 rc = ulp_mapper_mark_free(ulp, res);
3566 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
3567 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
3569 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
3570 rc = ulp_mapper_child_flow_free(ulp, fid, res);
3572 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3573 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
3583 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
3584 enum bnxt_ulp_fdb_type flow_type,
3587 struct ulp_flow_db_res_params res_parms = { 0 };
3591 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3596 * Set the critical resource on the first resource del, then iterate
3597 * while status is good
3599 if (flow_type != BNXT_ULP_FDB_TYPE_RID)
3600 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
3602 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
3606 * This is unexpected on the first call to resource del.
3607 * It likely means that the flow did not exist in the flow db.
3609 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
3610 flow_type, fid, rc);
3615 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
3618 * On fail, we still need to attempt to free the
3619 * remaining resources. Don't return
3622 "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
3623 "] failed rc=%d.\n",
3624 flow_type, fid, res_parms.resource_func,
3625 res_parms.resource_hndl, trc);
3627 /* All subsequent call require the non-critical_resource */
3628 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
3630 rc = ulp_flow_db_resource_del(ulp_ctx,
3636 /* Free the Flow ID since we've removed all resources */
3637 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
3643 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
3644 struct bnxt_ulp_mapper_data *mapper_data)
3646 struct bnxt_ulp_mapper_glb_resource_entry *ent;
3647 struct ulp_flow_db_res_params res;
3650 /* Iterate the global resources and process each one */
3651 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
3652 for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
3653 ent = &mapper_data->glb_res_tbl[dir][idx];
3654 if (ent->resource_func ==
3655 BNXT_ULP_RESOURCE_FUNC_INVALID ||
3658 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
3659 res.resource_func = ent->resource_func;
3660 res.direction = dir;
3661 res.resource_type = ent->resource_type;
3662 /*convert it from BE to cpu */
3664 tfp_be_to_cpu_64(ent->resource_hndl);
3665 ulp_mapper_resource_free(ulp_ctx, 0, &res);
3671 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
3672 enum bnxt_ulp_fdb_type flow_type,
3678 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3682 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
3686 /* Function to handle the mapping of the Flow to be compatible
3687 * with the underlying hardware.
3690 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
3691 struct bnxt_ulp_mapper_create_parms *cparms)
3693 struct bnxt_ulp_mapper_parms parms;
3694 struct ulp_regfile regfile;
3695 int32_t rc = 0, trc;
3697 if (!ulp_ctx || !cparms)
3700 /* Initialize the parms structure */
3701 memset(&parms, 0, sizeof(parms));
3702 parms.act_prop = cparms->act_prop;
3703 parms.act_bitmap = cparms->act;
3704 parms.hdr_bitmap = cparms->hdr_bitmap;
3705 parms.regfile = ®file;
3706 parms.hdr_field = cparms->hdr_field;
3707 parms.fld_bitmap = cparms->fld_bitmap;
3708 parms.comp_fld = cparms->comp_fld;
3709 parms.ulp_ctx = ulp_ctx;
3710 parms.act_tid = cparms->act_tid;
3711 parms.class_tid = cparms->class_tid;
3712 parms.flow_type = cparms->flow_type;
3713 parms.parent_flow = cparms->parent_flow;
3714 parms.parent_fid = cparms->parent_fid;
3715 parms.fid = cparms->flow_id;
3716 parms.tun_idx = cparms->tun_idx;
3717 parms.app_priority = cparms->app_priority;
3718 parms.flow_pattern_id = cparms->flow_pattern_id;
3719 parms.act_pattern_id = cparms->act_pattern_id;
3720 parms.app_id = cparms->app_id;
3722 /* Get the device id from the ulp context */
3723 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
3724 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
3728 /* Get the device params, it will be used in later processing */
3729 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
3730 if (!parms.device_params) {
3731 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
3737 * Get the mapper data for dynamic mapper data such as default
3740 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
3741 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3742 if (!parms.mapper_data) {
3743 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
3747 /* initialize the registry file for further processing */
3748 if (!ulp_regfile_init(parms.regfile)) {
3749 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
3753 /* Process the action template list from the selected action table*/
3754 if (parms.act_tid) {
3755 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
3756 /* Process the action template tables */
3757 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
3760 cparms->shared_hndl = parms.shared_hndl;
3763 if (parms.class_tid) {
3764 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
3766 /* Process the class template tables.*/
3767 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
3772 /* setup the parent-child details */
3773 if (parms.parent_flow) {
3774 /* create a parent flow details */
3775 rc = ulp_flow_db_parent_flow_create(&parms);
3778 } else if (parms.parent_fid) {
3779 /* create a child flow details */
3780 rc = ulp_flow_db_child_flow_create(&parms);
3788 /* Free all resources that were allocated during flow creation */
3789 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
3792 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
3798 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
3800 struct bnxt_ulp_mapper_data *data;
3807 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
3811 data = rte_zmalloc("ulp_mapper_data",
3812 sizeof(struct bnxt_ulp_mapper_data), 0);
3814 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
3818 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
3819 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
3820 /* Don't call deinit since the prof_func wasn't allocated. */
3825 /* Allocate the global resource ids */
3826 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
3828 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
3833 * Only initialize the app global resources if a shared session was
3836 if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
3837 rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
3839 BNXT_TF_DBG(ERR, "Failed to init app glb resources\n");
3844 /* Allocate the generic table list */
3845 rc = ulp_mapper_generic_tbl_list_init(data);
3847 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
3853 /* Ignore the return code in favor of returning the original error. */
3854 ulp_mapper_deinit(ulp_ctx);
3859 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
3861 struct bnxt_ulp_mapper_data *data;
3866 "Failed to acquire ulp context, so data may not be released.\n");
3870 data = (struct bnxt_ulp_mapper_data *)
3871 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3873 /* Go ahead and return since there is no allocated data. */
3874 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
3878 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
3880 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
3881 /* Free the mapper data regardless of errors. */
3882 goto free_mapper_data;
3885 /* Free the global resource info table entries */
3886 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
3889 /* Free the generic table */
3890 (void)ulp_mapper_generic_tbl_list_deinit(data);
3893 /* Reset the data pointer within the ulp_ctx. */
3894 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);