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 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable 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) =09return 0; } =20 -static void +void virtio_user_mem_event_cb(enum rte_mem_event type __rte_unused, -=09=09=09 const void *addr, +=09=09=09 const void *addr __rte_unused, =09=09=09 size_t len __rte_unused, =09=09=09 void *arg) { =09struct virtio_user_dev *dev =3D arg; -=09struct rte_memseg_list *msl; =09uint16_t i; =20 -=09/* ignore externally allocated memory */ -=09msl =3D rte_mem_virt2memseg_list(addr); -=09if (msl->external) -=09=09return; - =09pthread_mutex_lock(&dev->mutex); =20 =09if (dev->started =3D=3D 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, u= int16_t queue_idx); void virtio_user_handle_cq_packed(struct virtio_user_dev *dev, =09=09=09=09 uint16_t queue_idx); uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pair= s); +void +virtio_user_mem_event_cb(enum rte_mem_event type, +=09=09=09const void *addr, size_t len , void *arg); #endif diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/v= irtio_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 =3D { =09.notify_queue=09=3D virtio_user_notify_queue, }; =20 +static int +virtio_user_dma_map(struct rte_vdev_device *vdev, void *addr, +=09=09uint64_t iova __rte_unused, size_t len) +{ +=09const char *name; +=09struct rte_eth_dev *eth_dev; +=09struct virtio_hw *hw; +=09struct virtio_user_dev *dev; + +=09if (!vdev) +=09=09return -EINVAL; + +=09name =3D rte_vdev_device_name(vdev); +=09eth_dev =3D rte_eth_dev_allocated(name); +=09if (!eth_dev) +=09=09return -ENODEV; + +=09hw =3D eth_dev->data->dev_private; +=09dev =3D hw->virtio_user_dev; + +=09virtio_user_mem_event_cb(RTE_MEM_EVENT_ALLOC, +=09=09=09=09=09=09 addr, +=09=09=09=09=09=09 len, +=09=09=09=09=09=09 (void *)dev); + +=09return 0; +} + +static int +virtio_user_dma_unmap(struct rte_vdev_device *vdev, void *addr, +=09=09uint64_t iova __rte_unused, size_t len) +{ +=09const char *name; +=09struct rte_eth_dev *eth_dev; +=09struct virtio_hw *hw; +=09struct virtio_user_dev *dev; + +=09if (!vdev) +=09=09return -EINVAL; + +=09name =3D rte_vdev_device_name(vdev); +=09eth_dev =3D rte_eth_dev_allocated(name); +=09if (!eth_dev) +=09=09return -ENODEV; + +=09hw =3D eth_dev->data->dev_private; +=09dev =3D hw->virtio_user_dev; + +=09virtio_user_mem_event_cb(RTE_MEM_EVENT_FREE, +=09=09=09=09=09=09 addr, +=09=09=09=09=09=09 len, +=09=09=09=09=09=09 (void *)dev); + +=09return 0; +} + static const char *valid_args[] =3D { #define VIRTIO_USER_ARG_QUEUES_NUM "queues" =09VIRTIO_USER_ARG_QUEUES_NUM, @@ -717,6 +773,8 @@ virtio_user_pmd_remove(struct rte_vdev_device *vdev) } =20 static struct rte_vdev_driver virtio_user_driver =3D { +=09.dma_map =3D virtio_user_dma_map, +=09.dma_unmap =3D virtio_user_dma_unmap, =09.probe =3D virtio_user_pmd_probe, =09.remove =3D virtio_user_pmd_remove, }; --=20 2.21.0