xref: /dpdk/drivers/net/bnxt/tf_core/tf_tcam.h (revision e6e8f03e5459f25153f1e4cd3e9ac30d3e473a61)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2023 Broadcom
3  * All rights reserved.
4  */
5 
6 #ifndef _TF_TCAM_H_
7 #define _TF_TCAM_H_
8 
9 #include "tf_core.h"
10 
11 /**
12  * The TCAM module provides processing of Internal TCAM types.
13  */
14 
15 /* Number of slices per row for WC TCAM */
16 extern uint16_t g_wc_num_slices_per_row;
17 
18 /**
19  * TCAM configuration parameters
20  */
21 struct tf_tcam_cfg_parms {
22 	/**
23 	 * Number of tcam types in each of the configuration arrays
24 	 */
25 	uint16_t num_elements;
26 	/**
27 	 * TCAM configuration array
28 	 */
29 	struct tf_rm_element_cfg *cfg;
30 	/**
31 	 * Session resource allocations
32 	 */
33 	struct tf_session_resources *resources;
34 	/**
35 	 * WC number of slices per row.
36 	 */
37 	enum tf_wc_num_slice wc_num_slices;
38 };
39 
40 /**
41  * TCAM allocation parameters
42  */
43 struct tf_tcam_alloc_parms {
44 	/**
45 	 * [in] Receive or transmit direction
46 	 */
47 	enum tf_dir dir;
48 	/**
49 	 * [in] Type of the allocation
50 	 */
51 	enum tf_tcam_tbl_type type;
52 	/**
53 	 * [in] key size
54 	 */
55 	uint16_t key_size;
56 	/**
57 	 * [in] Priority of entry requested (definition TBD)
58 	 */
59 	uint32_t priority;
60 	/**
61 	 * [out] Idx of allocated entry or found entry (if search_enable)
62 	 */
63 	uint16_t idx;
64 };
65 
66 /**
67  * TCAM free parameters
68  */
69 struct tf_tcam_free_parms {
70 	/**
71 	 * [in] Receive or transmit direction
72 	 */
73 	enum tf_dir dir;
74 	/**
75 	 * [in] Type of the allocation type
76 	 */
77 	enum tf_tcam_tbl_type type;
78 	/**
79 	 * [in] Type of HCAPI
80 	 */
81 	uint16_t hcapi_type;
82 	/**
83 	 * [in] Index to free
84 	 */
85 	uint16_t idx;
86 };
87 
88 /**
89  * TCAM allocate search parameters
90  */
91 struct tf_tcam_alloc_search_parms {
92 	/**
93 	 * [in] receive or transmit direction
94 	 */
95 	enum tf_dir dir;
96 	/**
97 	 * [in] TCAM table type
98 	 */
99 	enum tf_tcam_tbl_type type;
100 	/**
101 	 * [in] Type of HCAPI
102 	 */
103 	uint16_t hcapi_type;
104 	/**
105 	 * [in] Key data to match on
106 	 */
107 	uint8_t *key;
108 	/**
109 	 * [in] key size in bits
110 	 */
111 	uint16_t key_size;
112 	/**
113 	 * [in] Mask data to match on
114 	 */
115 	uint8_t *mask;
116 	/**
117 	 * [in] Priority of entry requested (definition TBD)
118 	 */
119 	uint32_t priority;
120 	/**
121 	 * [in] Allocate on miss.
122 	 */
123 	uint8_t alloc;
124 	/**
125 	 * [out] Set if matching entry found
126 	 */
127 	uint8_t hit;
128 	/**
129 	 * [out] Search result status (hit, miss, reject)
130 	 */
131 	enum tf_search_status search_status;
132 	/**
133 	 * [out] Current refcnt after allocation
134 	 */
135 	uint16_t ref_cnt;
136 	/**
137 	 * [in,out] The result data from the search is copied here
138 	 */
139 	uint8_t *result;
140 	/**
141 	 * [in,out] result size in bits for the result data
142 	 */
143 	uint16_t result_size;
144 	/**
145 	 * [out] Index found
146 	 */
147 	uint16_t idx;
148 };
149 
150 /**
151  * TCAM set parameters
152  */
153 struct tf_tcam_set_parms {
154 	/**
155 	 * [in] Receive or transmit direction
156 	 */
157 	enum tf_dir dir;
158 	/**
159 	 * [in] Type of object to set
160 	 */
161 	enum tf_tcam_tbl_type type;
162 	/**
163 	 * [in] Type of HCAPI
164 	 */
165 	uint16_t hcapi_type;
166 	/**
167 	 * [in] Entry index to write to
168 	 */
169 	uint32_t idx;
170 	/**
171 	 * [in] array containing key
172 	 */
173 	uint8_t *key;
174 	/**
175 	 * [in] array containing mask fields
176 	 */
177 	uint8_t *mask;
178 	/**
179 	 * [in] key size
180 	 */
181 	uint16_t key_size;
182 	/**
183 	 * [in] array containing result
184 	 */
185 	uint8_t *result;
186 	/**
187 	 * [in] result size
188 	 */
189 	uint16_t result_size;
190 };
191 
192 /**
193  * TCAM get parameters
194  */
195 struct tf_tcam_get_parms {
196 	/**
197 	 * [in] Receive or transmit direction
198 	 */
199 	enum tf_dir dir;
200 	/**
201 	 * [in] Type of object to get
202 	 */
203 	enum tf_tcam_tbl_type type;
204 	/**
205 	 * [in] Type of HCAPI
206 	 */
207 	uint16_t hcapi_type;
208 	/**
209 	 * [in] Entry index to read
210 	 */
211 	uint32_t idx;
212 	/**
213 	 * [out] array containing key
214 	 */
215 	uint8_t *key;
216 	/**
217 	 * [out] array containing mask fields
218 	 */
219 	uint8_t *mask;
220 	/**
221 	 * [out] key size
222 	 */
223 	uint16_t key_size;
224 	/**
225 	 * [out] array containing result
226 	 */
227 	uint8_t *result;
228 	/**
229 	 * [out] result size
230 	 */
231 	uint16_t result_size;
232 };
233 
234 /**
235  * TCAM database
236  *
237  * Tcam rm database
238  *
239  */
240 struct tcam_rm_db {
241 	struct rm_db *tcam_db[TF_DIR_MAX];
242 };
243 
244 /**
245  * @page tcam TCAM
246  *
247  * @ref tf_tcam_bind
248  *
249  * @ref tf_tcam_unbind
250  *
251  * @ref tf_tcam_alloc
252  *
253  * @ref tf_tcam_free
254  *
255  * @ref tf_tcam_alloc_search
256  *
257  * @ref tf_tcam_set
258  *
259  * @ref tf_tcam_get
260  *
261  */
262 
263 /**
264  * Initializes the TCAM module with the requested DBs. Must be
265  * invoked as the first thing before any of the access functions.
266  *
267  * [in] tfp
268  *   Pointer to TF handle, used for HCAPI communication
269  *
270  * [in] parms
271  *   Pointer to parameters
272  *
273  * Returns
274  *   - (0) if successful.
275  *   - (-EINVAL) on failure.
276  */
277 int tf_tcam_bind(struct tf *tfp,
278 		 struct tf_tcam_cfg_parms *parms);
279 
280 /**
281  * Cleans up the private DBs and releases all the data.
282  *
283  * [in] tfp
284  *   Pointer to TF handle, used for HCAPI communication
285  *
286  * [in] parms
287  *   Pointer to parameters
288  *
289  * Returns
290  *   - (0) if successful.
291  *   - (-EINVAL) on failure.
292  */
293 int tf_tcam_unbind(struct tf *tfp);
294 
295 /**
296  * Allocates the requested tcam type from the internal RM DB.
297  *
298  * [in] tfp
299  *   Pointer to TF handle, used for HCAPI communication
300  *
301  * [in] parms
302  *   Pointer to parameters
303  *
304  * Returns
305  *   - (0) if successful.
306  *   - (-EINVAL) on failure.
307  */
308 int tf_tcam_alloc(struct tf *tfp,
309 		  struct tf_tcam_alloc_parms *parms);
310 
311 /**
312  * Free's the requested table type and returns it to the DB.
313  * If refcount goes to 0 then its returned to the table type DB.
314  *
315  * [in] tfp
316  *   Pointer to TF handle, used for HCAPI communication
317  *
318  * [in] parms
319  *   Pointer to parameters
320  *
321  * Returns
322  *   - (0) if successful.
323  *   - (-EINVAL) on failure.
324  */
325 int tf_tcam_free(struct tf *tfp,
326 		 struct tf_tcam_free_parms *parms);
327 
328 /**
329  * Configures the requested element by sending a firmware request which
330  * then installs it into the device internal structures.
331  *
332  * [in] tfp
333  *   Pointer to TF handle, used for HCAPI communication
334  *
335  * [in] parms
336  *   Pointer to parameters
337  *
338  * Returns
339  *   - (0) if successful.
340  *   - (-EINVAL) on failure.
341  */
342 int tf_tcam_set(struct tf *tfp,
343 		struct tf_tcam_set_parms *parms);
344 
345 /**
346  * Retrieves the requested element by sending a firmware request to get
347  * the element.
348  *
349  * [in] tfp
350  *   Pointer to TF handle, used for HCAPI communication
351  *
352  * [in] parms
353  *   Pointer to parameters
354  *
355  * Returns
356  *   - (0) if successful.
357  *   - (-EINVAL) on failure.
358  */
359 int tf_tcam_get(struct tf *tfp,
360 		struct tf_tcam_get_parms *parms);
361 
362 /**
363  * Retrieves the allocated resource info
364  *
365  * [in] tfp
366  *   Pointer to TF handle, used for HCAPI communication
367  *
368  * [in] parms
369  *   Pointer to parameters
370  *
371  * Returns
372  *   - (0) if successful.
373  *   - (-EINVAL) on failure.
374  */
375 int tf_tcam_get_resc_info(struct tf *tfp,
376 			  struct tf_tcam_resource_info *parms);
377 #endif /* _TF_TCAM_H */
378