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_flow_db.h"
18 #include "ulp_mapper.h"
20 static struct bnxt_ulp_glb_resource_info *
21 ulp_mapper_glb_resource_info_list_get(uint32_t *num_entries)
25 *num_entries = BNXT_ULP_GLB_RESOURCE_INFO_TBL_MAX_SZ;
26 return ulp_glb_resource_tbl;
30 * Read the global resource from the mapper global resource list
32 * The regval is always returned in big-endian.
34 * returns 0 on success
37 ulp_mapper_glb_resource_read(struct bnxt_ulp_mapper_data *mapper_data,
42 if (!mapper_data || !regval ||
43 dir >= TF_DIR_MAX || idx >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
46 *regval = mapper_data->glb_res_tbl[dir][idx].resource_hndl;
51 * Write a global resource to the mapper global resource list
53 * The regval value must be in big-endian.
55 * return 0 on success.
58 ulp_mapper_glb_resource_write(struct bnxt_ulp_mapper_data *data,
59 struct bnxt_ulp_glb_resource_info *res,
62 struct bnxt_ulp_mapper_glb_resource_entry *ent;
64 /* validate the arguments */
65 if (!data || res->direction >= TF_DIR_MAX ||
66 res->glb_regfile_index >= BNXT_ULP_GLB_REGFILE_INDEX_LAST)
69 /* write to the mapper data */
70 ent = &data->glb_res_tbl[res->direction][res->glb_regfile_index];
71 ent->resource_func = res->resource_func;
72 ent->resource_type = res->resource_type;
73 ent->resource_hndl = regval;
78 * Internal function to allocate identity resource and store it in mapper data.
80 * returns 0 on success
83 ulp_mapper_resource_ident_allocate(struct bnxt_ulp_context *ulp_ctx,
84 struct bnxt_ulp_mapper_data *mapper_data,
85 struct bnxt_ulp_glb_resource_info *glb_res)
87 struct tf_alloc_identifier_parms iparms = { 0 };
88 struct tf_free_identifier_parms fparms;
93 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
97 iparms.ident_type = glb_res->resource_type;
98 iparms.dir = glb_res->direction;
100 /* Allocate the Identifier using tf api */
101 rc = tf_alloc_identifier(tfp, &iparms);
103 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
104 (iparms.dir == TF_DIR_RX) ? "RX" : "TX",
109 /* entries are stored as big-endian format */
110 regval = tfp_cpu_to_be_64((uint64_t)iparms.id);
111 /* write to the mapper global resource */
112 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
114 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
115 /* Free the identifier when update failed */
116 fparms.dir = iparms.dir;
117 fparms.ident_type = iparms.ident_type;
118 fparms.id = iparms.id;
119 tf_free_identifier(tfp, &fparms);
122 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
123 BNXT_TF_DBG(DEBUG, "Allocated Glb Res Ident [%s][%d][%d] = 0x%04x\n",
124 (iparms.dir == TF_DIR_RX) ? "RX" : "TX",
125 glb_res->glb_regfile_index, iparms.ident_type, iparms.id);
131 * Internal function to allocate index tbl resource and store it in mapper data.
133 * returns 0 on success
136 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
137 struct bnxt_ulp_mapper_data *mapper_data,
138 struct bnxt_ulp_glb_resource_info *glb_res)
140 struct tf_alloc_tbl_entry_parms aparms = { 0 };
141 struct tf_free_tbl_entry_parms free_parms = { 0 };
144 uint32_t tbl_scope_id;
147 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
151 /* Get the scope id */
152 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &tbl_scope_id);
154 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
158 aparms.type = glb_res->resource_type;
159 aparms.dir = glb_res->direction;
160 aparms.search_enable = BNXT_ULP_SEARCH_BEFORE_ALLOC_NO;
161 aparms.tbl_scope_id = tbl_scope_id;
163 /* Allocate the index tbl using tf api */
164 rc = tf_alloc_tbl_entry(tfp, &aparms);
166 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
167 (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
172 /* entries are stored as big-endian format */
173 regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
174 /* write to the mapper global resource */
175 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
177 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
178 /* Free the identifier when update failed */
179 free_parms.dir = aparms.dir;
180 free_parms.type = aparms.type;
181 free_parms.idx = aparms.idx;
182 tf_free_tbl_entry(tfp, &free_parms);
185 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
186 BNXT_TF_DBG(DEBUG, "Allocated Glb Res Index [%s][%d][%d] = 0x%04x\n",
187 (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
188 glb_res->glb_regfile_index, aparms.type, aparms.idx);
193 /* Retrieve the cache initialization parameters for the tbl_idx */
194 static struct bnxt_ulp_cache_tbl_params *
195 ulp_mapper_cache_tbl_params_get(uint32_t tbl_idx)
197 if (tbl_idx >= BNXT_ULP_CACHE_TBL_MAX_SZ)
200 return &ulp_cache_tbl_params[tbl_idx];
203 /* Retrieve the global template table */
205 ulp_mapper_glb_template_table_get(uint32_t *num_entries)
209 *num_entries = BNXT_ULP_GLB_TEMPLATE_TBL_MAX_SZ;
210 return ulp_glb_template_tbl;
214 * Get the size of the action property for a given index.
216 * idx [in] The index for the action property
218 * returns the size of the action property.
221 ulp_mapper_act_prop_size_get(uint32_t idx)
223 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
225 return ulp_act_prop_map_table[idx];
229 * Get the list of result fields that implement the flow action.
230 * Gets a device dependent list of tables that implement the action template id.
232 * dev_id [in] The device id of the forwarding element
234 * tid [in] The action template id that matches the flow
236 * num_tbls [out] The number of action tables in the returned array
238 * Returns An array of action tables to implement the flow, or NULL on error.
240 static struct bnxt_ulp_mapper_tbl_info *
241 ulp_mapper_action_tbl_list_get(uint32_t dev_id,
249 BNXT_TF_DBG(ERR, "Invalid arguments\n");
253 /* template shift and device mask */
254 tidx = ULP_DEVICE_PARAMS_INDEX(tid, dev_id);
256 /* NOTE: Need to have something from template compiler to help validate
257 * range of dev_id and act_tid
259 idx = ulp_act_tmpl_list[tidx].start_tbl_idx;
260 *num_tbls = ulp_act_tmpl_list[tidx].num_tbls;
262 return &ulp_act_tbl_list[idx];
266 * Get a list of classifier tables that implement the flow
267 * Gets a device dependent list of tables that implement the class template id
269 * dev_id [in] The device id of the forwarding element
271 * tid [in] The template id that matches the flow
273 * num_tbls [out] The number of classifier tables in the returned array
275 * fdb_tbl_idx [out] The flow database index Regular or default
277 * returns An array of classifier tables to implement the flow, or NULL on
280 static struct bnxt_ulp_mapper_tbl_info *
281 ulp_mapper_class_tbl_list_get(uint32_t dev_id,
284 uint32_t *fdb_tbl_idx)
287 uint32_t tidx = ULP_DEVICE_PARAMS_INDEX(tid, dev_id);
292 /* NOTE: Need to have something from template compiler to help validate
293 * range of dev_id and tid
295 idx = ulp_class_tmpl_list[tidx].start_tbl_idx;
296 *num_tbls = ulp_class_tmpl_list[tidx].num_tbls;
297 *fdb_tbl_idx = ulp_class_tmpl_list[tidx].flow_db_table_type;
298 return &ulp_class_tbl_list[idx];
302 * Get the list of key fields that implement the flow.
304 * ctxt [in] The ulp context
306 * tbl [in] A single table instance to get the key fields from
308 * num_flds [out] The number of key fields in the returned array
310 * Returns array of Key fields, or NULL on error.
312 static struct bnxt_ulp_mapper_class_key_field_info *
313 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
318 if (!tbl || !num_flds)
321 idx = tbl->key_start_idx;
322 *num_flds = tbl->key_num_fields;
324 /* NOTE: Need template to provide range checking define */
325 return &ulp_class_key_field_list[idx];
329 * Get the list of data fields that implement the flow.
331 * ctxt [in] The ulp context
333 * tbl [in] A single table instance to get the data fields from
335 * num_flds [out] The number of data fields in the returned array.
337 * Returns array of data fields, or NULL on error.
339 static struct bnxt_ulp_mapper_result_field_info *
340 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
342 uint32_t *num_encap_flds)
346 if (!tbl || !num_flds)
349 idx = tbl->result_start_idx;
350 *num_flds = tbl->result_num_fields;
351 *num_encap_flds = tbl->encap_num_fields;
353 /* NOTE: Need template to provide range checking define */
354 return &ulp_class_result_field_list[idx];
358 * Get the list of result fields that implement the flow action.
360 * tbl [in] A single table instance to get the results fields
361 * from num_flds [out] The number of data fields in the returned
364 * Returns array of data fields, or NULL on error.
366 static struct bnxt_ulp_mapper_result_field_info *
367 ulp_mapper_act_result_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
368 uint32_t *num_rslt_flds,
369 uint32_t *num_encap_flds)
373 if (!tbl || !num_rslt_flds || !num_encap_flds)
376 idx = tbl->result_start_idx;
377 *num_rslt_flds = tbl->result_num_fields;
378 *num_encap_flds = tbl->encap_num_fields;
380 /* NOTE: Need template to provide range checking define */
381 return &ulp_act_result_field_list[idx];
385 * Get the list of ident fields that implement the flow
387 * tbl [in] A single table instance to get the ident fields from
389 * num_flds [out] The number of ident fields in the returned array
391 * returns array of ident fields, or NULL on error
393 static struct bnxt_ulp_mapper_ident_info *
394 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
399 if (!tbl || !num_flds)
402 idx = tbl->ident_start_idx;
403 *num_flds = tbl->ident_nums;
405 /* NOTE: Need template to provide range checking define */
406 return &ulp_ident_list[idx];
409 static struct bnxt_ulp_mapper_cache_entry *
410 ulp_mapper_cache_entry_get(struct bnxt_ulp_context *ulp,
414 struct bnxt_ulp_mapper_data *mapper_data;
416 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp);
417 if (!mapper_data || id >= BNXT_ULP_CACHE_TBL_MAX_SZ ||
418 !mapper_data->cache_tbl[id]) {
419 BNXT_TF_DBG(ERR, "Unable to acquire the cache tbl (%d)\n", id);
423 return &mapper_data->cache_tbl[id][key];
427 * Concatenates the tbl_type and tbl_id into a 32bit value for storing in the
428 * resource_type. This is done to conserve memory since both the tbl_type and
432 ulp_mapper_cache_res_type_set(struct ulp_flow_db_res_params *res,
436 res->resource_type = tbl_type;
437 res->resource_sub_type = tbl_id;
440 /* Extracts the tbl_type and tbl_id from the 32bit resource type. */
442 ulp_mapper_cache_res_type_get(struct ulp_flow_db_res_params *res,
446 *tbl_type = res->resource_type;
447 *tbl_id = res->resource_sub_type;
451 ulp_mapper_cache_entry_free(struct bnxt_ulp_context *ulp,
453 struct ulp_flow_db_res_params *res)
455 struct bnxt_ulp_mapper_cache_entry *cache_entry;
456 struct tf_free_identifier_parms ident_parms;
457 struct tf_free_tcam_entry_parms tcam_parms;
458 uint16_t table_id, table_type;
462 * The table id, used for cache, and table_type, used for tcam, are
463 * both encoded within the resource. We must first extract them to
464 * formulate the args for tf calls.
466 ulp_mapper_cache_res_type_get(res, &table_type, &table_id);
467 cache_entry = ulp_mapper_cache_entry_get(ulp, table_id,
468 (uint16_t)res->resource_hndl);
469 if (!cache_entry || !cache_entry->ref_count) {
470 BNXT_TF_DBG(ERR, "Cache entry (%d:%d) not valid on free.\n",
471 table_id, (uint16_t)res->resource_hndl);
476 * See if we need to delete the entry. The tcam and identifiers are all
477 * tracked by the cached entries reference count. All are deleted when
478 * the reference count hit zero.
480 cache_entry->ref_count--;
481 if (cache_entry->ref_count)
485 * Need to delete the tcam entry and the allocated identifiers.
486 * In the event of a failure, need to try to delete the remaining
487 * resources before returning error.
489 tcam_parms.dir = res->direction;
490 tcam_parms.tcam_tbl_type = table_type;
491 tcam_parms.idx = cache_entry->tcam_idx;
492 rc = tf_free_tcam_entry(tfp, &tcam_parms);
494 BNXT_TF_DBG(ERR, "Failed to free tcam [%d][%s][0x%04x] rc=%d\n",
496 (res->direction == TF_DIR_RX) ? "RX" : "TX",
500 * Free the identifiers associated with the tcam entry. Entries with
501 * negative one are considered uninitialized.
503 for (i = 0; i < BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM; i++) {
504 if (cache_entry->idents[i] == ULP_IDENTS_INVALID)
507 ident_parms.dir = res->direction;
508 ident_parms.ident_type = cache_entry->ident_types[i];
509 ident_parms.id = cache_entry->idents[i];
510 trc = tf_free_identifier(tfp, &ident_parms);
512 BNXT_TF_DBG(ERR, "Failed to free identifier "
513 "[%d][%s][0x%04x] rc=%d\n",
514 ident_parms.ident_type,
515 (res->direction == TF_DIR_RX) ? "RX" : "TX",
516 ident_parms.id, trc);
524 static inline int32_t
525 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp __rte_unused,
527 struct ulp_flow_db_res_params *res)
529 struct tf_free_tcam_entry_parms fparms = {
530 .dir = res->direction,
531 .tcam_tbl_type = res->resource_type,
532 .idx = (uint16_t)res->resource_hndl
535 return tf_free_tcam_entry(tfp, &fparms);
538 static inline int32_t
539 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
541 struct ulp_flow_db_res_params *res)
543 struct tf_free_tbl_entry_parms fparms = {
544 .dir = res->direction,
545 .type = res->resource_type,
546 .idx = (uint32_t)res->resource_hndl
550 * Just set the table scope, it will be ignored if not necessary
551 * by the tf_free_tbl_entry
553 bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
555 return tf_free_tbl_entry(tfp, &fparms);
558 static inline int32_t
559 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
561 struct ulp_flow_db_res_params *res)
563 struct tf_delete_em_entry_parms fparms = { 0 };
566 fparms.dir = res->direction;
567 if (res->resource_func == BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE)
568 fparms.mem = TF_MEM_EXTERNAL;
570 fparms.mem = TF_MEM_INTERNAL;
571 fparms.flow_handle = res->resource_hndl;
573 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
575 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
579 return tf_delete_em_entry(tfp, &fparms);
582 static inline int32_t
583 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
585 struct ulp_flow_db_res_params *res)
587 struct tf_free_identifier_parms fparms = {
588 .dir = res->direction,
589 .ident_type = res->resource_type,
590 .id = (uint16_t)res->resource_hndl
593 return tf_free_identifier(tfp, &fparms);
596 static inline int32_t
597 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
598 struct ulp_flow_db_res_params *res)
600 return ulp_mark_db_mark_del(ulp,
606 * Process the identifier instruction and either store it in the flow database
607 * or return it in the val (if not NULL) on success. If val is NULL, the
608 * identifier is to be stored in the flow database.
611 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
612 struct bnxt_ulp_mapper_tbl_info *tbl,
613 struct bnxt_ulp_mapper_ident_info *ident,
616 struct ulp_flow_db_res_params fid_parms;
619 struct tf_alloc_identifier_parms iparms = { 0 };
620 struct tf_free_identifier_parms free_parms = { 0 };
624 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
626 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
630 idx = ident->regfile_idx;
632 iparms.ident_type = ident->ident_type;
633 iparms.dir = tbl->direction;
635 rc = tf_alloc_identifier(tfp, &iparms);
637 BNXT_TF_DBG(ERR, "Alloc ident %s:%d failed.\n",
638 (iparms.dir == TF_DIR_RX) ? "RX" : "TX",
643 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
644 if (!ulp_regfile_write(parms->regfile, idx, id)) {
645 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
647 /* Need to free the identifier, so goto error */
651 /* Link the resource to the flow in the flow db */
653 memset(&fid_parms, 0, sizeof(fid_parms));
654 fid_parms.direction = tbl->direction;
655 fid_parms.resource_func = ident->resource_func;
656 fid_parms.resource_type = ident->ident_type;
657 fid_parms.resource_hndl = iparms.id;
658 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
660 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
665 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
667 /* Need to free the identifier, so goto error */
677 /* Need to free the identifier */
678 free_parms.dir = tbl->direction;
679 free_parms.ident_type = ident->ident_type;
680 free_parms.id = iparms.id;
682 (void)tf_free_identifier(tfp, &free_parms);
684 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
686 (tbl->direction == TF_DIR_RX) ? "RX" : "TX");
691 ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms,
693 struct bnxt_ulp_mapper_result_field_info *fld,
694 struct ulp_blob *blob,
697 uint16_t idx, size_idx;
700 uint32_t val_size = 0, field_size = 0;
704 switch (fld->result_opcode) {
705 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
706 val = fld->result_operand;
707 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
708 BNXT_TF_DBG(ERR, "%s failed to add field\n", name);
712 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_PROP:
713 if (!ulp_operand_read(fld->result_operand,
714 (uint8_t *)&idx, sizeof(uint16_t))) {
715 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
718 idx = tfp_be_to_cpu_16(idx);
720 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
721 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
724 val = &parms->act_prop->act_details[idx];
725 field_size = ulp_mapper_act_prop_size_get(idx);
726 if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
727 field_size = field_size -
728 ((fld->field_bit_size + 7) / 8);
731 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
732 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
736 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_BIT:
737 if (!ulp_operand_read(fld->result_operand,
738 (uint8_t *)&act_bit, sizeof(uint64_t))) {
739 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
742 act_bit = tfp_be_to_cpu_64(act_bit);
743 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
747 if (fld->field_bit_size > ULP_BYTE_2_BITS(sizeof(act_val))) {
748 BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
751 if (!ulp_blob_push(blob, &act_val, fld->field_bit_size)) {
752 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
757 case BNXT_ULP_MAPPER_OPC_SET_TO_ENCAP_ACT_PROP_SZ:
758 if (!ulp_operand_read(fld->result_operand,
759 (uint8_t *)&idx, sizeof(uint16_t))) {
760 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
763 idx = tfp_be_to_cpu_16(idx);
765 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
766 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
769 val = &parms->act_prop->act_details[idx];
771 /* get the size index next */
772 if (!ulp_operand_read(&fld->result_operand[sizeof(uint16_t)],
773 (uint8_t *)&size_idx, sizeof(uint16_t))) {
774 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
777 size_idx = tfp_be_to_cpu_16(size_idx);
779 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
780 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
783 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
785 val_size = tfp_be_to_cpu_32(val_size);
786 val_size = ULP_BYTE_2_BITS(val_size);
787 ulp_blob_push_encap(blob, val, val_size);
789 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
790 if (!ulp_operand_read(fld->result_operand,
791 (uint8_t *)&idx, sizeof(uint16_t))) {
792 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
796 idx = tfp_be_to_cpu_16(idx);
797 /* Uninitialized regfile entries return 0 */
798 if (!ulp_regfile_read(parms->regfile, idx, ®val)) {
799 BNXT_TF_DBG(ERR, "%s regfile[%d] read oob\n",
804 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
806 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
810 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
811 if (!ulp_operand_read(fld->result_operand,
814 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
817 idx = tfp_be_to_cpu_16(idx);
818 if (ulp_mapper_glb_resource_read(parms->mapper_data,
821 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
825 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
827 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
831 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
832 if (!ulp_operand_read(fld->result_operand,
835 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
838 idx = tfp_be_to_cpu_16(idx);
839 if (idx < BNXT_ULP_CF_IDX_LAST)
840 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
841 fld->field_bit_size);
843 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
847 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
848 if (ulp_blob_pad_push(blob, fld->field_bit_size) < 0) {
849 BNXT_TF_DBG(ERR, "%s too large for blob\n", name);
860 /* Function to alloc action record and set the table. */
862 ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms,
864 struct bnxt_ulp_mapper_class_key_field_info *f,
865 struct ulp_blob *blob,
870 uint16_t idx, bitlen;
873 struct ulp_regfile *regfile = parms->regfile;
875 struct bnxt_ulp_mapper_class_key_field_info *fld = f;
879 operand = fld->spec_operand;
880 opcode = fld->spec_opcode;
882 operand = fld->mask_operand;
883 opcode = fld->mask_opcode;
886 bitlen = fld->field_bit_size;
889 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
891 if (!ulp_blob_push(blob, val, bitlen)) {
892 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
896 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
897 if (ulp_blob_pad_push(blob, bitlen) < 0) {
898 BNXT_TF_DBG(ERR, "%s pad too large for blob\n", name);
903 case BNXT_ULP_MAPPER_OPC_SET_TO_HDR_FIELD:
904 if (!ulp_operand_read(operand, (uint8_t *)&idx,
906 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
909 idx = tfp_be_to_cpu_16(idx);
911 val = parms->hdr_field[idx].spec;
913 val = parms->hdr_field[idx].mask;
916 * Need to account for how much data was pushed to the header
917 * field vs how much is to be inserted in the key/mask.
919 field_size = parms->hdr_field[idx].size;
920 if (bitlen < ULP_BYTE_2_BITS(field_size)) {
921 field_size = field_size - ((bitlen + 7) / 8);
925 if (!ulp_blob_push(blob, val, bitlen)) {
926 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
930 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
931 if (!ulp_operand_read(operand, (uint8_t *)&idx,
933 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
936 idx = tfp_be_to_cpu_16(idx);
937 if (idx < BNXT_ULP_CF_IDX_LAST)
938 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
941 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
945 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
946 if (!ulp_operand_read(operand, (uint8_t *)&idx,
948 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
951 idx = tfp_be_to_cpu_16(idx);
953 if (!ulp_regfile_read(regfile, idx, &val64)) {
954 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
959 val = ulp_blob_push_64(blob, &val64, bitlen);
961 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
965 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
966 if (!ulp_operand_read(operand, (uint8_t *)&idx,
968 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
971 idx = tfp_be_to_cpu_16(idx);
972 if (ulp_mapper_glb_resource_read(parms->mapper_data,
975 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
979 val = ulp_blob_push_64(blob, &val64, bitlen);
981 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
993 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
994 struct bnxt_ulp_mapper_tbl_info *tbl,
997 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
998 struct ulp_flow_db_res_params fid_parms;
999 uint32_t mark, gfid, mark_flag;
1002 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1003 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1004 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1005 BNXT_ULP_ACTION_BIT_MARK)))
1006 return rc; /* no need to perform gfid process */
1008 /* Get the mark id details from action property */
1009 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1011 mark = tfp_be_to_cpu_32(mark);
1013 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1014 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1015 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1018 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1021 fid_parms.direction = tbl->direction;
1022 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1023 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1024 fid_parms.resource_type = mark_flag;
1025 fid_parms.resource_hndl = gfid;
1026 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1031 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1036 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1037 struct bnxt_ulp_mapper_tbl_info *tbl)
1039 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1040 struct ulp_flow_db_res_params fid_parms;
1041 uint32_t act_idx, mark, mark_flag;
1045 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1046 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1047 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1048 BNXT_ULP_ACTION_BIT_MARK)))
1049 return rc; /* no need to perform mark action process */
1051 /* Get the mark id details from action property */
1052 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1054 mark = tfp_be_to_cpu_32(mark);
1056 if (!ulp_regfile_read(parms->regfile,
1057 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1059 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1062 act_idx = tfp_be_to_cpu_64(val64);
1063 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1064 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1067 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1070 fid_parms.direction = tbl->direction;
1071 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1072 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1073 fid_parms.resource_type = mark_flag;
1074 fid_parms.resource_hndl = act_idx;
1075 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1080 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1085 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1086 struct bnxt_ulp_mapper_tbl_info *tbl)
1088 struct ulp_flow_db_res_params fid_parms;
1089 uint32_t act_idx, mark, mark_flag;
1091 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1094 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1095 mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION)
1096 return rc; /* no need to perform mark action process */
1098 /* Get the mark id details from the computed field of dev port id */
1099 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1101 /* Get the main action pointer */
1102 if (!ulp_regfile_read(parms->regfile,
1103 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1105 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1108 act_idx = tfp_be_to_cpu_64(val64);
1110 /* Set the mark flag to local fid and vfr flag */
1111 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1113 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1116 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1119 fid_parms.direction = tbl->direction;
1120 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1121 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1122 fid_parms.resource_type = mark_flag;
1123 fid_parms.resource_hndl = act_idx;
1124 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1129 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1134 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1135 struct bnxt_ulp_mapper_tbl_info *tbl)
1137 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1138 struct ulp_blob key, mask, data;
1139 uint32_t i, num_kflds;
1142 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1143 struct tf_set_tcam_entry_parms sparms = { 0 };
1144 struct ulp_flow_db_res_params fid_parms = { 0 };
1145 struct tf_free_tcam_entry_parms free_parms = { 0 };
1147 uint16_t tmplen = 0;
1149 /* Skip this if was handled by the cache. */
1150 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP) {
1151 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1155 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1157 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1161 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1162 if (!kflds || !num_kflds) {
1163 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1167 if (!ulp_blob_init(&key, tbl->key_bit_size,
1168 parms->device_params->byte_order) ||
1169 !ulp_blob_init(&mask, tbl->key_bit_size,
1170 parms->device_params->byte_order) ||
1171 !ulp_blob_init(&data, tbl->result_bit_size,
1172 parms->device_params->byte_order)) {
1173 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1177 /* create the key/mask */
1179 * NOTE: The WC table will require some kind of flag to handle the
1180 * mode bits within the key/mask
1182 for (i = 0; i < num_kflds; i++) {
1184 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1186 &key, 1, "TCAM Key");
1188 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1192 /* Setup the mask */
1193 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1195 &mask, 0, "TCAM Mask");
1197 BNXT_TF_DBG(ERR, "Mask field set failed.\n");
1202 aparms.dir = tbl->direction;
1203 aparms.tcam_tbl_type = tbl->resource_type;
1204 aparms.search_enable = tbl->srch_b4_alloc;
1205 aparms.key_sz_in_bits = tbl->key_bit_size;
1206 aparms.key = ulp_blob_data_get(&key, &tmplen);
1207 if (tbl->key_bit_size != tmplen) {
1208 BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n",
1209 tmplen, tbl->key_bit_size);
1213 aparms.mask = ulp_blob_data_get(&mask, &tmplen);
1214 if (tbl->key_bit_size != tmplen) {
1215 BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n",
1216 tmplen, tbl->key_bit_size);
1220 aparms.priority = tbl->priority;
1223 * All failures after this succeeds require the entry to be freed.
1224 * cannot return directly on failure, but needs to goto error
1226 rc = tf_alloc_tcam_entry(tfp, &aparms);
1228 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1234 /* Build the result */
1235 if (!tbl->srch_b4_alloc || !hit) {
1236 struct bnxt_ulp_mapper_result_field_info *dflds;
1237 struct bnxt_ulp_mapper_ident_info *idents;
1238 uint32_t num_dflds, num_idents;
1239 uint32_t encap_flds = 0;
1242 * Since the cache entry is responsible for allocating
1243 * identifiers when in use, allocate the identifiers only
1244 * during normal processing.
1246 if (parms->tcam_tbl_opc ==
1247 BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1248 idents = ulp_mapper_ident_fields_get(tbl, &num_idents);
1250 for (i = 0; i < num_idents; i++) {
1251 rc = ulp_mapper_ident_process(parms, tbl,
1253 /* Already logged the error, just return */
1259 /* Create the result data blob */
1260 dflds = ulp_mapper_result_fields_get(tbl, &num_dflds,
1262 if (!dflds || !num_dflds || encap_flds) {
1263 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1268 for (i = 0; i < num_dflds; i++) {
1269 rc = ulp_mapper_result_field_process(parms,
1275 BNXT_TF_DBG(ERR, "Failed to set data fields\n");
1280 sparms.dir = aparms.dir;
1281 sparms.tcam_tbl_type = aparms.tcam_tbl_type;
1282 sparms.idx = aparms.idx;
1283 /* Already verified the key/mask lengths */
1284 sparms.key = ulp_blob_data_get(&key, &tmplen);
1285 sparms.mask = ulp_blob_data_get(&mask, &tmplen);
1286 sparms.key_sz_in_bits = tbl->key_bit_size;
1287 sparms.result = ulp_blob_data_get(&data, &tmplen);
1289 if (tbl->result_bit_size != tmplen) {
1290 BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n",
1291 tmplen, tbl->result_bit_size);
1295 sparms.result_sz_in_bits = tbl->result_bit_size;
1297 rc = tf_set_tcam_entry(tfp, &sparms);
1299 BNXT_TF_DBG(ERR, "tcam[%d][%s][%d] write failed.\n",
1300 sparms.tcam_tbl_type,
1301 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1306 /* Update cache with TCAM index if the was cache allocated. */
1307 if (parms->tcam_tbl_opc ==
1308 BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) {
1309 if (!parms->cache_ptr) {
1310 BNXT_TF_DBG(ERR, "Unable to update cache");
1314 parms->cache_ptr->tcam_idx = aparms.idx;
1318 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1323 BNXT_TF_DBG(ERR, "Not supporting search before alloc now\n");
1329 * Only link the entry to the flow db in the event that cache was not
1332 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1333 fid_parms.direction = tbl->direction;
1334 fid_parms.resource_func = tbl->resource_func;
1335 fid_parms.resource_type = tbl->resource_type;
1336 fid_parms.critical_resource = tbl->critical_resource;
1337 fid_parms.resource_hndl = aparms.idx;
1338 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1344 "Failed to link resource to flow rc = %d\n",
1346 /* Need to free the identifier, so goto error */
1351 * Reset the tcam table opcode to normal in case the next tcam
1352 * entry does not use cache.
1354 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1355 parms->cache_ptr = NULL;
1360 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1361 free_parms.dir = tbl->direction;
1362 free_parms.tcam_tbl_type = tbl->resource_type;
1363 free_parms.idx = aparms.idx;
1364 trc = tf_free_tcam_entry(tfp, &free_parms);
1366 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
1367 tbl->resource_type, tbl->direction, aparms.idx);
1373 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1374 struct bnxt_ulp_mapper_tbl_info *tbl)
1376 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1377 struct bnxt_ulp_mapper_result_field_info *dflds;
1378 struct ulp_blob key, data;
1379 uint32_t i, num_kflds, num_dflds;
1381 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1382 struct ulp_flow_db_res_params fid_parms = { 0 };
1383 struct tf_insert_em_entry_parms iparms = { 0 };
1384 struct tf_delete_em_entry_parms free_parms = { 0 };
1386 enum bnxt_ulp_flow_mem_type mtype = parms->device_params->flow_mem_type;
1388 uint32_t encap_flds = 0;
1390 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1391 if (!kflds || !num_kflds) {
1392 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1396 /* Initialize the key/result blobs */
1397 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
1398 parms->device_params->byte_order) ||
1399 !ulp_blob_init(&data, tbl->result_bit_size,
1400 parms->device_params->byte_order)) {
1401 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1405 /* create the key */
1406 for (i = 0; i < num_kflds; i++) {
1408 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1412 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1418 * TBD: Normally should process identifiers in case of using recycle or
1419 * loopback. Not supporting recycle for now.
1422 /* Create the result data blob */
1423 dflds = ulp_mapper_result_fields_get(tbl, &num_dflds, &encap_flds);
1424 if (!dflds || !num_dflds || encap_flds) {
1425 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1429 for (i = 0; i < num_dflds; i++) {
1430 struct bnxt_ulp_mapper_result_field_info *fld;
1434 rc = ulp_mapper_result_field_process(parms,
1440 BNXT_TF_DBG(ERR, "Failed to set data fields.\n");
1444 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1445 ulp_mapper_result_dump("EEM Result", tbl, &data);
1448 /* do the transpose for the internal EM keys */
1449 if (tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE)
1450 ulp_blob_perform_byte_reverse(&key);
1452 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
1453 &iparms.tbl_scope_id);
1455 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1460 * NOTE: the actual blob size will differ from the size in the tbl
1461 * entry due to the padding.
1463 iparms.dup_check = 0;
1464 iparms.dir = tbl->direction;
1465 iparms.mem = tbl->resource_type;
1466 iparms.key = ulp_blob_data_get(&key, &tmplen);
1467 iparms.key_sz_in_bits = tbl->key_bit_size;
1468 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
1469 iparms.em_record_sz_in_bits = tbl->result_bit_size;
1471 rc = tf_insert_em_entry(tfp, &iparms);
1473 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
1477 /* Mark action process */
1478 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
1479 tbl->resource_type == TF_MEM_EXTERNAL)
1480 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
1481 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
1482 tbl->resource_type == TF_MEM_INTERNAL)
1483 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1485 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1489 /* Link the EM resource to the flow in the flow db */
1490 memset(&fid_parms, 0, sizeof(fid_parms));
1491 fid_parms.direction = tbl->direction;
1492 fid_parms.resource_func = tbl->resource_func;
1493 fid_parms.resource_type = tbl->resource_type;
1494 fid_parms.critical_resource = tbl->critical_resource;
1495 fid_parms.resource_hndl = iparms.flow_handle;
1497 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1502 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
1504 /* Need to free the identifier, so goto error */
1510 free_parms.dir = iparms.dir;
1511 free_parms.mem = iparms.mem;
1512 free_parms.tbl_scope_id = iparms.tbl_scope_id;
1513 free_parms.flow_handle = iparms.flow_handle;
1515 trc = tf_delete_em_entry(tfp, &free_parms);
1517 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
1523 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1524 struct bnxt_ulp_mapper_tbl_info *tbl,
1527 struct bnxt_ulp_mapper_result_field_info *flds;
1528 struct ulp_flow_db_res_params fid_parms;
1529 struct ulp_blob data;
1532 uint32_t i, num_flds;
1533 int32_t rc = 0, trc = 0;
1534 struct tf_alloc_tbl_entry_parms aparms = { 0 };
1535 struct tf_set_tbl_entry_parms sparms = { 0 };
1536 struct tf_free_tbl_entry_parms free_parms = { 0 };
1537 uint32_t tbl_scope_id;
1538 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1540 uint32_t encap_flds = 0;
1542 /* Get the scope id first */
1543 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
1545 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1549 /* use the max size if encap is enabled */
1550 if (tbl->encap_num_fields)
1551 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
1553 bit_size = tbl->result_bit_size;
1555 /* Initialize the blob data */
1556 if (!ulp_blob_init(&data, bit_size,
1557 parms->device_params->byte_order)) {
1558 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1562 /* Get the result fields list */
1564 flds = ulp_mapper_result_fields_get(tbl, &num_flds,
1567 flds = ulp_mapper_act_result_fields_get(tbl, &num_flds,
1570 if (!flds || (!num_flds && !encap_flds)) {
1571 BNXT_TF_DBG(ERR, "template undefined for the index table\n");
1575 /* process the result fields, loop through them */
1576 for (i = 0; i < (num_flds + encap_flds); i++) {
1577 /* set the swap index if encap swap bit is enabled */
1578 if (parms->device_params->encap_byte_swap && encap_flds &&
1580 ulp_blob_encap_swap_idx_set(&data);
1582 /* Process the result fields */
1583 rc = ulp_mapper_result_field_process(parms,
1589 BNXT_TF_DBG(ERR, "data field failed\n");
1594 /* if encap bit swap is enabled perform the bit swap */
1595 if (parms->device_params->encap_byte_swap && encap_flds) {
1596 ulp_blob_perform_encap_swap(&data);
1597 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1598 BNXT_TF_DBG(INFO, "Dump after encap swap\n");
1599 ulp_mapper_blob_dump(&data);
1604 * Check for index opcode, if it is Global then
1605 * no need to allocate the table, just set the table
1606 * and exit since it is not maintained in the flow db.
1608 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_GLOBAL) {
1609 /* get the index from index operand */
1610 if (tbl->index_operand < BNXT_ULP_GLB_REGFILE_INDEX_LAST &&
1611 ulp_mapper_glb_resource_read(parms->mapper_data,
1615 BNXT_TF_DBG(ERR, "Glbl regfile[%d] read failed.\n",
1616 tbl->index_operand);
1619 /* set the Tf index table */
1620 sparms.dir = tbl->direction;
1621 sparms.type = tbl->resource_type;
1622 sparms.data = ulp_blob_data_get(&data, &tmplen);
1623 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1624 sparms.idx = tfp_be_to_cpu_64(idx);
1625 sparms.tbl_scope_id = tbl_scope_id;
1627 rc = tf_set_tbl_entry(tfp, &sparms);
1630 "Glbl Set table[%d][%s][%d] failed rc=%d\n",
1632 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1637 return 0; /* success */
1640 /* Perform the tf table allocation by filling the alloc params */
1641 aparms.dir = tbl->direction;
1642 aparms.type = tbl->resource_type;
1643 aparms.search_enable = tbl->srch_b4_alloc;
1644 aparms.result = ulp_blob_data_get(&data, &tmplen);
1645 aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1646 aparms.tbl_scope_id = tbl_scope_id;
1648 /* All failures after the alloc succeeds require a free */
1649 rc = tf_alloc_tbl_entry(tfp, &aparms);
1651 BNXT_TF_DBG(ERR, "Alloc table[%d][%s] failed rc=%d\n",
1653 (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
1659 * calculate the idx for the result record, for external EM the offset
1660 * needs to be shifted accordingly. If external non-inline table types
1661 * are used then need to revisit this logic.
1663 if (aparms.type == TF_TBL_TYPE_EXT)
1664 idx = TF_ACT_REC_OFFSET_2_PTR(aparms.idx);
1668 /* Always storing values in Regfile in BE */
1669 idx = tfp_cpu_to_be_64(idx);
1670 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_ALLOCATE) {
1671 rc = ulp_regfile_write(parms->regfile, tbl->index_operand, idx);
1673 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
1674 tbl->index_operand);
1679 /* Perform the tf table set by filling the set params */
1680 if (!tbl->srch_b4_alloc || !aparms.hit) {
1681 sparms.dir = tbl->direction;
1682 sparms.type = tbl->resource_type;
1683 sparms.data = ulp_blob_data_get(&data, &tmplen);
1684 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1685 sparms.idx = aparms.idx;
1686 sparms.tbl_scope_id = tbl_scope_id;
1688 rc = tf_set_tbl_entry(tfp, &sparms);
1690 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
1692 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1699 /* Link the resource to the flow in the flow db */
1700 memset(&fid_parms, 0, sizeof(fid_parms));
1701 fid_parms.direction = tbl->direction;
1702 fid_parms.resource_func = tbl->resource_func;
1703 fid_parms.resource_type = tbl->resource_type;
1704 fid_parms.resource_sub_type = tbl->resource_sub_type;
1705 fid_parms.resource_hndl = aparms.idx;
1706 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1708 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1713 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
1718 /* Perform the VF rep action */
1719 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
1721 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
1727 * Free the allocated resource since we failed to either
1728 * write to the entry or link the flow
1730 free_parms.dir = tbl->direction;
1731 free_parms.type = tbl->resource_type;
1732 free_parms.idx = aparms.idx;
1733 free_parms.tbl_scope_id = tbl_scope_id;
1735 trc = tf_free_tbl_entry(tfp, &free_parms);
1737 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
1743 ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1744 struct bnxt_ulp_mapper_tbl_info *tbl)
1746 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1747 struct bnxt_ulp_mapper_cache_entry *cache_entry;
1748 struct bnxt_ulp_mapper_ident_info *idents;
1749 uint32_t i, num_kflds = 0, num_idents = 0;
1750 struct ulp_flow_db_res_params fid_parms;
1751 struct tf_free_identifier_parms fparms;
1752 uint16_t tmplen, tmp_ident;
1753 struct ulp_blob key;
1759 /* Get the key fields list and build the key. */
1760 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1761 if (!kflds || !num_kflds) {
1762 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1765 if (!ulp_blob_init(&key, tbl->key_bit_size,
1766 parms->device_params->byte_order)) {
1767 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
1770 for (i = 0; i < num_kflds; i++) {
1772 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1774 &key, 1, "Cache Key");
1777 "Failed to create key for Cache rc=%d\n",
1784 * Perform the lookup in the cache table with constructed key. The
1785 * cache_key is a byte array of tmplen, it needs to be converted to a
1786 * index for the cache table.
1788 cache_key = ulp_blob_data_get(&key, &tmplen);
1789 ckey = (uint16_t *)cache_key;
1792 * The id computed based on resource sub type and direction where
1793 * dir is the bit0 and rest of the bits come from resource
1796 cache_entry = ulp_mapper_cache_entry_get(parms->ulp_ctx,
1797 (tbl->resource_sub_type << 1 |
1798 (tbl->direction & 0x1)),
1802 * Get the identifier list for processing by both the hit and miss
1805 idents = ulp_mapper_ident_fields_get(tbl, &num_idents);
1807 if (!cache_entry->ref_count) {
1808 /* Initialize the cache entry */
1809 cache_entry->tcam_idx = 0;
1810 cache_entry->ref_count = 0;
1811 for (i = 0; i < BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM; i++)
1812 cache_entry->idents[i] = ULP_IDENTS_INVALID;
1814 /* Need to allocate identifiers for storing in the cache. */
1815 for (i = 0; i < num_idents; i++) {
1817 * Since we are using the cache, the identifier does not
1818 * get added to the flow db. Pass in the pointer to the
1821 rc = ulp_mapper_ident_process(parms, tbl,
1822 &idents[i], &tmp_ident);
1826 cache_entry->ident_types[i] = idents[i].ident_type;
1827 cache_entry->idents[i] = tmp_ident;
1830 /* Tell the TCAM processor to alloc an entry */
1831 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC;
1832 /* Store the cache key for use by the tcam process code */
1833 parms->cache_ptr = cache_entry;
1835 /* Cache hit, get values from result. */
1836 for (i = 0; i < num_idents; i++) {
1837 regval = (uint64_t)cache_entry->idents[i];
1838 if (!ulp_regfile_write(parms->regfile,
1839 idents[i].regfile_idx,
1840 tfp_cpu_to_be_64(regval))) {
1842 "Failed to write to regfile\n");
1847 * The cached entry is being used, so let the tcam processing
1848 * know not to process this table.
1850 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP;
1853 /* Made through the cache processing, increment the reference count. */
1854 cache_entry->ref_count++;
1856 /* Link the cache to the flow db. */
1857 memset(&fid_parms, 0, sizeof(fid_parms));
1858 fid_parms.direction = tbl->direction;
1859 fid_parms.resource_func = tbl->resource_func;
1862 * Cache resource type is composed of table_type, resource
1863 * sub type and direction, it needs to set appropriately via setter.
1865 ulp_mapper_cache_res_type_set(&fid_parms,
1867 (tbl->resource_sub_type << 1 |
1868 (tbl->direction & 0x1)));
1869 fid_parms.resource_hndl = (uint64_t)*ckey;
1870 fid_parms.critical_resource = tbl->critical_resource;
1871 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1876 BNXT_TF_DBG(ERR, "Failed to add cache to flow db.\n");
1881 * This error handling only gets called when the idents are being
1882 * allocated for the cache on misses. Using the num_idents that was
1885 for (i = 0; i < num_idents; i++) {
1886 if (cache_entry->idents[i] == ULP_IDENTS_INVALID)
1889 fparms.dir = tbl->direction;
1890 fparms.ident_type = idents[i].ident_type;
1891 fparms.id = cache_entry->idents[i];
1892 tf_free_identifier(parms->tfp, &fparms);
1899 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1900 struct bnxt_ulp_mapper_tbl_info *tbl)
1902 struct bnxt_ulp_mapper_result_field_info *flds;
1903 struct ulp_blob data;
1906 uint32_t i, num_flds;
1908 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
1909 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1910 uint32_t encap_flds;
1912 /* Initialize the blob data */
1913 if (!ulp_blob_init(&data, tbl->result_bit_size,
1914 parms->device_params->byte_order)) {
1915 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1919 /* Get the result fields list */
1920 flds = ulp_mapper_result_fields_get(tbl, &num_flds, &encap_flds);
1922 if (!flds || !num_flds || encap_flds) {
1923 BNXT_TF_DBG(ERR, "template undefined for the IF table\n");
1927 /* process the result fields, loop through them */
1928 for (i = 0; i < num_flds; i++) {
1929 /* Process the result fields */
1930 rc = ulp_mapper_result_field_process(parms,
1936 BNXT_TF_DBG(ERR, "data field failed\n");
1941 /* Get the index details from computed field */
1942 if (tbl->index_opcode != BNXT_ULP_INDEX_OPCODE_COMP_FIELD) {
1943 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
1946 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->index_operand);
1948 /* Perform the tf table set by filling the set params */
1949 iftbl_params.dir = tbl->direction;
1950 iftbl_params.type = tbl->resource_type;
1951 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
1952 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1953 iftbl_params.idx = idx;
1955 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
1957 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
1959 (iftbl_params.dir == TF_DIR_RX) ? "RX" : "TX",
1966 * TBD: Need to look at the need to store idx in flow db for restore
1967 * the table to its original state on deletion of this entry.
1973 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
1974 struct bnxt_ulp_mapper_data *mapper_data)
1976 struct bnxt_ulp_glb_resource_info *glb_res;
1977 uint32_t num_glb_res_ids, idx;
1980 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
1981 if (!glb_res || !num_glb_res_ids) {
1982 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
1986 /* Iterate the global resources and process each one */
1987 for (idx = 0; idx < num_glb_res_ids; idx++) {
1988 switch (glb_res[idx].resource_func) {
1989 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
1990 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
1994 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
1995 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
2000 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
2001 glb_res[idx].resource_func);
2012 * Function to process the conditional opcode of the mapper table.
2013 * returns 1 to skip the table.
2014 * return 0 to continue processing the table.
2017 ulp_mapper_tbl_cond_opcode_process(struct bnxt_ulp_mapper_parms *parms,
2018 struct bnxt_ulp_mapper_tbl_info *tbl)
2022 switch (tbl->cond_opcode) {
2023 case BNXT_ULP_COND_OPCODE_NOP:
2026 case BNXT_ULP_COND_OPCODE_COMP_FIELD:
2027 if (tbl->cond_operand < BNXT_ULP_CF_IDX_LAST &&
2028 ULP_COMP_FLD_IDX_RD(parms, tbl->cond_operand))
2031 case BNXT_ULP_COND_OPCODE_ACTION_BIT:
2032 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits,
2036 case BNXT_ULP_COND_OPCODE_HDR_BIT:
2037 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
2043 "Invalid arg in mapper tbl for cond opcode\n");
2050 * Function to process the action template. Iterate through the list
2051 * action info templates and process it.
2054 ulp_mapper_action_tbls_process(struct bnxt_ulp_mapper_parms *parms)
2058 struct bnxt_ulp_mapper_tbl_info *tbl;
2060 if (!parms->atbls || !parms->num_atbls) {
2061 BNXT_TF_DBG(ERR, "No action tables for template[%d][%d].\n",
2062 parms->dev_id, parms->act_tid);
2066 for (i = 0; i < parms->num_atbls; i++) {
2067 tbl = &parms->atbls[i];
2068 if (ulp_mapper_tbl_cond_opcode_process(parms, tbl))
2071 switch (tbl->resource_func) {
2072 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2073 rc = ulp_mapper_index_tbl_process(parms, tbl, false);
2075 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2076 tbl->resource_func);
2081 BNXT_TF_DBG(ERR, "Unexpected action resource %d\n",
2082 tbl->resource_func);
2090 /* Create the classifier table entries for a flow. */
2092 ulp_mapper_class_tbls_process(struct bnxt_ulp_mapper_parms *parms)
2100 if (!parms->ctbls || !parms->num_ctbls) {
2101 BNXT_TF_DBG(ERR, "No class tables for template[%d][%d].\n",
2102 parms->dev_id, parms->class_tid);
2106 for (i = 0; i < parms->num_ctbls; i++) {
2107 struct bnxt_ulp_mapper_tbl_info *tbl = &parms->ctbls[i];
2109 if (ulp_mapper_tbl_cond_opcode_process(parms, tbl))
2112 switch (tbl->resource_func) {
2113 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2114 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
2116 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2117 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2118 rc = ulp_mapper_em_tbl_process(parms, tbl);
2120 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2121 rc = ulp_mapper_index_tbl_process(parms, tbl, true);
2123 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2124 rc = ulp_mapper_cache_tbl_process(parms, tbl);
2126 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
2127 rc = ulp_mapper_if_tbl_process(parms, tbl);
2130 BNXT_TF_DBG(ERR, "Unexpected class resource %d\n",
2131 tbl->resource_func);
2136 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2137 tbl->resource_func);
2146 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
2147 struct ulp_flow_db_res_params *res)
2153 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
2157 tfp = bnxt_ulp_cntxt_tfp_get(ulp);
2159 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
2163 switch (res->resource_func) {
2164 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2165 rc = ulp_mapper_cache_entry_free(ulp, tfp, res);
2167 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2168 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
2170 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2171 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2172 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
2174 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2175 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
2177 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2178 rc = ulp_mapper_ident_free(ulp, tfp, res);
2180 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
2181 rc = ulp_mapper_mark_free(ulp, res);
2191 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
2193 enum bnxt_ulp_flow_db_tables tbl_type)
2195 struct ulp_flow_db_res_params res_parms = { 0 };
2199 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2204 * Set the critical resource on the first resource del, then iterate
2205 * while status is good
2207 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
2208 rc = ulp_flow_db_resource_del(ulp_ctx, tbl_type, fid, &res_parms);
2212 * This is unexpected on the first call to resource del.
2213 * It likely means that the flow did not exist in the flow db.
2215 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
2221 trc = ulp_mapper_resource_free(ulp_ctx, &res_parms);
2224 * On fail, we still need to attempt to free the
2225 * remaining resources. Don't return
2228 "Flow[%d][0x%x] Res[%d][0x%016" PRIx64
2229 "] failed rc=%d.\n",
2230 tbl_type, fid, res_parms.resource_func,
2231 res_parms.resource_hndl, trc);
2233 /* All subsequent call require the non-critical_resource */
2234 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
2236 rc = ulp_flow_db_resource_del(ulp_ctx,
2242 /* Free the Flow ID since we've removed all resources */
2243 rc = ulp_flow_db_fid_free(ulp_ctx, tbl_type, fid);
2249 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
2250 struct bnxt_ulp_mapper_data *mapper_data)
2252 struct bnxt_ulp_mapper_glb_resource_entry *ent;
2253 struct ulp_flow_db_res_params res;
2256 /* Iterate the global resources and process each one */
2257 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
2258 for (idx = 0; idx < BNXT_ULP_GLB_RESOURCE_INFO_TBL_MAX_SZ;
2260 ent = &mapper_data->glb_res_tbl[dir][idx];
2261 if (ent->resource_func ==
2262 BNXT_ULP_RESOURCE_FUNC_INVALID)
2264 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
2265 res.resource_func = ent->resource_func;
2266 res.direction = dir;
2267 res.resource_type = ent->resource_type;
2268 /*convert it from BE to cpu */
2270 tfp_be_to_cpu_64(ent->resource_hndl);
2271 ulp_mapper_resource_free(ulp_ctx, &res);
2277 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, uint32_t fid,
2278 enum bnxt_ulp_flow_db_tables flow_tbl_type)
2281 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2285 return ulp_mapper_resources_free(ulp_ctx, fid, flow_tbl_type);
2288 /* Function to handle the default global templates that are allocated during
2289 * the startup and reused later.
2292 ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx)
2294 uint32_t *glbl_tmpl_list;
2295 uint32_t num_glb_tmpls, idx, dev_id;
2296 struct bnxt_ulp_mapper_parms parms;
2297 struct bnxt_ulp_mapper_data *mapper_data;
2300 glbl_tmpl_list = ulp_mapper_glb_template_table_get(&num_glb_tmpls);
2301 if (!glbl_tmpl_list || !num_glb_tmpls)
2302 return rc; /* No global templates to process */
2304 /* Get the device id from the ulp context */
2305 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
2306 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2310 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2312 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2316 /* Iterate the global resources and process each one */
2317 for (idx = 0; idx < num_glb_tmpls; idx++) {
2318 /* Initialize the parms structure */
2319 memset(&parms, 0, sizeof(parms));
2320 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2321 parms.ulp_ctx = ulp_ctx;
2322 parms.dev_id = dev_id;
2323 parms.mapper_data = mapper_data;
2325 /* Get the class table entry from dev id and class id */
2326 parms.class_tid = glbl_tmpl_list[idx];
2327 parms.ctbls = ulp_mapper_class_tbl_list_get(parms.dev_id,
2331 if (!parms.ctbls || !parms.num_ctbls) {
2332 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2333 parms.dev_id, parms.class_tid);
2336 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2337 if (!parms.device_params) {
2338 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2339 parms.dev_id, parms.class_tid);
2342 rc = ulp_mapper_class_tbls_process(&parms);
2345 "class tables failed creation for %d:%d\n",
2346 parms.dev_id, parms.class_tid);
2353 /* Function to handle the mapping of the Flow to be compatible
2354 * with the underlying hardware.
2357 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
2358 struct bnxt_ulp_mapper_create_parms *cparms,
2361 struct bnxt_ulp_mapper_parms parms;
2362 struct ulp_regfile regfile;
2365 if (!ulp_ctx || !cparms)
2368 /* Initialize the parms structure */
2369 memset(&parms, 0, sizeof(parms));
2370 parms.act_prop = cparms->act_prop;
2371 parms.act_bitmap = cparms->act;
2372 parms.hdr_bitmap = cparms->hdr_bitmap;
2373 parms.regfile = ®file;
2374 parms.hdr_field = cparms->hdr_field;
2375 parms.comp_fld = cparms->comp_fld;
2376 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2377 parms.ulp_ctx = ulp_ctx;
2378 parms.tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
2380 /* Get the device id from the ulp context */
2381 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
2382 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2387 * Get the mapper data for dynamic mapper data such as default
2390 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
2391 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2392 if (!parms.mapper_data) {
2393 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2397 /* Get the action table entry from device id and act context id */
2398 parms.act_tid = cparms->act_tid;
2401 * Perform the action table get only if act template is not zero
2402 * for act template zero like for default rules ignore the action
2405 if (parms.act_tid) {
2406 parms.atbls = ulp_mapper_action_tbl_list_get(parms.dev_id,
2409 if (!parms.atbls || !parms.num_atbls) {
2410 BNXT_TF_DBG(ERR, "No action tables for %d:%d\n",
2411 parms.dev_id, parms.act_tid);
2416 /* Get the class table entry from device id and act context id */
2417 parms.class_tid = cparms->class_tid;
2418 parms.ctbls = ulp_mapper_class_tbl_list_get(parms.dev_id,
2422 if (!parms.ctbls || !parms.num_ctbls) {
2423 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2424 parms.dev_id, parms.class_tid);
2428 /* Get the device params, it will be used in later processing */
2429 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2430 if (!parms.device_params) {
2431 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2432 parms.dev_id, parms.class_tid);
2436 /* initialize the registry file for further processing */
2437 if (!ulp_regfile_init(parms.regfile)) {
2438 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
2442 rc = ulp_regfile_write(parms.regfile,
2443 BNXT_ULP_REGFILE_INDEX_CLASS_TID,
2444 tfp_cpu_to_be_64((uint64_t)parms.class_tid));
2446 BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
2450 /* Allocate a Flow ID for attaching all resources for the flow to.
2451 * Once allocated, all errors have to walk the list of resources and
2452 * free each of them.
2454 rc = ulp_flow_db_fid_alloc(ulp_ctx,
2459 BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n");
2463 /* Process the action template list from the selected action table*/
2464 if (parms.act_tid) {
2465 rc = ulp_mapper_action_tbls_process(&parms);
2468 "action tables failed creation for %d:%d\n",
2469 parms.dev_id, parms.act_tid);
2474 /* All good. Now process the class template */
2475 rc = ulp_mapper_class_tbls_process(&parms);
2477 BNXT_TF_DBG(ERR, "class tables failed creation for %d:%d\n",
2478 parms.dev_id, parms.class_tid);
2482 *flowid = parms.fid;
2487 /* Free all resources that were allocated during flow creation */
2488 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.fid,
2489 BNXT_ULP_REGULAR_FLOW_TABLE);
2491 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
2497 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
2499 struct bnxt_ulp_cache_tbl_params *tbl;
2500 struct bnxt_ulp_mapper_data *data;
2508 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2512 data = rte_zmalloc("ulp_mapper_data",
2513 sizeof(struct bnxt_ulp_mapper_data), 0);
2515 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
2519 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
2520 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
2521 /* Don't call deinit since the prof_func wasn't allocated. */
2526 /* Allocate the global resource ids */
2527 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
2529 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
2533 /* Allocate the ulp cache tables. */
2534 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
2535 tbl = ulp_mapper_cache_tbl_params_get(i);
2537 BNXT_TF_DBG(ERR, "Failed to get cache table parms (%d)",
2541 if (tbl->num_entries != 0) {
2542 csize = sizeof(struct bnxt_ulp_mapper_cache_entry) *
2544 data->cache_tbl[i] = rte_zmalloc("ulp mapper cache tbl",
2546 if (!data->cache_tbl[i]) {
2547 BNXT_TF_DBG(ERR, "Failed to allocate Cache "
2555 rc = ulp_mapper_glb_template_table_init(ulp_ctx);
2557 BNXT_TF_DBG(ERR, "Failed to initialize global templates\n");
2563 /* Ignore the return code in favor of returning the original error. */
2564 ulp_mapper_deinit(ulp_ctx);
2569 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
2571 struct bnxt_ulp_mapper_data *data;
2577 "Failed to acquire ulp context, so data may "
2578 "not be released.\n");
2582 data = (struct bnxt_ulp_mapper_data *)
2583 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2585 /* Go ahead and return since there is no allocated data. */
2586 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
2590 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2592 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
2593 /* Free the mapper data regardless of errors. */
2594 goto free_mapper_data;
2597 /* Free the global resource info table entries */
2598 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
2601 /* Free the ulp cache tables */
2602 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
2603 rte_free(data->cache_tbl[i]);
2604 data->cache_tbl[i] = NULL;
2608 /* Reset the data pointer within the ulp_ctx. */
2609 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);