Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2016 RehiveTech. All rights reserved. 3 : : */ 4 : : 5 : : #ifndef BUS_VDEV_DRIVER_H 6 : : #define BUS_VDEV_DRIVER_H 7 : : 8 : : #include <rte_bus_vdev.h> 9 : : #include <rte_compat.h> 10 : : #include <dev_driver.h> 11 : : #include <rte_devargs.h> 12 : : 13 : : #ifdef __cplusplus 14 : : extern "C" { 15 : : #endif 16 : : 17 : : struct rte_vdev_device { 18 : : RTE_TAILQ_ENTRY(rte_vdev_device) next; /**< Next attached vdev */ 19 : : struct rte_device device; /**< Inherit core device */ 20 : : }; 21 : : 22 : : /** 23 : : * @internal 24 : : * Helper macro for drivers that need to convert to struct rte_vdev_device. 25 : : */ 26 : : #define RTE_DEV_TO_VDEV(ptr) \ 27 : : container_of(ptr, struct rte_vdev_device, device) 28 : : 29 : : #define RTE_DEV_TO_VDEV_CONST(ptr) \ 30 : : container_of(ptr, const struct rte_vdev_device, device) 31 : : 32 : : #define RTE_ETH_DEV_TO_VDEV(eth_dev) RTE_DEV_TO_VDEV((eth_dev)->device) 33 : : 34 : : static inline const char * 35 : : rte_vdev_device_name(const struct rte_vdev_device *dev) 36 : : { 37 [ + - + - : 176 : if (dev && dev->device.name) + - + - + - + - + - + - # # # # ] 38 : 162 : return dev->device.name; 39 : : return NULL; 40 : : } 41 : : 42 : : static inline const char * 43 : : rte_vdev_device_args(const struct rte_vdev_device *dev) 44 : : { 45 [ + - + - : 27 : if (dev && dev->device.devargs) # # # # ] 46 : 27 : return dev->device.devargs->args; 47 : : return ""; 48 : : } 49 : : 50 : : /** 51 : : * Probe function called for each virtual device driver once. 52 : : */ 53 : : typedef int (rte_vdev_probe_t)(struct rte_vdev_device *dev); 54 : : 55 : : /** 56 : : * Remove function called for each virtual device driver once. 57 : : */ 58 : : typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev); 59 : : 60 : : /** 61 : : * Driver-specific DMA mapping. After a successful call the device 62 : : * will be able to read/write from/to this segment. 63 : : * 64 : : * @param dev 65 : : * Pointer to the Virtual device. 66 : : * @param addr 67 : : * Starting virtual address of memory to be mapped. 68 : : * @param iova 69 : : * Starting IOVA address of memory to be mapped. 70 : : * @param len 71 : : * Length of memory segment being mapped. 72 : : * @return 73 : : * - 0 On success. 74 : : * - Negative value and rte_errno is set otherwise. 75 : : */ 76 : : typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr, 77 : : uint64_t iova, size_t len); 78 : : 79 : : /** 80 : : * Driver-specific DMA un-mapping. After a successful call the device 81 : : * will not be able to read/write from/to this segment. 82 : : * 83 : : * @param dev 84 : : * Pointer to the Virtual device. 85 : : * @param addr 86 : : * Starting virtual address of memory to be unmapped. 87 : : * @param iova 88 : : * Starting IOVA address of memory to be unmapped. 89 : : * @param len 90 : : * Length of memory segment being unmapped. 91 : : * @return 92 : : * - 0 On success. 93 : : * - Negative value and rte_errno is set otherwise. 94 : : */ 95 : : typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr, 96 : : uint64_t iova, size_t len); 97 : : 98 : : /** 99 : : * A virtual device driver abstraction. 100 : : */ 101 : : struct rte_vdev_driver { 102 : : RTE_TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */ 103 : : struct rte_driver driver; /**< Inherited general driver. */ 104 : : rte_vdev_probe_t *probe; /**< Virtual device probe function. */ 105 : : rte_vdev_remove_t *remove; /**< Virtual device remove function. */ 106 : : rte_vdev_dma_map_t *dma_map; /**< Virtual device DMA map function. */ 107 : : rte_vdev_dma_unmap_t *dma_unmap; /**< Virtual device DMA unmap function. */ 108 : : uint32_t drv_flags; /**< Flags RTE_VDEV_DRV_*. */ 109 : : }; 110 : : 111 : : /** Device driver needs IOVA as VA and cannot work with IOVA as PA */ 112 : : #define RTE_VDEV_DRV_NEED_IOVA_AS_VA 0x0001 113 : : 114 : : /** 115 : : * Register a virtual device driver. 116 : : * 117 : : * @param driver 118 : : * A pointer to a rte_vdev_driver structure describing the driver 119 : : * to be registered. 120 : : */ 121 : : __rte_internal 122 : : void rte_vdev_register(struct rte_vdev_driver *driver); 123 : : 124 : : /** 125 : : * Unregister a virtual device driver. 126 : : * 127 : : * @param driver 128 : : * A pointer to a rte_vdev_driver structure describing the driver 129 : : * to be unregistered. 130 : : */ 131 : : __rte_internal 132 : : void rte_vdev_unregister(struct rte_vdev_driver *driver); 133 : : 134 : : #define RTE_PMD_REGISTER_VDEV(nm, vdrv)\ 135 : : static const char *vdrvinit_ ## nm ## _alias;\ 136 : : RTE_INIT(vdrvinitfn_ ##vdrv)\ 137 : : {\ 138 : : (vdrv).driver.name = RTE_STR(nm);\ 139 : : (vdrv).driver.alias = vdrvinit_ ## nm ## _alias;\ 140 : : rte_vdev_register(&vdrv);\ 141 : : } \ 142 : : RTE_PMD_EXPORT_NAME(nm, __COUNTER__) 143 : : 144 : : #define RTE_PMD_REGISTER_ALIAS(nm, alias)\ 145 : : static const char *vdrvinit_ ## nm ## _alias = RTE_STR(alias) 146 : : 147 : : #ifdef __cplusplus 148 : : } 149 : : #endif 150 : : 151 : : #endif /* BUS_VDEV_DRIVER_H */