1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2021 Broadcom
7 #include <rte_malloc.h>
9 #include "ulp_template_db_enum.h"
10 #include "ulp_template_struct.h"
11 #include "bnxt_tf_common.h"
12 #include "ulp_utils.h"
15 #include "tf_ext_flow_handle.h"
16 #include "ulp_mark_mgr.h"
17 #include "ulp_mapper.h"
18 #include "ulp_flow_db.h"
20 #include "ulp_template_db_tbl.h"
21 #include "ulp_port_db.h"
22 #include "ulp_ha_mgr.h"
23 #include "bnxt_tf_pmd_shim.h"
25 static uint8_t mapper_fld_zeros[16] = { 0 };
27 static uint8_t mapper_fld_ones[16] = {
28 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
29 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
32 static uint8_t mapper_fld_one[16] = {
33 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
34 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
38 ulp_mapper_tmpl_name_str(enum bnxt_ulp_template_type tmpl_type)
41 case BNXT_ULP_TEMPLATE_TYPE_CLASS:
43 case BNXT_ULP_TEMPLATE_TYPE_ACTION:
46 return "invalid template type";
50 static struct bnxt_ulp_glb_resource_info *
51 ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
55 *num_entries = BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
56 return ulp_glb_resource_tbl;
60 * Read the global resource from the mapper global resource list
62 * The regval is always returned in big-endian.
64 * returns 0 on success
67 ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
73 if (!mapper_data || !regval || !shared ||
74 dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_RF_IDX_LAST)
77 *regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
78 *shared = mapper_data->glb_res_tbl[dir][idx].shared;
83 * Write a global resource to the mapper global resource list
85 * The regval value must be in big-endian.
87 * return 0 on success.
90 ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
91 struct bnxt_ulp_glb_resource_info *res,
92 uint64_t regval, bool shared)
94 struct bnxt_ulp_mapper_glb_resource_entry *ent;
96 /* validate the arguments */
97 if (!data || res->direction >= TF_DIR_MAX ||
98 res->glb_regfile_index >= BNXT_ULP_GLB_RF_IDX_LAST)
101 /* write to the mapper data */
102 ent = &data->glb_res_tbl[res->direction][res->glb_regfile_index];
103 ent->resource_func = res->resource_func;
104 ent->resource_type = res->resource_type;
105 ent->resource_hndl = regval;
106 ent->shared = shared;
111 * Internal function to allocate identity resource and store it in mapper data.
113 * returns 0 on success
116 ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
117 struct bnxt_ulp_mapper_data *mapper_data,
118 struct bnxt_ulp_glb_resource_info *glb_res)
120 struct tf_alloc_identifier_parms iparms = { 0 };
121 struct tf_free_identifier_parms fparms;
126 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
130 iparms.ident_type = glb_res->resource_type;
131 iparms.dir = glb_res->direction;
133 /* Allocate the Identifier using tf api */
134 rc = tf_alloc_identifier(tfp, &iparms);
136 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
137 tf_dir_2_str(iparms.dir),
142 /* entries are stored as big-endian format */
143 regval = tfp_cpu_to_be_64((uint64_t)iparms.id);
145 * write to the mapper global resource
146 * Shared resources are never allocated through this method, so the
147 * shared flag is always false.
149 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
151 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
152 /* Free the identifier when update failed */
153 fparms.dir = iparms.dir;
154 fparms.ident_type = iparms.ident_type;
155 fparms.id = iparms.id;
156 tf_free_identifier(tfp, &fparms);
163 * Internal function to allocate index tbl resource and store it in mapper data.
165 * returns 0 on success
168 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
169 struct bnxt_ulp_mapper_data *mapper_data,
170 struct bnxt_ulp_glb_resource_info *glb_res)
172 struct tf_alloc_tbl_entry_parms aparms = { 0 };
173 struct tf_free_tbl_entry_parms free_parms = { 0 };
176 uint32_t tbl_scope_id;
179 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
183 /* Get the scope id */
184 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &tbl_scope_id);
186 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
190 aparms.type = glb_res->resource_type;
191 aparms.dir = glb_res->direction;
192 aparms.tbl_scope_id = tbl_scope_id;
194 /* Allocate the index tbl using tf api */
195 rc = tf_alloc_tbl_entry(tfp, &aparms);
197 BNXT_TF_DBG(ERR, "Failed to alloc index table [%s][%d]\n",
198 tf_dir_2_str(aparms.dir), aparms.type);
202 /* entries are stored as big-endian format */
203 regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
205 * write to the mapper global resource
206 * Shared resources are never allocated through this method, so the
207 * shared flag is always false.
209 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
211 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
212 /* Free the identifier when update failed */
213 free_parms.dir = aparms.dir;
214 free_parms.type = aparms.type;
215 free_parms.idx = aparms.idx;
216 tf_free_tbl_entry(tfp, &free_parms);
223 ulp_mapper_glb_field_tbl_get(struct bnxt_ulp_mapper_parms *parms,
229 t_idx = parms->app_id << (BNXT_ULP_APP_ID_SHIFT +
230 BNXT_ULP_HDR_SIG_ID_SHIFT +
231 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
232 t_idx += parms->class_tid << (BNXT_ULP_HDR_SIG_ID_SHIFT +
233 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
234 t_idx += ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_HDR_SIG_ID) <<
235 BNXT_ULP_GLB_FIELD_TBL_SHIFT;
238 if (t_idx >= BNXT_ULP_GLB_FIELD_TBL_SIZE) {
239 BNXT_TF_DBG(ERR, "Invalid hdr field index %x:%x:%x\n",
240 parms->class_tid, t_idx, operand);
242 return -EINVAL; /* error */
244 *val = ulp_glb_field_tbl[t_idx];
249 * Get the size of the action property for a given index.
251 * idx [in] The index for the action property
253 * returns the size of the action property.
256 ulp_mapper_act_prop_size_get(uint32_t idx)
258 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
260 return ulp_act_prop_map_table[idx];
263 static struct bnxt_ulp_mapper_cond_info *
264 ulp_mapper_tmpl_reject_list_get(struct bnxt_ulp_mapper_parms *mparms,
267 enum bnxt_ulp_cond_list_opc *opc)
270 const struct bnxt_ulp_template_device_tbls *dev_tbls;
272 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
273 *num_tbls = dev_tbls->tmpl_list[tid].reject_info.cond_nums;
274 *opc = dev_tbls->tmpl_list[tid].reject_info.cond_list_opcode;
275 idx = dev_tbls->tmpl_list[tid].reject_info.cond_start_idx;
277 return &dev_tbls->cond_list[idx];
280 static struct bnxt_ulp_mapper_cond_info *
281 ulp_mapper_tbl_execute_list_get(struct bnxt_ulp_mapper_parms *mparms,
282 struct bnxt_ulp_mapper_tbl_info *tbl,
284 enum bnxt_ulp_cond_list_opc *opc)
287 const struct bnxt_ulp_template_device_tbls *dev_tbls;
289 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
290 *num_tbls = tbl->execute_info.cond_nums;
291 *opc = tbl->execute_info.cond_list_opcode;
292 idx = tbl->execute_info.cond_start_idx;
294 return &dev_tbls->cond_list[idx];
298 * Get a list of classifier tables that implement the flow
299 * Gets a device dependent list of tables that implement the class template id
301 * mparms [in] The mappers parms with data related to the flow.
303 * tid [in] The template id that matches the flow
305 * num_tbls [out] The number of classifier tables in the returned array
307 * returns An array of classifier tables to implement the flow, or NULL on
310 static struct bnxt_ulp_mapper_tbl_info *
311 ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
316 const struct bnxt_ulp_template_device_tbls *dev_tbls;
318 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
320 idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
321 *num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
323 return &dev_tbls->tbl_list[idx];
327 * Get the list of key fields that implement the flow.
329 * mparms [in] The mapper parms with information about the flow
331 * tbl [in] A single table instance to get the key fields from
333 * num_flds [out] The number of key fields in the returned array
335 * Returns array of Key fields, or NULL on error.
337 static struct bnxt_ulp_mapper_key_info *
338 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
339 struct bnxt_ulp_mapper_tbl_info *tbl,
343 const struct bnxt_ulp_template_device_tbls *dev_tbls;
345 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
346 if (!dev_tbls->key_info_list) {
351 idx = tbl->key_start_idx;
352 *num_flds = tbl->key_num_fields;
354 return &dev_tbls->key_info_list[idx];
358 * Get the list of data fields that implement the flow.
360 * mparms [in] The mapper parms with information about the flow
362 * tbl [in] A single table instance to get the data fields from
364 * num_flds [out] The number of data fields in the returned array.
366 * num_encap_flds [out] The number of encap fields in the returned array.
368 * Returns array of data fields, or NULL on error.
370 static struct bnxt_ulp_mapper_field_info *
371 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
372 struct bnxt_ulp_mapper_tbl_info *tbl,
374 uint32_t *num_encap_flds)
377 const struct bnxt_ulp_template_device_tbls *dev_tbls;
379 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
380 if (!dev_tbls->result_field_list) {
386 idx = tbl->result_start_idx;
387 *num_flds = tbl->result_num_fields;
388 *num_encap_flds = tbl->encap_num_fields;
390 return &dev_tbls->result_field_list[idx];
394 * Get the list of ident fields that implement the flow
396 * tbl [in] A single table instance to get the ident fields from
398 * num_flds [out] The number of ident fields in the returned array
400 * returns array of ident fields, or NULL on error
402 static struct bnxt_ulp_mapper_ident_info *
403 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
404 struct bnxt_ulp_mapper_tbl_info *tbl,
408 const struct bnxt_ulp_template_device_tbls *dev_tbls;
410 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
411 if (!dev_tbls->ident_list) {
416 idx = tbl->ident_start_idx;
417 *num_flds = tbl->ident_nums;
419 return &dev_tbls->ident_list[idx];
422 static inline int32_t
423 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp,
425 struct ulp_flow_db_res_params *res)
427 struct tf_free_tcam_entry_parms fparms = {
428 .dir = res->direction,
429 .tcam_tbl_type = res->resource_type,
430 .idx = (uint16_t)res->resource_hndl
433 /* If HA is enabled, we may have to remap the TF Type */
434 if (bnxt_ulp_cntxt_ha_enabled(ulp)) {
435 enum ulp_ha_mgr_region region;
438 switch (res->resource_type) {
439 case TF_TCAM_TBL_TYPE_WC_TCAM_HIGH:
440 case TF_TCAM_TBL_TYPE_WC_TCAM_LOW:
441 rc = ulp_ha_mgr_region_get(ulp, ®ion);
443 /* Log this, but assume region is correct */
445 "Unable to get HA region (%d)\n",
448 fparms.tcam_tbl_type =
449 (region == ULP_HA_REGION_LOW) ?
450 TF_TCAM_TBL_TYPE_WC_TCAM_LOW :
451 TF_TCAM_TBL_TYPE_WC_TCAM_HIGH;
457 return tf_free_tcam_entry(tfp, &fparms);
460 static inline int32_t
461 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
463 struct ulp_flow_db_res_params *res)
465 struct tf_free_tbl_entry_parms fparms = {
466 .dir = res->direction,
467 .type = res->resource_type,
468 .idx = (uint32_t)res->resource_hndl
472 * Just get the table scope, it will be ignored if not necessary
473 * by the tf_free_tbl_entry
475 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
477 return tf_free_tbl_entry(tfp, &fparms);
480 static inline int32_t
481 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
483 struct ulp_flow_db_res_params *res)
485 struct tf_delete_em_entry_parms fparms = { 0 };
488 fparms.dir = res->direction;
489 fparms.flow_handle = res->resource_hndl;
491 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
493 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
497 return tf_delete_em_entry(tfp, &fparms);
500 static inline int32_t
501 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
503 struct ulp_flow_db_res_params *res)
505 struct tf_free_identifier_parms fparms = {
506 .dir = res->direction,
507 .ident_type = res->resource_type,
508 .id = (uint16_t)res->resource_hndl
511 return tf_free_identifier(tfp, &fparms);
514 static inline int32_t
515 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
516 struct ulp_flow_db_res_params *res)
518 return ulp_mark_db_mark_del(ulp,
523 static inline int32_t
524 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
526 struct ulp_flow_db_res_params *res)
528 uint32_t idx, child_fid = 0, parent_idx;
529 struct bnxt_ulp_flow_db *flow_db;
531 parent_idx = (uint32_t)res->resource_hndl;
533 /* check the validity of the parent fid */
534 if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
536 BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
540 /* Clear all the child flows parent index */
541 flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
542 while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
544 /* update the child flows resource handle */
545 if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
547 BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
553 /* free the parent entry in the parent table flow */
554 if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
555 BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
561 static inline int32_t
562 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
564 struct ulp_flow_db_res_params *res)
568 parent_fid = (uint32_t)res->resource_hndl;
570 return 0; /* Already freed - orphan child*/
572 /* reset the child flow bitset*/
573 if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
574 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
575 parent_fid, child_fid);
582 * Process the flow database opcode alloc action.
583 * returns 0 on success
586 ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
587 struct bnxt_ulp_mapper_tbl_info *tbl)
593 /* allocate a new fid */
594 rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
595 BNXT_ULP_FDB_TYPE_RID,
599 "Unable to allocate flow table entry\n");
602 /* Store the allocated fid in regfile*/
604 rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
605 tfp_cpu_to_be_64(val64));
607 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
609 ulp_flow_db_fid_free(parms->ulp_ctx,
610 BNXT_ULP_FDB_TYPE_RID, rid);
617 * Process the flow database opcode action.
618 * returns 0 on success.
621 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
622 struct bnxt_ulp_mapper_tbl_info *tbl,
623 struct ulp_flow_db_res_params *fid_parms)
627 enum bnxt_ulp_fdb_type flow_type;
630 switch (tbl->fdb_opcode) {
631 case BNXT_ULP_FDB_OPC_PUSH_FID:
632 push_fid = parms->fid;
633 flow_type = parms->flow_type;
635 case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
636 /* get the fid from the regfile */
637 rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
640 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
644 /* Use the extracted fid to update the flow resource */
645 push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
646 flow_type = BNXT_ULP_FDB_TYPE_RID;
649 return rc; /* Nothing to be done */
652 /* Add the resource to the flow database */
653 rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
654 push_fid, fid_parms);
656 BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
662 * Process the flow database opcode action.
663 * returns 0 on success.
666 ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms,
667 struct bnxt_ulp_mapper_tbl_info *tbl,
672 switch (tbl->pri_opcode) {
673 case BNXT_ULP_PRI_OPC_NOT_USED:
676 case BNXT_ULP_PRI_OPC_CONST:
677 *priority = tbl->pri_operand;
679 case BNXT_ULP_PRI_OPC_APP_PRI:
680 *priority = parms->app_priority;
683 BNXT_TF_DBG(ERR, "Priority opcode not supported %d\n",
692 * Process the identifier list in the given table.
693 * Extract the ident from the table entry and
694 * write it to the reg file.
695 * returns 0 on success.
698 ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
699 struct bnxt_ulp_mapper_tbl_info *tbl,
701 uint32_t byte_data_size,
702 enum bnxt_ulp_byte_order byte_order)
704 struct bnxt_ulp_mapper_ident_info *idents;
705 uint32_t i, num_idents = 0;
708 /* validate the null arguments */
710 BNXT_TF_DBG(ERR, "invalid argument\n");
714 /* Get the ident list and process each one */
715 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
717 for (i = 0; i < num_idents; i++) {
718 /* check the size of the buffer for validation */
719 if ((idents[i].ident_bit_pos + idents[i].ident_bit_size) >
720 ULP_BYTE_2_BITS(byte_data_size) ||
721 idents[i].ident_bit_size > ULP_BYTE_2_BITS(sizeof(val64))) {
722 BNXT_TF_DBG(ERR, "invalid offset or length %x:%x:%x\n",
723 idents[i].ident_bit_pos,
724 idents[i].ident_bit_size,
729 if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
730 ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
732 idents[i].ident_bit_pos,
733 idents[i].ident_bit_size);
735 ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
736 idents[i].ident_bit_pos,
737 idents[i].ident_bit_size);
739 /* Write it to the regfile, val64 is already in big-endian*/
740 if (ulp_regfile_write(parms->regfile,
741 idents[i].regfile_idx, val64)) {
742 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
743 idents[i].regfile_idx);
751 * Process the identifier instruction and either store it in the flow database
752 * or return it in the val (if not NULL) on success. If val is NULL, the
753 * identifier is to be stored in the flow database.
756 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
757 struct bnxt_ulp_mapper_tbl_info *tbl,
758 struct bnxt_ulp_mapper_ident_info *ident,
761 struct ulp_flow_db_res_params fid_parms;
764 struct tf_alloc_identifier_parms iparms = { 0 };
765 struct tf_free_identifier_parms free_parms = { 0 };
769 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
771 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
775 idx = ident->regfile_idx;
777 iparms.ident_type = ident->ident_type;
778 iparms.dir = tbl->direction;
780 rc = tf_alloc_identifier(tfp, &iparms);
782 BNXT_TF_DBG(ERR, "Alloc ident %s:%s failed.\n",
783 tf_dir_2_str(iparms.dir),
784 tf_ident_2_str(iparms.ident_type));
788 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
789 if (ulp_regfile_write(parms->regfile, idx, id)) {
790 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
792 /* Need to free the identifier, so goto error */
796 /* Link the resource to the flow in the flow db */
798 memset(&fid_parms, 0, sizeof(fid_parms));
799 fid_parms.direction = tbl->direction;
800 fid_parms.resource_func = ident->resource_func;
801 fid_parms.resource_type = ident->ident_type;
802 fid_parms.resource_hndl = iparms.id;
803 fid_parms.critical_resource = tbl->critical_resource;
804 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
806 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
808 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
810 /* Need to free the identifier, so goto error */
819 /* Need to free the identifier */
820 free_parms.dir = tbl->direction;
821 free_parms.ident_type = ident->ident_type;
822 free_parms.id = iparms.id;
824 (void)tf_free_identifier(tfp, &free_parms);
826 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
828 tf_dir_2_str(tbl->direction));
833 * Process the identifier instruction and extract it from result blob.
834 * Increment the identifier reference count and store it in the flow database.
837 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
838 struct bnxt_ulp_mapper_tbl_info *tbl,
839 struct bnxt_ulp_mapper_ident_info *ident,
840 struct ulp_blob *res_blob)
842 struct ulp_flow_db_res_params fid_parms;
845 struct tf_search_identifier_parms sparms = { 0 };
846 struct tf_free_identifier_parms free_parms = { 0 };
850 /* Get the tfp from ulp context */
851 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
853 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
857 /* Extract the index from the result blob */
858 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
859 ident->ident_bit_pos, ident->ident_bit_size);
861 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
865 /* populate the search params and search identifier shadow table */
866 sparms.ident_type = ident->ident_type;
867 sparms.dir = tbl->direction;
868 /* convert the idx into cpu format */
869 sparms.search_id = tfp_be_to_cpu_32(idx);
871 /* Search identifier also increase the reference count */
872 rc = tf_search_identifier(tfp, &sparms);
874 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
875 tf_dir_2_str(sparms.dir),
876 tf_ident_2_str(sparms.ident_type),
881 /* Write it to the regfile */
882 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
883 if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
884 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
886 /* Need to free the identifier, so goto error */
890 /* Link the resource to the flow in the flow db */
891 memset(&fid_parms, 0, sizeof(fid_parms));
892 fid_parms.direction = tbl->direction;
893 fid_parms.resource_func = ident->resource_func;
894 fid_parms.resource_type = ident->ident_type;
895 fid_parms.resource_hndl = sparms.search_id;
896 fid_parms.critical_resource = tbl->critical_resource;
897 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
899 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
901 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
903 /* Need to free the identifier, so goto error */
910 /* Need to free the identifier */
911 free_parms.dir = tbl->direction;
912 free_parms.ident_type = ident->ident_type;
913 free_parms.id = sparms.search_id;
914 (void)tf_free_identifier(tfp, &free_parms);
915 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
917 tf_dir_2_str(tbl->direction), sparms.search_id);
922 ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
927 enum bnxt_ulp_port_table port_data = val16;
930 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
931 if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
933 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
937 case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
938 if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
940 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
944 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
945 if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
947 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
952 BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
959 ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
960 enum bnxt_ulp_field_src field_src,
969 struct bnxt_ulp_mapper_data *m;
971 uint32_t port_id, val_size, field_size;
972 uint16_t idx, size_idx, offset;
973 uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
980 /* Perform the action */
982 case BNXT_ULP_FIELD_SRC_ZERO:
983 *val = mapper_fld_zeros;
985 case BNXT_ULP_FIELD_SRC_CONST:
988 case BNXT_ULP_FIELD_SRC_ONES:
989 *val = mapper_fld_ones;
992 case BNXT_ULP_FIELD_SRC_CF:
993 if (!ulp_operand_read(field_opr,
994 (uint8_t *)&idx, sizeof(uint16_t))) {
995 BNXT_TF_DBG(ERR, "CF operand read failed\n");
998 idx = tfp_be_to_cpu_16(idx);
999 if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t)) {
1000 BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
1004 buffer = (uint8_t *)&parms->comp_fld[idx];
1005 *val = &buffer[sizeof(uint64_t) - bytelen];
1006 *value = ULP_COMP_FLD_IDX_RD(parms, idx);
1008 case BNXT_ULP_FIELD_SRC_RF:
1009 if (!ulp_operand_read(field_opr,
1010 (uint8_t *)&idx, sizeof(uint16_t))) {
1011 BNXT_TF_DBG(ERR, "RF operand read failed\n");
1015 idx = tfp_be_to_cpu_16(idx);
1016 /* Uninitialized regfile entries return 0 */
1017 if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
1018 sizeof(uint64_t) < bytelen) {
1019 BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
1023 buffer = (uint8_t *)&parms->regfile->entry[idx].data;
1024 *val = &buffer[sizeof(uint64_t) - bytelen];
1025 *value = tfp_be_to_cpu_64(lregval);
1027 case BNXT_ULP_FIELD_SRC_ACT_PROP:
1028 if (!ulp_operand_read(field_opr,
1029 (uint8_t *)&idx, sizeof(uint16_t))) {
1030 BNXT_TF_DBG(ERR, "Action operand read failed\n");
1033 idx = tfp_be_to_cpu_16(idx);
1034 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1035 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
1038 buffer = &parms->act_prop->act_details[idx];
1039 field_size = ulp_mapper_act_prop_size_get(idx);
1040 if (bytelen > field_size) {
1041 BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
1045 *val = &buffer[field_size - bytelen];
1047 case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
1048 if (!ulp_operand_read(field_opr,
1049 (uint8_t *)&idx, sizeof(uint16_t))) {
1050 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1053 idx = tfp_be_to_cpu_16(idx);
1055 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1056 BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
1059 *val = &parms->act_prop->act_details[idx];
1061 /* get the size index next */
1062 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1063 (uint8_t *)&size_idx, sizeof(uint16_t))) {
1064 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1067 size_idx = tfp_be_to_cpu_16(size_idx);
1068 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1069 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
1072 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
1074 val_size = tfp_be_to_cpu_32(val_size);
1075 *val_len = ULP_BYTE_2_BITS(val_size);
1077 case BNXT_ULP_FIELD_SRC_GLB_RF:
1078 if (!ulp_operand_read(field_opr,
1079 (uint8_t *)&idx, sizeof(uint16_t))) {
1080 BNXT_TF_DBG(ERR, "Global regfile read failed\n");
1083 idx = tfp_be_to_cpu_16(idx);
1084 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1085 dir, idx, &lregval, &shared) ||
1086 sizeof(uint64_t) < bytelen) {
1087 BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
1091 m = parms->mapper_data;
1092 buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
1093 *val = &buffer[sizeof(uint64_t) - bytelen];
1094 *value = tfp_be_to_cpu_64(lregval);
1096 case BNXT_ULP_FIELD_SRC_HF:
1097 case BNXT_ULP_FIELD_SRC_SUB_HF:
1098 if (!ulp_operand_read(field_opr,
1099 (uint8_t *)&idx, sizeof(uint16_t))) {
1100 BNXT_TF_DBG(ERR, "Header field read failed\n");
1103 idx = tfp_be_to_cpu_16(idx);
1104 /* get the index from the global field list */
1105 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1106 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1111 buffer = parms->hdr_field[bit].spec;
1113 buffer = parms->hdr_field[bit].mask;
1115 field_size = parms->hdr_field[bit].size;
1116 if (bytelen > field_size) {
1117 BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
1121 if (field_src == BNXT_ULP_FIELD_SRC_HF) {
1122 *val = &buffer[field_size - bytelen];
1124 /* get the offset next */
1125 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1127 sizeof(uint16_t))) {
1128 BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
1131 offset = tfp_be_to_cpu_16(offset);
1132 offset = ULP_BITS_2_BYTE_NR(offset);
1133 if ((offset + bytelen) > field_size) {
1134 BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
1137 *val = &buffer[offset];
1140 case BNXT_ULP_FIELD_SRC_HDR_BIT:
1141 if (!ulp_operand_read(field_opr,
1142 (uint8_t *)&lregval, sizeof(uint64_t))) {
1143 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1146 lregval = tfp_be_to_cpu_64(lregval);
1147 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
1148 *val = mapper_fld_one;
1151 *val = mapper_fld_zeros;
1154 case BNXT_ULP_FIELD_SRC_ACT_BIT:
1155 if (!ulp_operand_read(field_opr,
1156 (uint8_t *)&lregval, sizeof(uint64_t))) {
1157 BNXT_TF_DBG(ERR, "Action bit read failed\n");
1160 lregval = tfp_be_to_cpu_64(lregval);
1161 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
1162 *val = mapper_fld_one;
1165 *val = mapper_fld_zeros;
1168 case BNXT_ULP_FIELD_SRC_FIELD_BIT:
1169 if (!ulp_operand_read(field_opr,
1170 (uint8_t *)&idx, sizeof(uint16_t))) {
1171 BNXT_TF_DBG(ERR, "Field bit read failed\n");
1174 idx = tfp_be_to_cpu_16(idx);
1175 /* get the index from the global field list */
1176 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1177 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1181 if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
1182 *val = mapper_fld_one;
1185 *val = mapper_fld_zeros;
1188 case BNXT_ULP_FIELD_SRC_PORT_TABLE:
1189 /* The port id is present in the comp field list */
1190 port_id = ULP_COMP_FLD_IDX_RD(parms,
1191 BNXT_ULP_CF_IDX_DEV_PORT_ID);
1192 /* get the port table enum */
1193 if (!ulp_operand_read(field_opr,
1194 (uint8_t *)&idx, sizeof(uint16_t))) {
1195 BNXT_TF_DBG(ERR, "Port table enum read failed\n");
1198 idx = tfp_be_to_cpu_16(idx);
1199 if (ulp_mapper_field_port_db_process(parms, port_id, idx,
1201 BNXT_TF_DBG(ERR, "field port table failed\n");
1204 case BNXT_ULP_FIELD_SRC_SKIP:
1207 case BNXT_ULP_FIELD_SRC_REJECT:
1210 BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
1216 static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
1224 bytelen = ULP_BITS_2_BYTE(bitlen);
1225 if (bytelen == sizeof(uint8_t)) {
1226 *output = *((uint8_t *)buffer);
1227 } else if (bytelen == sizeof(uint16_t)) {
1228 val_16 = *((uint16_t *)buffer);
1229 *output = tfp_be_to_cpu_16(val_16);
1230 } else if (bytelen == sizeof(uint32_t)) {
1231 val_32 = *((uint32_t *)buffer);
1232 *output = tfp_be_to_cpu_32(val_32);
1233 } else if (bytelen == sizeof(val_64)) {
1234 val_64 = *((uint64_t *)buffer);
1235 *output = tfp_be_to_cpu_64(val_64);
1243 static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
1244 struct ulp_blob *blob,
1249 if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
1250 if (ulp_blob_pad_push(blob, val_len) < 0) {
1251 BNXT_TF_DBG(ERR, "too large for blob\n");
1254 } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
1255 if (ulp_blob_push_encap(blob, val, val_len) < 0) {
1256 BNXT_TF_DBG(ERR, "encap blob push failed\n");
1260 if (!ulp_blob_push(blob, val, val_len)) {
1261 BNXT_TF_DBG(ERR, "push of val1 failed\n");
1270 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
1272 struct bnxt_ulp_mapper_field_info *fld,
1273 struct ulp_blob *blob,
1277 uint16_t write_idx = blob->write_idx;
1278 uint8_t *val = NULL, *val1, *val2, *val3;
1279 uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
1280 uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
1281 uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
1282 uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
1283 uint64_t value1 = 0, value2 = 0, value3 = 0;
1286 /* prepare the field source and values */
1287 switch (fld->field_opc) {
1288 case BNXT_ULP_FIELD_OPC_SRC1:
1291 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1294 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1295 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1303 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1304 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1305 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1306 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1307 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1308 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1318 /* process the src1 opcode */
1320 if (ulp_mapper_field_src_process(parms, fld->field_src1,
1321 fld->field_opr1, dir, is_key,
1322 fld->field_bit_size, &val1,
1323 &val1_len, &value1)) {
1324 BNXT_TF_DBG(ERR, "fld src1 process failed\n");
1328 if (ulp_mapper_field_buffer_eval(val1, val1_len,
1330 BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
1336 /* for "if then clause" set the correct process */
1337 if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
1344 /* process src2 opcode */
1346 if (ulp_mapper_field_src_process(parms, fld->field_src2,
1347 fld->field_opr2, dir, is_key,
1348 fld->field_bit_size, &val2,
1349 &val2_len, &value2)) {
1350 BNXT_TF_DBG(ERR, "fld src2 process failed\n");
1354 if (ulp_mapper_field_buffer_eval(val2, val2_len,
1356 BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
1362 /* process src3 opcode */
1364 if (ulp_mapper_field_src_process(parms, fld->field_src3,
1365 fld->field_opr3, dir, is_key,
1366 fld->field_bit_size, &val3,
1367 &val3_len, &value3)) {
1368 BNXT_TF_DBG(ERR, "fld src3 process failed\n");
1372 if (ulp_mapper_field_buffer_eval(val3, val3_len,
1374 BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
1380 val_len = fld->field_bit_size;
1381 /* process the field opcodes */
1382 switch (fld->field_opc) {
1383 case BNXT_ULP_FIELD_OPC_SRC1:
1384 rc = ulp_mapper_field_blob_write(fld->field_src1,
1385 blob, val1, val1_len, &val);
1388 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1390 rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
1391 val2, val2_len, &val);
1394 rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
1395 val3, val3_len, &val);
1399 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1400 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1401 val_int = val1_int + val2_int;
1402 val_int = tfp_cpu_to_be_64(val_int);
1403 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1407 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1408 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1409 val_int = val1_int - val2_int;
1410 val_int = tfp_cpu_to_be_64(val_int);
1411 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1415 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1416 val_int = val1_int | val2_int;
1417 val_int = tfp_cpu_to_be_64(val_int);
1418 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1422 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1423 val_int = val1_int | val2_int | val3_int;
1424 val_int = tfp_cpu_to_be_64(val_int);
1425 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1429 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1430 val_int = val1_int & val2_int;
1431 val_int = tfp_cpu_to_be_64(val_int);
1432 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1436 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1437 val_int = val1_int & (val2_int | val3_int);
1438 val_int = tfp_cpu_to_be_64(val_int);
1439 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1443 case BNXT_ULP_FIELD_OPC_SKIP:
1446 BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
1453 BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
1454 fld->description, (val) ? write_idx : 0, val_len);
1459 * Result table process and fill the result blob.
1460 * data [out] - the result blob data
1463 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
1464 struct bnxt_ulp_mapper_tbl_info *tbl,
1465 struct ulp_blob *data,
1468 struct bnxt_ulp_mapper_field_info *dflds;
1469 uint32_t i, num_flds = 0, encap_flds = 0;
1472 /* Get the result field list */
1473 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
1476 /* validate the result field list counts */
1477 if ((tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1478 (!num_flds && !encap_flds)) || !dflds ||
1479 (tbl->resource_func != BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1480 (!num_flds || encap_flds))) {
1481 BNXT_TF_DBG(ERR, "Failed to get data fields %x:%x\n",
1482 num_flds, encap_flds);
1486 /* process the result fields, loop through them */
1487 for (i = 0; i < (num_flds + encap_flds); i++) {
1488 /* set the swap index if encap swap bit is enabled */
1489 if (parms->device_params->encap_byte_swap && encap_flds &&
1491 ulp_blob_encap_swap_idx_set(data);
1493 /* Process the result fields */
1494 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1495 &dflds[i], data, 0, name);
1497 BNXT_TF_DBG(ERR, "data field failed\n");
1502 /* if encap bit swap is enabled perform the bit swap */
1503 if (parms->device_params->encap_byte_swap && encap_flds)
1504 ulp_blob_perform_encap_swap(data);
1510 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1511 struct bnxt_ulp_mapper_tbl_info *tbl,
1514 struct ulp_flow_db_res_params fid_parms;
1515 uint32_t mark, gfid, mark_flag;
1516 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1519 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1520 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1521 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1522 BNXT_ULP_ACT_BIT_MARK)))
1523 return rc; /* no need to perform gfid process */
1525 /* Get the mark id details from action property */
1526 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1528 mark = tfp_be_to_cpu_32(mark);
1530 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1531 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1533 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1536 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1539 fid_parms.direction = tbl->direction;
1540 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1541 fid_parms.critical_resource = tbl->critical_resource;
1542 fid_parms.resource_type = mark_flag;
1543 fid_parms.resource_hndl = gfid;
1544 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1546 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1548 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1553 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1554 struct bnxt_ulp_mapper_tbl_info *tbl)
1556 struct ulp_flow_db_res_params fid_parms;
1557 uint32_t act_idx, mark, mark_flag;
1559 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1562 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1563 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1564 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1565 BNXT_ULP_ACT_BIT_MARK)))
1566 return rc; /* no need to perform mark action process */
1568 /* Get the mark id details from action property */
1569 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1571 mark = tfp_be_to_cpu_32(mark);
1573 if (!ulp_regfile_read(parms->regfile,
1574 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1576 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1579 act_idx = tfp_be_to_cpu_64(val64);
1580 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1581 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1584 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1587 fid_parms.direction = tbl->direction;
1588 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1589 fid_parms.critical_resource = tbl->critical_resource;
1590 fid_parms.resource_type = mark_flag;
1591 fid_parms.resource_hndl = act_idx;
1592 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1594 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1596 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1601 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1602 struct bnxt_ulp_mapper_tbl_info *tbl)
1604 struct ulp_flow_db_res_params fid_parms;
1605 uint32_t act_idx, mark, mark_flag;
1607 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1610 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1611 mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
1612 return rc; /* no need to perform mark action process */
1614 /* Get the mark id details from the computed field of dev port id */
1615 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1617 /* Get the main action pointer */
1618 if (!ulp_regfile_read(parms->regfile,
1619 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1621 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1624 act_idx = tfp_be_to_cpu_64(val64);
1626 /* Set the mark flag to local fid and vfr flag */
1627 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1629 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1632 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1635 fid_parms.direction = tbl->direction;
1636 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1637 fid_parms.critical_resource = tbl->critical_resource;
1638 fid_parms.resource_type = mark_flag;
1639 fid_parms.resource_hndl = act_idx;
1640 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1642 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1644 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1648 /* Tcam table scan the identifier list and allocate each identifier */
1650 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1651 struct bnxt_ulp_mapper_tbl_info *tbl)
1653 struct bnxt_ulp_mapper_ident_info *idents;
1654 uint32_t num_idents;
1657 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1658 for (i = 0; i < num_idents; i++) {
1659 if (ulp_mapper_ident_process(parms, tbl,
1667 * Tcam table scan the identifier list and extract the identifier from
1671 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1672 struct bnxt_ulp_mapper_tbl_info *tbl,
1673 struct ulp_blob *data)
1675 struct bnxt_ulp_mapper_ident_info *idents;
1676 uint32_t num_idents = 0, i;
1680 * Extract the listed identifiers from the result field,
1681 * no need to allocate them.
1683 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1684 for (i = 0; i < num_idents; i++) {
1685 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1687 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1694 /* Internal function to write the tcam entry */
1696 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1697 struct bnxt_ulp_mapper_tbl_info *tbl,
1698 struct ulp_blob *key,
1699 struct ulp_blob *mask,
1700 struct ulp_blob *data,
1703 struct tf_set_tcam_entry_parms sparms = { 0 };
1708 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1710 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1714 sparms.dir = tbl->direction;
1715 sparms.tcam_tbl_type = tbl->resource_type;
1717 sparms.key = ulp_blob_data_get(key, &tmplen);
1718 sparms.key_sz_in_bits = tmplen;
1719 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1720 sparms.result = ulp_blob_data_get(data, &tmplen);
1721 sparms.result_sz_in_bits = tmplen;
1722 if (tf_set_tcam_entry(tfp, &sparms)) {
1723 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1724 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1725 tf_dir_2_str(sparms.dir), sparms.idx);
1730 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1732 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1740 * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
1742 * parms [in] The mappers parms with data related to the flow.
1744 * key [in] The original key to be transformed
1746 * mask [in] The original mask to be transformed
1748 * tkey [in/out] The transformed key
1750 * tmask [in/out] The transformed mask
1752 * returns zero on success, non-zero on failure
1755 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
1756 struct ulp_blob *key,
1757 struct ulp_blob *mask,
1758 struct ulp_blob *tkey,
1759 struct ulp_blob *tmask)
1761 uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
1762 uint32_t cword, i, rc;
1766 slice_width = dparms->wc_slice_width;
1767 clen = dparms->wc_ctl_size_bits;
1768 max_slices = dparms->wc_max_slices;
1769 blen = ulp_blob_data_len_get(key);
1771 /* Get the length of the key based on number of slices and width */
1774 while (tlen < blen &&
1775 num_slices <= max_slices) {
1776 num_slices = num_slices << 1;
1780 if (num_slices > max_slices) {
1781 BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
1785 /* The key/mask may not be on a natural slice boundary, pad it */
1787 if (ulp_blob_pad_push(key, pad) < 0 ||
1788 ulp_blob_pad_push(mask, pad) < 0) {
1789 BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
1793 /* The new length accounts for the ctrl word length and num slices */
1794 tlen = tlen + clen * num_slices;
1795 if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
1796 !ulp_blob_init(tmask, tlen, mask->byte_order)) {
1797 BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
1801 /* Build the transformed key/mask */
1802 cword = dparms->wc_mode_list[num_slices - 1];
1803 cword = tfp_cpu_to_be_32(cword);
1805 for (i = 0; i < num_slices; i++) {
1806 val = ulp_blob_push_32(tkey, &cword, clen);
1808 BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
1811 val = ulp_blob_push_32(tmask, &cword, clen);
1813 BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
1816 rc = ulp_blob_append(tkey, key, offset, slice_width);
1818 BNXT_TF_DBG(ERR, "Key blob append failed\n");
1821 rc = ulp_blob_append(tmask, mask, offset, slice_width);
1823 BNXT_TF_DBG(ERR, "Mask blob append failed\n");
1826 offset += slice_width;
1829 /* The key/mask are byte reversed on every 4 byte chunk */
1830 ulp_blob_perform_byte_reverse(tkey, 4);
1831 ulp_blob_perform_byte_reverse(tmask, 4);
1836 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1837 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
1839 ulp_blob_perform_64B_word_swap(blob);
1840 ulp_blob_perform_64B_byte_swap(blob);
1844 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1845 struct bnxt_ulp_mapper_tbl_info *tbl)
1847 struct bnxt_ulp_mapper_key_info *kflds;
1848 struct ulp_blob okey, omask, data, update_data;
1849 struct ulp_blob tkey, tmask; /* transform key and mask */
1850 struct ulp_blob *key, *mask;
1851 uint32_t i, num_kflds;
1854 struct bnxt_ulp_device_params *dparms = parms->device_params;
1855 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1856 struct tf_search_tcam_entry_parms searchparms = { 0 };
1857 struct ulp_flow_db_res_params fid_parms = { 0 };
1858 struct tf_free_tcam_entry_parms free_parms = { 0 };
1860 uint16_t tmplen = 0;
1863 /* Set the key and mask to the original key and mask. */
1867 /* Skip this if table opcode is NOP */
1868 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
1869 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
1870 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
1875 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1877 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1881 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1882 if (!kflds || !num_kflds) {
1883 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1887 if (!ulp_blob_init(key, tbl->blob_key_bit_size, tbl->byte_order) ||
1888 !ulp_blob_init(mask, tbl->blob_key_bit_size, tbl->byte_order) ||
1889 !ulp_blob_init(&data, tbl->result_bit_size, dparms->byte_order) ||
1890 !ulp_blob_init(&update_data, tbl->result_bit_size,
1891 dparms->byte_order)) {
1892 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1896 /* create the key/mask */
1898 * NOTE: The WC table will require some kind of flag to handle the
1899 * mode bits within the key/mask
1901 for (i = 0; i < num_kflds; i++) {
1903 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1904 &kflds[i].field_info_spec,
1905 key, 1, "TCAM Key");
1907 BNXT_TF_DBG(ERR, "Key field set failed %s\n",
1908 kflds[i].field_info_spec.description);
1912 /* Setup the mask */
1913 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1914 &kflds[i].field_info_mask,
1915 mask, 0, "TCAM Mask");
1917 BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
1918 kflds[i].field_info_mask.description);
1923 /* For wild card tcam perform the post process to swap the blob */
1924 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM ||
1925 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_HIGH ||
1926 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_LOW) {
1927 if (dparms->dynamic_pad_en) {
1928 /* Sets up the slices for writing to the WC TCAM */
1929 rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
1935 "Failed to post proc WC entry.\n");
1938 /* Now need to use the transform Key/Mask */
1942 ulp_mapper_wc_tcam_tbl_post_process(key);
1943 ulp_mapper_wc_tcam_tbl_post_process(mask);
1948 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1949 /* allocate the tcam index */
1950 aparms.dir = tbl->direction;
1951 aparms.tcam_tbl_type = tbl->resource_type;
1952 aparms.key = ulp_blob_data_get(key, &tmplen);
1953 aparms.key_sz_in_bits = tmplen;
1954 aparms.mask = ulp_blob_data_get(mask, &tmplen);
1956 /* calculate the entry priority */
1957 rc = ulp_mapper_priority_opc_process(parms, tbl,
1960 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1964 rc = tf_alloc_tcam_entry(tfp, &aparms);
1966 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1973 * Searching before allocation to see if we already have an
1974 * entry. This allows re-use of a constrained resource.
1976 searchparms.dir = tbl->direction;
1977 searchparms.tcam_tbl_type = tbl->resource_type;
1978 searchparms.key = ulp_blob_data_get(key, &tmplen);
1979 searchparms.key_sz_in_bits = tbl->key_bit_size;
1980 searchparms.mask = ulp_blob_data_get(mask, &tmplen);
1981 searchparms.alloc = 1;
1982 searchparms.result = ulp_blob_data_get(&data, &tmplen);
1983 searchparms.result_sz_in_bits = tbl->result_bit_size;
1985 /* calculate the entry priority */
1986 rc = ulp_mapper_priority_opc_process(parms, tbl,
1987 &searchparms.priority);
1989 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1993 rc = tf_search_tcam_entry(tfp, &searchparms);
1995 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
1999 /* Successful search, check the result */
2000 if (searchparms.search_status == REJECT) {
2001 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
2004 idx = searchparms.idx;
2005 hit = searchparms.hit;
2008 /* Write the tcam index into the regfile*/
2009 if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
2010 (uint64_t)tfp_cpu_to_be_64(idx))) {
2011 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
2014 /* Need to free the tcam idx, so goto error */
2018 /* if it is miss then it is same as no search before alloc */
2019 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
2020 /*Scan identifier list, allocate identifier and update regfile*/
2021 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
2022 /* Create the result blob */
2024 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2026 /* write the tcam entry */
2028 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
2031 /*Scan identifier list, extract identifier and update regfile*/
2032 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
2037 /* Add the tcam index to the flow database */
2038 fid_parms.direction = tbl->direction;
2039 fid_parms.resource_func = tbl->resource_func;
2040 fid_parms.resource_type = tbl->resource_type;
2041 fid_parms.critical_resource = tbl->critical_resource;
2042 fid_parms.resource_hndl = idx;
2043 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2045 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2047 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2049 /* Need to free the identifier, so goto error */
2055 free_parms.dir = tbl->direction;
2056 free_parms.tcam_tbl_type = tbl->resource_type;
2057 free_parms.idx = idx;
2058 trc = tf_free_tcam_entry(tfp, &free_parms);
2060 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
2061 tbl->resource_type, tbl->direction, idx);
2066 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2067 struct bnxt_ulp_mapper_tbl_info *tbl)
2069 struct bnxt_ulp_mapper_key_info *kflds;
2070 struct ulp_blob key, data;
2071 uint32_t i, num_kflds;
2074 struct ulp_flow_db_res_params fid_parms = { 0 };
2075 struct tf_insert_em_entry_parms iparms = { 0 };
2076 struct tf_delete_em_entry_parms free_parms = { 0 };
2077 enum bnxt_ulp_flow_mem_type mtype;
2078 struct bnxt_ulp_device_params *dparms = parms->device_params;
2083 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2084 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2086 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
2090 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2091 if (!kflds || !num_kflds) {
2092 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2096 /* Initialize the key/result blobs */
2097 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
2099 !ulp_blob_init(&data, tbl->result_bit_size,
2101 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2105 /* create the key */
2106 for (i = 0; i < num_kflds; i++) {
2108 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2109 &kflds[i].field_info_spec,
2112 BNXT_TF_DBG(ERR, "Key field set failed.\n");
2117 /* if dynamic padding is enabled then add padding to result data */
2118 if (dparms->dynamic_pad_en) {
2119 /* add padding to make sure key is at byte boundary */
2120 ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
2123 pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
2125 BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
2128 ulp_blob_pad_push(&data, (uint32_t)pad);
2131 /* Create the result data blob */
2132 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
2134 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2137 if (dparms->dynamic_pad_en) {
2138 uint32_t abits = dparms->em_blk_align_bits;
2140 /* when dynamic padding is enabled merge result + key */
2141 rc = ulp_blob_block_merge(&data, &key, abits, pad);
2143 BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
2147 /* add padding to make sure merged result is at slice boundary*/
2148 ulp_blob_pad_align(&data, abits);
2150 ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
2153 /* do the transpose for the internal EM keys */
2154 if (tbl->resource_type == TF_MEM_INTERNAL) {
2155 if (dparms->em_key_align_bytes) {
2156 int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
2158 tmplen = ulp_blob_data_len_get(&key);
2159 ulp_blob_pad_push(&key, b - tmplen);
2161 tmplen = ulp_blob_data_len_get(&key);
2162 ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
2165 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
2166 &iparms.tbl_scope_id);
2168 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2173 * NOTE: the actual blob size will differ from the size in the tbl
2174 * entry due to the padding.
2176 iparms.dup_check = 0;
2177 iparms.dir = tbl->direction;
2178 iparms.mem = tbl->resource_type;
2179 iparms.key = ulp_blob_data_get(&key, &tmplen);
2180 iparms.key_sz_in_bits = tbl->key_bit_size;
2181 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
2182 if (tbl->result_bit_size)
2183 iparms.em_record_sz_in_bits = tbl->result_bit_size;
2185 iparms.em_record_sz_in_bits = tmplen;
2187 rc = tf_insert_em_entry(tfp, &iparms);
2189 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
2193 /* Mark action process */
2194 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
2195 tbl->resource_type == TF_MEM_EXTERNAL)
2196 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
2197 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
2198 tbl->resource_type == TF_MEM_INTERNAL)
2199 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
2201 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
2205 /* Link the EM resource to the flow in the flow db */
2206 memset(&fid_parms, 0, sizeof(fid_parms));
2207 fid_parms.direction = tbl->direction;
2208 fid_parms.resource_func = tbl->resource_func;
2209 fid_parms.resource_type = tbl->resource_type;
2210 fid_parms.critical_resource = tbl->critical_resource;
2211 fid_parms.resource_hndl = iparms.flow_handle;
2213 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2215 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
2217 /* Need to free the identifier, so goto error */
2223 free_parms.dir = iparms.dir;
2224 free_parms.mem = iparms.mem;
2225 free_parms.tbl_scope_id = iparms.tbl_scope_id;
2226 free_parms.flow_handle = iparms.flow_handle;
2228 trc = tf_delete_em_entry(tfp, &free_parms);
2230 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
2236 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2237 struct bnxt_ulp_mapper_tbl_info *tbl)
2239 struct ulp_flow_db_res_params fid_parms;
2240 struct ulp_blob data;
2241 uint64_t regval = 0;
2244 int32_t rc = 0, trc = 0;
2245 struct tf_alloc_tbl_entry_parms aparms = { 0 };
2246 struct tf_set_tbl_entry_parms sparms = { 0 };
2247 struct tf_get_tbl_entry_parms gparms = { 0 };
2248 struct tf_free_tbl_entry_parms free_parms = { 0 };
2249 uint32_t tbl_scope_id;
2251 struct bnxt_ulp_glb_resource_info glb_res = { 0 };
2255 bool global = false;
2256 uint64_t act_rec_size;
2257 bool shared = false;
2259 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2260 /* use the max size if encap is enabled */
2261 if (tbl->encap_num_fields)
2262 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
2264 bit_size = tbl->result_bit_size;
2266 /* Initialize the blob data */
2267 if (!ulp_blob_init(&data, bit_size,
2268 parms->device_params->byte_order)) {
2269 BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
2273 /* Get the scope id first */
2274 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
2276 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2280 switch (tbl->tbl_opcode) {
2281 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
2284 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
2286 * Build the entry, alloc an index, write the table, and store
2287 * the data in the regfile.
2292 case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
2294 * get the index to write to from the regfile and then write
2297 if (!ulp_regfile_read(parms->regfile,
2301 "Failed to get tbl idx from regfile[%d].\n",
2305 index = tfp_be_to_cpu_64(regval);
2306 /* For external, we need to reverse shift */
2307 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2308 index = TF_ACT_REC_PTR_2_OFFSET(index);
2312 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
2314 * Build the entry, alloc an index, write the table, and store
2315 * the data in the global regfile.
2320 glb_res.direction = tbl->direction;
2321 glb_res.resource_func = tbl->resource_func;
2322 glb_res.resource_type = tbl->resource_type;
2323 glb_res.glb_regfile_index = tbl->tbl_operand;
2325 case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
2326 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2327 BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
2331 * get the index to write to from the global regfile and then
2334 if (ulp_mapper_glb_resource_read(parms->mapper_data,
2337 ®val, &shared)) {
2339 "Failed to get tbl idx from Glb RF[%d].\n",
2343 index = tfp_be_to_cpu_64(regval);
2344 /* For external, we need to reverse shift */
2345 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2346 index = TF_ACT_REC_PTR_2_OFFSET(index);
2349 case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
2351 * The read is different from the rest and can be handled here
2352 * instead of trying to use common code. Simply read the table
2353 * with the index from the regfile, scan and store the
2354 * identifiers, and return.
2356 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2357 /* Not currently supporting with EXT */
2359 "Ext Table Read Opcode not supported.\n");
2362 if (!ulp_regfile_read(parms->regfile,
2363 tbl->tbl_operand, ®val)) {
2365 "Failed to get tbl idx from regfile[%d]\n",
2369 index = tfp_be_to_cpu_64(regval);
2370 gparms.dir = tbl->direction;
2371 gparms.type = tbl->resource_type;
2372 gparms.data = ulp_blob_data_get(&data, &tmplen);
2373 gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tbl->result_bit_size);
2375 rc = tf_get_tbl_entry(tfp, &gparms);
2377 BNXT_TF_DBG(ERR, "Failed to read the tbl entry %d:%d\n",
2378 tbl->resource_type, index);
2382 * Scan the fields in the entry and push them into the regfile.
2384 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2386 gparms.data_sz_in_bytes,
2390 "Failed to get flds on tbl read rc=%d\n",
2396 BNXT_TF_DBG(ERR, "Invalid index table opcode %d\n",
2402 /* Get the result fields list */
2403 rc = ulp_mapper_tbl_result_build(parms,
2408 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2414 aparms.dir = tbl->direction;
2415 aparms.type = tbl->resource_type;
2416 aparms.tbl_scope_id = tbl_scope_id;
2418 /* All failures after the alloc succeeds require a free */
2419 rc = tf_alloc_tbl_entry(tfp, &aparms);
2421 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2422 tf_tbl_type_2_str(tbl->resource_type),
2423 tf_dir_2_str(tbl->direction), rc);
2429 * Store the index in the regfile since we either allocated it
2432 * Calculate the idx for the result record, for external EM the
2433 * offset needs to be shifted accordingly.
2434 * If external non-inline table types are used then need to
2435 * revisit this logic.
2437 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2438 regval = TF_ACT_REC_OFFSET_2_PTR(index);
2441 regval = tfp_cpu_to_be_64(regval);
2445 * Shared resources are never allocated through this
2446 * method, so the shared flag is always false.
2448 rc = ulp_mapper_glb_resource_write(parms->mapper_data,
2452 rc = ulp_regfile_write(parms->regfile,
2453 tbl->tbl_operand, regval);
2457 "Failed to write %s regfile[%d] rc=%d\n",
2458 (global) ? "global" : "reg",
2459 tbl->tbl_operand, rc);
2465 sparms.dir = tbl->direction;
2466 sparms.type = tbl->resource_type;
2467 sparms.data = ulp_blob_data_get(&data, &tmplen);
2468 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2470 sparms.tbl_scope_id = tbl_scope_id;
2472 tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
2473 rc = tf_set_tbl_entry(tfp, &sparms);
2476 "Index table[%s][%s][%x] write fail rc=%d\n",
2477 tf_tbl_type_2_str(sparms.type),
2478 tf_dir_2_str(sparms.dir),
2483 /* Calculate action record size */
2484 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2485 act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
2487 if (ulp_regfile_write(parms->regfile,
2488 BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
2489 tfp_cpu_to_be_64(act_rec_size)))
2491 "Failed write the act rec size\n");
2495 /* Link the resource to the flow in the flow db */
2496 memset(&fid_parms, 0, sizeof(fid_parms));
2497 fid_parms.direction = tbl->direction;
2498 fid_parms.resource_func = tbl->resource_func;
2499 fid_parms.resource_type = tbl->resource_type;
2500 fid_parms.resource_sub_type = tbl->resource_sub_type;
2501 fid_parms.resource_hndl = index;
2502 fid_parms.critical_resource = tbl->critical_resource;
2503 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2505 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2507 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2512 /* Perform the VF rep action */
2513 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2515 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2520 /* Shared resources are not freed */
2524 * Free the allocated resource since we failed to either
2525 * write to the entry or link the flow
2527 free_parms.dir = tbl->direction;
2528 free_parms.type = tbl->resource_type;
2529 free_parms.idx = index;
2530 free_parms.tbl_scope_id = tbl_scope_id;
2532 trc = tf_free_tbl_entry(tfp, &free_parms);
2534 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2540 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2541 struct bnxt_ulp_mapper_tbl_info *tbl)
2543 struct ulp_blob data, res_blob;
2547 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2548 struct tf_get_if_tbl_entry_parms get_parms = { 0 };
2550 enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
2553 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2554 /* Initialize the blob data */
2555 if (!ulp_blob_init(&data, tbl->result_bit_size,
2556 parms->device_params->byte_order)) {
2557 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2561 /* create the result blob */
2562 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
2564 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2568 /* Get the index details */
2570 case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
2571 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2573 case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
2574 if (!ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx)) {
2575 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
2579 idx = tfp_be_to_cpu_64(idx);
2581 case BNXT_ULP_IF_TBL_OPC_WR_CONST:
2582 idx = tbl->tbl_operand;
2584 case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
2585 /* Initialize the result blob */
2586 if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
2587 parms->device_params->byte_order)) {
2588 BNXT_TF_DBG(ERR, "Failed initial result blob\n");
2592 /* read the interface table */
2593 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2594 res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
2595 get_parms.dir = tbl->direction;
2596 get_parms.type = tbl->resource_type;
2597 get_parms.idx = idx;
2598 get_parms.data = ulp_blob_data_get(&res_blob, &tmplen);
2599 get_parms.data_sz_in_bytes = res_size;
2601 rc = tf_get_if_tbl_entry(tfp, &get_parms);
2603 BNXT_TF_DBG(ERR, "Get table[%d][%s][%x] failed rc=%d\n",
2605 tf_dir_2_str(get_parms.dir),
2609 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2612 res_blob.byte_order);
2614 BNXT_TF_DBG(ERR, "Scan and extract failed rc=%d\n", rc);
2616 case BNXT_ULP_IF_TBL_OPC_NOT_USED:
2617 return rc; /* skip it */
2619 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2623 /* Perform the tf table set by filling the set params */
2624 iftbl_params.dir = tbl->direction;
2625 iftbl_params.type = tbl->resource_type;
2626 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2627 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2628 iftbl_params.idx = idx;
2630 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2632 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2633 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2634 tf_dir_2_str(iftbl_params.dir),
2635 iftbl_params.idx, rc);
2640 * TBD: Need to look at the need to store idx in flow db for restore
2641 * the table to its original state on deletion of this entry.
2647 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2648 struct bnxt_ulp_mapper_tbl_info *tbl)
2650 struct ulp_mapper_gen_tbl_list *gen_tbl_list;
2651 struct bnxt_ulp_mapper_key_info *kflds;
2652 struct ulp_flow_db_res_params fid_parms;
2653 struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
2654 struct ulp_gen_hash_entry_params hash_entry;
2655 uint16_t tmplen = 0;
2656 struct ulp_blob key, data;
2659 uint32_t i, num_kflds = 0, key_index = 0;
2660 uint32_t gen_tbl_miss = 1, fdb_write = 0;
2664 /* Get the key fields list and build the key. */
2665 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2666 if (!kflds || !num_kflds) {
2667 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2671 if (!ulp_blob_init(&key, tbl->key_bit_size,
2672 parms->device_params->byte_order)) {
2673 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2676 for (i = 0; i < num_kflds; i++) {
2678 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2679 &kflds[i].field_info_spec,
2680 &key, 1, "Gen Tbl Key");
2683 "Failed to create key for Gen tbl rc=%d\n",
2689 /* Calculate the table index for the generic table*/
2690 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2693 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2694 tbl->resource_sub_type, tbl->direction);
2698 /* The_key is a byte array convert it to a search index */
2699 cache_key = ulp_blob_data_get(&key, &tmplen);
2700 /* get the generic table */
2701 gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
2703 /* Check if generic hash table */
2704 if (gen_tbl_list->hash_tbl) {
2705 if (tbl->gen_tbl_lkup_type !=
2706 BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
2707 BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
2708 gen_tbl_list->gen_tbl_name);
2711 hash_entry.key_data = cache_key;
2712 hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
2713 rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
2716 BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
2717 gen_tbl_list->gen_tbl_name);
2720 if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
2721 key_index = hash_entry.key_idx;
2722 /* Get the generic table entry */
2723 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
2727 /* store the hash index in the fdb */
2728 key_index = hash_entry.hash_index;
2731 /* convert key to index directly */
2732 if (ULP_BITS_2_BYTE(tmplen) > (int32_t)sizeof(key_index)) {
2733 BNXT_TF_DBG(ERR, "%s: keysize is bigger then 4 bytes\n",
2734 gen_tbl_list->gen_tbl_name);
2737 memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
2738 /* Get the generic table entry */
2739 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
2743 switch (tbl->tbl_opcode) {
2744 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2745 if (gen_tbl_list->hash_tbl) {
2746 if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
2747 break; /* nothing to be done , no entry */
2750 /* check the reference count */
2751 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2753 /* Scan ident list and create the result blob*/
2754 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2760 "Failed to scan ident list\n");
2763 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2764 /* increment the reference count */
2765 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2773 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
2774 if (gen_tbl_list->hash_tbl) {
2775 rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
2780 /* store the hash index in the fdb */
2781 key_index = hash_entry.hash_index;
2783 /* check the reference count */
2784 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2785 /* a hit then error */
2786 BNXT_TF_DBG(ERR, "generic entry already present\n");
2787 return -EINVAL; /* success */
2790 /* Initialize the blob data */
2791 if (!ulp_blob_init(&data, tbl->result_bit_size,
2792 gen_tbl_ent.byte_order)) {
2793 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2797 /* Get the result fields list */
2798 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2801 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2804 byte_data = ulp_blob_data_get(&data, &tmplen);
2805 rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
2807 ULP_BITS_2_BYTE(tmplen));
2809 BNXT_TF_DBG(ERR, "Failed to write generic table\n");
2813 /* increment the reference count */
2814 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2816 parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
2819 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
2823 /* Set the generic entry hit */
2824 rc = ulp_regfile_write(parms->regfile,
2825 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
2826 tfp_cpu_to_be_64(gen_tbl_miss));
2828 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2829 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
2833 /* add the entry to the flow database */
2835 memset(&fid_parms, 0, sizeof(fid_parms));
2836 fid_parms.direction = tbl->direction;
2837 fid_parms.resource_func = tbl->resource_func;
2838 fid_parms.resource_sub_type = tbl->resource_sub_type;
2839 fid_parms.resource_hndl = key_index;
2840 fid_parms.critical_resource = tbl->critical_resource;
2841 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2843 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2845 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
2851 ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2852 struct bnxt_ulp_mapper_tbl_info *tbl)
2856 /* process the fdb opcode for alloc push */
2857 if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
2858 rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
2860 BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
2868 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2869 struct bnxt_ulp_mapper_data *mapper_data)
2871 struct bnxt_ulp_glb_resource_info *glb_res;
2872 uint32_t num_glb_res_ids, idx, dev_id;
2876 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
2877 if (!glb_res || !num_glb_res_ids) {
2878 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2882 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2884 BNXT_TF_DBG(ERR, "Failed to get device id for glb init (%d)\n",
2889 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2891 BNXT_TF_DBG(ERR, "Failed to get app id for glb init (%d)\n",
2896 /* Iterate the global resources and process each one */
2897 for (idx = 0; idx < num_glb_res_ids; idx++) {
2898 if (dev_id != glb_res[idx].device_id ||
2899 glb_res[idx].app_id != app_id)
2901 switch (glb_res[idx].resource_func) {
2902 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2903 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
2907 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2908 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2913 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2914 glb_res[idx].resource_func);
2925 * Iterate over the shared resources assigned during tf_open_session and store
2926 * them in the global regfile with the shared flag.
2929 ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2930 struct bnxt_ulp_mapper_data *mapper_data)
2932 struct tf_get_shared_tbl_increment_parms iparms;
2933 struct bnxt_ulp_glb_resource_info *glb_res;
2934 struct tf_get_session_info_parms sparms;
2935 uint32_t num_entries, i, dev_id, res;
2936 struct tf_resource_info *res_info;
2944 memset(&sparms, 0, sizeof(sparms));
2945 glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
2946 if (!glb_res || !num_entries) {
2947 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2950 tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
2952 BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
2956 * Retrieve the resources that were assigned during the shared session
2959 rc = tf_get_session_info(tfp, &sparms);
2961 BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
2965 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2967 BNXT_TF_DBG(ERR, "Failed to get the app id in glb init (%d).\n",
2972 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2974 BNXT_TF_DBG(ERR, "Failed to get dev id for app glb init (%d)\n",
2979 /* Store all the app global resources */
2980 for (i = 0; i < num_entries; i++) {
2981 if (dev_id != glb_res[i].device_id ||
2982 app_id != glb_res[i].app_id)
2984 dir = glb_res[i].direction;
2985 res = glb_res[i].resource_type;
2988 switch (glb_res[i].resource_func) {
2989 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2990 res_info = &sparms.session_info.ident[dir].info[res];
2992 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2994 * Tables may have various strides for the allocations.
2997 memset(&iparms, 0, sizeof(iparms));
3000 rc = tf_get_shared_tbl_increment(tfp, &iparms);
3003 "Failed to get addend for %s[%s] rc=(%d)\n",
3004 tf_tbl_type_2_str(res),
3005 tf_dir_2_str(dir), rc);
3008 addend = iparms.increment_cnt;
3009 res_info = &sparms.session_info.tbl[dir].info[res];
3011 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3012 res_info = &sparms.session_info.tcam[dir].info[res];
3014 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3015 res_info = &sparms.session_info.em[dir].info[res];
3018 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
3019 glb_res[i].resource_func);
3022 regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
3023 res_info->start += addend;
3025 * All resources written to the global regfile are shared for
3028 rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
3038 * Common conditional opcode process routine that is used for both the template
3039 * rejection and table conditional execution.
3042 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
3043 enum bnxt_ulp_cond_opc opc,
3047 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
3053 case BNXT_ULP_COND_OPC_CF_IS_SET:
3054 if (operand < BNXT_ULP_CF_IDX_LAST) {
3055 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
3057 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3062 case BNXT_ULP_COND_OPC_CF_NOT_SET:
3063 if (operand < BNXT_ULP_CF_IDX_LAST) {
3064 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
3066 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3071 case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
3072 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3073 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3076 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3081 case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
3082 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3083 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3086 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3091 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
3092 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3093 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3096 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3101 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
3102 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3103 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3106 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3111 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
3112 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3114 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3118 *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3120 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
3121 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3123 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3127 *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3129 case BNXT_ULP_COND_OPC_RF_IS_SET:
3130 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3131 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3136 case BNXT_ULP_COND_OPC_RF_NOT_SET:
3137 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3138 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3143 case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
3144 if (parms->flow_pattern_id == operand) {
3145 BNXT_TF_DBG(ERR, "field pattern match failed %x\n",
3146 parms->flow_pattern_id);
3150 case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
3151 if (parms->act_pattern_id == operand) {
3152 BNXT_TF_DBG(ERR, "act pattern match failed %x\n",
3153 parms->act_pattern_id);
3157 case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
3158 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3159 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3162 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
3164 case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
3165 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3166 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3169 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
3172 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
3180 ulp_mapper_func_opr_compute(struct bnxt_ulp_mapper_parms *parms,
3182 enum bnxt_ulp_func_src func_src,
3191 case BNXT_ULP_FUNC_SRC_COMP_FIELD:
3192 if (func_opr >= BNXT_ULP_CF_IDX_LAST) {
3193 BNXT_TF_DBG(ERR, "invalid index %u\n", func_opr);
3196 *result = ULP_COMP_FLD_IDX_RD(parms, func_opr);
3198 case BNXT_ULP_FUNC_SRC_REGFILE:
3199 if (!ulp_regfile_read(parms->regfile, func_opr, ®val)) {
3200 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", func_opr);
3203 *result = tfp_be_to_cpu_64(regval);
3205 case BNXT_ULP_FUNC_SRC_GLB_REGFILE:
3206 if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
3207 func_opr, ®val, &shared)) {
3208 BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
3212 *result = tfp_be_to_cpu_64(regval);
3214 case BNXT_ULP_FUNC_SRC_CONST:
3218 BNXT_TF_DBG(ERR, "invalid src code %u\n", func_src);
3225 ulp_mapper_func_info_process(struct bnxt_ulp_mapper_parms *parms,
3226 struct bnxt_ulp_mapper_tbl_info *tbl)
3228 struct bnxt_ulp_mapper_func_info *func_info = &tbl->func_info;
3229 uint64_t res = 0, res1 = 0, res2 = 0;
3231 uint32_t process_src1 = 0, process_src2 = 0;
3233 /* determine which functional operands to compute */
3234 switch (func_info->func_opc) {
3235 case BNXT_ULP_FUNC_OPC_NOP:
3237 case BNXT_ULP_FUNC_OPC_EQ:
3238 case BNXT_ULP_FUNC_OPC_NE:
3239 case BNXT_ULP_FUNC_OPC_GE:
3240 case BNXT_ULP_FUNC_OPC_GT:
3241 case BNXT_ULP_FUNC_OPC_LE:
3242 case BNXT_ULP_FUNC_OPC_LT:
3246 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3254 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3255 func_info->func_src1,
3256 func_info->func_opr1, &res1);
3262 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3263 func_info->func_src2,
3264 func_info->func_opr2, &res2);
3269 /* perform the functional opcode operations */
3270 switch (func_info->func_opc) {
3271 case BNXT_ULP_FUNC_OPC_EQ:
3275 case BNXT_ULP_FUNC_OPC_NE:
3279 case BNXT_ULP_FUNC_OPC_GE:
3283 case BNXT_ULP_FUNC_OPC_GT:
3287 case BNXT_ULP_FUNC_OPC_LE:
3291 case BNXT_ULP_FUNC_OPC_LT:
3295 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3298 case BNXT_ULP_FUNC_OPC_RSS_CONFIG:
3299 /* apply the rss config using pmd method */
3300 return bnxt_rss_config_action_apply(parms);
3301 case BNXT_ULP_FUNC_OPC_GET_PARENT_MAC_ADDR:
3302 rc = bnxt_pmd_get_parent_mac_addr(parms, (uint8_t *)&res);
3305 res = tfp_be_to_cpu_64(res);
3308 BNXT_TF_DBG(ERR, "invalid func code %u\n", func_info->func_opc);
3311 if (ulp_regfile_write(parms->regfile, func_info->func_dst_opr,
3312 tfp_cpu_to_be_64(res))) {
3313 BNXT_TF_DBG(ERR, "Failed write the func_opc %u\n",
3314 func_info->func_dst_opr);
3323 * Processes a list of conditions and returns both a status and result of the
3324 * list. The status must be checked prior to verifying the result.
3326 * returns 0 for success, negative on failure
3327 * returns res = 1 for true, res = 0 for false.
3330 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
3331 enum bnxt_ulp_cond_list_opc list_opc,
3332 struct bnxt_ulp_mapper_cond_info *list,
3337 int32_t rc = 0, trc = 0;
3340 case BNXT_ULP_COND_LIST_OPC_AND:
3341 /* AND Defaults to true. */
3344 case BNXT_ULP_COND_LIST_OPC_OR:
3345 /* OR Defaults to false. */
3348 case BNXT_ULP_COND_LIST_OPC_TRUE:
3351 case BNXT_ULP_COND_LIST_OPC_FALSE:
3355 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
3361 for (i = 0; i < num; i++) {
3362 rc = ulp_mapper_cond_opc_process(parms,
3363 list[i].cond_opcode,
3364 list[i].cond_operand,
3369 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
3370 /* early return if result is ever zero */
3376 /* early return if result is ever non-zero */
3388 * Processes conflict resolution and returns both a status and result.
3389 * The status must be checked prior to verifying the result.
3391 * returns 0 for success, negative on failure
3392 * returns res = 1 for true, res = 0 for false.
3395 ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
3396 struct bnxt_ulp_mapper_tbl_info *tbl,
3404 switch (tbl->accept_opcode) {
3405 case BNXT_ULP_ACCEPT_OPC_ALWAYS:
3408 case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
3409 /* perform the signature validation*/
3410 if (tbl->resource_func ==
3411 BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
3412 /* Perform the check that generic table is hit or not */
3413 if (!ulp_regfile_read(parms->regfile,
3414 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3416 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3417 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3421 /* not a hit so no need to check flow sign*/
3426 /* compare the new flow signature against stored one */
3427 if (!ulp_regfile_read(parms->regfile,
3428 BNXT_ULP_RF_IDX_FLOW_SIG_ID,
3430 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3431 BNXT_ULP_RF_IDX_FLOW_SIG_ID);
3434 comp_sig = ULP_COMP_FLD_IDX_RD(parms,
3435 BNXT_ULP_CF_IDX_FLOW_SIG_ID);
3436 regval = tfp_be_to_cpu_64(regval);
3437 if (comp_sig == regval)
3440 BNXT_TF_DBG(ERR, "failed signature match 0x%016"
3441 PRIX64 ":%x\n", comp_sig, (uint32_t)regval);
3444 BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
3445 tbl->accept_opcode);
3452 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
3454 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
3455 enum bnxt_ulp_cond_list_opc cond_opc;
3456 struct bnxt_ulp_mapper_tbl_info *tbls;
3457 struct bnxt_ulp_mapper_tbl_info *tbl;
3458 uint32_t num_tbls, tbl_idx, num_cond_tbls;
3459 int32_t rc = -EINVAL, cond_rc = 0;
3460 int32_t cond_goto = 1;
3462 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
3466 * Process the reject list if exists, otherwise assume that the
3467 * template is allowed.
3469 if (cond_tbls && num_cond_tbls) {
3470 rc = ulp_mapper_cond_opc_list_process(parms,
3478 /* Reject the template if True */
3480 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
3481 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3487 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
3488 if (!tbls || !num_tbls) {
3489 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
3490 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3491 parms->dev_id, tid);
3495 for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
3496 tbl = &tbls[tbl_idx];
3497 cond_goto = tbl->execute_info.cond_true_goto;
3498 /* Process the conditional func code opcodes */
3499 if (ulp_mapper_func_info_process(parms, tbl)) {
3500 BNXT_TF_DBG(ERR, "Failed to process cond update\n");
3505 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
3508 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
3509 cond_tbls, num_cond_tbls,
3512 BNXT_TF_DBG(ERR, "Failed to proc cond opc list (%d)\n",
3516 /* Skip the table if False */
3518 cond_goto = tbl->execute_info.cond_false_goto;
3519 goto next_iteration;
3522 switch (tbl->resource_func) {
3523 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3524 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
3526 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3527 rc = ulp_mapper_em_tbl_process(parms, tbl);
3529 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3530 rc = ulp_mapper_index_tbl_process(parms, tbl);
3532 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
3533 rc = ulp_mapper_if_tbl_process(parms, tbl);
3535 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3536 rc = ulp_mapper_gen_tbl_process(parms, tbl);
3538 case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
3539 rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
3541 case BNXT_ULP_RESOURCE_FUNC_INVALID:
3545 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
3546 tbl->resource_func);
3552 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
3553 tbl->resource_func);
3557 /* perform the post table process */
3558 rc = ulp_mapper_conflict_resolution_process(parms, tbl,
3560 if (rc || !cond_rc) {
3561 BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
3566 if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
3567 BNXT_TF_DBG(ERR, "reject the flow\n");
3570 } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
3574 /* least significant 16 bits from reg_file index */
3575 rf_idx = (uint32_t)(cond_goto & 0xFFFF);
3576 if (!ulp_regfile_read(parms->regfile, rf_idx,
3578 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3583 cond_goto = (int32_t)regval;
3586 if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
3587 BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
3591 tbl_idx += cond_goto;
3596 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
3597 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3598 parms->dev_id, tid);
3603 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
3605 struct ulp_flow_db_res_params *res)
3611 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
3614 if (res->fdb_flags & ULP_FDB_FLAG_SHARED_SESSION)
3615 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_YES);
3617 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_NO);
3619 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
3623 switch (res->resource_func) {
3624 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3625 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
3627 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3628 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
3630 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3631 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
3633 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3634 rc = ulp_mapper_ident_free(ulp, tfp, res);
3636 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
3637 rc = ulp_mapper_mark_free(ulp, res);
3639 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
3640 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
3642 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
3643 rc = ulp_mapper_child_flow_free(ulp, fid, res);
3645 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3646 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
3656 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
3657 enum bnxt_ulp_fdb_type flow_type,
3660 struct ulp_flow_db_res_params res_parms = { 0 };
3664 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3669 * Set the critical resource on the first resource del, then iterate
3670 * while status is good
3672 if (flow_type != BNXT_ULP_FDB_TYPE_RID)
3673 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
3675 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
3679 * This is unexpected on the first call to resource del.
3680 * It likely means that the flow did not exist in the flow db.
3682 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
3683 flow_type, fid, rc);
3688 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
3691 * On fail, we still need to attempt to free the
3692 * remaining resources. Don't return
3695 "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
3696 "] failed rc=%d.\n",
3697 flow_type, fid, res_parms.resource_func,
3698 res_parms.resource_hndl, trc);
3700 /* All subsequent call require the non-critical_resource */
3701 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
3703 rc = ulp_flow_db_resource_del(ulp_ctx,
3709 /* Free the Flow ID since we've removed all resources */
3710 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
3716 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
3717 struct bnxt_ulp_mapper_data *mapper_data)
3719 struct bnxt_ulp_mapper_glb_resource_entry *ent;
3720 struct ulp_flow_db_res_params res;
3723 /* Iterate the global resources and process each one */
3724 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
3725 for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
3726 ent = &mapper_data->glb_res_tbl[dir][idx];
3727 if (ent->resource_func ==
3728 BNXT_ULP_RESOURCE_FUNC_INVALID ||
3731 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
3732 res.resource_func = ent->resource_func;
3733 res.direction = dir;
3734 res.resource_type = ent->resource_type;
3735 /*convert it from BE to cpu */
3737 tfp_be_to_cpu_64(ent->resource_hndl);
3738 ulp_mapper_resource_free(ulp_ctx, 0, &res);
3744 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
3745 enum bnxt_ulp_fdb_type flow_type,
3751 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3755 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
3759 /* Function to handle the mapping of the Flow to be compatible
3760 * with the underlying hardware.
3763 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
3764 struct bnxt_ulp_mapper_create_parms *cparms)
3766 struct bnxt_ulp_mapper_parms parms;
3767 struct ulp_regfile regfile;
3768 int32_t rc = 0, trc;
3770 if (!ulp_ctx || !cparms)
3773 /* Initialize the parms structure */
3774 memset(&parms, 0, sizeof(parms));
3775 parms.act_prop = cparms->act_prop;
3776 parms.act_bitmap = cparms->act;
3777 parms.hdr_bitmap = cparms->hdr_bitmap;
3778 parms.regfile = ®file;
3779 parms.hdr_field = cparms->hdr_field;
3780 parms.fld_bitmap = cparms->fld_bitmap;
3781 parms.comp_fld = cparms->comp_fld;
3782 parms.ulp_ctx = ulp_ctx;
3783 parms.act_tid = cparms->act_tid;
3784 parms.class_tid = cparms->class_tid;
3785 parms.flow_type = cparms->flow_type;
3786 parms.parent_flow = cparms->parent_flow;
3787 parms.parent_fid = cparms->parent_fid;
3788 parms.fid = cparms->flow_id;
3789 parms.tun_idx = cparms->tun_idx;
3790 parms.app_priority = cparms->app_priority;
3791 parms.flow_pattern_id = cparms->flow_pattern_id;
3792 parms.act_pattern_id = cparms->act_pattern_id;
3793 parms.app_id = cparms->app_id;
3794 parms.port_id = cparms->port_id;
3796 /* Get the device id from the ulp context */
3797 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
3798 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
3802 /* Get the device params, it will be used in later processing */
3803 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
3804 if (!parms.device_params) {
3805 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
3811 * Get the mapper data for dynamic mapper data such as default
3814 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
3815 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3816 if (!parms.mapper_data) {
3817 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
3821 /* initialize the registry file for further processing */
3822 if (!ulp_regfile_init(parms.regfile)) {
3823 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
3827 /* Process the action template list from the selected action table*/
3828 if (parms.act_tid) {
3829 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
3830 /* Process the action template tables */
3831 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
3834 cparms->shared_hndl = parms.shared_hndl;
3837 if (parms.class_tid) {
3838 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
3840 /* Process the class template tables.*/
3841 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
3846 /* setup the parent-child details */
3847 if (parms.parent_flow) {
3848 /* create a parent flow details */
3849 rc = ulp_flow_db_parent_flow_create(&parms);
3852 } else if (parms.parent_fid) {
3853 /* create a child flow details */
3854 rc = ulp_flow_db_child_flow_create(&parms);
3862 /* Free all resources that were allocated during flow creation */
3863 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
3866 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
3872 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
3874 struct bnxt_ulp_mapper_data *data;
3881 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
3885 data = rte_zmalloc("ulp_mapper_data",
3886 sizeof(struct bnxt_ulp_mapper_data), 0);
3888 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
3892 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
3893 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
3894 /* Don't call deinit since the prof_func wasn't allocated. */
3899 /* Allocate the global resource ids */
3900 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
3902 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
3907 * Only initialize the app global resources if a shared session was
3910 if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
3911 rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
3913 BNXT_TF_DBG(ERR, "Failed to init app glb resources\n");
3918 /* Allocate the generic table list */
3919 rc = ulp_mapper_generic_tbl_list_init(data);
3921 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
3927 /* Ignore the return code in favor of returning the original error. */
3928 ulp_mapper_deinit(ulp_ctx);
3933 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
3935 struct bnxt_ulp_mapper_data *data;
3940 "Failed to acquire ulp context, so data may not be released.\n");
3944 data = (struct bnxt_ulp_mapper_data *)
3945 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3947 /* Go ahead and return since there is no allocated data. */
3948 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
3952 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
3954 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
3955 /* Free the mapper data regardless of errors. */
3956 goto free_mapper_data;
3959 /* Free the global resource info table entries */
3960 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
3963 /* Free the generic table */
3964 (void)ulp_mapper_generic_tbl_list_deinit(data);
3967 /* Reset the data pointer within the ulp_ctx. */
3968 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);