1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
6 /* Truflow Table APIs and supporting code */
8 #include <rte_common.h>
11 #include "tf_common.h"
23 static void *tbl_db[TF_DIR_MAX];
28 /* static void *shadow_tbl_db[TF_DIR_MAX]; */
31 * Init flag, set on bind and cleared on unbind
36 * Shadow init flag, set on bind and cleared on unbind
38 /* static uint8_t shadow_init; */
41 tf_tbl_bind(struct tf *tfp,
42 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.type = TF_DEVICE_MODULE_TYPE_TABLE;
58 db_cfg.num_elements = parms->num_elements;
59 db_cfg.cfg = parms->cfg;
61 for (i = 0; i < TF_DIR_MAX; i++) {
63 db_cfg.alloc_cnt = parms->resources->tbl_cnt[i].cnt;
64 db_cfg.rm_db = &tbl_db[i];
65 rc = tf_rm_create_db(tfp, &db_cfg);
68 "%s: Table DB creation failed\n",
77 printf("Table Type - initialized\n");
83 tf_tbl_unbind(struct tf *tfp)
87 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);
114 tf_tbl_alloc(struct tf *tfp __rte_unused,
115 struct tf_tbl_alloc_parms *parms)
119 struct tf_rm_allocate_parms aparms = { 0 };
121 TF_CHECK_PARMS2(tfp, parms);
125 "%s: No Table DBs created\n",
126 tf_dir_2_str(parms->dir));
130 /* Allocate requested element */
131 aparms.rm_db = tbl_db[parms->dir];
132 aparms.db_index = parms->type;
134 rc = tf_rm_allocate(&aparms);
137 "%s: Failed allocate, type:%d\n",
138 tf_dir_2_str(parms->dir),
149 tf_tbl_free(struct tf *tfp __rte_unused,
150 struct tf_tbl_free_parms *parms)
153 struct tf_rm_is_allocated_parms aparms = { 0 };
154 struct tf_rm_free_parms fparms = { 0 };
157 TF_CHECK_PARMS2(tfp, parms);
161 "%s: No Table DBs created\n",
162 tf_dir_2_str(parms->dir));
166 /* Check if element is in use */
167 aparms.rm_db = tbl_db[parms->dir];
168 aparms.db_index = parms->type;
169 aparms.index = parms->idx;
170 aparms.allocated = &allocated;
171 rc = tf_rm_is_allocated(&aparms);
175 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
177 "%s: Entry already free, type:%d, index:%d\n",
178 tf_dir_2_str(parms->dir),
184 /* Free requested element */
185 fparms.rm_db = tbl_db[parms->dir];
186 fparms.db_index = 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 __rte_unused,
203 struct tf_tbl_alloc_search_parms *parms __rte_unused)
209 tf_tbl_set(struct tf *tfp,
210 struct tf_tbl_set_parms *parms)
215 struct tf_rm_is_allocated_parms aparms = { 0 };
216 struct tf_rm_get_hcapi_parms hparms = { 0 };
218 TF_CHECK_PARMS3(tfp, parms, parms->data);
222 "%s: No Table DBs created\n",
223 tf_dir_2_str(parms->dir));
227 /* Verify that the entry has been previously allocated */
228 aparms.rm_db = tbl_db[parms->dir];
229 aparms.db_index = parms->type;
230 aparms.index = parms->idx;
231 aparms.allocated = &allocated;
232 rc = tf_rm_is_allocated(&aparms);
236 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
238 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
239 tf_dir_2_str(parms->dir),
246 hparms.rm_db = tbl_db[parms->dir];
247 hparms.db_index = parms->type;
248 hparms.hcapi_type = &hcapi_type;
249 rc = tf_rm_get_hcapi_type(&hparms);
252 "%s, Failed type lookup, type:%d, rc:%s\n",
253 tf_dir_2_str(parms->dir),
259 rc = tf_msg_set_tbl_entry(tfp,
262 parms->data_sz_in_bytes,
267 "%s, Set failed, type:%d, rc:%s\n",
268 tf_dir_2_str(parms->dir),
277 tf_tbl_get(struct tf *tfp,
278 struct tf_tbl_get_parms *parms)
283 struct tf_rm_is_allocated_parms aparms = { 0 };
284 struct tf_rm_get_hcapi_parms hparms = { 0 };
286 TF_CHECK_PARMS3(tfp, parms, parms->data);
290 "%s: No Table DBs created\n",
291 tf_dir_2_str(parms->dir));
295 /* Verify that the entry has been previously allocated */
296 aparms.rm_db = tbl_db[parms->dir];
297 aparms.db_index = parms->type;
298 aparms.index = parms->idx;
299 aparms.allocated = &allocated;
300 rc = tf_rm_is_allocated(&aparms);
304 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
306 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
307 tf_dir_2_str(parms->dir),
314 hparms.rm_db = tbl_db[parms->dir];
315 hparms.db_index = parms->type;
316 hparms.hcapi_type = &hcapi_type;
317 rc = tf_rm_get_hcapi_type(&hparms);
320 "%s, Failed type lookup, type:%d, rc:%s\n",
321 tf_dir_2_str(parms->dir),
328 rc = tf_msg_get_tbl_entry(tfp,
331 parms->data_sz_in_bytes,
336 "%s, Get failed, type:%d, rc:%s\n",
337 tf_dir_2_str(parms->dir),
346 tf_tbl_bulk_get(struct tf *tfp,
347 struct tf_tbl_get_bulk_parms *parms)
354 struct tf_rm_is_allocated_parms aparms = { 0 };
355 struct tf_rm_get_hcapi_parms hparms = { 0 };
357 TF_CHECK_PARMS2(tfp, parms);
361 "%s: No Table DBs created\n",
362 tf_dir_2_str(parms->dir));
366 /* Verify that the entries has been previously allocated */
367 aparms.rm_db = tbl_db[parms->dir];
368 aparms.db_index = parms->type;
369 aparms.allocated = &allocated;
370 idx = parms->starting_idx;
371 for (i = 0; i < parms->num_entries; i++) {
373 rc = tf_rm_is_allocated(&aparms);
377 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
379 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
380 tf_dir_2_str(parms->dir),
388 hparms.rm_db = tbl_db[parms->dir];
389 hparms.db_index = parms->type;
390 hparms.hcapi_type = &hcapi_type;
391 rc = tf_rm_get_hcapi_type(&hparms);
394 "%s, Failed type lookup, type:%d, rc:%s\n",
395 tf_dir_2_str(parms->dir),
401 /* Get the entries */
402 rc = tf_msg_bulk_get_tbl_entry(tfp,
407 parms->entry_sz_in_bytes,
408 parms->physical_mem_addr);
411 "%s, Bulk get failed, type:%d, rc:%s\n",
412 tf_dir_2_str(parms->dir),