1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
6 #include <rte_common.h>
8 #include "tf_identifier.h"
19 static void *ident_db[TF_DIR_MAX];
22 * Init flag, set on bind and cleared on unbind
27 tf_ident_bind(struct tf *tfp,
28 struct tf_ident_cfg_parms *parms)
32 struct tf_rm_create_db_parms db_cfg = { 0 };
34 TF_CHECK_PARMS2(tfp, parms);
38 "Identifier DB already initialized\n");
42 db_cfg.type = TF_DEVICE_MODULE_TYPE_IDENTIFIER;
43 db_cfg.num_elements = parms->num_elements;
44 db_cfg.cfg = parms->cfg;
46 for (i = 0; i < TF_DIR_MAX; i++) {
48 db_cfg.alloc_cnt = parms->resources->ident_cnt[i].cnt;
49 db_cfg.rm_db = &ident_db[i];
50 rc = tf_rm_create_db(tfp, &db_cfg);
53 "%s: Identifier DB creation failed\n",
63 "Identifier - initialized\n");
69 tf_ident_unbind(struct tf *tfp)
73 struct tf_rm_free_db_parms fparms = { 0 };
77 /* Bail if nothing has been initialized */
80 "No Identifier DBs created\n");
84 for (i = 0; i < TF_DIR_MAX; i++) {
86 fparms.rm_db = ident_db[i];
87 rc = tf_rm_free_db(tfp, &fparms);
90 "rm free failed on unbind\n");
102 tf_ident_alloc(struct tf *tfp __rte_unused,
103 struct tf_ident_alloc_parms *parms)
107 struct tf_rm_allocate_parms aparms = { 0 };
109 TF_CHECK_PARMS2(tfp, parms);
113 "%s: No Identifier DBs created\n",
114 tf_dir_2_str(parms->dir));
118 /* Allocate requested element */
119 aparms.rm_db = ident_db[parms->dir];
120 aparms.db_index = parms->type;
122 rc = tf_rm_allocate(&aparms);
125 "%s: Failed allocate, type:%d\n",
126 tf_dir_2_str(parms->dir),
137 tf_ident_free(struct tf *tfp __rte_unused,
138 struct tf_ident_free_parms *parms)
141 struct tf_rm_is_allocated_parms aparms = { 0 };
142 struct tf_rm_free_parms fparms = { 0 };
145 TF_CHECK_PARMS2(tfp, parms);
149 "%s: No Identifier DBs created\n",
150 tf_dir_2_str(parms->dir));
154 /* Check if element is in use */
155 aparms.rm_db = ident_db[parms->dir];
156 aparms.db_index = parms->type;
157 aparms.index = parms->id;
158 aparms.allocated = &allocated;
159 rc = tf_rm_is_allocated(&aparms);
163 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
165 "%s: Entry already free, type:%d, index:%d\n",
166 tf_dir_2_str(parms->dir),
172 /* Free requested element */
173 fparms.rm_db = ident_db[parms->dir];
174 fparms.db_index = parms->type;
175 fparms.index = parms->id;
176 rc = tf_rm_free(&fparms);
179 "%s: Free failed, type:%d, index:%d\n",
180 tf_dir_2_str(parms->dir),