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