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 <bus_driver.h>
29 : : #include <rte_tailq.h>
30 : : #include <rte_devargs.h>
31 : : #include <rte_mbuf.h>
32 : : #include <rte_mbuf_dyn.h>
33 : :
34 : : #include <fslmc_vfio.h>
35 : :
36 : : #ifdef __cplusplus
37 : : extern "C" {
38 : : #endif
39 : :
40 : : struct vfio_device_info;
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 [ # # # # : 0 : 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 : : enum rte_dpaa2_dev_type {
70 : : /* Devices backed by DPDK driver */
71 : : DPAA2_ETH, /**< DPNI type device*/
72 : : DPAA2_CRYPTO, /**< DPSECI type device */
73 : : DPAA2_CON, /**< DPCONC type device */
74 : : /* Devices not backed by a DPDK driver: DPIO, DPBP, DPCI, DPMCP */
75 : : DPAA2_BPOOL, /**< DPBP type device */
76 : : DPAA2_IO, /**< DPIO type device */
77 : : DPAA2_CI, /**< DPCI type device */
78 : : DPAA2_MPORTAL, /**< DPMCP type device */
79 : : DPAA2_QDMA, /**< DPDMAI type device */
80 : : DPAA2_MUX, /**< DPDMUX type device */
81 : : DPAA2_SW, /**< DPSW type device */
82 : : DPAA2_DPRTC, /**< DPRTC type device */
83 : : DPAA2_DPRC, /**< DPRC type device */
84 : : DPAA2_MAC, /**< DPMAC type device */
85 : : /* Unknown device placeholder */
86 : : DPAA2_UNKNOWN,
87 : : DPAA2_DEVTYPE_MAX,
88 : : };
89 : :
90 : : /**
91 : : * A structure describing a DPAA2 device.
92 : : */
93 : : struct rte_dpaa2_device {
94 : : struct rte_device device; /**< Inherit core device */
95 : : enum rte_dpaa2_dev_type dev_type; /**< Device Type */
96 : : uint16_t object_id; /**< DPAA2 Object ID */
97 : : enum rte_dpaa2_dev_type ep_dev_type; /**< Endpoint Device Type */
98 : : struct dpaa2_dprc_dev *container;
99 : : uint16_t ep_object_id; /**< Endpoint DPAA2 Object ID */
100 : : char ep_name[RTE_DEV_NAME_MAX_LEN];
101 : : struct rte_intr_handle *intr_handle; /**< Interrupt handle */
102 : : char name[RTE_DEV_NAME_MAX_LEN];
103 : : };
104 : :
105 : : typedef int (*rte_dpaa2_obj_create_t)(int vdev_fd,
106 : : struct vfio_device_info *obj_info,
107 : : struct rte_dpaa2_device *dev);
108 : :
109 : : typedef void (*rte_dpaa2_obj_close_t)(int object_id);
110 : :
111 : : typedef int (*rte_dpaa2_probe_t)(struct rte_dpaa2_driver *dpaa2_drv,
112 : : struct rte_dpaa2_device *dpaa2_dev);
113 : : typedef int (*rte_dpaa2_remove_t)(struct rte_dpaa2_device *dpaa2_dev);
114 : :
115 : : TAILQ_HEAD(rte_dpaa2_object_list, rte_dpaa2_object);
116 : :
117 : : /**
118 : : * A structure describing a DPAA2 object.
119 : : */
120 : : struct rte_dpaa2_object {
121 : : TAILQ_ENTRY(rte_dpaa2_object) next; /**< Next in list. */
122 : : const char *name; /**< Name of Object. */
123 : : enum rte_dpaa2_dev_type dev_type; /**< Type of device */
124 : : rte_dpaa2_obj_create_t create;
125 : : rte_dpaa2_obj_close_t close;
126 : : };
127 : :
128 : : int
129 : : rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size);
130 : : int
131 : : rte_fslmc_vfio_mem_dmaunmap(uint64_t iova, uint64_t size);
132 : :
133 : : /**
134 : : * A structure describing a DPAA2 driver.
135 : : */
136 : : struct rte_dpaa2_driver {
137 : : struct rte_driver driver; /**< Inherit core driver. */
138 : : uint32_t drv_flags; /**< Flags for controlling device.*/
139 : : enum rte_dpaa2_dev_type drv_type; /**< Driver Type */
140 : : rte_dpaa2_probe_t probe;
141 : : rte_dpaa2_remove_t remove;
142 : : };
143 : :
144 : : int
145 : : rte_fslmc_vfio_mem_dmamap(uint64_t vaddr, uint64_t iova, uint64_t size);
146 : : __rte_internal
147 : : int
148 : : rte_fslmc_vfio_mem_dmaunmap(uint64_t iova, uint64_t size);
149 : : __rte_internal
150 : : uint64_t
151 : : rte_fslmc_cold_mem_vaddr_to_iova(void *vaddr,
152 : : uint64_t size);
153 : : __rte_internal
154 : : void *
155 : : rte_fslmc_cold_mem_iova_to_vaddr(uint64_t iova,
156 : : uint64_t size);
157 : : __rte_internal
158 : : __rte_hot uint64_t
159 : : rte_fslmc_mem_vaddr_to_iova(void *vaddr);
160 : : __rte_internal
161 : : __rte_hot void *
162 : : rte_fslmc_mem_iova_to_vaddr(uint64_t iova);
163 : : __rte_internal
164 : : uint64_t
165 : : rte_fslmc_io_vaddr_to_iova(void *vaddr);
166 : : __rte_internal
167 : : void *
168 : : rte_fslmc_io_iova_to_vaddr(uint64_t iova);
169 : :
170 : : /**
171 : : * Register a DPAA2 driver.
172 : : *
173 : : * @param driver
174 : : * A pointer to a rte_dpaa2_driver structure describing the driver
175 : : * to be registered.
176 : : */
177 : : __rte_internal
178 : : void rte_fslmc_driver_register(struct rte_dpaa2_driver *driver);
179 : :
180 : : /**
181 : : * Unregister a DPAA2 driver.
182 : : *
183 : : * @param driver
184 : : * A pointer to a rte_dpaa2_driver structure describing the driver
185 : : * to be unregistered.
186 : : */
187 : : __rte_internal
188 : : void rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver);
189 : :
190 : : /** Helper for DPAA2 device registration from driver (eth, crypto) instance */
191 : : #define RTE_PMD_REGISTER_DPAA2(nm, dpaa2_drv) \
192 : : RTE_INIT(dpaa2initfn_ ##nm) \
193 : : {\
194 : : (dpaa2_drv).driver.name = RTE_STR(nm);\
195 : : rte_fslmc_driver_register(&dpaa2_drv); \
196 : : } \
197 : : RTE_PMD_EXPORT_NAME(nm)
198 : :
199 : : /**
200 : : * Register a DPAA2 MC Object driver.
201 : : *
202 : : * @param mc_object
203 : : * A pointer to a rte_dpaa_object structure describing the mc object
204 : : * to be registered.
205 : : */
206 : : __rte_internal
207 : : void rte_fslmc_object_register(struct rte_dpaa2_object *object);
208 : :
209 : : /**
210 : : * Count of a particular type of DPAA2 device scanned on the bus.
211 : : *
212 : : * @param dev_type
213 : : * Type of device as rte_dpaa2_dev_type enumerator
214 : : * @return
215 : : * >=0 for count; 0 indicates either no device of the said type scanned or
216 : : * invalid device type.
217 : : */
218 : : __rte_internal
219 : : uint32_t rte_fslmc_get_device_count(enum rte_dpaa2_dev_type device_type);
220 : :
221 : : /** Helper for DPAA2 object registration */
222 : : #define RTE_PMD_REGISTER_DPAA2_OBJECT(nm, dpaa2_obj) \
223 : : RTE_INIT(dpaa2objinitfn_ ##nm) \
224 : : {\
225 : : (dpaa2_obj).name = RTE_STR(nm);\
226 : : rte_fslmc_object_register(&dpaa2_obj); \
227 : : } \
228 : : RTE_PMD_EXPORT_NAME(nm)
229 : :
230 : : #ifdef __cplusplus
231 : : }
232 : : #endif
233 : :
234 : : #endif /* BUS_FSLMC_DRIVER_H */
|