net/bnxt: add 64B SRAM record management with RM
[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          * Get SRAM table information.
225          *
226          * Converts an internal RM allocated element offset to
227          * a user address and vice versa.
228          *
229          * [in] tfp
230          *   Pointer to TF handle
231          *
232          * [in] type
233          *   Truflow index table type, e.g. TF_TYPE_FULL_ACT_RECORD
234          *
235          * [in/out] base
236          *   Pointer to the base address of the associated table type.
237          *
238          * [in/out] shift
239          *   Pointer to any shift required for the associated table type.
240          *
241          * Returns
242          *   - (0) if successful.
243          *   - (-EINVAL) on failure.
244          */
245         int (*tf_dev_get_tbl_info)(struct tf *tfp,
246                                    void *tbl_db,
247                                    enum tf_tbl_type type,
248                                    uint16_t *base,
249                                    uint16_t *shift);
250
251         /**
252          * Allocation of an index table type element.
253          *
254          * This API allocates the specified table type element from a
255          * device specific table type DB. The allocated element is
256          * returned.
257          *
258          * [in] tfp
259          *   Pointer to TF handle
260          *
261          * [in] parms
262          *   Pointer to table allocation parameters
263          *
264          * Returns
265          *   - (0) if successful.
266          *   - (-EINVAL) on failure.
267          */
268         int (*tf_dev_alloc_tbl)(struct tf *tfp,
269                                 struct tf_tbl_alloc_parms *parms);
270
271         /**
272          * Allocation of a external table type element.
273          *
274          * This API allocates the specified table type element from a
275          * device specific table type DB. The allocated element is
276          * returned.
277          *
278          * [in] tfp
279          *   Pointer to TF handle
280          *
281          * [in] parms
282          *   Pointer to table allocation parameters
283          *
284          * Returns
285          *   - (0) if successful.
286          *   - (-EINVAL) on failure.
287          */
288         int (*tf_dev_alloc_ext_tbl)(struct tf *tfp,
289                                     struct tf_tbl_alloc_parms *parms);
290
291         /**
292          * Free of a table type element.
293          *
294          * This API free's a previous allocated table type element from a
295          * device specific table type DB.
296          *
297          * [in] tfp
298          *   Pointer to TF handle
299          *
300          * [in] parms
301          *   Pointer to table free parameters
302          *
303          * Returns
304          *   - (0) if successful.
305          *   - (-EINVAL) on failure.
306          */
307         int (*tf_dev_free_tbl)(struct tf *tfp,
308                                struct tf_tbl_free_parms *parms);
309
310         /**
311          * Free of a external 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_ext_tbl)(struct tf *tfp,
327                                    struct tf_tbl_free_parms *parms);
328
329         /**
330          * Searches for the specified table type element in a shadow DB.
331          *
332          * This API searches for the specified table type element in a
333          * device specific shadow DB. If the element is found the
334          * reference count for the element is updated. If the element
335          * is not found a new element is allocated from the table type
336          * DB and then inserted into the shadow DB.
337          *
338          * [in] tfp
339          *   Pointer to TF handle
340          *
341          * [in] parms
342          *   Pointer to table allocation and search parameters
343          *
344          * Returns
345          *   - (0) if successful.
346          *   - (-EINVAL) on failure.
347          */
348         int (*tf_dev_alloc_search_tbl)(struct tf *tfp,
349                                        struct tf_tbl_alloc_search_parms *parms);
350
351         /**
352          * Sets the specified table type element.
353          *
354          * This API sets the specified element data by invoking the
355          * firmware.
356          *
357          * [in] tfp
358          *   Pointer to TF handle
359          *
360          * [in] parms
361          *   Pointer to table set parameters
362          *
363          * Returns
364          *   - (0) if successful.
365          *   - (-EINVAL) on failure.
366          */
367         int (*tf_dev_set_tbl)(struct tf *tfp,
368                               struct tf_tbl_set_parms *parms);
369
370         /**
371          * Sets the specified external 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_ext_tbl)(struct tf *tfp,
387                                   struct tf_tbl_set_parms *parms);
388
389         /**
390          * Retrieves the specified table type element.
391          *
392          * This API retrieves 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 get parameters
400          *
401          * Returns
402          *   - (0) if successful.
403          *   - (-EINVAL) on failure.
404          */
405         int (*tf_dev_get_tbl)(struct tf *tfp,
406                               struct tf_tbl_get_parms *parms);
407
408         /**
409          * Retrieves the specified table type element using 'bulk'
410          * mechanism.
411          *
412          * This API retrieves the specified element data by invoking the
413          * firmware.
414          *
415          * [in] tfp
416          *   Pointer to TF handle
417          *
418          * [in] parms
419          *   Pointer to table get bulk parameters
420          *
421          * Returns
422          *   - (0) if successful.
423          *   - (-EINVAL) on failure.
424          */
425         int (*tf_dev_get_bulk_tbl)(struct tf *tfp,
426                                    struct tf_tbl_get_bulk_parms *parms);
427
428         /**
429          * Allocation of a tcam element.
430          *
431          * This API allocates the specified tcam element from a device
432          * specific tcam DB. The allocated element is returned.
433          *
434          * [in] tfp
435          *   Pointer to TF handle
436          *
437          * [in] parms
438          *   Pointer to tcam allocation parameters
439          *
440          * Returns
441          *   - (0) if successful.
442          *   - (-EINVAL) on failure.
443          */
444         int (*tf_dev_alloc_tcam)(struct tf *tfp,
445                                  struct tf_tcam_alloc_parms *parms);
446
447         /**
448          * Free of a tcam element.
449          *
450          * This API free's a previous allocated tcam element from a
451          * device specific tcam DB.
452          *
453          * [in] tfp
454          *   Pointer to TF handle
455          *
456          * [in] parms
457          *   Pointer to tcam free parameters
458          *
459          * Returns
460          *   - (0) if successful.
461          *   - (-EINVAL) on failure.
462          */
463         int (*tf_dev_free_tcam)(struct tf *tfp,
464                                 struct tf_tcam_free_parms *parms);
465
466         /**
467          * Searches for the specified tcam element in a shadow DB.
468          *
469          * This API searches for the specified tcam element in a
470          * device specific shadow DB. If the element is found the
471          * reference count for the element is updated. If the element
472          * is not found a new element is allocated from the tcam DB
473          * and then inserted into the shadow DB.
474          *
475          * [in] tfp
476          *   Pointer to TF handle
477          *
478          * [in] parms
479          *   Pointer to tcam allocation and search parameters
480          *
481          * Returns
482          *   - (0) if successful.
483          *   - (-EINVAL) on failure.
484          */
485         int (*tf_dev_alloc_search_tcam)
486                         (struct tf *tfp,
487                         struct tf_tcam_alloc_search_parms *parms);
488
489         /**
490          * Sets the specified tcam element.
491          *
492          * This API sets the specified element data by invoking the
493          * firmware.
494          *
495          * [in] tfp
496          *   Pointer to TF handle
497          *
498          * [in] parms
499          *   Pointer to tcam set parameters
500          *
501          * Returns
502          *   - (0) if successful.
503          *   - (-EINVAL) on failure.
504          */
505         int (*tf_dev_set_tcam)(struct tf *tfp,
506                                struct tf_tcam_set_parms *parms);
507
508         /**
509          * Retrieves the specified tcam element.
510          *
511          * This API retrieves the specified element data by invoking the
512          * firmware.
513          *
514          * [in] tfp
515          *   Pointer to TF handle
516          *
517          * [in] parms
518          *   Pointer to tcam get parameters
519          *
520          * Returns
521          *   - (0) if successful.
522          *   - (-EINVAL) on failure.
523          */
524         int (*tf_dev_get_tcam)(struct tf *tfp,
525                                struct tf_tcam_get_parms *parms);
526
527         /**
528          * Insert EM hash entry API
529          *
530          * [in] tfp
531          *   Pointer to TF handle
532          *
533          * [in] parms
534          *   Pointer to E/EM insert parameters
535          *
536          *  Returns:
537          *    0       - Success
538          *    -EINVAL - Error
539          */
540         int (*tf_dev_insert_int_em_entry)(struct tf *tfp,
541                                           struct tf_insert_em_entry_parms *parms);
542
543         /**
544          * Delete EM hash entry API
545          *
546          * [in] tfp
547          *   Pointer to TF handle
548          *
549          * [in] parms
550          *   Pointer to E/EM delete parameters
551          *
552          *    returns:
553          *    0       - Success
554          *    -EINVAL - Error
555          */
556         int (*tf_dev_delete_int_em_entry)(struct tf *tfp,
557                                           struct tf_delete_em_entry_parms *parms);
558
559         /**
560          * Insert EEM hash entry API
561          *
562          * [in] tfp
563          *   Pointer to TF handle
564          *
565          * [in] parms
566          *   Pointer to E/EM insert parameters
567          *
568          *  Returns:
569          *    0       - Success
570          *    -EINVAL - Error
571          */
572         int (*tf_dev_insert_ext_em_entry)(struct tf *tfp,
573                                           struct tf_insert_em_entry_parms *parms);
574
575         /**
576          * Delete EEM hash entry API
577          *
578          * [in] tfp
579          *   Pointer to TF handle
580          *
581          * [in] parms
582          *   Pointer to E/EM delete parameters
583          *
584          *    returns:
585          *    0       - Success
586          *    -EINVAL - Error
587          */
588         int (*tf_dev_delete_ext_em_entry)(struct tf *tfp,
589                                           struct tf_delete_em_entry_parms *parms);
590
591         /**
592          * Allocate EEM table scope
593          *
594          * [in] tfp
595          *   Pointer to TF handle
596          *
597          * [in] parms
598          *   Pointer to table scope alloc parameters
599          *
600          *    returns:
601          *    0       - Success
602          *    -EINVAL - Error
603          */
604         int (*tf_dev_alloc_tbl_scope)(struct tf *tfp,
605                                       struct tf_alloc_tbl_scope_parms *parms);
606         /**
607          * Map EEM parif
608          *
609          * [in] tfp
610          *   Pointer to TF handle
611          *
612          * [in] pf
613          * PF associated with the table scope
614          *
615          * [in] parif_bitmask
616          * Bitmask of PARIFs to enable
617          *
618          * [in/out] pointer to the parif_2_pf data to be updated
619          *
620          * [in/out] pointer to the parif_2_pf mask to be updated
621          *
622          * [in] sz_in_bytes - number of bytes to be written
623          *
624          *    returns:
625          *    0       - Success
626          *    -EINVAL - Error
627          */
628         int (*tf_dev_map_parif)(struct tf *tfp,
629                                 uint16_t parif_bitmask,
630                                 uint16_t pf,
631                                 uint8_t *data,
632                                 uint8_t *mask,
633                                 uint16_t sz_in_bytes);
634         /**
635          * Map EEM table scope
636          *
637          * [in] tfp
638          *   Pointer to TF handle
639          *
640          * [in] parms
641          *   Pointer to table scope map parameters
642          *
643          *    returns:
644          *    0       - Success
645          *    -EINVAL - Error
646          */
647         int (*tf_dev_map_tbl_scope)(struct tf *tfp,
648                                     struct tf_map_tbl_scope_parms *parms);
649
650         /**
651          * Free EEM table scope
652          *
653          * [in] tfp
654          *   Pointer to TF handle
655          *
656          * [in] parms
657          *   Pointer to table scope free parameters
658          *
659          *    returns:
660          *    0       - Success
661          *    -EINVAL - Error
662          */
663         int (*tf_dev_free_tbl_scope)(struct tf *tfp,
664                                      struct tf_free_tbl_scope_parms *parms);
665
666         /**
667          * Sets the specified interface table type element.
668          *
669          * This API sets the specified element data by invoking the
670          * firmware.
671          *
672          * [in] tfp
673          *   Pointer to TF handle
674          *
675          * [in] parms
676          *   Pointer to interface table set parameters
677          *
678          * Returns
679          *   - (0) if successful.
680          *   - (-EINVAL) on failure.
681          */
682         int (*tf_dev_set_if_tbl)(struct tf *tfp,
683                                  struct tf_if_tbl_set_parms *parms);
684
685         /**
686          * Retrieves the specified interface table type element.
687          *
688          * This API retrieves the specified element data by invoking the
689          * firmware.
690          *
691          * [in] tfp
692          *   Pointer to TF handle
693          *
694          * [in] parms
695          *   Pointer to table get parameters
696          *
697          * Returns
698          *   - (0) if successful.
699          *   - (-EINVAL) on failure.
700          */
701         int (*tf_dev_get_if_tbl)(struct tf *tfp,
702                                  struct tf_if_tbl_get_parms *parms);
703
704         /**
705          * Update global cfg
706          *
707          * [in] tfp
708          *   Pointer to TF handle
709          *
710          * [in] parms
711          *   Pointer to global cfg parameters
712          *
713          *    returns:
714          *    0       - Success
715          *    -EINVAL - Error
716          */
717         int (*tf_dev_set_global_cfg)(struct tf *tfp,
718                                      struct tf_global_cfg_parms *parms);
719
720         /**
721          * Get global cfg
722          *
723          * [in] tfp
724          *   Pointer to TF handle
725          *
726          * [in] parms
727          *   Pointer to global cfg parameters
728          *
729          *    returns:
730          *    0       - Success
731          *    -EINVAL - Error
732          */
733         int (*tf_dev_get_global_cfg)(struct tf *tfp,
734                                      struct tf_global_cfg_parms *parms);
735
736         /**
737          * Get mailbox
738          *
739          *    returns:
740          *      mailbox
741          */
742         int (*tf_dev_get_mailbox)(void);
743
744         /**
745          * Convert length in bit to length in byte and align to word.
746          * The word length depends on device type.
747          *
748          * [in] size
749          *   Size in bit
750          *
751          * Returns
752          *   Size in byte
753          */
754         int (*tf_dev_word_align)(uint16_t size);
755 };
756
757 /**
758  * Supported device operation structures
759  */
760 extern const struct tf_dev_ops tf_dev_ops_p4_init;
761 extern const struct tf_dev_ops tf_dev_ops_p4;
762 extern const struct tf_dev_ops tf_dev_ops_p58_init;
763 extern const struct tf_dev_ops tf_dev_ops_p58;
764
765 #endif /* _TF_DEVICE_H_ */