net/bnxt: support L2 context TCAM operations
[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  * @page tcam TCAM
242  *
243  * @ref tf_tcam_bind
244  *
245  * @ref tf_tcam_unbind
246  *
247  * @ref tf_tcam_alloc
248  *
249  * @ref tf_tcam_free
250  *
251  * @ref tf_tcam_alloc_search
252  *
253  * @ref tf_tcam_set
254  *
255  * @ref tf_tcam_get
256  *
257  */
258
259 /**
260  * Initializes the TCAM module with the requested DBs. Must be
261  * invoked as the first thing before any of the access functions.
262  *
263  * [in] tfp
264  *   Pointer to TF handle, used for HCAPI communication
265  *
266  * [in] parms
267  *   Pointer to parameters
268  *
269  * Returns
270  *   - (0) if successful.
271  *   - (-EINVAL) on failure.
272  */
273 int tf_tcam_bind(struct tf *tfp,
274                  struct tf_tcam_cfg_parms *parms);
275
276 /**
277  * Cleans up the private DBs and releases all the data.
278  *
279  * [in] tfp
280  *   Pointer to TF handle, used for HCAPI communication
281  *
282  * [in] parms
283  *   Pointer to parameters
284  *
285  * Returns
286  *   - (0) if successful.
287  *   - (-EINVAL) on failure.
288  */
289 int tf_tcam_unbind(struct tf *tfp);
290
291 /**
292  * Allocates the requested tcam type from the internal RM DB.
293  *
294  * [in] tfp
295  *   Pointer to TF handle, used for HCAPI communication
296  *
297  * [in] parms
298  *   Pointer to parameters
299  *
300  * Returns
301  *   - (0) if successful.
302  *   - (-EINVAL) on failure.
303  */
304 int tf_tcam_alloc(struct tf *tfp,
305                   struct tf_tcam_alloc_parms *parms);
306
307 /**
308  * Free's the requested table type and returns it to the DB. If shadow
309  * DB is enabled its searched first and if found the element refcount
310  * is decremented. If refcount goes to 0 then its returned to the
311  * table type DB.
312  *
313  * [in] tfp
314  *   Pointer to TF handle, used for HCAPI communication
315  *
316  * [in] parms
317  *   Pointer to parameters
318  *
319  * Returns
320  *   - (0) if successful.
321  *   - (-EINVAL) on failure.
322  */
323 int tf_tcam_free(struct tf *tfp,
324                  struct tf_tcam_free_parms *parms);
325
326 /**
327  * Supported if Shadow DB is configured. Searches the Shadow DB for
328  * any matching element. If found the refcount in the shadow DB is
329  * updated accordingly. If not found a new element is allocated and
330  * installed into the shadow DB.
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_alloc_search(struct tf *tfp,
343                          struct tf_tcam_alloc_search_parms *parms);
344
345 /**
346  * Configures the requested element by sending a firmware request which
347  * then installs it into the device internal structures.
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_set(struct tf *tfp,
360                 struct tf_tcam_set_parms *parms);
361
362 /**
363  * Retrieves the requested element by sending a firmware request to get
364  * the element.
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_get(struct tf *tfp,
377                 struct tf_tcam_get_parms *parms);
378
379 #endif /* _TF_TCAM_H */