1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
6 /* Truflow Table APIs and supporting code */
8 #include <rte_common.h>
11 #include "tf_common.h"
16 #include "tf_session.h"
17 #include "tf_device.h"
24 static void *tbl_db[TF_DIR_MAX];
29 static void *shadow_tbl_db[TF_DIR_MAX];
32 * Init flag, set on bind and cleared on unbind
37 * Shadow init flag, set on bind and cleared on unbind
39 static uint8_t shadow_init;
42 tf_tbl_bind(struct tf *tfp,
43 struct tf_tbl_cfg_parms *parms)
46 struct tf_rm_create_db_parms db_cfg = { 0 };
48 TF_CHECK_PARMS2(tfp, parms);
52 "Table DB already initialized\n");
56 db_cfg.num_elements = parms->num_elements;
57 db_cfg.module = TF_MODULE_TYPE_TABLE;
58 db_cfg.num_elements = parms->num_elements;
59 db_cfg.cfg = parms->cfg;
61 for (d = 0; d < TF_DIR_MAX; d++) {
63 db_cfg.alloc_cnt = parms->resources->tbl_cnt[d].cnt;
64 db_cfg.rm_db = &tbl_db[d];
65 rc = tf_rm_create_db(tfp, &db_cfg);
68 "%s: Table DB creation failed\n",
78 "Table Type - initialized\n");
84 tf_tbl_unbind(struct tf *tfp)
88 struct tf_rm_free_db_parms fparms = { 0 };
91 /* Bail if nothing has been initialized */
94 "No Table DBs created\n");
98 for (i = 0; i < TF_DIR_MAX; i++) {
100 fparms.rm_db = tbl_db[i];
101 rc = tf_rm_free_db(tfp, &fparms);
115 tf_tbl_alloc(struct tf *tfp __rte_unused,
116 struct tf_tbl_alloc_parms *parms)
120 struct tf_rm_allocate_parms aparms = { 0 };
122 TF_CHECK_PARMS2(tfp, parms);
126 "%s: No Table DBs created\n",
127 tf_dir_2_str(parms->dir));
131 /* Allocate requested element */
132 aparms.rm_db = tbl_db[parms->dir];
133 aparms.subtype = parms->type;
135 rc = tf_rm_allocate(&aparms);
138 "%s: Failed allocate, type:%d\n",
139 tf_dir_2_str(parms->dir),
150 tf_tbl_free(struct tf *tfp __rte_unused,
151 struct tf_tbl_free_parms *parms)
154 struct tf_rm_is_allocated_parms aparms = { 0 };
155 struct tf_rm_free_parms fparms = { 0 };
158 TF_CHECK_PARMS2(tfp, parms);
162 "%s: No Table DBs created\n",
163 tf_dir_2_str(parms->dir));
167 /* Check if element is in use */
168 aparms.rm_db = tbl_db[parms->dir];
169 aparms.subtype = parms->type;
170 aparms.index = parms->idx;
171 aparms.allocated = &allocated;
172 rc = tf_rm_is_allocated(&aparms);
176 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
178 "%s: Entry already free, type:%d, index:%d\n",
179 tf_dir_2_str(parms->dir),
184 /* Free requested element */
185 fparms.rm_db = tbl_db[parms->dir];
186 fparms.subtype = parms->type;
187 fparms.index = parms->idx;
188 rc = tf_rm_free(&fparms);
191 "%s: Free failed, type:%d, index:%d\n",
192 tf_dir_2_str(parms->dir),
202 tf_tbl_alloc_search(struct tf *tfp,
203 struct tf_tbl_alloc_search_parms *parms)
206 TF_CHECK_PARMS2(tfp, parms);
208 if (!shadow_init || !shadow_tbl_db[parms->dir]) {
209 TFP_DRV_LOG(ERR, "%s: Shadow TBL not initialized.\n",
210 tf_dir_2_str(parms->dir));
218 tf_tbl_set(struct tf *tfp,
219 struct tf_tbl_set_parms *parms)
224 struct tf_rm_is_allocated_parms aparms = { 0 };
225 struct tf_rm_get_hcapi_parms hparms = { 0 };
227 TF_CHECK_PARMS3(tfp, parms, parms->data);
231 "%s: No Table DBs created\n",
232 tf_dir_2_str(parms->dir));
236 /* Verify that the entry has been previously allocated */
237 aparms.rm_db = tbl_db[parms->dir];
238 aparms.subtype = parms->type;
239 aparms.index = parms->idx;
240 aparms.allocated = &allocated;
241 rc = tf_rm_is_allocated(&aparms);
245 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
247 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
248 tf_dir_2_str(parms->dir),
255 hparms.rm_db = tbl_db[parms->dir];
256 hparms.subtype = parms->type;
257 hparms.hcapi_type = &hcapi_type;
258 rc = tf_rm_get_hcapi_type(&hparms);
261 "%s, Failed type lookup, type:%d, rc:%s\n",
262 tf_dir_2_str(parms->dir),
268 rc = tf_msg_set_tbl_entry(tfp,
271 parms->data_sz_in_bytes,
276 "%s, Set failed, type:%d, rc:%s\n",
277 tf_dir_2_str(parms->dir),
287 tf_tbl_get(struct tf *tfp,
288 struct tf_tbl_get_parms *parms)
293 struct tf_rm_is_allocated_parms aparms = { 0 };
294 struct tf_rm_get_hcapi_parms hparms = { 0 };
296 TF_CHECK_PARMS3(tfp, parms, parms->data);
300 "%s: No Table DBs created\n",
301 tf_dir_2_str(parms->dir));
305 /* Verify that the entry has been previously allocated */
306 aparms.rm_db = tbl_db[parms->dir];
307 aparms.subtype = parms->type;
308 aparms.index = parms->idx;
309 aparms.allocated = &allocated;
310 rc = tf_rm_is_allocated(&aparms);
314 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
316 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
317 tf_dir_2_str(parms->dir),
324 hparms.rm_db = tbl_db[parms->dir];
325 hparms.subtype = parms->type;
326 hparms.hcapi_type = &hcapi_type;
327 rc = tf_rm_get_hcapi_type(&hparms);
330 "%s, Failed type lookup, type:%d, rc:%s\n",
331 tf_dir_2_str(parms->dir),
338 rc = tf_msg_get_tbl_entry(tfp,
341 parms->data_sz_in_bytes,
346 "%s, Get failed, type:%d, rc:%s\n",
347 tf_dir_2_str(parms->dir),
357 tf_tbl_bulk_get(struct tf *tfp,
358 struct tf_tbl_get_bulk_parms *parms)
362 struct tf_rm_get_hcapi_parms hparms = { 0 };
363 struct tf_rm_check_indexes_in_range_parms cparms = { 0 };
365 TF_CHECK_PARMS2(tfp, parms);
369 "%s: No Table DBs created\n",
370 tf_dir_2_str(parms->dir));
375 /* Verify that the entries are in the range of reserved resources. */
376 cparms.rm_db = tbl_db[parms->dir];
377 cparms.subtype = parms->type;
378 cparms.starting_index = parms->starting_idx;
379 cparms.num_entries = parms->num_entries;
381 rc = tf_rm_check_indexes_in_range(&cparms);
384 "%s, Invalid or %d index starting from %d"
385 " not in range, type:%d",
386 tf_dir_2_str(parms->dir),
393 hparms.rm_db = tbl_db[parms->dir];
394 hparms.subtype = parms->type;
395 hparms.hcapi_type = &hcapi_type;
396 rc = tf_rm_get_hcapi_type(&hparms);
399 "%s, Failed type lookup, type:%d, rc:%s\n",
400 tf_dir_2_str(parms->dir),
406 /* Get the entries */
407 rc = tf_msg_bulk_get_tbl_entry(tfp,
412 parms->entry_sz_in_bytes,
413 parms->physical_mem_addr);
416 "%s, Bulk get failed, type:%d, rc:%s\n",
417 tf_dir_2_str(parms->dir),