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_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);
126 * Internal function to allocate index tbl resource and store it in mapper data.
128 * returns 0 on success
131 ulp_mapper_resource_index_tbl_alloc(struct bnxt_ulp_context *ulp_ctx,
132 struct bnxt_ulp_mapper_data *mapper_data,
133 struct bnxt_ulp_glb_resource_info *glb_res)
135 struct tf_alloc_tbl_entry_parms aparms = { 0 };
136 struct tf_free_tbl_entry_parms free_parms = { 0 };
139 uint32_t tbl_scope_id;
142 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
146 /* Get the scope id */
147 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp_ctx, &tbl_scope_id);
149 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
153 aparms.type = glb_res->resource_type;
154 aparms.dir = glb_res->direction;
155 aparms.search_enable = BNXT_ULP_SEARCH_BEFORE_ALLOC_NO;
156 aparms.tbl_scope_id = tbl_scope_id;
158 /* Allocate the index tbl using tf api */
159 rc = tf_alloc_tbl_entry(tfp, &aparms);
161 BNXT_TF_DBG(ERR, "Failed to alloc identifier [%s][%d]\n",
162 (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
167 /* entries are stored as big-endian format */
168 regval = tfp_cpu_to_be_64((uint64_t)aparms.idx);
169 /* write to the mapper global resource */
170 rc = ulp_mapper_glb_resource_write(mapper_data, glb_res, regval);
172 BNXT_TF_DBG(ERR, "Failed to write to global resource id\n");
173 /* Free the identifier when update failed */
174 free_parms.dir = aparms.dir;
175 free_parms.type = aparms.type;
176 free_parms.idx = aparms.idx;
177 tf_free_tbl_entry(tfp, &free_parms);
183 /* Retrieve the cache initialization parameters for the tbl_idx */
184 static struct bnxt_ulp_cache_tbl_params *
185 ulp_mapper_cache_tbl_params_get(uint32_t tbl_idx)
187 if (tbl_idx >= BNXT_ULP_CACHE_TBL_MAX_SZ)
190 return &ulp_cache_tbl_params[tbl_idx];
193 /* Retrieve the global template table */
195 ulp_mapper_glb_template_table_get(uint32_t *num_entries)
199 *num_entries = BNXT_ULP_GLB_TEMPLATE_TBL_MAX_SZ;
200 return ulp_glb_template_tbl;
204 * Get the size of the action property for a given index.
206 * idx [in] The index for the action property
208 * returns the size of the action property.
211 ulp_mapper_act_prop_size_get(uint32_t idx)
213 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST)
215 return ulp_act_prop_map_table[idx];
219 * Get the list of result fields that implement the flow action.
220 * Gets a device dependent list of tables that implement the action template id.
222 * dev_id [in] The device id of the forwarding element
224 * tid [in] The action template id that matches the flow
226 * num_tbls [out] The number of action tables in the returned array
228 * Returns An array of action tables to implement the flow, or NULL on error.
230 static struct bnxt_ulp_mapper_tbl_info *
231 ulp_mapper_action_tbl_list_get(uint32_t dev_id,
239 BNXT_TF_DBG(ERR, "Invalid arguments\n");
243 /* template shift and device mask */
244 tidx = ULP_DEVICE_PARAMS_INDEX(tid, dev_id);
246 /* NOTE: Need to have something from template compiler to help validate
247 * range of dev_id and act_tid
249 idx = ulp_act_tmpl_list[tidx].start_tbl_idx;
250 *num_tbls = ulp_act_tmpl_list[tidx].num_tbls;
252 return &ulp_act_tbl_list[idx];
256 * Get a list of classifier tables that implement the flow
257 * Gets a device dependent list of tables that implement the class template id
259 * dev_id [in] The device id of the forwarding element
261 * tid [in] The template id that matches the flow
263 * num_tbls [out] The number of classifier tables in the returned array
265 * fdb_tbl_idx [out] The flow database index Regular or default
267 * returns An array of classifier tables to implement the flow, or NULL on
270 static struct bnxt_ulp_mapper_tbl_info *
271 ulp_mapper_class_tbl_list_get(uint32_t dev_id,
274 uint32_t *fdb_tbl_idx)
277 uint32_t tidx = ULP_DEVICE_PARAMS_INDEX(tid, dev_id);
282 /* NOTE: Need to have something from template compiler to help validate
283 * range of dev_id and tid
285 idx = ulp_class_tmpl_list[tidx].start_tbl_idx;
286 *num_tbls = ulp_class_tmpl_list[tidx].num_tbls;
287 *fdb_tbl_idx = ulp_class_tmpl_list[tidx].flow_db_table_type;
288 return &ulp_class_tbl_list[idx];
292 * Get the list of key fields that implement the flow.
294 * ctxt [in] The ulp context
296 * tbl [in] A single table instance to get the key fields from
298 * num_flds [out] The number of key fields in the returned array
300 * Returns array of Key fields, or NULL on error.
302 static struct bnxt_ulp_mapper_class_key_field_info *
303 ulp_mapper_key_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
308 if (!tbl || !num_flds)
311 idx = tbl->key_start_idx;
312 *num_flds = tbl->key_num_fields;
314 /* NOTE: Need template to provide range checking define */
315 return &ulp_class_key_field_list[idx];
319 * Get the list of data fields that implement the flow.
321 * ctxt [in] The ulp context
323 * tbl [in] A single table instance to get the data fields from
325 * num_flds [out] The number of data fields in the returned array.
327 * Returns array of data fields, or NULL on error.
329 static struct bnxt_ulp_mapper_result_field_info *
330 ulp_mapper_result_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
332 uint32_t *num_encap_flds)
336 if (!tbl || !num_flds)
339 idx = tbl->result_start_idx;
340 *num_flds = tbl->result_num_fields;
341 *num_encap_flds = tbl->encap_num_fields;
343 /* NOTE: Need template to provide range checking define */
344 return &ulp_class_result_field_list[idx];
348 * Get the list of result fields that implement the flow action.
350 * tbl [in] A single table instance to get the results fields
351 * from num_flds [out] The number of data fields in the returned
354 * Returns array of data fields, or NULL on error.
356 static struct bnxt_ulp_mapper_result_field_info *
357 ulp_mapper_act_result_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
358 uint32_t *num_rslt_flds,
359 uint32_t *num_encap_flds)
363 if (!tbl || !num_rslt_flds || !num_encap_flds)
366 idx = tbl->result_start_idx;
367 *num_rslt_flds = tbl->result_num_fields;
368 *num_encap_flds = tbl->encap_num_fields;
370 /* NOTE: Need template to provide range checking define */
371 return &ulp_act_result_field_list[idx];
375 * Get the list of ident fields that implement the flow
377 * tbl [in] A single table instance to get the ident fields from
379 * num_flds [out] The number of ident fields in the returned array
381 * returns array of ident fields, or NULL on error
383 static struct bnxt_ulp_mapper_ident_info *
384 ulp_mapper_ident_fields_get(struct bnxt_ulp_mapper_tbl_info *tbl,
389 if (!tbl || !num_flds)
392 idx = tbl->ident_start_idx;
393 *num_flds = tbl->ident_nums;
395 /* NOTE: Need template to provide range checking define */
396 return &ulp_ident_list[idx];
399 static struct bnxt_ulp_mapper_cache_entry *
400 ulp_mapper_cache_entry_get(struct bnxt_ulp_context *ulp,
404 struct bnxt_ulp_mapper_data *mapper_data;
406 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp);
407 if (!mapper_data || id >= BNXT_ULP_CACHE_TBL_MAX_SZ ||
408 !mapper_data->cache_tbl[id]) {
409 BNXT_TF_DBG(ERR, "Unable to acquire the cache tbl (%d)\n", id);
413 return &mapper_data->cache_tbl[id][key];
417 * Concatenates the tbl_type and tbl_id into a 32bit value for storing in the
418 * resource_type. This is done to conserve memory since both the tbl_type and
422 ulp_mapper_cache_res_type_set(struct ulp_flow_db_res_params *res,
426 res->resource_type = tbl_type;
427 res->resource_sub_type = tbl_id;
430 /* Extracts the tbl_type and tbl_id from the 32bit resource type. */
432 ulp_mapper_cache_res_type_get(struct ulp_flow_db_res_params *res,
436 *tbl_type = res->resource_type;
437 *tbl_id = res->resource_sub_type;
441 ulp_mapper_cache_entry_free(struct bnxt_ulp_context *ulp,
443 struct ulp_flow_db_res_params *res)
445 struct bnxt_ulp_mapper_cache_entry *cache_entry;
446 struct tf_free_identifier_parms ident_parms;
447 struct tf_free_tcam_entry_parms tcam_parms;
448 uint16_t table_id, table_type;
452 * The table id, used for cache, and table_type, used for tcam, are
453 * both encoded within the resource. We must first extract them to
454 * formulate the args for tf calls.
456 ulp_mapper_cache_res_type_get(res, &table_type, &table_id);
457 cache_entry = ulp_mapper_cache_entry_get(ulp, table_id,
458 (uint16_t)res->resource_hndl);
459 if (!cache_entry || !cache_entry->ref_count) {
460 BNXT_TF_DBG(ERR, "Cache entry (%d:%d) not valid on free.\n",
461 table_id, (uint16_t)res->resource_hndl);
466 * See if we need to delete the entry. The tcam and identifiers are all
467 * tracked by the cached entries reference count. All are deleted when
468 * the reference count hit zero.
470 cache_entry->ref_count--;
471 if (cache_entry->ref_count)
475 * Need to delete the tcam entry and the allocated identifiers.
476 * In the event of a failure, need to try to delete the remaining
477 * resources before returning error.
479 tcam_parms.dir = res->direction;
480 tcam_parms.tcam_tbl_type = table_type;
481 tcam_parms.idx = cache_entry->tcam_idx;
482 rc = tf_free_tcam_entry(tfp, &tcam_parms);
484 BNXT_TF_DBG(ERR, "Failed to free tcam [%d][%s][0x%04x] rc=%d\n",
486 (res->direction == TF_DIR_RX) ? "RX" : "TX",
490 * Free the identifiers associated with the tcam entry. Entries with
491 * negative one are considered uninitialized.
493 for (i = 0; i < BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM; i++) {
494 if (cache_entry->idents[i] == ULP_IDENTS_INVALID)
497 ident_parms.dir = res->direction;
498 ident_parms.ident_type = cache_entry->ident_types[i];
499 ident_parms.id = cache_entry->idents[i];
500 trc = tf_free_identifier(tfp, &ident_parms);
502 BNXT_TF_DBG(ERR, "Failed to free identifier "
503 "[%d][%s][0x%04x] rc=%d\n",
504 ident_parms.ident_type,
505 (res->direction == TF_DIR_RX) ? "RX" : "TX",
506 ident_parms.id, trc);
514 static inline int32_t
515 ulp_mapper_tcam_entry_free(struct bnxt_ulp_context *ulp __rte_unused,
517 struct ulp_flow_db_res_params *res)
519 struct tf_free_tcam_entry_parms fparms = {
520 .dir = res->direction,
521 .tcam_tbl_type = res->resource_type,
522 .idx = (uint16_t)res->resource_hndl
525 return tf_free_tcam_entry(tfp, &fparms);
528 static inline int32_t
529 ulp_mapper_index_entry_free(struct bnxt_ulp_context *ulp,
531 struct ulp_flow_db_res_params *res)
533 struct tf_free_tbl_entry_parms fparms = {
534 .dir = res->direction,
535 .type = res->resource_type,
536 .idx = (uint32_t)res->resource_hndl
540 * Just set the table scope, it will be ignored if not necessary
541 * by the tf_free_tbl_entry
543 bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
545 return tf_free_tbl_entry(tfp, &fparms);
548 static inline int32_t
549 ulp_mapper_em_entry_free(struct bnxt_ulp_context *ulp,
551 struct ulp_flow_db_res_params *res)
553 struct tf_delete_em_entry_parms fparms = { 0 };
556 fparms.dir = res->direction;
557 if (res->resource_func == BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE)
558 fparms.mem = TF_MEM_EXTERNAL;
560 fparms.mem = TF_MEM_INTERNAL;
561 fparms.flow_handle = res->resource_hndl;
563 rc = bnxt_ulp_cntxt_tbl_scope_id_get(ulp, &fparms.tbl_scope_id);
565 BNXT_TF_DBG(ERR, "Failed to get table scope\n");
569 return tf_delete_em_entry(tfp, &fparms);
572 static inline int32_t
573 ulp_mapper_ident_free(struct bnxt_ulp_context *ulp __rte_unused,
575 struct ulp_flow_db_res_params *res)
577 struct tf_free_identifier_parms fparms = {
578 .dir = res->direction,
579 .ident_type = res->resource_type,
580 .id = (uint16_t)res->resource_hndl
583 return tf_free_identifier(tfp, &fparms);
586 static inline int32_t
587 ulp_mapper_mark_free(struct bnxt_ulp_context *ulp,
588 struct ulp_flow_db_res_params *res)
590 return ulp_mark_db_mark_del(ulp,
596 * Process the identifier instruction and either store it in the flow database
597 * or return it in the val (if not NULL) on success. If val is NULL, the
598 * identifier is to be stored in the flow database.
601 ulp_mapper_ident_process(struct bnxt_ulp_mapper_parms *parms,
602 struct bnxt_ulp_mapper_tbl_info *tbl,
603 struct bnxt_ulp_mapper_ident_info *ident,
606 struct ulp_flow_db_res_params fid_parms;
609 struct tf_alloc_identifier_parms iparms = { 0 };
610 struct tf_free_identifier_parms free_parms = { 0 };
614 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
616 BNXT_TF_DBG(ERR, "Failed to get tf pointer\n");
620 idx = ident->regfile_idx;
622 iparms.ident_type = ident->ident_type;
623 iparms.dir = tbl->direction;
625 rc = tf_alloc_identifier(tfp, &iparms);
627 BNXT_TF_DBG(ERR, "Alloc ident %s:%d failed.\n",
628 (iparms.dir == TF_DIR_RX) ? "RX" : "TX",
633 id = (uint64_t)tfp_cpu_to_be_64(iparms.id);
634 if (!ulp_regfile_write(parms->regfile, idx, id)) {
635 BNXT_TF_DBG(ERR, "Regfile[%d] write failed.\n", idx);
637 /* Need to free the identifier, so goto error */
641 /* Link the resource to the flow in the flow db */
643 memset(&fid_parms, 0, sizeof(fid_parms));
644 fid_parms.direction = tbl->direction;
645 fid_parms.resource_func = ident->resource_func;
646 fid_parms.resource_type = ident->ident_type;
647 fid_parms.resource_hndl = iparms.id;
648 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
650 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
655 BNXT_TF_DBG(ERR, "Failed to link res to flow rc = %d\n",
657 /* Need to free the identifier, so goto error */
667 /* Need to free the identifier */
668 free_parms.dir = tbl->direction;
669 free_parms.ident_type = ident->ident_type;
670 free_parms.id = iparms.id;
672 (void)tf_free_identifier(tfp, &free_parms);
674 BNXT_TF_DBG(ERR, "Ident process failed for %s:%s\n",
676 (tbl->direction == TF_DIR_RX) ? "RX" : "TX");
681 ulp_mapper_result_field_process(struct bnxt_ulp_mapper_parms *parms,
683 struct bnxt_ulp_mapper_result_field_info *fld,
684 struct ulp_blob *blob,
687 uint16_t idx, size_idx;
690 uint32_t val_size = 0, field_size = 0;
694 switch (fld->result_opcode) {
695 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
696 val = fld->result_operand;
697 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
698 BNXT_TF_DBG(ERR, "%s failed to add field\n", name);
702 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_PROP:
703 if (!ulp_operand_read(fld->result_operand,
704 (uint8_t *)&idx, sizeof(uint16_t))) {
705 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
708 idx = tfp_be_to_cpu_16(idx);
710 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
711 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
714 val = &parms->act_prop->act_details[idx];
715 field_size = ulp_mapper_act_prop_size_get(idx);
716 if (fld->field_bit_size < ULP_BYTE_2_BITS(field_size)) {
717 field_size = field_size -
718 ((fld->field_bit_size + 7) / 8);
721 if (!ulp_blob_push(blob, val, fld->field_bit_size)) {
722 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
726 case BNXT_ULP_MAPPER_OPC_SET_TO_ACT_BIT:
727 if (!ulp_operand_read(fld->result_operand,
728 (uint8_t *)&act_bit, sizeof(uint64_t))) {
729 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
732 act_bit = tfp_be_to_cpu_64(act_bit);
733 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits, act_bit))
737 if (fld->field_bit_size > ULP_BYTE_2_BITS(sizeof(act_val))) {
738 BNXT_TF_DBG(ERR, "%s field size is incorrect\n", name);
741 if (!ulp_blob_push(blob, &act_val, fld->field_bit_size)) {
742 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
747 case BNXT_ULP_MAPPER_OPC_SET_TO_ENCAP_ACT_PROP_SZ:
748 if (!ulp_operand_read(fld->result_operand,
749 (uint8_t *)&idx, sizeof(uint16_t))) {
750 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
753 idx = tfp_be_to_cpu_16(idx);
755 if (idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
756 BNXT_TF_DBG(ERR, "%s act_prop[%d] oob\n", name, idx);
759 val = &parms->act_prop->act_details[idx];
761 /* get the size index next */
762 if (!ulp_operand_read(&fld->result_operand[sizeof(uint16_t)],
763 (uint8_t *)&size_idx, sizeof(uint16_t))) {
764 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
767 size_idx = tfp_be_to_cpu_16(size_idx);
769 if (size_idx >= BNXT_ULP_ACT_PROP_IDX_LAST) {
770 BNXT_TF_DBG(ERR, "act_prop[%d] oob\n", size_idx);
773 memcpy(&val_size, &parms->act_prop->act_details[size_idx],
775 val_size = tfp_be_to_cpu_32(val_size);
776 val_size = ULP_BYTE_2_BITS(val_size);
777 ulp_blob_push_encap(blob, val, val_size);
779 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
780 if (!ulp_operand_read(fld->result_operand,
781 (uint8_t *)&idx, sizeof(uint16_t))) {
782 BNXT_TF_DBG(ERR, "%s operand read failed\n", name);
786 idx = tfp_be_to_cpu_16(idx);
787 /* Uninitialized regfile entries return 0 */
788 if (!ulp_regfile_read(parms->regfile, idx, ®val)) {
789 BNXT_TF_DBG(ERR, "%s regfile[%d] read oob\n",
794 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
796 BNXT_TF_DBG(ERR, "%s push field failed\n", name);
800 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
801 if (!ulp_operand_read(fld->result_operand,
804 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
807 idx = tfp_be_to_cpu_16(idx);
808 if (ulp_mapper_glb_resource_read(parms->mapper_data,
811 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
815 val = ulp_blob_push_64(blob, ®val, fld->field_bit_size);
817 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
821 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
822 if (!ulp_operand_read(fld->result_operand,
825 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
828 idx = tfp_be_to_cpu_16(idx);
829 if (idx < BNXT_ULP_CF_IDX_LAST)
830 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
831 fld->field_bit_size);
833 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
837 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
838 if (ulp_blob_pad_push(blob, fld->field_bit_size) < 0) {
839 BNXT_TF_DBG(ERR, "%s too large for blob\n", name);
850 /* Function to alloc action record and set the table. */
852 ulp_mapper_keymask_field_process(struct bnxt_ulp_mapper_parms *parms,
854 struct bnxt_ulp_mapper_class_key_field_info *f,
855 struct ulp_blob *blob,
860 uint16_t idx, bitlen;
863 struct ulp_regfile *regfile = parms->regfile;
865 struct bnxt_ulp_mapper_class_key_field_info *fld = f;
869 operand = fld->spec_operand;
870 opcode = fld->spec_opcode;
872 operand = fld->mask_operand;
873 opcode = fld->mask_opcode;
876 bitlen = fld->field_bit_size;
879 case BNXT_ULP_MAPPER_OPC_SET_TO_CONSTANT:
881 if (!ulp_blob_push(blob, val, bitlen)) {
882 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
886 case BNXT_ULP_MAPPER_OPC_SET_TO_ZERO:
887 if (ulp_blob_pad_push(blob, bitlen) < 0) {
888 BNXT_TF_DBG(ERR, "%s pad too large for blob\n", name);
893 case BNXT_ULP_MAPPER_OPC_SET_TO_HDR_FIELD:
894 if (!ulp_operand_read(operand, (uint8_t *)&idx,
896 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
899 idx = tfp_be_to_cpu_16(idx);
901 val = parms->hdr_field[idx].spec;
903 val = parms->hdr_field[idx].mask;
906 * Need to account for how much data was pushed to the header
907 * field vs how much is to be inserted in the key/mask.
909 field_size = parms->hdr_field[idx].size;
910 if (bitlen < ULP_BYTE_2_BITS(field_size)) {
911 field_size = field_size - ((bitlen + 7) / 8);
915 if (!ulp_blob_push(blob, val, bitlen)) {
916 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
920 case BNXT_ULP_MAPPER_OPC_SET_TO_COMP_FIELD:
921 if (!ulp_operand_read(operand, (uint8_t *)&idx,
923 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
926 idx = tfp_be_to_cpu_16(idx);
927 if (idx < BNXT_ULP_CF_IDX_LAST)
928 val = ulp_blob_push_32(blob, &parms->comp_fld[idx],
931 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
935 case BNXT_ULP_MAPPER_OPC_SET_TO_REGFILE:
936 if (!ulp_operand_read(operand, (uint8_t *)&idx,
938 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
941 idx = tfp_be_to_cpu_16(idx);
943 if (!ulp_regfile_read(regfile, idx, &val64)) {
944 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
949 val = ulp_blob_push_64(blob, &val64, bitlen);
951 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
955 case BNXT_ULP_MAPPER_OPC_SET_TO_GLB_REGFILE:
956 if (!ulp_operand_read(operand, (uint8_t *)&idx,
958 BNXT_TF_DBG(ERR, "%s key operand read failed.\n", name);
961 idx = tfp_be_to_cpu_16(idx);
962 if (ulp_mapper_glb_resource_read(parms->mapper_data,
965 BNXT_TF_DBG(ERR, "%s regfile[%d] read failed.\n",
969 val = ulp_blob_push_64(blob, &val64, bitlen);
971 BNXT_TF_DBG(ERR, "%s push to key blob failed\n", name);
983 ulp_mapper_mark_gfid_process(struct bnxt_ulp_mapper_parms *parms,
984 struct bnxt_ulp_mapper_tbl_info *tbl,
987 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
988 struct ulp_flow_db_res_params fid_parms;
989 uint32_t mark, gfid, mark_flag;
992 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
993 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
994 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
995 BNXT_ULP_ACTION_BIT_MARK)))
996 return rc; /* no need to perform gfid process */
998 /* Get the mark id details from action property */
999 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1001 mark = tfp_be_to_cpu_32(mark);
1003 TF_GET_GFID_FROM_FLOW_ID(flow_id, gfid);
1004 mark_flag = BNXT_ULP_MARK_GLOBAL_HW_FID;
1005 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1008 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1011 fid_parms.direction = tbl->direction;
1012 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1013 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1014 fid_parms.resource_type = mark_flag;
1015 fid_parms.resource_hndl = gfid;
1016 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1021 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1026 ulp_mapper_mark_act_ptr_process(struct bnxt_ulp_mapper_parms *parms,
1027 struct bnxt_ulp_mapper_tbl_info *tbl)
1029 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1030 struct ulp_flow_db_res_params fid_parms;
1031 uint32_t act_idx, mark, mark_flag;
1035 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1036 !(mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION &&
1037 ULP_BITMAP_ISSET(parms->act_bitmap->bits,
1038 BNXT_ULP_ACTION_BIT_MARK)))
1039 return rc; /* no need to perform mark action process */
1041 /* Get the mark id details from action property */
1042 memcpy(&mark, &parms->act_prop->act_details[BNXT_ULP_ACT_PROP_IDX_MARK],
1044 mark = tfp_be_to_cpu_32(mark);
1046 if (!ulp_regfile_read(parms->regfile,
1047 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1049 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1052 act_idx = tfp_be_to_cpu_64(val64);
1053 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID;
1054 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1057 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1060 fid_parms.direction = tbl->direction;
1061 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1062 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1063 fid_parms.resource_type = mark_flag;
1064 fid_parms.resource_hndl = act_idx;
1065 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1070 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1075 ulp_mapper_mark_vfr_idx_process(struct bnxt_ulp_mapper_parms *parms,
1076 struct bnxt_ulp_mapper_tbl_info *tbl)
1078 struct ulp_flow_db_res_params fid_parms;
1079 uint32_t act_idx, mark, mark_flag;
1081 enum bnxt_ulp_mark_db_opcode mark_op = tbl->mark_db_opcode;
1084 if (mark_op == BNXT_ULP_MARK_DB_OPCODE_NOP ||
1085 mark_op == BNXT_ULP_MARK_DB_OPCODE_SET_IF_MARK_ACTION)
1086 return rc; /* no need to perform mark action process */
1088 /* Get the mark id details from the computed field of dev port id */
1089 mark = ULP_COMP_FLD_IDX_RD(parms, BNXT_ULP_CF_IDX_DEV_PORT_ID);
1091 /* Get the main action pointer */
1092 if (!ulp_regfile_read(parms->regfile,
1093 BNXT_ULP_REGFILE_INDEX_MAIN_ACTION_PTR,
1095 BNXT_TF_DBG(ERR, "read action ptr main failed\n");
1098 act_idx = tfp_be_to_cpu_64(val64);
1100 /* Set the mark flag to local fid and vfr flag */
1101 mark_flag = BNXT_ULP_MARK_LOCAL_HW_FID | BNXT_ULP_MARK_VFR_ID;
1103 rc = ulp_mark_db_mark_add(parms->ulp_ctx, mark_flag,
1106 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1109 fid_parms.direction = tbl->direction;
1110 fid_parms.resource_func = BNXT_ULP_RESOURCE_FUNC_HW_FID;
1111 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1112 fid_parms.resource_type = mark_flag;
1113 fid_parms.resource_hndl = act_idx;
1114 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1119 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n", rc);
1124 ulp_mapper_tcam_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1125 struct bnxt_ulp_mapper_tbl_info *tbl)
1127 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1128 struct ulp_blob key, mask, data;
1129 uint32_t i, num_kflds;
1132 struct tf_alloc_tcam_entry_parms aparms = { 0 };
1133 struct tf_set_tcam_entry_parms sparms = { 0 };
1134 struct ulp_flow_db_res_params fid_parms = { 0 };
1135 struct tf_free_tcam_entry_parms free_parms = { 0 };
1137 uint16_t tmplen = 0;
1139 /* Skip this if was handled by the cache. */
1140 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP) {
1141 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1145 tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1147 BNXT_TF_DBG(ERR, "Failed to get truflow pointer\n");
1151 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1152 if (!kflds || !num_kflds) {
1153 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1157 if (!ulp_blob_init(&key, tbl->key_bit_size,
1158 parms->device_params->byte_order) ||
1159 !ulp_blob_init(&mask, tbl->key_bit_size,
1160 parms->device_params->byte_order) ||
1161 !ulp_blob_init(&data, tbl->result_bit_size,
1162 parms->device_params->byte_order)) {
1163 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1167 /* create the key/mask */
1169 * NOTE: The WC table will require some kind of flag to handle the
1170 * mode bits within the key/mask
1172 for (i = 0; i < num_kflds; i++) {
1174 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1176 &key, 1, "TCAM Key");
1178 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1182 /* Setup the mask */
1183 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1185 &mask, 0, "TCAM Mask");
1187 BNXT_TF_DBG(ERR, "Mask field set failed.\n");
1192 aparms.dir = tbl->direction;
1193 aparms.tcam_tbl_type = tbl->resource_type;
1194 aparms.search_enable = tbl->srch_b4_alloc;
1195 aparms.key_sz_in_bits = tbl->key_bit_size;
1196 aparms.key = ulp_blob_data_get(&key, &tmplen);
1197 if (tbl->key_bit_size != tmplen) {
1198 BNXT_TF_DBG(ERR, "Key len (%d) != Expected (%d)\n",
1199 tmplen, tbl->key_bit_size);
1203 aparms.mask = ulp_blob_data_get(&mask, &tmplen);
1204 if (tbl->key_bit_size != tmplen) {
1205 BNXT_TF_DBG(ERR, "Mask len (%d) != Expected (%d)\n",
1206 tmplen, tbl->key_bit_size);
1210 aparms.priority = tbl->priority;
1213 * All failures after this succeeds require the entry to be freed.
1214 * cannot return directly on failure, but needs to goto error
1216 rc = tf_alloc_tcam_entry(tfp, &aparms);
1218 BNXT_TF_DBG(ERR, "tcam alloc failed rc=%d.\n", rc);
1224 /* Build the result */
1225 if (!tbl->srch_b4_alloc || !hit) {
1226 struct bnxt_ulp_mapper_result_field_info *dflds;
1227 struct bnxt_ulp_mapper_ident_info *idents;
1228 uint32_t num_dflds, num_idents;
1229 uint32_t encap_flds = 0;
1232 * Since the cache entry is responsible for allocating
1233 * identifiers when in use, allocate the identifiers only
1234 * during normal processing.
1236 if (parms->tcam_tbl_opc ==
1237 BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1238 idents = ulp_mapper_ident_fields_get(tbl, &num_idents);
1240 for (i = 0; i < num_idents; i++) {
1241 rc = ulp_mapper_ident_process(parms, tbl,
1243 /* Already logged the error, just return */
1249 /* Create the result data blob */
1250 dflds = ulp_mapper_result_fields_get(tbl, &num_dflds,
1252 if (!dflds || !num_dflds || encap_flds) {
1253 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1258 for (i = 0; i < num_dflds; i++) {
1259 rc = ulp_mapper_result_field_process(parms,
1265 BNXT_TF_DBG(ERR, "Failed to set data fields\n");
1270 sparms.dir = aparms.dir;
1271 sparms.tcam_tbl_type = aparms.tcam_tbl_type;
1272 sparms.idx = aparms.idx;
1273 /* Already verified the key/mask lengths */
1274 sparms.key = ulp_blob_data_get(&key, &tmplen);
1275 sparms.mask = ulp_blob_data_get(&mask, &tmplen);
1276 sparms.key_sz_in_bits = tbl->key_bit_size;
1277 sparms.result = ulp_blob_data_get(&data, &tmplen);
1279 if (tbl->result_bit_size != tmplen) {
1280 BNXT_TF_DBG(ERR, "Result len (%d) != Expected (%d)\n",
1281 tmplen, tbl->result_bit_size);
1285 sparms.result_sz_in_bits = tbl->result_bit_size;
1287 rc = tf_set_tcam_entry(tfp, &sparms);
1289 BNXT_TF_DBG(ERR, "tcam[%d][%s][%d] write failed.\n",
1290 sparms.tcam_tbl_type,
1291 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1296 /* Update cache with TCAM index if the was cache allocated. */
1297 if (parms->tcam_tbl_opc ==
1298 BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC) {
1299 if (!parms->cache_ptr) {
1300 BNXT_TF_DBG(ERR, "Unable to update cache");
1304 parms->cache_ptr->tcam_idx = aparms.idx;
1308 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1313 BNXT_TF_DBG(ERR, "Not supporting search before alloc now\n");
1319 * Only link the entry to the flow db in the event that cache was not
1322 if (parms->tcam_tbl_opc == BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL) {
1323 fid_parms.direction = tbl->direction;
1324 fid_parms.resource_func = tbl->resource_func;
1325 fid_parms.resource_type = tbl->resource_type;
1326 fid_parms.critical_resource = tbl->critical_resource;
1327 fid_parms.resource_hndl = aparms.idx;
1328 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1334 "Failed to link resource to flow rc = %d\n",
1336 /* Need to free the identifier, so goto error */
1341 * Reset the tcam table opcode to normal in case the next tcam
1342 * entry does not use cache.
1344 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1345 parms->cache_ptr = NULL;
1350 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
1351 free_parms.dir = tbl->direction;
1352 free_parms.tcam_tbl_type = tbl->resource_type;
1353 free_parms.idx = aparms.idx;
1354 trc = tf_free_tcam_entry(tfp, &free_parms);
1356 BNXT_TF_DBG(ERR, "Failed to free tcam[%d][%d][%d] on failure\n",
1357 tbl->resource_type, tbl->direction, aparms.idx);
1363 ulp_mapper_em_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1364 struct bnxt_ulp_mapper_tbl_info *tbl)
1366 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1367 struct bnxt_ulp_mapper_result_field_info *dflds;
1368 struct ulp_blob key, data;
1369 uint32_t i, num_kflds, num_dflds;
1371 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1372 struct ulp_flow_db_res_params fid_parms = { 0 };
1373 struct tf_insert_em_entry_parms iparms = { 0 };
1374 struct tf_delete_em_entry_parms free_parms = { 0 };
1376 enum bnxt_ulp_flow_mem_type mtype = parms->device_params->flow_mem_type;
1378 uint32_t encap_flds = 0;
1380 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1381 if (!kflds || !num_kflds) {
1382 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1386 /* Initialize the key/result blobs */
1387 if (!ulp_blob_init(&key, tbl->blob_key_bit_size,
1388 parms->device_params->byte_order) ||
1389 !ulp_blob_init(&data, tbl->result_bit_size,
1390 parms->device_params->byte_order)) {
1391 BNXT_TF_DBG(ERR, "blob inits failed.\n");
1395 /* create the key */
1396 for (i = 0; i < num_kflds; i++) {
1398 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1402 BNXT_TF_DBG(ERR, "Key field set failed.\n");
1408 * TBD: Normally should process identifiers in case of using recycle or
1409 * loopback. Not supporting recycle for now.
1412 /* Create the result data blob */
1413 dflds = ulp_mapper_result_fields_get(tbl, &num_dflds, &encap_flds);
1414 if (!dflds || !num_dflds || encap_flds) {
1415 BNXT_TF_DBG(ERR, "Failed to get data fields.\n");
1419 for (i = 0; i < num_dflds; i++) {
1420 struct bnxt_ulp_mapper_result_field_info *fld;
1424 rc = ulp_mapper_result_field_process(parms,
1430 BNXT_TF_DBG(ERR, "Failed to set data fields.\n");
1435 /* do the transpose for the internal EM keys */
1436 if (tbl->resource_func == BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE)
1437 ulp_blob_perform_byte_reverse(&key);
1439 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx,
1440 &iparms.tbl_scope_id);
1442 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1447 * NOTE: the actual blob size will differ from the size in the tbl
1448 * entry due to the padding.
1450 iparms.dup_check = 0;
1451 iparms.dir = tbl->direction;
1452 iparms.mem = tbl->resource_type;
1453 iparms.key = ulp_blob_data_get(&key, &tmplen);
1454 iparms.key_sz_in_bits = tbl->key_bit_size;
1455 iparms.em_record = ulp_blob_data_get(&data, &tmplen);
1456 iparms.em_record_sz_in_bits = tbl->result_bit_size;
1458 rc = tf_insert_em_entry(tfp, &iparms);
1460 BNXT_TF_DBG(ERR, "Failed to insert em entry rc=%d.\n", rc);
1464 /* Mark action process */
1465 if (mtype == BNXT_ULP_FLOW_MEM_TYPE_EXT &&
1466 tbl->resource_type == TF_MEM_EXTERNAL)
1467 rc = ulp_mapper_mark_gfid_process(parms, tbl, iparms.flow_id);
1468 else if (mtype == BNXT_ULP_FLOW_MEM_TYPE_INT &&
1469 tbl->resource_type == TF_MEM_INTERNAL)
1470 rc = ulp_mapper_mark_act_ptr_process(parms, tbl);
1472 BNXT_TF_DBG(ERR, "Failed to add mark to flow\n");
1476 /* Link the EM resource to the flow in the flow db */
1477 memset(&fid_parms, 0, sizeof(fid_parms));
1478 fid_parms.direction = tbl->direction;
1479 fid_parms.resource_func = tbl->resource_func;
1480 fid_parms.resource_type = tbl->resource_type;
1481 fid_parms.critical_resource = tbl->critical_resource;
1482 fid_parms.resource_hndl = iparms.flow_handle;
1484 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1489 BNXT_TF_DBG(ERR, "Fail to link res to flow rc = %d\n",
1491 /* Need to free the identifier, so goto error */
1497 free_parms.dir = iparms.dir;
1498 free_parms.mem = iparms.mem;
1499 free_parms.tbl_scope_id = iparms.tbl_scope_id;
1500 free_parms.flow_handle = iparms.flow_handle;
1502 trc = tf_delete_em_entry(tfp, &free_parms);
1504 BNXT_TF_DBG(ERR, "Failed to delete EM entry on failed add\n");
1510 ulp_mapper_index_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1511 struct bnxt_ulp_mapper_tbl_info *tbl,
1514 struct bnxt_ulp_mapper_result_field_info *flds;
1515 struct ulp_flow_db_res_params fid_parms;
1516 struct ulp_blob data;
1519 uint32_t i, num_flds;
1520 int32_t rc = 0, trc = 0;
1521 struct tf_alloc_tbl_entry_parms aparms = { 0 };
1522 struct tf_set_tbl_entry_parms sparms = { 0 };
1523 struct tf_free_tbl_entry_parms free_parms = { 0 };
1524 uint32_t tbl_scope_id;
1525 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1527 uint32_t encap_flds = 0;
1529 /* Get the scope id first */
1530 rc = bnxt_ulp_cntxt_tbl_scope_id_get(parms->ulp_ctx, &tbl_scope_id);
1532 BNXT_TF_DBG(ERR, "Failed to get table scope rc=%d\n", rc);
1536 /* use the max size if encap is enabled */
1537 if (tbl->encap_num_fields)
1538 bit_size = BNXT_ULP_FLMP_BLOB_SIZE_IN_BITS;
1540 bit_size = tbl->result_bit_size;
1542 /* Initialize the blob data */
1543 if (!ulp_blob_init(&data, bit_size,
1544 parms->device_params->byte_order)) {
1545 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1549 /* Get the result fields list */
1551 flds = ulp_mapper_result_fields_get(tbl, &num_flds,
1554 flds = ulp_mapper_act_result_fields_get(tbl, &num_flds,
1557 if (!flds || (!num_flds && !encap_flds)) {
1558 BNXT_TF_DBG(ERR, "template undefined for the index table\n");
1562 /* process the result fields, loop through them */
1563 for (i = 0; i < (num_flds + encap_flds); i++) {
1564 /* set the swap index if encap swap bit is enabled */
1565 if (parms->device_params->encap_byte_swap && encap_flds &&
1567 ulp_blob_encap_swap_idx_set(&data);
1569 /* Process the result fields */
1570 rc = ulp_mapper_result_field_process(parms,
1576 BNXT_TF_DBG(ERR, "data field failed\n");
1581 /* if encap bit swap is enabled perform the bit swap */
1582 if (parms->device_params->encap_byte_swap && encap_flds) {
1583 ulp_blob_perform_encap_swap(&data);
1587 * Check for index opcode, if it is Global then
1588 * no need to allocate the table, just set the table
1589 * and exit since it is not maintained in the flow db.
1591 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_GLOBAL) {
1592 /* get the index from index operand */
1593 if (tbl->index_operand < BNXT_ULP_GLB_REGFILE_INDEX_LAST &&
1594 ulp_mapper_glb_resource_read(parms->mapper_data,
1598 BNXT_TF_DBG(ERR, "Glbl regfile[%d] read failed.\n",
1599 tbl->index_operand);
1602 /* set the Tf index table */
1603 sparms.dir = tbl->direction;
1604 sparms.type = tbl->resource_type;
1605 sparms.data = ulp_blob_data_get(&data, &tmplen);
1606 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1607 sparms.idx = tfp_be_to_cpu_64(idx);
1608 sparms.tbl_scope_id = tbl_scope_id;
1610 rc = tf_set_tbl_entry(tfp, &sparms);
1613 "Glbl Set table[%d][%s][%d] failed rc=%d\n",
1615 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1620 return 0; /* success */
1623 /* Perform the tf table allocation by filling the alloc params */
1624 aparms.dir = tbl->direction;
1625 aparms.type = tbl->resource_type;
1626 aparms.search_enable = tbl->srch_b4_alloc;
1627 aparms.result = ulp_blob_data_get(&data, &tmplen);
1628 aparms.result_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1629 aparms.tbl_scope_id = tbl_scope_id;
1631 /* All failures after the alloc succeeds require a free */
1632 rc = tf_alloc_tbl_entry(tfp, &aparms);
1634 BNXT_TF_DBG(ERR, "Alloc table[%d][%s] failed rc=%d\n",
1636 (aparms.dir == TF_DIR_RX) ? "RX" : "TX",
1642 * calculate the idx for the result record, for external EM the offset
1643 * needs to be shifted accordingly. If external non-inline table types
1644 * are used then need to revisit this logic.
1646 if (aparms.type == TF_TBL_TYPE_EXT)
1647 idx = TF_ACT_REC_OFFSET_2_PTR(aparms.idx);
1651 /* Always storing values in Regfile in BE */
1652 idx = tfp_cpu_to_be_64(idx);
1653 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_ALLOCATE) {
1654 rc = ulp_regfile_write(parms->regfile, tbl->index_operand, idx);
1656 BNXT_TF_DBG(ERR, "Write regfile[%d] failed\n",
1657 tbl->index_operand);
1662 /* Perform the tf table set by filling the set params */
1663 if (!tbl->srch_b4_alloc || !aparms.hit) {
1664 sparms.dir = tbl->direction;
1665 sparms.type = tbl->resource_type;
1666 sparms.data = ulp_blob_data_get(&data, &tmplen);
1667 sparms.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1668 sparms.idx = aparms.idx;
1669 sparms.tbl_scope_id = tbl_scope_id;
1671 rc = tf_set_tbl_entry(tfp, &sparms);
1673 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
1675 (sparms.dir == TF_DIR_RX) ? "RX" : "TX",
1682 /* Link the resource to the flow in the flow db */
1683 memset(&fid_parms, 0, sizeof(fid_parms));
1684 fid_parms.direction = tbl->direction;
1685 fid_parms.resource_func = tbl->resource_func;
1686 fid_parms.resource_type = tbl->resource_type;
1687 fid_parms.resource_sub_type = tbl->resource_sub_type;
1688 fid_parms.resource_hndl = aparms.idx;
1689 fid_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
1691 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1696 BNXT_TF_DBG(ERR, "Failed to link resource to flow rc = %d\n",
1701 /* Perform the VF rep action */
1702 rc = ulp_mapper_mark_vfr_idx_process(parms, tbl);
1704 BNXT_TF_DBG(ERR, "Failed to add vfr mark rc = %d\n", rc);
1710 * Free the allocated resource since we failed to either
1711 * write to the entry or link the flow
1713 free_parms.dir = tbl->direction;
1714 free_parms.type = tbl->resource_type;
1715 free_parms.idx = aparms.idx;
1716 free_parms.tbl_scope_id = tbl_scope_id;
1718 trc = tf_free_tbl_entry(tfp, &free_parms);
1720 BNXT_TF_DBG(ERR, "Failed to free tbl entry on failure\n");
1726 ulp_mapper_cache_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1727 struct bnxt_ulp_mapper_tbl_info *tbl)
1729 struct bnxt_ulp_mapper_class_key_field_info *kflds;
1730 struct bnxt_ulp_mapper_cache_entry *cache_entry;
1731 struct bnxt_ulp_mapper_ident_info *idents;
1732 uint32_t i, num_kflds = 0, num_idents = 0;
1733 struct ulp_flow_db_res_params fid_parms;
1734 struct tf_free_identifier_parms fparms;
1735 uint16_t tmplen, tmp_ident;
1736 struct ulp_blob key;
1742 /* Get the key fields list and build the key. */
1743 kflds = ulp_mapper_key_fields_get(tbl, &num_kflds);
1744 if (!kflds || !num_kflds) {
1745 BNXT_TF_DBG(ERR, "Failed to get key fields\n");
1748 if (!ulp_blob_init(&key, tbl->key_bit_size,
1749 parms->device_params->byte_order)) {
1750 BNXT_TF_DBG(ERR, "Failed to alloc blob\n");
1753 for (i = 0; i < num_kflds; i++) {
1755 rc = ulp_mapper_keymask_field_process(parms, tbl->direction,
1757 &key, 1, "Cache Key");
1760 "Failed to create key for Cache rc=%d\n",
1767 * Perform the lookup in the cache table with constructed key. The
1768 * cache_key is a byte array of tmplen, it needs to be converted to a
1769 * index for the cache table.
1771 cache_key = ulp_blob_data_get(&key, &tmplen);
1772 ckey = (uint16_t *)cache_key;
1775 * The id computed based on resource sub type and direction where
1776 * dir is the bit0 and rest of the bits come from resource
1779 cache_entry = ulp_mapper_cache_entry_get(parms->ulp_ctx,
1780 (tbl->resource_sub_type << 1 |
1781 (tbl->direction & 0x1)),
1785 * Get the identifier list for processing by both the hit and miss
1788 idents = ulp_mapper_ident_fields_get(tbl, &num_idents);
1790 if (!cache_entry->ref_count) {
1791 /* Initialize the cache entry */
1792 cache_entry->tcam_idx = 0;
1793 cache_entry->ref_count = 0;
1794 for (i = 0; i < BNXT_ULP_CACHE_TBL_IDENT_MAX_NUM; i++)
1795 cache_entry->idents[i] = ULP_IDENTS_INVALID;
1797 /* Need to allocate identifiers for storing in the cache. */
1798 for (i = 0; i < num_idents; i++) {
1800 * Since we are using the cache, the identifier does not
1801 * get added to the flow db. Pass in the pointer to the
1804 rc = ulp_mapper_ident_process(parms, tbl,
1805 &idents[i], &tmp_ident);
1809 cache_entry->ident_types[i] = idents[i].ident_type;
1810 cache_entry->idents[i] = tmp_ident;
1813 /* Tell the TCAM processor to alloc an entry */
1814 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_ALLOC;
1815 /* Store the cache key for use by the tcam process code */
1816 parms->cache_ptr = cache_entry;
1818 /* Cache hit, get values from result. */
1819 for (i = 0; i < num_idents; i++) {
1820 regval = (uint64_t)cache_entry->idents[i];
1821 if (!ulp_regfile_write(parms->regfile,
1822 idents[i].regfile_idx,
1823 tfp_cpu_to_be_64(regval))) {
1825 "Failed to write to regfile\n");
1830 * The cached entry is being used, so let the tcam processing
1831 * know not to process this table.
1833 parms->tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_CACHE_SKIP;
1836 /* Made through the cache processing, increment the reference count. */
1837 cache_entry->ref_count++;
1839 /* Link the cache to the flow db. */
1840 memset(&fid_parms, 0, sizeof(fid_parms));
1841 fid_parms.direction = tbl->direction;
1842 fid_parms.resource_func = tbl->resource_func;
1845 * Cache resource type is composed of table_type, resource
1846 * sub type and direction, it needs to set appropriately via setter.
1848 ulp_mapper_cache_res_type_set(&fid_parms,
1850 (tbl->resource_sub_type << 1 |
1851 (tbl->direction & 0x1)));
1852 fid_parms.resource_hndl = (uint64_t)*ckey;
1853 fid_parms.critical_resource = tbl->critical_resource;
1854 rc = ulp_flow_db_resource_add(parms->ulp_ctx,
1859 BNXT_TF_DBG(ERR, "Failed to add cache to flow db.\n");
1864 * This error handling only gets called when the idents are being
1865 * allocated for the cache on misses. Using the num_idents that was
1868 for (i = 0; i < num_idents; i++) {
1869 if (cache_entry->idents[i] == ULP_IDENTS_INVALID)
1872 fparms.dir = tbl->direction;
1873 fparms.ident_type = idents[i].ident_type;
1874 fparms.id = cache_entry->idents[i];
1875 tf_free_identifier(parms->tfp, &fparms);
1882 ulp_mapper_if_tbl_process(struct bnxt_ulp_mapper_parms *parms,
1883 struct bnxt_ulp_mapper_tbl_info *tbl)
1885 struct bnxt_ulp_mapper_result_field_info *flds;
1886 struct ulp_blob data;
1889 uint32_t i, num_flds;
1891 struct tf_set_if_tbl_entry_parms iftbl_params = { 0 };
1892 struct tf *tfp = bnxt_ulp_cntxt_tfp_get(parms->ulp_ctx);
1893 uint32_t encap_flds;
1895 /* Initialize the blob data */
1896 if (!ulp_blob_init(&data, tbl->result_bit_size,
1897 parms->device_params->byte_order)) {
1898 BNXT_TF_DBG(ERR, "Failed initial index table blob\n");
1902 /* Get the result fields list */
1903 flds = ulp_mapper_result_fields_get(tbl, &num_flds, &encap_flds);
1905 if (!flds || !num_flds || encap_flds) {
1906 BNXT_TF_DBG(ERR, "template undefined for the IF table\n");
1910 /* process the result fields, loop through them */
1911 for (i = 0; i < num_flds; i++) {
1912 /* Process the result fields */
1913 rc = ulp_mapper_result_field_process(parms,
1919 BNXT_TF_DBG(ERR, "data field failed\n");
1924 /* Get the index details from computed field */
1925 if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_COMP_FIELD) {
1926 idx = ULP_COMP_FLD_IDX_RD(parms, tbl->index_operand);
1927 } else if (tbl->index_opcode == BNXT_ULP_INDEX_OPCODE_CONSTANT) {
1928 idx = tbl->index_operand;
1930 BNXT_TF_DBG(ERR, "Invalid tbl index opcode\n");
1934 /* Perform the tf table set by filling the set params */
1935 iftbl_params.dir = tbl->direction;
1936 iftbl_params.type = tbl->resource_type;
1937 iftbl_params.data = ulp_blob_data_get(&data, &tmplen);
1938 iftbl_params.data_sz_in_bytes = ULP_BITS_2_BYTE(tmplen);
1939 iftbl_params.idx = idx;
1941 rc = tf_set_if_tbl_entry(tfp, &iftbl_params);
1943 BNXT_TF_DBG(ERR, "Set table[%d][%s][%d] failed rc=%d\n",
1945 (iftbl_params.dir == TF_DIR_RX) ? "RX" : "TX",
1952 * TBD: Need to look at the need to store idx in flow db for restore
1953 * the table to its original state on deletion of this entry.
1959 ulp_mapper_glb_resource_info_init(struct bnxt_ulp_context *ulp_ctx,
1960 struct bnxt_ulp_mapper_data *mapper_data)
1962 struct bnxt_ulp_glb_resource_info *glb_res;
1963 uint32_t num_glb_res_ids, idx;
1966 glb_res = ulp_mapper_glb_resource_info_list_get(&num_glb_res_ids);
1967 if (!glb_res || !num_glb_res_ids) {
1968 BNXT_TF_DBG(ERR, "Invalid Arguments\n");
1972 /* Iterate the global resources and process each one */
1973 for (idx = 0; idx < num_glb_res_ids; idx++) {
1974 switch (glb_res[idx].resource_func) {
1975 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
1976 rc = ulp_mapper_resource_ident_allocate(ulp_ctx,
1980 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
1981 rc = ulp_mapper_resource_index_tbl_alloc(ulp_ctx,
1986 BNXT_TF_DBG(ERR, "Global resource %x not supported\n",
1987 glb_res[idx].resource_func);
1998 * Function to process the conditional opcode of the mapper table.
1999 * returns 1 to skip the table.
2000 * return 0 to continue processing the table.
2003 ulp_mapper_tbl_cond_opcode_process(struct bnxt_ulp_mapper_parms *parms,
2004 struct bnxt_ulp_mapper_tbl_info *tbl)
2008 switch (tbl->cond_opcode) {
2009 case BNXT_ULP_COND_OPCODE_NOP:
2012 case BNXT_ULP_COND_OPCODE_COMP_FIELD_IS_SET:
2013 if (tbl->cond_operand < BNXT_ULP_CF_IDX_LAST &&
2014 ULP_COMP_FLD_IDX_RD(parms, tbl->cond_operand))
2017 case BNXT_ULP_COND_OPCODE_ACTION_BIT_IS_SET:
2018 if (ULP_BITMAP_ISSET(parms->act_bitmap->bits,
2022 case BNXT_ULP_COND_OPCODE_HDR_BIT_IS_SET:
2023 if (ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
2027 case BNXT_ULP_COND_OPCODE_COMP_FIELD_NOT_SET:
2028 if (tbl->cond_operand < BNXT_ULP_CF_IDX_LAST &&
2029 !ULP_COMP_FLD_IDX_RD(parms, tbl->cond_operand))
2032 case BNXT_ULP_COND_OPCODE_ACTION_BIT_NOT_SET:
2033 if (!ULP_BITMAP_ISSET(parms->act_bitmap->bits,
2037 case BNXT_ULP_COND_OPCODE_HDR_BIT_NOT_SET:
2038 if (!ULP_BITMAP_ISSET(parms->hdr_bitmap->bits,
2044 "Invalid arg in mapper tbl for cond opcode\n");
2051 * Function to process the action template. Iterate through the list
2052 * action info templates and process it.
2055 ulp_mapper_action_tbls_process(struct bnxt_ulp_mapper_parms *parms)
2059 struct bnxt_ulp_mapper_tbl_info *tbl;
2061 if (!parms->atbls || !parms->num_atbls) {
2062 BNXT_TF_DBG(ERR, "No action tables for template[%d][%d].\n",
2063 parms->dev_id, parms->act_tid);
2067 for (i = 0; i < parms->num_atbls; i++) {
2068 tbl = &parms->atbls[i];
2069 if (ulp_mapper_tbl_cond_opcode_process(parms, tbl))
2072 switch (tbl->resource_func) {
2073 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2074 rc = ulp_mapper_index_tbl_process(parms, tbl, false);
2076 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2077 tbl->resource_func);
2082 BNXT_TF_DBG(ERR, "Unexpected action resource %d\n",
2083 tbl->resource_func);
2091 /* Create the classifier table entries for a flow. */
2093 ulp_mapper_class_tbls_process(struct bnxt_ulp_mapper_parms *parms)
2101 if (!parms->ctbls || !parms->num_ctbls) {
2102 BNXT_TF_DBG(ERR, "No class tables for template[%d][%d].\n",
2103 parms->dev_id, parms->class_tid);
2107 for (i = 0; i < parms->num_ctbls; i++) {
2108 struct bnxt_ulp_mapper_tbl_info *tbl = &parms->ctbls[i];
2110 if (ulp_mapper_tbl_cond_opcode_process(parms, tbl))
2113 switch (tbl->resource_func) {
2114 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2115 rc = ulp_mapper_tcam_tbl_process(parms, tbl);
2117 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2118 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2119 rc = ulp_mapper_em_tbl_process(parms, tbl);
2121 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2122 rc = ulp_mapper_index_tbl_process(parms, tbl, true);
2124 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2125 rc = ulp_mapper_cache_tbl_process(parms, tbl);
2127 case BNXT_ULP_RESOURCE_FUNC_IF_TABLE:
2128 rc = ulp_mapper_if_tbl_process(parms, tbl);
2131 BNXT_TF_DBG(ERR, "Unexpected class resource %d\n",
2132 tbl->resource_func);
2137 BNXT_TF_DBG(ERR, "Resource type %d failed\n",
2138 tbl->resource_func);
2147 ulp_mapper_resource_free(struct bnxt_ulp_context *ulp,
2148 struct ulp_flow_db_res_params *res)
2154 BNXT_TF_DBG(ERR, "Unable to free resource\n ");
2158 tfp = bnxt_ulp_cntxt_tfp_get(ulp);
2160 BNXT_TF_DBG(ERR, "Unable to free resource failed to get tfp\n");
2164 switch (res->resource_func) {
2165 case BNXT_ULP_RESOURCE_FUNC_CACHE_TABLE:
2166 rc = ulp_mapper_cache_entry_free(ulp, tfp, res);
2168 case BNXT_ULP_RESOURCE_FUNC_TCAM_TABLE:
2169 rc = ulp_mapper_tcam_entry_free(ulp, tfp, res);
2171 case BNXT_ULP_RESOURCE_FUNC_EXT_EM_TABLE:
2172 case BNXT_ULP_RESOURCE_FUNC_INT_EM_TABLE:
2173 rc = ulp_mapper_em_entry_free(ulp, tfp, res);
2175 case BNXT_ULP_RESOURCE_FUNC_INDEX_TABLE:
2176 rc = ulp_mapper_index_entry_free(ulp, tfp, res);
2178 case BNXT_ULP_RESOURCE_FUNC_IDENTIFIER:
2179 rc = ulp_mapper_ident_free(ulp, tfp, res);
2181 case BNXT_ULP_RESOURCE_FUNC_HW_FID:
2182 rc = ulp_mapper_mark_free(ulp, res);
2192 ulp_mapper_resources_free(struct bnxt_ulp_context *ulp_ctx,
2194 enum bnxt_ulp_flow_db_tables tbl_type)
2196 struct ulp_flow_db_res_params res_parms = { 0 };
2200 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2205 * Set the critical resource on the first resource del, then iterate
2206 * while status is good
2208 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_YES;
2209 rc = ulp_flow_db_resource_del(ulp_ctx, tbl_type, fid, &res_parms);
2213 * This is unexpected on the first call to resource del.
2214 * It likely means that the flow did not exist in the flow db.
2216 BNXT_TF_DBG(ERR, "Flow[%d][0x%08x] failed to free (rc=%d)\n",
2222 trc = ulp_mapper_resource_free(ulp_ctx, &res_parms);
2225 * On fail, we still need to attempt to free the
2226 * remaining resources. Don't return
2229 "Flow[%d][0x%x] Res[%d][0x%016" PRIx64
2230 "] failed rc=%d.\n",
2231 tbl_type, fid, res_parms.resource_func,
2232 res_parms.resource_hndl, trc);
2234 /* All subsequent call require the non-critical_resource */
2235 res_parms.critical_resource = BNXT_ULP_CRITICAL_RESOURCE_NO;
2237 rc = ulp_flow_db_resource_del(ulp_ctx,
2243 /* Free the Flow ID since we've removed all resources */
2244 rc = ulp_flow_db_fid_free(ulp_ctx, tbl_type, fid);
2250 ulp_mapper_glb_resource_info_deinit(struct bnxt_ulp_context *ulp_ctx,
2251 struct bnxt_ulp_mapper_data *mapper_data)
2253 struct bnxt_ulp_mapper_glb_resource_entry *ent;
2254 struct ulp_flow_db_res_params res;
2257 /* Iterate the global resources and process each one */
2258 for (dir = TF_DIR_RX; dir < TF_DIR_MAX; dir++) {
2259 for (idx = 0; idx < BNXT_ULP_GLB_RESOURCE_TBL_MAX_SZ;
2261 ent = &mapper_data->glb_res_tbl[dir][idx];
2262 if (ent->resource_func ==
2263 BNXT_ULP_RESOURCE_FUNC_INVALID)
2265 memset(&res, 0, sizeof(struct ulp_flow_db_res_params));
2266 res.resource_func = ent->resource_func;
2267 res.direction = dir;
2268 res.resource_type = ent->resource_type;
2269 /*convert it from BE to cpu */
2271 tfp_be_to_cpu_64(ent->resource_hndl);
2272 ulp_mapper_resource_free(ulp_ctx, &res);
2278 ulp_mapper_flow_destroy(struct bnxt_ulp_context *ulp_ctx, uint32_t fid,
2279 enum bnxt_ulp_flow_db_tables flow_tbl_type)
2282 BNXT_TF_DBG(ERR, "Invalid parms, unable to free flow\n");
2286 return ulp_mapper_resources_free(ulp_ctx, fid, flow_tbl_type);
2289 /* Function to handle the default global templates that are allocated during
2290 * the startup and reused later.
2293 ulp_mapper_glb_template_table_init(struct bnxt_ulp_context *ulp_ctx)
2295 uint32_t *glbl_tmpl_list;
2296 uint32_t num_glb_tmpls, idx, dev_id;
2297 struct bnxt_ulp_mapper_parms parms;
2298 struct bnxt_ulp_mapper_data *mapper_data;
2301 glbl_tmpl_list = ulp_mapper_glb_template_table_get(&num_glb_tmpls);
2302 if (!glbl_tmpl_list || !num_glb_tmpls)
2303 return rc; /* No global templates to process */
2305 /* Get the device id from the ulp context */
2306 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &dev_id)) {
2307 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2311 mapper_data = bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2313 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2317 /* Iterate the global resources and process each one */
2318 for (idx = 0; idx < num_glb_tmpls; idx++) {
2319 /* Initialize the parms structure */
2320 memset(&parms, 0, sizeof(parms));
2321 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2322 parms.ulp_ctx = ulp_ctx;
2323 parms.dev_id = dev_id;
2324 parms.mapper_data = mapper_data;
2326 /* Get the class table entry from dev id and class id */
2327 parms.class_tid = glbl_tmpl_list[idx];
2328 parms.ctbls = ulp_mapper_class_tbl_list_get(parms.dev_id,
2332 if (!parms.ctbls || !parms.num_ctbls) {
2333 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2334 parms.dev_id, parms.class_tid);
2337 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2338 if (!parms.device_params) {
2339 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2340 parms.dev_id, parms.class_tid);
2343 rc = ulp_mapper_class_tbls_process(&parms);
2346 "class tables failed creation for %d:%d\n",
2347 parms.dev_id, parms.class_tid);
2354 /* Function to handle the mapping of the Flow to be compatible
2355 * with the underlying hardware.
2358 ulp_mapper_flow_create(struct bnxt_ulp_context *ulp_ctx,
2359 struct bnxt_ulp_mapper_create_parms *cparms,
2362 struct bnxt_ulp_mapper_parms parms;
2363 struct ulp_regfile regfile;
2366 if (!ulp_ctx || !cparms)
2369 /* Initialize the parms structure */
2370 memset(&parms, 0, sizeof(parms));
2371 parms.act_prop = cparms->act_prop;
2372 parms.act_bitmap = cparms->act;
2373 parms.hdr_bitmap = cparms->hdr_bitmap;
2374 parms.regfile = ®file;
2375 parms.hdr_field = cparms->hdr_field;
2376 parms.comp_fld = cparms->comp_fld;
2377 parms.tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2378 parms.ulp_ctx = ulp_ctx;
2379 parms.tcam_tbl_opc = BNXT_ULP_MAPPER_TCAM_TBL_OPC_NORMAL;
2381 /* Get the device id from the ulp context */
2382 if (bnxt_ulp_cntxt_dev_id_get(ulp_ctx, &parms.dev_id)) {
2383 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
2388 * Get the mapper data for dynamic mapper data such as default
2391 parms.mapper_data = (struct bnxt_ulp_mapper_data *)
2392 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2393 if (!parms.mapper_data) {
2394 BNXT_TF_DBG(ERR, "Failed to get the ulp mapper data\n");
2398 /* Get the action table entry from device id and act context id */
2399 parms.act_tid = cparms->act_tid;
2402 * Perform the action table get only if act template is not zero
2403 * for act template zero like for default rules ignore the action
2406 if (parms.act_tid) {
2407 parms.atbls = ulp_mapper_action_tbl_list_get(parms.dev_id,
2410 if (!parms.atbls || !parms.num_atbls) {
2411 BNXT_TF_DBG(ERR, "No action tables for %d:%d\n",
2412 parms.dev_id, parms.act_tid);
2417 /* Get the class table entry from device id and act context id */
2418 parms.class_tid = cparms->class_tid;
2419 parms.ctbls = ulp_mapper_class_tbl_list_get(parms.dev_id,
2423 if (!parms.ctbls || !parms.num_ctbls) {
2424 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2425 parms.dev_id, parms.class_tid);
2429 /* Get the device params, it will be used in later processing */
2430 parms.device_params = bnxt_ulp_device_params_get(parms.dev_id);
2431 if (!parms.device_params) {
2432 BNXT_TF_DBG(ERR, "No class tables for %d:%d\n",
2433 parms.dev_id, parms.class_tid);
2437 /* initialize the registry file for further processing */
2438 if (!ulp_regfile_init(parms.regfile)) {
2439 BNXT_TF_DBG(ERR, "regfile initialization failed.\n");
2443 rc = ulp_regfile_write(parms.regfile,
2444 BNXT_ULP_REGFILE_INDEX_CLASS_TID,
2445 tfp_cpu_to_be_64((uint64_t)parms.class_tid));
2447 BNXT_TF_DBG(ERR, "Unable to write template ID to regfile\n");
2451 /* Allocate a Flow ID for attaching all resources for the flow to.
2452 * Once allocated, all errors have to walk the list of resources and
2453 * free each of them.
2455 rc = ulp_flow_db_fid_alloc(ulp_ctx,
2460 BNXT_TF_DBG(ERR, "Unable to allocate flow table entry\n");
2464 /* Process the action template list from the selected action table*/
2465 if (parms.act_tid) {
2466 rc = ulp_mapper_action_tbls_process(&parms);
2469 "action tables failed creation for %d:%d\n",
2470 parms.dev_id, parms.act_tid);
2475 /* All good. Now process the class template */
2476 rc = ulp_mapper_class_tbls_process(&parms);
2478 BNXT_TF_DBG(ERR, "class tables failed creation for %d:%d\n",
2479 parms.dev_id, parms.class_tid);
2483 *flowid = parms.fid;
2488 /* Free all resources that were allocated during flow creation */
2489 trc = ulp_mapper_flow_destroy(ulp_ctx, parms.fid,
2490 BNXT_ULP_REGULAR_FLOW_TABLE);
2492 BNXT_TF_DBG(ERR, "Failed to free all resources rc=%d\n", trc);
2498 ulp_mapper_init(struct bnxt_ulp_context *ulp_ctx)
2500 struct bnxt_ulp_cache_tbl_params *tbl;
2501 struct bnxt_ulp_mapper_data *data;
2509 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2513 data = rte_zmalloc("ulp_mapper_data",
2514 sizeof(struct bnxt_ulp_mapper_data), 0);
2516 BNXT_TF_DBG(ERR, "Failed to allocate the mapper data\n");
2520 if (bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, data)) {
2521 BNXT_TF_DBG(ERR, "Failed to set mapper data in context\n");
2522 /* Don't call deinit since the prof_func wasn't allocated. */
2527 /* Allocate the global resource ids */
2528 rc = ulp_mapper_glb_resource_info_init(ulp_ctx, data);
2530 BNXT_TF_DBG(ERR, "Failed to initialize global resource ids\n");
2534 /* Allocate the ulp cache tables. */
2535 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
2536 tbl = ulp_mapper_cache_tbl_params_get(i);
2538 BNXT_TF_DBG(ERR, "Failed to get cache table parms (%d)",
2542 if (tbl->num_entries != 0) {
2543 csize = sizeof(struct bnxt_ulp_mapper_cache_entry) *
2545 data->cache_tbl[i] = rte_zmalloc("ulp mapper cache tbl",
2547 if (!data->cache_tbl[i]) {
2548 BNXT_TF_DBG(ERR, "Failed to allocate Cache "
2556 rc = ulp_mapper_glb_template_table_init(ulp_ctx);
2558 BNXT_TF_DBG(ERR, "Failed to initialize global templates\n");
2564 /* Ignore the return code in favor of returning the original error. */
2565 ulp_mapper_deinit(ulp_ctx);
2570 ulp_mapper_deinit(struct bnxt_ulp_context *ulp_ctx)
2572 struct bnxt_ulp_mapper_data *data;
2578 "Failed to acquire ulp context, so data may "
2579 "not be released.\n");
2583 data = (struct bnxt_ulp_mapper_data *)
2584 bnxt_ulp_cntxt_ptr2_mapper_data_get(ulp_ctx);
2586 /* Go ahead and return since there is no allocated data. */
2587 BNXT_TF_DBG(ERR, "No data appears to have been allocated.\n");
2591 tfp = bnxt_ulp_cntxt_tfp_get(ulp_ctx);
2593 BNXT_TF_DBG(ERR, "Failed to acquire tfp.\n");
2594 /* Free the mapper data regardless of errors. */
2595 goto free_mapper_data;
2598 /* Free the global resource info table entries */
2599 ulp_mapper_glb_resource_info_deinit(ulp_ctx, data);
2602 /* Free the ulp cache tables */
2603 for (i = 0; i < BNXT_ULP_CACHE_TBL_MAX_SZ; i++) {
2604 rte_free(data->cache_tbl[i]);
2605 data->cache_tbl[i] = NULL;
2609 /* Reset the data pointer within the ulp_ctx. */
2610 bnxt_ulp_cntxt_ptr2_mapper_data_set(ulp_ctx, NULL);