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. */
119 * Register a virtual device driver.
122 * A pointer to a rte_vdev_driver structure describing the driver
125 void rte_vdev_register(struct rte_vdev_driver *driver);
128 * Unregister a virtual device driver.
131 * A pointer to a rte_vdev_driver structure describing the driver
132 * to be unregistered.
134 void rte_vdev_unregister(struct rte_vdev_driver *driver);
136 #define RTE_PMD_REGISTER_VDEV(nm, vdrv)\
137 static const char *vdrvinit_ ## nm ## _alias;\
138 RTE_INIT(vdrvinitfn_ ##vdrv)\
140 (vdrv).driver.name = RTE_STR(nm);\
141 (vdrv).driver.alias = vdrvinit_ ## nm ## _alias;\
142 rte_vdev_register(&vdrv);\
144 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
146 #define RTE_PMD_REGISTER_ALIAS(nm, alias)\
147 static const char *vdrvinit_ ## nm ## _alias = RTE_STR(alias)
149 typedef void (*rte_vdev_scan_callback)(void *user_arg);
152 * Add a callback to be called on vdev scan
153 * before reading the devargs list.
155 * This function cannot be called in a scan callback
156 * because of deadlock.
159 * The function to be called which can update the devargs list.
161 * An opaque pointer passed to callback.
163 * 0 on success, negative on error
166 rte_vdev_add_custom_scan(rte_vdev_scan_callback callback, void *user_arg);
169 * Remove a registered scan callback.
171 * This function cannot be called in a scan callback
172 * because of deadlock.
175 * The registered function to be removed.
177 * The associated opaque pointer or (void*)-1 for any.
182 rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg);
185 * Initialize a driver specified by name.
188 * The pointer to a driver name to be initialized.
190 * The pointer to arguments used by driver initialization.
192 * 0 on success, negative on error
194 int rte_vdev_init(const char *name, const char *args);
197 * Uninitalize a driver specified by name.
200 * The pointer to a driver name to be uninitialized.
202 * 0 on success, negative on error
204 int rte_vdev_uninit(const char *name);