1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
7 #include <rte_common.h>
10 #include "tf_common.h"
12 #include "tf_rm_new.h"
13 #include "tf_device.h"
15 #include "tf_session.h"
23 static void *tcam_db[TF_DIR_MAX];
28 /* static void *shadow_tcam_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_tcam_bind(struct tf *tfp,
42 struct tf_tcam_cfg_parms *parms)
46 struct tf_rm_create_db_parms db_cfg = { 0 };
48 TF_CHECK_PARMS2(tfp, parms);
52 "TCAM already initialized\n");
56 db_cfg.type = TF_DEVICE_MODULE_TYPE_TCAM;
57 db_cfg.num_elements = parms->num_elements;
58 db_cfg.cfg = parms->cfg;
60 for (i = 0; i < TF_DIR_MAX; i++) {
62 db_cfg.alloc_cnt = parms->resources->tcam_cnt[i].cnt;
63 db_cfg.rm_db = &tcam_db[i];
64 rc = tf_rm_create_db(tfp, &db_cfg);
67 "%s: TCAM DB creation failed\n",
75 printf("TCAM - initialized\n");
81 tf_tcam_unbind(struct tf *tfp)
85 struct tf_rm_free_db_parms fparms = { 0 };
89 /* Bail if nothing has been initialized done silent as to
90 * allow for creation cleanup.
95 for (i = 0; i < TF_DIR_MAX; i++) {
97 fparms.rm_db = tcam_db[i];
98 rc = tf_rm_free_db(tfp, &fparms);
111 tf_tcam_alloc(struct tf *tfp,
112 struct tf_tcam_alloc_parms *parms)
115 struct tf_session *tfs;
116 struct tf_dev_info *dev;
117 struct tf_rm_allocate_parms aparms = { 0 };
118 uint16_t num_slice_per_row = 1;
120 TF_CHECK_PARMS2(tfp, parms);
124 "%s: No TCAM DBs created\n",
125 tf_dir_2_str(parms->dir));
129 /* Retrieve the session information */
130 rc = tf_session_get_session(tfp, &tfs);
134 /* Retrieve the device information */
135 rc = tf_session_get_device(tfs, &dev);
139 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
142 "%s: Operation not supported, rc:%s\n",
143 tf_dir_2_str(parms->dir),
148 /* Need to retrieve row size etc */
149 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
156 /* Allocate requested element */
157 aparms.rm_db = tcam_db[parms->dir];
158 aparms.db_index = parms->type;
159 aparms.priority = parms->priority;
160 aparms.index = (uint32_t *)&parms->idx;
161 rc = tf_rm_allocate(&aparms);
164 "%s: Failed tcam, type:%d\n",
165 tf_dir_2_str(parms->dir),
170 parms->idx *= num_slice_per_row;
176 tf_tcam_free(struct tf *tfp,
177 struct tf_tcam_free_parms *parms)
180 struct tf_session *tfs;
181 struct tf_dev_info *dev;
182 struct tf_rm_is_allocated_parms aparms = { 0 };
183 struct tf_rm_free_parms fparms = { 0 };
184 struct tf_rm_get_hcapi_parms hparms = { 0 };
185 uint16_t num_slice_per_row = 1;
188 TF_CHECK_PARMS2(tfp, parms);
192 "%s: No TCAM DBs created\n",
193 tf_dir_2_str(parms->dir));
197 /* Retrieve the session information */
198 rc = tf_session_get_session(tfp, &tfs);
202 /* Retrieve the device information */
203 rc = tf_session_get_device(tfs, &dev);
207 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
210 "%s: Operation not supported, rc:%s\n",
211 tf_dir_2_str(parms->dir),
216 /* Need to retrieve row size etc */
217 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
224 /* Check if element is in use */
225 aparms.rm_db = tcam_db[parms->dir];
226 aparms.db_index = parms->type;
227 aparms.index = parms->idx / num_slice_per_row;
228 aparms.allocated = &allocated;
229 rc = tf_rm_is_allocated(&aparms);
235 "%s: Entry already free, type:%d, index:%d\n",
236 tf_dir_2_str(parms->dir),
242 /* Free requested element */
243 fparms.rm_db = tcam_db[parms->dir];
244 fparms.db_index = parms->type;
245 fparms.index = parms->idx / num_slice_per_row;
246 rc = tf_rm_free(&fparms);
249 "%s: Free failed, type:%d, index:%d\n",
250 tf_dir_2_str(parms->dir),
256 /* Convert TF type to HCAPI RM type */
257 hparms.rm_db = tcam_db[parms->dir];
258 hparms.db_index = parms->type;
259 hparms.hcapi_type = &parms->hcapi_type;
261 rc = tf_rm_get_hcapi_type(&hparms);
265 rc = tf_msg_tcam_entry_free(tfp, parms);
268 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
269 tf_dir_2_str(parms->dir),
270 tf_tcam_tbl_2_str(parms->type),
279 tf_tcam_alloc_search(struct tf *tfp __rte_unused,
280 struct tf_tcam_alloc_search_parms *parms __rte_unused)
286 tf_tcam_set(struct tf *tfp __rte_unused,
287 struct tf_tcam_set_parms *parms __rte_unused)
290 struct tf_session *tfs;
291 struct tf_dev_info *dev;
292 struct tf_rm_is_allocated_parms aparms = { 0 };
293 struct tf_rm_get_hcapi_parms hparms = { 0 };
294 uint16_t num_slice_per_row = 1;
297 TF_CHECK_PARMS2(tfp, parms);
301 "%s: No TCAM DBs created\n",
302 tf_dir_2_str(parms->dir));
306 /* Retrieve the session information */
307 rc = tf_session_get_session(tfp, &tfs);
311 /* Retrieve the device information */
312 rc = tf_session_get_device(tfs, &dev);
316 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
319 "%s: Operation not supported, rc:%s\n",
320 tf_dir_2_str(parms->dir),
325 /* Need to retrieve row size etc */
326 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
333 /* Check if element is in use */
334 aparms.rm_db = tcam_db[parms->dir];
335 aparms.db_index = parms->type;
336 aparms.index = parms->idx / num_slice_per_row;
337 aparms.allocated = &allocated;
338 rc = tf_rm_is_allocated(&aparms);
344 "%s: Entry is not allocated, type:%d, index:%d\n",
345 tf_dir_2_str(parms->dir),
351 /* Convert TF type to HCAPI RM type */
352 hparms.rm_db = tcam_db[parms->dir];
353 hparms.db_index = parms->type;
354 hparms.hcapi_type = &parms->hcapi_type;
356 rc = tf_rm_get_hcapi_type(&hparms);
360 rc = tf_msg_tcam_entry_set(tfp, parms);
363 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
364 tf_dir_2_str(parms->dir),
365 tf_tcam_tbl_2_str(parms->type),
374 tf_tcam_get(struct tf *tfp __rte_unused,
375 struct tf_tcam_get_parms *parms __rte_unused)