diff mbox series

[12/40] net/virtio: remove bus type enum

Message ID 20201220211405.313012-13-maxime.coquelin@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers show
Series net/virtio: Virtio PMD rework | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Maxime Coquelin Dec. 20, 2020, 9:13 p.m. UTC
Bus type awareness at the generic ethdev level is no
more needed as previous patches have made it bus-agnostic.

This patch removes it from struct virtio_hw.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/net/virtio/virtio_ethdev.c      | 15 ---------------
 drivers/net/virtio/virtio_pci.c         |  2 --
 drivers/net/virtio/virtio_pci.h         |  8 --------
 drivers/net/virtio/virtio_pci_ethdev.c  |  7 ++++++-
 drivers/net/virtio/virtio_user_ethdev.c |  5 ++++-
 5 files changed, 10 insertions(+), 27 deletions(-)

Comments

Xia, Chenbo Dec. 30, 2020, 3:08 a.m. UTC | #1
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Monday, December 21, 2020 5:14 AM
> To: dev@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; olivier.matz@6wind.com;
> amorenoz@redhat.com; david.marchand@redhat.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Subject: [PATCH 12/40] net/virtio: remove bus type enum
> 
> Bus type awareness at the generic ethdev level is no
> more needed as previous patches have made it bus-agnostic.
> 
> This patch removes it from struct virtio_hw.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  drivers/net/virtio/virtio_ethdev.c      | 15 ---------------
>  drivers/net/virtio/virtio_pci.c         |  2 --
>  drivers/net/virtio/virtio_pci.h         |  8 --------
>  drivers/net/virtio/virtio_pci_ethdev.c  |  7 ++++++-
>  drivers/net/virtio/virtio_user_ethdev.c |  5 ++++-
>  5 files changed, 10 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_ethdev.c
> b/drivers/net/virtio/virtio_ethdev.c
> index 91a93b2b6e..86d8930e78 100644
> --- a/drivers/net/virtio/virtio_ethdev.c
> +++ b/drivers/net/virtio/virtio_ethdev.c
> @@ -1785,20 +1785,6 @@ virtio_init_device(struct rte_eth_dev *eth_dev,
> uint64_t req_features)
>  	return 0;
>  }
> 
> -
> -static void
> -virtio_set_vtpci_ops(struct virtio_hw *hw)
> -{
> -	if (hw->bus_type == VIRTIO_BUS_USER)
> -		VTPCI_OPS(hw) = &virtio_user_ops;
> -	else if (hw->bus_type == VIRTIO_BUS_PCI_MODERN)
> -		VTPCI_OPS(hw) = &modern_ops;
> -	else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
> -		VTPCI_OPS(hw) = &legacy_ops;
> -
> -	return;
> -}
> -
>  /*
>   * This function is based on probe() function in virtio_pci.c
>   * It returns 0 on success.
> @@ -1824,7 +1810,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
>  	eth_dev->rx_descriptor_done = virtio_dev_rx_queue_done;
> 
>  	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
> -		virtio_set_vtpci_ops(hw);
>  		set_rxtx_funcs(eth_dev);
>  		return 0;
>  	}
> diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
> index 3de7980b4f..f9331e37d7 100644
> --- a/drivers/net/virtio/virtio_pci.c
> +++ b/drivers/net/virtio/virtio_pci.c
> @@ -743,7 +743,6 @@ vtpci_init(struct rte_pci_device *pci_dev, struct
> virtio_pci_dev *dev)
>  	if (virtio_read_caps(pci_dev, hw) == 0) {
>  		PMD_INIT_LOG(INFO, "modern virtio pci detected.");
>  		virtio_hw_internal[hw->port_id].vtpci_ops = &modern_ops;
> -		hw->bus_type = VIRTIO_BUS_PCI_MODERN;
>  		dev->modern = true;
>  		goto msix_detect;
>  	}
> @@ -763,7 +762,6 @@ vtpci_init(struct rte_pci_device *pci_dev, struct
> virtio_pci_dev *dev)
>  	}
> 
>  	virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops;
> -	hw->bus_type = VIRTIO_BUS_PCI_LEGACY;
>  	dev->modern = false;
> 
>  msix_detect:
> diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
> index 22c21e6896..a60edc4a93 100644
> --- a/drivers/net/virtio/virtio_pci.h
> +++ b/drivers/net/virtio/virtio_pci.h
> @@ -245,15 +245,7 @@ struct virtio_pci_ops {
> 
>  struct virtio_net_config;
> 
> -enum virtio_bus_type {
> -	VIRTIO_BUS_UNKNOWN,
> -	VIRTIO_BUS_PCI_LEGACY,
> -	VIRTIO_BUS_PCI_MODERN,
> -	VIRTIO_BUS_USER,
> -};
> -
>  struct virtio_hw {
> -	enum virtio_bus_type bus_type;
>  	struct virtnet_ctl *cvq;
>  	uint64_t    req_guest_features;
>  	uint64_t    guest_features;
> diff --git a/drivers/net/virtio/virtio_pci_ethdev.c
> b/drivers/net/virtio/virtio_pci_ethdev.c
> index f513381707..a6d5e2e158 100644
> --- a/drivers/net/virtio/virtio_pci_ethdev.c
> +++ b/drivers/net/virtio/virtio_pci_ethdev.c
> @@ -82,6 +82,11 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
>  			return -1;
>  		}
>  	} else {
> +		if (dev->modern)
> +			VTPCI_OPS(hw) = &modern_ops;
> +		else
> +			VTPCI_OPS(hw) = &legacy_ops;
> +
>  		ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
>  		if (ret < 0) {
>  			PMD_INIT_LOG(ERR, "Failed to remap PCI device\n");
> @@ -103,7 +108,7 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
> 
>  err_unmap:
>  	rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
> -	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
> +	if (!dev->modern)
>  		rte_pci_ioport_unmap(VTPCI_IO(hw));
> 
>  	return ret;
> diff --git a/drivers/net/virtio/virtio_user_ethdev.c
> b/drivers/net/virtio/virtio_user_ethdev.c
> index c93e0e43f5..1420db32be 100644
> --- a/drivers/net/virtio/virtio_user_ethdev.c
> +++ b/drivers/net/virtio/virtio_user_ethdev.c
> @@ -641,7 +641,6 @@ virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
>  	 * Here just pretend that we support msix.
>  	 */
>  	hw->use_msix = 1;
> -	hw->bus_type = VIRTIO_BUS_USER;
>  	hw->use_vec_rx = 0;
>  	hw->use_vec_tx = 0;
>  	hw->use_inorder_rx = 0;
> @@ -700,6 +699,10 @@ virtio_user_pmd_probe(struct rte_vdev_device *vdev)
>  			return -1;
>  		}
> 
> +		dev = eth_dev->data->dev_private;
> +		hw = &dev->hw;
> +		VTPCI_OPS(hw) = &virtio_user_ops;
> +
>  		if (eth_virtio_dev_init(eth_dev) < 0) {
>  			PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
>  			rte_eth_dev_release_port(eth_dev);
> --
> 2.29.2

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
David Marchand Jan. 6, 2021, 9:33 a.m. UTC | #2
On Sun, Dec 20, 2020 at 10:15 PM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
>
> Bus type awareness at the generic ethdev level is no
> more needed as previous patches have made it bus-agnostic.
>
> This patch removes it from struct virtio_hw.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Reviewed-by: David Marchand <david.marchand@redhat.com>
diff mbox series

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 91a93b2b6e..86d8930e78 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1785,20 +1785,6 @@  virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
 	return 0;
 }
 
