From patchwork Fri Sep 11 15:08:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 77430 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A5359A04BB; Fri, 11 Sep 2020 17:08:41 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EDED51C115; Fri, 11 Sep 2020 17:08:23 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 159A31C0D5 for ; Fri, 11 Sep 2020 17:08:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599836899; 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=/IhmGc9dU+vaCiLlIQxDt2xa/0Qdv9Xi7Kbn0qhVSpo=; b=diW0So2hFe+rqn9abccHkLmwJlPTwS653kvbWaCHK77Q5L3Y73QjjyvoheCMOl2P8NebYX AZ5u8e5oj8mYRvMmbKQNkyUMSmOcIGOXPWXcsq4ENlhhUgmQAhXjQc1AKA8lTKnFl3MeSC yhu6LBHiiOYMKh3R4ryGi8KEPHigAo4= 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-166-N3tg_ryyO2Cbxt4PpBqBvA-1; Fri, 11 Sep 2020 11:08:17 -0400 X-MC-Unique: N3tg_ryyO2Cbxt4PpBqBvA-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 A4CBD801AFD; Fri, 11 Sep 2020 15:08:16 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.110.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 520D43C89; Fri, 11 Sep 2020 15:08:15 +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:08:00 +0200 Message-Id: <20200911150805.79901-3-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 Subject: [dpdk-dev] [PATCH 2/7] net/virtio: introduce DMA 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 callbacks to the virtio_user pmd, which could be leveraged by vdev bus driver to map memory for backend devices with DMA capability. Signed-off-by: Maxime Coquelin --- drivers/net/virtio/virtio_user/vhost.h | 4 ++ drivers/net/virtio/virtio_user_ethdev.c | 54 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h index 8f49ef4574..2e71995a79 100644 --- a/drivers/net/virtio/virtio_user/vhost.h +++ b/drivers/net/virtio/virtio_user/vhost.h @@ -105,6 +105,10 @@ struct virtio_user_backend_ops { int (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int enable); + int (*dma_map)(struct virtio_user_dev *dev, void *addr, + uint64_t iova, size_t len); + int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, + uint64_t iova, size_t len); }; extern struct virtio_user_backend_ops virtio_ops_user; diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 87f6cb6950..60d17af888 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -818,9 +818,63 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev) return 0; } +static int virtio_user_pmd_dma_map(struct rte_vdev_device *vdev, void *addr, + uint64_t iova, size_t len) +{ + const char *name; + struct rte_eth_dev *eth_dev; + struct virtio_user_dev *dev; + struct virtio_hw *hw; + + if (!vdev) + return -EINVAL; + + name = rte_vdev_device_name(vdev); + eth_dev = rte_eth_dev_allocated(name); + /* Port has already been released by close. */ + if (!eth_dev) + return 0; + + hw = (struct virtio_hw *)eth_dev->data->dev_private; + dev = hw->virtio_user_dev; + + if (dev->ops->dma_map) + return dev->ops->dma_map(dev, addr, iova, len); + + return 0; +} + +static int virtio_user_pmd_dma_unmap(struct rte_vdev_device *vdev, void *addr, + uint64_t iova, size_t len) +{ + const char *name; + struct rte_eth_dev *eth_dev; + struct virtio_user_dev *dev; + struct virtio_hw *hw; + + if (!vdev) + return -EINVAL; + + name = rte_vdev_device_name(vdev); + eth_dev = rte_eth_dev_allocated(name); + /* Port has already been released by close. */ + if (!eth_dev) + return 0; + + hw = (struct virtio_hw *)eth_dev->data->dev_private; + dev = hw->virtio_user_dev; + + if (dev->ops->dma_unmap) + return dev->ops->dma_unmap(dev, addr, iova, len); + + return 0; +} + static struct rte_vdev_driver virtio_user_driver = { .probe = virtio_user_pmd_probe, .remove = virtio_user_pmd_remove, + .dma_map = virtio_user_pmd_dma_map, + .dma_unmap = virtio_user_pmd_dma_unmap, }; RTE_PMD_REGISTER_VDEV(net_virtio_user, virtio_user_driver);