16c2fe0f640293ae6f62225898b5a00661f805ed
[dpdk.git] / drivers / net / bnxt / tf_core / tf_device.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019-2021 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  * The Device module provides a general device template. A supported
21  * device type should implement one or more of the listed function
22  * pointers according to its capabilities.
23  *
24  * If a device function pointer is NULL the device capability is not
25  * supported.
26  */
27
28 /**
29  * TF device information
30  */
31 struct tf_dev_info {
32         enum tf_device_type type;
33         const struct tf_dev_ops *ops;
34 };
35
36 /**
37  * @page device Device
38  *
39  * @ref tf_dev_bind
40  *
41  * @ref tf_dev_unbind
42  */
43
44 /**
45  * Device bind handles the initialization of the specified device
46  * type.
47  *
48  * [in] tfp
49  *   Pointer to TF handle
50  *
51  * [in] type
52  *   Device type
53  *
54  * [in] resources
55  *   Pointer to resource allocation information
56  *
57  * [out] dev_handle
58  *   Device handle
59  *
60  * Returns
61  *   - (0) if successful.
62  *   - (-EINVAL) parameter failure.
63  *   - (-ENODEV) no such device supported.
64  */
65 int tf_dev_bind(struct tf *tfp,
66                 enum tf_device_type type,
67                 bool shadow_copy,
68                 struct tf_session_resources *resources,
69                 struct tf_dev_info *dev_handle);
70
71 /**
72  * Device release handles cleanup of the device specific information.
73  *
74  * [in] tfp
75  *   Pointer to TF handle
76  *
77  * [in] dev_handle
78  *   Device handle
79  *
80  * Returns
81  *   - (0) if successful.
82  *   - (-EINVAL) parameter failure.
83  *   - (-ENODEV) no such device supported.
84  */
85 int tf_dev_unbind(struct tf *tfp,
86                   struct tf_dev_info *dev_handle);
87
88 int
89 tf_dev_bind_ops(enum tf_device_type type,
90                 struct tf_dev_info *dev_handle);
91
92 /**
93  * Truflow device specific function hooks structure
94  *
95  * The following device hooks can be defined; unless noted otherwise,
96  * they are optional and can be filled with a null pointer. The
97  * purpose of these hooks is to support Truflow device operations for
98  * different device variants.
99  */
100 struct tf_dev_ops {
101         /**
102          * Retrieves the MAX number of resource types that the device
103          * supports.
104          *
105          * [in] tfp
106          *   Pointer to TF handle
107          *
108          * [out] max_types
109          *   Pointer to MAX number of types the device supports
110          *
111          * Returns
112          *   - (0) if successful.
113          *   - (-EINVAL) on failure.
114          */
115         int (*tf_dev_get_max_types)(struct tf *tfp,
116                                     uint16_t *max_types);
117
118         /**
119          * Retrieves the string description for the CFA resource
120          * type
121          *
122          * [in] tfp
123          *   Pointer to TF handle
124          *
125          * [in] resource_id
126          *   HCAPI cfa resource type id
127          *
128          * [out] resource_str
129          *   Pointer to a string
130          *
131          * Returns
132          *   - (0) if successful.
133          *   - (-EINVAL) on failure.
134          */
135         int (*tf_dev_get_resource_str)(struct tf *tfp,
136                                        uint16_t resource_id,
137                                        const char **resource_str);
138
139
140         /**
141          * Retrieves the WC TCAM slice information that the device
142          * supports.
143          *
144          * [in] tfp
145          *   Pointer to TF handle
146          *
147          * [in] type
148          *   TCAM table type
149          *
150          * [in] key_sz
151          *   Key size
152          *
153          * [out] num_slices_per_row
154          *   Pointer to number of slices per row the device supports
155          *
156          * Returns
157          *   - (0) if successful.
158          *   - (-EINVAL) on failure.
159          */
160         int (*tf_dev_get_tcam_slice_info)(struct tf *tfp,
161                                           enum tf_tcam_tbl_type type,
162                                           uint16_t key_sz,
163                                           uint16_t *num_slices_per_row);
164
165         /**
166          * Allocation of an identifier element.
167          *
168          * This API allocates the specified identifier element from a
169          * device specific identifier DB. The allocated element is
170          * returned.
171          *
172          * [in] tfp
173          *   Pointer to TF handle
174          *
175          * [in] parms
176          *   Pointer to identifier allocation parameters
177          *
178          * Returns
179          *   - (0) if successful.
180          *   - (-EINVAL) on failure.
181          */
182         int (*tf_dev_alloc_ident)(struct tf *tfp,
183                                   struct tf_ident_alloc_parms *parms);
184
185         /**
186          * Free of an identifier element.
187          *
188          * This API free's a previous allocated identifier element from a
189          * device specific identifier DB.
190          *
191          * [in] tfp
192          *   Pointer to TF handle
193          *
194          * [in] parms
195          *   Pointer to identifier free parameters
196          *
197          * Returns
198          *   - (0) if successful.
199          *   - (-EINVAL) on failure.
200          */
201         int (*tf_dev_free_ident)(struct tf *tfp,
202                                  struct tf_ident_free_parms *parms);
203
204         /**
205          * Search of an identifier element.
206          *
207          * This API search the specified identifier element from a
208          * device specific identifier shadow DB. The allocated element
209          * is returned.
210          *
211          * [in] tfp
212          *   Pointer to TF handle
213          *
214          * [in] parms
215          *   Pointer to identifier search parameters
216          *
217          * Returns
218          *   - (0) if successful.
219          *   - (-EINVAL) on failure.
220          */
221         int (*tf_dev_search_ident)(struct tf *tfp,
222                                    struct tf_ident_search_parms *parms);
223
224         /**
225          * Retrieves the identifier resource info.
226          *
227          * This API retrieves the identifier resource info from the rm db.
228          *
229          * [in] tfp
230          *   Pointer to TF handle
231          *
232          * [in] parms
233          *   Pointer to identifier info
234          *
235          * Returns
236          *   - (0) if successful.
237          *   - (-EINVAL) on failure.
238          */
239         int (*tf_dev_get_ident_resc_info)(struct tf *tfp,
240                                           struct tf_identifier_resource_info *parms);
241
242         /**
243          * Get SRAM table information.
244          *
245          * Converts an internal RM allocated element offset to
246          * a user address and vice versa.
247          *
248          * [in] tfp
249          *   Pointer to TF handle
250          *
251          * [in] type
252          *   Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
253          *
254          * [in/out] base
255          *   Pointer to the base address of the associated table type.
256          *
257          * [in/out] shift
258          *   Pointer to any shift required for the associated table type.
259          *
260          * Returns
261          *   - (0) if successful.
262          *   - (-EINVAL) on failure.
263          */
264         int (*tf_dev_get_tbl_info)(struct tf *tfp,
265                                    void *tbl_db,
266                                    enum tf_tbl_type type,
267                                    uint16_t *base,
268                                    uint16_t *shift);
269
270         /**
271          * Allocation of an index table type element.
272          *
273          * This API allocates the specified table type element from a
274          * device specific table type DB. The allocated element is
275          * returned.
276          *
277          * [in] tfp
278          *   Pointer to TF handle
279          *
280          * [in] parms
281          *   Pointer to table allocation parameters
282          *
283          * Returns
284          *   - (0) if successful.
285          *   - (-EINVAL) on failure.
286          */
287         int (*tf_dev_alloc_tbl)(struct tf *tfp,
288                                 struct tf_tbl_alloc_parms *parms);
289
290         /**
291          * Allocation of a external table type element.
292          *
293          * This API allocates the specified table type element from a
294          * device specific table type DB. The allocated element is
295          * returned.
296          *
297          * [in] tfp
298          *   Pointer to TF handle
299          *
300          * [in] parms
301          *   Pointer to table allocation parameters
302          *
303          * Returns
304          *   - (0) if successful.
305          *   - (-EINVAL) on failure.
306          */
307         int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
308                                     struct tf_tbl_alloc_parms *parms);
309
310         /**
311          * Free of a table type element.
312          *
313          * This API free's a previous allocated table type element from a
314          * device specific table type DB.
315          *
316          * [in] tfp
317          *   Pointer to TF handle
318          *
319          * [in] parms
320          *   Pointer to table free parameters
321          *
322          * Returns
323          *   - (0) if successful.
324          *   - (-EINVAL) on failure.
325          */
326         int (*tf_dev_free_tbl)(struct tf *tfp,
327                                struct tf_tbl_free_parms *parms);
328
329         /**
330          * Free of a external table type element.
331          *
332          * This API free's a previous allocated table type element from a
333          * device specific table type DB.
334          *
335          * [in] tfp
336          *   Pointer to TF handle
337          *
338          * [in] parms
339          *   Pointer to table free parameters
340          *
341          * Returns
342          *   - (0) if successful.
343          *   - (-EINVAL) on failure.
344          */
345         int (*tf_dev_free_ext_tbl)(struct tf *tfp,
346                                    struct tf_tbl_free_parms *parms);
347
348         /**
349          * Searches for the specified table type element in a shadow DB.
350          *
351          * This API searches for the specified table type element in a
352          * device specific shadow DB. If the element is found the
353          * reference count for the element is updated. If the element
354          * is not found a new element is allocated from the table type
355          * DB and then inserted into the shadow DB.
356          *
357          * [in] tfp
358          *   Pointer to TF handle
359          *
360          * [in] parms
361          *   Pointer to table allocation and search parameters
362          *
363          * Returns
364          *   - (0) if successful.
365          *   - (-EINVAL) on failure.
366          */
367         int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
368                                        struct tf_tbl_alloc_search_parms *parms);
369
370         /**
371          * Sets the specified table type element.
372          *
373          * This API sets the specified element data by invoking the
374          * firmware.
375          *
376          * [in] tfp
377          *   Pointer to TF handle
378          *
379          * [in] parms
380          *   Pointer to table set parameters
381          *
382          * Returns
383          *   - (0) if successful.
384          *   - (-EINVAL) on failure.
385          */
386         int (*tf_dev_set_tbl)(struct tf *tfp,
387                               struct tf_tbl_set_parms *parms);
388
389         /**
390          * Sets the specified external table type element.
391          *
392          * This API sets the specified element data by invoking the
393          * firmware.
394          *
395          * [in] tfp
396          *   Pointer to TF handle
397          *
398          * [in] parms
399          *   Pointer to table set parameters
400          *
401          * Returns
402          *   - (0) if successful.
403          *   - (-EINVAL) on failure.
404          */
405         int (*tf_dev_set_ext_tbl)(struct tf *tfp,
406                                   struct tf_tbl_set_parms *parms);
407
408         /**
409          * Retrieves the specified table type element.
410          *
411          * This API retrieves the specified element data by invoking the
412          * firmware.
413          *
414          * [in] tfp
415          *   Pointer to TF handle
416          *
417          * [in] parms
418          *   Pointer to table get parameters
419          *
420          * Returns
421          *   - (0) if successful.
422          *   - (-EINVAL) on failure.
423          */
424         int (*tf_dev_get_tbl)(struct tf *tfp,
425                               struct tf_tbl_get_parms *parms);
426
427         /**
428          * Retrieves the specified table type element using 'bulk'
429          * mechanism.
430          *
431          * This API retrieves the specified element data by invoking the
432          * firmware.
433          *
434          * [in] tfp
435          *   Pointer to TF handle
436          *
437          * [in] parms
438          *   Pointer to table get bulk parameters
439          *
440          * Returns
441          *   - (0) if successful.
442          *   - (-EINVAL) on failure.
443          */
444         int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
445                                    struct tf_tbl_get_bulk_parms *parms);
446
447         /**
448          * Retrieves the table resource info.
449          *
450          * This API retrieves the table resource info from the rm db.
451          *
452          * [in] tfp
453          *   Pointer to TF handle
454          *
455          * [in] parms
456          *   Pointer to tbl info
457          *
458          * Returns
459          *   - (0) if successful.
460          *   - (-EINVAL) on failure.
461          */
462         int (*tf_dev_get_tbl_resc_info)(struct tf *tfp,
463                                          struct tf_tbl_resource_info *parms);
464
465         /**
466          * Allocation of a tcam element.
467          *
468          * This API allocates the specified tcam element from a device
469          * specific tcam DB. The allocated element is returned.
470          *
471          * [in] tfp
472          *   Pointer to TF handle
473          *
474          * [in] parms
475          *   Pointer to tcam allocation parameters
476          *
477          * Returns
478          *   - (0) if successful.
479          *   - (-EINVAL) on failure.
480          */
481         int (*tf_dev_alloc_tcam)(struct tf *tfp,
482                                  struct tf_tcam_alloc_parms *parms);
483
484         /**
485          * Free of a tcam element.
486          *
487          * This API free's a previous allocated tcam element from a
488          * device specific tcam DB.
489          *
490          * [in] tfp
491          *   Pointer to TF handle
492          *
493          * [in] parms
494          *   Pointer to tcam free parameters
495          *
496          * Returns
497          *   - (0) if successful.
498          *   - (-EINVAL) on failure.
499          */
500         int (*tf_dev_free_tcam)(struct tf *tfp,
501                                 struct tf_tcam_free_parms *parms);
502
503         /**
504          * Searches for the specified tcam element in a shadow DB.
505          *
506          * This API searches for the specified tcam element in a
507          * device specific shadow DB. If the element is found the
508          * reference count for the element is updated. If the element
509          * is not found a new element is allocated from the tcam DB
510          * and then inserted into the shadow DB.
511          *
512          * [in] tfp
513          *   Pointer to TF handle
514          *
515          * [in] parms
516          *   Pointer to tcam allocation and search parameters
517          *
518          * Returns
519          *   - (0) if successful.
520          *   - (-EINVAL) on failure.
521          */
522         int (*tf_dev_alloc_search_tcam)
523                         (struct tf *tfp,
524                         struct tf_tcam_alloc_search_parms *parms);
525
526         /**
527          * Sets the specified tcam element.
528          *
529          * This API sets the specified element data by invoking the
530          * firmware.
531          *
532          * [in] tfp
533          *   Pointer to TF handle
534          *
535          * [in] parms
536          *   Pointer to tcam set parameters
537          *
538          * Returns
539          *   - (0) if successful.
540          *   - (-EINVAL) on failure.
541          */
542         int (*tf_dev_set_tcam)(struct tf *tfp,
543                                struct tf_tcam_set_parms *parms);
544
545         /**
546          * Retrieves the specified tcam element.
547          *
548          * This API retrieves the specified element data by invoking the
549          * firmware.
550          *
551          * [in] tfp
552          *   Pointer to TF handle
553          *
554          * [in] parms
555          *   Pointer to tcam get parameters
556          *
557          * Returns
558          *   - (0) if successful.
559          *   - (-EINVAL) on failure.
560          */
561         int (*tf_dev_get_tcam)(struct tf *tfp,
562                                struct tf_tcam_get_parms *parms);
563
564         /**
565          * Retrieves the tcam resource info.
566          *
567          * This API retrieves the tcam resource info from the rm db.
568          *
569          * [in] tfp
570          *   Pointer to TF handle
571          *
572          * [in] parms
573          *   Pointer to tcam info
574          *
575          * Returns
576          *   - (0) if successful.
577          *   - (-EINVAL) on failure.
578          */
579         int (*tf_dev_get_tcam_resc_info)(struct tf *tfp,
580                                          struct tf_tcam_resource_info *parms);
581
582         /**
583          * Insert EM hash entry API
584          *
585          * [in] tfp
586          *   Pointer to TF handle
587          *
588          * [in] parms
589          *   Pointer to E/EM insert parameters
590          *
591          *  Returns:
592          *    0       - Success
593          *    -EINVAL - Error
594          */
595         int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
596                                           struct tf_insert_em_entry_parms *parms);
597
598         /**
599          * Delete EM hash entry API
600          *
601          * [in] tfp
602          *   Pointer to TF handle
603          *
604          * [in] parms
605          *   Pointer to E/EM delete parameters
606          *
607          *    returns:
608          *    0       - Success
609          *    -EINVAL - Error
610          */
611         int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
612                                           struct tf_delete_em_entry_parms *parms);
613
614         /**
615          * Insert EEM hash entry API
616          *
617          * [in] tfp
618          *   Pointer to TF handle
619          *
620          * [in] parms
621          *   Pointer to E/EM insert parameters
622          *
623          *  Returns:
624          *    0       - Success
625          *    -EINVAL - Error
626          */
627         int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
628                                           struct tf_insert_em_entry_parms *parms);
629
630         /**
631          * Delete EEM hash entry API
632          *
633          * [in] tfp
634          *   Pointer to TF handle
635          *
636          * [in] parms
637          *   Pointer to E/EM delete parameters
638          *
639          *    returns:
640          *    0       - Success
641          *    -EINVAL - Error
642          */
643         int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
644                                           struct tf_delete_em_entry_parms *parms);
645
646         /**
647          * Retrieves the em resource info.
648          *
649          * This API retrieves the em resource info from the rm db.
650          *
651          * [in] tfp
652          *   Pointer to TF handle
653          *
654          * [in] parms
655          *   Pointer to em info
656          *
657          * Returns
658          *   - (0) if successful.
659          *   - (-EINVAL) on failure.
660          */
661         int (*tf_dev_get_em_resc_info)(struct tf *tfp,
662                                        struct tf_em_resource_info *parms);
663
664         /**
665          * Allocate EEM table scope
666          *
667          * [in] tfp
668          *   Pointer to TF handle
669          *
670          * [in] parms
671          *   Pointer to table scope alloc parameters
672          *
673          *    returns:
674          *    0       - Success
675          *    -EINVAL - Error
676          */
677         int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
678                                       struct tf_alloc_tbl_scope_parms *parms);
679         /**
680          * Map EEM parif
681          *
682          * [in] tfp
683          *   Pointer to TF handle
684          *
685          * [in] pf
686          * PF associated with the table scope
687          *
688          * [in] parif_bitmask
689          * Bitmask of PARIFs to enable
690          *
691          * [in/out] pointer to the parif_2_pf data to be updated
692          *
693          * [in/out] pointer to the parif_2_pf mask to be updated
694          *
695          * [in] sz_in_bytes - number of bytes to be written
696          *
697          *    returns:
698          *    0       - Success
699          *    -EINVAL - Error
700          */
701         int (*tf_dev_map_parif)(struct tf *tfp,
702                                 uint16_t parif_bitmask,
703                                 uint16_t pf,
704                                 uint8_t *data,
705                                 uint8_t *mask,
706                                 uint16_t sz_in_bytes);
707         /**
708          * Map EEM table scope
709          *
710          * [in] tfp
711          *   Pointer to TF handle
712          *
713          * [in] parms
714          *   Pointer to table scope map parameters
715          *
716          *    returns:
717          *    0       - Success
718          *    -EINVAL - Error
719          */
720         int (*tf_dev_map_tbl_scope)(struct tf *tfp,
721                                     struct tf_map_tbl_scope_parms *parms);
722
723         /**
724          * Free EEM table scope
725          *
726          * [in] tfp
727          *   Pointer to TF handle
728          *
729          * [in] parms
730          *   Pointer to table scope free parameters
731          *
732          *    returns:
733          *    0       - Success
734          *    -EINVAL - Error
735          */
736         int (*tf_dev_free_tbl_scope)(struct tf *tfp,
737                                      struct tf_free_tbl_scope_parms *parms);
738
739         /**
740          * Sets the specified interface table type element.
741          *
742          * This API sets the specified element data by invoking the
743          * firmware.
744          *
745          * [in] tfp
746          *   Pointer to TF handle
747          *
748          * [in] parms
749          *   Pointer to interface table set parameters
750          *
751          * Returns
752          *   - (0) if successful.
753          *   - (-EINVAL) on failure.
754          */
755         int (*tf_dev_set_if_tbl)(struct tf *tfp,
756                                  struct tf_if_tbl_set_parms *parms);
757
758         /**
759          * Retrieves the specified interface table type element.
760          *
761          * This API retrieves the specified element data by invoking the
762          * firmware.
763          *
764          * [in] tfp
765          *   Pointer to TF handle
766          *
767          * [in] parms
768          *   Pointer to table get parameters
769          *
770          * Returns
771          *   - (0) if successful.
772          *   - (-EINVAL) on failure.
773          */
774         int (*tf_dev_get_if_tbl)(struct tf *tfp,
775                                  struct tf_if_tbl_get_parms *parms);
776
777         /**
778          * Update global cfg
779          *
780          * [in] tfp
781          *   Pointer to TF handle
782          *
783          * [in] parms
784          *   Pointer to global cfg parameters
785          *
786          *    returns:
787          *    0       - Success
788          *    -EINVAL - Error
789          */
790         int (*tf_dev_set_global_cfg)(struct tf *tfp,
791                                      struct tf_global_cfg_parms *parms);
792
793         /**
794          * Get global cfg
795          *
796          * [in] tfp
797          *   Pointer to TF handle
798          *
799          * [in] parms
800          *   Pointer to global cfg parameters
801          *
802          *    returns:
803          *    0       - Success
804          *    -EINVAL - Error
805          */
806         int (*tf_dev_get_global_cfg)(struct tf *tfp,
807                                      struct tf_global_cfg_parms *parms);
808
809         /**
810          * Get mailbox
811          *
812          *    returns:
813          *      mailbox
814          */
815         int (*tf_dev_get_mailbox)(void);
816
817         /**
818          * Convert length in bit to length in byte and align to word.
819          * The word length depends on device type.
820          *
821          * [in] size
822          *   Size in bit
823          *
824          * Returns
825          *   Size in byte
826          */
827         int (*tf_dev_word_align)(uint16_t size);
828
829         /**
830          * Hash key using crc32 and lookup3
831          *
832          * [in] key_data
833          *   Pointer to key
834          *
835          * [in] bitlen
836          *   Number of key bits
837          *
838          * Returns
839          *   Hashes
840          */
841         uint64_t (*tf_dev_cfa_key_hash)(uint64_t *key_data,
842                                           uint16_t bitlen);
843 };
844
845 /**
846  * Supported device operation structures
847  */
848 extern const struct tf_dev_ops tf_dev_ops_p4_init;
849 extern const struct tf_dev_ops tf_dev_ops_p4;
850 extern const struct tf_dev_ops tf_dev_ops_p58_init;
851 extern const struct tf_dev_ops tf_dev_ops_p58;
852
853 #endif /* _TF_DEVICE_H_ */