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