Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright 2016,2021-2023 NXP
4 : : *
5 : : */
6 : :
7 : : #ifndef BUS_FSLMC_DRIVER_H
8 : : #define BUS_FSLMC_DRIVER_H
9 : :
10 : : /**
11 : : * @file
12 : : *
13 : : * RTE FSLMC Bus Interface
14 : : */
15 : :
16 : : #include <stdio.h>
17 : : #include <stdlib.h>
18 : : #include <limits.h>
19 : : #include <errno.h>
20 : : #include <sys/queue.h>
21 : : #include <stdint.h>
22 : : #include <inttypes.h>
23 : :
24 : : #include <rte_compat.h>
25 : : #include <rte_debug.h>
26 : : #include <rte_interrupts.h>
27 : : #include <dev_driver.h>
28 : : #include <rte_tailq.h>
29 : : #include <rte_devargs.h>
30 : : #include <rte_mbuf.h>
31 : : #include <rte_mbuf_dyn.h>
32 : :
33 : : #include <fslmc_vfio.h>
34 : :
35 : : #ifdef __cplusplus
36 : : extern "C" {
37 : : #endif
38 : :
39 : : struct vfio_device_info;
40 : :
41 : : #define FSLMC_OBJECT_MAX_LEN 32 /**< Length of each device on bus */
42 : :
43 : : #define DPAA2_INVALID_MBUF_SEQN 0
44 : :
45 : : typedef uint32_t dpaa2_seqn_t;
46 : : extern int dpaa2_seqn_dynfield_offset;
47 : :
48 : : /**
49 : : * Read dpaa2 sequence number from mbuf.
50 : : *
51 : : * @param mbuf Structure to read from.
52 : : * @return pointer to dpaa2 sequence number.
53 : : */
54 : : __rte_internal
55 : : static inline dpaa2_seqn_t *
56 : : dpaa2_seqn(struct rte_mbuf *mbuf)
57 : : {
58 [ # # # # : 0 : return RTE_MBUF_DYNFIELD(mbuf, dpaa2_seqn_dynfield_offset,
# # # # #
# # # ]
59 : : dpaa2_seqn_t *);
60 : : }
61 : :
62 : : /** Device driver supports link state interrupt */
63 : : #define RTE_DPAA2_DRV_INTR_LSC 0x0008
64 : :
65 : : /** Device driver supports IOVA as VA */
66 : : #define RTE_DPAA2_DRV_IOVA_AS_VA 0X0040
67 : :
68 : : struct rte_dpaa2_driver;
69 : :
70 : : #define RTE_DEV_TO_FSLMC_CONST(ptr) \
71 : : container_of(ptr, const struct rte_dpaa2_device, device)
72 : :
73 : : enum rte_dpaa2_dev_type {
74 : : /* Devices backed by DPDK driver */
75 : : DPAA2_ETH, /**< DPNI type device*/
76 : : DPAA2_CRYPTO, /**< DPSECI type device */
77 : : DPAA2_CON, /**< DPCONC type device */
78 : : /* Devices not backed by a DPDK driver: DPIO, DPBP, DPCI, DPMCP */
79 : : DPAA2_BPOOL, /**< DPBP type device */
80 : : DPAA2_IO, /**< DPIO type device */
81 : : DPAA2_CI, /**< DPCI type device */
82 : : DPAA2_MPORTAL, /**< DPMCP type device */
83 : : DPAA2_QDMA, /**< DPDMAI type device */
84 : : DPAA2_MUX, /**< DPDMUX type device */
85 : : DPAA2_SW, /**< DPSW type device */
86 : : DPAA2_DPRTC, /**< DPRTC type device */
87 : : DPAA2_DPRC, /**< DPRC type device */
88 : : DPAA2_MAC, /**< DPMAC type device */
89 : : /* Unknown device placeholder */
90 : : DPAA2_UNKNOWN,
91 : : DPAA2_DEVTYPE_MAX,
92 : : };
93 : :
94 : : /**
95 : : * A structure describing a DPAA2 device.
96 : : */
97 : : struct rte_dpaa2_device {
98 : : TAILQ_ENTRY(rte_dpaa2_device) next; /**< Next probed DPAA2 device. */
99 : : struct rte_device device; /**< Inherit core device */
100 : : union {
101 : : struct rte_eth_dev *eth_dev; /**< ethernet device */
102 : : struct rte_cryptodev *cryptodev; /**< Crypto Device */
103 : : struct rte_dma_dev *dmadev; /**< DMA Device */
104 : : struct rte_rawdev *rawdev; /**< Raw Device */
105 : : };
106 : : enum rte_dpaa2_dev_type dev_type; /**< Device Type */
107 : : uint16_t object_id; /**< DPAA2 Object ID */
108 : : enum rte_dpaa2_dev_type ep_dev_type; /**< Endpoint Device Type */
109 : : struct dpaa2_dprc_dev *container;
110 : : uint16_t ep_object_id; /**< Endpoint DPAA2 Object ID */
111 : : char ep_name[RTE_DEV_NAME_MAX_LEN];
112 : : struct rte_intr_handle *intr_handle; /**< Interrupt handle */
113 : : struct rte_dpaa2_driver *driver; /**< Associated driver */
114 : : char name[FSLMC_OBJECT_MAX_LEN]; /**< DPAA2 Object name*/
115 : : };
116 : :
117 : : typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
118 : : struct vfio_device_info *obj_info,
119 : : struct rte_dpaa2_device *dev);
120 : :
121 : : typedef void (*rte_dpaa2_obj_close_t)(int object_id);
122 : :
123 : : typedef int (*rte_dpaa2_probe_t)(struct rte_dpaa2_driver *dpaa2_drv,
124 : : struct rte_dpaa2_device *dpaa2_dev);
125 : : typedef int (*rte_dpaa2_remove_t)(struct rte_dpaa2_device *dpaa2_dev);
126 : :
127 : : TAILQ_HEAD(rte_dpaa2_object_list, rte_dpaa2_object);
128 : :
129 : : /**
130 : : * A structure describing a DPAA2 object.
131 : : */
132 : : struct rte_dpaa2_object {
133 : : TAILQ_ENTRY(rte_dpaa2_object) next; /**< Next in list. */
134 : : const char *name; /**< Name of Object. */
135 : : enum rte_dpaa2_dev_type dev_type; /**< Type of device */
136 : : rte_dpaa2_obj_create_t create;
137 : : rte_dpaa2_obj_close_t close;
138 : : };
139 : :
140 : : int
141 : : rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size);
142 : : int
143 : : rte_fslmc_vfio_mem_dmaunmap(uint64_t iova, uint64_t size);
144 : :
145 : : /**
146 : : * A structure describing a DPAA2 driver.
147 : : */
148 : : struct rte_dpaa2_driver {
149 : : TAILQ_ENTRY(rte_dpaa2_driver) next; /**< Next in list. */
150 : : struct rte_driver driver; /**< Inherit core driver. */
151 : : uint32_t drv_flags; /**< Flags for controlling device.*/
152 : : enum rte_dpaa2_dev_type drv_type; /**< Driver Type */
153 : : rte_dpaa2_probe_t probe;
154 : : rte_dpaa2_remove_t remove;
155 : : };
156 : :
157 : : int
158 : : rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size);
159 : : __rte_internal
160 : : int
161 : : rte_fslmc_vfio_mem_dmaunmap(uint64_t iova, uint64_t size);
162 : : __rte_internal
163 : : uint64_t
164 : : rte_fslmc_cold_mem_vaddr_to_iova(void *vaddr,
165 : : uint64_t size);
166 : : __rte_internal
167 : : void *
168 : : rte_fslmc_cold_mem_iova_to_vaddr(uint64_t iova,
169 : : uint64_t size);
170 : : __rte_internal
171 : : __rte_hot uint64_t
172 : : rte_fslmc_mem_vaddr_to_iova(void *vaddr);
173 : : __rte_internal
174 : : __rte_hot void *
175 : : rte_fslmc_mem_iova_to_vaddr(uint64_t iova);
176 : : __rte_internal
177 : : uint64_t
178 : : rte_fslmc_io_vaddr_to_iova(void *vaddr);
179 : : __rte_internal
180 : : void *
181 : : rte_fslmc_io_iova_to_vaddr(uint64_t iova);
182 : :
183 : : /**
184 : : * Register a DPAA2 driver.
185 : : *
186 : : * @param driver
187 : : * A pointer to a rte_dpaa2_driver structure describing the driver
188 : : * to be registered.
189 : : */
190 : : __rte_internal
191 : : void rte_fslmc_driver_register(struct rte_dpaa2_driver *driver);
192 : :
193 : : /**
194 : : * Unregister a DPAA2 driver.
195 : : *
196 : : * @param driver
197 : : * A pointer to a rte_dpaa2_driver structure describing the driver
198 : : * to be unregistered.
199 : : */
200 : : __rte_internal
201 : : void rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver);
202 : :
203 : : /** Helper for DPAA2 device registration from driver (eth, crypto) instance */
204 : : #define RTE_PMD_REGISTER_DPAA2(nm, dpaa2_drv) \
205 : : RTE_INIT(dpaa2initfn_ ##nm) \
206 : : {\
207 : : (dpaa2_drv).driver.name = RTE_STR(nm);\
208 : : rte_fslmc_driver_register(&dpaa2_drv); \
209 : : } \
210 : : RTE_PMD_EXPORT_NAME(nm)
211 : :
212 : : /**
213 : : * Register a DPAA2 MC Object driver.
214 : : *
215 : : * @param mc_object
216 : : * A pointer to a rte_dpaa_object structure describing the mc object
217 : : * to be registered.
218 : : */
219 : : __rte_internal
220 : : void rte_fslmc_object_register(struct rte_dpaa2_object *object);
221 : :
222 : : /**
223 : : * Count of a particular type of DPAA2 device scanned on the bus.
224 : : *
225 : : * @param dev_type
226 : : * Type of device as rte_dpaa2_dev_type enumerator
227 : : * @return
228 : : * >=0 for count; 0 indicates either no device of the said type scanned or
229 : : * invalid device type.
230 : : */
231 : : __rte_internal
232 : : uint32_t rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type);
233 : :
234 : : /** Helper for DPAA2 object registration */
235 : : #define RTE_PMD_REGISTER_DPAA2_OBJECT(nm, dpaa2_obj) \
236 : : RTE_INIT(dpaa2objinitfn_ ##nm) \
237 : : {\
238 : : (dpaa2_obj).name = RTE_STR(nm);\
239 : : rte_fslmc_object_register(&dpaa2_obj); \
240 : : } \
241 : : RTE_PMD_EXPORT_NAME(nm)
242 : :
243 : : #ifdef __cplusplus
244 : : }
245 : : #endif
246 : :
247 : : #endif /* BUS_FSLMC_DRIVER_H */
|