net/bnxt: update table get to use new design
[dpdk.git] / drivers / net / bnxt / tf_core / tf_device.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #ifndef _TF_DEVICE_H_
7 #define _TF_DEVICE_H_
8
9 #include "tf_core.h"
10 #include "tf_identifier.h"
11 #include "tf_tbl.h"
12 #include "tf_tcam.h"
13
14 struct tf;
15 struct tf_session;
16
17 /**
18  * Device module types
19  */
20 enum tf_device_module_type {
21         /**
22          * Identifier module
23          */
24         TF_DEVICE_MODULE_TYPE_IDENTIFIER,
25         /**
26          * Table type module
27          */
28         TF_DEVICE_MODULE_TYPE_TABLE,
29         /**
30          * TCAM module
31          */
32         TF_DEVICE_MODULE_TYPE_TCAM,
33         /**
34          * EM module
35          */
36         TF_DEVICE_MODULE_TYPE_EM,
37         TF_DEVICE_MODULE_TYPE_MAX
38 };
39
40 /**
41  * The Device module provides a general device template. A supported
42  * device type should implement one or more of the listed function
43  * pointers according to its capabilities.
44  *
45  * If a device function pointer is NULL the device capability is not
46  * supported.
47  */
48
49 /**
50  * TF device information
51  */
52 struct tf_dev_info {
53         enum tf_device_type type;
54         const struct tf_dev_ops *ops;
55 };
56
57 /**
58  * @page device Device
59  *
60  * @ref tf_dev_bind
61  *
62  * @ref tf_dev_unbind
63  */
64
65 /**
66  * Device bind handles the initialization of the specified device
67  * type.
68  *
69  * [in] tfp
70  *   Pointer to TF handle
71  *
72  * [in] type
73  *   Device type
74  *
75  * [in] resources
76  *   Pointer to resource allocation information
77  *
78  * [out] dev_handle
79  *   Device handle
80  *
81  * Returns
82  *   - (0) if successful.
83  *   - (-EINVAL) parameter failure.
84  *   - (-ENODEV) no such device supported.
85  */
86 int tf_dev_bind(struct tf *tfp,
87                 enum tf_device_type type,
88                 bool shadow_copy,
89                 struct tf_session_resources *resources,
90                 struct tf_dev_info *dev_handle);
91
92 /**
93  * Device release handles cleanup of the device specific information.
94  *
95  * [in] tfp
96  *   Pointer to TF handle
97  *
98  * [in] dev_handle
99  *   Device handle
100  *
101  * Returns
102  *   - (0) if successful.
103  *   - (-EINVAL) parameter failure.
104  *   - (-ENODEV) no such device supported.
105  */
106 int tf_dev_unbind(struct tf *tfp,
107                   struct tf_dev_info *dev_handle);
108
109 /**
110  * Truflow device specific function hooks structure
111  *
112  * The following device hooks can be defined; unless noted otherwise,
113  * they are optional and can be filled with a null pointer. The
114  * purpose of these hooks is to support Truflow device operations for
115  * different device variants.
116  */
117 struct tf_dev_ops {
118         /**
119          * Retrieves the MAX number of resource types that the device
120          * supports.
121          *
122          * [in] tfp
123          *   Pointer to TF handle
124          *
125          * [out] max_types
126          *   Pointer to MAX number of types the device supports
127          *
128          * Returns
129          *   - (0) if successful.
130          *   - (-EINVAL) on failure.
131          */
132         int (*tf_dev_get_max_types)(struct tf *tfp,
133                                     uint16_t *max_types);
134
135         /**
136          * Retrieves the WC TCAM slice information that the device
137          * supports.
138          *
139          * [in] tfp
140          *   Pointer to TF handle
141          *
142          * [in] type
143          *   TCAM table type
144          *
145          * [in] key_sz
146          *   Key size
147          *
148          * [out] num_slices_per_row
149          *   Pointer to number of slices per row the device supports
150          *
151          * Returns
152          *   - (0) if successful.
153          *   - (-EINVAL) on failure.
154          */
155         int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
156                                           enum tf_tcam_tbl_type type,
157                                           uint16_t key_sz,
158                                           uint16_t *num_slices_per_row);
159
160         /**
161          * Allocation of an identifier element.
162          *
163          * This API allocates the specified identifier element from a
164          * device specific identifier DB. The allocated element is
165          * returned.
166          *
167          * [in] tfp
168          *   Pointer to TF handle
169          *
170          * [in] parms
171          *   Pointer to identifier allocation parameters
172          *
173          * Returns
174          *   - (0) if successful.
175          *   - (-EINVAL) on failure.
176          */
177         int (*tf_dev_alloc_ident)(struct tf *tfp,
178                                   struct tf_ident_alloc_parms *parms);
179
180         /**
181          * Free of an identifier element.
182          *
183          * This API free's a previous allocated identifier element from a
184          * device specific identifier DB.
185          *
186          * [in] tfp
187          *   Pointer to TF handle
188          *
189          * [in] parms
190          *   Pointer to identifier free parameters
191          *
192          * Returns
193          *   - (0) if successful.
194          *   - (-EINVAL) on failure.
195          */
196         int (*tf_dev_free_ident)(struct tf *tfp,
197                                  struct tf_ident_free_parms *parms);
198
199         /**
200          * Allocation of a table type element.
201          *
202          * This API allocates the specified table type element from a
203          * device specific table type DB. The allocated element is
204          * returned.
205          *
206          * [in] tfp
207          *   Pointer to TF handle
208          *
209          * [in] parms
210          *   Pointer to table allocation parameters
211          *
212          * Returns
213          *   - (0) if successful.
214          *   - (-EINVAL) on failure.
215          */
216         int (*tf_dev_alloc_tbl)(struct tf *tfp,
217                                 struct tf_tbl_alloc_parms *parms);
218
219         /**
220          * Free of a table type element.
221          *
222          * This API free's a previous allocated table type element from a
223          * device specific table type DB.
224          *
225          * [in] tfp
226          *   Pointer to TF handle
227          *
228          * [in] parms
229          *   Pointer to table free parameters
230          *
231          * Returns
232          *   - (0) if successful.
233          *   - (-EINVAL) on failure.
234          */
235         int (*tf_dev_free_tbl)(struct tf *tfp,
236                                struct tf_tbl_free_parms *parms);
237
238         /**
239          * Searches for the specified table type element in a shadow DB.
240          *
241          * This API searches for the specified table type element in a
242          * device specific shadow DB. If the element is found the
243          * reference count for the element is updated. If the element
244          * is not found a new element is allocated from the table type
245          * DB and then inserted into the shadow DB.
246          *
247          * [in] tfp
248          *   Pointer to TF handle
249          *
250          * [in] parms
251          *   Pointer to table allocation and search parameters
252          *
253          * Returns
254          *   - (0) if successful.
255          *   - (-EINVAL) on failure.
256          */
257         int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
258                                        struct tf_tbl_alloc_search_parms *parms);
259
260         /**
261          * Sets the specified table type element.
262          *
263          * This API sets the specified element data by invoking the
264          * firmware.
265          *
266          * [in] tfp
267          *   Pointer to TF handle
268          *
269          * [in] parms
270          *   Pointer to table set parameters
271          *
272          * Returns
273          *   - (0) if successful.
274          *   - (-EINVAL) on failure.
275          */
276         int (*tf_dev_set_tbl)(struct tf *tfp,
277                               struct tf_tbl_set_parms *parms);
278
279         /**
280          * Retrieves the specified table type element.
281          *
282          * This API retrieves the specified element data by invoking the
283          * firmware.
284          *
285          * [in] tfp
286          *   Pointer to TF handle
287          *
288          * [in] parms
289          *   Pointer to table get parameters
290          *
291          * Returns
292          *   - (0) if successful.
293          *   - (-EINVAL) on failure.
294          */
295         int (*tf_dev_get_tbl)(struct tf *tfp,
296                               struct tf_tbl_get_parms *parms);
297
298         /**
299          * Retrieves the specified table type element using 'bulk'
300          * mechanism.
301          *
302          * This API retrieves the specified element data by invoking the
303          * firmware.
304          *
305          * [in] tfp
306          *   Pointer to TF handle
307          *
308          * [in] parms
309          *   Pointer to table get bulk parameters
310          *
311          * Returns
312          *   - (0) if successful.
313          *   - (-EINVAL) on failure.
314          */
315         int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
316                                    struct tf_tbl_get_bulk_parms *parms);
317
318         /**
319          * Allocation of a tcam element.
320          *
321          * This API allocates the specified tcam element from a device
322          * specific tcam DB. The allocated element is returned.
323          *
324          * [in] tfp
325          *   Pointer to TF handle
326          *
327          * [in] parms
328          *   Pointer to tcam allocation parameters
329          *
330          * Returns
331          *   - (0) if successful.
332          *   - (-EINVAL) on failure.
333          */
334         int (*tf_dev_alloc_tcam)(struct tf *tfp,
335                                  struct tf_tcam_alloc_parms *parms);
336
337         /**
338          * Free of a tcam element.
339          *
340          * This API free's a previous allocated tcam element from a
341          * device specific tcam DB.
342          *
343          * [in] tfp
344          *   Pointer to TF handle
345          *
346          * [in] parms
347          *   Pointer to tcam free parameters
348          *
349          * Returns
350          *   - (0) if successful.
351          *   - (-EINVAL) on failure.
352          */
353         int (*tf_dev_free_tcam)(struct tf *tfp,
354                                 struct tf_tcam_free_parms *parms);
355
356         /**
357          * Searches for the specified tcam element in a shadow DB.
358          *
359          * This API searches for the specified tcam element in a
360          * device specific shadow DB. If the element is found the
361          * reference count for the element is updated. If the element
362          * is not found a new element is allocated from the tcam DB
363          * and then inserted into the shadow DB.
364          *
365          * [in] tfp
366          *   Pointer to TF handle
367          *
368          * [in] parms
369          *   Pointer to tcam allocation and search parameters
370          *
371          * Returns
372          *   - (0) if successful.
373          *   - (-EINVAL) on failure.
374          */
375         int (*tf_dev_alloc_search_tcam)
376                         (struct tf *tfp,
377                         struct tf_tcam_alloc_search_parms *parms);
378
379         /**
380          * Sets the specified tcam element.
381          *
382          * This API sets the specified element data by invoking the
383          * firmware.
384          *
385          * [in] tfp
386          *   Pointer to TF handle
387          *
388          * [in] parms
389          *   Pointer to tcam set parameters
390          *
391          * Returns
392          *   - (0) if successful.
393          *   - (-EINVAL) on failure.
394          */
395         int (*tf_dev_set_tcam)(struct tf *tfp,
396                                struct tf_tcam_set_parms *parms);
397
398         /**
399          * Retrieves the specified tcam element.
400          *
401          * This API retrieves the specified element data by invoking the
402          * firmware.
403          *
404          * [in] tfp
405          *   Pointer to TF handle
406          *
407          * [in] parms
408          *   Pointer to tcam get parameters
409          *
410          * Returns
411          *   - (0) if successful.
412          *   - (-EINVAL) on failure.
413          */
414         int (*tf_dev_get_tcam)(struct tf *tfp,
415                                struct tf_tcam_get_parms *parms);
416
417         /**
418          * Insert EM hash entry API
419          *
420          * [in] tfp
421          *   Pointer to TF handle
422          *
423          * [in] parms
424          *   Pointer to E/EM insert parameters
425          *
426          *  Returns:
427          *    0       - Success
428          *    -EINVAL - Error
429          */
430         int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
431                                           struct tf_insert_em_entry_parms *parms);
432
433         /**
434          * Delete EM hash entry API
435          *
436          * [in] tfp
437          *   Pointer to TF handle
438          *
439          * [in] parms
440          *   Pointer to E/EM delete parameters
441          *
442          *    returns:
443          *    0       - Success
444          *    -EINVAL - Error
445          */
446         int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
447                                           struct tf_delete_em_entry_parms *parms);
448
449         /**
450          * Insert EEM hash entry API
451          *
452          * [in] tfp
453          *   Pointer to TF handle
454          *
455          * [in] parms
456          *   Pointer to E/EM insert parameters
457          *
458          *  Returns:
459          *    0       - Success
460          *    -EINVAL - Error
461          */
462         int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
463                                           struct tf_insert_em_entry_parms *parms);
464
465         /**
466          * Delete EEM hash entry API
467          *
468          * [in] tfp
469          *   Pointer to TF handle
470          *
471          * [in] parms
472          *   Pointer to E/EM delete parameters
473          *
474          *    returns:
475          *    0       - Success
476          *    -EINVAL - Error
477          */
478         int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
479                                           struct tf_delete_em_entry_parms *parms);
480
481         /**
482          * Allocate EEM table scope
483          *
484          * [in] tfp
485          *   Pointer to TF handle
486          *
487          * [in] parms
488          *   Pointer to table scope alloc parameters
489          *
490          *    returns:
491          *    0       - Success
492          *    -EINVAL - Error
493          */
494         int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
495                                       struct tf_alloc_tbl_scope_parms *parms);
496
497         /**
498          * Free EEM table scope
499          *
500          * [in] tfp
501          *   Pointer to TF handle
502          *
503          * [in] parms
504          *   Pointer to table scope free parameters
505          *
506          *    returns:
507          *    0       - Success
508          *    -EINVAL - Error
509          */
510         int (*tf_dev_free_tbl_scope)(struct tf *tfp,
511                                      struct tf_free_tbl_scope_parms *parms);
512 };
513
514 /**
515  * Supported device operation structures
516  */
517 extern const struct tf_dev_ops tf_dev_ops_p4_init;
518 extern const struct tf_dev_ops tf_dev_ops_p4;
519
520 #endif /* _TF_DEVICE_H_ */