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 3/4] bus/vdev: add DMA mapping supprt
Date: Fri, 13 Dec 2019 15:13:21 +0100	[thread overview]
Message-ID: <20191213141322.32730-4-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20191213141322.32730-1-maxime.coquelin@redhat.com>

This patch enables VDEVs to implement their own DMA map
and unmap callbacks.

It will be used by Virtio-user PMD to support external
memory registered by applications like Seastar or VPP.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/bus/vdev/rte_bus_vdev.h | 24 ++++++++++++++++
 drivers/bus/vdev/vdev.c         | 50 +++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/drivers/bus/vdev/rte_bus_vdev.h b/drivers/bus/vdev/rte_bus_vdev.h
index 2bc46530c9..6f920cb064 100644
--- a/drivers/bus/vdev/rte_bus_vdev.h
+++ b/drivers/bus/vdev/rte_bus_vdev.h
@@ -53,6 +53,18 @@ rte_vdev_device_args(const struct rte_vdev_device *dev)
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
+/**
+ * Virtual device DMA map function.
+ */
+typedef int (rte_vdev_dma_map_t)(struct rte_vdev_device *dev, void *addr,
+			    uint64_t iova, size_t len);
+
+/**
+ * Virtual device DMA unmap function.
+ */
+typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr,
+			    uint64_t iova, size_t len);
+
 /**
  * Probe function called for each virtual device driver once.
  */
@@ -69,10 +81,22 @@ typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
 struct rte_vdev_driver {
 	TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */
 	struct rte_driver driver;      /**< Inherited general driver. */
+	rte_vdev_dma_map_t *dma_map;   /**<Virtual device DMA map function. */
+	rte_vdev_dma_unmap_t *dma_unmap;   /**<Virtual device DMA unmap function. */
 	rte_vdev_probe_t *probe;       /**< Virtual device probe function. */
 	rte_vdev_remove_t *remove;     /**< Virtual device remove function. */
 };
 
+/**
+ * @internal
+ * Helper macro for drivers that need to convert to struct rte_vdev_driver.
+ */
+#define RTE_DRV_TO_VDRV(ptr) \
+	container_of(ptr, struct rte_vdev_driver, driver)
+
+#define RTE_DRV_TO_VDRV_CONST(ptr) \
+	container_of(ptr, const struct rte_vdev_driver, driver)
+
 /**
  * Register a virtual device driver.
  *
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index a89ea23530..8bdca23448 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -546,6 +546,54 @@ vdev_unplug(struct rte_device *dev)
 	return rte_vdev_uninit(dev->name);
 }
 
+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 *vdrv;
+
+	if (!dev || !dev->driver) {
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	vdrv = RTE_DRV_TO_VDRV_CONST(dev->driver);
+	if (!vdrv) {
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	if (vdrv->dma_map)
+		return vdrv->dma_map(vdev, addr, iova, len);
+
+	rte_errno = ENOTSUP;
+	return -1;
+}
+
+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 *vdrv;
+
+	if (!dev || !dev->driver) {
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	vdrv = RTE_DRV_TO_VDRV_CONST(dev->driver);
+	if (!vdrv) {
+		rte_errno = EINVAL;
+		return -1;
+	}
+
+	if (vdrv->dma_map)
+		return vdrv->dma_unmap(vdev, addr, iova, len);
+
+	rte_errno = ENOTSUP;
+	return -1;
+}
+
 static struct rte_bus rte_vdev_bus = {
 	.scan = vdev_scan,
 	.probe = vdev_probe,
@@ -553,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,
 };
 
-- 
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 ` Maxime Coquelin [this message]
2019-12-13 14:13 ` [dpdk-dev] [PATCH 4/4] net/virtio: add DMA mapping callback to virtio-user Maxime Coquelin
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-4-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).