0bc7090568f3e9419d79df685db9f93d9e636cd6
[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 #include "tf_if_tbl.h"
14 #include "tf_global_cfg.h"
15
16 struct tf;
17 struct tf_session;
18
19 /**
20  * Device module types
21  */
22 enum tf_device_module_type {
23         /**
24          * Identifier module
25          */
26         TF_DEVICE_MODULE_TYPE_IDENTIFIER,
27         /**
28          * Table type module
29          */
30         TF_DEVICE_MODULE_TYPE_TABLE,
31         /**
32          * TCAM module
33          */
34         TF_DEVICE_MODULE_TYPE_TCAM,
35         /**
36          * EM module
37          */
38         TF_DEVICE_MODULE_TYPE_EM,
39         TF_DEVICE_MODULE_TYPE_MAX
40 };
41
42 /**
43  * The Device module provides a general device template. A supported
44  * device type should implement one or more of the listed function
45  * pointers according to its capabilities.
46  *
47  * If a device function pointer is NULL the device capability is not
48  * supported.
49  */
50
51 /**
52  * TF device information
53  */
54 struct tf_dev_info {
55         enum tf_device_type type;
56         const struct tf_dev_ops *ops;
57 };
58
59 /**
60  * @page device Device
61  *
62  * @ref tf_dev_bind
63  *
64  * @ref tf_dev_unbind
65  */
66
67 /**
68  * Device bind handles the initialization of the specified device
69  * type.
70  *
71  * [in] tfp
72  *   Pointer to TF handle
73  *
74  * [in] type
75  *   Device type
76  *
77  * [in] resources
78  *   Pointer to resource allocation information
79  *
80  * [out] dev_handle
81  *   Device handle
82  *
83  * Returns
84  *   - (0) if successful.
85  *   - (-EINVAL) parameter failure.
86  *   - (-ENODEV) no such device supported.
87  */
88 int tf_dev_bind(struct tf *tfp,
89                 enum tf_device_type type,
90                 bool shadow_copy,
91                 struct tf_session_resources *resources,
92                 struct tf_dev_info *dev_handle);
93
94 /**
95  * Device release handles cleanup of the device specific information.
96  *
97  * [in] tfp
98  *   Pointer to TF handle
99  *
100  * [in] dev_handle
101  *   Device handle
102  *
103  * Returns
104  *   - (0) if successful.
105  *   - (-EINVAL) parameter failure.
106  *   - (-ENODEV) no such device supported.
107  */
108 int tf_dev_unbind(struct tf *tfp,
109                   struct tf_dev_info *dev_handle);
110
111 /**
112  * Truflow device specific function hooks structure
113  *
114  * The following device hooks can be defined; unless noted otherwise,
115  * they are optional and can be filled with a null pointer. The
116  * purpose of these hooks is to support Truflow device operations for
117  * different device variants.
118  */
119 struct tf_dev_ops {
120         /**
121          * Retrieves the MAX number of resource types that the device
122          * supports.
123          *
124          * [in] tfp
125          *   Pointer to TF handle
126          *
127          * [out] max_types
128          *   Pointer to MAX number of types the device supports
129          *
130          * Returns
131          *   - (0) if successful.
132          *   - (-EINVAL) on failure.
133          */
134         int (*tf_dev_get_max_types)(struct tf *tfp,
135                                     uint16_t *max_types);
136
137         /**
138          * Retrieves the WC TCAM slice information that the device
139          * supports.
140          *
141          * [in] tfp
142          *   Pointer to TF handle
143          *
144          * [in] type
145          *   TCAM table type
146          *
147          * [in] key_sz
148          *   Key size
149          *
150          * [out] num_slices_per_row
151          *   Pointer to number of slices per row the device supports
152          *
153          * Returns
154          *   - (0) if successful.
155          *   - (-EINVAL) on failure.
156          */
157         int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
158                                           enum tf_tcam_tbl_type type,
159                                           uint16_t key_sz,
160                                           uint16_t *num_slices_per_row);
161
162         /**
163          * Allocation of an identifier element.
164          *
165          * This API allocates the specified identifier element from a
166          * device specific identifier DB. The allocated element is
167          * returned.
168          *
169          * [in] tfp
170          *   Pointer to TF handle
171          *
172          * [in] parms
173          *   Pointer to identifier allocation parameters
174          *
175          * Returns
176          *   - (0) if successful.
177          *   - (-EINVAL) on failure.
178          */
179         int (*tf_dev_alloc_ident)(struct tf *tfp,
180                                   struct tf_ident_alloc_parms *parms);
181
182         /**
183          * Free of an identifier element.
184          *
185          * This API free's a previous allocated identifier element from a
186          * device specific identifier DB.
187          *
188          * [in] tfp
189          *   Pointer to TF handle
190          *
191          * [in] parms
192          *   Pointer to identifier free parameters
193          *
194          * Returns
195          *   - (0) if successful.
196          *   - (-EINVAL) on failure.
197          */
198         int (*tf_dev_free_ident)(struct tf *tfp,
199                                  struct tf_ident_free_parms *parms);
200
201         /**
202          * Allocation of a table type element.
203          *
204          * This API allocates the specified table type element from a
205          * device specific table type DB. The allocated element is
206          * returned.
207          *
208          * [in] tfp
209          *   Pointer to TF handle
210          *
211          * [in] parms
212          *   Pointer to table allocation parameters
213          *
214          * Returns
215          *   - (0) if successful.
216          *   - (-EINVAL) on failure.
217          */
218         int (*tf_dev_alloc_tbl)(struct tf *tfp,
219                                 struct tf_tbl_alloc_parms *parms);
220
221         /**
222          * Allocation of a external table type element.
223          *
224          * This API allocates the specified table type element from a
225          * device specific table type DB. The allocated element is
226          * returned.
227          *
228          * [in] tfp
229          *   Pointer to TF handle
230          *
231          * [in] parms
232          *   Pointer to table allocation parameters
233          *
234          * Returns
235          *   - (0) if successful.
236          *   - (-EINVAL) on failure.
237          */
238         int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
239                                     struct tf_tbl_alloc_parms *parms);
240
241         /**
242          * Free of a table type element.
243          *
244          * This API free's a previous allocated table type element from a
245          * device specific table type DB.
246          *
247          * [in] tfp
248          *   Pointer to TF handle
249          *
250          * [in] parms
251          *   Pointer to table free parameters
252          *
253          * Returns
254          *   - (0) if successful.
255          *   - (-EINVAL) on failure.
256          */
257         int (*tf_dev_free_tbl)(struct tf *tfp,
258                                struct tf_tbl_free_parms *parms);
259
260         /**
261          * Free of a external table type element.
262          *
263          * This API free's a previous allocated table type element from a
264          * device specific table type DB.
265          *
266          * [in] tfp
267          *   Pointer to TF handle
268          *
269          * [in] parms
270          *   Pointer to table free parameters
271          *
272          * Returns
273          *   - (0) if successful.
274          *   - (-EINVAL) on failure.
275          */
276         int (*tf_dev_free_ext_tbl)(struct tf *tfp,
277                                    struct tf_tbl_free_parms *parms);
278
279         /**
280          * Searches for the specified table type element in a shadow DB.
281          *
282          * This API searches for the specified table type element in a
283          * device specific shadow DB. If the element is found the
284          * reference count for the element is updated. If the element
285          * is not found a new element is allocated from the table type
286          * DB and then inserted into the shadow DB.
287          *
288          * [in] tfp
289          *   Pointer to TF handle
290          *
291          * [in] parms
292          *   Pointer to table allocation and search parameters
293          *
294          * Returns
295          *   - (0) if successful.
296          *   - (-EINVAL) on failure.
297          */
298         int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
299                                        struct tf_tbl_alloc_search_parms *parms);
300
301         /**
302          * Sets the specified table type element.
303          *
304          * This API sets the specified element data by invoking the
305          * firmware.
306          *
307          * [in] tfp
308          *   Pointer to TF handle
309          *
310          * [in] parms
311          *   Pointer to table set parameters
312          *
313          * Returns
314          *   - (0) if successful.
315          *   - (-EINVAL) on failure.
316          */
317         int (*tf_dev_set_tbl)(struct tf *tfp,
318                               struct tf_tbl_set_parms *parms);
319
320         /**
321          * Sets the specified external table type element.
322          *
323          * This API sets the specified element data by invoking the
324          * firmware.
325          *
326          * [in] tfp
327          *   Pointer to TF handle
328          *
329          * [in] parms
330          *   Pointer to table set parameters
331          *
332          * Returns
333          *   - (0) if successful.
334          *   - (-EINVAL) on failure.
335          */
336         int (*tf_dev_set_ext_tbl)(struct tf *tfp,
337                                   struct tf_tbl_set_parms *parms);
338
339         /**
340          * Retrieves the specified table type element.
341          *
342          * This API retrieves the specified element data by invoking the
343          * firmware.
344          *
345          * [in] tfp
346          *   Pointer to TF handle
347          *
348          * [in] parms
349          *   Pointer to table get parameters
350          *
351          * Returns
352          *   - (0) if successful.
353          *   - (-EINVAL) on failure.
354          */
355         int (*tf_dev_get_tbl)(struct tf *tfp,
356                               struct tf_tbl_get_parms *parms);
357
358         /**
359          * Retrieves the specified table type element using 'bulk'
360          * mechanism.
361          *
362          * This API retrieves the specified element data by invoking the
363          * firmware.
364          *
365          * [in] tfp
366          *   Pointer to TF handle
367          *
368          * [in] parms
369          *   Pointer to table get bulk parameters
370          *
371          * Returns
372          *   - (0) if successful.
373          *   - (-EINVAL) on failure.
374          */
375         int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
376                                    struct tf_tbl_get_bulk_parms *parms);
377
378         /**
379          * Allocation of a tcam element.
380          *
381          * This API allocates the specified tcam element from a device
382          * specific tcam DB. The allocated element is returned.
383          *
384          * [in] tfp
385          *   Pointer to TF handle
386          *
387          * [in] parms
388          *   Pointer to tcam allocation parameters
389          *
390          * Returns
391          *   - (0) if successful.
392          *   - (-EINVAL) on failure.
393          */
394         int (*tf_dev_alloc_tcam)(struct tf *tfp,
395                                  struct tf_tcam_alloc_parms *parms);
396
397         /**
398          * Free of a tcam element.
399          *
400          * This API free's a previous allocated tcam element from a
401          * device specific tcam DB.
402          *
403          * [in] tfp
404          *   Pointer to TF handle
405          *
406          * [in] parms
407          *   Pointer to tcam free parameters
408          *
409          * Returns
410          *   - (0) if successful.
411          *   - (-EINVAL) on failure.
412          */
413         int (*tf_dev_free_tcam)(struct tf *tfp,
414                                 struct tf_tcam_free_parms *parms);
415
416         /**
417          * Searches for the specified tcam element in a shadow DB.
418          *
419          * This API searches for the specified tcam element in a
420          * device specific shadow DB. If the element is found the
421          * reference count for the element is updated. If the element
422          * is not found a new element is allocated from the tcam DB
423          * and then inserted into the shadow DB.
424          *
425          * [in] tfp
426          *   Pointer to TF handle
427          *
428          * [in] parms
429          *   Pointer to tcam allocation and search parameters
430          *
431          * Returns
432          *   - (0) if successful.
433          *   - (-EINVAL) on failure.
434          */
435         int (*tf_dev_alloc_search_tcam)
436                         (struct tf *tfp,
437                         struct tf_tcam_alloc_search_parms *parms);
438
439         /**
440          * Sets the specified tcam element.
441          *
442          * This API sets the specified element data by invoking the
443          * firmware.
444          *
445          * [in] tfp
446          *   Pointer to TF handle
447          *
448          * [in] parms
449          *   Pointer to tcam set parameters
450          *
451          * Returns
452          *   - (0) if successful.
453          *   - (-EINVAL) on failure.
454          */
455         int (*tf_dev_set_tcam)(struct tf *tfp,
456                                struct tf_tcam_set_parms *parms);
457
458         /**
459          * Retrieves the specified tcam element.
460          *
461          * This API retrieves the specified element data by invoking the
462          * firmware.
463          *
464          * [in] tfp
465          *   Pointer to TF handle
466          *
467          * [in] parms
468          *   Pointer to tcam get parameters
469          *
470          * Returns
471          *   - (0) if successful.
472          *   - (-EINVAL) on failure.
473          */
474         int (*tf_dev_get_tcam)(struct tf *tfp,
475                                struct tf_tcam_get_parms *parms);
476
477         /**
478          * Insert EM hash entry API
479          *
480          * [in] tfp
481          *   Pointer to TF handle
482          *
483          * [in] parms
484          *   Pointer to E/EM insert parameters
485          *
486          *  Returns:
487          *    0       - Success
488          *    -EINVAL - Error
489          */
490         int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
491                                           struct tf_insert_em_entry_parms *parms);
492
493         /**
494          * Delete EM hash entry API
495          *
496          * [in] tfp
497          *   Pointer to TF handle
498          *
499          * [in] parms
500          *   Pointer to E/EM delete parameters
501          *
502          *    returns:
503          *    0       - Success
504          *    -EINVAL - Error
505          */
506         int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
507                                           struct tf_delete_em_entry_parms *parms);
508
509         /**
510          * Insert EEM hash entry API
511          *
512          * [in] tfp
513          *   Pointer to TF handle
514          *
515          * [in] parms
516          *   Pointer to E/EM insert parameters
517          *
518          *  Returns:
519          *    0       - Success
520          *    -EINVAL - Error
521          */
522         int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
523                                           struct tf_insert_em_entry_parms *parms);
524
525         /**
526          * Delete EEM hash entry API
527          *
528          * [in] tfp
529          *   Pointer to TF handle
530          *
531          * [in] parms
532          *   Pointer to E/EM delete parameters
533          *
534          *    returns:
535          *    0       - Success
536          *    -EINVAL - Error
537          */
538         int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
539                                           struct tf_delete_em_entry_parms *parms);
540
541         /**
542          * Allocate EEM table scope
543          *
544          * [in] tfp
545          *   Pointer to TF handle
546          *
547          * [in] parms
548          *   Pointer to table scope alloc parameters
549          *
550          *    returns:
551          *    0       - Success
552          *    -EINVAL - Error
553          */
554         int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
555                                       struct tf_alloc_tbl_scope_parms *parms);
556
557         /**
558          * Free EEM table scope
559          *
560          * [in] tfp
561          *   Pointer to TF handle
562          *
563          * [in] parms
564          *   Pointer to table scope free parameters
565          *
566          *    returns:
567          *    0       - Success
568          *    -EINVAL - Error
569          */
570         int (*tf_dev_free_tbl_scope)(struct tf *tfp,
571                                      struct tf_free_tbl_scope_parms *parms);
572
573         /**
574          * Sets the specified interface table type element.
575          *
576          * This API sets the specified element data by invoking the
577          * firmware.
578          *
579          * [in] tfp
580          *   Pointer to TF handle
581          *
582          * [in] parms
583          *   Pointer to interface table set parameters
584          *
585          * Returns
586          *   - (0) if successful.
587          *   - (-EINVAL) on failure.
588          */
589         int (*tf_dev_set_if_tbl)(struct tf *tfp,
590                                  struct tf_if_tbl_set_parms *parms);
591
592         /**
593          * Retrieves the specified interface table type element.
594          *
595          * This API retrieves the specified element data by invoking the
596          * firmware.
597          *
598          * [in] tfp
599          *   Pointer to TF handle
600          *
601          * [in] parms
602          *   Pointer to table get parameters
603          *
604          * Returns
605          *   - (0) if successful.
606          *   - (-EINVAL) on failure.
607          */
608         int (*tf_dev_get_if_tbl)(struct tf *tfp,
609                                  struct tf_if_tbl_get_parms *parms);
610
611         /**
612          * Update global cfg
613          *
614          * [in] tfp
615          *   Pointer to TF handle
616          *
617          * [in] parms
618          *   Pointer to global cfg parameters
619          *
620          *    returns:
621          *    0       - Success
622          *    -EINVAL - Error
623          */
624         int (*tf_dev_set_global_cfg)(struct tf *tfp,
625                                      struct tf_dev_global_cfg_parms *parms);
626
627         /**
628          * Get global cfg
629          *
630          * [in] tfp
631          *   Pointer to TF handle
632          *
633          * [in] parms
634          *   Pointer to global cfg parameters
635          *
636          *    returns:
637          *    0       - Success
638          *    -EINVAL - Error
639          */
640         int (*tf_dev_get_global_cfg)(struct tf *tfp,
641                                      struct tf_dev_global_cfg_parms *parms);
642 };
643
644 /**
645  * Supported device operation structures
646  */
647 extern const struct tf_dev_ops tf_dev_ops_p4_init;
648 extern const struct tf_dev_ops tf_dev_ops_p4;
649
650 #endif /* _TF_DEVICE_H_ */