[4/4] net/virtio: add DMA mapping callback to virtio-user
diff mbox series

Message ID 20191213141322.32730-5-maxime.coquelin@redhat.com
State New
Headers show
Series
  • Add external contiguous memory support to Virtio-user
Related show

Checks

Context Check Description
ci/travis-robot success Travis build: passed
ci/Intel-compilation fail Compilation issues
ci/checkpatch warning coding style issues

Commit Message

Maxime Coquelin Dec. 13, 2019, 2:13 p.m. UTC
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 10 +---
 .../net/virtio/virtio_user/virtio_user_dev.h  |  3 +
 drivers/net/virtio/virtio_user_ethdev.c       | 58 +++++++++++++++++++
 3 files changed, 63 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index ea016e85d8..c72a9543cd 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -313,21 +313,15 @@  virtio_user_fill_intr_handle(struct virtio_user_dev *dev)
 	return 0;
 }
 
-static void
+void
 virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused,
-			 const void *addr,
+			 const void *addr __rte_unused,
 			 size_t len __rte_unused,
 			 void *arg)
 {
 	struct virtio_user_dev *dev = arg;
-	struct rte_memseg_list *msl;
 	uint16_t i;
 
-	/* ignore externally allocated memory */
-	msl = rte_mem_virt2memseg_list(addr);
-	if (msl->external)
-		return;
-
 	pthread_mutex_lock(&dev->mutex);
 
 	if (dev->started == false)
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.h b/drivers/net/virtio/virtio_user/virtio_user_dev.h
index ad86837717..5a147c74f0 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.h
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.h
@@ -67,4 +67,7 @@  void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
 void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
 				  uint16_t queue_idx);
 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
+void
+virtio_user_mem_event_cb(enum rte_mem_event type,
+			const void *addr, size_t len , void *arg);
 #endif
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 3fc1725736..fd3ce2dfab 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -385,6 +385,62 @@  const struct virtio_pci_ops virtio_user_ops = {
 	.notify_queue	= virtio_user_notify_queue,
 };
 
+static int
+virtio_user_dma_map(struct rte_vdev_device *vdev, void *addr,
+		uint64_t iova __rte_unused, size_t len)
+{
+	const char *name;
+	struct rte_eth_dev *eth_dev;
+	struct virtio_hw *hw;
+	struct virtio_user_dev *dev;
+
+	if (!vdev)
+		return -EINVAL;
+
+	name = rte_vdev_device_name(vdev);
+	eth_dev = rte_eth_dev_allocated(name);
+	if (!eth_dev)
+		return -ENODEV;
+
+	hw = eth_dev->data->dev_private;
+	dev = hw->virtio_user_dev;
+
+	virtio_user_mem_event_cb(RTE_MEM_EVENT_ALLOC,
+						 addr,
+						 len,
+						 (void *)dev);
+
+	return 0;
+}
+
+static int
+virtio_user_dma_unmap(struct rte_vdev_device *vdev, void *addr,
+		uint64_t iova __rte_unused, size_t len)
+{
+	const char *name;
+	struct rte_eth_dev *eth_dev;
+	struct virtio_hw *hw;
+	struct virtio_user_dev *dev;
+
+	if (!vdev)
+		return -EINVAL;
+
+	name = rte_vdev_device_name(vdev);
+	eth_dev = rte_eth_dev_allocated(name);
+	if (!eth_dev)
+		return -ENODEV;
+
+	hw = eth_dev->data->dev_private;
+	dev = hw->virtio_user_dev;
+
+	virtio_user_mem_event_cb(RTE_MEM_EVENT_FREE,
+						 addr,
+						 len,
+						 (void *)dev);
+
+	return 0;
+}
+
 static const char *valid_args[] = {
 #define VIRTIO_USER_ARG_QUEUES_NUM     "queues"
 	VIRTIO_USER_ARG_QUEUES_NUM,
@@ -717,6 +773,8 @@  virtio_user_pmd_remove(struct rte_vdev_device *vdev)
 }
 
 static struct rte_vdev_driver virtio_user_driver = {
+	.dma_map = virtio_user_dma_map,
+	.dma_unmap = virtio_user_dma_unmap,
 	.probe = virtio_user_pmd_probe,
 	.remove = virtio_user_pmd_remove,
 };