From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E761AA04BB; Fri, 11 Sep 2020 17:08:27 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 82C741C0D9; Fri, 11 Sep 2020 17:08:20 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 614411C0CF for ; Fri, 11 Sep 2020 17:08:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599836897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zjbafbAJq9n5GmbtXjKuLhOT8YS7EqmLajAw6a0nFRI=; b=N5bVswHeeVBUV1jJzHvkHfO3DHe/tbZ1TOT+FoQDf83f9rMS8MnbtglFvbf1iLhibMN9hM +KH2T3PPZ3EJrTwKdepZiAbGug854maZGVWi8UuuHwE6dAD6AMvJ0gDjM/c30hAKhrVpKm G8kYCmbilbcxVpOQkC2NN3cidbGVNdE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-O49rG6CcOgqylcSCNkujDA-1; Fri, 11 Sep 2020 11:08:15 -0400 X-MC-Unique: O49rG6CcOgqylcSCNkujDA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ECFEC8064BA; Fri, 11 Sep 2020 15:08:14 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC26B1A887; Fri, 11 Sep 2020 15:08:13 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, patrick.fu@intel.com, amorenoz@redhat.com Cc: Maxime Coquelin Date: Fri, 11 Sep 2020 17:07:59 +0200 Message-Id: <20200911150805.79901-2-maxime.coquelin@redhat.com> In-Reply-To: <20200911150805.79901-1-maxime.coquelin@redhat.com> References: <20200911150805.79901-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 1/7] bus/vdev: add DMA mapping ops X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Add DMA map/unmap operation callbacks to the vdev bus, which could be used by DMA capable vdev drivers. Signed-off-by: Maxime Coquelin --- drivers/bus/vdev/rte_bus_vdev.h | 46 +++++++++++++++++++++++++++-- drivers/bus/vdev/vdev.c | 52 +++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/drivers/bus/vdev/rte_bus_vdev.h b/drivers/bus/vdev/rte_bus_vdev.h index 78a032cea8..3fe0b35a82 100644 --- a/drivers/bus/vdev/rte_bus_vdev.h +++ b/drivers/bus/vdev/rte_bus_vdev.h @@ -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; /**< vdev DMA map function. */ + rte_vdev_dma_unmap_t *dma_unmap; /**< vdev DMA unmap function. */ }; /** diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index d746149a2e..455d0bd0c2 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -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; 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, }; -- 2.26.2