40395eb773176e2c9e35042eb4b0d5a2b37e52df
[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          * Allocation of a external table type element.
221          *
222          * This API allocates the specified table type element from a
223          * device specific table type DB. The allocated element is
224          * returned.
225          *
226          * [in] tfp
227          *   Pointer to TF handle
228          *
229          * [in] parms
230          *   Pointer to table allocation parameters
231          *
232          * Returns
233          *   - (0) if successful.
234          *   - (-EINVAL) on failure.
235          */
236         int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
237                                     struct tf_tbl_alloc_parms *parms);
238
239         /**
240          * Free of a table type element.
241          *
242          * This API free's a previous allocated table type element from a
243          * device specific table type DB.
244          *
245          * [in] tfp
246          *   Pointer to TF handle
247          *
248          * [in] parms
249          *   Pointer to table free parameters
250          *
251          * Returns
252          *   - (0) if successful.
253          *   - (-EINVAL) on failure.
254          */
255         int (*tf_dev_free_tbl)(struct tf *tfp,
256                                struct tf_tbl_free_parms *parms);
257
258         /**
259          * Free of a external table type element.
260          *
261          * This API free's a previous allocated table type element from a
262          * device specific table type DB.
263          *
264          * [in] tfp
265          *   Pointer to TF handle
266          *
267          * [in] parms
268          *   Pointer to table free parameters
269          *
270          * Returns
271          *   - (0) if successful.
272          *   - (-EINVAL) on failure.
273          */
274         int (*tf_dev_free_ext_tbl)(struct tf *tfp,
275                                    struct tf_tbl_free_parms *parms);
276
277         /**
278          * Searches for the specified table type element in a shadow DB.
279          *
280          * This API searches for the specified table type element in a
281          * device specific shadow DB. If the element is found the
282          * reference count for the element is updated. If the element
283          * is not found a new element is allocated from the table type
284          * DB and then inserted into the shadow DB.
285          *
286          * [in] tfp
287          *   Pointer to TF handle
288          *
289          * [in] parms
290          *   Pointer to table allocation and search parameters
291          *
292          * Returns
293          *   - (0) if successful.
294          *   - (-EINVAL) on failure.
295          */
296         int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
297                                        struct tf_tbl_alloc_search_parms *parms);
298
299         /**
300          * Sets the specified table type element.
301          *
302          * This API sets 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 set parameters
310          *
311          * Returns
312          *   - (0) if successful.
313          *   - (-EINVAL) on failure.
314          */
315         int (*tf_dev_set_tbl)(struct tf *tfp,
316                               struct tf_tbl_set_parms *parms);
317
318         /**
319          * Sets the specified external table type element.
320          *
321          * This API sets the specified element data by invoking the
322          * firmware.
323          *
324          * [in] tfp
325          *   Pointer to TF handle
326          *
327          * [in] parms
328          *   Pointer to table set parameters
329          *
330          * Returns
331          *   - (0) if successful.
332          *   - (-EINVAL) on failure.
333          */
334         int (*tf_dev_set_ext_tbl)(struct tf *tfp,
335                                   struct tf_tbl_set_parms *parms);
336
337         /**
338          * Retrieves the specified table type element.
339          *
340          * This API retrieves the specified element data by invoking the
341          * firmware.
342          *
343          * [in] tfp
344          *   Pointer to TF handle
345          *
346          * [in] parms
347          *   Pointer to table get parameters
348          *
349          * Returns
350          *   - (0) if successful.
351          *   - (-EINVAL) on failure.
352          */
353         int (*tf_dev_get_tbl)(struct tf *tfp,
354                               struct tf_tbl_get_parms *parms);
355
356         /**
357          * Retrieves the specified table type element using 'bulk'
358          * mechanism.
359          *
360          * This API retrieves the specified element data by invoking the
361          * firmware.
362          *
363          * [in] tfp
364          *   Pointer to TF handle
365          *
366          * [in] parms
367          *   Pointer to table get bulk parameters
368          *
369          * Returns
370          *   - (0) if successful.
371          *   - (-EINVAL) on failure.
372          */
373         int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
374                                    struct tf_tbl_get_bulk_parms *parms);
375
376         /**
377          * Allocation of a tcam element.
378          *
379          * This API allocates the specified tcam element from a device
380          * specific tcam DB. The allocated element is returned.
381          *
382          * [in] tfp
383          *   Pointer to TF handle
384          *
385          * [in] parms
386          *   Pointer to tcam allocation parameters
387          *
388          * Returns
389          *   - (0) if successful.
390          *   - (-EINVAL) on failure.
391          */
392         int (*tf_dev_alloc_tcam)(struct tf *tfp,
393                                  struct tf_tcam_alloc_parms *parms);
394
395         /**
396          * Free of a tcam element.
397          *
398          * This API free's a previous allocated tcam element from a
399          * device specific tcam DB.
400          *
401          * [in] tfp
402          *   Pointer to TF handle
403          *
404          * [in] parms
405          *   Pointer to tcam free parameters
406          *
407          * Returns
408          *   - (0) if successful.
409          *   - (-EINVAL) on failure.
410          */
411         int (*tf_dev_free_tcam)(struct tf *tfp,
412                                 struct tf_tcam_free_parms *parms);
413
414         /**
415          * Searches for the specified tcam element in a shadow DB.
416          *
417          * This API searches for the specified tcam element in a
418          * device specific shadow DB. If the element is found the
419          * reference count for the element is updated. If the element
420          * is not found a new element is allocated from the tcam DB
421          * and then inserted into the shadow DB.
422          *
423          * [in] tfp
424          *   Pointer to TF handle
425          *
426          * [in] parms
427          *   Pointer to tcam allocation and search parameters
428          *
429          * Returns
430          *   - (0) if successful.
431          *   - (-EINVAL) on failure.
432          */
433         int (*tf_dev_alloc_search_tcam)
434                         (struct tf *tfp,
435                         struct tf_tcam_alloc_search_parms *parms);
436
437         /**
438          * Sets the specified tcam element.
439          *
440          * This API sets the specified element data by invoking the
441          * firmware.
442          *
443          * [in] tfp
444          *   Pointer to TF handle
445          *
446          * [in] parms
447          *   Pointer to tcam set parameters
448          *
449          * Returns
450          *   - (0) if successful.
451          *   - (-EINVAL) on failure.
452          */
453         int (*tf_dev_set_tcam)(struct tf *tfp,
454                                struct tf_tcam_set_parms *parms);
455
456         /**
457          * Retrieves the specified tcam element.
458          *
459          * This API retrieves the specified element data by invoking the
460          * firmware.
461          *
462          * [in] tfp
463          *   Pointer to TF handle
464          *
465          * [in] parms
466          *   Pointer to tcam get parameters
467          *
468          * Returns
469          *   - (0) if successful.
470          *   - (-EINVAL) on failure.
471          */
472         int (*tf_dev_get_tcam)(struct tf *tfp,
473                                struct tf_tcam_get_parms *parms);
474
475         /**
476          * Insert EM hash entry API
477          *
478          * [in] tfp
479          *   Pointer to TF handle
480          *
481          * [in] parms
482          *   Pointer to E/EM insert parameters
483          *
484          *  Returns:
485          *    0       - Success
486          *    -EINVAL - Error
487          */
488         int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
489                                           struct tf_insert_em_entry_parms *parms);
490
491         /**
492          * Delete EM hash entry API
493          *
494          * [in] tfp
495          *   Pointer to TF handle
496          *
497          * [in] parms
498          *   Pointer to E/EM delete parameters
499          *
500          *    returns:
501          *    0       - Success
502          *    -EINVAL - Error
503          */
504         int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
505                                           struct tf_delete_em_entry_parms *parms);
506
507         /**
508          * Insert EEM hash entry API
509          *
510          * [in] tfp
511          *   Pointer to TF handle
512          *
513          * [in] parms
514          *   Pointer to E/EM insert parameters
515          *
516          *  Returns:
517          *    0       - Success
518          *    -EINVAL - Error
519          */
520         int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
521                                           struct tf_insert_em_entry_parms *parms);
522
523         /**
524          * Delete EEM hash entry API
525          *
526          * [in] tfp
527          *   Pointer to TF handle
528          *
529          * [in] parms
530          *   Pointer to E/EM delete parameters
531          *
532          *    returns:
533          *    0       - Success
534          *    -EINVAL - Error
535          */
536         int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
537                                           struct tf_delete_em_entry_parms *parms);
538
539         /**
540          * Allocate EEM table scope
541          *
542          * [in] tfp
543          *   Pointer to TF handle
544          *
545          * [in] parms
546          *   Pointer to table scope alloc parameters
547          *
548          *    returns:
549          *    0       - Success
550          *    -EINVAL - Error
551          */
552         int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
553                                       struct tf_alloc_tbl_scope_parms *parms);
554
555         /**
556          * Free EEM table scope
557          *
558          * [in] tfp
559          *   Pointer to TF handle
560          *
561          * [in] parms
562          *   Pointer to table scope free parameters
563          *
564          *    returns:
565          *    0       - Success
566          *    -EINVAL - Error
567          */
568         int (*tf_dev_free_tbl_scope)(struct tf *tfp,
569                                      struct tf_free_tbl_scope_parms *parms);
570 };
571
572 /**
573  * Supported device operation structures
574  */
575 extern const struct tf_dev_ops tf_dev_ops_p4_init;
576 extern const struct tf_dev_ops tf_dev_ops_p4;
577
578 #endif /* _TF_DEVICE_H_ */