[v2,1/8] bus/vdev: add DMA mapping ops
Checks
Commit Message
Add DMA map/unmap operation callbacks to the vdev bus, which
could be used by DMA capable vdev drivers.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
drivers/bus/vdev/rte_bus_vdev.h | 46 +++++++++++++++++++++++++++--
drivers/bus/vdev/vdev.c | 52 +++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 3 deletions(-)
Comments
25/09/2020 14:31, Maxime Coquelin:
> Add DMA map/unmap operation callbacks to the vdev bus, which
> could be used by DMA capable vdev drivers.
[...]
> @@ -551,6 +601,8 @@ static struct rte_bus rte_vdev_bus = {
> .plug = vdev_plug,
> .unplug = vdev_unplug,
> .parse = vdev_parse,
> + .dma_map = vdev_dma_map,
> + .dma_unmap = vdev_dma_unmap,
> .dev_iterate = rte_vdev_dev_iterate,
> };
The functions map/unmap look to be the same as in PCI bus driver.
I wonder whether it would make sense to move these operations
at rte_driver level?
It seems we don't need anything specific to PCI or vdev,
but just being able to get some class driver private data, right?
@@ -63,14 +63,54 @@ typedef int (rte_vdev_probe_t)(struct rte_vdev_device *dev);
*/
typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
+/**
+ * Driver-specific DMA mapping. After a successful call the device
+ * will be able to read/write from/to this segment.
+ *
+ * @param dev
+ * Pointer to the Virtual device.
+ * @param addr
+ * Starting virtual address of memory to be mapped.
+ * @param iova
+ * Starting IOVA address of memory to be mapped.
+ * @param len
+ * Length of memory segment being mapped.
+ * @return
+ * - 0 On success.
+ * - Negative value and rte_errno is set otherwise.
+ */
+typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr,
+ uint64_t iova, size_t len);
+
+/**
+ * Driver-specific DMA un-mapping. After a successful call the device
+ * will not be able to read/write from/to this segment.
+ *
+ * @param dev
+ * Pointer to the Virtual device.
+ * @param addr
+ * Starting virtual address of memory to be unmapped.
+ * @param iova
+ * Starting IOVA address of memory to be unmapped.
+ * @param len
+ * Length of memory segment being unmapped.
+ * @return
+ * - 0 On success.
+ * - Negative value and rte_errno is set otherwise.
+ */
+typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr,
+ uint64_t iova, size_t len);
+
/**
* A virtual device driver abstraction.
*/
struct rte_vdev_driver {
TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */
- struct rte_driver driver; /**< Inherited general driver. */
- rte_vdev_probe_t *probe; /**< Virtual device probe function. */
- rte_vdev_remove_t *remove; /**< Virtual device remove function. */
+ struct rte_driver driver; /**< Inherited general driver. */
+ rte_vdev_probe_t *probe; /**< Virtual device probe function. */
+ rte_vdev_remove_t *remove; /**< Virtual device remove function. */
+ rte_vdev_dma_map_t *dma_map; /**< Virtual device DMA map function. */
+ rte_vdev_dma_unmap_t *dma_unmap; /**< Virtual device DMA unmap function. */
};
/**
@@ -134,6 +134,56 @@ vdev_parse(const char *name, void *addr)
return driver == NULL;
}
+static int
+vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
+{
+ struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
+ const struct rte_vdev_driver *driver;
+
+ if (!vdev) {
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ if (!vdev->device.driver) {
+ VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
+ return 1;
+ }
+
+ driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
+ driver);
+
+ if (driver->dma_map)
+ return driver->dma_map(vdev, addr, iova, len);
+
+ return 0;
+}
+
+static int
+vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
+{
+ struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
+ const struct rte_vdev_driver *driver;
+
+ if (!vdev) {
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ if (!vdev->device.driver) {
+ VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
+ return 1;
+ }
+
+ driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
+ driver);
+
+ if (driver->dma_unmap)
+ return driver->dma_unmap(vdev, addr, iova, len);
+
+ return 0;
+}
+
static int
vdev_probe_all_drivers(struct rte_vdev_device *dev)
{
@@ -551,6 +601,8 @@ static struct rte_bus rte_vdev_bus = {
.plug = vdev_plug,
.unplug = vdev_unplug,
.parse = vdev_parse,
+ .dma_map = vdev_dma_map,
+ .dma_unmap = vdev_dma_unmap,
.dev_iterate = rte_vdev_dev_iterate,
};