1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016 RehiveTech. All rights reserved.
19 #include <rte_devargs.h>
21 struct rte_vdev_device {
22 RTE_TAILQ_ENTRY(rte_vdev_device) next; /**< Next attached vdev */
23 struct rte_device device; /**< Inherit core device */
28 * Helper macro for drivers that need to convert to struct rte_vdev_device.
30 #define RTE_DEV_TO_VDEV(ptr) \
31 container_of(ptr, struct rte_vdev_device, device)
33 #define RTE_DEV_TO_VDEV_CONST(ptr) \
34 container_of(ptr, const struct rte_vdev_device, device)
36 #define RTE_ETH_DEV_TO_VDEV(eth_dev) RTE_DEV_TO_VDEV((eth_dev)->device)
38 static inline const char *
39 rte_vdev_device_name(const struct rte_vdev_device *dev)
41 if (dev && dev->device.name)
42 return dev->device.name;
46 static inline const char *
47 rte_vdev_device_args(const struct rte_vdev_device *dev)
49 if (dev && dev->device.devargs)
50 return dev->device.devargs->args;
54 /** Double linked list of virtual device drivers. */
55 RTE_TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
58 * Probe function called for each virtual device driver once.
60 typedef int (rte_vdev_probe_t)(struct rte_vdev_device *dev);
63 * Remove function called for each virtual device driver once.
65 typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
68 * Driver-specific DMA mapping. After a successful call the device
69 * will be able to read/write from/to this segment.
72 * Pointer to the Virtual device.
74 * Starting virtual address of memory to be mapped.
76 * Starting IOVA address of memory to be mapped.
78 * Length of memory segment being mapped.
81 * - Negative value and rte_errno is set otherwise.
83 typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr,
84 uint64_t iova, size_t len);
87 * Driver-specific DMA un-mapping. After a successful call the device
88 * will not be able to read/write from/to this segment.
91 * Pointer to the Virtual device.
93 * Starting virtual address of memory to be unmapped.
95 * Starting IOVA address of memory to be unmapped.
97 * Length of memory segment being unmapped.
100 * - Negative value and rte_errno is set otherwise.
102 typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr,
103 uint64_t iova, size_t len);
106 * A virtual device driver abstraction.
108 struct rte_vdev_driver {
109 RTE_TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */
110 struct rte_driver driver; /**< Inherited general driver. */
111 rte_vdev_probe_t *probe; /**< Virtual device probe function. */
112 rte_vdev_remove_t *remove; /**< Virtual device remove function. */
113 rte_vdev_dma_map_t *dma_map; /**< Virtual device DMA map function. */
114 rte_vdev_dma_unmap_t *dma_unmap; /**< Virtual device DMA unmap function. */
115 uint32_t drv_flags; /**< Flags RTE_VDEV_DRV_*. */
118 /** Device driver needs IOVA as VA and cannot work with IOVA as PA */
119 #define RTE_VDEV_DRV_NEED_IOVA_AS_VA 0x0001
122 * Register a virtual device driver.
125 * A pointer to a rte_vdev_driver structure describing the driver
128 void rte_vdev_register(struct rte_vdev_driver *driver);
131 * Unregister a virtual device driver.
134 * A pointer to a rte_vdev_driver structure describing the driver
135 * to be unregistered.
137 void rte_vdev_unregister(struct rte_vdev_driver *driver);
139 #define RTE_PMD_REGISTER_VDEV(nm, vdrv)\
140 static const char *vdrvinit_ ## nm ## _alias;\
141 RTE_INIT(vdrvinitfn_ ##vdrv)\
143 (vdrv).driver.name = RTE_STR(nm);\
144 (vdrv).driver.alias = vdrvinit_ ## nm ## _alias;\
145 rte_vdev_register(&vdrv);\
147 RTE_PMD_EXPORT_NAME(nm, __COUNTER__)
149 #define RTE_PMD_REGISTER_ALIAS(nm, alias)\
150 static const char *vdrvinit_ ## nm ## _alias = RTE_STR(alias)
152 typedef void (*rte_vdev_scan_callback)(void *user_arg);
155 * Add a callback to be called on vdev scan
156 * before reading the devargs list.
158 * This function cannot be called in a scan callback
159 * because of deadlock.
162 * The function to be called which can update the devargs list.
164 * An opaque pointer passed to callback.
166 * 0 on success, negative on error
169 rte_vdev_add_custom_scan(rte_vdev_scan_callback callback, void *user_arg);
172 * Remove a registered scan callback.
174 * This function cannot be called in a scan callback
175 * because of deadlock.
178 * The registered function to be removed.
180 * The associated opaque pointer or (void*)-1 for any.
185 rte_vdev_remove_custom_scan(rte_vdev_scan_callback callback, void *user_arg);
188 * Initialize a driver specified by name.
191 * The pointer to a driver name to be initialized.
193 * The pointer to arguments used by driver initialization.
195 * 0 on success, negative on error
197 int rte_vdev_init(const char *name, const char *args);
200 * Uninitialize a driver specified by name.
203 * The pointer to a driver name to be uninitialized.
205 * 0 on success, negative on error
207 int rte_vdev_uninit(const char *name);