-
-static void
-virtio_set_vtpci_ops(struct virtio_hw *hw)
-{
-	if (hw->bus_type == VIRTIO_BUS_USER)
-		VTPCI_OPS(hw) = &virtio_user_ops;
-	else if (hw->bus_type == VIRTIO_BUS_PCI_MODERN)
-		VTPCI_OPS(hw) = &modern_ops;
-	else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
-		VTPCI_OPS(hw) = &legacy_ops;
-
-	return;
-}
-
 /*
  * This function is based on probe() function in virtio_pci.c
  * It returns 0 on success.
@@ -1824,7 +1810,6 @@  eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 	eth_dev->rx_descriptor_done = virtio_dev_rx_queue_done;
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
-		virtio_set_vtpci_ops(hw);
 		set_rxtx_funcs(eth_dev);
 		return 0;
 	}
diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 3de7980b4f..f9331e37d7 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -743,7 +743,6 @@  vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 	if (virtio_read_caps(pci_dev, hw) == 0) {
 		PMD_INIT_LOG(INFO, "modern virtio pci detected.");
 		virtio_hw_internal[hw->port_id].vtpci_ops = &modern_ops;
-		hw->bus_type = VIRTIO_BUS_PCI_MODERN;
 		dev->modern = true;
 		goto msix_detect;
 	}
@@ -763,7 +762,6 @@  vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 	}
 
 	virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops;
-	hw->bus_type = VIRTIO_BUS_PCI_LEGACY;
 	dev->modern = false;
 
 msix_detect:
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index 22c21e6896..a60edc4a93 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -245,15 +245,7 @@  struct virtio_pci_ops {
 
 struct virtio_net_config;
 
-enum virtio_bus_type {
-	VIRTIO_BUS_UNKNOWN,
-	VIRTIO_BUS_PCI_LEGACY,
-	VIRTIO_BUS_PCI_MODERN,
-	VIRTIO_BUS_USER,
-};
-
 struct virtio_hw {
-	enum virtio_bus_type bus_type;
 	struct virtnet_ctl *cvq;
 	uint64_t    req_guest_features;
 	uint64_t    guest_features;
diff --git a/drivers/net/virtio/virtio_pci_ethdev.c b/drivers/net/virtio/virtio_pci_ethdev.c
index f513381707..a6d5e2e158 100644
--- a/drivers/net/virtio/virtio_pci_ethdev.c
+++ b/drivers/net/virtio/virtio_pci_ethdev.c
@@ -82,6 +82,11 @@  eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 			return -1;
 		}
 	} else {
+		if (dev->modern)
+			VTPCI_OPS(hw) = &modern_ops;
+		else
+			VTPCI_OPS(hw) = &legacy_ops;
+
 		ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
 		if (ret < 0) {
 			PMD_INIT_LOG(ERR, "Failed to remap PCI device\n");
@@ -103,7 +108,7 @@  eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
 
 err_unmap:
 	rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
-	if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY)
+	if (!dev->modern)
 		rte_pci_ioport_unmap(VTPCI_IO(hw));
 
 	return ret;
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index c93e0e43f5..1420db32be 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -641,7 +641,6 @@  virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
 	 * Here just pretend that we support msix.
 	 */
 	hw->use_msix = 1;
-	hw->bus_type = VIRTIO_BUS_USER;
 	hw->use_vec_rx = 0;
 	hw->use_vec_tx = 0;
 	hw->use_inorder_rx = 0;
@@ -700,6 +699,10 @@  virtio_user_pmd_probe(struct rte_vdev_device *vdev)
 			return -1;
 		}
 
+		dev = eth_dev->data->dev_private;
+		hw = &dev->hw;
+		VTPCI_OPS(hw) = &virtio_user_ops;
+
 		if (eth_virtio_dev_init(eth_dev) < 0) {
 			PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
 			rte_eth_dev_release_port(eth_dev);