drivers: remove direct access to interrupt handle
[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 #include <rte_mbuf.h>
36 #include <rte_mbuf_dyn.h>
37
38 #include <fslmc_vfio.h>
39
40 #define FSLMC_OBJECT_MAX_LEN 32   /**< Length of each device on bus */
41
42 #define DPAA2_INVALID_MBUF_SEQN        0
43
44 typedef uint32_t dpaa2_seqn_t;
45 extern int dpaa2_seqn_dynfield_offset;
46
47 /**
48  * Read dpaa2 sequence number from mbuf.
49  *
50  * @param mbuf Structure to read from.
51  * @return pointer to dpaa2 sequence number.
52  */
53 __rte_internal
54 static inline dpaa2_seqn_t *
55 dpaa2_seqn(struct rte_mbuf *mbuf)
56 {
57         return RTE_MBUF_DYNFIELD(mbuf, dpaa2_seqn_dynfield_offset,
58                 dpaa2_seqn_t *);
59 }
60
61 /** Device driver supports link state interrupt */
62 #define RTE_DPAA2_DRV_INTR_LSC  0x0008
63
64 /** Device driver supports IOVA as VA */
65 #define RTE_DPAA2_DRV_IOVA_AS_VA 0X0040
66
67 struct rte_dpaa2_driver;
68
69 /* DPAA2 Device and Driver lists for FSLMC bus */
70 TAILQ_HEAD(rte_fslmc_device_list, rte_dpaa2_device);
71 TAILQ_HEAD(rte_fslmc_driver_list, rte_dpaa2_driver);
72
73 #define RTE_DEV_TO_FSLMC_CONST(ptr) \
74         container_of(ptr, const struct rte_dpaa2_device, device)
75
76 extern struct rte_fslmc_bus rte_fslmc_bus;
77
78 enum rte_dpaa2_dev_type {
79         /* Devices backed by DPDK driver */
80         DPAA2_ETH,      /**< DPNI type device*/
81         DPAA2_CRYPTO,   /**< DPSECI type device */
82         DPAA2_CON,      /**< DPCONC type device */
83         /* Devices not backed by a DPDK driver: DPIO, DPBP, DPCI, DPMCP */
84         DPAA2_BPOOL,    /**< DPBP type device */
85         DPAA2_IO,       /**< DPIO type device */
86         DPAA2_CI,       /**< DPCI type device */
87         DPAA2_MPORTAL,  /**< DPMCP type device */
88         DPAA2_QDMA,     /**< DPDMAI type device */
89         DPAA2_MUX,      /**< DPDMUX type device */
90         DPAA2_DPRTC,    /**< DPRTC type device */
91         /* Unknown device placeholder */
92         DPAA2_UNKNOWN,
93         DPAA2_DEVTYPE_MAX,
94 };
95
96 TAILQ_HEAD(rte_dpaa2_object_list, rte_dpaa2_object);
97
98 typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
99                                       struct vfio_device_info *obj_info,
100                                       int object_id);
101
102 /**
103  * A structure describing a DPAA2 object.
104  */
105 struct rte_dpaa2_object {
106         TAILQ_ENTRY(rte_dpaa2_object) next; /**< Next in list. */
107         const char *name;                   /**< Name of Object. */
108         enum rte_dpaa2_dev_type dev_type;   /**< Type of device */
109         rte_dpaa2_obj_create_t create;
110 };
111
112 /**
113  * A structure describing a DPAA2 device.
114  */
115 struct rte_dpaa2_device {
116         TAILQ_ENTRY(rte_dpaa2_device) next; /**< Next probed DPAA2 device. */
117         struct rte_device device;           /**< Inherit core device */
118         union {
119                 struct rte_eth_dev *eth_dev;        /**< ethernet device */
120                 struct rte_cryptodev *cryptodev;    /**< Crypto Device */
121                 struct rte_rawdev *rawdev;          /**< Raw Device */
122         };
123         enum rte_dpaa2_dev_type dev_type;   /**< Device Type */
124         uint16_t object_id;                 /**< DPAA2 Object ID */
125         struct rte_intr_handle *intr_handle; /**< Interrupt handle */
126         struct rte_dpaa2_driver *driver;    /**< Associated driver */
127         char name[FSLMC_OBJECT_MAX_LEN];    /**< DPAA2 Object name*/
128 };
129
130 typedef int (*rte_dpaa2_probe_t)(struct rte_dpaa2_driver *dpaa2_drv,
131                                  struct rte_dpaa2_device *dpaa2_dev);
132 typedef int (*rte_dpaa2_remove_t)(struct rte_dpaa2_device *dpaa2_dev);
133
134 /**
135  * A structure describing a DPAA2 driver.
136  */
137 struct rte_dpaa2_driver {
138         TAILQ_ENTRY(rte_dpaa2_driver) next; /**< Next in list. */
139         struct rte_driver driver;           /**< Inherit core driver. */
140         struct rte_fslmc_bus *fslmc_bus;    /**< FSLMC bus reference */
141         uint32_t drv_flags;                 /**< Flags for controlling device.*/
142         enum rte_dpaa2_dev_type drv_type;   /**< Driver Type */
143         rte_dpaa2_probe_t probe;
144         rte_dpaa2_remove_t remove;
145 };
146
147 /*
148  * FSLMC bus
149  */
150 struct rte_fslmc_bus {
151         struct rte_bus bus;     /**< Generic Bus object */
152         struct rte_fslmc_device_list device_list;
153                                 /**< FSLMC DPAA2 Device list */
154         struct rte_fslmc_driver_list driver_list;
155                                 /**< FSLMC DPAA2 Driver list */
156         int device_count[DPAA2_DEVTYPE_MAX];
157                                 /**< Count of all devices scanned */
158 };
159
160 /**
161  * Register a DPAA2 driver.
162  *
163  * @param driver
164  *   A pointer to a rte_dpaa2_driver structure describing the driver
165  *   to be registered.
166  */
167 __rte_internal
168 void rte_fslmc_driver_register(struct rte_dpaa2_driver *driver);
169
170 /**
171  * Unregister a DPAA2 driver.
172  *
173  * @param driver
174  *   A pointer to a rte_dpaa2_driver structure describing the driver
175  *   to be unregistered.
176  */
177 __rte_internal
178 void rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver);
179
180 /** Helper for DPAA2 device registration from driver (eth, crypto) instance */
181 #define RTE_PMD_REGISTER_DPAA2(nm, dpaa2_drv) \
182 RTE_INIT(dpaa2initfn_ ##nm) \
183 {\
184         (dpaa2_drv).driver.name = RTE_STR(nm);\
185         rte_fslmc_driver_register(&dpaa2_drv); \
186 } \
187 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
188
189 /**
190  * Register a DPAA2 MC Object driver.
191  *
192  * @param mc_object
193  *   A pointer to a rte_dpaa_object structure describing the mc object
194  *   to be registered.
195  */
196 __rte_internal
197 void rte_fslmc_object_register(struct rte_dpaa2_object *object);
198
199 /**
200  * Count of a particular type of DPAA2 device scanned on the bus.
201  *
202  * @param dev_type
203  *   Type of device as rte_dpaa2_dev_type enumerator
204  * @return
205  *   >=0 for count; 0 indicates either no device of the said type scanned or
206  *   invalid device type.
207  */
208 __rte_internal
209 uint32_t rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type);
210
211 /** Helper for DPAA2 object registration */
212 #define RTE_PMD_REGISTER_DPAA2_OBJECT(nm, dpaa2_obj) \
213 RTE_INIT(dpaa2objinitfn_ ##nm) \
214 {\
215         (dpaa2_obj).name = RTE_STR(nm);\
216         rte_fslmc_object_register(&dpaa2_obj); \
217 } \
218 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif /* _RTE_FSLMC_H_ */