net/bnxt: support TCAM access
[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] Entry index to write to
151          */
152         uint32_t idx;
153         /**
154          * [in] array containing key
155          */
156         uint8_t *key;
157         /**
158          * [in] array containing mask fields
159          */
160         uint8_t *mask;
161         /**
162          * [in] key size
163          */
164         uint16_t key_size;
165         /**
166          * [in] array containing result
167          */
168         uint8_t *result;
169         /**
170          * [in] result size
171          */
172         uint16_t result_size;
173 };
174
175 /**
176  * TCAM get parameters
177  */
178 struct tf_tcam_get_parms {
179         /**
180          * [in] Receive or transmit direction
181          */
182         enum tf_dir dir;
183         /**
184          * [in] Type of object to get
185          */
186         enum tf_tcam_tbl_type type;
187         /**
188          * [in] Entry index to read
189          */
190         uint32_t idx;
191         /**
192          * [out] array containing key
193          */
194         uint8_t *key;
195         /**
196          * [out] array containing mask fields
197          */
198         uint8_t *mask;
199         /**
200          * [out] key size
201          */
202         uint16_t key_size;
203         /**
204          * [out] array containing result
205          */
206         uint8_t *result;
207         /**
208          * [out] result size
209          */
210         uint16_t result_size;
211 };
212
213 /**
214  * @page tcam TCAM
215  *
216  * @ref tf_tcam_bind
217  *
218  * @ref tf_tcam_unbind
219  *
220  * @ref tf_tcam_alloc
221  *
222  * @ref tf_tcam_free
223  *
224  * @ref tf_tcam_alloc_search
225  *
226  * @ref tf_tcam_set
227  *
228  * @ref tf_tcam_get
229  *
230  */
231
232 /**
233  * Initializes the TCAM module with the requested DBs. Must be
234  * invoked as the first thing before any of the access functions.
235  *
236  * [in] tfp
237  *   Pointer to TF handle, used for HCAPI communication
238  *
239  * [in] parms
240  *   Pointer to parameters
241  *
242  * Returns
243  *   - (0) if successful.
244  *   - (-EINVAL) on failure.
245  */
246 int tf_tcam_bind(struct tf *tfp,
247                  struct tf_tcam_cfg_parms *parms);
248
249 /**
250  * Cleans up the private DBs and releases all the data.
251  *
252  * [in] tfp
253  *   Pointer to TF handle, used for HCAPI communication
254  *
255  * [in] parms
256  *   Pointer to parameters
257  *
258  * Returns
259  *   - (0) if successful.
260  *   - (-EINVAL) on failure.
261  */
262 int tf_tcam_unbind(struct tf *tfp);
263
264 /**
265  * Allocates the requested tcam type from the internal RM DB.
266  *
267  * [in] tfp
268  *   Pointer to TF handle, used for HCAPI communication
269  *
270  * [in] parms
271  *   Pointer to parameters
272  *
273  * Returns
274  *   - (0) if successful.
275  *   - (-EINVAL) on failure.
276  */
277 int tf_tcam_alloc(struct tf *tfp,
278                   struct tf_tcam_alloc_parms *parms);
279
280 /**
281  * Free's the requested table type and returns it to the DB. If shadow
282  * DB is enabled its searched first and if found the element refcount
283  * is decremented. If refcount goes to 0 then its returned to the
284  * table type DB.
285  *
286  * [in] tfp
287  *   Pointer to TF handle, used for HCAPI communication
288  *
289  * [in] parms
290  *   Pointer to parameters
291  *
292  * Returns
293  *   - (0) if successful.
294  *   - (-EINVAL) on failure.
295  */
296 int tf_tcam_free(struct tf *tfp,
297                  struct tf_tcam_free_parms *parms);
298
299 /**
300  * Supported if Shadow DB is configured. Searches the Shadow DB for
301  * any matching element. If found the refcount in the shadow DB is
302  * updated accordingly. If not found a new element is allocated and
303  * installed into the shadow DB.
304  *
305  * [in] tfp
306  *   Pointer to TF handle, used for HCAPI communication
307  *
308  * [in] parms
309  *   Pointer to parameters
310  *
311  * Returns
312  *   - (0) if successful.
313  *   - (-EINVAL) on failure.
314  */
315 int tf_tcam_alloc_search(struct tf *tfp,
316                          struct tf_tcam_alloc_search_parms *parms);
317
318 /**
319  * Configures the requested element by sending a firmware request which
320  * then installs it into the device internal structures.
321  *
322  * [in] tfp
323  *   Pointer to TF handle, used for HCAPI communication
324  *
325  * [in] parms
326  *   Pointer to parameters
327  *
328  * Returns
329  *   - (0) if successful.
330  *   - (-EINVAL) on failure.
331  */
332 int tf_tcam_set(struct tf *tfp,
333                 struct tf_tcam_set_parms *parms);
334
335 /**
336  * Retrieves the requested element by sending a firmware request to get
337  * the element.
338  *
339  * [in] tfp
340  *   Pointer to TF handle, used for HCAPI communication
341  *
342  * [in] parms
343  *   Pointer to parameters
344  *
345  * Returns
346  *   - (0) if successful.
347  *   - (-EINVAL) on failure.
348  */
349 int tf_tcam_get(struct tf *tfp,
350                 struct tf_tcam_get_parms *parms);
351
352 #endif /* _TF_TCAM_H */