1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 RehiveTech. All rights reserved.
18 #include <sys/queue.h>
20 #include <rte_devargs.h>
22 struct rte_vdev_device {
23 TAILQ_ENTRY(rte_vdev_device) next; /**< Next attached vdev */
24 struct rte_device device; /**< Inherit core device */
29 * Helper macro for drivers that need to convert to struct rte_vdev_device.
31 #define RTE_DEV_TO_VDEV(ptr) \
32 container_of(ptr, struct rte_vdev_device, device)
34 #define RTE_DEV_TO_VDEV_CONST(ptr) \
35 container_of(ptr, const struct rte_vdev_device, device)
37 #define RTE_ETH_DEV_TO_VDEV(eth_dev) RTE_DEV_TO_VDEV((eth_dev)->device)
39 static inline const char *
40 rte_vdev_device_name(const struct rte_vdev_device *dev)
42 if (dev && dev->device.name)
43 return dev->device.name;
47 static inline const char *
48 rte_vdev_device_args(const struct rte_vdev_device *dev)
50 if (dev && dev->device.devargs)
51 return dev->device.devargs->args;
55 /** Double linked list of virtual device drivers. */
56 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
59 * Probe function called for each virtual device driver once.
61 typedef int (rte_vdev_probe_t)(struct rte_vdev_device *dev);
64 * Remove function called for each virtual device driver once.
66 typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
69 * Driver-specific DMA mapping. After a successful call the device
70 * will be able to read/write from/to this segment.
73 * Pointer to the Virtual device.
75 * Starting virtual address of memory to be mapped.
77 * Starting IOVA address of memory to be mapped.
79 * Length of memory segment being mapped.
82 * - Negative value and rte_errno is set otherwise.
84 typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr,
85 uint64_t iova, size_t len);
88 * Driver-specific DMA un-mapping. After a successful call the device
89 * will not be able to read/write from/to this segment.
92 * Pointer to the Virtual device.
94 * Starting virtual address of memory to be unmapped.
96 * Starting IOVA address of memory to be unmapped.
98 * Length of memory segment being unmapped.
101 * - Negative value and rte_errno is set otherwise.
103 typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr,
104 uint64_t iova, size_t len);
107 * A virtual device driver abstraction.
109 struct rte_vdev_driver {
110 TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */
111 struct rte_driver driver; /**< Inherited general driver. */
112 rte_vdev_probe_t *probe; /**< Virtual device probe function. */
113 rte_vdev_remove_t *remove; /**< Virtual device remove function. */
114 rte_vdev_dma_map_t *dma_map; /**< Virtual device DMA map function. */
115 rte_vdev_dma_unmap_t *dma_unmap; /**< Virtual device DMA unmap function. */
116 uint32_t drv_flags; /**< Flags RTE_VDEV_DRV_*. */
119 /** Device driver needs IOVA as VA and cannot work with IOVA as PA */
120 #define RTE_VDEV_DRV_NEED_IOVA_AS_VA 0x0001
123 * Register a virtual device driver.
126 * A pointer to a rte_vdev_driver structure describing the driver
129 void rte_vdev_register(struct rte_vdev_driver *driver);
132 * Unregister a virtual device driver.
135 * A pointer to a rte_vdev_driver structure describing the driver
136 * to be unregistered.
138 void rte_vdev_unregister(struct rte_vdev_driver *driver);
140 #define RTE_PMD_REGISTER_VDEV(nm, vdrv)\
141 static const char *vdrvinit_ ## nm ## _alias;\
142 RTE_INIT(vdrvinitfn_ ##vdrv)\
144 (vdrv).driver.name = RTE_STR(nm);\
145 (vdrv).driver.alias = vdrvinit_ ## nm ## _alias;\
146 rte_vdev_register(&vdrv);\
148 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
150 #define RTE_PMD_REGISTER_ALIAS(nm, alias)\
151 static const char *vdrvinit_ ## nm ## _alias = RTE_STR(alias)
153 typedef void (*rte_vdev_scan_callback)(void *user_arg);
156 * Add a callback to be called on vdev scan
157 * before reading the devargs list.
159 * This function cannot be called in a scan callback
160 * because of deadlock.
163 * The function to be called which can update the devargs list.
165 * An opaque pointer passed to callback.
167 * 0 on success, negative on error
170 rte_vdev_add_custom_scan(rte_vdev_scan_callback callback, void *user_arg);
173 * Remove a registered scan callback.
175 * This function cannot be called in a scan callback
176 * because of deadlock.
179 * The registered function to be removed.
181 * The associated opaque pointer or (void*)-1 for any.
186 rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg);
189 * Initialize a driver specified by name.
192 * The pointer to a driver name to be initialized.
194 * The pointer to arguments used by driver initialization.
196 * 0 on success, negative on error
198 int rte_vdev_init(const char *name, const char *args);
201 * Uninitalize a driver specified by name.
204 * The pointer to a driver name to be uninitialized.
206 * 0 on success, negative on error
208 int rte_vdev_uninit(const char *name);