Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2021-2023 Broadcom
3 : : * All rights reserved.
4 : : */
5 : :
6 : : /*
7 : : * This file will "do the right thing" for each of the primitives set, get and
8 : : * free. The TCAM manager is running in the core, so the tables will be cached.
9 : : * Set and free messages will also be sent to the firmware. Instead of sending
10 : : * get messages, the entry will be read from the cached copy thus saving a
11 : : * firmware message.
12 : : */
13 : :
14 : : #include "tf_tcam.h"
15 : : #include "hcapi_cfa_defs.h"
16 : : #include "cfa_tcam_mgr.h"
17 : : #include "cfa_tcam_mgr_hwop_msg.h"
18 : : #include "cfa_tcam_mgr_device.h"
19 : : #include "cfa_tcam_mgr_p58.h"
20 : : #include "cfa_tcam_mgr_p4.h"
21 : : #include "tf_session.h"
22 : : #include "tf_msg.h"
23 : : #include "tfp.h"
24 : : #include "tf_util.h"
25 : :
26 : : /*
27 : : * The free hwop will free more than a single slice so cannot be used.
28 : : */
29 : : struct cfa_tcam_mgr_hwops_funcs hwop_funcs;
30 : :
31 : : int
32 : 0 : cfa_tcam_mgr_hwops_init(enum cfa_tcam_mgr_device_type type)
33 : : {
34 [ # # # ]: 0 : switch (type) {
35 : 0 : case CFA_TCAM_MGR_DEVICE_TYPE_P4:
36 : : case CFA_TCAM_MGR_DEVICE_TYPE_SR:
37 : 0 : return cfa_tcam_mgr_hwops_get_funcs_p4(&hwop_funcs);
38 : 0 : case CFA_TCAM_MGR_DEVICE_TYPE_P5:
39 : 0 : return cfa_tcam_mgr_hwops_get_funcs_p58(&hwop_funcs);
40 : 0 : default:
41 : 0 : CFA_TCAM_MGR_LOG(ERR, "No such device\n");
42 : 0 : return -CFA_TCAM_MGR_ERR_CODE(NODEV);
43 : : }
44 : : }
45 : :
46 : : /*
47 : : * This is the glue between the TCAM manager and the firmware HW operations. It
48 : : * is intended to abstract out the location of the TCAM manager so that the TCAM
49 : : * manager code will be the same whether or not it is actually using the
50 : : * firmware.
51 : : */
52 : :
53 : : int
54 : 0 : cfa_tcam_mgr_entry_set_msg(int sess_idx, struct cfa_tcam_mgr_context *context
55 : : __rte_unused,
56 : : struct cfa_tcam_mgr_set_parms *parms,
57 : : int row, int slice,
58 : : int max_slices __rte_unused)
59 : : {
60 : : cfa_tcam_mgr_hwop_set_func_t set_func;
61 : :
62 : 0 : set_func = hwop_funcs.set;
63 [ # # ]: 0 : if (set_func == NULL)
64 : : return -CFA_TCAM_MGR_ERR_CODE(PERM);
65 : :
66 : : struct tf_tcam_set_parms sparms;
67 : : struct tf_session *tfs;
68 : : struct tf_dev_info *dev;
69 : : int rc;
70 : 0 : enum tf_tcam_tbl_type type =
71 : 0 : cfa_tcam_mgr_get_phys_table_type(parms->type);
72 : :
73 : : /* Retrieve the session information */
74 : 0 : rc = tf_session_get_session_internal(context->tfp, &tfs);
75 [ # # ]: 0 : if (rc)
76 : : return rc;
77 : :
78 : : /* Retrieve the device information */
79 : 0 : rc = tf_session_get_device(tfs, &dev);
80 [ # # ]: 0 : if (rc)
81 : : return rc;
82 : :
83 : : memset(&sparms, 0, sizeof(sparms));
84 : 0 : sparms.dir = parms->dir;
85 : 0 : sparms.type = type;
86 : 0 : sparms.hcapi_type = parms->hcapi_type;
87 : 0 : sparms.idx = (row * max_slices) + slice;
88 : 0 : sparms.key = parms->key;
89 : 0 : sparms.mask = parms->mask;
90 : 0 : sparms.key_size = parms->key_size;
91 : 0 : sparms.result = parms->result;
92 : 0 : sparms.result_size = parms->result_size;
93 : :
94 : 0 : rc = tf_msg_tcam_entry_set(context->tfp, dev, &sparms);
95 [ # # ]: 0 : if (rc) {
96 : : /* Log error */
97 : 0 : CFA_TCAM_MGR_LOG_DIR_TYPE(ERR, parms->dir, parms->type,
98 : : "Entry %d set failed, rc:%d\n",
99 : : parms->id, -rc);
100 : 0 : return rc;
101 : : }
102 : :
103 : 0 : return set_func(sess_idx, parms, row, slice, max_slices);
104 : : }
105 : :
106 : : int
107 : 0 : cfa_tcam_mgr_entry_get_msg(int sess_idx, struct cfa_tcam_mgr_context *context
108 : : __rte_unused,
109 : : struct cfa_tcam_mgr_get_parms *parms,
110 : : int row, int slice,
111 : : int max_slices __rte_unused)
112 : : {
113 : : cfa_tcam_mgr_hwop_get_func_t get_func;
114 : :
115 : 0 : get_func = hwop_funcs.get;
116 [ # # ]: 0 : if (get_func == NULL)
117 : : return -CFA_TCAM_MGR_ERR_CODE(PERM);
118 : :
119 : 0 : return get_func(sess_idx, parms, row, slice, max_slices);
120 : : }
121 : :
122 : : int
123 : 0 : cfa_tcam_mgr_entry_free_msg(int sess_idx, struct cfa_tcam_mgr_context *context
124 : : __rte_unused,
125 : : struct cfa_tcam_mgr_free_parms *parms,
126 : : int row, int slice,
127 : : int key_size,
128 : : int result_size,
129 : : int max_slices)
130 : : {
131 : : cfa_tcam_mgr_hwop_free_func_t free_func;
132 : :
133 : 0 : free_func = hwop_funcs.free;
134 [ # # ]: 0 : if (free_func == NULL)
135 : : return -CFA_TCAM_MGR_ERR_CODE(PERM);
136 : :
137 : : struct tf_dev_info *dev;
138 : : struct tf_session *tfs;
139 : : int rc;
140 : 0 : enum tf_tcam_tbl_type type =
141 : 0 : cfa_tcam_mgr_get_phys_table_type(parms->type);
142 : :
143 : : /* Free will clear an entire row. */
144 : : /* Use set message to clear an individual entry */
145 : : struct tf_tcam_set_parms sparms;
146 : 0 : uint8_t key[CFA_TCAM_MGR_MAX_KEY_SIZE] = { 0 };
147 : 0 : uint8_t mask[CFA_TCAM_MGR_MAX_KEY_SIZE] = { 0 };
148 : :
149 : : /* Retrieve the session information */
150 : 0 : rc = tf_session_get_session_internal(context->tfp, &tfs);
151 [ # # ]: 0 : if (rc)
152 : : return rc;
153 : :
154 : : /* Retrieve the device information */
155 : 0 : rc = tf_session_get_device(tfs, &dev);
156 [ # # ]: 0 : if (rc)
157 : : return rc;
158 : :
159 [ # # ]: 0 : if (key_size > CFA_TCAM_MGR_MAX_KEY_SIZE) {
160 : 0 : CFA_TCAM_MGR_LOG_DIR_TYPE(ERR, parms->dir, parms->type,
161 : : "Entry %d key size is %d greater than:%d\n",
162 : : parms->id, key_size,
163 : : CFA_TCAM_MGR_MAX_KEY_SIZE);
164 : 0 : return -EINVAL;
165 : : }
166 : :
167 [ # # ]: 0 : if (result_size > CFA_TCAM_MGR_MAX_KEY_SIZE) {
168 : 0 : CFA_TCAM_MGR_LOG_DIR_TYPE(ERR, parms->dir, parms->type,
169 : : "Entry %d result size is %d greater than:%d\n",
170 : : parms->id, result_size,
171 : : CFA_TCAM_MGR_MAX_KEY_SIZE);
172 : 0 : return -EINVAL;
173 : : }
174 : :
175 : : memset(&sparms, 0, sizeof(sparms));
176 : : memset(&key, 0, sizeof(key));
177 : : memset(&mask, 0xff, sizeof(mask));
178 : :
179 : 0 : sparms.dir = parms->dir;
180 : 0 : sparms.type = type;
181 : 0 : sparms.hcapi_type = parms->hcapi_type;
182 : 0 : sparms.key = key;
183 : 0 : sparms.mask = mask;
184 : 0 : sparms.result = key;
185 : 0 : sparms.idx = (row * max_slices) + slice;
186 : 0 : sparms.key_size = key_size;
187 : 0 : sparms.result_size = result_size;
188 : :
189 : 0 : rc = tf_msg_tcam_entry_set(context->tfp, dev, &sparms);
190 [ # # ]: 0 : if (rc) {
191 : : /* Log error */
192 : 0 : CFA_TCAM_MGR_LOG_DIR_TYPE(ERR, parms->dir, parms->type,
193 : : "Row %d, slice %d set failed, "
194 : : "rc:%d.\n",
195 : : row,
196 : : slice,
197 : : rc);
198 : 0 : return rc;
199 : : }
200 : 0 : return free_func(sess_idx, parms, row, slice, max_slices);
201 : : }
|