1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2020 Broadcom
6 #include <rte_common.h>
7 #include <rte_malloc.h>
11 #include "tf_ext_flow_handle.h"
12 #include "ulp_mark_mgr.h"
13 #include "bnxt_tf_common.h"
14 #include "ulp_template_db.h"
15 #include "ulp_template_struct.h"
17 static inline uint32_t
18 ulp_mark_db_idx_get(bool is_gfid, uint32_t fid, struct bnxt_ulp_mark_tbl *mtbl)
20 uint32_t idx = 0, hashtype = 0;
23 TF_GET_HASH_TYPE_FROM_GFID(fid, hashtype);
24 TF_GET_HASH_INDEX_FROM_GFID(fid, idx);
26 /* Need to truncate anything beyond supported flows */
27 idx &= mtbl->gfid_mask;
30 idx |= mtbl->gfid_type_bit;
39 ulp_mark_db_mark_set(struct bnxt_ulp_context *ctxt,
44 struct bnxt_ulp_mark_tbl *mtbl;
48 BNXT_TF_DBG(ERR, "Invalid ulp context\n");
52 mtbl = bnxt_ulp_cntxt_ptr2_mark_db_get(ctxt);
54 BNXT_TF_DBG(ERR, "Unable to get Mark DB\n");
58 idx = ulp_mark_db_idx_get(is_gfid, fid, mtbl);
61 BNXT_TF_DBG(ERR, "Set GFID[0x%0x] = 0x%0x\n", idx, mark);
63 mtbl->gfid_tbl[idx].mark_id = mark;
64 mtbl->gfid_tbl[idx].valid = true;
66 /* For the LFID, the FID is used as the index */
67 mtbl->lfid_tbl[fid].mark_id = mark;
68 mtbl->lfid_tbl[fid].valid = true;
75 * Allocate and Initialize all Mark Manager resources for this ulp context.
77 * ctxt [in] The ulp context for the mark manager.
81 ulp_mark_db_init(struct bnxt_ulp_context *ctxt)
83 struct bnxt_ulp_device_params *dparms;
84 struct bnxt_ulp_mark_tbl *mark_tbl = NULL;
88 BNXT_TF_DBG(DEBUG, "Invalid ULP CTXT\n");
92 if (bnxt_ulp_cntxt_dev_id_get(ctxt, &dev_id)) {
93 BNXT_TF_DBG(DEBUG, "Failed to get device id\n");
97 dparms = bnxt_ulp_device_params_get(dev_id);
99 BNXT_TF_DBG(DEBUG, "Failed to device parms\n");
103 mark_tbl = rte_zmalloc("ulp_rx_mark_tbl_ptr",
104 sizeof(struct bnxt_ulp_mark_tbl), 0);
108 /* Need to allocate 2 * Num flows to account for hash type bit. */
109 mark_tbl->lfid_tbl = rte_zmalloc("ulp_rx_em_flow_mark_table",
110 dparms->lfid_entries *
111 sizeof(struct bnxt_lfid_mark_info),
114 if (!mark_tbl->lfid_tbl)
117 /* Need to allocate 2 * Num flows to account for hash type bit. */
118 mark_tbl->gfid_tbl = rte_zmalloc("ulp_rx_eem_flow_mark_table",
119 2 * dparms->num_flows *
120 sizeof(struct bnxt_gfid_mark_info),
122 if (!mark_tbl->gfid_tbl)
126 * TBD: This needs to be generalized for better mark handling
127 * These values are used to compress the FID to the allowable index
128 * space. The FID from hw may be the full hash.
130 mark_tbl->gfid_max = dparms->gfid_entries - 1;
131 mark_tbl->gfid_mask = (dparms->gfid_entries / 2) - 1;
132 mark_tbl->gfid_type_bit = (dparms->gfid_entries / 2);
134 BNXT_TF_DBG(DEBUG, "GFID Max = 0x%08x\nGFID MASK = 0x%08x\n",
136 mark_tbl->gfid_mask);
138 /* Add the mart tbl to the ulp context. */
139 bnxt_ulp_cntxt_ptr2_mark_db_set(ctxt, mark_tbl);
144 rte_free(mark_tbl->gfid_tbl);
145 rte_free(mark_tbl->lfid_tbl);
148 "Failed to allocate memory for mark mgr\n");
154 * Release all resources in the Mark Manager for this ulp context
156 * ctxt [in] The ulp context for the mark manager
160 ulp_mark_db_deinit(struct bnxt_ulp_context *ctxt)
162 struct bnxt_ulp_mark_tbl *mtbl;
164 mtbl = bnxt_ulp_cntxt_ptr2_mark_db_get(ctxt);
167 rte_free(mtbl->gfid_tbl);
168 rte_free(mtbl->lfid_tbl);
171 /* Safe to ignore on deinit */
172 (void)bnxt_ulp_cntxt_ptr2_mark_db_set(ctxt, NULL);
179 * Adds a Mark to the Mark Manager
181 * ctxt [in] The ulp context for the mark manager
183 * is_gfid [in] The type of fid (GFID or LFID)
185 * fid [in] The flow id that is returned by HW in BD
187 * mark [in] The mark to be associated with the FID
191 ulp_mark_db_mark_add(struct bnxt_ulp_context *ctxt,
196 return ulp_mark_db_mark_set(ctxt, is_gfid, gfid, mark);