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",
78 "Table Type - initialized\n");
84 tf_tbl_unbind(struct tf *tfp)
88 struct tf_rm_free_db_parms fparms = { 0 };
92 /* Bail if nothing has been initialized */
95 "No Table DBs created\n");
99 for (i = 0; i < TF_DIR_MAX; i++) {
101 fparms.rm_db = tbl_db[i];
102 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.db_index = 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.db_index = 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),
185 /* Free requested element */
186 fparms.rm_db = tbl_db[parms->dir];
187 fparms.db_index = parms->type;
188 fparms.index = parms->idx;
189 rc = tf_rm_free(&fparms);
192 "%s: Free failed, type:%d, index:%d\n",
193 tf_dir_2_str(parms->dir),
203 tf_tbl_alloc_search(struct tf *tfp __rte_unused,
204 struct tf_tbl_alloc_search_parms *parms __rte_unused)
210 tf_tbl_set(struct tf *tfp,
211 struct tf_tbl_set_parms *parms)
216 struct tf_rm_is_allocated_parms aparms = { 0 };
217 struct tf_rm_get_hcapi_parms hparms = { 0 };
219 TF_CHECK_PARMS3(tfp, parms, parms->data);
223 "%s: No Table DBs created\n",
224 tf_dir_2_str(parms->dir));
228 /* Verify that the entry has been previously allocated */
229 aparms.rm_db = tbl_db[parms->dir];
230 aparms.db_index = parms->type;
231 aparms.index = parms->idx;
232 aparms.allocated = &allocated;
233 rc = tf_rm_is_allocated(&aparms);
237 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
239 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
240 tf_dir_2_str(parms->dir),
247 hparms.rm_db = tbl_db[parms->dir];
248 hparms.db_index = parms->type;
249 hparms.hcapi_type = &hcapi_type;
250 rc = tf_rm_get_hcapi_type(&hparms);
253 "%s, Failed type lookup, type:%d, rc:%s\n",
254 tf_dir_2_str(parms->dir),
260 rc = tf_msg_set_tbl_entry(tfp,
263 parms->data_sz_in_bytes,
268 "%s, Set failed, type:%d, rc:%s\n",
269 tf_dir_2_str(parms->dir),
279 tf_tbl_get(struct tf *tfp,
280 struct tf_tbl_get_parms *parms)
285 struct tf_rm_is_allocated_parms aparms = { 0 };
286 struct tf_rm_get_hcapi_parms hparms = { 0 };
288 TF_CHECK_PARMS3(tfp, parms, parms->data);
292 "%s: No Table DBs created\n",
293 tf_dir_2_str(parms->dir));
297 /* Verify that the entry has been previously allocated */
298 aparms.rm_db = tbl_db[parms->dir];
299 aparms.db_index = parms->type;
300 aparms.index = parms->idx;
301 aparms.allocated = &allocated;
302 rc = tf_rm_is_allocated(&aparms);
306 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
308 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
309 tf_dir_2_str(parms->dir),
316 hparms.rm_db = tbl_db[parms->dir];
317 hparms.db_index = parms->type;
318 hparms.hcapi_type = &hcapi_type;
319 rc = tf_rm_get_hcapi_type(&hparms);
322 "%s, Failed type lookup, type:%d, rc:%s\n",
323 tf_dir_2_str(parms->dir),
330 rc = tf_msg_get_tbl_entry(tfp,
333 parms->data_sz_in_bytes,
338 "%s, Get failed, type:%d, rc:%s\n",
339 tf_dir_2_str(parms->dir),
349 tf_tbl_bulk_get(struct tf *tfp,
350 struct tf_tbl_get_bulk_parms *parms)
357 struct tf_rm_is_allocated_parms aparms = { 0 };
358 struct tf_rm_get_hcapi_parms hparms = { 0 };
360 TF_CHECK_PARMS2(tfp, parms);
364 "%s: No Table DBs created\n",
365 tf_dir_2_str(parms->dir));
369 /* Verify that the entries has been previously allocated */
370 aparms.rm_db = tbl_db[parms->dir];
371 aparms.db_index = parms->type;
372 aparms.allocated = &allocated;
373 idx = parms->starting_idx;
374 for (i = 0; i < parms->num_entries; i++) {
376 rc = tf_rm_is_allocated(&aparms);
380 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
382 "%s, Invalid or not allocated index, type:%d, idx:%d\n",
383 tf_dir_2_str(parms->dir),
391 hparms.rm_db = tbl_db[parms->dir];
392 hparms.db_index = parms->type;
393 hparms.hcapi_type = &hcapi_type;
394 rc = tf_rm_get_hcapi_type(&hparms);
397 "%s, Failed type lookup, type:%d, rc:%s\n",
398 tf_dir_2_str(parms->dir),
404 /* Get the entries */
405 rc = tf_msg_bulk_get_tbl_entry(tfp,
410 parms->entry_sz_in_bytes,
411 parms->physical_mem_addr);
414 "%s, Bulk get failed, type:%d, rc:%s\n",
415 tf_dir_2_str(parms->dir),