DPDK patches and discussions
 help / color / mirror / Atom feed
From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com,
	anatoly.burakov@intel.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Subject: [dpdk-dev] [PATCH 4/4] net/virtio: add DMA mapping callback to virtio-user
Date: Fri, 13 Dec 2019 15:13:22 +0100	[thread overview]
Message-ID: <20191213141322.32730-5-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20191213141322.32730-1-maxime.coquelin@redhat.com>

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(-)

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,
 };
-- 
2.21.0


  parent reply	other threads:[~2019-12-13 14:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13 14:13 [dpdk-dev] [PATCH 0/4] Add external contiguous memory support to Virtio-user Maxime Coquelin
2019-12-13 14:13 ` [dpdk-dev] [PATCH 1/4] eal: add new API to register contiguous external memory Maxime Coquelin
2020-01-23 13:06   ` Burakov, Anatoly
2019-12-13 14:13 ` [dpdk-dev] [PATCH 2/4] eal: allow getting memory segment FD with " Maxime Coquelin
2019-12-13 14:13 ` [dpdk-dev] [PATCH 3/4] bus/vdev: add DMA mapping supprt Maxime Coquelin
2019-12-13 14:13 ` Maxime Coquelin [this message]
2020-01-08 16:11 ` [dpdk-dev] [PATCH 0/4] Add external contiguous memory support to Virtio-user Maxime Coquelin
2023-08-25  9:55 ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191213141322.32730-5-maxime.coquelin@redhat.com \
    --to=maxime.coquelin@redhat.com \
    --cc=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    --cc=tiwei.bie@intel.com \
    --cc=zhihong.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).