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.search_enable = 0;
193 aparms.tbl_scope_id = tbl_scope_id;
195 /* Allocate the index tbl using tf api */
196 rc = tf_alloc_tbl_entry(tfp, &aparms);
198 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
199 tf_dir_2_str(aparms.dir), aparms.type);
203 /* entries are stored as big-endian format */
204 regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
206 * write to the mapper global resource
207 * Shared resources are never allocated through this method, so the
208 * shared flag is always false.
210 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval, false);
212 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
213 /* Free the identifier when update failed */
214 free_parms.dir = aparms.dir;
215 free_parms.type = aparms.type;
216 free_parms.idx = aparms.idx;
217 tf_free_tbl_entry(tfp, &free_parms);
224 ulp_mapper_glb_field_tbl_get(struct bnxt_ulp_mapper_parms *parms,
230 t_idx = parms->app_id << (BNXT_ULP_APP_ID_SHIFT +
231 BNXT_ULP_HDR_SIG_ID_SHIFT +
232 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
233 t_idx += parms->class_tid << (BNXT_ULP_HDR_SIG_ID_SHIFT +
234 BNXT_ULP_GLB_FIELD_TBL_SHIFT);
235 t_idx += ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_HDR_SIG_ID) <<
236 BNXT_ULP_GLB_FIELD_TBL_SHIFT;
239 if (t_idx >= BNXT_ULP_GLB_FIELD_TBL_SIZE) {
240 BNXT_TF_DBG(ERR, "Invalid hdr field index %x:%x:%x\n",
241 parms->class_tid, t_idx, operand);
243 return -EINVAL; /* error */
245 *val = ulp_glb_field_tbl[t_idx];
250 * Get the size of the action property for a given index.
252 * idx [in] The index for the action property
254 * returns the size of the action property.
257 ulp_mapper_act_prop_size_get(uint32_t idx)
259 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
261 return ulp_act_prop_map_table[idx];
264 static struct bnxt_ulp_mapper_cond_info *
265 ulp_mapper_tmpl_reject_list_get(struct bnxt_ulp_mapper_parms *mparms,
268 enum bnxt_ulp_cond_list_opc *opc)
271 const struct bnxt_ulp_template_device_tbls *dev_tbls;
273 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
274 *num_tbls = dev_tbls->tmpl_list[tid].reject_info.cond_nums;
275 *opc = dev_tbls->tmpl_list[tid].reject_info.cond_list_opcode;
276 idx = dev_tbls->tmpl_list[tid].reject_info.cond_start_idx;
278 return &dev_tbls->cond_list[idx];
281 static struct bnxt_ulp_mapper_cond_info *
282 ulp_mapper_tbl_execute_list_get(struct bnxt_ulp_mapper_parms *mparms,
283 struct bnxt_ulp_mapper_tbl_info *tbl,
285 enum bnxt_ulp_cond_list_opc *opc)
288 const struct bnxt_ulp_template_device_tbls *dev_tbls;
290 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
291 *num_tbls = tbl->execute_info.cond_nums;
292 *opc = tbl->execute_info.cond_list_opcode;
293 idx = tbl->execute_info.cond_start_idx;
295 return &dev_tbls->cond_list[idx];
299 * Get a list of classifier tables that implement the flow
300 * Gets a device dependent list of tables that implement the class template id
302 * mparms [in] The mappers parms with data related to the flow.
304 * tid [in] The template id that matches the flow
306 * num_tbls [out] The number of classifier tables in the returned array
308 * returns An array of classifier tables to implement the flow, or NULL on
311 static struct bnxt_ulp_mapper_tbl_info *
312 ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
317 const struct bnxt_ulp_template_device_tbls *dev_tbls;
319 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
321 idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
322 *num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
324 return &dev_tbls->tbl_list[idx];
328 * Get the list of key fields that implement the flow.
330 * mparms [in] The mapper parms with information about the flow
332 * tbl [in] A single table instance to get the key fields from
334 * num_flds [out] The number of key fields in the returned array
336 * Returns array of Key fields, or NULL on error.
338 static struct bnxt_ulp_mapper_key_info *
339 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
340 struct bnxt_ulp_mapper_tbl_info *tbl,
344 const struct bnxt_ulp_template_device_tbls *dev_tbls;
346 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
347 if (!dev_tbls->key_info_list) {
352 idx = tbl->key_start_idx;
353 *num_flds = tbl->key_num_fields;
355 return &dev_tbls->key_info_list[idx];
359 * Get the list of data fields that implement the flow.
361 * mparms [in] The mapper parms with information about the flow
363 * tbl [in] A single table instance to get the data fields from
365 * num_flds [out] The number of data fields in the returned array.
367 * num_encap_flds [out] The number of encap fields in the returned array.
369 * Returns array of data fields, or NULL on error.
371 static struct bnxt_ulp_mapper_field_info *
372 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
373 struct bnxt_ulp_mapper_tbl_info *tbl,
375 uint32_t *num_encap_flds)
378 const struct bnxt_ulp_template_device_tbls *dev_tbls;
380 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
381 if (!dev_tbls->result_field_list) {
387 idx = tbl->result_start_idx;
388 *num_flds = tbl->result_num_fields;
389 *num_encap_flds = tbl->encap_num_fields;
391 return &dev_tbls->result_field_list[idx];
395 * Get the list of ident fields that implement the flow
397 * tbl [in] A single table instance to get the ident fields from
399 * num_flds [out] The number of ident fields in the returned array
401 * returns array of ident fields, or NULL on error
403 static struct bnxt_ulp_mapper_ident_info *
404 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
405 struct bnxt_ulp_mapper_tbl_info *tbl,
409 const struct bnxt_ulp_template_device_tbls *dev_tbls;
411 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
412 if (!dev_tbls->ident_list) {
417 idx = tbl->ident_start_idx;
418 *num_flds = tbl->ident_nums;
420 return &dev_tbls->ident_list[idx];
423 static inline int32_t
424 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp,
426 struct ulp_flow_db_res_params *res)
428 struct tf_free_tcam_entry_parms fparms = {
429 .dir = res->direction,
430 .tcam_tbl_type = res->resource_type,
431 .idx = (uint16_t)res->resource_hndl
434 /* If HA is enabled, we may have to remap the TF Type */
435 if (bnxt_ulp_cntxt_ha_enabled(ulp)) {
436 enum ulp_ha_mgr_region region;
439 switch (res->resource_type) {
440 case TF_TCAM_TBL_TYPE_WC_TCAM_HIGH:
441 case TF_TCAM_TBL_TYPE_WC_TCAM_LOW:
442 rc = ulp_ha_mgr_region_get(ulp, ®ion);
444 /* Log this, but assume region is correct */
446 "Unable to get HA region (%d)\n",
449 fparms.tcam_tbl_type =
450 (region == ULP_HA_REGION_LOW) ?
451 TF_TCAM_TBL_TYPE_WC_TCAM_LOW :
452 TF_TCAM_TBL_TYPE_WC_TCAM_HIGH;
458 return tf_free_tcam_entry(tfp, &fparms);
461 static inline int32_t
462 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
464 struct ulp_flow_db_res_params *res)
466 struct tf_free_tbl_entry_parms fparms = {
467 .dir = res->direction,
468 .type = res->resource_type,
469 .idx = (uint32_t)res->resource_hndl
473 * Just get the table scope, it will be ignored if not necessary
474 * by the tf_free_tbl_entry
476 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
478 return tf_free_tbl_entry(tfp, &fparms);
481 static inline int32_t
482 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
484 struct ulp_flow_db_res_params *res)
486 struct tf_delete_em_entry_parms fparms = { 0 };
489 fparms.dir = res->direction;
490 fparms.flow_handle = res->resource_hndl;
492 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
494 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
498 return tf_delete_em_entry(tfp, &fparms);
501 static inline int32_t
502 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
504 struct ulp_flow_db_res_params *res)
506 struct tf_free_identifier_parms fparms = {
507 .dir = res->direction,
508 .ident_type = res->resource_type,
509 .id = (uint16_t)res->resource_hndl
512 return tf_free_identifier(tfp, &fparms);
515 static inline int32_t
516 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
517 struct ulp_flow_db_res_params *res)
519 return ulp_mark_db_mark_del(ulp,
524 static inline int32_t
525 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
527 struct ulp_flow_db_res_params *res)
529 uint32_t idx, child_fid = 0, parent_idx;
530 struct bnxt_ulp_flow_db *flow_db;
532 parent_idx = (uint32_t)res->resource_hndl;
534 /* check the validity of the parent fid */
535 if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
537 BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
541 /* Clear all the child flows parent index */
542 flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
543 while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
545 /* update the child flows resource handle */
546 if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
548 BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
554 /* free the parent entry in the parent table flow */
555 if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
556 BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
562 static inline int32_t
563 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
565 struct ulp_flow_db_res_params *res)
569 parent_fid = (uint32_t)res->resource_hndl;
571 return 0; /* Already freed - orphan child*/
573 /* reset the child flow bitset*/
574 if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
575 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
576 parent_fid, child_fid);
583 * Process the flow database opcode alloc action.
584 * returns 0 on success
587 ulp_mapper_fdb_opc_alloc_rid(struct bnxt_ulp_mapper_parms *parms,
588 struct bnxt_ulp_mapper_tbl_info *tbl)
594 /* allocate a new fid */
595 rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
596 BNXT_ULP_FDB_TYPE_RID,
600 "Unable to allocate flow table entry\n");
603 /* Store the allocated fid in regfile*/
605 rc = ulp_regfile_write(parms->regfile, tbl->fdb_operand,
606 tfp_cpu_to_be_64(val64));
608 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
610 ulp_flow_db_fid_free(parms->ulp_ctx,
611 BNXT_ULP_FDB_TYPE_RID, rid);
618 * Process the flow database opcode action.
619 * returns 0 on success.
622 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
623 struct bnxt_ulp_mapper_tbl_info *tbl,
624 struct ulp_flow_db_res_params *fid_parms)
628 enum bnxt_ulp_fdb_type flow_type;
631 switch (tbl->fdb_opcode) {
632 case BNXT_ULP_FDB_OPC_PUSH_FID:
633 push_fid = parms->fid;
634 flow_type = parms->flow_type;
636 case BNXT_ULP_FDB_OPC_PUSH_RID_REGFILE:
637 /* get the fid from the regfile */
638 rc = ulp_regfile_read(parms->regfile, tbl->fdb_operand,
641 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
645 /* Use the extracted fid to update the flow resource */
646 push_fid = (uint32_t)tfp_be_to_cpu_64(val64);
647 flow_type = BNXT_ULP_FDB_TYPE_RID;
650 return rc; /* Nothing to be done */
653 /* Add the resource to the flow database */
654 rc = ulp_flow_db_resource_add(parms->ulp_ctx, flow_type,
655 push_fid, fid_parms);
657 BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
663 * Process the flow database opcode action.
664 * returns 0 on success.
667 ulp_mapper_priority_opc_process(struct bnxt_ulp_mapper_parms *parms,
668 struct bnxt_ulp_mapper_tbl_info *tbl,
673 switch (tbl->pri_opcode) {
674 case BNXT_ULP_PRI_OPC_NOT_USED:
677 case BNXT_ULP_PRI_OPC_CONST:
678 *priority = tbl->pri_operand;
680 case BNXT_ULP_PRI_OPC_APP_PRI:
681 *priority = parms->app_priority;
684 BNXT_TF_DBG(ERR, "Priority opcode not supported %d\n",
693 * Process the identifier list in the given table.
694 * Extract the ident from the table entry and
695 * write it to the reg file.
696 * returns 0 on success.
699 ulp_mapper_tbl_ident_scan_ext(struct bnxt_ulp_mapper_parms *parms,
700 struct bnxt_ulp_mapper_tbl_info *tbl,
702 uint32_t byte_data_size,
703 enum bnxt_ulp_byte_order byte_order)
705 struct bnxt_ulp_mapper_ident_info *idents;
706 uint32_t i, num_idents = 0;
709 /* validate the null arguments */
711 BNXT_TF_DBG(ERR, "invalid argument\n");
715 /* Get the ident list and process each one */
716 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
718 for (i = 0; i < num_idents; i++) {
719 /* check the size of the buffer for validation */
720 if ((idents[i].ident_bit_pos + idents[i].ident_bit_size) >
721 ULP_BYTE_2_BITS(byte_data_size) ||
722 idents[i].ident_bit_size > ULP_BYTE_2_BITS(sizeof(val64))) {
723 BNXT_TF_DBG(ERR, "invalid offset or length %x:%x:%x\n",
724 idents[i].ident_bit_pos,
725 idents[i].ident_bit_size,
730 if (byte_order == BNXT_ULP_BYTE_ORDER_LE)
731 ulp_bs_pull_lsb(byte_data, (uint8_t *)&val64,
733 idents[i].ident_bit_pos,
734 idents[i].ident_bit_size);
736 ulp_bs_pull_msb(byte_data, (uint8_t *)&val64,
737 idents[i].ident_bit_pos,
738 idents[i].ident_bit_size);
740 /* Write it to the regfile, val64 is already in big-endian*/
741 if (ulp_regfile_write(parms->regfile,
742 idents[i].regfile_idx, val64)) {
743 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
744 idents[i].regfile_idx);
752 * Process the identifier instruction and either store it in the flow database
753 * or return it in the val (if not NULL) on success. If val is NULL, the
754 * identifier is to be stored in the flow database.
757 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
758 struct bnxt_ulp_mapper_tbl_info *tbl,
759 struct bnxt_ulp_mapper_ident_info *ident,
762 struct ulp_flow_db_res_params fid_parms;
765 struct tf_alloc_identifier_parms iparms = { 0 };
766 struct tf_free_identifier_parms free_parms = { 0 };
770 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
772 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
776 idx = ident->regfile_idx;
778 iparms.ident_type = ident->ident_type;
779 iparms.dir = tbl->direction;
781 rc = tf_alloc_identifier(tfp, &iparms);
783 BNXT_TF_DBG(ERR, "Alloc ident %s:%s failed.\n",
784 tf_dir_2_str(iparms.dir),
785 tf_ident_2_str(iparms.ident_type));
789 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
790 if (ulp_regfile_write(parms->regfile, idx, id)) {
791 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
793 /* Need to free the identifier, so goto error */
797 /* Link the resource to the flow in the flow db */
799 memset(&fid_parms, 0, sizeof(fid_parms));
800 fid_parms.direction = tbl->direction;
801 fid_parms.resource_func = ident->resource_func;
802 fid_parms.resource_type = ident->ident_type;
803 fid_parms.resource_hndl = iparms.id;
804 fid_parms.critical_resource = tbl->critical_resource;
805 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
807 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
809 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
811 /* Need to free the identifier, so goto error */
820 /* Need to free the identifier */
821 free_parms.dir = tbl->direction;
822 free_parms.ident_type = ident->ident_type;
823 free_parms.id = iparms.id;
825 (void)tf_free_identifier(tfp, &free_parms);
827 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
829 tf_dir_2_str(tbl->direction));
834 * Process the identifier instruction and extract it from result blob.
835 * Increment the identifier reference count and store it in the flow database.
838 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
839 struct bnxt_ulp_mapper_tbl_info *tbl,
840 struct bnxt_ulp_mapper_ident_info *ident,
841 struct ulp_blob *res_blob)
843 struct ulp_flow_db_res_params fid_parms;
846 struct tf_search_identifier_parms sparms = { 0 };
847 struct tf_free_identifier_parms free_parms = { 0 };
851 /* Get the tfp from ulp context */
852 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
854 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
858 /* Extract the index from the result blob */
859 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
860 ident->ident_bit_pos, ident->ident_bit_size);
862 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
866 /* populate the search params and search identifier shadow table */
867 sparms.ident_type = ident->ident_type;
868 sparms.dir = tbl->direction;
869 /* convert the idx into cpu format */
870 sparms.search_id = tfp_be_to_cpu_32(idx);
872 /* Search identifier also increase the reference count */
873 rc = tf_search_identifier(tfp, &sparms);
875 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
876 tf_dir_2_str(sparms.dir),
877 tf_ident_2_str(sparms.ident_type),
882 /* Write it to the regfile */
883 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
884 if (ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
885 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
887 /* Need to free the identifier, so goto error */
891 /* Link the resource to the flow in the flow db */
892 memset(&fid_parms, 0, sizeof(fid_parms));
893 fid_parms.direction = tbl->direction;
894 fid_parms.resource_func = ident->resource_func;
895 fid_parms.resource_type = ident->ident_type;
896 fid_parms.resource_hndl = sparms.search_id;
897 fid_parms.critical_resource = tbl->critical_resource;
898 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
900 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
902 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
904 /* Need to free the identifier, so goto error */
911 /* Need to free the identifier */
912 free_parms.dir = tbl->direction;
913 free_parms.ident_type = ident->ident_type;
914 free_parms.id = sparms.search_id;
915 (void)tf_free_identifier(tfp, &free_parms);
916 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
918 tf_dir_2_str(tbl->direction), sparms.search_id);
923 ulp_mapper_field_port_db_process(struct bnxt_ulp_mapper_parms *parms,
928 enum bnxt_ulp_port_table port_data = val16;
931 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_MAC:
932 if (ulp_port_db_parent_mac_addr_get(parms->ulp_ctx, port_id,
934 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
938 case BNXT_ULP_PORT_TABLE_DRV_FUNC_MAC:
939 if (ulp_port_db_drv_mac_addr_get(parms->ulp_ctx, port_id,
941 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
945 case BNXT_ULP_PORT_TABLE_DRV_FUNC_PARENT_VNIC:
946 if (ulp_port_db_parent_vnic_get(parms->ulp_ctx, port_id,
948 BNXT_TF_DBG(ERR, "Invalid port id %u\n", port_id);
953 BNXT_TF_DBG(ERR, "Invalid port_data %d\n", port_data);
960 ulp_mapper_field_src_process(struct bnxt_ulp_mapper_parms *parms,
961 enum bnxt_ulp_field_src field_src,
970 struct bnxt_ulp_mapper_data *m;
972 uint32_t port_id, val_size, field_size;
973 uint16_t idx, size_idx, offset;
974 uint32_t bytelen = ULP_BITS_2_BYTE(bitlen);
981 /* Perform the action */
983 case BNXT_ULP_FIELD_SRC_ZERO:
984 *val = mapper_fld_zeros;
986 case BNXT_ULP_FIELD_SRC_CONST:
989 case BNXT_ULP_FIELD_SRC_ONES:
990 *val = mapper_fld_ones;
993 case BNXT_ULP_FIELD_SRC_CF:
994 if (!ulp_operand_read(field_opr,
995 (uint8_t *)&idx, sizeof(uint16_t))) {
996 BNXT_TF_DBG(ERR, "CF operand read failed\n");
999 idx = tfp_be_to_cpu_16(idx);
1000 if (idx >= BNXT_ULP_CF_IDX_LAST || bytelen > sizeof(uint64_t)) {
1001 BNXT_TF_DBG(ERR, "comp field [%d] read oob %d\n", idx,
1005 buffer = (uint8_t *)&parms->comp_fld[idx];
1006 *val = &buffer[sizeof(uint64_t) - bytelen];
1007 *value = ULP_COMP_FLD_IDX_RD(parms, idx);
1009 case BNXT_ULP_FIELD_SRC_RF:
1010 if (!ulp_operand_read(field_opr,
1011 (uint8_t *)&idx, sizeof(uint16_t))) {
1012 BNXT_TF_DBG(ERR, "RF operand read failed\n");
1016 idx = tfp_be_to_cpu_16(idx);
1017 /* Uninitialized regfile entries return 0 */
1018 if (!ulp_regfile_read(parms->regfile, idx, &lregval) ||
1019 sizeof(uint64_t) < bytelen) {
1020 BNXT_TF_DBG(ERR, "regfile[%d] read oob %u\n", idx,
1024 buffer = (uint8_t *)&parms->regfile->entry[idx].data;
1025 *val = &buffer[sizeof(uint64_t) - bytelen];
1026 *value = tfp_be_to_cpu_64(lregval);
1028 case BNXT_ULP_FIELD_SRC_ACT_PROP:
1029 if (!ulp_operand_read(field_opr,
1030 (uint8_t *)&idx, sizeof(uint16_t))) {
1031 BNXT_TF_DBG(ERR, "Action operand read failed\n");
1034 idx = tfp_be_to_cpu_16(idx);
1035 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1036 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", idx);
1039 buffer = &parms->act_prop->act_details[idx];
1040 field_size = ulp_mapper_act_prop_size_get(idx);
1041 if (bytelen > field_size) {
1042 BNXT_TF_DBG(ERR, "act_prop[%d] field size small %u\n",
1046 *val = &buffer[field_size - bytelen];
1048 case BNXT_ULP_FIELD_SRC_ACT_PROP_SZ:
1049 if (!ulp_operand_read(field_opr,
1050 (uint8_t *)&idx, sizeof(uint16_t))) {
1051 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1054 idx = tfp_be_to_cpu_16(idx);
1056 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1057 BNXT_TF_DBG(ERR, "act_prop_sz[%d] oob\n", idx);
1060 *val = &parms->act_prop->act_details[idx];
1062 /* get the size index next */
1063 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1064 (uint8_t *)&size_idx, sizeof(uint16_t))) {
1065 BNXT_TF_DBG(ERR, "Action sz operand read failed\n");
1068 size_idx = tfp_be_to_cpu_16(size_idx);
1069 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
1070 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
1073 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
1075 val_size = tfp_be_to_cpu_32(val_size);
1076 *val_len = ULP_BYTE_2_BITS(val_size);
1078 case BNXT_ULP_FIELD_SRC_GLB_RF:
1079 if (!ulp_operand_read(field_opr,
1080 (uint8_t *)&idx, sizeof(uint16_t))) {
1081 BNXT_TF_DBG(ERR, "Global regfile read failed\n");
1084 idx = tfp_be_to_cpu_16(idx);
1085 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1086 dir, idx, &lregval, &shared) ||
1087 sizeof(uint64_t) < bytelen) {
1088 BNXT_TF_DBG(ERR, "Global regfile[%d] read failed %u\n",
1092 m = parms->mapper_data;
1093 buffer = (uint8_t *)&m->glb_res_tbl[dir][idx].resource_hndl;
1094 *val = &buffer[sizeof(uint64_t) - bytelen];
1095 *value = tfp_be_to_cpu_64(lregval);
1097 case BNXT_ULP_FIELD_SRC_HF:
1098 case BNXT_ULP_FIELD_SRC_SUB_HF:
1099 if (!ulp_operand_read(field_opr,
1100 (uint8_t *)&idx, sizeof(uint16_t))) {
1101 BNXT_TF_DBG(ERR, "Header field read failed\n");
1104 idx = tfp_be_to_cpu_16(idx);
1105 /* get the index from the global field list */
1106 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1107 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1112 buffer = parms->hdr_field[bit].spec;
1114 buffer = parms->hdr_field[bit].mask;
1116 field_size = parms->hdr_field[bit].size;
1117 if (bytelen > field_size) {
1118 BNXT_TF_DBG(ERR, "Hdr field[%d] size small %u\n",
1122 if (field_src == BNXT_ULP_FIELD_SRC_HF) {
1123 *val = &buffer[field_size - bytelen];
1125 /* get the offset next */
1126 if (!ulp_operand_read(&field_opr[sizeof(uint16_t)],
1128 sizeof(uint16_t))) {
1129 BNXT_TF_DBG(ERR, "Hdr fld size read failed\n");
1132 offset = tfp_be_to_cpu_16(offset);
1133 offset = ULP_BITS_2_BYTE_NR(offset);
1134 if ((offset + bytelen) > field_size) {
1135 BNXT_TF_DBG(ERR, "Hdr field[%d] oob\n", bit);
1138 *val = &buffer[offset];
1141 case BNXT_ULP_FIELD_SRC_HDR_BIT:
1142 if (!ulp_operand_read(field_opr,
1143 (uint8_t *)&lregval, sizeof(uint64_t))) {
1144 BNXT_TF_DBG(ERR, "Header bit read failed\n");
1147 lregval = tfp_be_to_cpu_64(lregval);
1148 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, lregval)) {
1149 *val = mapper_fld_one;
1152 *val = mapper_fld_zeros;
1155 case BNXT_ULP_FIELD_SRC_ACT_BIT:
1156 if (!ulp_operand_read(field_opr,
1157 (uint8_t *)&lregval, sizeof(uint64_t))) {
1158 BNXT_TF_DBG(ERR, "Action bit read failed\n");
1161 lregval = tfp_be_to_cpu_64(lregval);
1162 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, lregval)) {
1163 *val = mapper_fld_one;
1166 *val = mapper_fld_zeros;
1169 case BNXT_ULP_FIELD_SRC_FIELD_BIT:
1170 if (!ulp_operand_read(field_opr,
1171 (uint8_t *)&idx, sizeof(uint16_t))) {
1172 BNXT_TF_DBG(ERR, "Field bit read failed\n");
1175 idx = tfp_be_to_cpu_16(idx);
1176 /* get the index from the global field list */
1177 if (ulp_mapper_glb_field_tbl_get(parms, idx, &bit)) {
1178 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
1182 if (ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit)) {
1183 *val = mapper_fld_one;
1186 *val = mapper_fld_zeros;
1189 case BNXT_ULP_FIELD_SRC_PORT_TABLE:
1190 /* The port id is present in the comp field list */
1191 port_id = ULP_COMP_FLD_IDX_RD(parms,
1192 BNXT_ULP_CF_IDX_DEV_PORT_ID);
1193 /* get the port table enum */
1194 if (!ulp_operand_read(field_opr,
1195 (uint8_t *)&idx, sizeof(uint16_t))) {
1196 BNXT_TF_DBG(ERR, "Port table enum read failed\n");
1199 idx = tfp_be_to_cpu_16(idx);
1200 if (ulp_mapper_field_port_db_process(parms, port_id, idx,
1202 BNXT_TF_DBG(ERR, "field port table failed\n");
1205 case BNXT_ULP_FIELD_SRC_SKIP:
1208 case BNXT_ULP_FIELD_SRC_REJECT:
1211 BNXT_TF_DBG(ERR, "invalid field opcode 0x%x\n", field_src);
1217 static int32_t ulp_mapper_field_buffer_eval(uint8_t *buffer, uint32_t bitlen,
1225 bytelen = ULP_BITS_2_BYTE(bitlen);
1226 if (bytelen == sizeof(uint8_t)) {
1227 *output = *((uint8_t *)buffer);
1228 } else if (bytelen == sizeof(uint16_t)) {
1229 val_16 = *((uint16_t *)buffer);
1230 *output = tfp_be_to_cpu_16(val_16);
1231 } else if (bytelen == sizeof(uint32_t)) {
1232 val_32 = *((uint32_t *)buffer);
1233 *output = tfp_be_to_cpu_32(val_32);
1234 } else if (bytelen == sizeof(val_64)) {
1235 val_64 = *((uint64_t *)buffer);
1236 *output = tfp_be_to_cpu_64(val_64);
1244 static int32_t ulp_mapper_field_blob_write(enum bnxt_ulp_field_src fld_src,
1245 struct ulp_blob *blob,
1250 if (fld_src == BNXT_ULP_FIELD_SRC_ZERO) {
1251 if (ulp_blob_pad_push(blob, val_len) < 0) {
1252 BNXT_TF_DBG(ERR, "too large for blob\n");
1255 } else if (fld_src == BNXT_ULP_FIELD_SRC_ACT_PROP_SZ) {
1256 if (ulp_blob_push_encap(blob, val, val_len) < 0) {
1257 BNXT_TF_DBG(ERR, "encap blob push failed\n");
1261 if (!ulp_blob_push(blob, val, val_len)) {
1262 BNXT_TF_DBG(ERR, "push of val1 failed\n");
1271 ulp_mapper_field_opc_process(struct bnxt_ulp_mapper_parms *parms,
1273 struct bnxt_ulp_mapper_field_info *fld,
1274 struct ulp_blob *blob,
1278 uint16_t write_idx = blob->write_idx;
1279 uint8_t *val = NULL, *val1, *val2, *val3;
1280 uint32_t val_len = 0, val1_len = 0, val2_len = 0, val3_len = 0;
1281 uint8_t process_src1 = 0, process_src2 = 0, process_src3 = 0;
1282 uint8_t eval_src1 = 0, eval_src2 = 0, eval_src3 = 0;
1283 uint64_t val_int = 0, val1_int = 0, val2_int = 0, val3_int = 0;
1284 uint64_t value1 = 0, value2 = 0, value3 = 0;
1287 /* prepare the field source and values */
1288 switch (fld->field_opc) {
1289 case BNXT_ULP_FIELD_OPC_SRC1:
1292 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1295 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1296 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1304 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1305 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1306 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1307 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1308 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1309 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1319 /* process the src1 opcode */
1321 if (ulp_mapper_field_src_process(parms, fld->field_src1,
1322 fld->field_opr1, dir, is_key,
1323 fld->field_bit_size, &val1,
1324 &val1_len, &value1)) {
1325 BNXT_TF_DBG(ERR, "fld src1 process failed\n");
1329 if (ulp_mapper_field_buffer_eval(val1, val1_len,
1331 BNXT_TF_DBG(ERR, "fld src1 eval failed\n");
1337 /* for "if then clause" set the correct process */
1338 if (fld->field_opc == BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3) {
1345 /* process src2 opcode */
1347 if (ulp_mapper_field_src_process(parms, fld->field_src2,
1348 fld->field_opr2, dir, is_key,
1349 fld->field_bit_size, &val2,
1350 &val2_len, &value2)) {
1351 BNXT_TF_DBG(ERR, "fld src2 process failed\n");
1355 if (ulp_mapper_field_buffer_eval(val2, val2_len,
1357 BNXT_TF_DBG(ERR, "fld src2 eval failed\n");
1363 /* process src3 opcode */
1365 if (ulp_mapper_field_src_process(parms, fld->field_src3,
1366 fld->field_opr3, dir, is_key,
1367 fld->field_bit_size, &val3,
1368 &val3_len, &value3)) {
1369 BNXT_TF_DBG(ERR, "fld src3 process failed\n");
1373 if (ulp_mapper_field_buffer_eval(val3, val3_len,
1375 BNXT_TF_DBG(ERR, "fld src3 eval failed\n");
1381 val_len = fld->field_bit_size;
1382 /* process the field opcodes */
1383 switch (fld->field_opc) {
1384 case BNXT_ULP_FIELD_OPC_SRC1:
1385 rc = ulp_mapper_field_blob_write(fld->field_src1,
1386 blob, val1, val1_len, &val);
1389 case BNXT_ULP_FIELD_OPC_SRC1_THEN_SRC2_ELSE_SRC3:
1391 rc = ulp_mapper_field_blob_write(fld->field_src2, blob,
1392 val2, val2_len, &val);
1395 rc = ulp_mapper_field_blob_write(fld->field_src3, blob,
1396 val3, val3_len, &val);
1400 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2:
1401 case BNXT_ULP_FIELD_OPC_SRC1_PLUS_SRC2_POST:
1402 val_int = val1_int + val2_int;
1403 val_int = tfp_cpu_to_be_64(val_int);
1404 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1408 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2:
1409 case BNXT_ULP_FIELD_OPC_SRC1_MINUS_SRC2_POST:
1410 val_int = val1_int - val2_int;
1411 val_int = tfp_cpu_to_be_64(val_int);
1412 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1416 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2:
1417 val_int = val1_int | val2_int;
1418 val_int = tfp_cpu_to_be_64(val_int);
1419 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1423 case BNXT_ULP_FIELD_OPC_SRC1_OR_SRC2_OR_SRC3:
1424 val_int = val1_int | val2_int | val3_int;
1425 val_int = tfp_cpu_to_be_64(val_int);
1426 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1430 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2:
1431 val_int = val1_int & val2_int;
1432 val_int = tfp_cpu_to_be_64(val_int);
1433 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1437 case BNXT_ULP_FIELD_OPC_SRC1_AND_SRC2_OR_SRC3:
1438 val_int = val1_int & (val2_int | val3_int);
1439 val_int = tfp_cpu_to_be_64(val_int);
1440 val = ulp_blob_push_64(blob, &val_int, fld->field_bit_size);
1444 case BNXT_ULP_FIELD_OPC_SKIP:
1447 BNXT_TF_DBG(ERR, "Invalid fld opcode %u\n", fld->field_opc);
1454 BNXT_TF_DBG(ERR, "Error in %s:%s process %u:%u\n", name,
1455 fld->description, (val) ? write_idx : 0, val_len);
1460 * Result table process and fill the result blob.
1461 * data [out] - the result blob data
1464 ulp_mapper_tbl_result_build(struct bnxt_ulp_mapper_parms *parms,
1465 struct bnxt_ulp_mapper_tbl_info *tbl,
1466 struct ulp_blob *data,
1469 struct bnxt_ulp_mapper_field_info *dflds;
1470 uint32_t i, num_flds = 0, encap_flds = 0;
1473 /* Get the result field list */
1474 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_flds,
1477 /* validate the result field list counts */
1478 if ((tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1479 (!num_flds && !encap_flds)) || !dflds ||
1480 (tbl->resource_func != BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE &&
1481 (!num_flds || encap_flds))) {
1482 BNXT_TF_DBG(ERR, "Failed to get data fields %x:%x\n",
1483 num_flds, encap_flds);
1487 /* process the result fields, loop through them */
1488 for (i = 0; i < (num_flds + encap_flds); i++) {
1489 /* set the swap index if encap swap bit is enabled */
1490 if (parms->device_params->encap_byte_swap && encap_flds &&
1492 ulp_blob_encap_swap_idx_set(data);
1494 /* Process the result fields */
1495 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1496 &dflds[i], data, 0, name);
1498 BNXT_TF_DBG(ERR, "data field failed\n");
1503 /* if encap bit swap is enabled perform the bit swap */
1504 if (parms->device_params->encap_byte_swap && encap_flds)
1505 ulp_blob_perform_encap_swap(data);
1511 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1512 struct bnxt_ulp_mapper_tbl_info *tbl,
1515 struct ulp_flow_db_res_params fid_parms;
1516 uint32_t mark, gfid, mark_flag;
1517 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1520 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1521 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1522 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1523 BNXT_ULP_ACT_BIT_MARK)))
1524 return rc; /* no need to perform gfid process */
1526 /* Get the mark id details from action property */
1527 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1529 mark = tfp_be_to_cpu_32(mark);
1531 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1532 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1534 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1537 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1540 fid_parms.direction = tbl->direction;
1541 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1542 fid_parms.critical_resource = tbl->critical_resource;
1543 fid_parms.resource_type = mark_flag;
1544 fid_parms.resource_hndl = gfid;
1545 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1547 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1549 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1554 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1555 struct bnxt_ulp_mapper_tbl_info *tbl)
1557 struct ulp_flow_db_res_params fid_parms;
1558 uint32_t act_idx, mark, mark_flag;
1560 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1563 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1564 !(mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION &&
1565 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1566 BNXT_ULP_ACT_BIT_MARK)))
1567 return rc; /* no need to perform mark action process */
1569 /* Get the mark id details from action property */
1570 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1572 mark = tfp_be_to_cpu_32(mark);
1574 if (!ulp_regfile_read(parms->regfile,
1575 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1577 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1580 act_idx = tfp_be_to_cpu_64(val64);
1581 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1582 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1585 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1588 fid_parms.direction = tbl->direction;
1589 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1590 fid_parms.critical_resource = tbl->critical_resource;
1591 fid_parms.resource_type = mark_flag;
1592 fid_parms.resource_hndl = act_idx;
1593 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1595 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1597 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1602 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1603 struct bnxt_ulp_mapper_tbl_info *tbl)
1605 struct ulp_flow_db_res_params fid_parms;
1606 uint32_t act_idx, mark, mark_flag;
1608 enum bnxt_ulp_mark_db_opc mark_op = tbl->mark_db_opcode;
1611 if (mark_op == BNXT_ULP_MARK_DB_OPC_NOP ||
1612 mark_op == BNXT_ULP_MARK_DB_OPC_PUSH_IF_MARK_ACTION)
1613 return rc; /* no need to perform mark action process */
1615 /* Get the mark id details from the computed field of dev port id */
1616 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1618 /* Get the main action pointer */
1619 if (!ulp_regfile_read(parms->regfile,
1620 BNXT_ULP_RF_IDX_MAIN_ACTION_PTR,
1622 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1625 act_idx = tfp_be_to_cpu_64(val64);
1627 /* Set the mark flag to local fid and vfr flag */
1628 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1630 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1633 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1636 fid_parms.direction = tbl->direction;
1637 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1638 fid_parms.critical_resource = tbl->critical_resource;
1639 fid_parms.resource_type = mark_flag;
1640 fid_parms.resource_hndl = act_idx;
1641 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
1643 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1645 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1649 /* Tcam table scan the identifier list and allocate each identifier */
1651 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1652 struct bnxt_ulp_mapper_tbl_info *tbl)
1654 struct bnxt_ulp_mapper_ident_info *idents;
1655 uint32_t num_idents;
1658 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1659 for (i = 0; i < num_idents; i++) {
1660 if (ulp_mapper_ident_process(parms, tbl,
1668 * Tcam table scan the identifier list and extract the identifier from
1672 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1673 struct bnxt_ulp_mapper_tbl_info *tbl,
1674 struct ulp_blob *data)
1676 struct bnxt_ulp_mapper_ident_info *idents;
1677 uint32_t num_idents = 0, i;
1681 * Extract the listed identifiers from the result field,
1682 * no need to allocate them.
1684 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1685 for (i = 0; i < num_idents; i++) {
1686 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1688 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1695 /* Internal function to write the tcam entry */
1697 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1698 struct bnxt_ulp_mapper_tbl_info *tbl,
1699 struct ulp_blob *key,
1700 struct ulp_blob *mask,
1701 struct ulp_blob *data,
1704 struct tf_set_tcam_entry_parms sparms = { 0 };
1709 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1711 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1715 sparms.dir = tbl->direction;
1716 sparms.tcam_tbl_type = tbl->resource_type;
1718 sparms.key = ulp_blob_data_get(key, &tmplen);
1719 sparms.key_sz_in_bits = tmplen;
1720 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1721 sparms.result = ulp_blob_data_get(data, &tmplen);
1722 sparms.result_sz_in_bits = tmplen;
1723 if (tf_set_tcam_entry(tfp, &sparms)) {
1724 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1725 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1726 tf_dir_2_str(sparms.dir), sparms.idx);
1731 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1733 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1741 * internal function to post process key/mask blobs for dynamic pad WC tcam tbl
1743 * parms [in] The mappers parms with data related to the flow.
1745 * key [in] The original key to be transformed
1747 * mask [in] The original mask to be transformed
1749 * tkey [in/out] The transformed key
1751 * tmask [in/out] The transformed mask
1753 * returns zero on success, non-zero on failure
1756 ulp_mapper_wc_tcam_tbl_dyn_post_process(struct bnxt_ulp_device_params *dparms,
1757 struct ulp_blob *key,
1758 struct ulp_blob *mask,
1759 struct ulp_blob *tkey,
1760 struct ulp_blob *tmask)
1762 uint16_t tlen, blen, clen, slice_width, num_slices, max_slices, offset;
1763 uint32_t cword, i, rc;
1767 slice_width = dparms->wc_slice_width;
1768 clen = dparms->wc_ctl_size_bits;
1769 max_slices = dparms->wc_max_slices;
1770 blen = ulp_blob_data_len_get(key);
1772 /* Get the length of the key based on number of slices and width */
1775 while (tlen < blen &&
1776 num_slices <= max_slices) {
1777 num_slices = num_slices << 1;
1781 if (num_slices > max_slices) {
1782 BNXT_TF_DBG(ERR, "Key size (%d) too large for WC\n", blen);
1786 /* The key/mask may not be on a natural slice boundary, pad it */
1788 if (ulp_blob_pad_push(key, pad) < 0 ||
1789 ulp_blob_pad_push(mask, pad) < 0) {
1790 BNXT_TF_DBG(ERR, "Unable to pad key/mask\n");
1794 /* The new length accounts for the ctrl word length and num slices */
1795 tlen = tlen + clen * num_slices;
1796 if (!ulp_blob_init(tkey, tlen, key->byte_order) ||
1797 !ulp_blob_init(tmask, tlen, mask->byte_order)) {
1798 BNXT_TF_DBG(ERR, "Unable to post process wc tcam entry\n");
1802 /* Build the transformed key/mask */
1803 cword = dparms->wc_mode_list[num_slices - 1];
1804 cword = tfp_cpu_to_be_32(cword);
1806 for (i = 0; i < num_slices; i++) {
1807 val = ulp_blob_push_32(tkey, &cword, clen);
1809 BNXT_TF_DBG(ERR, "Key ctrl word push failed\n");
1812 val = ulp_blob_push_32(tmask, &cword, clen);
1814 BNXT_TF_DBG(ERR, "Mask ctrl word push failed\n");
1817 rc = ulp_blob_append(tkey, key, offset, slice_width);
1819 BNXT_TF_DBG(ERR, "Key blob append failed\n");
1822 rc = ulp_blob_append(tmask, mask, offset, slice_width);
1824 BNXT_TF_DBG(ERR, "Mask blob append failed\n");
1827 offset += slice_width;
1830 /* The key/mask are byte reversed on every 4 byte chunk */
1831 ulp_blob_perform_byte_reverse(tkey, 4);
1832 ulp_blob_perform_byte_reverse(tmask, 4);
1837 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1838 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob)
1840 ulp_blob_perform_64B_word_swap(blob);
1841 ulp_blob_perform_64B_byte_swap(blob);
1845 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1846 struct bnxt_ulp_mapper_tbl_info *tbl)
1848 struct bnxt_ulp_mapper_key_info *kflds;
1849 struct ulp_blob okey, omask, data, update_data;
1850 struct ulp_blob tkey, tmask; /* transform key and mask */
1851 struct ulp_blob *key, *mask;
1852 uint32_t i, num_kflds;
1855 struct bnxt_ulp_device_params *dparms = parms->device_params;
1856 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1857 struct tf_search_tcam_entry_parms searchparms = { 0 };
1858 struct ulp_flow_db_res_params fid_parms = { 0 };
1859 struct tf_free_tcam_entry_parms free_parms = { 0 };
1861 uint16_t tmplen = 0;
1864 /* Set the key and mask to the original key and mask. */
1868 /* Skip this if table opcode is NOP */
1869 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
1870 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
1871 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
1876 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
1878 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1882 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1883 if (!kflds || !num_kflds) {
1884 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1888 if (!ulp_blob_init(key, tbl->blob_key_bit_size, tbl->byte_order) ||
1889 !ulp_blob_init(mask, tbl->blob_key_bit_size, tbl->byte_order) ||
1890 !ulp_blob_init(&data, tbl->result_bit_size, dparms->byte_order) ||
1891 !ulp_blob_init(&update_data, tbl->result_bit_size,
1892 dparms->byte_order)) {
1893 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1897 /* create the key/mask */
1899 * NOTE: The WC table will require some kind of flag to handle the
1900 * mode bits within the key/mask
1902 for (i = 0; i < num_kflds; i++) {
1904 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1905 &kflds[i].field_info_spec,
1906 key, 1, "TCAM Key");
1908 BNXT_TF_DBG(ERR, "Key field set failed %s\n",
1909 kflds[i].field_info_spec.description);
1913 /* Setup the mask */
1914 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
1915 &kflds[i].field_info_mask,
1916 mask, 0, "TCAM Mask");
1918 BNXT_TF_DBG(ERR, "Mask field set failed %s\n",
1919 kflds[i].field_info_mask.description);
1924 /* For wild card tcam perform the post process to swap the blob */
1925 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM ||
1926 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_HIGH ||
1927 tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM_LOW) {
1928 if (dparms->dynamic_pad_en) {
1929 /* Sets up the slices for writing to the WC TCAM */
1930 rc = ulp_mapper_wc_tcam_tbl_dyn_post_process(dparms,
1936 "Failed to post proc WC entry.\n");
1939 /* Now need to use the transform Key/Mask */
1943 ulp_mapper_wc_tcam_tbl_post_process(key);
1944 ulp_mapper_wc_tcam_tbl_post_process(mask);
1949 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1950 /* allocate the tcam index */
1951 aparms.dir = tbl->direction;
1952 aparms.tcam_tbl_type = tbl->resource_type;
1953 aparms.key = ulp_blob_data_get(key, &tmplen);
1954 aparms.key_sz_in_bits = tmplen;
1955 aparms.mask = ulp_blob_data_get(mask, &tmplen);
1957 /* calculate the entry priority */
1958 rc = ulp_mapper_priority_opc_process(parms, tbl,
1961 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1965 rc = tf_alloc_tcam_entry(tfp, &aparms);
1967 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1974 * Searching before allocation to see if we already have an
1975 * entry. This allows re-use of a constrained resource.
1977 searchparms.dir = tbl->direction;
1978 searchparms.tcam_tbl_type = tbl->resource_type;
1979 searchparms.key = ulp_blob_data_get(key, &tmplen);
1980 searchparms.key_sz_in_bits = tbl->key_bit_size;
1981 searchparms.mask = ulp_blob_data_get(mask, &tmplen);
1982 searchparms.alloc = 1;
1983 searchparms.result = ulp_blob_data_get(&data, &tmplen);
1984 searchparms.result_sz_in_bits = tbl->result_bit_size;
1986 /* calculate the entry priority */
1987 rc = ulp_mapper_priority_opc_process(parms, tbl,
1988 &searchparms.priority);
1990 BNXT_TF_DBG(ERR, "entry priority process failed\n");
1994 rc = tf_search_tcam_entry(tfp, &searchparms);
1996 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
2000 /* Successful search, check the result */
2001 if (searchparms.search_status == REJECT) {
2002 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
2005 idx = searchparms.idx;
2006 hit = searchparms.hit;
2009 /* Write the tcam index into the regfile*/
2010 if (ulp_regfile_write(parms->regfile, tbl->tbl_operand,
2011 (uint64_t)tfp_cpu_to_be_64(idx))) {
2012 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
2015 /* Need to free the tcam idx, so goto error */
2019 /* if it is miss then it is same as no search before alloc */
2020 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
2021 /*Scan identifier list, allocate identifier and update regfile*/
2022 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
2023 /* Create the result blob */
2025 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2027 /* write the tcam entry */
2029 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, key,
2032 /*Scan identifier list, extract identifier and update regfile*/
2033 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
2038 /* Add the tcam index to the flow database */
2039 fid_parms.direction = tbl->direction;
2040 fid_parms.resource_func = tbl->resource_func;
2041 fid_parms.resource_type = tbl->resource_type;
2042 fid_parms.critical_resource = tbl->critical_resource;
2043 fid_parms.resource_hndl = idx;
2044 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2046 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2048 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2050 /* Need to free the identifier, so goto error */
2056 free_parms.dir = tbl->direction;
2057 free_parms.tcam_tbl_type = tbl->resource_type;
2058 free_parms.idx = idx;
2059 trc = tf_free_tcam_entry(tfp, &free_parms);
2061 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
2062 tbl->resource_type, tbl->direction, idx);
2067 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2068 struct bnxt_ulp_mapper_tbl_info *tbl)
2070 struct bnxt_ulp_mapper_key_info *kflds;
2071 struct ulp_blob key, data;
2072 uint32_t i, num_kflds;
2075 struct ulp_flow_db_res_params fid_parms = { 0 };
2076 struct tf_insert_em_entry_parms iparms = { 0 };
2077 struct tf_delete_em_entry_parms free_parms = { 0 };
2078 enum bnxt_ulp_flow_mem_type mtype;
2079 struct bnxt_ulp_device_params *dparms = parms->device_params;
2084 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2085 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2087 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
2091 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2092 if (!kflds || !num_kflds) {
2093 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2097 /* Initialize the key/result blobs */
2098 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
2100 !ulp_blob_init(&data, tbl->result_bit_size,
2102 BNXT_TF_DBG(ERR, "blob inits failed.\n");
2106 /* create the key */
2107 for (i = 0; i < num_kflds; i++) {
2109 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2110 &kflds[i].field_info_spec,
2113 BNXT_TF_DBG(ERR, "Key field set failed.\n");
2118 /* if dynamic padding is enabled then add padding to result data */
2119 if (dparms->dynamic_pad_en) {
2120 /* add padding to make sure key is at byte boundary */
2121 ulp_blob_pad_align(&key, ULP_BUFFER_ALIGN_8_BITS);
2124 pad = dparms->em_blk_align_bits - dparms->em_blk_size_bits;
2126 BNXT_TF_DBG(ERR, "Invalid em blk size and align\n");
2129 ulp_blob_pad_push(&data, (uint32_t)pad);
2132 /* Create the result data blob */
2133 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "EM Result");
2135 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2138 if (dparms->dynamic_pad_en) {
2139 uint32_t abits = dparms->em_blk_align_bits;
2141 /* when dynamic padding is enabled merge result + key */
2142 rc = ulp_blob_block_merge(&data, &key, abits, pad);
2144 BNXT_TF_DBG(ERR, "Failed to merge the result blob\n");
2148 /* add padding to make sure merged result is at slice boundary*/
2149 ulp_blob_pad_align(&data, abits);
2151 ulp_blob_perform_byte_reverse(&data, ULP_BITS_2_BYTE(abits));
2154 /* do the transpose for the internal EM keys */
2155 if (tbl->resource_type == TF_MEM_INTERNAL) {
2156 if (dparms->em_key_align_bytes) {
2157 int32_t b = ULP_BYTE_2_BITS(dparms->em_key_align_bytes);
2159 tmplen = ulp_blob_data_len_get(&key);
2160 ulp_blob_pad_push(&key, b - tmplen);
2162 tmplen = ulp_blob_data_len_get(&key);
2163 ulp_blob_perform_byte_reverse(&key, ULP_BITS_2_BYTE(tmplen));
2166 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
2167 &iparms.tbl_scope_id);
2169 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2174 * NOTE: the actual blob size will differ from the size in the tbl
2175 * entry due to the padding.
2177 iparms.dup_check = 0;
2178 iparms.dir = tbl->direction;
2179 iparms.mem = tbl->resource_type;
2180 iparms.key = ulp_blob_data_get(&key, &tmplen);
2181 iparms.key_sz_in_bits = tbl->key_bit_size;
2182 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
2183 if (tbl->result_bit_size)
2184 iparms.em_record_sz_in_bits = tbl->result_bit_size;
2186 iparms.em_record_sz_in_bits = tmplen;
2188 rc = tf_insert_em_entry(tfp, &iparms);
2190 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
2194 /* Mark action process */
2195 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
2196 tbl->resource_type == TF_MEM_EXTERNAL)
2197 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
2198 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
2199 tbl->resource_type == TF_MEM_INTERNAL)
2200 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
2202 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
2206 /* Link the EM resource to the flow in the flow db */
2207 memset(&fid_parms, 0, sizeof(fid_parms));
2208 fid_parms.direction = tbl->direction;
2209 fid_parms.resource_func = tbl->resource_func;
2210 fid_parms.resource_type = tbl->resource_type;
2211 fid_parms.critical_resource = tbl->critical_resource;
2212 fid_parms.resource_hndl = iparms.flow_handle;
2214 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2216 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
2218 /* Need to free the identifier, so goto error */
2224 free_parms.dir = iparms.dir;
2225 free_parms.mem = iparms.mem;
2226 free_parms.tbl_scope_id = iparms.tbl_scope_id;
2227 free_parms.flow_handle = iparms.flow_handle;
2229 trc = tf_delete_em_entry(tfp, &free_parms);
2231 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
2237 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2238 struct bnxt_ulp_mapper_tbl_info *tbl)
2240 struct ulp_flow_db_res_params fid_parms;
2241 struct ulp_blob data;
2242 uint64_t regval = 0;
2245 int32_t rc = 0, trc = 0;
2246 struct tf_alloc_tbl_entry_parms aparms = { 0 };
2247 struct tf_set_tbl_entry_parms sparms = { 0 };
2248 struct tf_get_tbl_entry_parms gparms = { 0 };
2249 struct tf_free_tbl_entry_parms free_parms = { 0 };
2250 uint32_t tbl_scope_id;
2252 struct bnxt_ulp_glb_resource_info glb_res;
2256 bool global = false;
2257 uint64_t act_rec_size;
2258 bool shared = false;
2260 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2261 /* use the max size if encap is enabled */
2262 if (tbl->encap_num_fields)
2263 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
2265 bit_size = tbl->result_bit_size;
2267 /* Initialize the blob data */
2268 if (!ulp_blob_init(&data, bit_size,
2269 parms->device_params->byte_order)) {
2270 BNXT_TF_DBG(ERR, "Failed to initialize index table blob\n");
2274 /* Get the scope id first */
2275 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
2277 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
2281 switch (tbl->tbl_opcode) {
2282 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_REGFILE:
2285 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_REGFILE:
2287 * Build the entry, alloc an index, write the table, and store
2288 * the data in the regfile.
2293 case BNXT_ULP_INDEX_TBL_OPC_WR_REGFILE:
2295 * get the index to write to from the regfile and then write
2298 if (!ulp_regfile_read(parms->regfile,
2302 "Failed to get tbl idx from regfile[%d].\n",
2306 index = tfp_be_to_cpu_64(regval);
2307 /* For external, we need to reverse shift */
2308 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2309 index = TF_ACT_REC_PTR_2_OFFSET(index);
2313 case BNXT_ULP_INDEX_TBL_OPC_ALLOC_WR_GLB_REGFILE:
2315 * Build the entry, alloc an index, write the table, and store
2316 * the data in the global regfile.
2321 glb_res.direction = tbl->direction;
2322 glb_res.resource_func = tbl->resource_func;
2323 glb_res.resource_type = tbl->resource_type;
2324 glb_res.glb_regfile_index = tbl->tbl_operand;
2326 case BNXT_ULP_INDEX_TBL_OPC_WR_GLB_REGFILE:
2327 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2328 BNXT_TF_DBG(ERR, "Template error, wrong fdb opcode\n");
2332 * get the index to write to from the global regfile and then
2335 if (ulp_mapper_glb_resource_read(parms->mapper_data,
2338 ®val, &shared)) {
2340 "Failed to get tbl idx from Glb RF[%d].\n",
2344 index = tfp_be_to_cpu_64(regval);
2345 /* For external, we need to reverse shift */
2346 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2347 index = TF_ACT_REC_PTR_2_OFFSET(index);
2350 case BNXT_ULP_INDEX_TBL_OPC_RD_REGFILE:
2352 * The read is different from the rest and can be handled here
2353 * instead of trying to use common code. Simply read the table
2354 * with the index from the regfile, scan and store the
2355 * identifiers, and return.
2357 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2358 /* Not currently supporting with EXT */
2360 "Ext Table Read Opcode not supported.\n");
2363 if (!ulp_regfile_read(parms->regfile,
2364 tbl->tbl_operand, ®val)) {
2366 "Failed to get tbl idx from regfile[%d]\n",
2370 index = tfp_be_to_cpu_64(regval);
2371 gparms.dir = tbl->direction;
2372 gparms.type = tbl->resource_type;
2373 gparms.data = ulp_blob_data_get(&data, &tmplen);
2374 gparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tbl->result_bit_size);
2376 rc = tf_get_tbl_entry(tfp, &gparms);
2378 BNXT_TF_DBG(ERR, "Failed to read the tbl entry %d:%d\n",
2379 tbl->resource_type, index);
2383 * Scan the fields in the entry and push them into the regfile.
2385 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2387 gparms.data_sz_in_bytes,
2391 "Failed to get flds on tbl read rc=%d\n",
2397 BNXT_TF_DBG(ERR, "Invalid index table opcode %d\n",
2403 /* Get the result fields list */
2404 rc = ulp_mapper_tbl_result_build(parms,
2409 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2415 aparms.dir = tbl->direction;
2416 aparms.type = tbl->resource_type;
2417 aparms.tbl_scope_id = tbl_scope_id;
2419 /* All failures after the alloc succeeds require a free */
2420 rc = tf_alloc_tbl_entry(tfp, &aparms);
2422 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2423 tf_tbl_type_2_str(tbl->resource_type),
2424 tf_dir_2_str(tbl->direction), rc);
2430 * Store the index in the regfile since we either allocated it
2433 * Calculate the idx for the result record, for external EM the
2434 * offset needs to be shifted accordingly.
2435 * If external non-inline table types are used then need to
2436 * revisit this logic.
2438 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2439 regval = TF_ACT_REC_OFFSET_2_PTR(index);
2442 regval = tfp_cpu_to_be_64(regval);
2446 * Shared resources are never allocated through this
2447 * method, so the shared flag is always false.
2449 rc = ulp_mapper_glb_resource_write(parms->mapper_data,
2453 rc = ulp_regfile_write(parms->regfile,
2454 tbl->tbl_operand, regval);
2458 "Failed to write %s regfile[%d] rc=%d\n",
2459 (global) ? "global" : "reg",
2460 tbl->tbl_operand, rc);
2466 sparms.dir = tbl->direction;
2467 sparms.type = tbl->resource_type;
2468 sparms.data = ulp_blob_data_get(&data, &tmplen);
2469 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2471 sparms.tbl_scope_id = tbl_scope_id;
2473 tfp = bnxt_ulp_cntxt_shared_tfp_get(parms->ulp_ctx);
2474 rc = tf_set_tbl_entry(tfp, &sparms);
2477 "Index table[%s][%s][%x] write fail rc=%d\n",
2478 tf_tbl_type_2_str(sparms.type),
2479 tf_dir_2_str(sparms.dir),
2484 /* Calculate action record size */
2485 if (tbl->resource_type == TF_TBL_TYPE_EXT) {
2486 act_rec_size = (ULP_BITS_2_BYTE_NR(tmplen) + 15) / 16;
2488 if (ulp_regfile_write(parms->regfile,
2489 BNXT_ULP_RF_IDX_ACTION_REC_SIZE,
2490 tfp_cpu_to_be_64(act_rec_size)))
2492 "Failed write the act rec size\n");
2496 /* Link the resource to the flow in the flow db */
2497 memset(&fid_parms, 0, sizeof(fid_parms));
2498 fid_parms.direction = tbl->direction;
2499 fid_parms.resource_func = tbl->resource_func;
2500 fid_parms.resource_type = tbl->resource_type;
2501 fid_parms.resource_sub_type = tbl->resource_sub_type;
2502 fid_parms.resource_hndl = index;
2503 fid_parms.critical_resource = tbl->critical_resource;
2504 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2506 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2508 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2513 /* Perform the VF rep action */
2514 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2516 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2521 /* Shared resources are not freed */
2525 * Free the allocated resource since we failed to either
2526 * write to the entry or link the flow
2528 free_parms.dir = tbl->direction;
2529 free_parms.type = tbl->resource_type;
2530 free_parms.idx = index;
2531 free_parms.tbl_scope_id = tbl_scope_id;
2533 trc = tf_free_tbl_entry(tfp, &free_parms);
2535 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2541 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2542 struct bnxt_ulp_mapper_tbl_info *tbl)
2544 struct ulp_blob data, res_blob;
2548 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2549 struct tf_get_if_tbl_entry_parms get_parms = { 0 };
2551 enum bnxt_ulp_if_tbl_opc if_opc = tbl->tbl_opcode;
2554 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx, tbl->shared_session);
2555 /* Initialize the blob data */
2556 if (!ulp_blob_init(&data, tbl->result_bit_size,
2557 parms->device_params->byte_order)) {
2558 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2562 /* create the result blob */
2563 rc = ulp_mapper_tbl_result_build(parms, tbl, &data, "IFtable Result");
2565 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2569 /* Get the index details */
2571 case BNXT_ULP_IF_TBL_OPC_WR_COMP_FIELD:
2572 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2574 case BNXT_ULP_IF_TBL_OPC_WR_REGFILE:
2575 if (!ulp_regfile_read(parms->regfile, tbl->tbl_operand, &idx)) {
2576 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
2580 idx = tfp_be_to_cpu_64(idx);
2582 case BNXT_ULP_IF_TBL_OPC_WR_CONST:
2583 idx = tbl->tbl_operand;
2585 case BNXT_ULP_IF_TBL_OPC_RD_COMP_FIELD:
2586 /* Initialize the result blob */
2587 if (!ulp_blob_init(&res_blob, tbl->result_bit_size,
2588 parms->device_params->byte_order)) {
2589 BNXT_TF_DBG(ERR, "Failed initial result blob\n");
2593 /* read the interface table */
2594 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->tbl_operand);
2595 res_size = ULP_BITS_2_BYTE(tbl->result_bit_size);
2596 get_parms.dir = tbl->direction;
2597 get_parms.type = tbl->resource_type;
2598 get_parms.idx = idx;
2599 get_parms.data = ulp_blob_data_get(&res_blob, &tmplen);
2600 get_parms.data_sz_in_bytes = res_size;
2602 rc = tf_get_if_tbl_entry(tfp, &get_parms);
2604 BNXT_TF_DBG(ERR, "Get table[%d][%s][%x] failed rc=%d\n",
2606 tf_dir_2_str(get_parms.dir),
2610 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2613 res_blob.byte_order);
2615 BNXT_TF_DBG(ERR, "Scan and extract failed rc=%d\n", rc);
2617 case BNXT_ULP_IF_TBL_OPC_NOT_USED:
2618 return rc; /* skip it */
2620 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2624 /* Perform the tf table set by filling the set params */
2625 iftbl_params.dir = tbl->direction;
2626 iftbl_params.type = tbl->resource_type;
2627 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2628 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2629 iftbl_params.idx = idx;
2631 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2633 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2634 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2635 tf_dir_2_str(iftbl_params.dir),
2636 iftbl_params.idx, rc);
2641 * TBD: Need to look at the need to store idx in flow db for restore
2642 * the table to its original state on deletion of this entry.
2648 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2649 struct bnxt_ulp_mapper_tbl_info *tbl)
2651 struct ulp_mapper_gen_tbl_list *gen_tbl_list;
2652 struct bnxt_ulp_mapper_key_info *kflds;
2653 struct ulp_flow_db_res_params fid_parms;
2654 struct ulp_mapper_gen_tbl_entry gen_tbl_ent, *g;
2655 struct ulp_gen_hash_entry_params hash_entry;
2656 uint16_t tmplen = 0;
2657 struct ulp_blob key, data;
2660 uint32_t i, num_kflds = 0, key_index = 0;
2661 uint32_t gen_tbl_miss = 1, fdb_write = 0;
2665 /* Get the key fields list and build the key. */
2666 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2667 if (!kflds || !num_kflds) {
2668 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2672 if (!ulp_blob_init(&key, tbl->key_bit_size,
2673 parms->device_params->byte_order)) {
2674 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2677 for (i = 0; i < num_kflds; i++) {
2679 rc = ulp_mapper_field_opc_process(parms, tbl->direction,
2680 &kflds[i].field_info_spec,
2681 &key, 1, "Gen Tbl Key");
2684 "Failed to create key for Gen tbl rc=%d\n",
2690 /* Calculate the table index for the generic table*/
2691 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2694 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2695 tbl->resource_sub_type, tbl->direction);
2699 /* The_key is a byte array convert it to a search index */
2700 cache_key = ulp_blob_data_get(&key, &tmplen);
2701 /* get the generic table */
2702 gen_tbl_list = &parms->mapper_data->gen_tbl_list[tbl_idx];
2704 /* Check if generic hash table */
2705 if (gen_tbl_list->hash_tbl) {
2706 if (tbl->gen_tbl_lkup_type !=
2707 BNXT_ULP_GENERIC_TBL_LKUP_TYPE_HASH) {
2708 BNXT_TF_DBG(ERR, "%s: Invalid template lkup type\n",
2709 gen_tbl_list->gen_tbl_name);
2712 hash_entry.key_data = cache_key;
2713 hash_entry.key_length = ULP_BITS_2_BYTE(tmplen);
2714 rc = ulp_gen_hash_tbl_list_key_search(gen_tbl_list->hash_tbl,
2717 BNXT_TF_DBG(ERR, "%s: hash tbl search failed\n",
2718 gen_tbl_list->gen_tbl_name);
2721 if (hash_entry.search_flag == ULP_GEN_HASH_SEARCH_FOUND) {
2722 key_index = hash_entry.key_idx;
2723 /* Get the generic table entry */
2724 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list,
2728 /* store the hash index in the fdb */
2729 key_index = hash_entry.hash_index;
2732 /* convert key to index directly */
2733 if (ULP_BITS_2_BYTE(tmplen) > (int32_t)sizeof(key_index)) {
2734 BNXT_TF_DBG(ERR, "%s: keysize is bigger then 4 bytes\n",
2735 gen_tbl_list->gen_tbl_name);
2738 memcpy(&key_index, cache_key, ULP_BITS_2_BYTE(tmplen));
2739 /* Get the generic table entry */
2740 if (ulp_mapper_gen_tbl_entry_get(gen_tbl_list, key_index,
2744 switch (tbl->tbl_opcode) {
2745 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2746 if (gen_tbl_list->hash_tbl) {
2747 if (hash_entry.search_flag != ULP_GEN_HASH_SEARCH_FOUND)
2748 break; /* nothing to be done , no entry */
2751 /* check the reference count */
2752 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2754 /* Scan ident list and create the result blob*/
2755 rc = ulp_mapper_tbl_ident_scan_ext(parms, tbl,
2761 "Failed to scan ident list\n");
2764 if (tbl->fdb_opcode != BNXT_ULP_FDB_OPC_NOP) {
2765 /* increment the reference count */
2766 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2774 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
2775 if (gen_tbl_list->hash_tbl) {
2776 rc = ulp_mapper_gen_tbl_hash_entry_add(gen_tbl_list,
2781 /* store the hash index in the fdb */
2782 key_index = hash_entry.hash_index;
2784 /* check the reference count */
2785 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2786 /* a hit then error */
2787 BNXT_TF_DBG(ERR, "generic entry already present\n");
2788 return -EINVAL; /* success */
2791 /* Initialize the blob data */
2792 if (!ulp_blob_init(&data, tbl->result_bit_size,
2793 gen_tbl_ent.byte_order)) {
2794 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2798 /* Get the result fields list */
2799 rc = ulp_mapper_tbl_result_build(parms, tbl, &data,
2802 BNXT_TF_DBG(ERR, "Failed to build the result blob\n");
2805 byte_data = ulp_blob_data_get(&data, &tmplen);
2806 rc = ulp_mapper_gen_tbl_entry_data_set(&gen_tbl_ent,
2808 ULP_BITS_2_BYTE(tmplen));
2810 BNXT_TF_DBG(ERR, "Failed to write generic table\n");
2814 /* increment the reference count */
2815 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2817 parms->shared_hndl = (uint64_t)tbl_idx << 32 | key_index;
2820 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
2824 /* Set the generic entry hit */
2825 rc = ulp_regfile_write(parms->regfile,
2826 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
2827 tfp_cpu_to_be_64(gen_tbl_miss));
2829 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2830 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
2834 /* add the entry to the flow database */
2836 memset(&fid_parms, 0, sizeof(fid_parms));
2837 fid_parms.direction = tbl->direction;
2838 fid_parms.resource_func = tbl->resource_func;
2839 fid_parms.resource_sub_type = tbl->resource_sub_type;
2840 fid_parms.resource_hndl = key_index;
2841 fid_parms.critical_resource = tbl->critical_resource;
2842 ulp_flow_db_shared_session_set(&fid_parms, tbl->shared_session);
2844 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2846 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
2852 ulp_mapper_ctrl_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2853 struct bnxt_ulp_mapper_tbl_info *tbl)
2857 /* process the fdb opcode for alloc push */
2858 if (tbl->fdb_opcode == BNXT_ULP_FDB_OPC_ALLOC_RID_REGFILE) {
2859 rc = ulp_mapper_fdb_opc_alloc_rid(parms, tbl);
2861 BNXT_TF_DBG(ERR, "Failed to do fdb alloc\n");
2869 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2870 struct bnxt_ulp_mapper_data *mapper_data)
2872 struct bnxt_ulp_glb_resource_info *glb_res;
2873 uint32_t num_glb_res_ids, idx, dev_id;
2877 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
2878 if (!glb_res || !num_glb_res_ids) {
2879 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2883 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2885 BNXT_TF_DBG(ERR, "Failed to get device id for glb init (%d)\n",
2890 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2892 BNXT_TF_DBG(ERR, "Failed to get app id for glb init (%d)\n",
2897 /* Iterate the global resources and process each one */
2898 for (idx = 0; idx < num_glb_res_ids; idx++) {
2899 if (dev_id != glb_res[idx].device_id ||
2900 glb_res[idx].app_id != app_id)
2902 switch (glb_res[idx].resource_func) {
2903 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2904 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
2908 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2909 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2914 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2915 glb_res[idx].resource_func);
2926 * Iterate over the shared resources assigned during tf_open_session and store
2927 * them in the global regfile with the shared flag.
2930 ulp_mapper_app_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2931 struct bnxt_ulp_mapper_data *mapper_data)
2933 struct tf_get_shared_tbl_increment_parms iparms;
2934 struct bnxt_ulp_glb_resource_info *glb_res;
2935 struct tf_get_session_info_parms sparms;
2936 uint32_t num_entries, i, dev_id, res;
2937 struct tf_resource_info *res_info;
2945 memset(&sparms, 0, sizeof(sparms));
2946 glb_res = bnxt_ulp_app_glb_resource_info_list_get(&num_entries);
2947 if (!glb_res || !num_entries) {
2948 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2951 tfp = bnxt_ulp_cntxt_shared_tfp_get(ulp_ctx);
2953 BNXT_TF_DBG(ERR, "Failed to get tfp for app global init");
2957 * Retrieve the resources that were assigned during the shared session
2960 rc = tf_get_session_info(tfp, &sparms);
2962 BNXT_TF_DBG(ERR, "Failed to get session info (%d)\n", rc);
2966 rc = bnxt_ulp_cntxt_app_id_get(ulp_ctx, &app_id);
2968 BNXT_TF_DBG(ERR, "Failed to get the app id in glb init (%d).\n",
2973 rc = bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id);
2975 BNXT_TF_DBG(ERR, "Failed to get dev id for app glb init (%d)\n",
2980 /* Store all the app global resources */
2981 for (i = 0; i < num_entries; i++) {
2982 if (dev_id != glb_res[i].device_id ||
2983 app_id != glb_res[i].app_id)
2985 dir = glb_res[i].direction;
2986 res = glb_res[i].resource_type;
2989 switch (glb_res[i].resource_func) {
2990 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2991 res_info = &sparms.session_info.ident[dir].info[res];
2993 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2995 * Tables may have various strides for the allocations.
2998 memset(&iparms, 0, sizeof(iparms));
3001 rc = tf_get_shared_tbl_increment(tfp, &iparms);
3004 "Failed to get addend for %s[%s] rc=(%d)\n",
3005 tf_tbl_type_2_str(res),
3006 tf_dir_2_str(dir), rc);
3009 addend = iparms.increment_cnt;
3010 res_info = &sparms.session_info.tbl[dir].info[res];
3012 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3013 res_info = &sparms.session_info.tcam[dir].info[res];
3015 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3016 res_info = &sparms.session_info.em[dir].info[res];
3019 BNXT_TF_DBG(ERR, "Unknown resource func (0x%x)\n",
3020 glb_res[i].resource_func);
3023 regval = tfp_cpu_to_be_64((uint64_t)res_info->start);
3024 res_info->start += addend;
3026 * All resources written to the global regfile are shared for
3029 rc = ulp_mapper_glb_resource_write(mapper_data, &glb_res[i],
3039 * Common conditional opcode process routine that is used for both the template
3040 * rejection and table conditional execution.
3043 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
3044 enum bnxt_ulp_cond_opc opc,
3048 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
3054 case BNXT_ULP_COND_OPC_CF_IS_SET:
3055 if (operand < BNXT_ULP_CF_IDX_LAST) {
3056 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
3058 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3063 case BNXT_ULP_COND_OPC_CF_NOT_SET:
3064 if (operand < BNXT_ULP_CF_IDX_LAST) {
3065 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
3067 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
3072 case BNXT_ULP_COND_OPC_ACT_BIT_IS_SET:
3073 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3074 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3077 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3082 case BNXT_ULP_COND_OPC_ACT_BIT_NOT_SET:
3083 if (operand < BNXT_ULP_ACT_BIT_LAST) {
3084 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
3087 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
3092 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
3093 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3094 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3097 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3102 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
3103 if (operand < BNXT_ULP_HDR_BIT_LAST) {
3104 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
3107 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
3112 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
3113 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3115 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3119 *res = ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3121 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
3122 rc = ulp_mapper_glb_field_tbl_get(parms, operand, &bit);
3124 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
3128 *res = !ULP_INDEX_BITMAP_GET(parms->fld_bitmap->bits, bit);
3130 case BNXT_ULP_COND_OPC_RF_IS_SET:
3131 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3132 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3137 case BNXT_ULP_COND_OPC_RF_NOT_SET:
3138 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
3139 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
3144 case BNXT_ULP_COND_OPC_FLOW_PAT_MATCH:
3145 if (parms->flow_pattern_id == operand) {
3146 BNXT_TF_DBG(ERR, "field pattern match failed %x\n",
3147 parms->flow_pattern_id);
3151 case BNXT_ULP_COND_OPC_ACT_PAT_MATCH:
3152 if (parms->act_pattern_id == operand) {
3153 BNXT_TF_DBG(ERR, "act pattern match failed %x\n",
3154 parms->act_pattern_id);
3158 case BNXT_ULP_COND_OPC_EXT_MEM_IS_SET:
3159 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3160 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3163 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 0 : 1;
3165 case BNXT_ULP_COND_OPC_EXT_MEM_NOT_SET:
3166 if (bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype)) {
3167 BNXT_TF_DBG(ERR, "Failed to get the mem type\n");
3170 *res = (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT) ? 1 : 0;
3173 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
3181 ulp_mapper_func_opr_compute(struct bnxt_ulp_mapper_parms *parms,
3183 enum bnxt_ulp_func_src func_src,
3192 case BNXT_ULP_FUNC_SRC_COMP_FIELD:
3193 if (func_opr >= BNXT_ULP_CF_IDX_LAST) {
3194 BNXT_TF_DBG(ERR, "invalid index %u\n", func_opr);
3197 *result = ULP_COMP_FLD_IDX_RD(parms, func_opr);
3199 case BNXT_ULP_FUNC_SRC_REGFILE:
3200 if (!ulp_regfile_read(parms->regfile, func_opr, ®val)) {
3201 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", func_opr);
3204 *result = tfp_be_to_cpu_64(regval);
3206 case BNXT_ULP_FUNC_SRC_GLB_REGFILE:
3207 if (ulp_mapper_glb_resource_read(parms->mapper_data, dir,
3208 func_opr, ®val, &shared)) {
3209 BNXT_TF_DBG(ERR, "global regfile[%d] read failed.\n",
3213 *result = tfp_be_to_cpu_64(regval);
3215 case BNXT_ULP_FUNC_SRC_CONST:
3219 BNXT_TF_DBG(ERR, "invalid src code %u\n", func_src);
3226 ulp_mapper_func_info_process(struct bnxt_ulp_mapper_parms *parms,
3227 struct bnxt_ulp_mapper_tbl_info *tbl)
3229 struct bnxt_ulp_mapper_func_info *func_info = &tbl->func_info;
3230 uint64_t res = 0, res1 = 0, res2 = 0;
3232 uint32_t process_src1 = 0, process_src2 = 0;
3234 /* determine which functional operands to compute */
3235 switch (func_info->func_opc) {
3236 case BNXT_ULP_FUNC_OPC_NOP:
3238 case BNXT_ULP_FUNC_OPC_EQ:
3239 case BNXT_ULP_FUNC_OPC_NE:
3240 case BNXT_ULP_FUNC_OPC_GE:
3241 case BNXT_ULP_FUNC_OPC_GT:
3242 case BNXT_ULP_FUNC_OPC_LE:
3243 case BNXT_ULP_FUNC_OPC_LT:
3247 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3255 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3256 func_info->func_src1,
3257 func_info->func_opr1, &res1);
3263 rc = ulp_mapper_func_opr_compute(parms, tbl->direction,
3264 func_info->func_src2,
3265 func_info->func_opr2, &res2);
3270 /* perform the functional opcode operations */
3271 switch (func_info->func_opc) {
3272 case BNXT_ULP_FUNC_OPC_EQ:
3276 case BNXT_ULP_FUNC_OPC_NE:
3280 case BNXT_ULP_FUNC_OPC_GE:
3284 case BNXT_ULP_FUNC_OPC_GT:
3288 case BNXT_ULP_FUNC_OPC_LE:
3292 case BNXT_ULP_FUNC_OPC_LT:
3296 case BNXT_ULP_FUNC_OPC_COPY_SRC1_TO_RF:
3299 case BNXT_ULP_FUNC_OPC_RSS_CONFIG:
3300 /* apply the rss config using pmd method */
3301 return bnxt_rss_config_action_apply(parms);
3302 case BNXT_ULP_FUNC_OPC_GET_PARENT_MAC_ADDR:
3303 rc = bnxt_pmd_get_parent_mac_addr(parms, (uint8_t *)&res);
3306 res = tfp_be_to_cpu_64(res);
3309 BNXT_TF_DBG(ERR, "invalid func code %u\n", func_info->func_opc);
3312 if (ulp_regfile_write(parms->regfile, func_info->func_dst_opr,
3313 tfp_cpu_to_be_64(res))) {
3314 BNXT_TF_DBG(ERR, "Failed write the func_opc %u\n",
3315 func_info->func_dst_opr);
3324 * Processes a list of conditions and returns both a status and result of the
3325 * list. The status must be checked prior to verifying the result.
3327 * returns 0 for success, negative on failure
3328 * returns res = 1 for true, res = 0 for false.
3331 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
3332 enum bnxt_ulp_cond_list_opc list_opc,
3333 struct bnxt_ulp_mapper_cond_info *list,
3338 int32_t rc = 0, trc = 0;
3341 case BNXT_ULP_COND_LIST_OPC_AND:
3342 /* AND Defaults to true. */
3345 case BNXT_ULP_COND_LIST_OPC_OR:
3346 /* OR Defaults to false. */
3349 case BNXT_ULP_COND_LIST_OPC_TRUE:
3352 case BNXT_ULP_COND_LIST_OPC_FALSE:
3356 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
3362 for (i = 0; i < num; i++) {
3363 rc = ulp_mapper_cond_opc_process(parms,
3364 list[i].cond_opcode,
3365 list[i].cond_operand,
3370 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
3371 /* early return if result is ever zero */
3377 /* early return if result is ever non-zero */
3389 * Processes conflict resolution and returns both a status and result.
3390 * The status must be checked prior to verifying the result.
3392 * returns 0 for success, negative on failure
3393 * returns res = 1 for true, res = 0 for false.
3396 ulp_mapper_conflict_resolution_process(struct bnxt_ulp_mapper_parms *parms,
3397 struct bnxt_ulp_mapper_tbl_info *tbl,
3405 switch (tbl->accept_opcode) {
3406 case BNXT_ULP_ACCEPT_OPC_ALWAYS:
3409 case BNXT_ULP_ACCEPT_OPC_FLOW_SIG_ID_MATCH:
3410 /* perform the signature validation*/
3411 if (tbl->resource_func ==
3412 BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE) {
3413 /* Perform the check that generic table is hit or not */
3414 if (!ulp_regfile_read(parms->regfile,
3415 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS,
3417 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3418 BNXT_ULP_RF_IDX_GENERIC_TBL_MISS);
3422 /* not a hit so no need to check flow sign*/
3427 /* compare the new flow signature against stored one */
3428 if (!ulp_regfile_read(parms->regfile,
3429 BNXT_ULP_RF_IDX_FLOW_SIG_ID,
3431 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3432 BNXT_ULP_RF_IDX_FLOW_SIG_ID);
3435 comp_sig = ULP_COMP_FLD_IDX_RD(parms,
3436 BNXT_ULP_CF_IDX_FLOW_SIG_ID);
3437 regval = tfp_be_to_cpu_64(regval);
3438 if (comp_sig == regval)
3441 BNXT_TF_DBG(ERR, "failed signature match 0x%016"
3442 PRIX64 ":%x\n", comp_sig, (uint32_t)regval);
3445 BNXT_TF_DBG(ERR, "Invalid accept opcode %d\n",
3446 tbl->accept_opcode);
3453 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
3455 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
3456 enum bnxt_ulp_cond_list_opc cond_opc;
3457 struct bnxt_ulp_mapper_tbl_info *tbls;
3458 struct bnxt_ulp_mapper_tbl_info *tbl;
3459 uint32_t num_tbls, tbl_idx, num_cond_tbls;
3460 int32_t rc = -EINVAL, cond_rc = 0;
3461 int32_t cond_goto = 1;
3463 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
3467 * Process the reject list if exists, otherwise assume that the
3468 * template is allowed.
3470 if (cond_tbls && num_cond_tbls) {
3471 rc = ulp_mapper_cond_opc_list_process(parms,
3479 /* Reject the template if True */
3481 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
3482 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3488 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
3489 if (!tbls || !num_tbls) {
3490 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
3491 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3492 parms->dev_id, tid);
3496 for (tbl_idx = 0; tbl_idx < num_tbls && cond_goto;) {
3497 tbl = &tbls[tbl_idx];
3498 cond_goto = tbl->execute_info.cond_true_goto;
3499 /* Process the conditional func code opcodes */
3500 if (ulp_mapper_func_info_process(parms, tbl)) {
3501 BNXT_TF_DBG(ERR, "Failed to process cond update\n");
3506 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
3509 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
3510 cond_tbls, num_cond_tbls,
3513 BNXT_TF_DBG(ERR, "Failed to proc cond opc list (%d)\n",
3517 /* Skip the table if False */
3519 cond_goto = tbl->execute_info.cond_false_goto;
3520 goto next_iteration;
3523 switch (tbl->resource_func) {
3524 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3525 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
3527 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3528 rc = ulp_mapper_em_tbl_process(parms, tbl);
3530 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3531 rc = ulp_mapper_index_tbl_process(parms, tbl);
3533 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
3534 rc = ulp_mapper_if_tbl_process(parms, tbl);
3536 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3537 rc = ulp_mapper_gen_tbl_process(parms, tbl);
3539 case BNXT_ULP_RESOURCE_FUNC_CTRL_TABLE:
3540 rc = ulp_mapper_ctrl_tbl_process(parms, tbl);
3542 case BNXT_ULP_RESOURCE_FUNC_INVALID:
3546 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
3547 tbl->resource_func);
3553 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
3554 tbl->resource_func);
3558 /* perform the post table process */
3559 rc = ulp_mapper_conflict_resolution_process(parms, tbl,
3561 if (rc || !cond_rc) {
3562 BNXT_TF_DBG(ERR, "Failed due to conflict resolution\n");
3567 if (cond_goto == BNXT_ULP_COND_GOTO_REJECT) {
3568 BNXT_TF_DBG(ERR, "reject the flow\n");
3571 } else if (cond_goto & BNXT_ULP_COND_GOTO_RF) {
3575 /* least significant 16 bits from reg_file index */
3576 rf_idx = (uint32_t)(cond_goto & 0xFFFF);
3577 if (!ulp_regfile_read(parms->regfile, rf_idx,
3579 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
3584 cond_goto = (int32_t)regval;
3587 if (cond_goto < 0 && ((int32_t)tbl_idx + cond_goto) < 0) {
3588 BNXT_TF_DBG(ERR, "invalid conditional goto %d\n",
3592 tbl_idx += cond_goto;
3597 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
3598 ulp_mapper_tmpl_name_str(parms->tmpl_type),
3599 parms->dev_id, tid);
3604 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
3606 struct ulp_flow_db_res_params *res)
3612 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
3615 if (res->fdb_flags & ULP_FDB_FLAG_SHARED_SESSION)
3616 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_YES);
3618 tfp = bnxt_ulp_cntxt_tfp_get(ulp, BNXT_ULP_SHARED_SESSION_NO);
3620 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
3624 switch (res->resource_func) {
3625 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
3626 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
3628 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
3629 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
3631 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
3632 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
3634 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
3635 rc = ulp_mapper_ident_free(ulp, tfp, res);
3637 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
3638 rc = ulp_mapper_mark_free(ulp, res);
3640 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
3641 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
3643 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
3644 rc = ulp_mapper_child_flow_free(ulp, fid, res);
3646 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
3647 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
3657 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
3658 enum bnxt_ulp_fdb_type flow_type,
3661 struct ulp_flow_db_res_params res_parms = { 0 };
3665 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3670 * Set the critical resource on the first resource del, then iterate
3671 * while status is good
3673 if (flow_type != BNXT_ULP_FDB_TYPE_RID)
3674 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
3676 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
3680 * This is unexpected on the first call to resource del.
3681 * It likely means that the flow did not exist in the flow db.
3683 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
3684 flow_type, fid, rc);
3689 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
3692 * On fail, we still need to attempt to free the
3693 * remaining resources. Don't return
3696 "Flow[%d][0x%x] Res[%d][0x%016" PRIX64
3697 "] failed rc=%d.\n",
3698 flow_type, fid, res_parms.resource_func,
3699 res_parms.resource_hndl, trc);
3701 /* All subsequent call require the non-critical_resource */
3702 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
3704 rc = ulp_flow_db_resource_del(ulp_ctx,
3710 /* Free the Flow ID since we've removed all resources */
3711 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
3717 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
3718 struct bnxt_ulp_mapper_data *mapper_data)
3720 struct bnxt_ulp_mapper_glb_resource_entry *ent;
3721 struct ulp_flow_db_res_params res;
3724 /* Iterate the global resources and process each one */
3725 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
3726 for (idx = 0; idx < BNXT_ULP_GLB_RF_IDX_LAST; idx++) {
3727 ent = &mapper_data->glb_res_tbl[dir][idx];
3728 if (ent->resource_func ==
3729 BNXT_ULP_RESOURCE_FUNC_INVALID ||
3732 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
3733 res.resource_func = ent->resource_func;
3734 res.direction = dir;
3735 res.resource_type = ent->resource_type;
3736 /*convert it from BE to cpu */
3738 tfp_be_to_cpu_64(ent->resource_hndl);
3739 ulp_mapper_resource_free(ulp_ctx, 0, &res);
3745 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
3746 enum bnxt_ulp_fdb_type flow_type,
3752 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
3756 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
3760 /* Function to handle the mapping of the Flow to be compatible
3761 * with the underlying hardware.
3764 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
3765 struct bnxt_ulp_mapper_create_parms *cparms)
3767 struct bnxt_ulp_mapper_parms parms;
3768 struct ulp_regfile regfile;
3769 int32_t rc = 0, trc;
3771 if (!ulp_ctx || !cparms)
3774 /* Initialize the parms structure */
3775 memset(&parms, 0, sizeof(parms));
3776 parms.act_prop = cparms->act_prop;
3777 parms.act_bitmap = cparms->act;
3778 parms.hdr_bitmap = cparms->hdr_bitmap;
3779 parms.regfile = ®file;
3780 parms.hdr_field = cparms->hdr_field;
3781 parms.fld_bitmap = cparms->fld_bitmap;
3782 parms.comp_fld = cparms->comp_fld;
3783 parms.ulp_ctx = ulp_ctx;
3784 parms.act_tid = cparms->act_tid;
3785 parms.class_tid = cparms->class_tid;
3786 parms.flow_type = cparms->flow_type;
3787 parms.parent_flow = cparms->parent_flow;
3788 parms.parent_fid = cparms->parent_fid;
3789 parms.fid = cparms->flow_id;
3790 parms.tun_idx = cparms->tun_idx;
3791 parms.app_priority = cparms->app_priority;
3792 parms.flow_pattern_id = cparms->flow_pattern_id;
3793 parms.act_pattern_id = cparms->act_pattern_id;
3794 parms.app_id = cparms->app_id;
3795 parms.port_id = cparms->port_id;
3797 /* Get the device id from the ulp context */
3798 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
3799 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
3803 /* Get the device params, it will be used in later processing */
3804 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
3805 if (!parms.device_params) {
3806 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
3812 * Get the mapper data for dynamic mapper data such as default
3815 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
3816 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3817 if (!parms.mapper_data) {
3818 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
3822 /* initialize the registry file for further processing */
3823 if (!ulp_regfile_init(parms.regfile)) {
3824 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
3828 /* Process the action template list from the selected action table*/
3829 if (parms.act_tid) {
3830 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
3831 /* Process the action template tables */
3832 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
3835 cparms->shared_hndl = parms.shared_hndl;
3838 if (parms.class_tid) {
3839 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
3841 /* Process the class template tables.*/
3842 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
3847 /* setup the parent-child details */
3848 if (parms.parent_flow) {
3849 /* create a parent flow details */
3850 rc = ulp_flow_db_parent_flow_create(&parms);
3853 } else if (parms.parent_fid) {
3854 /* create a child flow details */
3855 rc = ulp_flow_db_child_flow_create(&parms);
3863 /* Free all resources that were allocated during flow creation */
3864 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.flow_type,
3867 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
3873 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
3875 struct bnxt_ulp_mapper_data *data;
3882 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
3886 data = rte_zmalloc("ulp_mapper_data",
3887 sizeof(struct bnxt_ulp_mapper_data), 0);
3889 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
3893 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
3894 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
3895 /* Don't call deinit since the prof_func wasn't allocated. */
3900 /* Allocate the global resource ids */
3901 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
3903 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
3908 * Only initialize the app global resources if a shared session was
3911 if (bnxt_ulp_cntxt_shared_session_enabled(ulp_ctx)) {
3912 rc = ulp_mapper_app_glb_resource_info_init(ulp_ctx, data);
3914 BNXT_TF_DBG(ERR, "Failed to init app glb resources\n");
3919 /* Allocate the generic table list */
3920 rc = ulp_mapper_generic_tbl_list_init(data);
3922 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
3928 /* Ignore the return code in favor of returning the original error. */
3929 ulp_mapper_deinit(ulp_ctx);
3934 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
3936 struct bnxt_ulp_mapper_data *data;
3941 "Failed to acquire ulp context, so data may not be released.\n");
3945 data = (struct bnxt_ulp_mapper_data *)
3946 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3948 /* Go ahead and return since there is no allocated data. */
3949 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
3953 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx, BNXT_ULP_SHARED_SESSION_NO);
3955 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
3956 /* Free the mapper data regardless of errors. */
3957 goto free_mapper_data;
3960 /* Free the global resource info table entries */
3961 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
3964 /* Free the generic table */
3965 (void)ulp_mapper_generic_tbl_list_deinit(data);
3968 /* Reset the data pointer within the ulp_ctx. */
3969 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);