1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2020 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"
21 static struct bnxt_ulp_glb_resource_info *
22 ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
26 *num_entries = BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
27 return ulp_glb_resource_tbl;
31 * Read the global resource from the mapper global resource list
33 * The regval is always returned in big-endian.
35 * returns 0 on success
38 ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
43 if (!mapper_data || !regval ||
44 dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
47 *regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
52 * Write a global resource to the mapper global resource list
54 * The regval value must be in big-endian.
56 * return 0 on success.
59 ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
60 struct bnxt_ulp_glb_resource_info *res,
63 struct bnxt_ulp_mapper_glb_resource_entry *ent;
65 /* validate the arguments */
66 if (!data || res->direction >= TF_DIR_MAX ||
67 res->glb_regfile_index >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
70 /* write to the mapper data */
71 ent = &data->glb_res_tbl[res->direction][res->glb_regfile_index];
72 ent->resource_func = res->resource_func;
73 ent->resource_type = res->resource_type;
74 ent->resource_hndl = regval;
79 * Internal function to allocate identity resource and store it in mapper data.
81 * returns 0 on success
84 ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
85 struct bnxt_ulp_mapper_data *mapper_data,
86 struct bnxt_ulp_glb_resource_info *glb_res)
88 struct tf_alloc_identifier_parms iparms = { 0 };
89 struct tf_free_identifier_parms fparms;
94 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
98 iparms.ident_type = glb_res->resource_type;
99 iparms.dir = glb_res->direction;
101 /* Allocate the Identifier using tf api */
102 rc = tf_alloc_identifier(tfp, &iparms);
104 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
105 (iparms.dir == TF_DIR_RX) ? "RX" : "TX",
110 /* entries are stored as big-endian format */
111 regval = tfp_cpu_to_be_64((uint64_t)iparms.id);
112 /* write to the mapper global resource */
113 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
115 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
116 /* Free the identifier when update failed */
117 fparms.dir = iparms.dir;
118 fparms.ident_type = iparms.ident_type;
119 fparms.id = iparms.id;
120 tf_free_identifier(tfp, &fparms);
127 * Internal function to allocate index tbl resource and store it in mapper data.
129 * returns 0 on success
132 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
133 struct bnxt_ulp_mapper_data *mapper_data,
134 struct bnxt_ulp_glb_resource_info *glb_res)
136 struct tf_alloc_tbl_entry_parms aparms = { 0 };
137 struct tf_free_tbl_entry_parms free_parms = { 0 };
140 uint32_t tbl_scope_id;
143 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
147 /* Get the scope id */
148 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &tbl_scope_id);
150 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
154 aparms.type = glb_res->resource_type;
155 aparms.dir = glb_res->direction;
156 aparms.search_enable = BNXT_ULP_SEARCH_BEFORE_ALLOC_NO;
157 aparms.tbl_scope_id = tbl_scope_id;
159 /* Allocate the index tbl using tf api */
160 rc = tf_alloc_tbl_entry(tfp, &aparms);
162 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
163 (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
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 cache initialization parameters for the tbl_idx */
185 static struct bnxt_ulp_cache_tbl_params *
186 ulp_mapper_cache_tbl_params_get(uint32_t tbl_idx)
188 if (tbl_idx >= BNXT_ULP_CACHE_TBL_MAX_SZ)
191 return &ulp_cache_tbl_params[tbl_idx];
194 /* Retrieve the global template table */
196 ulp_mapper_glb_template_table_get(uint32_t *num_entries)
200 *num_entries = BNXT_ULP_GLB_TEMPLATE_TBL_MAX_SZ;
201 return ulp_glb_template_tbl;
205 * Get the size of the action property for a given index.
207 * idx [in] The index for the action property
209 * returns the size of the action property.
212 ulp_mapper_act_prop_size_get(uint32_t idx)
214 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
216 return ulp_act_prop_map_table[idx];
220 * Get a list of classifier tables that implement the flow
221 * Gets a device dependent list of tables that implement the class template id
223 * mparms [in] The mappers parms with data related to the flow.
225 * tid [in] The template id that matches the flow
227 * num_tbls [out] The number of classifier tables in the returned array
229 * returns An array of classifier tables to implement the flow, or NULL on
232 static struct bnxt_ulp_mapper_tbl_info *
233 ulp_mapper_tbl_list_get(struct bnxt_ulp_mapper_parms *mparms,
238 const struct ulp_template_device_tbls *dev_tbls;
240 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
242 idx = dev_tbls->tmpl_list[tid].start_tbl_idx;
243 *num_tbls = dev_tbls->tmpl_list[tid].num_tbls;
245 return &dev_tbls->tbl_list[idx];
249 * Get the list of key fields that implement the flow.
251 * mparms [in] The mapper parms with information about the flow
253 * tbl [in] A single table instance to get the key fields from
255 * num_flds [out] The number of key fields in the returned array
257 * Returns array of Key fields, or NULL on error.
259 static struct bnxt_ulp_mapper_key_field_info *
260 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_parms *mparms,
261 struct bnxt_ulp_mapper_tbl_info *tbl,
265 const struct ulp_template_device_tbls *dev_tbls;
267 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
268 if (!dev_tbls->key_field_list) {
273 idx = tbl->key_start_idx;
274 *num_flds = tbl->key_num_fields;
276 return &dev_tbls->key_field_list[idx];
280 * Get the list of data fields that implement the flow.
282 * mparms [in] The mapper parms with information about the flow
284 * tbl [in] A single table instance to get the data fields from
286 * num_flds [out] The number of data fields in the returned array.
288 * num_encap_flds [out] The number of encap fields in the returned array.
290 * Returns array of data fields, or NULL on error.
292 static struct bnxt_ulp_mapper_result_field_info *
293 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_parms *mparms,
294 struct bnxt_ulp_mapper_tbl_info *tbl,
296 uint32_t *num_encap_flds)
299 const struct ulp_template_device_tbls *dev_tbls;
301 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
302 if (!dev_tbls->result_field_list) {
308 idx = tbl->result_start_idx;
309 *num_flds = tbl->result_num_fields;
310 *num_encap_flds = tbl->encap_num_fields;
312 return &dev_tbls->result_field_list[idx];
316 * Get the list of ident fields that implement the flow
318 * tbl [in] A single table instance to get the ident fields from
320 * num_flds [out] The number of ident fields in the returned array
322 * returns array of ident fields, or NULL on error
324 static struct bnxt_ulp_mapper_ident_info *
325 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_parms *mparms,
326 struct bnxt_ulp_mapper_tbl_info *tbl,
330 const struct ulp_template_device_tbls *dev_tbls;
332 dev_tbls = &mparms->device_params->dev_tbls[mparms->tmpl_type];
333 if (!dev_tbls->ident_list) {
338 idx = tbl->ident_start_idx;
339 *num_flds = tbl->ident_nums;
341 return &dev_tbls->ident_list[idx];
344 static struct bnxt_ulp_mapper_cache_entry *
345 ulp_mapper_cache_entry_get(struct bnxt_ulp_context *ulp,
349 struct bnxt_ulp_mapper_data *mapper_data;
351 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp);
352 if (!mapper_data || id >= BNXT_ULP_CACHE_TBL_MAX_SZ ||
353 !mapper_data->cache_tbl[id]) {
354 BNXT_TF_DBG(ERR, "Unable to acquire the cache tbl (%d)\n", id);
358 return &mapper_data->cache_tbl[id][key];
362 * Concatenates the tbl_type and tbl_id into a 32bit value for storing in the
363 * resource_type. This is done to conserve memory since both the tbl_type and
367 ulp_mapper_cache_res_type_set(struct ulp_flow_db_res_params *res,
371 res->resource_type = tbl_type;
372 res->resource_sub_type = tbl_id;
375 /* Extracts the tbl_type and tbl_id from the 32bit resource type. */
377 ulp_mapper_cache_res_type_get(struct ulp_flow_db_res_params *res,
381 *tbl_type = res->resource_type;
382 *tbl_id = res->resource_sub_type;
386 ulp_mapper_cache_entry_free(struct bnxt_ulp_context *ulp,
388 struct ulp_flow_db_res_params *res)
390 struct bnxt_ulp_mapper_cache_entry *cache_entry;
391 struct tf_free_identifier_parms ident_parms;
392 struct tf_free_tcam_entry_parms tcam_parms;
393 uint16_t table_id, table_type;
397 * The table id, used for cache, and table_type, used for tcam, are
398 * both encoded within the resource. We must first extract them to
399 * formulate the args for tf calls.
401 ulp_mapper_cache_res_type_get(res, &table_type, &table_id);
402 cache_entry = ulp_mapper_cache_entry_get(ulp, table_id,
403 (uint16_t)res->resource_hndl);
404 if (!cache_entry || !cache_entry->ref_count) {
405 BNXT_TF_DBG(ERR, "Cache entry (%d:%d) not valid on free.\n",
406 table_id, (uint16_t)res->resource_hndl);
411 * See if we need to delete the entry. The tcam and identifiers are all
412 * tracked by the cached entries reference count. All are deleted when
413 * the reference count hit zero.
415 cache_entry->ref_count--;
416 if (cache_entry->ref_count)
420 * Need to delete the tcam entry and the allocated identifiers.
421 * In the event of a failure, need to try to delete the remaining
422 * resources before returning error.
424 tcam_parms.dir = res->direction;
425 tcam_parms.tcam_tbl_type = table_type;
426 tcam_parms.idx = cache_entry->tcam_idx;
427 rc = tf_free_tcam_entry(tfp, &tcam_parms);
429 BNXT_TF_DBG(ERR, "Failed to free tcam [%d][%s][0x%04x] rc=%d\n",
431 (res->direction == TF_DIR_RX) ? "RX" : "TX",
435 * Free the identifiers associated with the tcam entry. Entries with
436 * negative one are considered uninitialized.
438 for (i = 0; i < BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM; i++) {
439 if (cache_entry->idents[i] == ULP_IDENTS_INVALID)
442 ident_parms.dir = res->direction;
443 ident_parms.ident_type = cache_entry->ident_types[i];
444 ident_parms.id = cache_entry->idents[i];
445 trc = tf_free_identifier(tfp, &ident_parms);
447 BNXT_TF_DBG(ERR, "Failed to free identifier "
448 "[%d][%s][0x%04x] rc=%d\n",
449 ident_parms.ident_type,
450 (res->direction == TF_DIR_RX) ? "RX" : "TX",
451 ident_parms.id, trc);
459 static inline int32_t
460 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp __rte_unused,
462 struct ulp_flow_db_res_params *res)
464 struct tf_free_tcam_entry_parms fparms = {
465 .dir = res->direction,
466 .tcam_tbl_type = res->resource_type,
467 .idx = (uint16_t)res->resource_hndl
470 return tf_free_tcam_entry(tfp, &fparms);
473 static inline int32_t
474 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
476 struct ulp_flow_db_res_params *res)
478 struct tf_free_tbl_entry_parms fparms = {
479 .dir = res->direction,
480 .type = res->resource_type,
481 .idx = (uint32_t)res->resource_hndl
485 * Just get the table scope, it will be ignored if not necessary
486 * by the tf_free_tbl_entry
488 (void)bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
490 return tf_free_tbl_entry(tfp, &fparms);
493 static inline int32_t
494 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
496 struct ulp_flow_db_res_params *res)
498 struct tf_delete_em_entry_parms fparms = { 0 };
501 fparms.dir = res->direction;
502 if (res->resource_func == BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE)
503 fparms.mem = TF_MEM_EXTERNAL;
505 fparms.mem = TF_MEM_INTERNAL;
506 fparms.flow_handle = res->resource_hndl;
508 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
510 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
514 return tf_delete_em_entry(tfp, &fparms);
517 static inline int32_t
518 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
520 struct ulp_flow_db_res_params *res)
522 struct tf_free_identifier_parms fparms = {
523 .dir = res->direction,
524 .ident_type = res->resource_type,
525 .id = (uint16_t)res->resource_hndl
528 return tf_free_identifier(tfp, &fparms);
531 static inline int32_t
532 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
533 struct ulp_flow_db_res_params *res)
535 return ulp_mark_db_mark_del(ulp,
541 static inline int32_t
542 ulp_mapper_parent_flow_free(struct bnxt_ulp_context *ulp,
544 struct ulp_flow_db_res_params *res)
546 uint32_t idx, child_fid = 0, parent_idx;
547 struct bnxt_ulp_flow_db *flow_db;
549 parent_idx = (uint32_t)res->resource_hndl;
551 /* check the validity of the parent fid */
552 if (ulp_flow_db_parent_flow_idx_get(ulp, parent_fid, &idx) ||
554 BNXT_TF_DBG(ERR, "invalid parent flow id %x\n", parent_fid);
558 /* Clear all the child flows parent index */
559 flow_db = bnxt_ulp_cntxt_ptr2_flow_db_get(ulp);
560 while (!ulp_flow_db_parent_child_flow_next_entry_get(flow_db, idx,
562 /* update the child flows resource handle */
563 if (ulp_flow_db_child_flow_reset(ulp, BNXT_ULP_FDB_TYPE_REGULAR,
565 BNXT_TF_DBG(ERR, "failed to reset child flow %x\n",
571 /* free the parent entry in the parent table flow */
572 if (ulp_flow_db_parent_flow_free(ulp, parent_fid)) {
573 BNXT_TF_DBG(ERR, "failed to free parent flow %x\n", parent_fid);
579 static inline int32_t
580 ulp_mapper_child_flow_free(struct bnxt_ulp_context *ulp,
582 struct ulp_flow_db_res_params *res)
586 parent_fid = (uint32_t)res->resource_hndl;
588 return 0; /* Already freed - orphan child*/
590 /* reset the child flow bitset*/
591 if (ulp_flow_db_parent_child_flow_set(ulp, parent_fid, child_fid, 0)) {
592 BNXT_TF_DBG(ERR, "error in resetting child flow bitset %x:%x\n",
593 parent_fid, child_fid);
600 * Process the identifier instruction and either store it in the flow database
601 * or return it in the val (if not NULL) on success. If val is NULL, the
602 * identifier is to be stored in the flow database.
605 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
606 struct bnxt_ulp_mapper_tbl_info *tbl,
607 struct bnxt_ulp_mapper_ident_info *ident,
610 struct ulp_flow_db_res_params fid_parms;
613 struct tf_alloc_identifier_parms iparms = { 0 };
614 struct tf_free_identifier_parms free_parms = { 0 };
618 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
620 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
624 idx = ident->regfile_idx;
626 iparms.ident_type = ident->ident_type;
627 iparms.dir = tbl->direction;
629 rc = tf_alloc_identifier(tfp, &iparms);
631 BNXT_TF_DBG(ERR, "Alloc ident %s:%d failed.\n",
632 (iparms.dir == TF_DIR_RX) ? "RX" : "TX",
637 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
638 if (!ulp_regfile_write(parms->regfile, idx, id)) {
639 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
641 /* Need to free the identifier, so goto error */
645 /* Link the resource to the flow in the flow db */
647 memset(&fid_parms, 0, sizeof(fid_parms));
648 fid_parms.direction = tbl->direction;
649 fid_parms.resource_func = ident->resource_func;
650 fid_parms.resource_type = ident->ident_type;
651 fid_parms.resource_hndl = iparms.id;
652 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
654 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
659 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
661 /* Need to free the identifier, so goto error */
671 /* Need to free the identifier */
672 free_parms.dir = tbl->direction;
673 free_parms.ident_type = ident->ident_type;
674 free_parms.id = iparms.id;
676 (void)tf_free_identifier(tfp, &free_parms);
678 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
680 (tbl->direction == TF_DIR_RX) ? "RX" : "TX");
685 * Process the identifier instruction and extract it from result blob.
686 * Increment the identifier reference count and store it in the flow database.
689 ulp_mapper_ident_extract(struct bnxt_ulp_mapper_parms *parms,
690 struct bnxt_ulp_mapper_tbl_info *tbl,
691 struct bnxt_ulp_mapper_ident_info *ident,
692 struct ulp_blob *res_blob)
694 struct ulp_flow_db_res_params fid_parms;
697 struct tf_search_identifier_parms sparms = { 0 };
698 struct tf_free_identifier_parms free_parms = { 0 };
702 /* Get the tfp from ulp context */
703 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
705 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
709 /* Extract the index from the result blob */
710 rc = ulp_blob_pull(res_blob, (uint8_t *)&idx, sizeof(idx),
711 ident->ident_bit_pos, ident->ident_bit_size);
713 BNXT_TF_DBG(ERR, "Failed to extract identifier from blob\n");
717 /* populate the search params and search identifier shadow table */
718 sparms.ident_type = ident->ident_type;
719 sparms.dir = tbl->direction;
720 /* convert the idx into cpu format */
721 sparms.search_id = tfp_be_to_cpu_32(idx);
723 /* Search identifier also increase the reference count */
724 rc = tf_search_identifier(tfp, &sparms);
726 BNXT_TF_DBG(ERR, "Search ident %s:%x failed.\n",
727 tf_dir_2_str(sparms.dir),
731 BNXT_TF_DBG(INFO, "Search ident %s:%x.success.\n",
732 tf_dir_2_str(sparms.dir),
735 /* Write it to the regfile */
736 id = (uint64_t)tfp_cpu_to_be_64(sparms.search_id);
737 if (!ulp_regfile_write(parms->regfile, ident->regfile_idx, id)) {
738 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
740 /* Need to free the identifier, so goto error */
744 /* Link the resource to the flow in the flow db */
745 memset(&fid_parms, 0, sizeof(fid_parms));
746 fid_parms.direction = tbl->direction;
747 fid_parms.resource_func = ident->resource_func;
748 fid_parms.resource_type = ident->ident_type;
749 fid_parms.resource_hndl = sparms.search_id;
750 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
751 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
756 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
758 /* Need to free the identifier, so goto error */
765 /* Need to free the identifier */
766 free_parms.dir = tbl->direction;
767 free_parms.ident_type = ident->ident_type;
768 free_parms.id = sparms.search_id;
769 (void)tf_free_identifier(tfp, &free_parms);
770 BNXT_TF_DBG(ERR, "Ident extract failed for %s:%s:%x\n",
772 tf_dir_2_str(tbl->direction), sparms.search_id);
777 ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms,
779 struct bnxt_ulp_mapper_result_field_info *fld,
780 struct ulp_blob *blob,
783 uint16_t idx, size_idx;
786 uint32_t val_size = 0, field_size = 0;
791 switch (fld->result_opcode) {
792 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
793 val = fld->result_operand;
794 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
795 BNXT_TF_DBG(ERR, "%s failed to add field\n", name);
799 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_PROP:
800 if (!ulp_operand_read(fld->result_operand,
801 (uint8_t *)&idx, sizeof(uint16_t))) {
802 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
805 idx = tfp_be_to_cpu_16(idx);
807 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
808 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
811 val = &parms->act_prop->act_details[idx];
812 field_size = ulp_mapper_act_prop_size_get(idx);
813 if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
814 field_size = field_size -
815 ((fld->field_bit_size + 7) / 8);
818 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
819 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
823 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_BIT:
824 if (!ulp_operand_read(fld->result_operand,
825 (uint8_t *)&act_bit, sizeof(uint64_t))) {
826 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
829 act_bit = tfp_be_to_cpu_64(act_bit);
830 memset(act_val, 0, sizeof(act_val));
831 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
833 if (fld->field_bit_size > ULP_BYTE_2_BITS(sizeof(act_val))) {
834 BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
837 if (!ulp_blob_push(blob, act_val, fld->field_bit_size)) {
838 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
843 case BNXT_ULP_MAPPER_OPC_SET_TO_ENCAP_ACT_PROP_SZ:
844 if (!ulp_operand_read(fld->result_operand,
845 (uint8_t *)&idx, sizeof(uint16_t))) {
846 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
849 idx = tfp_be_to_cpu_16(idx);
851 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
852 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
855 val = &parms->act_prop->act_details[idx];
857 /* get the size index next */
858 if (!ulp_operand_read(&fld->result_operand[sizeof(uint16_t)],
859 (uint8_t *)&size_idx, sizeof(uint16_t))) {
860 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
863 size_idx = tfp_be_to_cpu_16(size_idx);
865 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
866 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
869 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
871 val_size = tfp_be_to_cpu_32(val_size);
872 val_size = ULP_BYTE_2_BITS(val_size);
873 ulp_blob_push_encap(blob, val, val_size);
875 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
876 if (!ulp_operand_read(fld->result_operand,
877 (uint8_t *)&idx, sizeof(uint16_t))) {
878 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
882 idx = tfp_be_to_cpu_16(idx);
883 /* Uninitialized regfile entries return 0 */
884 if (!ulp_regfile_read(parms->regfile, idx, ®val)) {
885 BNXT_TF_DBG(ERR, "%s regfile[%d] read oob\n",
890 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
892 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
896 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
897 if (!ulp_operand_read(fld->result_operand,
900 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
903 idx = tfp_be_to_cpu_16(idx);
904 if (ulp_mapper_glb_resource_read(parms->mapper_data,
907 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
911 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
913 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
917 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
918 if (!ulp_operand_read(fld->result_operand,
921 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
924 idx = tfp_be_to_cpu_16(idx);
925 if (idx < BNXT_ULP_CF_IDX_LAST)
926 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
927 fld->field_bit_size);
929 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
933 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
934 if (ulp_blob_pad_push(blob, fld->field_bit_size) < 0) {
935 BNXT_TF_DBG(ERR, "%s too large for blob\n", name);
940 case BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_ACT_PROP_ELSE_CONST:
941 if (!ulp_operand_read(fld->result_operand,
942 (uint8_t *)&act_bit, sizeof(uint64_t))) {
943 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
946 act_bit = tfp_be_to_cpu_64(act_bit);
947 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit)) {
948 /* Action bit is set so consider operand_true */
949 if (!ulp_operand_read(fld->result_operand_true,
952 BNXT_TF_DBG(ERR, "%s operand read failed\n",
956 idx = tfp_be_to_cpu_16(idx);
957 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
958 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n",
962 val = &parms->act_prop->act_details[idx];
963 field_size = ulp_mapper_act_prop_size_get(idx);
964 if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
965 field_size = field_size -
966 ((fld->field_bit_size + 7) / 8);
969 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
970 BNXT_TF_DBG(ERR, "%s push field failed\n",
975 /* action bit is not set, use the operand false */
976 val = fld->result_operand_false;
977 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
978 BNXT_TF_DBG(ERR, "%s failed to add field\n",
984 case BNXT_ULP_MAPPER_OPC_IF_ACT_BIT_THEN_CONST_ELSE_CONST:
985 if (!ulp_operand_read(fld->result_operand,
986 (uint8_t *)&act_bit, sizeof(uint64_t))) {
987 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
990 act_bit = tfp_be_to_cpu_64(act_bit);
991 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit)) {
992 /* Action bit is set so consider operand_true */
993 val = fld->result_operand_true;
995 /* action bit is not set, use the operand false */
996 val = fld->result_operand_false;
998 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
999 BNXT_TF_DBG(ERR, "%s failed to add field\n",
1004 case BNXT_ULP_MAPPER_OPC_IF_COMP_FIELD_THEN_CF_ELSE_CF:
1005 if (!ulp_operand_read(fld->result_operand,
1007 sizeof(uint16_t))) {
1008 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1011 idx = tfp_be_to_cpu_16(idx);
1012 if (idx >= BNXT_ULP_CF_IDX_LAST) {
1013 BNXT_TF_DBG(ERR, "%s invalid index %u\n", name, idx);
1016 /* check if the computed field is set */
1017 if (ULP_COMP_FLD_IDX_RD(parms, idx))
1018 val = fld->result_operand_true;
1020 val = fld->result_operand_false;
1022 /* read the appropriate computed field */
1023 if (!ulp_operand_read(val, (uint8_t *)&idx, sizeof(uint16_t))) {
1024 BNXT_TF_DBG(ERR, "%s val operand read failed\n", name);
1027 idx = tfp_be_to_cpu_16(idx);
1028 if (idx >= BNXT_ULP_CF_IDX_LAST) {
1029 BNXT_TF_DBG(ERR, "%s invalid index %u\n", name, idx);
1032 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
1033 fld->field_bit_size);
1035 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1039 case BNXT_ULP_MAPPER_OPC_IF_HDR_BIT_THEN_CONST_ELSE_CONST:
1040 if (!ulp_operand_read(fld->result_operand,
1041 (uint8_t *)&hdr_bit, sizeof(uint64_t))) {
1042 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
1045 hdr_bit = tfp_be_to_cpu_64(hdr_bit);
1046 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits, hdr_bit)) {
1047 /* Header bit is set so consider operand_true */
1048 val = fld->result_operand_true;
1050 /* Header bit is not set, use the operand false */
1051 val = fld->result_operand_false;
1053 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
1054 BNXT_TF_DBG(ERR, "%s failed to add field\n",
1060 BNXT_TF_DBG(ERR, "invalid result mapper opcode 0x%x\n",
1061 fld->result_opcode);
1067 /* Function to alloc action record and set the table. */
1069 ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms,
1071 struct bnxt_ulp_mapper_key_field_info *f,
1072 struct ulp_blob *blob,
1077 uint16_t idx, bitlen;
1080 struct ulp_regfile *regfile = parms->regfile;
1081 uint8_t *val = NULL;
1082 struct bnxt_ulp_mapper_key_field_info *fld = f;
1083 uint32_t field_size;
1086 operand = fld->spec_operand;
1087 opcode = fld->spec_opcode;
1089 operand = fld->mask_operand;
1090 opcode = fld->mask_opcode;
1093 bitlen = fld->field_bit_size;
1096 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
1098 if (!ulp_blob_push(blob, val, bitlen)) {
1099 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1103 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
1104 if (ulp_blob_pad_push(blob, bitlen) < 0) {
1105 BNXT_TF_DBG(ERR, "%s pad too large for blob\n", name);
1110 case BNXT_ULP_MAPPER_OPC_SET_TO_HDR_FIELD:
1111 if (!ulp_operand_read(operand, (uint8_t *)&idx,
1112 sizeof(uint16_t))) {
1113 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1116 idx = tfp_be_to_cpu_16(idx);
1118 val = parms->hdr_field[idx].spec;
1120 val = parms->hdr_field[idx].mask;
1123 * Need to account for how much data was pushed to the header
1124 * field vs how much is to be inserted in the key/mask.
1126 field_size = parms->hdr_field[idx].size;
1127 if (bitlen < ULP_BYTE_2_BITS(field_size)) {
1128 field_size = field_size - ((bitlen + 7) / 8);
1132 if (!ulp_blob_push(blob, val, bitlen)) {
1133 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1137 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
1138 if (!ulp_operand_read(operand, (uint8_t *)&idx,
1139 sizeof(uint16_t))) {
1140 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1143 idx = tfp_be_to_cpu_16(idx);
1144 if (idx < BNXT_ULP_CF_IDX_LAST)
1145 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
1148 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1152 case BNXT_ULP_MAPPER_OPC_SET_TO_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);
1160 if (!ulp_regfile_read(regfile, idx, &val64)) {
1161 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);
1172 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
1173 if (!ulp_operand_read(operand, (uint8_t *)&idx,
1174 sizeof(uint16_t))) {
1175 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
1178 idx = tfp_be_to_cpu_16(idx);
1179 if (ulp_mapper_glb_resource_read(parms->mapper_data,
1182 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
1186 val = ulp_blob_push_64(blob, &val64, bitlen);
1188 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
1193 BNXT_TF_DBG(ERR, "invalid keymask mapper opcode 0x%x\n",
1203 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
1204 struct bnxt_ulp_mapper_tbl_info *tbl,
1207 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1208 struct ulp_flow_db_res_params fid_parms;
1209 uint32_t mark, gfid, mark_flag;
1212 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1213 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1214 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1215 BNXT_ULP_ACTION_BIT_MARK)))
1216 return rc; /* no need to perform gfid process */
1218 /* Get the mark id details from action property */
1219 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1221 mark = tfp_be_to_cpu_32(mark);
1223 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1224 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1225 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1228 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1231 fid_parms.direction = tbl->direction;
1232 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1233 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1234 fid_parms.resource_type = mark_flag;
1235 fid_parms.resource_hndl = gfid;
1236 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1241 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1246 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1247 struct bnxt_ulp_mapper_tbl_info *tbl)
1249 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1250 struct ulp_flow_db_res_params fid_parms;
1251 uint32_t act_idx, mark, mark_flag;
1255 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1256 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1257 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1258 BNXT_ULP_ACTION_BIT_MARK)))
1259 return rc; /* no need to perform mark action process */
1261 /* Get the mark id details from action property */
1262 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1264 mark = tfp_be_to_cpu_32(mark);
1266 if (!ulp_regfile_read(parms->regfile,
1267 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1269 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1272 act_idx = tfp_be_to_cpu_64(val64);
1273 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1274 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1277 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1280 fid_parms.direction = tbl->direction;
1281 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1282 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1283 fid_parms.resource_type = mark_flag;
1284 fid_parms.resource_hndl = act_idx;
1285 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1290 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1295 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1296 struct bnxt_ulp_mapper_tbl_info *tbl)
1298 struct ulp_flow_db_res_params fid_parms;
1299 uint32_t act_idx, mark, mark_flag;
1301 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1304 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1305 mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION)
1306 return rc; /* no need to perform mark action process */
1308 /* Get the mark id details from the computed field of dev port id */
1309 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1311 /* Get the main action pointer */
1312 if (!ulp_regfile_read(parms->regfile,
1313 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1315 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1318 act_idx = tfp_be_to_cpu_64(val64);
1320 /* Set the mark flag to local fid and vfr flag */
1321 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1323 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1326 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1329 fid_parms.direction = tbl->direction;
1330 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1331 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1332 fid_parms.resource_type = mark_flag;
1333 fid_parms.resource_hndl = act_idx;
1334 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1339 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1344 * Tcam table - create the result blob.
1345 * data [out] - the result blob data
1348 ulp_mapper_tcam_tbl_result_create(struct bnxt_ulp_mapper_parms *parms,
1349 struct bnxt_ulp_mapper_tbl_info *tbl,
1350 struct ulp_blob *data)
1352 struct bnxt_ulp_mapper_result_field_info *dflds;
1354 uint32_t encap_flds = 0;
1358 /* Create the result data blob */
1359 dflds = ulp_mapper_result_fields_get(parms, tbl, &num_dflds,
1361 if (!dflds || !num_dflds || encap_flds) {
1362 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1366 for (i = 0; i < num_dflds; i++) {
1367 rc = ulp_mapper_result_field_process(parms,
1373 BNXT_TF_DBG(ERR, "Failed to set data fields\n");
1380 /* Tcam table scan the identifier list and allocate each identifier */
1382 ulp_mapper_tcam_tbl_scan_ident_alloc(struct bnxt_ulp_mapper_parms *parms,
1383 struct bnxt_ulp_mapper_tbl_info *tbl)
1385 struct bnxt_ulp_mapper_ident_info *idents;
1386 uint32_t num_idents;
1390 * Since the cache entry is responsible for allocating
1391 * identifiers when in use, allocate the identifiers only
1392 * during normal processing.
1394 if (parms->tcam_tbl_opc ==
1395 BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1396 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1398 for (i = 0; i < num_idents; i++) {
1399 if (ulp_mapper_ident_process(parms, tbl,
1408 * Tcam table scan the identifier list and extract the identifier from
1412 ulp_mapper_tcam_tbl_scan_ident_extract(struct bnxt_ulp_mapper_parms *parms,
1413 struct bnxt_ulp_mapper_tbl_info *tbl,
1414 struct ulp_blob *data)
1416 struct bnxt_ulp_mapper_ident_info *idents;
1417 uint32_t num_idents = 0, i;
1421 * Extract the listed identifiers from the result field,
1422 * no need to allocate them.
1424 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
1425 for (i = 0; i < num_idents; i++) {
1426 rc = ulp_mapper_ident_extract(parms, tbl, &idents[i], data);
1428 BNXT_TF_DBG(ERR, "Error in identifier extraction\n");
1435 /* Internal function to write the tcam entry */
1437 ulp_mapper_tcam_tbl_entry_write(struct bnxt_ulp_mapper_parms *parms,
1438 struct bnxt_ulp_mapper_tbl_info *tbl,
1439 struct ulp_blob *key,
1440 struct ulp_blob *mask,
1441 struct ulp_blob *data,
1444 struct tf_set_tcam_entry_parms sparms = { 0 };
1449 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1451 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1455 sparms.dir = tbl->direction;
1456 sparms.tcam_tbl_type = tbl->resource_type;
1458 /* Already verified the key/mask lengths */
1459 sparms.key = ulp_blob_data_get(key, &tmplen);
1460 sparms.mask = ulp_blob_data_get(mask, &tmplen);
1461 sparms.key_sz_in_bits = tbl->key_bit_size;
1462 sparms.result = ulp_blob_data_get(data, &tmplen);
1464 if (tbl->result_bit_size != tmplen) {
1465 BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n",
1466 tmplen, tbl->result_bit_size);
1469 sparms.result_sz_in_bits = tbl->result_bit_size;
1470 if (tf_set_tcam_entry(tfp, &sparms)) {
1471 BNXT_TF_DBG(ERR, "tcam[%s][%s][%x] write failed.\n",
1472 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1473 tf_dir_2_str(sparms.dir), sparms.idx);
1476 BNXT_TF_DBG(INFO, "tcam[%s][%s][%x] write success.\n",
1477 tf_tcam_tbl_2_str(sparms.tcam_tbl_type),
1478 tf_dir_2_str(sparms.dir), sparms.idx);
1480 /* Update cache with TCAM index if the was cache allocated. */
1481 if (parms->tcam_tbl_opc ==
1482 BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) {
1483 if (!parms->cache_ptr) {
1484 BNXT_TF_DBG(ERR, "Unable to update cache");
1487 parms->cache_ptr->tcam_idx = idx;
1491 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1493 BNXT_TF_DBG(ERR, "failed mark action processing\n");
1500 #define BNXT_ULP_WC_TCAM_SLICE_SIZE 80
1501 /* internal function to post process the key/mask blobs for wildcard tcam tbl */
1502 static void ulp_mapper_wc_tcam_tbl_post_process(struct ulp_blob *blob,
1505 uint8_t mode[2] = {0x0, 0x0};
1506 uint32_t mode_len = len / BNXT_ULP_WC_TCAM_SLICE_SIZE;
1509 /* Add the mode bits to the key and mask*/
1512 else if (mode_len > 2)
1515 size = BNXT_ULP_WC_TCAM_SLICE_SIZE + ULP_BYTE_2_BITS(sizeof(mode));
1516 for (idx = 0; idx < mode_len; idx++)
1517 ulp_blob_insert(blob, (size * idx), mode,
1518 ULP_BYTE_2_BITS(sizeof(mode)));
1519 ulp_blob_perform_64B_word_swap(blob);
1520 ulp_blob_perform_64B_byte_swap(blob);
1524 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1525 struct bnxt_ulp_mapper_tbl_info *tbl)
1527 struct bnxt_ulp_mapper_key_field_info *kflds;
1528 struct ulp_blob key, mask, data, update_data;
1529 uint32_t i, num_kflds;
1532 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1533 struct tf_search_tcam_entry_parms searchparms = { 0 };
1534 struct ulp_flow_db_res_params fid_parms = { 0 };
1535 struct tf_free_tcam_entry_parms free_parms = { 0 };
1536 enum bnxt_ulp_search_before_alloc search_flag;
1538 uint16_t tmplen = 0;
1541 /* Skip this if was handled by the cache. */
1542 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP) {
1543 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1547 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1549 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1553 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1554 if (!kflds || !num_kflds) {
1555 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1559 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
1560 parms->device_params->byte_order) ||
1561 !ulp_blob_init(&mask, tbl->blob_key_bit_size,
1562 parms->device_params->byte_order) ||
1563 !ulp_blob_init(&data, tbl->result_bit_size,
1564 parms->device_params->byte_order) ||
1565 !ulp_blob_init(&update_data, tbl->result_bit_size,
1566 parms->device_params->byte_order)) {
1567 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1571 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
1572 key.byte_order = BNXT_ULP_BYTE_ORDER_BE;
1573 mask.byte_order = BNXT_ULP_BYTE_ORDER_BE;
1576 /* create the key/mask */
1578 * NOTE: The WC table will require some kind of flag to handle the
1579 * mode bits within the key/mask
1581 for (i = 0; i < num_kflds; i++) {
1583 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1585 &key, 1, "TCAM Key");
1587 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1591 /* Setup the mask */
1592 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1594 &mask, 0, "TCAM Mask");
1596 BNXT_TF_DBG(ERR, "Mask field set failed.\n");
1601 if (tbl->resource_type == TF_TCAM_TBL_TYPE_WC_TCAM) {
1602 ulp_mapper_wc_tcam_tbl_post_process(&key, tbl->key_bit_size);
1603 ulp_mapper_wc_tcam_tbl_post_process(&mask, tbl->key_bit_size);
1606 if (tbl->srch_b4_alloc == BNXT_ULP_SEARCH_BEFORE_ALLOC_NO) {
1608 * No search for re-use is requested, so simply allocate the
1611 aparms.dir = tbl->direction;
1612 aparms.tcam_tbl_type = tbl->resource_type;
1613 aparms.search_enable = tbl->srch_b4_alloc;
1614 aparms.key = ulp_blob_data_get(&key, &tmplen);
1615 aparms.key_sz_in_bits = tmplen;
1616 if (tbl->blob_key_bit_size != tmplen) {
1617 BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n",
1618 tmplen, tbl->blob_key_bit_size);
1622 aparms.mask = ulp_blob_data_get(&mask, &tmplen);
1623 if (tbl->blob_key_bit_size != tmplen) {
1624 BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n",
1625 tmplen, tbl->blob_key_bit_size);
1629 aparms.priority = tbl->priority;
1632 * All failures after this succeeds require the entry to be
1633 * freed. cannot return directly on failure, but needs to goto
1636 rc = tf_alloc_tcam_entry(tfp, &aparms);
1638 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1645 * Searching before allocation to see if we already have an
1646 * entry. This allows re-use of a constrained resource.
1648 searchparms.dir = tbl->direction;
1649 searchparms.tcam_tbl_type = tbl->resource_type;
1650 searchparms.key = ulp_blob_data_get(&key, &tmplen);
1651 searchparms.key_sz_in_bits = tbl->key_bit_size;
1652 searchparms.mask = ulp_blob_data_get(&mask, &tmplen);
1653 searchparms.priority = tbl->priority;
1654 searchparms.alloc = 1;
1655 searchparms.result = ulp_blob_data_get(&data, &tmplen);
1656 searchparms.result_sz_in_bits = tbl->result_bit_size;
1658 rc = tf_search_tcam_entry(tfp, &searchparms);
1660 BNXT_TF_DBG(ERR, "tcam search failed rc=%d\n", rc);
1664 /* Successful search, check the result */
1665 if (searchparms.search_status == REJECT) {
1666 BNXT_TF_DBG(ERR, "tcam alloc rejected\n");
1669 idx = searchparms.idx;
1670 hit = searchparms.hit;
1673 /* if it is miss then it is same as no search before alloc */
1675 search_flag = BNXT_ULP_SEARCH_BEFORE_ALLOC_NO;
1677 search_flag = tbl->srch_b4_alloc;
1679 switch (search_flag) {
1680 case BNXT_ULP_SEARCH_BEFORE_ALLOC_NO:
1681 /*Scan identifier list, allocate identifier and update regfile*/
1682 rc = ulp_mapper_tcam_tbl_scan_ident_alloc(parms, tbl);
1683 /* Create the result blob */
1685 rc = ulp_mapper_tcam_tbl_result_create(parms, tbl,
1687 /* write the tcam entry */
1689 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key,
1692 case BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_SKIP:
1693 /*Scan identifier list, extract identifier and update regfile*/
1694 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
1696 case BNXT_ULP_SEARCH_BEFORE_ALLOC_SEARCH_IF_HIT_UPDATE:
1697 /*Scan identifier list, extract identifier and update regfile*/
1698 rc = ulp_mapper_tcam_tbl_scan_ident_extract(parms, tbl, &data);
1699 /* Create the result blob */
1701 rc = ulp_mapper_tcam_tbl_result_create(parms, tbl,
1703 /* Update/overwrite the tcam entry */
1705 rc = ulp_mapper_tcam_tbl_entry_write(parms, tbl, &key,
1710 BNXT_TF_DBG(ERR, "invalid search opcode\n");
1718 * Only link the entry to the flow db in the event that cache was not
1721 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1722 fid_parms.direction = tbl->direction;
1723 fid_parms.resource_func = tbl->resource_func;
1724 fid_parms.resource_type = tbl->resource_type;
1725 fid_parms.critical_resource = tbl->critical_resource;
1726 fid_parms.resource_hndl = idx;
1727 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1733 "Failed to link resource to flow rc = %d\n",
1735 /* Need to free the identifier, so goto error */
1740 * Reset the tcam table opcode to normal in case the next tcam
1741 * entry does not use cache.
1743 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1744 parms->cache_ptr = NULL;
1749 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1750 free_parms.dir = tbl->direction;
1751 free_parms.tcam_tbl_type = tbl->resource_type;
1752 free_parms.idx = idx;
1753 trc = tf_free_tcam_entry(tfp, &free_parms);
1755 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
1756 tbl->resource_type, tbl->direction, idx);
1762 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1763 struct bnxt_ulp_mapper_tbl_info *tbl)
1765 struct bnxt_ulp_mapper_key_field_info *kflds;
1766 struct bnxt_ulp_mapper_result_field_info *dflds;
1767 struct ulp_blob key, data;
1768 uint32_t i, num_kflds, num_dflds;
1770 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1771 struct ulp_flow_db_res_params fid_parms = { 0 };
1772 struct tf_insert_em_entry_parms iparms = { 0 };
1773 struct tf_delete_em_entry_parms free_parms = { 0 };
1774 enum bnxt_ulp_flow_mem_type mtype;
1777 uint32_t encap_flds = 0;
1779 rc = bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
1781 BNXT_TF_DBG(ERR, "Failed to get the mem type for EM\n");
1785 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
1786 if (!kflds || !num_kflds) {
1787 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1791 /* Initialize the key/result blobs */
1792 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
1793 parms->device_params->byte_order) ||
1794 !ulp_blob_init(&data, tbl->result_bit_size,
1795 parms->device_params->byte_order)) {
1796 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1800 /* create the key */
1801 for (i = 0; i < num_kflds; i++) {
1803 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1807 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1813 * TBD: Normally should process identifiers in case of using recycle or
1814 * loopback. Not supporting recycle for now.
1817 /* Create the result data blob */
1818 dflds = ulp_mapper_result_fields_get(parms, tbl,
1819 &num_dflds, &encap_flds);
1820 if (!dflds || !num_dflds || encap_flds) {
1821 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1825 for (i = 0; i < num_dflds; i++) {
1826 struct bnxt_ulp_mapper_result_field_info *fld;
1830 rc = ulp_mapper_result_field_process(parms,
1836 BNXT_TF_DBG(ERR, "Failed to set data fields.\n");
1841 /* do the transpose for the internal EM keys */
1842 if (tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE)
1843 ulp_blob_perform_byte_reverse(&key);
1845 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
1846 &iparms.tbl_scope_id);
1848 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1853 * NOTE: the actual blob size will differ from the size in the tbl
1854 * entry due to the padding.
1856 iparms.dup_check = 0;
1857 iparms.dir = tbl->direction;
1858 iparms.mem = tbl->resource_type;
1859 iparms.key = ulp_blob_data_get(&key, &tmplen);
1860 iparms.key_sz_in_bits = tbl->key_bit_size;
1861 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
1862 iparms.em_record_sz_in_bits = tbl->result_bit_size;
1864 rc = tf_insert_em_entry(tfp, &iparms);
1866 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
1870 /* Mark action process */
1871 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
1872 tbl->resource_type == TF_MEM_EXTERNAL)
1873 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
1874 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
1875 tbl->resource_type == TF_MEM_INTERNAL)
1876 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1878 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1882 /* Link the EM resource to the flow in the flow db */
1883 memset(&fid_parms, 0, sizeof(fid_parms));
1884 fid_parms.direction = tbl->direction;
1885 fid_parms.resource_func = tbl->resource_func;
1886 fid_parms.resource_type = tbl->resource_type;
1887 fid_parms.critical_resource = tbl->critical_resource;
1888 fid_parms.resource_hndl = iparms.flow_handle;
1890 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1895 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
1897 /* Need to free the identifier, so goto error */
1903 free_parms.dir = iparms.dir;
1904 free_parms.mem = iparms.mem;
1905 free_parms.tbl_scope_id = iparms.tbl_scope_id;
1906 free_parms.flow_handle = iparms.flow_handle;
1908 trc = tf_delete_em_entry(tfp, &free_parms);
1910 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
1916 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1917 struct bnxt_ulp_mapper_tbl_info *tbl)
1919 struct bnxt_ulp_mapper_result_field_info *flds;
1920 struct ulp_flow_db_res_params fid_parms;
1921 struct ulp_blob data;
1924 uint32_t i, num_flds, index, hit;
1925 int32_t rc = 0, trc = 0;
1926 struct tf_alloc_tbl_entry_parms aparms = { 0 };
1927 struct tf_search_tbl_entry_parms srchparms = { 0 };
1928 struct tf_set_tbl_entry_parms sparms = { 0 };
1929 struct tf_free_tbl_entry_parms free_parms = { 0 };
1930 uint32_t tbl_scope_id;
1931 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1933 uint32_t encap_flds = 0;
1935 /* Get the scope id first */
1936 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
1938 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1942 /* use the max size if encap is enabled */
1943 if (tbl->encap_num_fields)
1944 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
1946 bit_size = tbl->result_bit_size;
1948 /* Initialize the blob data */
1949 if (!ulp_blob_init(&data, bit_size,
1950 parms->device_params->byte_order)) {
1951 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1955 /* Get the result fields list */
1956 flds = ulp_mapper_result_fields_get(parms, tbl, &num_flds, &encap_flds);
1958 if (!flds || (!num_flds && !encap_flds)) {
1959 BNXT_TF_DBG(ERR, "template undefined for the index table\n");
1963 /* process the result fields, loop through them */
1964 for (i = 0; i < (num_flds + encap_flds); i++) {
1965 /* set the swap index if encap swap bit is enabled */
1966 if (parms->device_params->encap_byte_swap && encap_flds &&
1968 ulp_blob_encap_swap_idx_set(&data);
1970 /* Process the result fields */
1971 rc = ulp_mapper_result_field_process(parms,
1977 BNXT_TF_DBG(ERR, "data field failed\n");
1982 /* if encap bit swap is enabled perform the bit swap */
1983 if (parms->device_params->encap_byte_swap && encap_flds) {
1984 ulp_blob_perform_encap_swap(&data);
1988 * Check for index opcode, if it is Global then
1989 * no need to allocate the table, just set the table
1990 * and exit since it is not maintained in the flow db.
1992 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_GLOBAL) {
1993 /* get the index from index operand */
1994 if (tbl->index_operand < BNXT_ULP_GLB_REGFILE_INDEX_LAST &&
1995 ulp_mapper_glb_resource_read(parms->mapper_data,
1999 BNXT_TF_DBG(ERR, "Glbl regfile[%d] read failed.\n",
2000 tbl->index_operand);
2003 /* set the Tf index table */
2004 sparms.dir = tbl->direction;
2005 sparms.type = tbl->resource_type;
2006 sparms.data = ulp_blob_data_get(&data, &tmplen);
2007 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2008 sparms.idx = tfp_be_to_cpu_64(idx);
2009 sparms.tbl_scope_id = tbl_scope_id;
2011 rc = tf_set_tbl_entry(tfp, &sparms);
2014 "Glbl Set table[%d][%s][%d] failed rc=%d\n",
2016 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
2021 return 0; /* success */
2026 /* Perform the tf table allocation by filling the alloc params */
2027 if (tbl->srch_b4_alloc) {
2028 memset(&srchparms, 0, sizeof(srchparms));
2029 srchparms.dir = tbl->direction;
2030 srchparms.type = tbl->resource_type;
2031 srchparms.alloc = 1;
2032 srchparms.result = ulp_blob_data_get(&data, &tmplen);
2033 srchparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2034 srchparms.tbl_scope_id = tbl_scope_id;
2035 rc = tf_search_tbl_entry(tfp, &srchparms);
2037 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2038 tf_tbl_type_2_str(tbl->resource_type),
2039 tf_dir_2_str(tbl->direction), rc);
2042 if (srchparms.search_status == REJECT) {
2043 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] rejected.\n",
2044 tf_tbl_type_2_str(tbl->resource_type),
2045 tf_dir_2_str(tbl->direction));
2048 index = srchparms.idx;
2049 hit = srchparms.hit;
2051 aparms.dir = tbl->direction;
2052 aparms.type = tbl->resource_type;
2053 aparms.search_enable = tbl->srch_b4_alloc;
2054 aparms.result = ulp_blob_data_get(&data, &tmplen);
2055 aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2056 aparms.tbl_scope_id = tbl_scope_id;
2058 /* All failures after the alloc succeeds require a free */
2059 rc = tf_alloc_tbl_entry(tfp, &aparms);
2061 BNXT_TF_DBG(ERR, "Alloc table[%s][%s] failed rc=%d\n",
2062 tf_tbl_type_2_str(tbl->resource_type),
2063 tf_dir_2_str(tbl->direction), rc);
2069 * calculate the idx for the result record, for external EM the offset
2070 * needs to be shifted accordingly. If external non-inline table types
2071 * are used then need to revisit this logic.
2073 if (tbl->resource_type == TF_TBL_TYPE_EXT)
2074 idx = TF_ACT_REC_OFFSET_2_PTR(index);
2078 /* Always storing values in Regfile in BE */
2079 idx = tfp_cpu_to_be_64(idx);
2080 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_ALLOCATE) {
2081 rc = ulp_regfile_write(parms->regfile, tbl->index_operand, idx);
2083 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
2084 tbl->index_operand);
2089 /* Perform the tf table set by filling the set params */
2090 if (!tbl->srch_b4_alloc || !hit) {
2091 sparms.dir = tbl->direction;
2092 sparms.type = tbl->resource_type;
2093 sparms.data = ulp_blob_data_get(&data, &tmplen);
2094 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2096 sparms.tbl_scope_id = tbl_scope_id;
2098 rc = tf_set_tbl_entry(tfp, &sparms);
2100 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
2102 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
2109 /* Link the resource to the flow in the flow db */
2110 memset(&fid_parms, 0, sizeof(fid_parms));
2111 fid_parms.direction = tbl->direction;
2112 fid_parms.resource_func = tbl->resource_func;
2113 fid_parms.resource_type = tbl->resource_type;
2114 fid_parms.resource_sub_type = tbl->resource_sub_type;
2115 fid_parms.resource_hndl = index;
2116 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
2118 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
2123 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
2128 /* Perform the VF rep action */
2129 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
2131 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
2137 * Free the allocated resource since we failed to either
2138 * write to the entry or link the flow
2140 free_parms.dir = tbl->direction;
2141 free_parms.type = tbl->resource_type;
2142 free_parms.idx = index;
2143 free_parms.tbl_scope_id = tbl_scope_id;
2145 trc = tf_free_tbl_entry(tfp, &free_parms);
2147 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
2153 ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2154 struct bnxt_ulp_mapper_tbl_info *tbl)
2156 struct bnxt_ulp_mapper_key_field_info *kflds;
2157 struct bnxt_ulp_mapper_cache_entry *cache_entry;
2158 struct bnxt_ulp_mapper_ident_info *idents;
2159 uint32_t i, num_kflds = 0, num_idents = 0;
2160 struct ulp_flow_db_res_params fid_parms;
2161 struct tf_free_identifier_parms fparms;
2162 uint16_t tmplen, tmp_ident;
2163 struct ulp_blob key;
2169 /* Get the key fields list and build the key. */
2170 kflds = ulp_mapper_key_fields_get(parms, tbl, &num_kflds);
2171 if (!kflds || !num_kflds) {
2172 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
2175 if (!ulp_blob_init(&key, tbl->key_bit_size,
2176 parms->device_params->byte_order)) {
2177 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
2180 for (i = 0; i < num_kflds; i++) {
2182 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
2184 &key, 1, "Cache Key");
2187 "Failed to create key for Cache rc=%d\n",
2194 * Perform the lookup in the cache table with constructed key. The
2195 * cache_key is a byte array of tmplen, it needs to be converted to a
2196 * index for the cache table.
2198 cache_key = ulp_blob_data_get(&key, &tmplen);
2199 ckey = (uint16_t *)cache_key;
2202 * The id computed based on resource sub type and direction where
2203 * dir is the bit0 and rest of the bits come from resource
2206 cache_entry = ulp_mapper_cache_entry_get(parms->ulp_ctx,
2207 (tbl->resource_sub_type << 1 |
2208 (tbl->direction & 0x1)),
2212 * Get the identifier list for processing by both the hit and miss
2215 idents = ulp_mapper_ident_fields_get(parms, tbl, &num_idents);
2217 if (!cache_entry->ref_count) {
2218 /* Initialize the cache entry */
2219 cache_entry->tcam_idx = 0;
2220 cache_entry->ref_count = 0;
2221 for (i = 0; i < BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM; i++)
2222 cache_entry->idents[i] = ULP_IDENTS_INVALID;
2224 /* Need to allocate identifiers for storing in the cache. */
2225 for (i = 0; i < num_idents; i++) {
2227 * Since we are using the cache, the identifier does not
2228 * get added to the flow db. Pass in the pointer to the
2231 rc = ulp_mapper_ident_process(parms, tbl,
2232 &idents[i], &tmp_ident);
2236 cache_entry->ident_types[i] = idents[i].ident_type;
2237 cache_entry->idents[i] = tmp_ident;
2240 /* Tell the TCAM processor to alloc an entry */
2241 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC;
2242 /* Store the cache key for use by the tcam process code */
2243 parms->cache_ptr = cache_entry;
2245 /* Cache hit, get values from result. */
2246 for (i = 0; i < num_idents; i++) {
2247 regval = (uint64_t)cache_entry->idents[i];
2248 if (!ulp_regfile_write(parms->regfile,
2249 idents[i].regfile_idx,
2250 tfp_cpu_to_be_64(regval))) {
2252 "Failed to write to regfile\n");
2257 * The cached entry is being used, so let the tcam processing
2258 * know not to process this table.
2260 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP;
2263 /* Made through the cache processing, increment the reference count. */
2264 cache_entry->ref_count++;
2266 /* Link the cache to the flow db. */
2267 memset(&fid_parms, 0, sizeof(fid_parms));
2268 fid_parms.direction = tbl->direction;
2269 fid_parms.resource_func = tbl->resource_func;
2272 * Cache resource type is composed of table_type, resource
2273 * sub type and direction, it needs to set appropriately via setter.
2275 ulp_mapper_cache_res_type_set(&fid_parms,
2277 (tbl->resource_sub_type << 1 |
2278 (tbl->direction & 0x1)));
2279 fid_parms.resource_hndl = (uint64_t)*ckey;
2280 fid_parms.critical_resource = tbl->critical_resource;
2281 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
2286 BNXT_TF_DBG(ERR, "Failed to add cache to flow db.\n");
2291 * This error handling only gets called when the idents are being
2292 * allocated for the cache on misses. Using the num_idents that was
2295 for (i = 0; i < num_idents; i++) {
2296 if (cache_entry->idents[i] == ULP_IDENTS_INVALID)
2299 fparms.dir = tbl->direction;
2300 fparms.ident_type = idents[i].ident_type;
2301 fparms.id = cache_entry->idents[i];
2302 tf_free_identifier(parms->tfp, &fparms);
2309 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
2310 struct bnxt_ulp_mapper_tbl_info *tbl)
2312 struct bnxt_ulp_mapper_result_field_info *flds;
2313 struct ulp_blob data;
2316 uint32_t i, num_flds;
2318 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
2319 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
2320 uint32_t encap_flds;
2322 /* Initialize the blob data */
2323 if (!ulp_blob_init(&data, tbl->result_bit_size,
2324 parms->device_params->byte_order)) {
2325 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
2329 /* Get the result fields list */
2330 flds = ulp_mapper_result_fields_get(parms, tbl, &num_flds, &encap_flds);
2332 if (!flds || !num_flds || encap_flds) {
2333 BNXT_TF_DBG(ERR, "template undefined for the IF table\n");
2337 /* process the result fields, loop through them */
2338 for (i = 0; i < num_flds; i++) {
2339 /* Process the result fields */
2340 rc = ulp_mapper_result_field_process(parms,
2346 BNXT_TF_DBG(ERR, "data field failed\n");
2351 /* Get the index details from computed field */
2352 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_COMP_FIELD) {
2353 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->index_operand);
2354 } else if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_CONSTANT) {
2355 idx = tbl->index_operand;
2357 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
2361 /* Perform the tf table set by filling the set params */
2362 iftbl_params.dir = tbl->direction;
2363 iftbl_params.type = tbl->resource_type;
2364 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
2365 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
2366 iftbl_params.idx = idx;
2368 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
2370 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
2372 (iftbl_params.dir == TF_DIR_RX) ? "RX" : "TX",
2379 * TBD: Need to look at the need to store idx in flow db for restore
2380 * the table to its original state on deletion of this entry.
2386 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
2387 struct bnxt_ulp_mapper_data *mapper_data)
2389 struct bnxt_ulp_glb_resource_info *glb_res;
2390 uint32_t num_glb_res_ids, idx;
2393 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
2394 if (!glb_res || !num_glb_res_ids) {
2395 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
2399 /* Iterate the global resources and process each one */
2400 for (idx = 0; idx < num_glb_res_ids; idx++) {
2401 switch (glb_res[idx].resource_func) {
2402 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2403 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
2407 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2408 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2413 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2414 glb_res[idx].resource_func);
2425 * Function to process the conditional opcode of the mapper table.
2426 * returns 1 to skip the table.
2427 * return 0 to continue processing the table.
2432 ulp_mapper_tbl_cond_opcode_process(struct bnxt_ulp_mapper_parms *parms,
2433 struct bnxt_ulp_mapper_tbl_info *tbl)
2437 switch (tbl->cond_opcode) {
2438 case BNXT_ULP_COND_OPCODE_NOP:
2441 case BNXT_ULP_COND_OPCODE_COMP_FIELD_IS_SET:
2442 if (tbl->cond_operand < BNXT_ULP_CF_IDX_LAST &&
2443 ULP_COMP_FLD_IDX_RD(parms, tbl->cond_operand))
2446 case BNXT_ULP_COND_OPCODE_ACTION_BIT_IS_SET:
2447 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits,
2451 case BNXT_ULP_COND_OPCODE_HDR_BIT_IS_SET:
2452 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
2456 case BNXT_ULP_COND_OPCODE_COMP_FIELD_NOT_SET:
2457 if (tbl->cond_operand < BNXT_ULP_CF_IDX_LAST &&
2458 !ULP_COMP_FLD_IDX_RD(parms, tbl->cond_operand))
2461 case BNXT_ULP_COND_OPCODE_ACTION_BIT_NOT_SET:
2462 if (!ULP_BITMAP_ISSET(parms->act_bitmap->bits,
2466 case BNXT_ULP_COND_OPCODE_HDR_BIT_NOT_SET:
2467 if (!ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
2473 "Invalid arg in mapper tbl for cond opcode\n");
2480 * Function to process the memtype opcode of the mapper table.
2481 * returns 1 to skip the table.
2482 * return 0 to continue processing the table.
2487 ulp_mapper_tbl_memtype_opcode_process(struct bnxt_ulp_mapper_parms *parms,
2488 struct bnxt_ulp_mapper_tbl_info *tbl)
2490 enum bnxt_ulp_flow_mem_type mtype = BNXT_ULP_FLOW_MEM_TYPE_INT;
2493 bnxt_ulp_cntxt_mem_type_get(parms->ulp_ctx, &mtype);
2495 switch (tbl->mem_type_opcode) {
2496 case BNXT_ULP_MEM_TYPE_OPCODE_EXECUTE_IF_INT:
2497 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT)
2500 case BNXT_ULP_MEM_TYPE_OPCODE_EXECUTE_IF_EXT:
2501 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT)
2504 case BNXT_ULP_MEM_TYPE_OPCODE_NOP:
2509 "Invalid arg in mapper in memtype opcode\n");
2516 ulp_mapper_tbls_process(struct bnxt_ulp_mapper_parms *parms, uint32_t tid)
2518 struct bnxt_ulp_mapper_tbl_info *tbls;
2519 uint32_t num_tbls, i;
2520 int32_t rc = -EINVAL;
2522 tbls = ulp_mapper_tbl_list_get(parms, tid, &num_tbls);
2523 if (!tbls || !num_tbls) {
2524 BNXT_TF_DBG(ERR, "No %s tables for %d:%d\n",
2525 (parms->tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
2526 "class" : "action", parms->dev_id, tid);
2530 for (i = 0; i < num_tbls; i++) {
2531 struct bnxt_ulp_mapper_tbl_info *tbl = &tbls[i];
2533 if (ulp_mapper_tbl_memtype_opcode_process(parms, tbl))
2535 if (ulp_mapper_tbl_cond_opcode_process(parms, tbl))
2538 switch (tbl->resource_func) {
2539 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2540 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
2542 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2543 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2544 rc = ulp_mapper_em_tbl_process(parms, tbl);
2546 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2547 rc = ulp_mapper_index_tbl_process(parms, tbl);
2549 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2550 rc = ulp_mapper_cache_tbl_process(parms, tbl);
2552 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
2553 rc = ulp_mapper_if_tbl_process(parms, tbl);
2556 BNXT_TF_DBG(ERR, "Unexpected mapper resource %d\n",
2557 tbl->resource_func);
2563 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2564 tbl->resource_func);
2571 BNXT_TF_DBG(ERR, "%s tables failed creation for %d:%d\n",
2572 (parms->tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS) ?
2573 "class" : "action", parms->dev_id, tid);
2578 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
2580 struct ulp_flow_db_res_params *res)
2586 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
2590 tfp = bnxt_ulp_cntxt_tfp_get(ulp);
2592 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
2596 switch (res->resource_func) {
2597 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2598 rc = ulp_mapper_cache_entry_free(ulp, tfp, res);
2600 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2601 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
2603 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2604 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2605 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
2607 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2608 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
2610 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2611 rc = ulp_mapper_ident_free(ulp, tfp, res);
2613 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
2614 rc = ulp_mapper_mark_free(ulp, res);
2616 case BNXT_ULP_RESOURCE_FUNC_PARENT_FLOW:
2617 rc = ulp_mapper_parent_flow_free(ulp, fid, res);
2619 case BNXT_ULP_RESOURCE_FUNC_CHILD_FLOW:
2620 rc = ulp_mapper_child_flow_free(ulp, fid, res);
2630 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
2631 enum bnxt_ulp_fdb_type flow_type,
2634 struct ulp_flow_db_res_params res_parms = { 0 };
2638 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2643 * Set the critical resource on the first resource del, then iterate
2644 * while status is good
2646 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
2647 rc = ulp_flow_db_resource_del(ulp_ctx, flow_type, fid, &res_parms);
2651 * This is unexpected on the first call to resource del.
2652 * It likely means that the flow did not exist in the flow db.
2654 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
2655 flow_type, fid, rc);
2660 trc = ulp_mapper_resource_free(ulp_ctx, fid, &res_parms);
2663 * On fail, we still need to attempt to free the
2664 * remaining resources. Don't return
2667 "Flow[%d][0x%x] Res[%d][0x%016" PRIx64
2668 "] failed rc=%d.\n",
2669 flow_type, fid, res_parms.resource_func,
2670 res_parms.resource_hndl, trc);
2672 /* All subsequent call require the non-critical_resource */
2673 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
2675 rc = ulp_flow_db_resource_del(ulp_ctx,
2681 /* Free the Flow ID since we've removed all resources */
2682 rc = ulp_flow_db_fid_free(ulp_ctx, flow_type, fid);
2688 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
2689 struct bnxt_ulp_mapper_data *mapper_data)
2691 struct bnxt_ulp_mapper_glb_resource_entry *ent;
2692 struct ulp_flow_db_res_params res;
2695 /* Iterate the global resources and process each one */
2696 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
2697 for (idx = 0; idx < BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
2699 ent = &mapper_data->glb_res_tbl[dir][idx];
2700 if (ent->resource_func ==
2701 BNXT_ULP_RESOURCE_FUNC_INVALID)
2703 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
2704 res.resource_func = ent->resource_func;
2705 res.direction = dir;
2706 res.resource_type = ent->resource_type;
2707 /*convert it from BE to cpu */
2709 tfp_be_to_cpu_64(ent->resource_hndl);
2710 ulp_mapper_resource_free(ulp_ctx, 0, &res);
2716 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx,
2717 enum bnxt_ulp_fdb_type flow_type,
2723 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2727 rc = ulp_mapper_resources_free(ulp_ctx, flow_type, fid);
2731 /* Function to handle the default global templates that are allocated during
2732 * the startup and reused later.
2735 ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx)
2737 uint32_t *glbl_tmpl_list;
2738 uint32_t num_glb_tmpls, idx, dev_id;
2739 struct bnxt_ulp_mapper_parms parms;
2740 struct bnxt_ulp_mapper_data *mapper_data;
2743 glbl_tmpl_list = ulp_mapper_glb_template_table_get(&num_glb_tmpls);
2744 if (!glbl_tmpl_list || !num_glb_tmpls)
2745 return rc; /* No global templates to process */
2747 /* Get the device id from the ulp context */
2748 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
2749 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2753 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2755 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2759 /* Iterate the global resources and process each one */
2760 for (idx = 0; idx < num_glb_tmpls; idx++) {
2761 /* Initialize the parms structure */
2762 memset(&parms, 0, sizeof(parms));
2763 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2764 parms.ulp_ctx = ulp_ctx;
2765 parms.dev_id = dev_id;
2766 parms.mapper_data = mapper_data;
2767 parms.flow_type = BNXT_ULP_FDB_TYPE_DEFAULT;
2768 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
2770 /* Get the class table entry from dev id and class id */
2771 parms.class_tid = glbl_tmpl_list[idx];
2773 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2774 if (!parms.device_params) {
2775 BNXT_TF_DBG(ERR, "No device for device id %d\n",
2780 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
2787 /* Function to handle the mapping of the Flow to be compatible
2788 * with the underlying hardware.
2791 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
2792 struct bnxt_ulp_mapper_create_parms *cparms)
2794 struct bnxt_ulp_mapper_parms parms;
2795 struct ulp_regfile regfile;
2798 if (!ulp_ctx || !cparms)
2801 /* Initialize the parms structure */
2802 memset(&parms, 0, sizeof(parms));
2803 parms.act_prop = cparms->act_prop;
2804 parms.act_bitmap = cparms->act;
2805 parms.hdr_bitmap = cparms->hdr_bitmap;
2806 parms.regfile = ®file;
2807 parms.hdr_field = cparms->hdr_field;
2808 parms.comp_fld = cparms->comp_fld;
2809 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2810 parms.ulp_ctx = ulp_ctx;
2811 parms.tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
2812 parms.act_tid = cparms->act_tid;
2813 parms.class_tid = cparms->class_tid;
2814 parms.flow_type = cparms->flow_type;
2815 parms.parent_flow = cparms->parent_flow;
2816 parms.parent_fid = cparms->parent_fid;
2817 parms.fid = cparms->flow_id;
2818 parms.tun_idx = cparms->tun_idx;
2820 /* Get the device id from the ulp context */
2821 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
2822 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2826 /* Get the device params, it will be used in later processing */
2827 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2828 if (!parms.device_params) {
2829 BNXT_TF_DBG(ERR, "No device parms for device id %d\n",
2835 * Get the mapper data for dynamic mapper data such as default
2838 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
2839 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2840 if (!parms.mapper_data) {
2841 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2845 /* initialize the registry file for further processing */
2846 if (!ulp_regfile_init(parms.regfile)) {
2847 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
2851 rc = ulp_regfile_write(parms.regfile,
2852 BNXT_ULP_REGFILE_INDEX_CLASS_TID,
2853 tfp_cpu_to_be_64((uint64_t)parms.class_tid));
2855 BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
2859 /* Process the action template list from the selected action table*/
2860 if (parms.act_tid) {
2861 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_ACTION;
2862 /* Process the action template tables */
2863 rc = ulp_mapper_tbls_process(&parms, parms.act_tid);
2868 if (parms.class_tid) {
2869 parms.tmpl_type = BNXT_ULP_TEMPLATE_TYPE_CLASS;
2871 /* Process the class template tables.*/
2872 rc = ulp_mapper_tbls_process(&parms, parms.class_tid);
2877 /* setup the parent-child details */
2878 if (parms.parent_flow) {
2879 /* create a parent flow details */
2880 rc = ulp_flow_db_parent_flow_create(&parms);
2883 } else if (parms.parent_fid) {
2884 /* create a child flow details */
2885 rc = ulp_flow_db_child_flow_create(&parms);
2893 /* Free all resources that were allocated during flow creation */
2894 trc = ulp_mapper_flow_destroy(ulp_ctx, BNXT_ULP_FDB_TYPE_REGULAR,
2897 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
2903 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
2905 struct bnxt_ulp_cache_tbl_params *tbl;
2906 struct bnxt_ulp_mapper_data *data;
2914 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2918 data = rte_zmalloc("ulp_mapper_data",
2919 sizeof(struct bnxt_ulp_mapper_data), 0);
2921 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
2925 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
2926 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
2927 /* Don't call deinit since the prof_func wasn't allocated. */
2932 /* Allocate the global resource ids */
2933 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
2935 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
2939 /* Allocate the ulp cache tables. */
2940 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
2941 tbl = ulp_mapper_cache_tbl_params_get(i);
2943 BNXT_TF_DBG(ERR, "Failed to get cache table parms (%d)",
2947 if (tbl->num_entries != 0) {
2948 csize = sizeof(struct bnxt_ulp_mapper_cache_entry) *
2950 data->cache_tbl[i] = rte_zmalloc("ulp mapper cache tbl",
2952 if (!data->cache_tbl[i]) {
2953 BNXT_TF_DBG(ERR, "Failed to allocate Cache "
2961 rc = ulp_mapper_glb_template_table_init(ulp_ctx);
2963 BNXT_TF_DBG(ERR, "Failed to initialize global templates\n");
2969 /* Ignore the return code in favor of returning the original error. */
2970 ulp_mapper_deinit(ulp_ctx);
2975 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
2977 struct bnxt_ulp_mapper_data *data;
2983 "Failed to acquire ulp context, so data may "
2984 "not be released.\n");
2988 data = (struct bnxt_ulp_mapper_data *)
2989 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2991 /* Go ahead and return since there is no allocated data. */
2992 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
2996 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2998 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
2999 /* Free the mapper data regardless of errors. */
3000 goto free_mapper_data;
3003 /* Free the global resource info table entries */
3004 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
3007 /* Free the ulp cache tables */
3008 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
3009 rte_free(data->cache_tbl[i]);
3010 data->cache_tbl[i] = NULL;
3014 /* Reset the data pointer within the ulp_ctx. */
3015 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);