1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
7 #include <rte_common.h>
10 #include "tf_common.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 DB 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 */
92 "No TCAM DBs created\n");
96 for (i = 0; i < TF_DIR_MAX; i++) {
98 fparms.rm_db = tcam_db[i];
99 rc = tf_rm_free_db(tfp, &fparms);
112 tf_tcam_alloc(struct tf *tfp,
113 struct tf_tcam_alloc_parms *parms)
116 struct tf_session *tfs;
117 struct tf_dev_info *dev;
118 struct tf_rm_allocate_parms aparms = { 0 };
119 uint16_t num_slice_per_row = 1;
121 TF_CHECK_PARMS2(tfp, parms);
125 "%s: No TCAM DBs created\n",
126 tf_dir_2_str(parms->dir));
130 /* Retrieve the session information */
131 rc = tf_session_get_session(tfp, &tfs);
135 /* Retrieve the device information */
136 rc = tf_session_get_device(tfs, &dev);
140 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
143 "%s: Operation not supported, rc:%s\n",
144 tf_dir_2_str(parms->dir),
149 /* Need to retrieve row size etc */
150 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
157 /* Allocate requested element */
158 aparms.rm_db = tcam_db[parms->dir];
159 aparms.db_index = parms->type;
160 aparms.priority = parms->priority;
161 aparms.index = (uint32_t *)&parms->idx;
162 rc = tf_rm_allocate(&aparms);
165 "%s: Failed tcam, type:%d\n",
166 tf_dir_2_str(parms->dir),
171 parms->idx *= num_slice_per_row;
177 tf_tcam_free(struct tf *tfp,
178 struct tf_tcam_free_parms *parms)
181 struct tf_session *tfs;
182 struct tf_dev_info *dev;
183 struct tf_rm_is_allocated_parms aparms = { 0 };
184 struct tf_rm_free_parms fparms = { 0 };
185 struct tf_rm_get_hcapi_parms hparms = { 0 };
186 uint16_t num_slice_per_row = 1;
189 TF_CHECK_PARMS2(tfp, parms);
193 "%s: No TCAM DBs created\n",
194 tf_dir_2_str(parms->dir));
198 /* Retrieve the session information */
199 rc = tf_session_get_session(tfp, &tfs);
203 /* Retrieve the device information */
204 rc = tf_session_get_device(tfs, &dev);
208 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
211 "%s: Operation not supported, rc:%s\n",
212 tf_dir_2_str(parms->dir),
217 /* Need to retrieve row size etc */
218 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
225 /* Check if element is in use */
226 aparms.rm_db = tcam_db[parms->dir];
227 aparms.db_index = parms->type;
228 aparms.index = parms->idx / num_slice_per_row;
229 aparms.allocated = &allocated;
230 rc = tf_rm_is_allocated(&aparms);
236 "%s: Entry already free, type:%d, index:%d\n",
237 tf_dir_2_str(parms->dir),
243 /* Free requested element */
244 fparms.rm_db = tcam_db[parms->dir];
245 fparms.db_index = parms->type;
246 fparms.index = parms->idx / num_slice_per_row;
247 rc = tf_rm_free(&fparms);
250 "%s: Free failed, type:%d, index:%d\n",
251 tf_dir_2_str(parms->dir),
257 /* Convert TF type to HCAPI RM type */
258 hparms.rm_db = tcam_db[parms->dir];
259 hparms.db_index = parms->type;
260 hparms.hcapi_type = &parms->hcapi_type;
262 rc = tf_rm_get_hcapi_type(&hparms);
266 rc = tf_msg_tcam_entry_free(tfp, parms);
269 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
270 tf_dir_2_str(parms->dir),
271 tf_tcam_tbl_2_str(parms->type),
280 tf_tcam_alloc_search(struct tf *tfp __rte_unused,
281 struct tf_tcam_alloc_search_parms *parms __rte_unused)
287 tf_tcam_set(struct tf *tfp __rte_unused,
288 struct tf_tcam_set_parms *parms __rte_unused)
291 struct tf_session *tfs;
292 struct tf_dev_info *dev;
293 struct tf_rm_is_allocated_parms aparms = { 0 };
294 struct tf_rm_get_hcapi_parms hparms = { 0 };
295 uint16_t num_slice_per_row = 1;
298 TF_CHECK_PARMS2(tfp, parms);
302 "%s: No TCAM DBs created\n",
303 tf_dir_2_str(parms->dir));
307 /* Retrieve the session information */
308 rc = tf_session_get_session(tfp, &tfs);
312 /* Retrieve the device information */
313 rc = tf_session_get_device(tfs, &dev);
317 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
320 "%s: Operation not supported, rc:%s\n",
321 tf_dir_2_str(parms->dir),
326 /* Need to retrieve row size etc */
327 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
334 /* Check if element is in use */
335 aparms.rm_db = tcam_db[parms->dir];
336 aparms.db_index = parms->type;
337 aparms.index = parms->idx / num_slice_per_row;
338 aparms.allocated = &allocated;
339 rc = tf_rm_is_allocated(&aparms);
345 "%s: Entry is not allocated, type:%d, index:%d\n",
346 tf_dir_2_str(parms->dir),
352 /* Convert TF type to HCAPI RM type */
353 hparms.rm_db = tcam_db[parms->dir];
354 hparms.db_index = parms->type;
355 hparms.hcapi_type = &parms->hcapi_type;
357 rc = tf_rm_get_hcapi_type(&hparms);
361 rc = tf_msg_tcam_entry_set(tfp, parms);
364 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
365 tf_dir_2_str(parms->dir),
366 tf_tcam_tbl_2_str(parms->type),
375 tf_tcam_get(struct tf *tfp __rte_unused,
376 struct tf_tcam_get_parms *parms __rte_unused)