1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
6 #include <rte_common.h>
8 #include "tf_identifier.h"
9 #include "tf_shadow_identifier.h"
10 #include "tf_common.h"
20 static void *ident_db[TF_DIR_MAX];
23 * Init flag, set on bind and cleared on unbind
28 * Identifier shadow DBs.
30 static void *ident_shadow_db[TF_DIR_MAX];
33 * Shadow DB Init flag, set on bind and cleared on unbind
35 static uint8_t shadow_init;
38 tf_ident_bind(struct tf *tfp,
39 struct tf_ident_cfg_parms *parms)
43 struct tf_rm_create_db_parms db_cfg = { 0 };
44 struct tf_shadow_ident_cfg_parms shadow_cfg = { 0 };
45 struct tf_shadow_ident_create_db_parms shadow_cdb = { 0 };
47 TF_CHECK_PARMS2(tfp, parms);
51 "Identifier DB already initialized\n");
55 db_cfg.type = TF_DEVICE_MODULE_TYPE_IDENTIFIER;
56 db_cfg.num_elements = parms->num_elements;
57 db_cfg.cfg = parms->cfg;
59 for (i = 0; i < TF_DIR_MAX; i++) {
61 db_cfg.alloc_cnt = parms->resources->ident_cnt[i].cnt;
62 db_cfg.rm_db = &ident_db[i];
63 rc = tf_rm_create_db(tfp, &db_cfg);
66 "%s: Identifier DB creation failed\n",
72 if (parms->shadow_copy) {
73 shadow_cfg.alloc_cnt =
74 parms->resources->ident_cnt[i].cnt;
75 shadow_cdb.num_elements = parms->num_elements;
76 shadow_cdb.tf_shadow_ident_db = &ident_shadow_db[i];
77 shadow_cdb.cfg = &shadow_cfg;
78 rc = tf_shadow_ident_create_db(&shadow_cdb);
81 "%s: Ident shadow DB creation failed\n",
93 "Identifier - initialized\n");
99 tf_ident_unbind(struct tf *tfp)
103 struct tf_rm_free_db_parms fparms = { 0 };
104 struct tf_shadow_ident_free_db_parms sparms = { 0 };
106 TF_CHECK_PARMS1(tfp);
108 /* Bail if nothing has been initialized */
111 "No Identifier DBs created\n");
115 for (i = 0; i < TF_DIR_MAX; i++) {
117 fparms.rm_db = ident_db[i];
118 rc = tf_rm_free_db(tfp, &fparms);
121 "rm free failed on unbind\n");
124 sparms.tf_shadow_ident_db = ident_shadow_db[i];
125 rc = tf_shadow_ident_free_db(&sparms);
127 /* TODO: If there are failures on unbind we
128 * really just have to try until all DBs are
129 * attempted to be cleared.
132 ident_shadow_db[i] = NULL;
144 tf_ident_alloc(struct tf *tfp __rte_unused,
145 struct tf_ident_alloc_parms *parms)
150 struct tf_rm_allocate_parms aparms = { 0 };
151 struct tf_shadow_ident_insert_parms iparms = { 0 };
153 TF_CHECK_PARMS2(tfp, parms);
157 "%s: No Identifier DBs created\n",
158 tf_dir_2_str(parms->dir));
162 /* Allocate requested element */
163 aparms.rm_db = ident_db[parms->dir];
164 aparms.db_index = parms->type;
166 aparms.base_index = &base_id;
167 rc = tf_rm_allocate(&aparms);
170 "%s: Failed allocate, type:%d\n",
171 tf_dir_2_str(parms->dir),
177 iparms.tf_shadow_ident_db = ident_shadow_db[parms->dir];
178 iparms.type = parms->type;
181 rc = tf_shadow_ident_insert(&iparms);
184 "%s: Failed insert shadow DB, type:%d\n",
185 tf_dir_2_str(parms->dir),
197 tf_ident_free(struct tf *tfp __rte_unused,
198 struct tf_ident_free_parms *parms)
201 struct tf_rm_is_allocated_parms aparms = { 0 };
202 struct tf_rm_free_parms fparms = { 0 };
203 struct tf_shadow_ident_remove_parms rparms = { 0 };
207 TF_CHECK_PARMS2(tfp, parms);
211 "%s: No Identifier DBs created\n",
212 tf_dir_2_str(parms->dir));
216 /* Check if element is in use */
217 aparms.rm_db = ident_db[parms->dir];
218 aparms.db_index = parms->type;
219 aparms.index = parms->id;
220 aparms.base_index = &base_id;
221 aparms.allocated = &allocated;
222 rc = tf_rm_is_allocated(&aparms);
226 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
228 "%s: Entry already free, type:%d, index:%d\n",
229 tf_dir_2_str(parms->dir),
236 rparms.tf_shadow_ident_db = ident_shadow_db[parms->dir];
237 rparms.type = parms->type;
239 rparms.ref_cnt = parms->ref_cnt;
241 rc = tf_shadow_ident_remove(&rparms);
244 "%s: ref_cnt was 0 in shadow DB,"
245 " type:%d, index:%d\n",
246 tf_dir_2_str(parms->dir),
252 if (*rparms.ref_cnt > 0)
256 /* Free requested element */
257 fparms.rm_db = ident_db[parms->dir];
258 fparms.db_index = parms->type;
259 fparms.index = parms->id;
260 rc = tf_rm_free(&fparms);
263 "%s: Free failed, type:%d, index:%d\n",
264 tf_dir_2_str(parms->dir),
274 tf_ident_search(struct tf *tfp __rte_unused,
275 struct tf_ident_search_parms *parms)
278 struct tf_rm_is_allocated_parms aparms = { 0 };
279 struct tf_shadow_ident_search_parms sparms = { 0 };
283 TF_CHECK_PARMS2(tfp, parms);
287 "%s: No Identifier DBs created\n",
288 tf_dir_2_str(parms->dir));
294 "%s: Identifier Shadow copy is not enabled\n",
295 tf_dir_2_str(parms->dir));
299 /* Check if element is in use */
300 aparms.rm_db = ident_db[parms->dir];
301 aparms.db_index = parms->type;
302 aparms.index = parms->search_id;
303 aparms.base_index = &base_id;
304 aparms.allocated = &allocated;
305 rc = tf_rm_is_allocated(&aparms);
309 if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
311 "%s: Entry not allocated, type:%d, index:%d\n",
312 tf_dir_2_str(parms->dir),
318 sparms.tf_shadow_ident_db = ident_shadow_db[parms->dir];
319 sparms.type = parms->type;
320 sparms.search_id = base_id;
321 sparms.hit = parms->hit;
322 sparms.ref_cnt = parms->ref_cnt;
324 rc = tf_shadow_ident_search(&sparms);
327 "%s: Failed search shadow DB, type:%d\n",
328 tf_dir_2_str(parms->dir),