bus/fslmc: mark internal symbols
[dpdk.git] / drivers / bus / fslmc / rte_fslmc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  *   Copyright 2016,2019 NXP
4  *
5  */
6
7 #ifndef _RTE_FSLMC_H_
8 #define _RTE_FSLMC_H_
9
10 /**
11  * @file
12  *
13  * RTE FSLMC Bus Interface
14  */
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <limits.h>
23 #include <errno.h>
24 #include <sys/queue.h>
25 #include <stdint.h>
26 #include <inttypes.h>
27 #include <linux/vfio.h>
28
29 #include <rte_debug.h>
30 #include <rte_interrupts.h>
31 #include <rte_dev.h>
32 #include <rte_bus.h>
33 #include <rte_tailq.h>
34 #include <rte_devargs.h>
35
36 #include <fslmc_vfio.h>
37
38 #define FSLMC_OBJECT_MAX_LEN 32   /**< Length of each device on bus */
39
40
41 /** Device driver supports link state interrupt */
42 #define RTE_DPAA2_DRV_INTR_LSC  0x0008
43
44 /** Device driver supports IOVA as VA */
45 #define RTE_DPAA2_DRV_IOVA_AS_VA 0X0040
46
47 struct rte_dpaa2_driver;
48
49 /* DPAA2 Device and Driver lists for FSLMC bus */
50 TAILQ_HEAD(rte_fslmc_device_list, rte_dpaa2_device);
51 TAILQ_HEAD(rte_fslmc_driver_list, rte_dpaa2_driver);
52
53 #define RTE_DEV_TO_FSLMC_CONST(ptr) \
54         container_of(ptr, const struct rte_dpaa2_device, device)
55
56 extern struct rte_fslmc_bus rte_fslmc_bus;
57
58 enum rte_dpaa2_dev_type {
59         /* Devices backed by DPDK driver */
60         DPAA2_ETH,      /**< DPNI type device*/
61         DPAA2_CRYPTO,   /**< DPSECI type device */
62         DPAA2_CON,      /**< DPCONC type device */
63         /* Devices not backed by a DPDK driver: DPIO, DPBP, DPCI, DPMCP */
64         DPAA2_BPOOL,    /**< DPBP type device */
65         DPAA2_IO,       /**< DPIO type device */
66         DPAA2_CI,       /**< DPCI type device */
67         DPAA2_MPORTAL,  /**< DPMCP type device */
68         DPAA2_QDMA,     /**< DPDMAI type device */
69         DPAA2_MUX,      /**< DPDMUX type device */
70         DPAA2_DPRTC,    /**< DPRTC type device */
71         /* Unknown device placeholder */
72         DPAA2_UNKNOWN,
73         DPAA2_DEVTYPE_MAX,
74 };
75
76 TAILQ_HEAD(rte_dpaa2_object_list, rte_dpaa2_object);
77
78 typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
79                                       struct vfio_device_info *obj_info,
80                                       int object_id);
81
82 /**
83  * A structure describing a DPAA2 object.
84  */
85 struct rte_dpaa2_object {
86         TAILQ_ENTRY(rte_dpaa2_object) next; /**< Next in list. */
87         const char *name;                   /**< Name of Object. */
88         enum rte_dpaa2_dev_type dev_type;   /**< Type of device */
89         rte_dpaa2_obj_create_t create;
90 };
91
92 /**
93  * A structure describing a DPAA2 device.
94  */
95 struct rte_dpaa2_device {
96         TAILQ_ENTRY(rte_dpaa2_device) next; /**< Next probed DPAA2 device. */
97         struct rte_device device;           /**< Inherit core device */
98         union {
99                 struct rte_eth_dev *eth_dev;        /**< ethernet device */
100                 struct rte_cryptodev *cryptodev;    /**< Crypto Device */
101                 struct rte_rawdev *rawdev;          /**< Raw Device */
102         };
103         enum rte_dpaa2_dev_type dev_type;   /**< Device Type */
104         uint16_t object_id;                 /**< DPAA2 Object ID */
105         struct rte_intr_handle intr_handle; /**< Interrupt handle */
106         struct rte_dpaa2_driver *driver;    /**< Associated driver */
107         char name[FSLMC_OBJECT_MAX_LEN];    /**< DPAA2 Object name*/
108 };
109
110 typedef int (*rte_dpaa2_probe_t)(struct rte_dpaa2_driver *dpaa2_drv,
111                                  struct rte_dpaa2_device *dpaa2_dev);
112 typedef int (*rte_dpaa2_remove_t)(struct rte_dpaa2_device *dpaa2_dev);
113
114 /**
115  * A structure describing a DPAA2 driver.
116  */
117 struct rte_dpaa2_driver {
118         TAILQ_ENTRY(rte_dpaa2_driver) next; /**< Next in list. */
119         struct rte_driver driver;           /**< Inherit core driver. */
120         struct rte_fslmc_bus *fslmc_bus;    /**< FSLMC bus reference */
121         uint32_t drv_flags;                 /**< Flags for controlling device.*/
122         enum rte_dpaa2_dev_type drv_type;   /**< Driver Type */
123         rte_dpaa2_probe_t probe;
124         rte_dpaa2_remove_t remove;
125 };
126
127 /*
128  * FSLMC bus
129  */
130 struct rte_fslmc_bus {
131         struct rte_bus bus;     /**< Generic Bus object */
132         struct rte_fslmc_device_list device_list;
133                                 /**< FSLMC DPAA2 Device list */
134         struct rte_fslmc_driver_list driver_list;
135                                 /**< FSLMC DPAA2 Driver list */
136         int device_count[DPAA2_DEVTYPE_MAX];
137                                 /**< Count of all devices scanned */
138 };
139
140 #define DPAA2_PORTAL_DEQUEUE_DEPTH      32
141
142 /* Create storage for dqrr entries per lcore */
143 struct dpaa2_portal_dqrr {
144         struct rte_mbuf *mbuf[DPAA2_PORTAL_DEQUEUE_DEPTH];
145         uint64_t dqrr_held;
146         uint8_t dqrr_size;
147 };
148
149 RTE_DECLARE_PER_LCORE(struct dpaa2_portal_dqrr, dpaa2_held_bufs);
150
151 #define DPAA2_PER_LCORE_DQRR_SIZE \
152         RTE_PER_LCORE(dpaa2_held_bufs).dqrr_size
153 #define DPAA2_PER_LCORE_DQRR_HELD \
154         RTE_PER_LCORE(dpaa2_held_bufs).dqrr_held
155 #define DPAA2_PER_LCORE_DQRR_MBUF(i) \
156         RTE_PER_LCORE(dpaa2_held_bufs).mbuf[i]
157
158 /**
159  * Register a DPAA2 driver.
160  *
161  * @param driver
162  *   A pointer to a rte_dpaa2_driver structure describing the driver
163  *   to be registered.
164  */
165 __rte_internal
166 void rte_fslmc_driver_register(struct rte_dpaa2_driver *driver);
167
168 /**
169  * Unregister a DPAA2 driver.
170  *
171  * @param driver
172  *   A pointer to a rte_dpaa2_driver structure describing the driver
173  *   to be unregistered.
174  */
175 __rte_internal
176 void rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver);
177
178 /** Helper for DPAA2 device registration from driver (eth, crypto) instance */
179 #define RTE_PMD_REGISTER_DPAA2(nm, dpaa2_drv) \
180 RTE_INIT(dpaa2initfn_ ##nm) \
181 {\
182         (dpaa2_drv).driver.name = RTE_STR(nm);\
183         rte_fslmc_driver_register(&dpaa2_drv); \
184 } \
185 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
186
187 /**
188  * Register a DPAA2 MC Object driver.
189  *
190  * @param mc_object
191  *   A pointer to a rte_dpaa_object structure describing the mc object
192  *   to be registered.
193  */
194 __rte_internal
195 void rte_fslmc_object_register(struct rte_dpaa2_object *object);
196
197 /**
198  * Count of a particular type of DPAA2 device scanned on the bus.
199  *
200  * @param dev_type
201  *   Type of device as rte_dpaa2_dev_type enumerator
202  * @return
203  *   >=0 for count; 0 indicates either no device of the said type scanned or
204  *   invalid device type.
205  */
206 __rte_internal
207 uint32_t rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type);
208
209 /** Helper for DPAA2 object registration */
210 #define RTE_PMD_REGISTER_DPAA2_OBJECT(nm, dpaa2_obj) \
211 RTE_INIT(dpaa2objinitfn_ ##nm) \
212 {\
213         (dpaa2_obj).name = RTE_STR(nm);\
214         rte_fslmc_object_register(&dpaa2_obj); \
215 } \
216 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
217
218 #ifdef __cplusplus
219 }
220 #endif
221
222 #endif /* _RTE_FSLMC_H_ */