From patchwork Tue Jan 19 21:24:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 86908 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D06EAA0A05; Tue, 19 Jan 2021 22:27:32 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 36382140E88; Tue, 19 Jan 2021 22:26:35 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id D5028140DD3 for ; Tue, 19 Jan 2021 22:26:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611091592; 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=OHFQTNTEOzyU11CeRHh1+zcxVUkhcQ6pJAv+zBoOUYw=; b=Cc2Mvvbg3IAeGgooNSfrzgXNkLHbB9uNf71yM7E3Lhaa8u8ePMi2VwOEofAZVZvleHPP/J GmC53hvCdlG9Lgh4AR27pBSayUjZriBV25K0s8SW1sjrQm5uc1//28FCVoV2fmuAdqRc9R 7N+eO+mbRKf960qLYjzhDKF262HGrV8= 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-129-wj2FNVbNMQyGT8hjmbg7Bg-1; Tue, 19 Jan 2021 16:26:30 -0500 X-MC-Unique: wj2FNVbNMQyGT8hjmbg7Bg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 105BC800D55; Tue, 19 Jan 2021 21:26:29 +0000 (UTC) Received: from max-t490s.redhat.com (unknown [10.36.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A8705D9DD; Tue, 19 Jan 2021 21:26:27 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, chenbo.xia@intel.com, olivier.matz@6wind.com, amorenoz@redhat.com, david.marchand@redhat.com Cc: Maxime Coquelin Date: Tue, 19 Jan 2021 22:24:35 +0100 Message-Id: <20210119212507.1043636-13-maxime.coquelin@redhat.com> In-Reply-To: <20210119212507.1043636-1-maxime.coquelin@redhat.com> References: <20210119212507.1043636-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH v2 12/44] net/virtio: add callback for device closing 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" This patch introduces a new callback for device closing, making virtio_dev_close() bus-agnostic. Signed-off-by: Maxime Coquelin Reviewed-by: Chenbo Xia Reviewed-by: David Marchand --- drivers/net/virtio/meson.build | 2 -- drivers/net/virtio/virtio_ethdev.c | 13 +------------ drivers/net/virtio/virtio_pci.c | 25 +++++++++++++++++++++++++ drivers/net/virtio/virtio_pci.h | 2 ++ drivers/net/virtio/virtio_user_ethdev.c | 11 +++++++++++ 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/drivers/net/virtio/meson.build b/drivers/net/virtio/meson.build index 07e085376b..f2873d6180 100644 --- a/drivers/net/virtio/meson.build +++ b/drivers/net/virtio/meson.build @@ -44,8 +44,6 @@ elif arch_subdir == 'arm' and host_machine.cpu_family().startswith('aarch64') endif if is_linux - dpdk_conf.set('RTE_VIRTIO_USER', 1) - sources += files('virtio_user_ethdev.c', 'virtio_user/vhost_kernel.c', 'virtio_user/vhost_kernel_tap.c', diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index da0e168355..7e2240fd79 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -718,18 +718,7 @@ virtio_dev_close(struct rte_eth_dev *dev) virtio_dev_free_mbufs(dev); virtio_free_queues(hw); -#ifdef RTE_VIRTIO_USER - if (hw->bus_type == VIRTIO_BUS_USER) - virtio_user_dev_uninit(dev->data->dev_private); - else -#endif - if (dev->device) { - rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(dev)); - if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY) - rte_pci_ioport_unmap(VTPCI_IO(hw)); - } - - return 0; + return VTPCI_OPS(hw)->dev_close(hw); } static int diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c index 7475d5af3a..145bc38de3 100644 --- a/drivers/net/virtio/virtio_pci.c +++ b/drivers/net/virtio/virtio_pci.c @@ -297,6 +297,17 @@ legacy_intr_event(struct virtio_hw *hw) hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw)); } +static int +legacy_dev_close(struct virtio_hw *hw) +{ + struct virtio_pci_dev *dev = virtio_pci_get_dev(hw); + + rte_pci_unmap_device(dev->pci_dev); + rte_pci_ioport_unmap(VTPCI_IO(hw)); + + return 0; +} + const struct virtio_pci_ops legacy_ops = { .read_dev_cfg = legacy_read_dev_config, .write_dev_cfg = legacy_write_dev_config, @@ -312,6 +323,7 @@ const struct virtio_pci_ops legacy_ops = { .del_queue = legacy_del_queue, .notify_queue = legacy_notify_queue, .intr_event = legacy_intr_event, + .dev_close = legacy_dev_close, }; static inline void @@ -511,6 +523,16 @@ modern_intr_event(struct virtio_hw *hw) hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw)); } +static int +modern_dev_close(struct virtio_hw *hw) +{ + struct virtio_pci_dev *dev = virtio_pci_get_dev(hw); + + rte_pci_unmap_device(dev->pci_dev); + + return 0; +} + const struct virtio_pci_ops modern_ops = { .read_dev_cfg = modern_read_dev_config, .write_dev_cfg = modern_write_dev_config, @@ -526,6 +548,7 @@ const struct virtio_pci_ops modern_ops = { .del_queue = modern_del_queue, .notify_queue = modern_notify_queue, .intr_event = modern_intr_event, + .dev_close = modern_dev_close, }; @@ -757,6 +780,8 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev) RTE_BUILD_BUG_ON(offsetof(struct virtio_pci_dev, hw) != 0); + dev->pci_dev = pci_dev; + /* * Try if we can succeed reading virtio pci caps, which exists * only on modern pci device. If failed, we fallback to legacy diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h index 61850ec4b2..d1bed0ad59 100644 --- a/drivers/net/virtio/virtio_pci.h +++ b/drivers/net/virtio/virtio_pci.h @@ -240,6 +240,7 @@ struct virtio_pci_ops { void (*del_queue)(struct virtio_hw *hw, struct virtqueue *vq); void (*notify_queue)(struct virtio_hw *hw, struct virtqueue *vq); void (*intr_event)(struct virtio_hw *hw); + int (*dev_close)(struct virtio_hw *hw); }; struct virtio_net_config; @@ -292,6 +293,7 @@ struct virtio_hw { struct virtio_pci_dev { struct virtio_hw hw; + struct rte_pci_device *pci_dev; bool modern; }; diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 241fe373b9..3cbf310c03 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -462,6 +462,16 @@ virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq) strerror(errno)); } +static int +virtio_user_dev_close(struct virtio_hw *hw) +{ + struct virtio_user_dev *dev = virtio_user_get_dev(hw); + + virtio_user_dev_uninit(dev); + + return 0; +} + const struct virtio_pci_ops virtio_user_ops = { .read_dev_cfg = virtio_user_read_dev_config, .write_dev_cfg = virtio_user_write_dev_config, @@ -476,6 +486,7 @@ const struct virtio_pci_ops virtio_user_ops = { .setup_queue = virtio_user_setup_queue, .del_queue = virtio_user_del_queue, .notify_queue = virtio_user_notify_queue, + .dev_close = virtio_user_dev_close, }; static const char *valid_args[] = {