From patchwork Fri Dec 13 14:13:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 63848 X-Patchwork-Delegate: david.marchand@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 8CE6DA04F1; Fri, 13 Dec 2019 15:14:12 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0C94D1BFB3; Fri, 13 Dec 2019 15:13:45 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 3C0EC1BFA9 for ; Fri, 13 Dec 2019 15:13:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576246421; 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=oXqyoVNdKeqPMxeyIbjM1YEPLHWDRCeaFFL3jCsedLk=; b=cjhljLenS/iKz1Upm/fUriuFjQpSd89oxH7QsgiyP2ikXlhg6KOKRMTTwvW6W71lrYDdNs 7kDRZr2sc78LR9IiSEbz2wRbaC1LlvCo4NL0KDZ4FEIRdQOrkbWsHMT3ndc59Ex1g43kFq UwArmj5oVkeDo6wSGjivD7N5+KFbukY= 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-146-zTYvulwSMPmsvr-_Ourueg-1; Fri, 13 Dec 2019 09:13:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 800EB18B62A0; Fri, 13 Dec 2019 14:13:39 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id B021760C05; Fri, 13 Dec 2019 14:13:37 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, zhihong.wang@intel.com, anatoly.burakov@intel.com Cc: Maxime Coquelin Date: Fri, 13 Dec 2019 15:13:22 +0100 Message-Id: <20191213141322.32730-5-maxime.coquelin@redhat.com> In-Reply-To: <20191213141322.32730-1-maxime.coquelin@redhat.com> References: <20191213141322.32730-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: zTYvulwSMPmsvr-_Ourueg-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH 4/4] net/virtio: add DMA mapping callback to virtio-user 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" Signed-off-by: Maxime Coquelin --- .../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, };