net/bnxt: update RM with residual checker
[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] Index to free
81          */
82         uint16_t idx;
83         /**
84          * [out] Reference count after free, only valid if session has been
85          * created with shadow_copy.
86          */
87         uint16_t ref_cnt;
88 };
89
90 /**
91  * TCAM allocate search parameters
92  */
93 struct tf_tcam_alloc_search_parms {
94         /**
95          * [in] receive or transmit direction
96          */
97         enum tf_dir dir;
98         /**
99          * [in] TCAM table type
100          */
101         enum tf_tcam_tbl_type type;
102         /**
103          * [in] Enable search for matching entry
104          */
105         uint8_t search_enable;
106         /**
107          * [in] Key data to match on (if search)
108          */
109         uint8_t *key;
110         /**
111          * [in] key size (if search)
112          */
113         uint16_t key_size;
114         /**
115          * [in] Mask data to match on (if search)
116          */
117         uint8_t *mask;
118         /**
119          * [in] Priority of entry requested (definition TBD)
120          */
121         uint32_t priority;
122         /**
123          * [out] If search, set if matching entry found
124          */
125         uint8_t hit;
126         /**
127          * [out] Current refcnt after allocation
128          */
129         uint16_t ref_cnt;
130         /**
131          * [out] Idx allocated
132          *
133          */
134         uint16_t idx;
135 };
136
137 /**
138  * TCAM set parameters
139  */
140 struct tf_tcam_set_parms {
141         /**
142          * [in] Receive or transmit direction
143          */
144         enum tf_dir dir;
145         /**
146          * [in] Type of object to set
147          */
148         enum tf_tcam_tbl_type type;
149         /**
150          * [in] Type of HCAPI
151          */
152         uint16_t hcapi_type;
153         /**
154          * [in] Entry index to write to
155          */
156         uint32_t idx;
157         /**
158          * [in] array containing key
159          */
160         uint8_t *key;
161         /**
162          * [in] array containing mask fields
163          */
164         uint8_t *mask;
165         /**
166          * [in] key size
167          */
168         uint16_t key_size;
169         /**
170          * [in] array containing result
171          */
172         uint8_t *result;
173         /**
174          * [in] result size
175          */
176         uint16_t result_size;
177 };
178
179 /**
180  * TCAM get parameters
181  */
182 struct tf_tcam_get_parms {
183         /**
184          * [in] Receive or transmit direction
185          */
186         enum tf_dir dir;
187         /**
188          * [in] Type of object to get
189          */
190         enum tf_tcam_tbl_type type;
191         /**
192          * [in] Entry index to read
193          */
194         uint32_t idx;
195         /**
196          * [out] array containing key
197          */
198         uint8_t *key;
199         /**
200          * [out] array containing mask fields
201          */
202         uint8_t *mask;
203         /**
204          * [out] key size
205          */
206         uint16_t key_size;
207         /**
208          * [out] array containing result
209          */
210         uint8_t *result;
211         /**
212          * [out] result size
213          */
214         uint16_t result_size;
215 };
216
217 /**
218  * @page tcam TCAM
219  *
220  * @ref tf_tcam_bind
221  *
222  * @ref tf_tcam_unbind
223  *
224  * @ref tf_tcam_alloc
225  *
226  * @ref tf_tcam_free
227  *
228  * @ref tf_tcam_alloc_search
229  *
230  * @ref tf_tcam_set
231  *
232  * @ref tf_tcam_get
233  *
234  */
235
236 /**
237  * Initializes the TCAM module with the requested DBs. Must be
238  * invoked as the first thing before any of the access functions.
239  *
240  * [in] tfp
241  *   Pointer to TF handle, used for HCAPI communication
242  *
243  * [in] parms
244  *   Pointer to parameters
245  *
246  * Returns
247  *   - (0) if successful.
248  *   - (-EINVAL) on failure.
249  */
250 int tf_tcam_bind(struct tf *tfp,
251                  struct tf_tcam_cfg_parms *parms);
252
253 /**
254  * Cleans up the private DBs and releases all the data.
255  *
256  * [in] tfp
257  *   Pointer to TF handle, used for HCAPI communication
258  *
259  * [in] parms
260  *   Pointer to parameters
261  *
262  * Returns
263  *   - (0) if successful.
264  *   - (-EINVAL) on failure.
265  */
266 int tf_tcam_unbind(struct tf *tfp);
267
268 /**
269  * Allocates the requested tcam type from the internal RM DB.
270  *
271  * [in] tfp
272  *   Pointer to TF handle, used for HCAPI communication
273  *
274  * [in] parms
275  *   Pointer to parameters
276  *
277  * Returns
278  *   - (0) if successful.
279  *   - (-EINVAL) on failure.
280  */
281 int tf_tcam_alloc(struct tf *tfp,
282                   struct tf_tcam_alloc_parms *parms);
283
284 /**
285  * Free's the requested table type and returns it to the DB. If shadow
286  * DB is enabled its searched first and if found the element refcount
287  * is decremented. If refcount goes to 0 then its returned to the
288  * table type DB.
289  *
290  * [in] tfp
291  *   Pointer to TF handle, used for HCAPI communication
292  *
293  * [in] parms
294  *   Pointer to parameters
295  *
296  * Returns
297  *   - (0) if successful.
298  *   - (-EINVAL) on failure.
299  */
300 int tf_tcam_free(struct tf *tfp,
301                  struct tf_tcam_free_parms *parms);
302
303 /**
304  * Supported if Shadow DB is configured. Searches the Shadow DB for
305  * any matching element. If found the refcount in the shadow DB is
306  * updated accordingly. If not found a new element is allocated and
307  * installed into the shadow DB.
308  *
309  * [in] tfp
310  *   Pointer to TF handle, used for HCAPI communication
311  *
312  * [in] parms
313  *   Pointer to parameters
314  *
315  * Returns
316  *   - (0) if successful.
317  *   - (-EINVAL) on failure.
318  */
319 int tf_tcam_alloc_search(struct tf *tfp,
320                          struct tf_tcam_alloc_search_parms *parms);
321
322 /**
323  * Configures the requested element by sending a firmware request which
324  * then installs it into the device internal structures.
325  *
326  * [in] tfp
327  *   Pointer to TF handle, used for HCAPI communication
328  *
329  * [in] parms
330  *   Pointer to parameters
331  *
332  * Returns
333  *   - (0) if successful.
334  *   - (-EINVAL) on failure.
335  */
336 int tf_tcam_set(struct tf *tfp,
337                 struct tf_tcam_set_parms *parms);
338
339 /**
340  * Retrieves the requested element by sending a firmware request to get
341  * the element.
342  *
343  * [in] tfp
344  *   Pointer to TF handle, used for HCAPI communication
345  *
346  * [in] parms
347  *   Pointer to parameters
348  *
349  * Returns
350  *   - (0) if successful.
351  *   - (-EINVAL) on failure.
352  */
353 int tf_tcam_get(struct tf *tfp,
354                 struct tf_tcam_get_parms *parms);
355
356 #endif /* _TF_TCAM_H */