From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 11461A034F; Thu, 1 Apr 2021 00:46:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8947C140F1E; Thu, 1 Apr 2021 00:46:33 +0200 (CEST) Received: from new2-smtp.messagingengine.com (new2-smtp.messagingengine.com [66.111.4.224]) by mails.dpdk.org (Postfix) with ESMTP id 5632D40142 for ; Thu, 1 Apr 2021 00:46:32 +0200 (CEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id BACE15808E1; Wed, 31 Mar 2021 18:46:31 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 31 Mar 2021 18:46:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=zaIeQkK4rQu4QUXfR3zCxp1aG2 TjHDVyeLQrQ8zHGYU=; b=1w/Wrf4YLhNw8w1f3rCdYaUBWAaBMcwg9WSByPiigE PEHgUatZgWab5EOmkZ9Oj1uFhbwfYTppW4oO4sIbyVBX3IaqHPFVea4LnfT6XYRx BXpc2iqi97971dGucKjnqhoSLhIR9dFTydT652g98SvRDYzSuIX5swsJXtXr5n3L RiIg+g7GObGsHz9H1StluQAyrhcyokUJqw3JmDwoYTPTBf3IL7/jEB4uU+uNZXpG DeVKUB0ym4xOvr88Zg9SbjmjpNav2eZPhQ9h7BY81Q9O2rAO+z4PhlOdUIisdEJ7 pbn230fWRRz+vbE+KtzkpQq88ctjk/O7c8NGBZWVNagw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=zaIeQkK4rQu4QUXfR 3zCxp1aG2TjHDVyeLQrQ8zHGYU=; b=u4cDmzIfgmtJ4PyFan6/9wydtir9IcbJT XC4l3PX00q1lL8mfLGG/pFWwPq+vUrin0y2FG7PnIVc32B4RBsEpR8eu9i1bPduf K6AYDoES31EJ7GMJI5d7fBcR1LYxDnkyABm1wyWA7HXAE07BlBV9lL+FDov1nXjw FGT8fYbUSBt0Hcl8fFUzSJykmTs9L1UL0oK3aLb8ocuLtviH/Hd2EjpNiW/qwyT5 XYWJCw7oOxIcVUgZcwAGnYt08ajCNnB4TL0Tz6BbN5ie8kRP0ptuIJVlBbzi//w0 bNg2bwRrZ5ioX58lTVwumnC12uj8wkCn55flDEIBBSJ8Cj7VzZUZA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudeifedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpefvhhhomhgrshcu ofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecuggftrf grthhtvghrnhepvdelvdduhedvudduveeuvdevheegudelgeeigfejheduhedttdegudff jeeihffgnecukfhppeejjedrudefgedrvddtfedrudekgeenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhomhgrshesmhhonhhjrghlohhn rdhnvght X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id E914124005E; Wed, 31 Mar 2021 18:46:28 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: hemant.agrawal@nxp.com, rosen.xu@intel.com, sthemmin@microsoft.com, longli@microsoft.com, jerinj@marvell.com, ferruh.yigit@intel.com, andrew.rybchenko@oktetlabs.ru, Matan Azrad , Shahaf Shuler , Viacheslav Ovsiienko , Maxime Coquelin , Chenbo Xia Date: Thu, 1 Apr 2021 00:45:46 +0200 Message-Id: <20210331224547.2217759-1-thomas@monjalon.net> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] eal: move DMA mapping from bus-specific to generic driver X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The operations of DMA mapping and unmapping are controlled in some bus drivers, following rte_bus specification. If the device driver don't provide any specific mapping operation, the bus driver may have a fallback (VFIO case for PCI). The DMA mapping done by the device drivers are called from the bus drivers via function pointers in bus-specific structures: rte_vdev_driver and rte_pci_driver. The device driver DMA mapping is not specific to the bus, so it can be generalized to all device drivers, based on rte_device. That's why the function pointers dma_map and dma_unmap are moved to rte_driver, avoiding useless casts of device object. The function prototypes rte_dev_dma_map_t and rte_dev_dma_unmap_t are removed from rte_bus.h because the definition in rte_dev.h is enough, but they are still used in rte_bus for bus drivers, while being added in rte_driver for device drivers, and removed from rte_vdev_driver/rte_pci_driver. The impacted device drivers are mlx5 (PCI) and virtio_user (vdev). Signed-off-by: Thomas Monjalon --- Depends-on: series-16017 ("pci: add rte prefix") --- drivers/bus/pci/pci_common.c | 8 ++-- drivers/bus/pci/rte_bus_pci.h | 40 -------------------- drivers/bus/vdev/rte_bus_vdev.h | 40 -------------------- drivers/bus/vdev/vdev.c | 32 +++++----------- drivers/common/mlx5/mlx5_common_pci.c | 30 ++++++++------- drivers/net/mlx5/mlx5.c | 4 +- drivers/net/mlx5/mlx5_mr.c | 50 +++++++++++++------------ drivers/net/mlx5/mlx5_rxtx.h | 4 +- drivers/net/virtio/virtio_user_ethdev.c | 22 +++++------ lib/librte_eal/include/rte_bus.h | 42 --------------------- lib/librte_eal/include/rte_dev.h | 49 +++++++++++++++++++++++- 11 files changed, 117 insertions(+), 204 deletions(-) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index ee7f966358..75e3f01352 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -585,8 +585,8 @@ pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) rte_errno = EINVAL; return -1; } - if (pdev->driver->dma_map) - return pdev->driver->dma_map(pdev, addr, iova, len); + if (dev->driver->dma_map) + return dev->driver->dma_map(dev, addr, iova, len); /** * In case driver don't provides any specific mapping * try fallback to VFIO. @@ -608,8 +608,8 @@ pci_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len) rte_errno = EINVAL; return -1; } - if (pdev->driver->dma_unmap) - return pdev->driver->dma_unmap(pdev, addr, iova, len); + if (dev->driver->dma_unmap) + return dev->driver->dma_unmap(dev, addr, iova, len); /** * In case driver don't provides any specific mapping * try fallback to VFIO. diff --git a/drivers/bus/pci/rte_bus_pci.h b/drivers/bus/pci/rte_bus_pci.h index 64886b4731..5f2bf1cc33 100644 --- a/drivers/bus/pci/rte_bus_pci.h +++ b/drivers/bus/pci/rte_bus_pci.h @@ -119,44 +119,6 @@ typedef int (rte_pci_probe_t)(struct rte_pci_driver *, struct rte_pci_device *); */ typedef int (rte_pci_remove_t)(struct rte_pci_device *); -/** - * 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 PCI 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 (pci_dma_map_t)(struct rte_pci_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 PCI 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 (pci_dma_unmap_t)(struct rte_pci_device *dev, void *addr, - uint64_t iova, size_t len); - /** * A structure describing a PCI driver. */ @@ -166,8 +128,6 @@ struct rte_pci_driver { struct rte_pci_bus *bus; /**< PCI bus reference. */ rte_pci_probe_t *probe; /**< Device probe function. */ rte_pci_remove_t *remove; /**< Device remove function. */ - pci_dma_map_t *dma_map; /**< device dma map function. */ - pci_dma_unmap_t *dma_unmap; /**< device dma unmap function. */ const struct rte_pci_id *id_table; /**< ID table, NULL terminated. */ uint32_t drv_flags; /**< Flags RTE_PCI_DRV_*. */ }; diff --git a/drivers/bus/vdev/rte_bus_vdev.h b/drivers/bus/vdev/rte_bus_vdev.h index fc315d10fa..a5ea830e55 100644 --- a/drivers/bus/vdev/rte_bus_vdev.h +++ b/drivers/bus/vdev/rte_bus_vdev.h @@ -65,44 +65,6 @@ 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. */ @@ -111,8 +73,6 @@ struct rte_vdev_driver { 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. */ uint32_t drv_flags; /**< Flags RTE_VDEV_DRV_*. */ }; diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 9a673347ae..3ba268f783 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -137,24 +137,18 @@ vdev_parse(const char *name, void *addr) 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) { + if (dev == NULL) { rte_errno = EINVAL; return -1; } - if (!vdev->device.driver) { - VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name); + if (dev->driver == NULL) { + VDEV_LOG(DEBUG, "no driver attached 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); + if (dev->driver->dma_map) + return dev->driver->dma_map(dev, addr, iova, len); return 0; } @@ -162,24 +156,18 @@ vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) 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) { + if (dev == NULL) { rte_errno = EINVAL; return -1; } - if (!vdev->device.driver) { - VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name); + if (dev->driver == NULL) { + VDEV_LOG(DEBUG, "no driver attached 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); + if (dev->driver->dma_unmap) + return dev->driver->dma_unmap(dev, addr, iova, len); return 0; } diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c index a7f541a90c..a9f50dca07 100644 --- a/drivers/common/mlx5/mlx5_common_pci.c +++ b/drivers/common/mlx5/mlx5_common_pci.c @@ -350,7 +350,7 @@ mlx5_common_pci_remove(struct rte_pci_device *pci_dev) } static int -mlx5_common_pci_dma_map(struct rte_pci_device *pci_dev, void *addr, +mlx5_common_pci_dma_map(struct rte_device *rte_dev, void *addr, uint64_t iova, size_t len) { struct mlx5_pci_driver *driver = NULL; @@ -358,14 +358,14 @@ mlx5_common_pci_dma_map(struct rte_pci_device *pci_dev, void *addr, struct mlx5_pci_device *dev; int ret = -EINVAL; - dev = pci_to_mlx5_device(pci_dev); + dev = pci_to_mlx5_device(RTE_DEV_TO_PCI(rte_dev)); if (!dev) return -ENODEV; TAILQ_FOREACH(driver, &drv_list, next) { if (device_class_enabled(dev, driver->driver_class) && - driver->pci_driver.dma_map) { - ret = driver->pci_driver.dma_map(pci_dev, addr, - iova, len); + driver->pci_driver.driver.dma_map) { + ret = driver->pci_driver.driver.dma_map(rte_dev, + addr, iova, len); if (ret) goto map_err; } @@ -376,14 +376,16 @@ mlx5_common_pci_dma_map(struct rte_pci_device *pci_dev, void *addr, if (temp == driver) break; if (device_class_enabled(dev, temp->driver_class) && - temp->pci_driver.dma_map && temp->pci_driver.dma_unmap) - temp->pci_driver.dma_unmap(pci_dev, addr, iova, len); + temp->pci_driver.driver.dma_map && + temp->pci_driver.driver.dma_unmap) + temp->pci_driver.driver.dma_unmap(rte_dev, + addr, iova, len); } return ret; } static int -mlx5_common_pci_dma_unmap(struct rte_pci_device *pci_dev, void *addr, +mlx5_common_pci_dma_unmap(struct rte_device *rte_dev, void *addr, uint64_t iova, size_t len) { struct mlx5_pci_driver *driver; @@ -391,16 +393,16 @@ mlx5_common_pci_dma_unmap(struct rte_pci_device *pci_dev, void *addr, int local_ret = -EINVAL; int ret; - dev = pci_to_mlx5_device(pci_dev); + dev = pci_to_mlx5_device(RTE_DEV_TO_PCI(rte_dev)); if (!dev) return -ENODEV; ret = 0; /* There is no unmap error recovery in current implementation. */ TAILQ_FOREACH_REVERSE(driver, &drv_list, mlx5_pci_bus_drv_head, next) { if (device_class_enabled(dev, driver->driver_class) && - driver->pci_driver.dma_unmap) { - local_ret = driver->pci_driver.dma_unmap(pci_dev, addr, - iova, len); + driver->pci_driver.driver.dma_unmap) { + local_ret = driver->pci_driver.driver.dma_unmap(rte_dev, + addr, iova, len); if (local_ret && (ret == 0)) ret = local_ret; } @@ -416,11 +418,11 @@ static struct rte_pci_id *mlx5_pci_id_table; static struct rte_pci_driver mlx5_pci_driver = { .driver = { .name = MLX5_DRIVER_NAME, + .dma_map = mlx5_common_pci_dma_map, + .dma_unmap = mlx5_common_pci_dma_unmap, }, .probe = mlx5_common_pci_probe, .remove = mlx5_common_pci_remove, - .dma_map = mlx5_common_pci_dma_map, - .dma_unmap = mlx5_common_pci_dma_unmap, }; static int diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index abd7ff70df..f420fc7986 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -2216,12 +2216,12 @@ static struct mlx5_pci_driver mlx5_driver = { .pci_driver = { .driver = { .name = MLX5_DRIVER_NAME, + .dma_map = mlx5_dma_map, + .dma_unmap = mlx5_dma_unmap, }, .id_table = mlx5_pci_id_map, .probe = mlx5_os_pci_probe, .remove = mlx5_pci_remove, - .dma_map = mlx5_dma_map, - .dma_unmap = mlx5_dma_unmap, .drv_flags = PCI_DRV_FLAGS, }, }; diff --git a/drivers/net/mlx5/mlx5_mr.c b/drivers/net/mlx5/mlx5_mr.c index 3255393ca2..6caf046838 100644 --- a/drivers/net/mlx5/mlx5_mr.c +++ b/drivers/net/mlx5/mlx5_mr.c @@ -288,33 +288,33 @@ mlx5_mr_update_ext_mp_cb(struct rte_mempool *mp, void *opaque, } /** - * Finds the first ethdev that match the pci device. - * The existence of multiple ethdev per pci device is only with representors. + * Find the first ethdev that matches the device. + * The existence of multiple ethdev per device is only with representors. * On such case, it is enough to get only one of the ports as they all share * the same ibv context. * - * @param pdev - * Pointer to the PCI device. + * @param dev + * Pointer to the generic device. * * @return * Pointer to the ethdev if found, NULL otherwise. */ static struct rte_eth_dev * -pci_dev_to_eth_dev(struct rte_pci_device *pdev) +dev_to_eth_dev(struct rte_device *dev) { uint16_t port_id; - port_id = rte_eth_find_next_of(0, &pdev->device); - if (port_id == RTE_MAX_ETHPORTS) - return NULL; - return &rte_eth_devices[port_id]; + RTE_ETH_FOREACH_DEV_OF(port_id, dev) + return &rte_eth_devices[port_id]; + + return NULL; } /** * DPDK callback to DMA map external memory to a PCI device. * - * @param pdev - * Pointer to the PCI device. + * @param rte_dev + * Pointer to the generic device. * @param addr * Starting virtual address of memory to be mapped. * @param iova @@ -326,7 +326,7 @@ pci_dev_to_eth_dev(struct rte_pci_device *pdev) * 0 on success, negative value on error. */ int -mlx5_dma_map(struct rte_pci_device *pdev, void *addr, +mlx5_dma_map(struct rte_device *rte_dev, void *addr, uint64_t iova __rte_unused, size_t len) { struct rte_eth_dev *dev; @@ -334,10 +334,11 @@ mlx5_dma_map(struct rte_pci_device *pdev, void *addr, struct mlx5_priv *priv; struct mlx5_dev_ctx_shared *sh; - dev = pci_dev_to_eth_dev(pdev); + dev = dev_to_eth_dev(rte_dev); if (!dev) { - DRV_LOG(WARNING, "unable to find matching ethdev " - "to PCI device %p", (void *)pdev); + DRV_LOG(WARNING, + "unable to find matching ethdev to device %s", + rte_dev->name); rte_errno = ENODEV; return -1; } @@ -362,8 +363,8 @@ mlx5_dma_map(struct rte_pci_device *pdev, void *addr, /** * DPDK callback to DMA unmap external memory to a PCI device. * - * @param pdev - * Pointer to the PCI device. + * @param rte_dev + * Pointer to the generic device. * @param addr * Starting virtual address of memory to be unmapped. * @param iova @@ -375,7 +376,7 @@ mlx5_dma_map(struct rte_pci_device *pdev, void *addr, * 0 on success, negative value on error. */ int -mlx5_dma_unmap(struct rte_pci_device *pdev, void *addr, +mlx5_dma_unmap(struct rte_device *rte_dev, void *addr, uint64_t iova __rte_unused, size_t len __rte_unused) { struct rte_eth_dev *dev; @@ -384,10 +385,11 @@ mlx5_dma_unmap(struct rte_pci_device *pdev, void *addr, struct mlx5_mr *mr; struct mr_cache_entry entry; - dev = pci_dev_to_eth_dev(pdev); + dev = dev_to_eth_dev(rte_dev); if (!dev) { - DRV_LOG(WARNING, "unable to find matching ethdev " - "to PCI device %p", (void *)pdev); + DRV_LOG(WARNING, + "unable to find matching ethdev to device %s", + rte_dev->name); rte_errno = ENODEV; return -1; } @@ -397,9 +399,9 @@ mlx5_dma_unmap(struct rte_pci_device *pdev, void *addr, mr = mlx5_mr_lookup_list(&sh->share_cache, &entry, (uintptr_t)addr); if (!mr) { rte_rwlock_read_unlock(&sh->share_cache.rwlock); - DRV_LOG(WARNING, "address 0x%" PRIxPTR " wasn't registered " - "to PCI device %p", (uintptr_t)addr, - (void *)pdev); + DRV_LOG(WARNING, + "address 0x%" PRIxPTR " wasn't registered to device %s", + (uintptr_t)addr, rte_dev->name); rte_errno = EINVAL; return -1; } diff --git a/drivers/net/mlx5/mlx5_rxtx.h b/drivers/net/mlx5/mlx5_rxtx.h index 4f0fda0dec..ba0eb28995 100644 --- a/drivers/net/mlx5/mlx5_rxtx.h +++ b/drivers/net/mlx5/mlx5_rxtx.h @@ -458,9 +458,9 @@ uint32_t mlx5_rx_addr2mr_bh(struct mlx5_rxq_data *rxq, uintptr_t addr); uint32_t mlx5_tx_mb2mr_bh(struct mlx5_txq_data *txq, struct rte_mbuf *mb); uint32_t mlx5_tx_update_ext_mp(struct mlx5_txq_data *txq, uintptr_t addr, struct rte_mempool *mp); -int mlx5_dma_map(struct rte_pci_device *pdev, void *addr, uint64_t iova, +int mlx5_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len); -int mlx5_dma_unmap(struct rte_pci_device *pdev, void *addr, uint64_t iova, +int mlx5_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len); /** diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 1810a54694..3d640fb951 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -712,18 +712,16 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev) return rte_eth_dev_close(eth_dev->data->port_id); } -static int virtio_user_pmd_dma_map(struct rte_vdev_device *vdev, void *addr, +static int virtio_user_pmd_dma_map(struct rte_device *rte_dev, void *addr, uint64_t iova, size_t len) { - const char *name; struct rte_eth_dev *eth_dev; struct virtio_user_dev *dev; - if (!vdev) + if (rte_dev == NULL) return -EINVAL; - name = rte_vdev_device_name(vdev); - eth_dev = rte_eth_dev_allocated(name); + eth_dev = rte_eth_dev_allocated(rte_dev->name); /* Port has already been released by close. */ if (!eth_dev) return 0; @@ -736,18 +734,16 @@ static int virtio_user_pmd_dma_map(struct rte_vdev_device *vdev, void *addr, return 0; } -static int virtio_user_pmd_dma_unmap(struct rte_vdev_device *vdev, void *addr, +static int virtio_user_pmd_dma_unmap(struct rte_device *rte_dev, void *addr, uint64_t iova, size_t len) { - const char *name; struct rte_eth_dev *eth_dev; struct virtio_user_dev *dev; - if (!vdev) + if (rte_dev == NULL) return -EINVAL; - name = rte_vdev_device_name(vdev); - eth_dev = rte_eth_dev_allocated(name); + eth_dev = rte_eth_dev_allocated(rte_dev->name); /* Port has already been released by close. */ if (!eth_dev) return 0; @@ -761,10 +757,12 @@ static int virtio_user_pmd_dma_unmap(struct rte_vdev_device *vdev, void *addr, } static struct rte_vdev_driver virtio_user_driver = { + .driver = { + .dma_map = virtio_user_pmd_dma_map, + .dma_unmap = virtio_user_pmd_dma_unmap, + }, .probe = virtio_user_pmd_probe, .remove = virtio_user_pmd_remove, - .dma_map = virtio_user_pmd_dma_map, - .dma_unmap = virtio_user_pmd_dma_unmap, .drv_flags = RTE_VDEV_DRV_NEED_IOVA_AS_VA, }; diff --git a/lib/librte_eal/include/rte_bus.h b/lib/librte_eal/include/rte_bus.h index 80b154fb98..9f48ee7728 100644 --- a/lib/librte_eal/include/rte_bus.h +++ b/lib/librte_eal/include/rte_bus.h @@ -139,48 +139,6 @@ typedef int (*rte_bus_unplug_t)(struct rte_device *dev); */ typedef int (*rte_bus_parse_t)(const char *name, void *addr); -/** - * Device level DMA map function. - * After a successful call, the memory segment will be mapped to the - * given device. - * - * @param dev - * Device pointer. - * @param addr - * Virtual address to map. - * @param iova - * IOVA address to map. - * @param len - * Length of the memory segment being mapped. - * - * @return - * 0 if mapping was successful. - * Negative value and rte_errno is set otherwise. - */ -typedef int (*rte_dev_dma_map_t)(struct rte_device *dev, void *addr, - uint64_t iova, size_t len); - -/** - * Device level DMA unmap function. - * After a successful call, the memory segment will no longer be - * accessible by the given device. - * - * @param dev - * Device pointer. - * @param addr - * Virtual address to unmap. - * @param iova - * IOVA address to unmap. - * @param len - * Length of the memory segment being mapped. - * - * @return - * 0 if un-mapping was successful. - * Negative value and rte_errno is set otherwise. - */ -typedef int (*rte_dev_dma_unmap_t)(struct rte_device *dev, void *addr, - uint64_t iova, size_t len); - /** * Implement a specific hot-unplug handler, which is responsible for * handle the failure when device be hot-unplugged. When the event of diff --git a/lib/librte_eal/include/rte_dev.h b/lib/librte_eal/include/rte_dev.h index 6dd72c11a1..b4de2ef653 100644 --- a/lib/librte_eal/include/rte_dev.h +++ b/lib/librte_eal/include/rte_dev.h @@ -24,6 +24,9 @@ extern "C" { #include #include +/* Forward declaration, defined below. */ +struct rte_device; + /** * The device event type. */ @@ -71,13 +74,55 @@ struct rte_mem_resource { void *addr; /**< Virtual address, NULL when not mapped. */ }; +/** + * 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 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_dev_dma_map_t)(struct rte_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 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_dev_dma_unmap_t)(struct rte_device *dev, + void *addr, uint64_t iova, size_t len); + /** * A structure describing a device driver. */ struct rte_driver { - TAILQ_ENTRY(rte_driver) next; /**< Next in list. */ - const char *name; /**< Driver name. */ + TAILQ_ENTRY(rte_driver) next; /**< Next in list. */ + const char *name; /**< Driver name. */ const char *alias; /**< Driver alias. */ + rte_dev_dma_map_t dma_map; /**< Device DMA map function. */ + rte_dev_dma_unmap_t dma_unmap; /**< Device DMA unmap function. */ }; /* -- 2.30.1