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.num_elements = parms->num_elements;
57 db_cfg.type = TF_DEVICE_MODULE_TYPE_TCAM;
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->tcam_cnt[i].cnt;
64 db_cfg.rm_db = &tcam_db[i];
65 rc = tf_rm_create_db(tfp, &db_cfg);
68 "%s: TCAM DB creation failed\n",
76 printf("TCAM - initialized\n");
82 tf_tcam_unbind(struct tf *tfp)
86 struct tf_rm_free_db_parms fparms = { 0 };
90 /* Bail if nothing has been initialized done silent as to
91 * allow for creation cleanup.
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 __rte_unused,
178 struct tf_tcam_free_parms *parms __rte_unused)
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 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 rc = tf_msg_tcam_entry_free(tfp, parms);
259 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
260 tf_dir_2_str(parms->dir),
261 tf_tcam_tbl_2_str(parms->type),
270 tf_tcam_alloc_search(struct tf *tfp __rte_unused,
271 struct tf_tcam_alloc_search_parms *parms __rte_unused)
277 tf_tcam_set(struct tf *tfp __rte_unused,
278 struct tf_tcam_set_parms *parms __rte_unused)
281 struct tf_session *tfs;
282 struct tf_dev_info *dev;
283 struct tf_rm_is_allocated_parms aparms = { 0 };
284 uint16_t num_slice_per_row = 1;
287 TF_CHECK_PARMS2(tfp, parms);
291 "%s: No TCAM DBs created\n",
292 tf_dir_2_str(parms->dir));
296 /* Retrieve the session information */
297 rc = tf_session_get_session(tfp, &tfs);
301 /* Retrieve the device information */
302 rc = tf_session_get_device(tfs, &dev);
306 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
309 "%s: Operation not supported, rc:%s\n",
310 tf_dir_2_str(parms->dir),
315 /* Need to retrieve row size etc */
316 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
323 /* Check if element is in use */
324 aparms.rm_db = tcam_db[parms->dir];
325 aparms.db_index = parms->type;
326 aparms.index = parms->idx / num_slice_per_row;
327 aparms.allocated = &allocated;
328 rc = tf_rm_is_allocated(&aparms);
334 "%s: Entry is not allocated, type:%d, index:%d\n",
335 tf_dir_2_str(parms->dir),
341 rc = tf_msg_tcam_entry_set(tfp, parms);
344 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
345 tf_dir_2_str(parms->dir),
346 tf_tcam_tbl_2_str(parms->type),
355 tf_tcam_get(struct tf *tfp __rte_unused,
356 struct tf_tcam_get_parms *parms __rte_unused)