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_eem_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 fparms.mem = TF_MEM_EXTERNAL;
568 fparms.flow_handle = res->resource_hndl;
570 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
572 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
576 return tf_delete_em_entry(tfp, &fparms);
579 static inline int32_t
580 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
582 struct ulp_flow_db_res_params *res)
584 struct tf_free_identifier_parms fparms = {
585 .dir = res->direction,
586 .ident_type = res->resource_type,
587 .id = (uint16_t)res->resource_hndl
590 return tf_free_identifier(tfp, &fparms);
593 static inline int32_t
594 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
595 struct ulp_flow_db_res_params *res)
597 return ulp_mark_db_mark_del(ulp,
603 * Process the identifier instruction and either store it in the flow database
604 * or return it in the val (if not NULL) on success. If val is NULL, the
605 * identifier is to be stored in the flow database.
608 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
609 struct bnxt_ulp_mapper_tbl_info *tbl,
610 struct bnxt_ulp_mapper_ident_info *ident,
613 struct ulp_flow_db_res_params fid_parms;
616 struct tf_alloc_identifier_parms iparms = { 0 };
617 struct tf_free_identifier_parms free_parms = { 0 };
621 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
623 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
627 idx = ident->regfile_idx;
629 iparms.ident_type = ident->ident_type;
630 iparms.dir = tbl->direction;
632 rc = tf_alloc_identifier(tfp, &iparms);
634 BNXT_TF_DBG(ERR, "Alloc ident %s:%d failed.\n",
635 (iparms.dir == TF_DIR_RX) ? "RX" : "TX",
640 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
641 if (!ulp_regfile_write(parms->regfile, idx, id)) {
642 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
644 /* Need to free the identifier, so goto error */
648 /* Link the resource to the flow in the flow db */
650 memset(&fid_parms, 0, sizeof(fid_parms));
651 fid_parms.direction = tbl->direction;
652 fid_parms.resource_func = ident->resource_func;
653 fid_parms.resource_type = ident->ident_type;
654 fid_parms.resource_hndl = iparms.id;
655 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
657 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
662 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
664 /* Need to free the identifier, so goto error */
674 /* Need to free the identifier */
675 free_parms.dir = tbl->direction;
676 free_parms.ident_type = ident->ident_type;
677 free_parms.id = iparms.id;
679 (void)tf_free_identifier(tfp, &free_parms);
681 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
683 (tbl->direction == TF_DIR_RX) ? "RX" : "TX");
688 ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms,
690 struct bnxt_ulp_mapper_result_field_info *fld,
691 struct ulp_blob *blob,
694 uint16_t idx, size_idx;
697 uint32_t val_size = 0, field_size = 0;
701 switch (fld->result_opcode) {
702 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
703 val = fld->result_operand;
704 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
705 BNXT_TF_DBG(ERR, "%s failed to add field\n", name);
709 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_PROP:
710 if (!ulp_operand_read(fld->result_operand,
711 (uint8_t *)&idx, sizeof(uint16_t))) {
712 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
715 idx = tfp_be_to_cpu_16(idx);
717 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
718 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
721 val = &parms->act_prop->act_details[idx];
722 field_size = ulp_mapper_act_prop_size_get(idx);
723 if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
724 field_size = field_size -
725 ((fld->field_bit_size + 7) / 8);
728 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
729 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
733 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_BIT:
734 if (!ulp_operand_read(fld->result_operand,
735 (uint8_t *)&act_bit, sizeof(uint64_t))) {
736 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
739 act_bit = tfp_be_to_cpu_64(act_bit);
740 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
744 if (fld->field_bit_size > ULP_BYTE_2_BITS(sizeof(act_val))) {
745 BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
748 if (!ulp_blob_push(blob, &act_val, fld->field_bit_size)) {
749 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
754 case BNXT_ULP_MAPPER_OPC_SET_TO_ENCAP_ACT_PROP_SZ:
755 if (!ulp_operand_read(fld->result_operand,
756 (uint8_t *)&idx, sizeof(uint16_t))) {
757 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
760 idx = tfp_be_to_cpu_16(idx);
762 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
763 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
766 val = &parms->act_prop->act_details[idx];
768 /* get the size index next */
769 if (!ulp_operand_read(&fld->result_operand[sizeof(uint16_t)],
770 (uint8_t *)&size_idx, sizeof(uint16_t))) {
771 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
774 size_idx = tfp_be_to_cpu_16(size_idx);
776 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
777 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
780 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
782 val_size = tfp_be_to_cpu_32(val_size);
783 val_size = ULP_BYTE_2_BITS(val_size);
784 ulp_blob_push_encap(blob, val, val_size);
786 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
787 if (!ulp_operand_read(fld->result_operand,
788 (uint8_t *)&idx, sizeof(uint16_t))) {
789 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
793 idx = tfp_be_to_cpu_16(idx);
794 /* Uninitialized regfile entries return 0 */
795 if (!ulp_regfile_read(parms->regfile, idx, ®val)) {
796 BNXT_TF_DBG(ERR, "%s regfile[%d] read oob\n",
801 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
803 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
807 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
808 if (!ulp_operand_read(fld->result_operand,
811 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
814 idx = tfp_be_to_cpu_16(idx);
815 if (ulp_mapper_glb_resource_read(parms->mapper_data,
818 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
822 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
824 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
828 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
829 if (!ulp_operand_read(fld->result_operand,
832 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
835 idx = tfp_be_to_cpu_16(idx);
836 if (idx < BNXT_ULP_CF_IDX_LAST)
837 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
838 fld->field_bit_size);
840 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
844 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
845 if (ulp_blob_pad_push(blob, fld->field_bit_size) < 0) {
846 BNXT_TF_DBG(ERR, "%s too large for blob\n", name);
857 /* Function to alloc action record and set the table. */
859 ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms,
861 struct bnxt_ulp_mapper_class_key_field_info *f,
862 struct ulp_blob *blob,
867 uint16_t idx, bitlen;
870 struct ulp_regfile *regfile = parms->regfile;
872 struct bnxt_ulp_mapper_class_key_field_info *fld = f;
876 operand = fld->spec_operand;
877 opcode = fld->spec_opcode;
879 operand = fld->mask_operand;
880 opcode = fld->mask_opcode;
883 bitlen = fld->field_bit_size;
886 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
888 if (!ulp_blob_push(blob, val, bitlen)) {
889 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
893 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
894 if (ulp_blob_pad_push(blob, bitlen) < 0) {
895 BNXT_TF_DBG(ERR, "%s pad too large for blob\n", name);
900 case BNXT_ULP_MAPPER_OPC_SET_TO_HDR_FIELD:
901 if (!ulp_operand_read(operand, (uint8_t *)&idx,
903 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
906 idx = tfp_be_to_cpu_16(idx);
908 val = parms->hdr_field[idx].spec;
910 val = parms->hdr_field[idx].mask;
913 * Need to account for how much data was pushed to the header
914 * field vs how much is to be inserted in the key/mask.
916 field_size = parms->hdr_field[idx].size;
917 if (bitlen < ULP_BYTE_2_BITS(field_size)) {
918 field_size = field_size - ((bitlen + 7) / 8);
922 if (!ulp_blob_push(blob, val, bitlen)) {
923 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
927 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
928 if (!ulp_operand_read(operand, (uint8_t *)&idx,
930 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
933 idx = tfp_be_to_cpu_16(idx);
934 if (idx < BNXT_ULP_CF_IDX_LAST)
935 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
938 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
942 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
943 if (!ulp_operand_read(operand, (uint8_t *)&idx,
945 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
948 idx = tfp_be_to_cpu_16(idx);
950 if (!ulp_regfile_read(regfile, idx, &val64)) {
951 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
956 val = ulp_blob_push_64(blob, &val64, bitlen);
958 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
962 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
963 if (!ulp_operand_read(operand, (uint8_t *)&idx,
965 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
968 idx = tfp_be_to_cpu_16(idx);
969 if (ulp_mapper_glb_resource_read(parms->mapper_data,
972 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
976 val = ulp_blob_push_64(blob, &val64, bitlen);
978 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
990 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
991 struct bnxt_ulp_mapper_tbl_info *tbl,
994 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
995 struct ulp_flow_db_res_params fid_parms;
996 uint32_t mark, gfid, mark_flag;
999 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1000 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1001 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1002 BNXT_ULP_ACTION_BIT_MARK)))
1003 return rc; /* no need to perform gfid process */
1005 /* Get the mark id details from action property */
1006 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1008 mark = tfp_be_to_cpu_32(mark);
1010 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1011 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1012 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1015 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1018 fid_parms.direction = tbl->direction;
1019 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1020 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1021 fid_parms.resource_type = mark_flag;
1022 fid_parms.resource_hndl = gfid;
1023 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1028 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1033 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1034 struct bnxt_ulp_mapper_tbl_info *tbl)
1036 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1037 struct ulp_flow_db_res_params fid_parms;
1038 uint32_t act_idx, mark, mark_flag;
1042 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1043 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1044 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1045 BNXT_ULP_ACTION_BIT_MARK)))
1046 return rc; /* no need to perform mark action process */
1048 /* Get the mark id details from action property */
1049 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1051 mark = tfp_be_to_cpu_32(mark);
1053 if (!ulp_regfile_read(parms->regfile,
1054 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1056 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1059 act_idx = tfp_be_to_cpu_64(val64);
1060 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1061 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1064 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1067 fid_parms.direction = tbl->direction;
1068 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1069 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1070 fid_parms.resource_type = mark_flag;
1071 fid_parms.resource_hndl = act_idx;
1072 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1077 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1082 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1083 struct bnxt_ulp_mapper_tbl_info *tbl)
1085 struct ulp_flow_db_res_params fid_parms;
1086 uint32_t act_idx, mark, mark_flag;
1088 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1091 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1092 mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION)
1093 return rc; /* no need to perform mark action process */
1095 /* Get the mark id details from the computed field of dev port id */
1096 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1098 /* Get the main action pointer */
1099 if (!ulp_regfile_read(parms->regfile,
1100 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1102 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1105 act_idx = tfp_be_to_cpu_64(val64);
1107 /* Set the mark flag to local fid and vfr flag */
1108 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1110 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1113 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1116 fid_parms.direction = tbl->direction;
1117 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1118 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1119 fid_parms.resource_type = mark_flag;
1120 fid_parms.resource_hndl = act_idx;
1121 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1126 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1131 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1132 struct bnxt_ulp_mapper_tbl_info *tbl)
1134 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1135 struct ulp_blob key, mask, data;
1136 uint32_t i, num_kflds;
1139 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1140 struct tf_set_tcam_entry_parms sparms = { 0 };
1141 struct ulp_flow_db_res_params fid_parms = { 0 };
1142 struct tf_free_tcam_entry_parms free_parms = { 0 };
1144 uint16_t tmplen = 0;
1146 /* Skip this if was handled by the cache. */
1147 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP) {
1148 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1152 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1154 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1158 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1159 if (!kflds || !num_kflds) {
1160 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1164 if (!ulp_blob_init(&key, tbl->key_bit_size,
1165 parms->device_params->byte_order) ||
1166 !ulp_blob_init(&mask, tbl->key_bit_size,
1167 parms->device_params->byte_order) ||
1168 !ulp_blob_init(&data, tbl->result_bit_size,
1169 parms->device_params->byte_order)) {
1170 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1174 /* create the key/mask */
1176 * NOTE: The WC table will require some kind of flag to handle the
1177 * mode bits within the key/mask
1179 for (i = 0; i < num_kflds; i++) {
1181 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1183 &key, 1, "TCAM Key");
1185 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1189 /* Setup the mask */
1190 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1192 &mask, 0, "TCAM Mask");
1194 BNXT_TF_DBG(ERR, "Mask field set failed.\n");
1199 aparms.dir = tbl->direction;
1200 aparms.tcam_tbl_type = tbl->resource_type;
1201 aparms.search_enable = tbl->srch_b4_alloc;
1202 aparms.key_sz_in_bits = tbl->key_bit_size;
1203 aparms.key = ulp_blob_data_get(&key, &tmplen);
1204 if (tbl->key_bit_size != tmplen) {
1205 BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n",
1206 tmplen, tbl->key_bit_size);
1210 aparms.mask = ulp_blob_data_get(&mask, &tmplen);
1211 if (tbl->key_bit_size != tmplen) {
1212 BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n",
1213 tmplen, tbl->key_bit_size);
1217 aparms.priority = tbl->priority;
1220 * All failures after this succeeds require the entry to be freed.
1221 * cannot return directly on failure, but needs to goto error
1223 rc = tf_alloc_tcam_entry(tfp, &aparms);
1225 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1231 /* Build the result */
1232 if (!tbl->srch_b4_alloc || !hit) {
1233 struct bnxt_ulp_mapper_result_field_info *dflds;
1234 struct bnxt_ulp_mapper_ident_info *idents;
1235 uint32_t num_dflds, num_idents;
1236 uint32_t encap_flds = 0;
1239 * Since the cache entry is responsible for allocating
1240 * identifiers when in use, allocate the identifiers only
1241 * during normal processing.
1243 if (parms->tcam_tbl_opc ==
1244 BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1245 idents = ulp_mapper_ident_fields_get(tbl, &num_idents);
1247 for (i = 0; i < num_idents; i++) {
1248 rc = ulp_mapper_ident_process(parms, tbl,
1250 /* Already logged the error, just return */
1256 /* Create the result data blob */
1257 dflds = ulp_mapper_result_fields_get(tbl, &num_dflds,
1259 if (!dflds || !num_dflds || encap_flds) {
1260 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1265 for (i = 0; i < num_dflds; i++) {
1266 rc = ulp_mapper_result_field_process(parms,
1272 BNXT_TF_DBG(ERR, "Failed to set data fields\n");
1277 sparms.dir = aparms.dir;
1278 sparms.tcam_tbl_type = aparms.tcam_tbl_type;
1279 sparms.idx = aparms.idx;
1280 /* Already verified the key/mask lengths */
1281 sparms.key = ulp_blob_data_get(&key, &tmplen);
1282 sparms.mask = ulp_blob_data_get(&mask, &tmplen);
1283 sparms.key_sz_in_bits = tbl->key_bit_size;
1284 sparms.result = ulp_blob_data_get(&data, &tmplen);
1286 if (tbl->result_bit_size != tmplen) {
1287 BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n",
1288 tmplen, tbl->result_bit_size);
1292 sparms.result_sz_in_bits = tbl->result_bit_size;
1294 rc = tf_set_tcam_entry(tfp, &sparms);
1296 BNXT_TF_DBG(ERR, "tcam[%d][%s][%d] write failed.\n",
1297 sparms.tcam_tbl_type,
1298 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1303 /* Update cache with TCAM index if the was cache allocated. */
1304 if (parms->tcam_tbl_opc ==
1305 BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) {
1306 if (!parms->cache_ptr) {
1307 BNXT_TF_DBG(ERR, "Unable to update cache");
1311 parms->cache_ptr->tcam_idx = aparms.idx;
1315 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1320 BNXT_TF_DBG(ERR, "Not supporting search before alloc now\n");
1326 * Only link the entry to the flow db in the event that cache was not
1329 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1330 fid_parms.direction = tbl->direction;
1331 fid_parms.resource_func = tbl->resource_func;
1332 fid_parms.resource_type = tbl->resource_type;
1333 fid_parms.critical_resource = tbl->critical_resource;
1334 fid_parms.resource_hndl = aparms.idx;
1335 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1341 "Failed to link resource to flow rc = %d\n",
1343 /* Need to free the identifier, so goto error */
1348 * Reset the tcam table opcode to normal in case the next tcam
1349 * entry does not use cache.
1351 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1352 parms->cache_ptr = NULL;
1357 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1358 free_parms.dir = tbl->direction;
1359 free_parms.tcam_tbl_type = tbl->resource_type;
1360 free_parms.idx = aparms.idx;
1361 trc = tf_free_tcam_entry(tfp, &free_parms);
1363 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
1364 tbl->resource_type, tbl->direction, aparms.idx);
1370 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1371 struct bnxt_ulp_mapper_tbl_info *tbl)
1373 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1374 struct bnxt_ulp_mapper_result_field_info *dflds;
1375 struct ulp_blob key, data;
1376 uint32_t i, num_kflds, num_dflds;
1378 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1379 struct ulp_flow_db_res_params fid_parms = { 0 };
1380 struct tf_insert_em_entry_parms iparms = { 0 };
1381 struct tf_delete_em_entry_parms free_parms = { 0 };
1383 enum bnxt_ulp_flow_mem_type mtype = parms->device_params->flow_mem_type;
1385 uint32_t encap_flds = 0;
1387 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1388 if (!kflds || !num_kflds) {
1389 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1393 /* Initialize the key/result blobs */
1394 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
1395 parms->device_params->byte_order) ||
1396 !ulp_blob_init(&data, tbl->result_bit_size,
1397 parms->device_params->byte_order)) {
1398 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1402 /* create the key */
1403 for (i = 0; i < num_kflds; i++) {
1405 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1409 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1415 * TBD: Normally should process identifiers in case of using recycle or
1416 * loopback. Not supporting recycle for now.
1419 /* Create the result data blob */
1420 dflds = ulp_mapper_result_fields_get(tbl, &num_dflds, &encap_flds);
1421 if (!dflds || !num_dflds || encap_flds) {
1422 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1426 for (i = 0; i < num_dflds; i++) {
1427 struct bnxt_ulp_mapper_result_field_info *fld;
1431 rc = ulp_mapper_result_field_process(parms,
1437 BNXT_TF_DBG(ERR, "Failed to set data fields.\n");
1441 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1442 ulp_mapper_result_dump("EEM Result", tbl, &data);
1445 /* do the transpose for the internal EM keys */
1446 if (tbl->resource_type == TF_MEM_INTERNAL)
1447 ulp_blob_perform_byte_reverse(&key);
1449 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
1450 &iparms.tbl_scope_id);
1452 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1457 * NOTE: the actual blob size will differ from the size in the tbl
1458 * entry due to the padding.
1460 iparms.dup_check = 0;
1461 iparms.dir = tbl->direction;
1462 iparms.mem = tbl->resource_type;
1463 iparms.key = ulp_blob_data_get(&key, &tmplen);
1464 iparms.key_sz_in_bits = tbl->key_bit_size;
1465 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
1466 iparms.em_record_sz_in_bits = tbl->result_bit_size;
1468 rc = tf_insert_em_entry(tfp, &iparms);
1470 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
1474 /* Mark action process */
1475 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
1476 tbl->resource_type == TF_MEM_EXTERNAL)
1477 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
1478 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
1479 tbl->resource_type == TF_MEM_INTERNAL)
1480 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1482 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1486 /* Link the EM resource to the flow in the flow db */
1487 memset(&fid_parms, 0, sizeof(fid_parms));
1488 fid_parms.direction = tbl->direction;
1489 fid_parms.resource_func = tbl->resource_func;
1490 fid_parms.resource_type = tbl->resource_type;
1491 fid_parms.critical_resource = tbl->critical_resource;
1492 fid_parms.resource_hndl = iparms.flow_handle;
1494 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1499 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
1501 /* Need to free the identifier, so goto error */
1507 free_parms.dir = iparms.dir;
1508 free_parms.mem = iparms.mem;
1509 free_parms.tbl_scope_id = iparms.tbl_scope_id;
1510 free_parms.flow_handle = iparms.flow_handle;
1512 trc = tf_delete_em_entry(tfp, &free_parms);
1514 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
1520 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1521 struct bnxt_ulp_mapper_tbl_info *tbl,
1524 struct bnxt_ulp_mapper_result_field_info *flds;
1525 struct ulp_flow_db_res_params fid_parms;
1526 struct ulp_blob data;
1529 uint32_t i, num_flds;
1530 int32_t rc = 0, trc = 0;
1531 struct tf_alloc_tbl_entry_parms aparms = { 0 };
1532 struct tf_set_tbl_entry_parms sparms = { 0 };
1533 struct tf_free_tbl_entry_parms free_parms = { 0 };
1534 uint32_t tbl_scope_id;
1535 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1537 uint32_t encap_flds = 0;
1539 /* Get the scope id first */
1540 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
1542 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1546 /* use the max size if encap is enabled */
1547 if (tbl->encap_num_fields)
1548 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
1550 bit_size = tbl->result_bit_size;
1552 /* Initialize the blob data */
1553 if (!ulp_blob_init(&data, bit_size,
1554 parms->device_params->byte_order)) {
1555 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1559 /* Get the result fields list */
1561 flds = ulp_mapper_result_fields_get(tbl, &num_flds,
1564 flds = ulp_mapper_act_result_fields_get(tbl, &num_flds,
1567 if (!flds || (!num_flds && !encap_flds)) {
1568 BNXT_TF_DBG(ERR, "template undefined for the index table\n");
1572 /* process the result fields, loop through them */
1573 for (i = 0; i < (num_flds + encap_flds); i++) {
1574 /* set the swap index if encap swap bit is enabled */
1575 if (parms->device_params->encap_byte_swap && encap_flds &&
1577 ulp_blob_encap_swap_idx_set(&data);
1579 /* Process the result fields */
1580 rc = ulp_mapper_result_field_process(parms,
1586 BNXT_TF_DBG(ERR, "data field failed\n");
1591 /* if encap bit swap is enabled perform the bit swap */
1592 if (parms->device_params->encap_byte_swap && encap_flds) {
1593 ulp_blob_perform_encap_swap(&data);
1594 #ifdef RTE_LIBRTE_BNXT_TRUFLOW_DEBUG
1595 BNXT_TF_DBG(INFO, "Dump after encap swap\n");
1596 ulp_mapper_blob_dump(&data);
1601 * Check for index opcode, if it is Global then
1602 * no need to allocate the table, just set the table
1603 * and exit since it is not maintained in the flow db.
1605 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_GLOBAL) {
1606 /* get the index from index operand */
1607 if (tbl->index_operand < BNXT_ULP_GLB_REGFILE_INDEX_LAST &&
1608 ulp_mapper_glb_resource_read(parms->mapper_data,
1612 BNXT_TF_DBG(ERR, "Glbl regfile[%d] read failed.\n",
1613 tbl->index_operand);
1616 /* set the Tf index table */
1617 sparms.dir = tbl->direction;
1618 sparms.type = tbl->resource_type;
1619 sparms.data = ulp_blob_data_get(&data, &tmplen);
1620 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1621 sparms.idx = tfp_be_to_cpu_64(idx);
1622 sparms.tbl_scope_id = tbl_scope_id;
1624 rc = tf_set_tbl_entry(tfp, &sparms);
1627 "Glbl Set table[%d][%s][%d] failed rc=%d\n",
1629 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1634 return 0; /* success */
1637 /* Perform the tf table allocation by filling the alloc params */
1638 aparms.dir = tbl->direction;
1639 aparms.type = tbl->resource_type;
1640 aparms.search_enable = tbl->srch_b4_alloc;
1641 aparms.result = ulp_blob_data_get(&data, &tmplen);
1642 aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1643 aparms.tbl_scope_id = tbl_scope_id;
1645 /* All failures after the alloc succeeds require a free */
1646 rc = tf_alloc_tbl_entry(tfp, &aparms);
1648 BNXT_TF_DBG(ERR, "Alloc table[%d][%s] failed rc=%d\n",
1650 (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
1656 * calculate the idx for the result record, for external EM the offset
1657 * needs to be shifted accordingly. If external non-inline table types
1658 * are used then need to revisit this logic.
1660 if (aparms.type == TF_TBL_TYPE_EXT)
1661 idx = TF_ACT_REC_OFFSET_2_PTR(aparms.idx);
1665 /* Always storing values in Regfile in BE */
1666 idx = tfp_cpu_to_be_64(idx);
1667 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_ALLOCATE) {
1668 rc = ulp_regfile_write(parms->regfile, tbl->index_operand, idx);
1670 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
1671 tbl->index_operand);
1676 /* Perform the tf table set by filling the set params */
1677 if (!tbl->srch_b4_alloc || !aparms.hit) {
1678 sparms.dir = tbl->direction;
1679 sparms.type = tbl->resource_type;
1680 sparms.data = ulp_blob_data_get(&data, &tmplen);
1681 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1682 sparms.idx = aparms.idx;
1683 sparms.tbl_scope_id = tbl_scope_id;
1685 rc = tf_set_tbl_entry(tfp, &sparms);
1687 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
1689 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1696 /* Link the resource to the flow in the flow db */
1697 memset(&fid_parms, 0, sizeof(fid_parms));
1698 fid_parms.direction = tbl->direction;
1699 fid_parms.resource_func = tbl->resource_func;
1700 fid_parms.resource_type = tbl->resource_type;
1701 fid_parms.resource_sub_type = tbl->resource_sub_type;
1702 fid_parms.resource_hndl = aparms.idx;
1703 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1705 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1710 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
1715 /* Perform the VF rep action */
1716 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
1718 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
1724 * Free the allocated resource since we failed to either
1725 * write to the entry or link the flow
1727 free_parms.dir = tbl->direction;
1728 free_parms.type = tbl->resource_type;
1729 free_parms.idx = aparms.idx;
1730 free_parms.tbl_scope_id = tbl_scope_id;
1732 trc = tf_free_tbl_entry(tfp, &free_parms);
1734 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
1740 ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1741 struct bnxt_ulp_mapper_tbl_info *tbl)
1743 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1744 struct bnxt_ulp_mapper_cache_entry *cache_entry;
1745 struct bnxt_ulp_mapper_ident_info *idents;
1746 uint32_t i, num_kflds = 0, num_idents = 0;
1747 struct ulp_flow_db_res_params fid_parms;
1748 struct tf_free_identifier_parms fparms;
1749 uint16_t tmplen, tmp_ident;
1750 struct ulp_blob key;
1756 /* Get the key fields list and build the key. */
1757 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1758 if (!kflds || !num_kflds) {
1759 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1762 if (!ulp_blob_init(&key, tbl->key_bit_size,
1763 parms->device_params->byte_order)) {
1764 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
1767 for (i = 0; i < num_kflds; i++) {
1769 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1771 &key, 1, "Cache Key");
1774 "Failed to create key for Cache rc=%d\n",
1781 * Perform the lookup in the cache table with constructed key. The
1782 * cache_key is a byte array of tmplen, it needs to be converted to a
1783 * index for the cache table.
1785 cache_key = ulp_blob_data_get(&key, &tmplen);
1786 ckey = (uint16_t *)cache_key;
1789 * The id computed based on resource sub type and direction where
1790 * dir is the bit0 and rest of the bits come from resource
1793 cache_entry = ulp_mapper_cache_entry_get(parms->ulp_ctx,
1794 (tbl->resource_sub_type << 1 |
1795 (tbl->direction & 0x1)),
1799 * Get the identifier list for processing by both the hit and miss
1802 idents = ulp_mapper_ident_fields_get(tbl, &num_idents);
1804 if (!cache_entry->ref_count) {
1805 /* Initialize the cache entry */
1806 cache_entry->tcam_idx = 0;
1807 cache_entry->ref_count = 0;
1808 for (i = 0; i < BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM; i++)
1809 cache_entry->idents[i] = ULP_IDENTS_INVALID;
1811 /* Need to allocate identifiers for storing in the cache. */
1812 for (i = 0; i < num_idents; i++) {
1814 * Since we are using the cache, the identifier does not
1815 * get added to the flow db. Pass in the pointer to the
1818 rc = ulp_mapper_ident_process(parms, tbl,
1819 &idents[i], &tmp_ident);
1823 cache_entry->ident_types[i] = idents[i].ident_type;
1824 cache_entry->idents[i] = tmp_ident;
1827 /* Tell the TCAM processor to alloc an entry */
1828 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC;
1829 /* Store the cache key for use by the tcam process code */
1830 parms->cache_ptr = cache_entry;
1832 /* Cache hit, get values from result. */
1833 for (i = 0; i < num_idents; i++) {
1834 regval = (uint64_t)cache_entry->idents[i];
1835 if (!ulp_regfile_write(parms->regfile,
1836 idents[i].regfile_idx,
1837 tfp_cpu_to_be_64(regval))) {
1839 "Failed to write to regfile\n");
1844 * The cached entry is being used, so let the tcam processing
1845 * know not to process this table.
1847 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP;
1850 /* Made through the cache processing, increment the reference count. */
1851 cache_entry->ref_count++;
1853 /* Link the cache to the flow db. */
1854 memset(&fid_parms, 0, sizeof(fid_parms));
1855 fid_parms.direction = tbl->direction;
1856 fid_parms.resource_func = tbl->resource_func;
1859 * Cache resource type is composed of table_type, resource
1860 * sub type and direction, it needs to set appropriately via setter.
1862 ulp_mapper_cache_res_type_set(&fid_parms,
1864 (tbl->resource_sub_type << 1 |
1865 (tbl->direction & 0x1)));
1866 fid_parms.resource_hndl = (uint64_t)*ckey;
1867 fid_parms.critical_resource = tbl->critical_resource;
1868 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1873 BNXT_TF_DBG(ERR, "Failed to add cache to flow db.\n");
1878 * This error handling only gets called when the idents are being
1879 * allocated for the cache on misses. Using the num_idents that was
1882 for (i = 0; i < num_idents; i++) {
1883 if (cache_entry->idents[i] == ULP_IDENTS_INVALID)
1886 fparms.dir = tbl->direction;
1887 fparms.ident_type = idents[i].ident_type;
1888 fparms.id = cache_entry->idents[i];
1889 tf_free_identifier(parms->tfp, &fparms);
1896 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1897 struct bnxt_ulp_mapper_tbl_info *tbl)
1899 struct bnxt_ulp_mapper_result_field_info *flds;
1900 struct ulp_blob data;
1903 uint32_t i, num_flds;
1905 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
1906 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1907 uint32_t encap_flds;
1909 /* Initialize the blob data */
1910 if (!ulp_blob_init(&data, tbl->result_bit_size,
1911 parms->device_params->byte_order)) {
1912 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1916 /* Get the result fields list */
1917 flds = ulp_mapper_result_fields_get(tbl, &num_flds, &encap_flds);
1919 if (!flds || !num_flds || encap_flds) {
1920 BNXT_TF_DBG(ERR, "template undefined for the IF table\n");
1924 /* process the result fields, loop through them */
1925 for (i = 0; i < num_flds; i++) {
1926 /* Process the result fields */
1927 rc = ulp_mapper_result_field_process(parms,
1933 BNXT_TF_DBG(ERR, "data field failed\n");
1938 /* Get the index details from computed field */
1939 if (tbl->index_opcode != BNXT_ULP_INDEX_OPCODE_COMP_FIELD) {
1940 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
1943 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->index_operand);
1945 /* Perform the tf table set by filling the set params */
1946 iftbl_params.dir = tbl->direction;
1947 iftbl_params.type = tbl->resource_type;
1948 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
1949 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1950 iftbl_params.idx = idx;
1952 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
1954 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
1956 (iftbl_params.dir == TF_DIR_RX) ? "RX" : "TX",
1963 * TBD: Need to look at the need to store idx in flow db for restore
1964 * the table to its original state on deletion of this entry.
1970 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
1971 struct bnxt_ulp_mapper_data *mapper_data)
1973 struct bnxt_ulp_glb_resource_info *glb_res;
1974 uint32_t num_glb_res_ids, idx;
1977 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
1978 if (!glb_res || !num_glb_res_ids) {
1979 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
1983 /* Iterate the global resources and process each one */
1984 for (idx = 0; idx < num_glb_res_ids; idx++) {
1985 switch (glb_res[idx].resource_func) {
1986 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
1987 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
1991 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
1992 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
1997 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
1998 glb_res[idx].resource_func);
2009 * Function to process the action template. Iterate through the list
2010 * action info templates and process it.
2013 ulp_mapper_action_tbls_process(struct bnxt_ulp_mapper_parms *parms)
2017 struct bnxt_ulp_mapper_tbl_info *tbl;
2019 if (!parms->atbls || !parms->num_atbls) {
2020 BNXT_TF_DBG(ERR, "No action tables for template[%d][%d].\n",
2021 parms->dev_id, parms->act_tid);
2025 for (i = 0; i < parms->num_atbls; i++) {
2026 tbl = &parms->atbls[i];
2027 switch (tbl->resource_func) {
2028 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2029 rc = ulp_mapper_index_tbl_process(parms, tbl, false);
2031 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2032 tbl->resource_func);
2037 BNXT_TF_DBG(ERR, "Unexpected action resource %d\n",
2038 tbl->resource_func);
2046 /* Create the classifier table entries for a flow. */
2048 ulp_mapper_class_tbls_process(struct bnxt_ulp_mapper_parms *parms)
2056 if (!parms->ctbls || !parms->num_ctbls) {
2057 BNXT_TF_DBG(ERR, "No class tables for template[%d][%d].\n",
2058 parms->dev_id, parms->class_tid);
2062 for (i = 0; i < parms->num_ctbls; i++) {
2063 struct bnxt_ulp_mapper_tbl_info *tbl = &parms->ctbls[i];
2065 switch (tbl->resource_func) {
2066 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2067 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
2069 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
2070 rc = ulp_mapper_em_tbl_process(parms, tbl);
2072 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2073 rc = ulp_mapper_index_tbl_process(parms, tbl, true);
2075 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2076 rc = ulp_mapper_cache_tbl_process(parms, tbl);
2078 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
2079 rc = ulp_mapper_if_tbl_process(parms, tbl);
2082 BNXT_TF_DBG(ERR, "Unexpected class resource %d\n",
2083 tbl->resource_func);
2088 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2089 tbl->resource_func);
2098 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
2099 struct ulp_flow_db_res_params *res)
2105 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
2109 tfp = bnxt_ulp_cntxt_tfp_get(ulp);
2111 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
2115 switch (res->resource_func) {
2116 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2117 rc = ulp_mapper_cache_entry_free(ulp, tfp, res);
2119 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2120 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
2122 case BNXT_ULP_RESOURCE_FUNC_EM_TABLE:
2123 rc = ulp_mapper_eem_entry_free(ulp, tfp, res);
2125 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2126 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
2128 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2129 rc = ulp_mapper_ident_free(ulp, tfp, res);
2131 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
2132 rc = ulp_mapper_mark_free(ulp, res);
2142 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
2144 enum bnxt_ulp_flow_db_tables tbl_type)
2146 struct ulp_flow_db_res_params res_parms = { 0 };
2150 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2155 * Set the critical resource on the first resource del, then iterate
2156 * while status is good
2158 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
2159 rc = ulp_flow_db_resource_del(ulp_ctx, tbl_type, fid, &res_parms);
2163 * This is unexpected on the first call to resource del.
2164 * It likely means that the flow did not exist in the flow db.
2166 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
2172 trc = ulp_mapper_resource_free(ulp_ctx, &res_parms);
2175 * On fail, we still need to attempt to free the
2176 * remaining resources. Don't return
2179 "Flow[%d][0x%x] Res[%d][0x%016" PRIx64
2180 "] failed rc=%d.\n",
2181 tbl_type, fid, res_parms.resource_func,
2182 res_parms.resource_hndl, trc);
2184 /* All subsequent call require the non-critical_resource */
2185 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
2187 rc = ulp_flow_db_resource_del(ulp_ctx,
2193 /* Free the Flow ID since we've removed all resources */
2194 rc = ulp_flow_db_fid_free(ulp_ctx, tbl_type, fid);
2200 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
2201 struct bnxt_ulp_mapper_data *mapper_data)
2203 struct bnxt_ulp_mapper_glb_resource_entry *ent;
2204 struct ulp_flow_db_res_params res;
2207 /* Iterate the global resources and process each one */
2208 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
2209 for (idx = 0; idx < BNXT_ULP_GLB_RESOURCE_INFO_TBL_MAX_SZ;
2211 ent = &mapper_data->glb_res_tbl[dir][idx];
2212 if (ent->resource_func ==
2213 BNXT_ULP_RESOURCE_FUNC_INVALID)
2215 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
2216 res.resource_func = ent->resource_func;
2217 res.direction = dir;
2218 res.resource_type = ent->resource_type;
2219 /*convert it from BE to cpu */
2221 tfp_be_to_cpu_64(ent->resource_hndl);
2222 ulp_mapper_resource_free(ulp_ctx, &res);
2228 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, uint32_t fid)
2231 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2235 return ulp_mapper_resources_free(ulp_ctx,
2237 BNXT_ULP_REGULAR_FLOW_TABLE);
2240 /* Function to handle the default global templates that are allocated during
2241 * the startup and reused later.
2244 ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx)
2246 uint32_t *glbl_tmpl_list;
2247 uint32_t num_glb_tmpls, idx, dev_id;
2248 struct bnxt_ulp_mapper_parms parms;
2249 struct bnxt_ulp_mapper_data *mapper_data;
2252 glbl_tmpl_list = ulp_mapper_glb_template_table_get(&num_glb_tmpls);
2253 if (!glbl_tmpl_list || !num_glb_tmpls)
2254 return rc; /* No global templates to process */
2256 /* Get the device id from the ulp context */
2257 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
2258 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2262 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2264 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2268 /* Iterate the global resources and process each one */
2269 for (idx = 0; idx < num_glb_tmpls; idx++) {
2270 /* Initialize the parms structure */
2271 memset(&parms, 0, sizeof(parms));
2272 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2273 parms.ulp_ctx = ulp_ctx;
2274 parms.dev_id = dev_id;
2275 parms.mapper_data = mapper_data;
2277 /* Get the class table entry from dev id and class id */
2278 parms.class_tid = glbl_tmpl_list[idx];
2279 parms.ctbls = ulp_mapper_class_tbl_list_get(parms.dev_id,
2283 if (!parms.ctbls || !parms.num_ctbls) {
2284 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2285 parms.dev_id, parms.class_tid);
2288 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2289 if (!parms.device_params) {
2290 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2291 parms.dev_id, parms.class_tid);
2294 rc = ulp_mapper_class_tbls_process(&parms);
2297 "class tables failed creation for %d:%d\n",
2298 parms.dev_id, parms.class_tid);
2305 /* Function to handle the mapping of the Flow to be compatible
2306 * with the underlying hardware.
2309 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
2310 struct bnxt_ulp_mapper_create_parms *cparms,
2313 struct bnxt_ulp_mapper_parms parms;
2314 struct ulp_regfile regfile;
2317 if (!ulp_ctx || !cparms)
2320 /* Initialize the parms structure */
2321 memset(&parms, 0, sizeof(parms));
2322 parms.act_prop = cparms->act_prop;
2323 parms.act_bitmap = cparms->act;
2324 parms.regfile = ®file;
2325 parms.hdr_field = cparms->hdr_field;
2326 parms.comp_fld = cparms->comp_fld;
2327 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2328 parms.ulp_ctx = ulp_ctx;
2329 parms.tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
2331 /* Get the device id from the ulp context */
2332 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
2333 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2338 * Get the mapper data for dynamic mapper data such as default
2341 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
2342 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2343 if (!parms.mapper_data) {
2344 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2348 /* Get the action table entry from device id and act context id */
2349 parms.act_tid = cparms->act_tid;
2352 * Perform the action table get only if act template is not zero
2353 * for act template zero like for default rules ignore the action
2356 if (parms.act_tid) {
2357 parms.atbls = ulp_mapper_action_tbl_list_get(parms.dev_id,
2360 if (!parms.atbls || !parms.num_atbls) {
2361 BNXT_TF_DBG(ERR, "No action tables for %d:%d\n",
2362 parms.dev_id, parms.act_tid);
2367 /* Get the class table entry from device id and act context id */
2368 parms.class_tid = cparms->class_tid;
2369 parms.ctbls = ulp_mapper_class_tbl_list_get(parms.dev_id,
2373 if (!parms.ctbls || !parms.num_ctbls) {
2374 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2375 parms.dev_id, parms.class_tid);
2379 /* Get the device params, it will be used in later processing */
2380 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2381 if (!parms.device_params) {
2382 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2383 parms.dev_id, parms.class_tid);
2387 /* initialize the registry file for further processing */
2388 if (!ulp_regfile_init(parms.regfile)) {
2389 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
2393 rc = ulp_regfile_write(parms.regfile,
2394 BNXT_ULP_REGFILE_INDEX_CLASS_TID,
2395 tfp_cpu_to_be_64((uint64_t)parms.class_tid));
2397 BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
2401 /* Allocate a Flow ID for attaching all resources for the flow to.
2402 * Once allocated, all errors have to walk the list of resources and
2403 * free each of them.
2405 rc = ulp_flow_db_fid_alloc(ulp_ctx,
2410 BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n");
2414 /* Process the action template list from the selected action table*/
2415 if (parms.act_tid) {
2416 rc = ulp_mapper_action_tbls_process(&parms);
2419 "action tables failed creation for %d:%d\n",
2420 parms.dev_id, parms.act_tid);
2425 /* All good. Now process the class template */
2426 rc = ulp_mapper_class_tbls_process(&parms);
2428 BNXT_TF_DBG(ERR, "class tables failed creation for %d:%d\n",
2429 parms.dev_id, parms.class_tid);
2433 *flowid = parms.fid;
2438 /* Free all resources that were allocated during flow creation */
2439 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.fid);
2441 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
2447 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
2449 struct bnxt_ulp_cache_tbl_params *tbl;
2450 struct bnxt_ulp_mapper_data *data;
2458 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2462 data = rte_zmalloc("ulp_mapper_data",
2463 sizeof(struct bnxt_ulp_mapper_data), 0);
2465 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
2469 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
2470 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
2471 /* Don't call deinit since the prof_func wasn't allocated. */
2476 /* Allocate the global resource ids */
2477 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
2479 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
2483 /* Allocate the ulp cache tables. */
2484 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
2485 tbl = ulp_mapper_cache_tbl_params_get(i);
2487 BNXT_TF_DBG(ERR, "Failed to get cache table parms (%d)",
2491 if (tbl->num_entries != 0) {
2492 csize = sizeof(struct bnxt_ulp_mapper_cache_entry) *
2494 data->cache_tbl[i] = rte_zmalloc("ulp mapper cache tbl",
2496 if (!data->cache_tbl[i]) {
2497 BNXT_TF_DBG(ERR, "Failed to allocate Cache "
2505 rc = ulp_mapper_glb_template_table_init(ulp_ctx);
2507 BNXT_TF_DBG(ERR, "Failed to initialize global templates\n");
2513 /* Ignore the return code in favor of returning the original error. */
2514 ulp_mapper_deinit(ulp_ctx);
2519 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
2521 struct bnxt_ulp_mapper_data *data;
2527 "Failed to acquire ulp context, so data may "
2528 "not be released.\n");
2532 data = (struct bnxt_ulp_mapper_data *)
2533 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2535 /* Go ahead and return since there is no allocated data. */
2536 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
2540 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2542 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
2543 /* Free the mapper data regardless of errors. */
2544 goto free_mapper_data;
2547 /* Free the global resource info table entries */
2548 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
2551 /* Free the ulp cache tables */
2552 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
2553 rte_free(data->cache_tbl[i]);
2554 data->cache_tbl[i] = NULL;
2558 /* Reset the data pointer within the ulp_ctx. */
2559 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);