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