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;
58 for (i = 0; i < TF_DIR_MAX; i++) {
60 db_cfg.num_elements = parms->num_elements;
61 db_cfg.cfg = parms->cfg;
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.index = (uint32_t *)&parms->idx;
160 rc = tf_rm_allocate(&aparms);
163 "%s: Failed tcam, type:%d\n",
164 tf_dir_2_str(parms->dir),
169 parms->idx *= num_slice_per_row;
175 tf_tcam_free(struct tf *tfp __rte_unused,
176 struct tf_tcam_free_parms *parms __rte_unused)
179 struct tf_session *tfs;
180 struct tf_dev_info *dev;
181 struct tf_rm_is_allocated_parms aparms = { 0 };
182 struct tf_rm_free_parms fparms = { 0 };
183 uint16_t num_slice_per_row = 1;
186 TF_CHECK_PARMS2(tfp, parms);
190 "%s: No TCAM DBs created\n",
191 tf_dir_2_str(parms->dir));
195 /* Retrieve the session information */
196 rc = tf_session_get_session(tfp, &tfs);
200 /* Retrieve the device information */
201 rc = tf_session_get_device(tfs, &dev);
205 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
208 "%s: Operation not supported, rc:%s\n",
209 tf_dir_2_str(parms->dir),
214 /* Need to retrieve row size etc */
215 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
222 /* Check if element is in use */
223 aparms.rm_db = tcam_db[parms->dir];
224 aparms.db_index = parms->type;
225 aparms.index = parms->idx / num_slice_per_row;
226 aparms.allocated = &allocated;
227 rc = tf_rm_is_allocated(&aparms);
233 "%s: Entry already free, type:%d, index:%d\n",
234 tf_dir_2_str(parms->dir),
240 /* Free requested element */
241 fparms.rm_db = tcam_db[parms->dir];
242 fparms.db_index = parms->type;
243 fparms.index = parms->idx / num_slice_per_row;
244 rc = tf_rm_free(&fparms);
247 "%s: Free failed, type:%d, index:%d\n",
248 tf_dir_2_str(parms->dir),
254 rc = tf_msg_tcam_entry_free(tfp, parms);
257 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
258 tf_dir_2_str(parms->dir),
259 tf_tcam_tbl_2_str(parms->type),
268 tf_tcam_alloc_search(struct tf *tfp __rte_unused,
269 struct tf_tcam_alloc_search_parms *parms __rte_unused)
275 tf_tcam_set(struct tf *tfp __rte_unused,
276 struct tf_tcam_set_parms *parms __rte_unused)
279 struct tf_session *tfs;
280 struct tf_dev_info *dev;
281 struct tf_rm_is_allocated_parms aparms = { 0 };
282 uint16_t num_slice_per_row = 1;
285 TF_CHECK_PARMS2(tfp, parms);
289 "%s: No TCAM DBs created\n",
290 tf_dir_2_str(parms->dir));
294 /* Retrieve the session information */
295 rc = tf_session_get_session(tfp, &tfs);
299 /* Retrieve the device information */
300 rc = tf_session_get_device(tfs, &dev);
304 if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
307 "%s: Operation not supported, rc:%s\n",
308 tf_dir_2_str(parms->dir),
313 /* Need to retrieve row size etc */
314 rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
321 /* Check if element is in use */
322 aparms.rm_db = tcam_db[parms->dir];
323 aparms.db_index = parms->type;
324 aparms.index = parms->idx / num_slice_per_row;
325 aparms.allocated = &allocated;
326 rc = tf_rm_is_allocated(&aparms);
332 "%s: Entry is not allocated, type:%d, index:%d\n",
333 tf_dir_2_str(parms->dir),
339 rc = tf_msg_tcam_entry_set(tfp, parms);
342 TFP_DRV_LOG(ERR, "%s: %s: Entry %d free failed with err %s",
343 tf_dir_2_str(parms->dir),
344 tf_tcam_tbl_2_str(parms->type),
353 tf_tcam_get(struct tf *tfp __rte_unused,
354 struct tf_tcam_get_parms *parms __rte_unused)