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"
22 static struct bnxt_ulp_glb_resource_info *
23 ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
27 *num_entries = BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
28 return ulp_glb_resource_tbl;
32 * Read the global resource from the mapper global resource list
34 * The regval is always returned in big-endian.
36 * returns 0 on success
39 ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
44 if (!mapper_data || !regval ||
45 dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
48 *regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
53 * Write a global resource to the mapper global resource list
55 * The regval value must be in big-endian.
57 * return 0 on success.
60 ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
61 struct bnxt_ulp_glb_resource_info *res,
64 struct bnxt_ulp_mapper_glb_resource_entry *ent;
66 /* validate the arguments */
67 if (!data || res->direction >= TF_DIR_MAX ||
68 res->glb_regfile_index >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
71 /* write to the mapper data */
72 ent = &data->glb_res_tbl[res->direction][res->glb_regfile_index];
73 ent->resource_func = res->resource_func;
74 ent->resource_type = res->resource_type;
75 ent->resource_hndl = regval;
80 * Internal function to allocate identity resource and store it in mapper data.
82 * returns 0 on success
85 ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
86 struct bnxt_ulp_mapper_data *mapper_data,
87 struct bnxt_ulp_glb_resource_info *glb_res)
89 struct tf_alloc_identifier_parms iparms = { 0 };
90 struct tf_free_identifier_parms fparms;
95 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
99 iparms.ident_type = glb_res->resource_type;
100 iparms.dir = glb_res->direction;
102 /* Allocate the Identifier using tf api */
103 rc = tf_alloc_identifier(tfp, &iparms);
105 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
106 tf_dir_2_str(iparms.dir),
111 /* entries are stored as big-endian format */
112 regval = tfp_cpu_to_be_64((uint64_t)iparms.id);
113 /* write to the mapper global resource */
114 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
116 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
117 /* Free the identifier when update failed */
118 fparms.dir = iparms.dir;
119 fparms.ident_type = iparms.ident_type;
120 fparms.id = iparms.id;
121 tf_free_identifier(tfp, &fparms);
128 * Internal function to allocate index tbl resource and store it in mapper data.
130 * returns 0 on success
133 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
134 struct bnxt_ulp_mapper_data *mapper_data,
135 struct bnxt_ulp_glb_resource_info *glb_res)
137 struct tf_alloc_tbl_entry_parms aparms = { 0 };
138 struct tf_free_tbl_entry_parms free_parms = { 0 };
141 uint32_t tbl_scope_id;
144 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
148 /* Get the scope id */
149 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &tbl_scope_id);
151 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
155 aparms.type = glb_res->resource_type;
156 aparms.dir = glb_res->direction;
157 aparms.search_enable = BNXT_ULP_SEARCH_BEFORE_ALLOC_NO;
158 aparms.tbl_scope_id = tbl_scope_id;
160 /* Allocate the index tbl using tf api */
161 rc = tf_alloc_tbl_entry(tfp, &aparms);
163 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
164 tf_dir_2_str(aparms.dir), aparms.type);
168 /* entries are stored as big-endian format */
169 regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
170 /* write to the mapper global resource */
171 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
173 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
174 /* Free the identifier when update failed */
175 free_parms.dir = aparms.dir;
176 free_parms.type = aparms.type;
177 free_parms.idx = aparms.idx;
178 tf_free_tbl_entry(tfp, &free_parms);
184 /* Retrieve the global template table */
186 ulp_mapper_glb_template_table_get(uint32_t *num_entries)
190 *num_entries = BNXT_ULP_GLB_TEMPLATE_TBL_MAX_SZ;
191 return ulp_glb_template_tbl;
195 ulp_mapper_glb_field_tbl_get(uint32_t idx)
197 return &ulp_glb_field_tbl[idx];
201 * Get the size of the action property for a given index.
203 * idx [in] The index for the action property
205 * returns the size of the action property.
208 ulp_mapper_act_prop_size_get(uint32_t idx)
210 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
212 return ulp_act_prop_map_table[idx];
215 static struct bnxt_ulp_mapper_cond_info *
216 ulp_mapper_tmpl_reject_list_get(struct bnxt_ulp_mapper_parms *mparms,
219 enum bnxt_ulp_cond_list_opc *opc)
222 const struct ulp_template_device_tbls *dev_tbls;
224 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
225 *num_tbls = dev_tbls->tmpl_list[tid].reject_info.cond_nums;
226 *opc = dev_tbls->tmpl_list[tid].reject_info.cond_list_opcode;
227 idx = dev_tbls->tmpl_list[tid].reject_info.cond_start_idx;
229 return &dev_tbls->cond_list[idx];
232 static struct bnxt_ulp_mapper_cond_info *
233 ulp_mapper_tbl_execute_list_get(struct bnxt_ulp_mapper_parms *mparms,
234 struct bnxt_ulp_mapper_tbl_info *tbl,
236 enum bnxt_ulp_cond_list_opc *opc)
239 const struct ulp_template_device_tbls *dev_tbls;
241 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
242 *num_tbls = tbl->execute_info.cond_nums;
243 *opc = tbl->execute_info.cond_list_opcode;
244 idx = tbl->execute_info.cond_start_idx;
246 return &dev_tbls->cond_list[idx];
250 * Get a list of classifier tables that implement the flow
251 * Gets a device dependent list of tables that implement the class template id
253 * mparms [in] The mappers parms with data related to the flow.
255 * tid [in] The template id that matches the flow
257 * num_tbls [out] The number of classifier tables in the returned array
259 * returns An array of classifier tables to implement the flow, or NULL on
262 static struct bnxt_ulp_mapper_tbl_info *
263 ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
268 const struct ulp_template_device_tbls *dev_tbls;
270 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
272 idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
273 *num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
275 return &dev_tbls->tbl_list[idx];
279 * Get the list of key fields that implement the flow.
281 * mparms [in] The mapper parms with information about the flow
283 * tbl [in] A single table instance to get the key fields from
285 * num_flds [out] The number of key fields in the returned array
287 * Returns array of Key fields, or NULL on error.
289 static struct bnxt_ulp_mapper_key_field_info *
290 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
291 struct bnxt_ulp_mapper_tbl_info *tbl,
295 const struct ulp_template_device_tbls *dev_tbls;
297 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
298 if (!dev_tbls->key_field_list) {
303 idx = tbl->key_start_idx;
304 *num_flds = tbl->key_num_fields;
306 return &dev_tbls->key_field_list[idx];
310 * Get the list of data fields that implement the flow.
312 * mparms [in] The mapper parms with information about the flow
314 * tbl [in] A single table instance to get the data fields from
316 * num_flds [out] The number of data fields in the returned array.
318 * num_encap_flds [out] The number of encap fields in the returned array.
320 * Returns array of data fields, or NULL on error.
322 static struct bnxt_ulp_mapper_result_field_info *
323 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
324 struct bnxt_ulp_mapper_tbl_info *tbl,
326 uint32_t *num_encap_flds)
329 const struct ulp_template_device_tbls *dev_tbls;
331 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
332 if (!dev_tbls->result_field_list) {
338 idx = tbl->result_start_idx;
339 *num_flds = tbl->result_num_fields;
340 *num_encap_flds = tbl->encap_num_fields;
342 return &dev_tbls->result_field_list[idx];
346 * Get the list of ident fields that implement the flow
348 * tbl [in] A single table instance to get the ident fields from
350 * num_flds [out] The number of ident fields in the returned array
352 * returns array of ident fields, or NULL on error
354 static struct bnxt_ulp_mapper_ident_info *
355 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
356 struct bnxt_ulp_mapper_tbl_info *tbl,
360 const struct ulp_template_device_tbls *dev_tbls;
362 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
363 if (!dev_tbls->ident_list) {
368 idx = tbl->ident_start_idx;
369 *num_flds = tbl->ident_nums;
371 return &dev_tbls->ident_list[idx];
374 static inline int32_t
375 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp __rte_unused,
377 struct ulp_flow_db_res_params *res)
379 struct tf_free_tcam_entry_parms fparms = {
380 .dir = res->direction,
381 .tcam_tbl_type = res->resource_type,
382 .idx = (uint16_t)res->resource_hndl
385 return tf_free_tcam_entry(tfp, &fparms);
388 static inline int32_t
389 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
391 struct ulp_flow_db_res_params *res)
393 struct tf_free_tbl_entry_parms fparms = {
394 .dir = res->direction,
395 .type = res->resource_type,
396 .idx = (uint32_t)res->resource_hndl
400 * Just get the table scope, it will be ignored if not necessary
401 * by the tf_free_tbl_entry
403 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
405 return tf_free_tbl_entry(tfp, &fparms);
408 static inline int32_t
409 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
411 struct ulp_flow_db_res_params *res)
413 struct tf_delete_em_entry_parms fparms = { 0 };
416 fparms.dir = res->direction;
417 if (res->resource_func == BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE)
418 fparms.mem = TF_MEM_EXTERNAL;
420 fparms.mem = TF_MEM_INTERNAL;
421 fparms.flow_handle = res->resource_hndl;
423 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
425 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
429 return tf_delete_em_entry(tfp, &fparms);
432 static inline int32_t
433 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
435 struct ulp_flow_db_res_params *res)
437 struct tf_free_identifier_parms fparms = {
438 .dir = res->direction,
439 .ident_type = res->resource_type,
440 .id = (uint16_t)res->resource_hndl
443 return tf_free_identifier(tfp, &fparms);
446 static inline int32_t
447 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
448 struct ulp_flow_db_res_params *res)
450 return ulp_mark_db_mark_del(ulp,
455 static inline int32_t
456 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
458 struct ulp_flow_db_res_params *res)
460 uint32_t idx, child_fid = 0, parent_idx;
461 struct bnxt_ulp_flow_db *flow_db;
463 parent_idx = (uint32_t)res->resource_hndl;
465 /* check the validity of the parent fid */
466 if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
468 BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
472 /* Clear all the child flows parent index */
473 flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
474 while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
476 /* update the child flows resource handle */
477 if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
479 BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
485 /* free the parent entry in the parent table flow */
486 if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
487 BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
493 static inline int32_t
494 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
496 struct ulp_flow_db_res_params *res)
500 parent_fid = (uint32_t)res->resource_hndl;
502 return 0; /* Already freed - orphan child*/
504 /* reset the child flow bitset*/
505 if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
506 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
507 parent_fid, child_fid);
514 * Process the flow database opcode action.
515 * returns 0 on success.
518 ulp_mapper_fdb_opc_process(struct bnxt_ulp_mapper_parms *parms,
519 struct bnxt_ulp_mapper_tbl_info *tbl,
520 struct ulp_flow_db_res_params *fid_parms)
522 uint32_t push_fid, fid = 0;
526 switch (tbl->fdb_opcode) {
527 case BNXT_ULP_FDB_OPC_PUSH:
528 push_fid = parms->fid;
530 case BNXT_ULP_FDB_OPC_ALLOC_PUSH_REGFILE:
531 /* allocate a new fid */
532 rc = ulp_flow_db_fid_alloc(parms->ulp_ctx,
533 BNXT_ULP_FDB_TYPE_REGULAR,
534 tbl->resource_func, &fid);
537 "Unable to allocate flow table entry\n");
540 /* Store the allocated fid in regfile*/
542 rc = ulp_regfile_write(parms->regfile, tbl->flow_db_operand,
545 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
546 tbl->flow_db_operand);
550 /* Use the allocated fid to update the flow resource */
553 case BNXT_ULP_FDB_OPC_PUSH_REGFILE:
554 /* get the fid from the regfile */
555 rc = ulp_regfile_read(parms->regfile, tbl->flow_db_operand,
558 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n",
559 tbl->flow_db_operand);
562 /* Use the extracted fid to update the flow resource */
563 push_fid = (uint32_t)val64;
566 return rc; /* Nothing to be done */
569 /* Add the resource to the flow database */
570 rc = ulp_flow_db_resource_add(parms->ulp_ctx, parms->flow_type,
571 push_fid, fid_parms);
573 BNXT_TF_DBG(ERR, "Failed to add res to flow %x rc = %d\n",
580 /* free the allocated fid */
582 ulp_flow_db_fid_free(parms->ulp_ctx,
583 BNXT_ULP_FDB_TYPE_REGULAR, fid);
588 * Process the identifier instruction and either store it in the flow database
589 * or return it in the val (if not NULL) on success. If val is NULL, the
590 * identifier is to be stored in the flow database.
593 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
594 struct bnxt_ulp_mapper_tbl_info *tbl,
595 struct bnxt_ulp_mapper_ident_info *ident,
598 struct ulp_flow_db_res_params fid_parms;
601 struct tf_alloc_identifier_parms iparms = { 0 };
602 struct tf_free_identifier_parms free_parms = { 0 };
606 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
608 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
612 idx = ident->regfile_idx;
614 iparms.ident_type = ident->ident_type;
615 iparms.dir = tbl->direction;
617 rc = tf_alloc_identifier(tfp, &iparms);
619 BNXT_TF_DBG(ERR, "Alloc ident %s:%s failed.\n",
620 tf_dir_2_str(iparms.dir),
621 tf_ident_2_str(iparms.ident_type));
625 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
626 if (!ulp_regfile_write(parms->regfile, idx, id)) {
627 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
629 /* Need to free the identifier, so goto error */
633 /* Link the resource to the flow in the flow db */
635 memset(&fid_parms, 0, sizeof(fid_parms));
636 fid_parms.direction = tbl->direction;
637 fid_parms.resource_func = ident->resource_func;
638 fid_parms.resource_type = ident->ident_type;
639 fid_parms.resource_hndl = iparms.id;
640 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
642 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
644 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
646 /* Need to free the identifier, so goto error */
655 /* Need to free the identifier */
656 free_parms.dir = tbl->direction;
657 free_parms.ident_type = ident->ident_type;
658 free_parms.id = iparms.id;
660 (void)tf_free_identifier(tfp, &free_parms);
662 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
664 tf_dir_2_str(tbl->direction));
669 * Process the identifier instruction and extract it from result blob.
670 * Increment the identifier reference count and store it in the flow database.
673 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
674 struct bnxt_ulp_mapper_tbl_info *tbl,
675 struct bnxt_ulp_mapper_ident_info *ident,
676 struct ulp_blob *res_blob)
678 struct ulp_flow_db_res_params fid_parms;
681 struct tf_search_identifier_parms sparms = { 0 };
682 struct tf_free_identifier_parms free_parms = { 0 };
686 /* Get the tfp from ulp context */
687 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
689 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
693 /* Extract the index from the result blob */
694 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
695 ident->ident_bit_pos, ident->ident_bit_size);
697 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
701 /* populate the search params and search identifier shadow table */
702 sparms.ident_type = ident->ident_type;
703 sparms.dir = tbl->direction;
704 /* convert the idx into cpu format */
705 sparms.search_id = tfp_be_to_cpu_32(idx);
707 /* Search identifier also increase the reference count */
708 rc = tf_search_identifier(tfp, &sparms);
710 BNXT_TF_DBG(ERR, "Search ident %s:%s:%x failed.\n",
711 tf_dir_2_str(sparms.dir),
712 tf_ident_2_str(sparms.ident_type),
717 /* Write it to the regfile */
718 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
719 if (!ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
720 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
722 /* Need to free the identifier, so goto error */
726 /* Link the resource to the flow in the flow db */
727 memset(&fid_parms, 0, sizeof(fid_parms));
728 fid_parms.direction = tbl->direction;
729 fid_parms.resource_func = ident->resource_func;
730 fid_parms.resource_type = ident->ident_type;
731 fid_parms.resource_hndl = sparms.search_id;
732 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
733 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
735 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
737 /* Need to free the identifier, so goto error */
744 /* Need to free the identifier */
745 free_parms.dir = tbl->direction;
746 free_parms.ident_type = ident->ident_type;
747 free_parms.id = sparms.search_id;
748 (void)tf_free_identifier(tfp, &free_parms);
749 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
751 tf_dir_2_str(tbl->direction), sparms.search_id);
756 ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms,
758 struct bnxt_ulp_mapper_result_field_info *fld,
759 struct ulp_blob *blob,
762 uint16_t idx, size_idx;
764 uint16_t write_idx = blob->write_idx;
766 uint32_t val_size = 0, field_size = 0;
771 switch (fld->result_opcode) {
772 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
773 val = fld->result_operand;
774 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
775 BNXT_TF_DBG(ERR, "%s failed to add field\n", name);
779 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_PROP:
780 if (!ulp_operand_read(fld->result_operand,
781 (uint8_t *)&idx, sizeof(uint16_t))) {
782 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
785 idx = tfp_be_to_cpu_16(idx);
787 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
788 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
791 val = &parms->act_prop->act_details[idx];
792 field_size = ulp_mapper_act_prop_size_get(idx);
793 if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
794 field_size = field_size -
795 ((fld->field_bit_size + 7) / 8);
798 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
799 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
803 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_BIT:
804 if (!ulp_operand_read(fld->result_operand,
805 (uint8_t *)&act_bit, sizeof(uint64_t))) {
806 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
809 act_bit = tfp_be_to_cpu_64(act_bit);
810 memset(act_val, 0, sizeof(act_val));
811 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
813 if (fld->field_bit_size > ULP_BYTE_2_BITS(sizeof(act_val))) {
814 BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
817 if (!ulp_blob_push(blob, act_val, fld->field_bit_size)) {
818 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
823 case BNXT_ULP_MAPPER_OPC_SET_TO_ENCAP_ACT_PROP_SZ:
824 if (!ulp_operand_read(fld->result_operand,
825 (uint8_t *)&idx, sizeof(uint16_t))) {
826 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
829 idx = tfp_be_to_cpu_16(idx);
831 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
832 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
835 val = &parms->act_prop->act_details[idx];
837 /* get the size index next */
838 if (!ulp_operand_read(&fld->result_operand[sizeof(uint16_t)],
839 (uint8_t *)&size_idx, sizeof(uint16_t))) {
840 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
843 size_idx = tfp_be_to_cpu_16(size_idx);
845 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
846 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
849 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
851 val_size = tfp_be_to_cpu_32(val_size);
852 val_size = ULP_BYTE_2_BITS(val_size);
853 ulp_blob_push_encap(blob, val, val_size);
855 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
856 if (!ulp_operand_read(fld->result_operand,
857 (uint8_t *)&idx, sizeof(uint16_t))) {
858 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
862 idx = tfp_be_to_cpu_16(idx);
863 /* Uninitialized regfile entries return 0 */
864 if (!ulp_regfile_read(parms->regfile, idx, ®val)) {
865 BNXT_TF_DBG(ERR, "%s regfile[%d] read oob\n",
870 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
872 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
876 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
877 if (!ulp_operand_read(fld->result_operand,
880 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
883 idx = tfp_be_to_cpu_16(idx);
884 if (ulp_mapper_glb_resource_read(parms->mapper_data,
887 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
891 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
893 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
897 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
898 if (!ulp_operand_read(fld->result_operand,
901 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
904 idx = tfp_be_to_cpu_16(idx);
905 if (idx < BNXT_ULP_CF_IDX_LAST)
906 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
907 fld->field_bit_size);
909 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
913 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
914 if (ulp_blob_pad_push(blob, fld->field_bit_size) < 0) {
915 BNXT_TF_DBG(ERR, "%s too large for blob\n", name);
920 case BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_ACT_PROP_ELSE_CONST:
921 if (!ulp_operand_read(fld->result_operand,
922 (uint8_t *)&act_bit, sizeof(uint64_t))) {
923 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
926 act_bit = tfp_be_to_cpu_64(act_bit);
927 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit)) {
928 /* Action bit is set so consider operand_true */
929 if (!ulp_operand_read(fld->result_operand_true,
932 BNXT_TF_DBG(ERR, "%s operand read failed\n",
936 idx = tfp_be_to_cpu_16(idx);
937 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
938 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n",
942 val = &parms->act_prop->act_details[idx];
943 field_size = ulp_mapper_act_prop_size_get(idx);
944 if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
945 field_size = field_size -
946 ((fld->field_bit_size + 7) / 8);
949 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
950 BNXT_TF_DBG(ERR, "%s push field failed\n",
955 /* action bit is not set, use the operand false */
956 val = fld->result_operand_false;
957 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
958 BNXT_TF_DBG(ERR, "%s failed to add field\n",
964 case BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_CONST_ELSE_CONST:
965 if (!ulp_operand_read(fld->result_operand,
966 (uint8_t *)&act_bit, sizeof(uint64_t))) {
967 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
970 act_bit = tfp_be_to_cpu_64(act_bit);
971 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit)) {
972 /* Action bit is set so consider operand_true */
973 val = fld->result_operand_true;
975 /* action bit is not set, use the operand false */
976 val = fld->result_operand_false;
978 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
979 BNXT_TF_DBG(ERR, "%s failed to add field\n",
984 case BNXT_ULP_MAPPER_OPC_IF_COMP_FIELD_THEN_CF_ELSE_CF:
985 if (!ulp_operand_read(fld->result_operand,
988 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
991 idx = tfp_be_to_cpu_16(idx);
992 if (idx >= BNXT_ULP_CF_IDX_LAST) {
993 BNXT_TF_DBG(ERR, "%s invalid index %u\n", name, idx);
996 /* check if the computed field is set */
997 if (ULP_COMP_FLD_IDX_RD(parms, idx))
998 val = fld->result_operand_true;
1000 val = fld->result_operand_false;
1002 /* read the appropriate computed field */
1003 if (!ulp_operand_read(val, (uint8_t *)&idx, sizeof(uint16_t))) {
1004 BNXT_TF_DBG(ERR, "%s val operand read failed\n", name);
1007 idx = tfp_be_to_cpu_16(idx);
1008 if (idx >= BNXT_ULP_CF_IDX_LAST) {
1009 BNXT_TF_DBG(ERR, "%s invalid index %u\n", name, idx);
1012 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
1013 fld->field_bit_size);
1015 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1019 case BNXT_ULP_MAPPER_OPC_IF_HDR_BIT_THEN_CONST_ELSE_CONST:
1020 if (!ulp_operand_read(fld->result_operand,
1021 (uint8_t *)&hdr_bit, sizeof(uint64_t))) {
1022 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
1025 hdr_bit = tfp_be_to_cpu_64(hdr_bit);
1026 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, hdr_bit)) {
1027 /* Header bit is set so consider operand_true */
1028 val = fld->result_operand_true;
1030 /* Header bit is not set, use the operand false */
1031 val = fld->result_operand_false;
1033 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
1034 BNXT_TF_DBG(ERR, "%s failed to add field\n",
1040 BNXT_TF_DBG(ERR, "invalid result mapper opcode 0x%x at %d\n",
1041 fld->result_opcode, write_idx);
1047 /* Function to alloc action record and set the table. */
1049 ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms,
1051 struct bnxt_ulp_mapper_key_field_info *f,
1052 struct ulp_blob *blob,
1057 uint16_t idx, bitlen;
1060 struct ulp_regfile *regfile = parms->regfile;
1061 uint8_t *val = NULL;
1062 struct bnxt_ulp_mapper_key_field_info *fld = f;
1063 uint32_t field_size;
1066 operand = fld->spec_operand;
1067 opcode = fld->spec_opcode;
1069 operand = fld->mask_operand;
1070 opcode = fld->mask_opcode;
1073 bitlen = fld->field_bit_size;
1076 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
1078 if (!ulp_blob_push(blob, val, bitlen)) {
1079 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1083 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
1084 if (ulp_blob_pad_push(blob, bitlen) < 0) {
1085 BNXT_TF_DBG(ERR, "%s pad too large for blob\n", name);
1090 case BNXT_ULP_MAPPER_OPC_SET_TO_HDR_FIELD:
1091 if (!ulp_operand_read(operand, (uint8_t *)&idx,
1092 sizeof(uint16_t))) {
1093 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1096 idx = tfp_be_to_cpu_16(idx);
1098 val = parms->hdr_field[idx].spec;
1100 val = parms->hdr_field[idx].mask;
1103 * Need to account for how much data was pushed to the header
1104 * field vs how much is to be inserted in the key/mask.
1106 field_size = parms->hdr_field[idx].size;
1107 if (bitlen < ULP_BYTE_2_BITS(field_size)) {
1108 field_size = field_size - ((bitlen + 7) / 8);
1112 if (!ulp_blob_push(blob, val, bitlen)) {
1113 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1117 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
1118 if (!ulp_operand_read(operand, (uint8_t *)&idx,
1119 sizeof(uint16_t))) {
1120 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1123 idx = tfp_be_to_cpu_16(idx);
1124 if (idx < BNXT_ULP_CF_IDX_LAST)
1125 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
1128 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1132 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
1133 if (!ulp_operand_read(operand, (uint8_t *)&idx,
1134 sizeof(uint16_t))) {
1135 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1138 idx = tfp_be_to_cpu_16(idx);
1140 if (!ulp_regfile_read(regfile, idx, &val64)) {
1141 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
1146 val = ulp_blob_push_64(blob, &val64, bitlen);
1148 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1152 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
1153 if (!ulp_operand_read(operand, (uint8_t *)&idx,
1154 sizeof(uint16_t))) {
1155 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1158 idx = tfp_be_to_cpu_16(idx);
1159 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1162 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
1166 val = ulp_blob_push_64(blob, &val64, bitlen);
1168 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1173 BNXT_TF_DBG(ERR, "invalid keymask mapper opcode 0x%x\n",
1181 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1182 struct bnxt_ulp_mapper_tbl_info *tbl,
1185 struct ulp_flow_db_res_params fid_parms;
1186 uint32_t mark, gfid, mark_flag;
1187 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1190 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1191 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1192 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1193 BNXT_ULP_ACTION_BIT_MARK)))
1194 return rc; /* no need to perform gfid process */
1196 /* Get the mark id details from action property */
1197 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1199 mark = tfp_be_to_cpu_32(mark);
1201 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1202 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1204 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1207 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1210 fid_parms.direction = tbl->direction;
1211 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1212 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1213 fid_parms.resource_type = mark_flag;
1214 fid_parms.resource_hndl = gfid;
1215 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1217 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1222 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1223 struct bnxt_ulp_mapper_tbl_info *tbl)
1225 struct ulp_flow_db_res_params fid_parms;
1226 uint32_t act_idx, mark, mark_flag;
1228 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1231 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1232 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1233 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1234 BNXT_ULP_ACTION_BIT_MARK)))
1235 return rc; /* no need to perform mark action process */
1237 /* Get the mark id details from action property */
1238 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1240 mark = tfp_be_to_cpu_32(mark);
1242 if (!ulp_regfile_read(parms->regfile,
1243 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1245 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1248 act_idx = tfp_be_to_cpu_64(val64);
1249 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1250 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1253 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1256 fid_parms.direction = tbl->direction;
1257 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1258 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1259 fid_parms.resource_type = mark_flag;
1260 fid_parms.resource_hndl = act_idx;
1261 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1263 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1268 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1269 struct bnxt_ulp_mapper_tbl_info *tbl)
1271 struct ulp_flow_db_res_params fid_parms;
1272 uint32_t act_idx, mark, mark_flag;
1274 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1277 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1278 mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION)
1279 return rc; /* no need to perform mark action process */
1281 /* Get the mark id details from the computed field of dev port id */
1282 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1284 /* Get the main action pointer */
1285 if (!ulp_regfile_read(parms->regfile,
1286 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1288 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1291 act_idx = tfp_be_to_cpu_64(val64);
1293 /* Set the mark flag to local fid and vfr flag */
1294 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1296 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1299 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1302 fid_parms.direction = tbl->direction;
1303 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1304 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1305 fid_parms.resource_type = mark_flag;
1306 fid_parms.resource_hndl = act_idx;
1307 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1309 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1314 * Tcam table - create the result blob.
1315 * data [out] - the result blob data
1318 ulp_mapper_tcam_tbl_result_create(struct bnxt_ulp_mapper_parms *parms,
1319 struct bnxt_ulp_mapper_tbl_info *tbl,
1320 struct ulp_blob *data)
1322 struct bnxt_ulp_mapper_result_field_info *dflds;
1324 uint32_t encap_flds = 0;
1328 /* Create the result data blob */
1329 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_dflds,
1331 if (!dflds || !num_dflds || encap_flds) {
1332 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1336 for (i = 0; i < num_dflds; i++) {
1337 rc = ulp_mapper_result_field_process(parms,
1343 BNXT_TF_DBG(ERR, "Failed to set data fields\n");
1350 /* Tcam table scan the identifier list and allocate each identifier */
1352 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1353 struct bnxt_ulp_mapper_tbl_info *tbl)
1355 struct bnxt_ulp_mapper_ident_info *idents;
1356 uint32_t num_idents;
1359 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1360 for (i = 0; i < num_idents; i++) {
1361 if (ulp_mapper_ident_process(parms, tbl,
1369 * Tcam table scan the identifier list and extract the identifier from
1373 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1374 struct bnxt_ulp_mapper_tbl_info *tbl,
1375 struct ulp_blob *data)
1377 struct bnxt_ulp_mapper_ident_info *idents;
1378 uint32_t num_idents = 0, i;
1382 * Extract the listed identifiers from the result field,
1383 * no need to allocate them.
1385 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1386 for (i = 0; i < num_idents; i++) {
1387 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1389 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1396 /* Internal function to write the tcam entry */
1398 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1399 struct bnxt_ulp_mapper_tbl_info *tbl,
1400 struct ulp_blob *key,
1401 struct ulp_blob *mask,
1402 struct ulp_blob *data,
1405 struct tf_set_tcam_entry_parms sparms = { 0 };
1410 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1412 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1416 sparms.dir = tbl->direction;
1417 sparms.tcam_tbl_type = tbl->resource_type;
1419 /* Already verified the key/mask lengths */
1420 sparms.key = ulp_blob_data_get(key, &tmplen);
1421 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1422 sparms.key_sz_in_bits = tbl->key_bit_size;
1423 sparms.result = ulp_blob_data_get(data, &tmplen);
1425 if (tbl->result_bit_size != tmplen) {
1426 BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n",
1427 tmplen, tbl->result_bit_size);
1430 sparms.result_sz_in_bits = tbl->result_bit_size;
1431 if (tf_set_tcam_entry(tfp, &sparms)) {
1432 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1433 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1434 tf_dir_2_str(sparms.dir), sparms.idx);
1439 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1441 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1448 #define BNXT_ULP_WC_TCAM_SLICE_SIZE 80
1449 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1450 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob,
1453 uint8_t mode[2] = {0x0, 0x0};
1454 uint32_t mode_len = len / BNXT_ULP_WC_TCAM_SLICE_SIZE;
1457 /* Add the mode bits to the key and mask*/
1460 else if (mode_len > 2)
1463 size = BNXT_ULP_WC_TCAM_SLICE_SIZE + ULP_BYTE_2_BITS(sizeof(mode));
1464 for (idx = 0; idx < mode_len; idx++)
1465 ulp_blob_insert(blob, (size * idx), mode,
1466 ULP_BYTE_2_BITS(sizeof(mode)));
1467 ulp_blob_perform_64B_word_swap(blob);
1468 ulp_blob_perform_64B_byte_swap(blob);
1472 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1473 struct bnxt_ulp_mapper_tbl_info *tbl)
1475 struct bnxt_ulp_mapper_key_field_info *kflds;
1476 struct ulp_blob key, mask, data, update_data;
1477 uint32_t i, num_kflds;
1480 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1481 struct tf_search_tcam_entry_parms searchparms = { 0 };
1482 struct ulp_flow_db_res_params fid_parms = { 0 };
1483 struct tf_free_tcam_entry_parms free_parms = { 0 };
1485 uint16_t tmplen = 0;
1488 /* Skip this if table opcode is NOP */
1489 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_NOT_USED ||
1490 tbl->tbl_opcode >= BNXT_ULP_TCAM_TBL_OPC_LAST) {
1491 BNXT_TF_DBG(ERR, "Invalid tcam table opcode %d\n",
1496 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1498 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1502 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1503 if (!kflds || !num_kflds) {
1504 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1508 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
1509 parms->device_params->byte_order) ||
1510 !ulp_blob_init(&mask, tbl->blob_key_bit_size,
1511 parms->device_params->byte_order) ||
1512 !ulp_blob_init(&data, tbl->result_bit_size,
1513 parms->device_params->byte_order) ||
1514 !ulp_blob_init(&update_data, tbl->result_bit_size,
1515 parms->device_params->byte_order)) {
1516 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1520 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
1521 key.byte_order = BNXT_ULP_BYTE_ORDER_BE;
1522 mask.byte_order = BNXT_ULP_BYTE_ORDER_BE;
1525 /* create the key/mask */
1527 * NOTE: The WC table will require some kind of flag to handle the
1528 * mode bits within the key/mask
1530 for (i = 0; i < num_kflds; i++) {
1532 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1534 &key, 1, "TCAM Key");
1536 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1540 /* Setup the mask */
1541 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1543 &mask, 0, "TCAM Mask");
1545 BNXT_TF_DBG(ERR, "Mask field set failed.\n");
1550 /* For wild card tcam perform the post process to swap the blob */
1551 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
1552 ulp_mapper_wc_tcam_tbl_post_process(&key, tbl->key_bit_size);
1553 ulp_mapper_wc_tcam_tbl_post_process(&mask, tbl->key_bit_size);
1556 if (tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1557 /* allocate the tcam index */
1558 aparms.dir = tbl->direction;
1559 aparms.tcam_tbl_type = tbl->resource_type;
1560 aparms.key = ulp_blob_data_get(&key, &tmplen);
1561 aparms.key_sz_in_bits = tmplen;
1562 if (tbl->blob_key_bit_size != tmplen) {
1563 BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n",
1564 tmplen, tbl->blob_key_bit_size);
1568 aparms.mask = ulp_blob_data_get(&mask, &tmplen);
1569 if (tbl->blob_key_bit_size != tmplen) {
1570 BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n",
1571 tmplen, tbl->blob_key_bit_size);
1574 aparms.priority = tbl->priority;
1575 rc = tf_alloc_tcam_entry(tfp, &aparms);
1577 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1584 * Searching before allocation to see if we already have an
1585 * entry. This allows re-use of a constrained resource.
1587 searchparms.dir = tbl->direction;
1588 searchparms.tcam_tbl_type = tbl->resource_type;
1589 searchparms.key = ulp_blob_data_get(&key, &tmplen);
1590 searchparms.key_sz_in_bits = tbl->key_bit_size;
1591 searchparms.mask = ulp_blob_data_get(&mask, &tmplen);
1592 searchparms.priority = tbl->priority;
1593 searchparms.alloc = 1;
1594 searchparms.result = ulp_blob_data_get(&data, &tmplen);
1595 searchparms.result_sz_in_bits = tbl->result_bit_size;
1597 rc = tf_search_tcam_entry(tfp, &searchparms);
1599 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
1603 /* Successful search, check the result */
1604 if (searchparms.search_status == REJECT) {
1605 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
1608 idx = searchparms.idx;
1609 hit = searchparms.hit;
1612 /* Write the tcam index into the regfile*/
1613 if (!ulp_regfile_write(parms->regfile, tbl->tbl_operand,
1614 (uint64_t)tfp_cpu_to_be_64(idx))) {
1615 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
1618 /* Need to free the tcam idx, so goto error */
1622 /* if it is miss then it is same as no search before alloc */
1623 if (!hit || tbl->tbl_opcode == BNXT_ULP_TCAM_TBL_OPC_ALLOC_WR_REGFILE) {
1624 /*Scan identifier list, allocate identifier and update regfile*/
1625 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
1626 /* Create the result blob */
1628 rc = ulp_mapper_tcam_tbl_result_create(parms, tbl,
1630 /* write the tcam entry */
1632 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key,
1635 /*Scan identifier list, extract identifier and update regfile*/
1636 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
1641 /* Add the tcam index to the flow database */
1642 fid_parms.direction = tbl->direction;
1643 fid_parms.resource_func = tbl->resource_func;
1644 fid_parms.resource_type = tbl->resource_type;
1645 fid_parms.critical_resource = tbl->critical_resource;
1646 fid_parms.resource_hndl = idx;
1647 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1649 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
1651 /* Need to free the identifier, so goto error */
1657 free_parms.dir = tbl->direction;
1658 free_parms.tcam_tbl_type = tbl->resource_type;
1659 free_parms.idx = idx;
1660 trc = tf_free_tcam_entry(tfp, &free_parms);
1662 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
1663 tbl->resource_type, tbl->direction, idx);
1668 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1669 struct bnxt_ulp_mapper_tbl_info *tbl)
1671 struct bnxt_ulp_mapper_key_field_info *kflds;
1672 struct bnxt_ulp_mapper_result_field_info *dflds;
1673 struct ulp_blob key, data;
1674 uint32_t i, num_kflds, num_dflds;
1676 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1677 struct ulp_flow_db_res_params fid_parms = { 0 };
1678 struct tf_insert_em_entry_parms iparms = { 0 };
1679 struct tf_delete_em_entry_parms free_parms = { 0 };
1680 enum bnxt_ulp_flow_mem_type mtype;
1683 uint32_t encap_flds = 0;
1685 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
1687 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
1691 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1692 if (!kflds || !num_kflds) {
1693 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1697 /* Initialize the key/result blobs */
1698 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
1699 parms->device_params->byte_order) ||
1700 !ulp_blob_init(&data, tbl->result_bit_size,
1701 parms->device_params->byte_order)) {
1702 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1706 /* create the key */
1707 for (i = 0; i < num_kflds; i++) {
1709 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1713 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1719 * TBD: Normally should process identifiers in case of using recycle or
1720 * loopback. Not supporting recycle for now.
1723 /* Create the result data blob */
1724 dflds = ulp_mapper_result_fields_get(parms, tbl,
1725 &num_dflds, &encap_flds);
1726 if (!dflds || !num_dflds || encap_flds) {
1727 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1731 for (i = 0; i < num_dflds; i++) {
1732 struct bnxt_ulp_mapper_result_field_info *fld;
1736 rc = ulp_mapper_result_field_process(parms,
1742 BNXT_TF_DBG(ERR, "Failed to set data fields.\n");
1746 /* do the transpose for the internal EM keys */
1747 if (tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE)
1748 ulp_blob_perform_byte_reverse(&key);
1750 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
1751 &iparms.tbl_scope_id);
1753 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1758 * NOTE: the actual blob size will differ from the size in the tbl
1759 * entry due to the padding.
1761 iparms.dup_check = 0;
1762 iparms.dir = tbl->direction;
1763 iparms.mem = tbl->resource_type;
1764 iparms.key = ulp_blob_data_get(&key, &tmplen);
1765 iparms.key_sz_in_bits = tbl->key_bit_size;
1766 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
1767 iparms.em_record_sz_in_bits = tbl->result_bit_size;
1769 rc = tf_insert_em_entry(tfp, &iparms);
1771 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
1775 /* Mark action process */
1776 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
1777 tbl->resource_type == TF_MEM_EXTERNAL)
1778 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
1779 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
1780 tbl->resource_type == TF_MEM_INTERNAL)
1781 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1783 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1787 /* Link the EM resource to the flow in the flow db */
1788 memset(&fid_parms, 0, sizeof(fid_parms));
1789 fid_parms.direction = tbl->direction;
1790 fid_parms.resource_func = tbl->resource_func;
1791 fid_parms.resource_type = tbl->resource_type;
1792 fid_parms.critical_resource = tbl->critical_resource;
1793 fid_parms.resource_hndl = iparms.flow_handle;
1795 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
1797 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
1799 /* Need to free the identifier, so goto error */
1805 free_parms.dir = iparms.dir;
1806 free_parms.mem = iparms.mem;
1807 free_parms.tbl_scope_id = iparms.tbl_scope_id;
1808 free_parms.flow_handle = iparms.flow_handle;
1810 trc = tf_delete_em_entry(tfp, &free_parms);
1812 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
1818 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1819 struct bnxt_ulp_mapper_tbl_info *tbl)
1821 struct bnxt_ulp_mapper_result_field_info *flds;
1822 struct ulp_flow_db_res_params fid_parms;
1823 struct ulp_blob data;
1826 uint32_t i, num_flds, index, hit;
1827 int32_t rc = 0, trc = 0;
1828 struct tf_alloc_tbl_entry_parms aparms = { 0 };
1829 struct tf_search_tbl_entry_parms srchparms = { 0 };
1830 struct tf_set_tbl_entry_parms sparms = { 0 };
1831 struct tf_free_tbl_entry_parms free_parms = { 0 };
1832 uint32_t tbl_scope_id;
1833 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1835 uint32_t encap_flds = 0;
1837 /* Get the scope id first */
1838 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
1840 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1844 /* use the max size if encap is enabled */
1845 if (tbl->encap_num_fields)
1846 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
1848 bit_size = tbl->result_bit_size;
1850 /* Initialize the blob data */
1851 if (!ulp_blob_init(&data, bit_size,
1852 parms->device_params->byte_order)) {
1853 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1857 /* Get the result fields list */
1858 flds = ulp_mapper_result_fields_get(parms, tbl, &num_flds, &encap_flds);
1860 if (!flds || (!num_flds && !encap_flds)) {
1861 BNXT_TF_DBG(ERR, "template undefined for the index table\n");
1865 /* process the result fields, loop through them */
1866 for (i = 0; i < (num_flds + encap_flds); i++) {
1867 /* set the swap index if encap swap bit is enabled */
1868 if (parms->device_params->encap_byte_swap && encap_flds &&
1870 ulp_blob_encap_swap_idx_set(&data);
1872 /* Process the result fields */
1873 rc = ulp_mapper_result_field_process(parms,
1879 BNXT_TF_DBG(ERR, "data field failed\n");
1884 /* if encap bit swap is enabled perform the bit swap */
1885 if (parms->device_params->encap_byte_swap && encap_flds) {
1886 ulp_blob_perform_encap_swap(&data);
1890 * Check for index opcode, if it is Global then
1891 * no need to allocate the table, just set the table
1892 * and exit since it is not maintained in the flow db.
1894 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_GLOBAL) {
1895 /* get the index from index operand */
1896 if (tbl->index_operand < BNXT_ULP_GLB_REGFILE_INDEX_LAST &&
1897 ulp_mapper_glb_resource_read(parms->mapper_data,
1901 BNXT_TF_DBG(ERR, "Glbl regfile[%d] read failed.\n",
1902 tbl->index_operand);
1905 /* set the Tf index table */
1906 sparms.dir = tbl->direction;
1907 sparms.type = tbl->resource_type;
1908 sparms.data = ulp_blob_data_get(&data, &tmplen);
1909 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1910 sparms.idx = tfp_be_to_cpu_64(idx);
1911 sparms.tbl_scope_id = tbl_scope_id;
1913 rc = tf_set_tbl_entry(tfp, &sparms);
1916 "Glbl Index table[%s][%s][%x] failed rc=%d\n",
1917 tf_tbl_type_2_str(sparms.type),
1918 tf_dir_2_str(sparms.dir),
1922 return 0; /* success */
1927 /* Perform the tf table allocation by filling the alloc params */
1928 if (tbl->srch_b4_alloc) {
1929 memset(&srchparms, 0, sizeof(srchparms));
1930 srchparms.dir = tbl->direction;
1931 srchparms.type = tbl->resource_type;
1932 srchparms.alloc = 1;
1933 srchparms.result = ulp_blob_data_get(&data, &tmplen);
1934 srchparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1935 srchparms.tbl_scope_id = tbl_scope_id;
1936 rc = tf_search_tbl_entry(tfp, &srchparms);
1938 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
1939 tf_tbl_type_2_str(tbl->resource_type),
1940 tf_dir_2_str(tbl->direction), rc);
1943 if (srchparms.search_status == REJECT) {
1944 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] rejected.\n",
1945 tf_tbl_type_2_str(tbl->resource_type),
1946 tf_dir_2_str(tbl->direction));
1949 index = srchparms.idx;
1950 hit = srchparms.hit;
1952 aparms.dir = tbl->direction;
1953 aparms.type = tbl->resource_type;
1954 aparms.search_enable = tbl->srch_b4_alloc;
1955 aparms.result = ulp_blob_data_get(&data, &tmplen);
1956 aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1957 aparms.tbl_scope_id = tbl_scope_id;
1959 /* All failures after the alloc succeeds require a free */
1960 rc = tf_alloc_tbl_entry(tfp, &aparms);
1962 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
1963 tf_tbl_type_2_str(tbl->resource_type),
1964 tf_dir_2_str(tbl->direction), rc);
1971 * calculate the idx for the result record, for external EM the offset
1972 * needs to be shifted accordingly. If external non-inline table types
1973 * are used then need to revisit this logic.
1975 if (tbl->resource_type == TF_TBL_TYPE_EXT)
1976 idx = TF_ACT_REC_OFFSET_2_PTR(index);
1980 /* Always storing values in Regfile in BE */
1981 idx = tfp_cpu_to_be_64(idx);
1982 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_ALLOCATE) {
1983 rc = ulp_regfile_write(parms->regfile, tbl->index_operand, idx);
1985 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
1986 tbl->index_operand);
1991 /* Perform the tf table set by filling the set params */
1992 if (!tbl->srch_b4_alloc || !hit) {
1993 sparms.dir = tbl->direction;
1994 sparms.type = tbl->resource_type;
1995 sparms.data = ulp_blob_data_get(&data, &tmplen);
1996 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1998 sparms.tbl_scope_id = tbl_scope_id;
2000 rc = tf_set_tbl_entry(tfp, &sparms);
2002 BNXT_TF_DBG(ERR, "Set table[%s][%s][%x] failed rc=%d\n",
2003 tf_tbl_type_2_str(sparms.type),
2004 tf_dir_2_str(sparms.dir),
2010 /* Link the resource to the flow in the flow db */
2011 memset(&fid_parms, 0, sizeof(fid_parms));
2012 fid_parms.direction = tbl->direction;
2013 fid_parms.resource_func = tbl->resource_func;
2014 fid_parms.resource_type = tbl->resource_type;
2015 fid_parms.resource_sub_type = tbl->resource_sub_type;
2016 fid_parms.resource_hndl = index;
2017 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
2019 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2021 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2026 /* Perform the VF rep action */
2027 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2029 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2035 * Free the allocated resource since we failed to either
2036 * write to the entry or link the flow
2038 free_parms.dir = tbl->direction;
2039 free_parms.type = tbl->resource_type;
2040 free_parms.idx = index;
2041 free_parms.tbl_scope_id = tbl_scope_id;
2043 trc = tf_free_tbl_entry(tfp, &free_parms);
2045 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2051 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2052 struct bnxt_ulp_mapper_tbl_info *tbl)
2054 struct bnxt_ulp_mapper_result_field_info *flds;
2055 struct ulp_blob data;
2058 uint32_t i, num_flds;
2060 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2061 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2062 uint32_t encap_flds;
2064 /* Initialize the blob data */
2065 if (!ulp_blob_init(&data, tbl->result_bit_size,
2066 parms->device_params->byte_order)) {
2067 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2071 /* Get the result fields list */
2072 flds = ulp_mapper_result_fields_get(parms, tbl, &num_flds, &encap_flds);
2074 if (!flds || !num_flds || encap_flds) {
2075 BNXT_TF_DBG(ERR, "template undefined for the IF table\n");
2079 /* process the result fields, loop through them */
2080 for (i = 0; i < num_flds; i++) {
2081 /* Process the result fields */
2082 rc = ulp_mapper_result_field_process(parms,
2088 BNXT_TF_DBG(ERR, "data field failed\n");
2093 /* Get the index details from computed field */
2094 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_COMP_FIELD) {
2095 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->index_operand);
2096 } else if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_CONSTANT) {
2097 idx = tbl->index_operand;
2099 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2103 /* Perform the tf table set by filling the set params */
2104 iftbl_params.dir = tbl->direction;
2105 iftbl_params.type = tbl->resource_type;
2106 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2107 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2108 iftbl_params.idx = idx;
2110 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2112 BNXT_TF_DBG(ERR, "Set table[%d][%s][%x] failed rc=%d\n",
2113 iftbl_params.type,/* TBD: add tf_if_tbl_2_str */
2114 tf_dir_2_str(iftbl_params.dir),
2115 iftbl_params.idx, rc);
2120 * TBD: Need to look at the need to store idx in flow db for restore
2121 * the table to its original state on deletion of this entry.
2127 * Process the identifier list in the generic table.
2128 * Extract the ident from the generic table entry and
2129 * write it to the reg file.
2132 ulp_mapper_gen_tbl_ident_scan(struct bnxt_ulp_mapper_parms *parms,
2133 struct bnxt_ulp_mapper_tbl_info *tbl,
2134 struct ulp_mapper_gen_tbl_entry *gen_tbl_ent)
2136 struct bnxt_ulp_mapper_ident_info *idents;
2137 uint32_t i, idx, num_idents = 0;
2140 /* Get the ident list */
2141 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
2143 for (i = 0; i < num_idents; i++) {
2144 /* Extract the index from the result byte data array */
2145 rc = ulp_mapper_gen_tbl_entry_data_get(gen_tbl_ent,
2146 idents[i].ident_bit_pos,
2147 idents[i].ident_bit_size,
2151 /* validate the extraction */
2153 BNXT_TF_DBG(ERR, "failed to read %s:%x:%x\n",
2154 idents[i].description,
2155 idents[i].ident_bit_pos,
2156 idents[i].ident_bit_size);
2160 /* Write it to the regfile */
2161 if (!ulp_regfile_write(parms->regfile,
2162 idents[i].regfile_idx, idx)) {
2163 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
2164 idents[i].regfile_idx);
2172 * Process the identifier list in the generic table.
2173 * Write the ident to the generic table entry
2176 ulp_mapper_gen_tbl_ident_write(struct bnxt_ulp_mapper_parms *parms,
2177 struct bnxt_ulp_mapper_tbl_info *tbl,
2178 struct ulp_mapper_gen_tbl_entry *gen_tbl_ent)
2180 struct bnxt_ulp_mapper_ident_info *idents;
2181 uint32_t i, num_idents = 0;
2184 /* Get the ident list */
2185 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
2187 for (i = 0; i < num_idents; i++) {
2188 /* read from the regfile */
2189 if (!ulp_regfile_read(parms->regfile, idents[i].regfile_idx,
2191 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n",
2192 idents[i].regfile_idx);
2196 /* Update the gen tbl entry with the new data */
2197 ulp_mapper_gen_tbl_entry_data_set(gen_tbl_ent,
2198 idents[i].ident_bit_pos,
2199 idents[i].ident_bit_size,
2206 ulp_mapper_gen_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2207 struct bnxt_ulp_mapper_tbl_info *tbl)
2209 struct bnxt_ulp_mapper_key_field_info *kflds;
2210 struct ulp_flow_db_res_params fid_parms;
2211 struct ulp_mapper_gen_tbl_entry gen_tbl_ent;
2213 struct ulp_blob key;
2216 uint32_t i, ckey, num_kflds = 0;
2217 uint32_t gen_tbl_hit = 0, fdb_write = 0;
2220 /* Get the key fields list and build the key. */
2221 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2222 if (!kflds || !num_kflds) {
2223 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2226 if (!ulp_blob_init(&key, tbl->key_bit_size,
2227 parms->device_params->byte_order)) {
2228 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2231 for (i = 0; i < num_kflds; i++) {
2233 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
2235 &key, 1, "Gen Tbl Key");
2238 "Failed to create key for Gen tbl rc=%d\n",
2244 /* Calculate the table index for the generic table*/
2245 tbl_idx = ulp_mapper_gen_tbl_idx_calculate(tbl->resource_sub_type,
2248 BNXT_TF_DBG(ERR, "Invalid table index %x:%x\n",
2249 tbl->resource_sub_type, tbl->direction);
2253 /* The_key is a byte array convert it to a search index */
2254 cache_key = ulp_blob_data_get(&key, &tmplen);
2255 memcpy(&ckey, cache_key, sizeof(ckey));
2256 /* Get the generic table entry */
2257 rc = ulp_mapper_gen_tbl_entry_get(parms->ulp_ctx,
2258 tbl_idx, ckey, &gen_tbl_ent);
2261 "Failed to create key for Gen tbl rc=%d\n", rc);
2264 switch (tbl->tbl_opcode) {
2265 case BNXT_ULP_GENERIC_TBL_OPC_READ:
2266 /* check the reference count */
2267 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2268 /* Scan ident list and create the result blob*/
2269 rc = ulp_mapper_gen_tbl_ident_scan(parms, tbl,
2273 "Failed to scan ident list\n");
2276 /* increment the reference count */
2277 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2284 case BNXT_ULP_GENERIC_TBL_OPC_WRITE:
2285 /* check the reference count */
2286 if (ULP_GEN_TBL_REF_CNT(&gen_tbl_ent)) {
2287 /* a hit then error */
2288 BNXT_TF_DBG(ERR, "generic entry already present %x\n",
2290 return -EINVAL; /* success */
2293 /* Create the result blob from the ident list */
2294 rc = ulp_mapper_gen_tbl_ident_write(parms, tbl, &gen_tbl_ent);
2297 "Failed to write ident list\n");
2301 /* increment the reference count */
2302 ULP_GEN_TBL_REF_CNT_INC(&gen_tbl_ent);
2306 BNXT_TF_DBG(ERR, "Invalid table opcode %x\n", tbl->tbl_opcode);
2310 /* Set the generic entry hit */
2311 rc = ulp_regfile_write(parms->regfile,
2312 BNXT_ULP_REGFILE_INDEX_GENERIC_TBL_HIT,
2315 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2316 tbl->index_operand);
2320 /* add the entry to the flow database */
2322 memset(&fid_parms, 0, sizeof(fid_parms));
2323 fid_parms.direction = tbl->direction;
2324 fid_parms.resource_func = tbl->resource_func;
2325 fid_parms.resource_sub_type = tbl->resource_sub_type;
2326 fid_parms.resource_hndl = ckey;
2327 fid_parms.critical_resource = tbl->critical_resource;
2328 rc = ulp_mapper_fdb_opc_process(parms, tbl, &fid_parms);
2330 BNXT_TF_DBG(ERR, "Fail to add gen ent flowdb %d\n", rc);
2336 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2337 struct bnxt_ulp_mapper_data *mapper_data)
2339 struct bnxt_ulp_glb_resource_info *glb_res;
2340 uint32_t num_glb_res_ids, idx;
2343 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
2344 if (!glb_res || !num_glb_res_ids) {
2345 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2349 /* Iterate the global resources and process each one */
2350 for (idx = 0; idx < num_glb_res_ids; idx++) {
2351 switch (glb_res[idx].resource_func) {
2352 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2353 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
2357 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2358 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2363 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2364 glb_res[idx].resource_func);
2375 * Function to process the memtype opcode of the mapper table.
2376 * returns 1 to skip the table.
2377 * return 0 to continue processing the table.
2382 ulp_mapper_tbl_memtype_opcode_process(struct bnxt_ulp_mapper_parms *parms,
2383 struct bnxt_ulp_mapper_tbl_info *tbl)
2385 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
2388 bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2390 switch (tbl->mem_type_opcode) {
2391 case BNXT_ULP_MEM_TYPE_OPCODE_EXECUTE_IF_INT:
2392 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT)
2395 case BNXT_ULP_MEM_TYPE_OPCODE_EXECUTE_IF_EXT:
2396 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT)
2399 case BNXT_ULP_MEM_TYPE_OPCODE_NOP:
2404 "Invalid arg in mapper in memtype opcode\n");
2411 * Common conditional opcode process routine that is used for both the template
2412 * rejection and table conditional execution.
2415 ulp_mapper_cond_opc_process(struct bnxt_ulp_mapper_parms *parms,
2416 enum bnxt_ulp_cond_opc opc,
2426 case BNXT_ULP_COND_OPC_COMP_FIELD_IS_SET:
2427 if (operand < BNXT_ULP_CF_IDX_LAST) {
2428 *res = ULP_COMP_FLD_IDX_RD(parms, operand);
2430 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
2435 case BNXT_ULP_COND_OPC_COMP_FIELD_NOT_SET:
2436 if (operand < BNXT_ULP_CF_IDX_LAST) {
2437 *res = !ULP_COMP_FLD_IDX_RD(parms, operand);
2439 BNXT_TF_DBG(ERR, "comp field out of bounds %d\n",
2444 case BNXT_ULP_COND_OPC_ACTION_BIT_IS_SET:
2445 if (operand < BNXT_ULP_ACTION_BIT_LAST) {
2446 *res = ULP_BITMAP_ISSET(parms->act_bitmap->bits,
2449 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
2454 case BNXT_ULP_COND_OPC_ACTION_BIT_NOT_SET:
2455 if (operand < BNXT_ULP_ACTION_BIT_LAST) {
2456 *res = !ULP_BITMAP_ISSET(parms->act_bitmap->bits,
2459 BNXT_TF_DBG(ERR, "action bit out of bounds %d\n",
2464 case BNXT_ULP_COND_OPC_HDR_BIT_IS_SET:
2465 if (operand < BNXT_ULP_HDR_BIT_LAST) {
2466 *res = ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
2469 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
2474 case BNXT_ULP_COND_OPC_HDR_BIT_NOT_SET:
2475 if (operand < BNXT_ULP_HDR_BIT_LAST) {
2476 *res = !ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
2479 BNXT_TF_DBG(ERR, "header bit out of bounds %d\n",
2484 case BNXT_ULP_COND_OPC_FIELD_BIT_IS_SET:
2485 idx = (parms->class_tid << BNXT_ULP_GLB_FIELD_TBL_SHIFT) |
2487 bit = ulp_mapper_glb_field_tbl_get(idx);
2489 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
2493 *res = ULP_BITMAP_ISSET(parms->fld_bitmap->bits, (1 << *bit));
2495 case BNXT_ULP_COND_OPC_FIELD_BIT_NOT_SET:
2496 idx = (parms->class_tid << BNXT_ULP_GLB_FIELD_TBL_SHIFT) |
2498 bit = ulp_mapper_glb_field_tbl_get(idx);
2500 BNXT_TF_DBG(ERR, "invalid ulp_glb_field_tbl idx %d\n",
2504 *res = !ULP_BITMAP_ISSET(parms->fld_bitmap->bits, (1 << *bit));
2506 case BNXT_ULP_COND_OPC_REGFILE_IS_SET:
2507 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
2508 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
2513 case BNXT_ULP_COND_OPC_REGFILE_NOT_SET:
2514 if (!ulp_regfile_read(parms->regfile, operand, ®val)) {
2515 BNXT_TF_DBG(ERR, "regfile[%d] read oob\n", operand);
2521 BNXT_TF_DBG(ERR, "Invalid conditional opcode %d\n", opc);
2529 * Processes a list of conditions and returns both a status and result of the
2530 * list. The status must be checked prior to verifying the result.
2532 * returns 0 for success, negative on failure
2533 * returns res = 1 for true, res = 0 for false.
2536 ulp_mapper_cond_opc_list_process(struct bnxt_ulp_mapper_parms *parms,
2537 enum bnxt_ulp_cond_list_opc list_opc,
2538 struct bnxt_ulp_mapper_cond_info *list,
2543 int32_t rc = 0, trc;
2546 case BNXT_ULP_COND_LIST_OPC_AND:
2547 /* AND Defaults to true. */
2550 case BNXT_ULP_COND_LIST_OPC_OR:
2551 /* OR Defaults to false. */
2554 case BNXT_ULP_COND_LIST_OPC_TRUE:
2557 case BNXT_ULP_COND_LIST_OPC_FALSE:
2561 BNXT_TF_DBG(ERR, "Invalid conditional list opcode %d\n",
2566 for (i = 0; i < num; i++) {
2567 rc = ulp_mapper_cond_opc_process(parms,
2568 list[i].cond_opcode,
2569 list[i].cond_operand,
2574 if (list_opc == BNXT_ULP_COND_LIST_OPC_AND) {
2575 /* early return if result is ever zero */
2581 /* early return if result is ever non-zero */
2593 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
2595 struct bnxt_ulp_mapper_cond_info *cond_tbls = NULL;
2596 enum bnxt_ulp_cond_list_opc cond_opc;
2597 struct bnxt_ulp_mapper_tbl_info *tbls;
2598 struct bnxt_ulp_mapper_tbl_info *tbl;
2599 uint32_t num_tbls, i, num_cond_tbls;
2600 int32_t rc = -EINVAL, cond_rc = 0;
2602 cond_tbls = ulp_mapper_tmpl_reject_list_get(parms, tid,
2606 * Process the reject list if exists, otherwise assume that the
2607 * template is allowed.
2609 if (cond_tbls && num_cond_tbls) {
2610 rc = ulp_mapper_cond_opc_list_process(parms,
2618 /* Reject the template if True */
2620 BNXT_TF_DBG(ERR, "%s Template %d rejected.\n",
2621 (parms->tmpl_type ==
2622 BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
2623 "class" : "action", tid);
2628 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
2629 if (!tbls || !num_tbls) {
2630 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
2631 (parms->tmpl_type == BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
2632 "class" : "action", parms->dev_id, tid);
2636 for (i = 0; i < num_tbls; i++) {
2639 /* Handle the table level opcodes to determine if required. */
2640 if (ulp_mapper_tbl_memtype_opcode_process(parms, tbl))
2642 cond_tbls = ulp_mapper_tbl_execute_list_get(parms, tbl,
2645 rc = ulp_mapper_cond_opc_list_process(parms, cond_opc,
2646 cond_tbls, num_cond_tbls,
2649 BNXT_TF_DBG(ERR, "Failed to process cond opc list "
2653 /* Skip the table if False */
2657 switch (tbl->resource_func) {
2658 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2659 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
2661 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2662 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2663 rc = ulp_mapper_em_tbl_process(parms, tbl);
2665 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2666 rc = ulp_mapper_index_tbl_process(parms, tbl);
2668 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
2669 rc = ulp_mapper_if_tbl_process(parms, tbl);
2671 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
2672 rc = ulp_mapper_gen_tbl_process(parms, tbl);
2674 case BNXT_ULP_RESOURCE_FUNC_INVALID:
2678 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
2679 tbl->resource_func);
2685 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2686 tbl->resource_func);
2693 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
2694 (parms->tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
2695 "class" : "action", parms->dev_id, tid);
2700 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
2702 struct ulp_flow_db_res_params *res)
2708 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
2712 tfp = bnxt_ulp_cntxt_tfp_get(ulp);
2714 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
2718 switch (res->resource_func) {
2719 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2720 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
2722 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2723 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2724 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
2726 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2727 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
2729 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2730 rc = ulp_mapper_ident_free(ulp, tfp, res);
2732 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
2733 rc = ulp_mapper_mark_free(ulp, res);
2735 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
2736 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
2738 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
2739 rc = ulp_mapper_child_flow_free(ulp, fid, res);
2741 case BNXT_ULP_RESOURCE_FUNC_GENERIC_TABLE:
2742 rc = ulp_mapper_gen_tbl_res_free(ulp, res);
2752 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
2753 enum bnxt_ulp_fdb_type flow_type,
2756 struct ulp_flow_db_res_params res_parms = { 0 };
2760 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2765 * Set the critical resource on the first resource del, then iterate
2766 * while status is good
2768 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
2769 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
2773 * This is unexpected on the first call to resource del.
2774 * It likely means that the flow did not exist in the flow db.
2776 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
2777 flow_type, fid, rc);
2782 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
2785 * On fail, we still need to attempt to free the
2786 * remaining resources. Don't return
2789 "Flow[%d][0x%x] Res[%d][0x%016" PRIx64
2790 "] failed rc=%d.\n",
2791 flow_type, fid, res_parms.resource_func,
2792 res_parms.resource_hndl, trc);
2794 /* All subsequent call require the non-critical_resource */
2795 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
2797 rc = ulp_flow_db_resource_del(ulp_ctx,
2803 /* Free the Flow ID since we've removed all resources */
2804 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
2810 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
2811 struct bnxt_ulp_mapper_data *mapper_data)
2813 struct bnxt_ulp_mapper_glb_resource_entry *ent;
2814 struct ulp_flow_db_res_params res;
2817 /* Iterate the global resources and process each one */
2818 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
2819 for (idx = 0; idx < BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
2821 ent = &mapper_data->glb_res_tbl[dir][idx];
2822 if (ent->resource_func ==
2823 BNXT_ULP_RESOURCE_FUNC_INVALID)
2825 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
2826 res.resource_func = ent->resource_func;
2827 res.direction = dir;
2828 res.resource_type = ent->resource_type;
2829 /*convert it from BE to cpu */
2831 tfp_be_to_cpu_64(ent->resource_hndl);
2832 ulp_mapper_resource_free(ulp_ctx, 0, &res);
2838 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
2839 enum bnxt_ulp_fdb_type flow_type,
2845 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2849 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
2853 /* Function to handle the default global templates that are allocated during
2854 * the startup and reused later.
2857 ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx)
2859 uint32_t *glbl_tmpl_list;
2860 uint32_t num_glb_tmpls, idx, dev_id;
2861 struct bnxt_ulp_mapper_parms parms;
2862 struct bnxt_ulp_mapper_data *mapper_data;
2865 glbl_tmpl_list = ulp_mapper_glb_template_table_get(&num_glb_tmpls);
2866 if (!glbl_tmpl_list || !num_glb_tmpls)
2867 return rc; /* No global templates to process */
2869 /* Get the device id from the ulp context */
2870 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
2871 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2875 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2877 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2881 /* Iterate the global resources and process each one */
2882 for (idx = 0; idx < num_glb_tmpls; idx++) {
2883 /* Initialize the parms structure */
2884 memset(&parms, 0, sizeof(parms));
2885 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2886 parms.ulp_ctx = ulp_ctx;
2887 parms.dev_id = dev_id;
2888 parms.mapper_data = mapper_data;
2889 parms.flow_type = BNXT_ULP_FDB_TYPE_DEFAULT;
2890 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
2892 /* Get the class table entry from dev id and class id */
2893 parms.class_tid = glbl_tmpl_list[idx];
2895 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2896 if (!parms.device_params) {
2897 BNXT_TF_DBG(ERR, "No device for device id %d\n",
2902 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
2909 /* Function to handle the mapping of the Flow to be compatible
2910 * with the underlying hardware.
2913 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
2914 struct bnxt_ulp_mapper_create_parms *cparms)
2916 struct bnxt_ulp_mapper_parms parms;
2917 struct ulp_regfile regfile;
2920 if (!ulp_ctx || !cparms)
2923 /* Initialize the parms structure */
2924 memset(&parms, 0, sizeof(parms));
2925 parms.act_prop = cparms->act_prop;
2926 parms.act_bitmap = cparms->act;
2927 parms.hdr_bitmap = cparms->hdr_bitmap;
2928 parms.regfile = ®file;
2929 parms.hdr_field = cparms->hdr_field;
2930 parms.comp_fld = cparms->comp_fld;
2931 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2932 parms.ulp_ctx = ulp_ctx;
2933 parms.act_tid = cparms->act_tid;
2934 parms.class_tid = cparms->class_tid;
2935 parms.flow_type = cparms->flow_type;
2936 parms.parent_flow = cparms->parent_flow;
2937 parms.parent_fid = cparms->parent_fid;
2938 parms.fid = cparms->flow_id;
2939 parms.tun_idx = cparms->tun_idx;
2941 /* Get the device id from the ulp context */
2942 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
2943 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2947 /* Get the device params, it will be used in later processing */
2948 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2949 if (!parms.device_params) {
2950 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
2956 * Get the mapper data for dynamic mapper data such as default
2959 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
2960 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2961 if (!parms.mapper_data) {
2962 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2966 /* initialize the registry file for further processing */
2967 if (!ulp_regfile_init(parms.regfile)) {
2968 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
2972 rc = ulp_regfile_write(parms.regfile,
2973 BNXT_ULP_REGFILE_INDEX_CLASS_TID,
2974 tfp_cpu_to_be_64((uint64_t)parms.class_tid));
2976 BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
2980 /* Process the action template list from the selected action table*/
2981 if (parms.act_tid) {
2982 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
2983 /* Process the action template tables */
2984 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
2989 if (parms.class_tid) {
2990 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
2992 /* Process the class template tables.*/
2993 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
2998 /* setup the parent-child details */
2999 if (parms.parent_flow) {
3000 /* create a parent flow details */
3001 rc = ulp_flow_db_parent_flow_create(&parms);
3004 } else if (parms.parent_fid) {
3005 /* create a child flow details */
3006 rc = ulp_flow_db_child_flow_create(&parms);
3014 /* Free all resources that were allocated during flow creation */
3015 trc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
3018 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
3024 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
3026 struct bnxt_ulp_mapper_data *data;
3033 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3037 data = rte_zmalloc("ulp_mapper_data",
3038 sizeof(struct bnxt_ulp_mapper_data), 0);
3040 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
3044 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
3045 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
3046 /* Don't call deinit since the prof_func wasn't allocated. */
3051 /* Allocate the global resource ids */
3052 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
3054 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
3058 /* Allocate the generic table list */
3059 rc = ulp_mapper_generic_tbl_list_init(data);
3061 BNXT_TF_DBG(ERR, "Failed to initialize generic tbl list\n");
3065 /* Allocate global template table entries */
3066 rc = ulp_mapper_glb_template_table_init(ulp_ctx);
3068 BNXT_TF_DBG(ERR, "Failed to initialize global templates\n");
3074 /* Ignore the return code in favor of returning the original error. */
3075 ulp_mapper_deinit(ulp_ctx);
3080 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
3082 struct bnxt_ulp_mapper_data *data;
3087 "Failed to acquire ulp context, so data may "
3088 "not be released.\n");
3092 data = (struct bnxt_ulp_mapper_data *)
3093 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
3095 /* Go ahead and return since there is no allocated data. */
3096 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
3100 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
3102 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
3103 /* Free the mapper data regardless of errors. */
3104 goto free_mapper_data;
3107 /* Free the global resource info table entries */
3108 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
3111 /* Free the generic table */
3112 (void)ulp_mapper_generic_tbl_list_deinit(data);
3115 /* Reset the data pointer within the ulp_ctx. */
3116 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);