From: Maxime Coquelin Date: Tue, 26 Jan 2021 10:16:07 +0000 (+0100) Subject: net/virtio: add callback for device closing X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=f12908c81a2b462452f8574c4d880269ee9183dd;p=dpdk.git net/virtio: add callback for device closing 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 --- 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 bf5b0119bf..98a393d752 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 6d9c712fd5..ea4ab381a6 100644 --- a/drivers/net/virtio/virtio_pci.c +++ b/drivers/net/virtio/virtio_pci.c @@ -297,6 +297,17 @@ legacy_intr_detect(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_detect = legacy_intr_detect, + .dev_close = legacy_dev_close, }; static inline void @@ -511,6 +523,16 @@ modern_intr_detect(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_detect = modern_intr_detect, + .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 906de06b06..35f84890a8 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_detect)(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 968bc8eb12..b4a433123c 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[] = {