ee5bacc09096c32816d2f42d93545e42867ec51d
[dpdk.git] / drivers / net / bnxt / tf_core / tf_tcam.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 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] Enable search for matching entry
108          */
109         uint8_t search_enable;
110         /**
111          * [in] Key data to match on (if search)
112          */
113         uint8_t *key;
114         /**
115          * [in] key size (if search)
116          */
117         uint16_t key_size;
118         /**
119          * [in] Mask data to match on (if search)
120          */
121         uint8_t *mask;
122         /**
123          * [in] Priority of entry requested (definition TBD)
124          */
125         uint32_t priority;
126         /**
127          * [out] If search, set if matching entry found
128          */
129         uint8_t hit;
130         /**
131          * [out] Current refcnt after allocation
132          */
133         uint16_t ref_cnt;
134         /**
135          * [out] Idx allocated
136          *
137          */
138         uint16_t idx;
139 };
140
141 /**
142  * TCAM set parameters
143  */
144 struct tf_tcam_set_parms {
145         /**
146          * [in] Receive or transmit direction
147          */
148         enum tf_dir dir;
149         /**
150          * [in] Type of object to set
151          */
152         enum tf_tcam_tbl_type type;
153         /**
154          * [in] Type of HCAPI
155          */
156         uint16_t hcapi_type;
157         /**
158          * [in] Entry index to write to
159          */
160         uint32_t idx;
161         /**
162          * [in] array containing key
163          */
164         uint8_t *key;
165         /**
166          * [in] array containing mask fields
167          */
168         uint8_t *mask;
169         /**
170          * [in] key size
171          */
172         uint16_t key_size;
173         /**
174          * [in] array containing result
175          */
176         uint8_t *result;
177         /**
178          * [in] result size
179          */
180         uint16_t result_size;
181 };
182
183 /**
184  * TCAM get parameters
185  */
186 struct tf_tcam_get_parms {
187         /**
188          * [in] Receive or transmit direction
189          */
190         enum tf_dir dir;
191         /**
192          * [in] Type of object to get
193          */
194         enum tf_tcam_tbl_type type;
195         /**
196          * [in] Entry index to read
197          */
198         uint32_t idx;
199         /**
200          * [out] array containing key
201          */
202         uint8_t *key;
203         /**
204          * [out] array containing mask fields
205          */
206         uint8_t *mask;
207         /**
208          * [out] key size
209          */
210         uint16_t key_size;
211         /**
212          * [out] array containing result
213          */
214         uint8_t *result;
215         /**
216          * [out] result size
217          */
218         uint16_t result_size;
219 };
220
221 /**
222  * @page tcam TCAM
223  *
224  * @ref tf_tcam_bind
225  *
226  * @ref tf_tcam_unbind
227  *
228  * @ref tf_tcam_alloc
229  *
230  * @ref tf_tcam_free
231  *
232  * @ref tf_tcam_alloc_search
233  *
234  * @ref tf_tcam_set
235  *
236  * @ref tf_tcam_get
237  *
238  */
239
240 /**
241  * Initializes the TCAM module with the requested DBs. Must be
242  * invoked as the first thing before any of the access functions.
243  *
244  * [in] tfp
245  *   Pointer to TF handle, used for HCAPI communication
246  *
247  * [in] parms
248  *   Pointer to parameters
249  *
250  * Returns
251  *   - (0) if successful.
252  *   - (-EINVAL) on failure.
253  */
254 int tf_tcam_bind(struct tf *tfp,
255                  struct tf_tcam_cfg_parms *parms);
256
257 /**
258  * Cleans up the private DBs and releases all the data.
259  *
260  * [in] tfp
261  *   Pointer to TF handle, used for HCAPI communication
262  *
263  * [in] parms
264  *   Pointer to parameters
265  *
266  * Returns
267  *   - (0) if successful.
268  *   - (-EINVAL) on failure.
269  */
270 int tf_tcam_unbind(struct tf *tfp);
271
272 /**
273  * Allocates the requested tcam type from the internal RM DB.
274  *
275  * [in] tfp
276  *   Pointer to TF handle, used for HCAPI communication
277  *
278  * [in] parms
279  *   Pointer to parameters
280  *
281  * Returns
282  *   - (0) if successful.
283  *   - (-EINVAL) on failure.
284  */
285 int tf_tcam_alloc(struct tf *tfp,
286                   struct tf_tcam_alloc_parms *parms);
287
288 /**
289  * Free's the requested table type and returns it to the DB. If shadow
290  * DB is enabled its searched first and if found the element refcount
291  * is decremented. If refcount goes to 0 then its returned to the
292  * table type 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_free(struct tf *tfp,
305                  struct tf_tcam_free_parms *parms);
306
307 /**
308  * Supported if Shadow DB is configured. Searches the Shadow DB for
309  * any matching element. If found the refcount in the shadow DB is
310  * updated accordingly. If not found a new element is allocated and
311  * installed into the shadow 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_alloc_search(struct tf *tfp,
324                          struct tf_tcam_alloc_search_parms *parms);
325
326 /**
327  * Configures the requested element by sending a firmware request which
328  * then installs it into the device internal structures.
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_set(struct tf *tfp,
341                 struct tf_tcam_set_parms *parms);
342
343 /**
344  * Retrieves the requested element by sending a firmware request to get
345  * the element.
346  *
347  * [in] tfp
348  *   Pointer to TF handle, used for HCAPI communication
349  *
350  * [in] parms
351  *   Pointer to parameters
352  *
353  * Returns
354  *   - (0) if successful.
355  *   - (-EINVAL) on failure.
356  */
357 int tf_tcam_get(struct tf *tfp,
358                 struct tf_tcam_get_parms *parms);
359
360 #endif /* _TF_TCAM_H */