[15/40] net/virtio: move legacy IO to Virtio PCI

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

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Maxime Coquelin Dec. 20, 2020, 9:13 p.m. UTC
  This patch moves Virtio PCI legacy IO handling to
virtio_pci.c. Two functions are created so that
virtio_pci_ethdev does not have to care about it.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/net/virtio/virtio_pci.c        | 21 +++++++++++++++++++++
 drivers/net/virtio/virtio_pci.h        |  6 +++---
 drivers/net/virtio/virtio_pci_ethdev.c |  4 ++--
 3 files changed, 26 insertions(+), 5 deletions(-)
  

Comments

Chenbo Xia Dec. 30, 2020, 3:09 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 15/40] net/virtio: move legacy IO to Virtio PCI
> 
> This patch moves Virtio PCI legacy IO handling to
> virtio_pci.c. Two functions are created so that
> virtio_pci_ethdev does not have to care about it.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  drivers/net/virtio/virtio_pci.c        | 21 +++++++++++++++++++++
>  drivers/net/virtio/virtio_pci.h        |  6 +++---
>  drivers/net/virtio/virtio_pci_ethdev.c |  4 ++--
>  3 files changed, 26 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
> index 8c62507a0a..230a438bf7 100644
> --- a/drivers/net/virtio/virtio_pci.c
> +++ b/drivers/net/virtio/virtio_pci.c
> @@ -31,6 +31,15 @@
>  #define VIRTIO_PCI_CONFIG(hw) \
>  		(((hw)->use_msix == VIRTIO_MSIX_ENABLED) ? 24 : 20)
> 
> +
> +struct virtio_pci_internal {
> +	struct rte_pci_ioport io;
> +};
> +
> +#define VTPCI_IO(hw) (&virtio_pci_internal[(hw)->port_id].io)
> +
> +struct virtio_pci_internal virtio_pci_internal[RTE_MAX_ETHPORTS];
> +
>  static inline int
>  check_vq_phys_addr_ok(struct virtqueue *vq)
>  {
> @@ -838,3 +847,15 @@ vtpci_msix_detect(struct rte_pci_device *dev)
> 
>  	return VIRTIO_MSIX_NONE;
>  }
> +
> +void vtpci_legacy_ioport_unmap(struct virtio_hw *hw)
> +{
> +	rte_pci_ioport_unmap(VTPCI_IO(hw));
> +}
> +
> +int vtpci_legacy_ioport_map(struct virtio_hw *hw)
> +{
> +	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
> +
> +	return rte_pci_ioport_map(dev->pci_dev, 0, VTPCI_IO(hw));
> +}
> diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
> index 15f68f141c..c3db36d2fc 100644
> --- a/drivers/net/virtio/virtio_pci.h
> +++ b/drivers/net/virtio/virtio_pci.h
> @@ -297,15 +297,12 @@ struct virtio_pci_dev {
>   */
>  struct virtio_hw_internal {
>  	const struct virtio_pci_ops *vtpci_ops;
> -	struct rte_pci_ioport io;
>  };
> 
>  #define VTPCI_OPS(hw)	(virtio_hw_internal[(hw)->port_id].vtpci_ops)
> -#define VTPCI_IO(hw)	(&virtio_hw_internal[(hw)->port_id].io)
> 
>  extern struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
> 
> -
>  /*
>   * This structure is just a reference to read
>   * net device specific config space; it just a chodu structure
> @@ -380,6 +377,9 @@ uint8_t vtpci_isr(struct virtio_hw *);
> 
>  enum virtio_msix_status vtpci_msix_detect(struct rte_pci_device *dev);
> 
> +void vtpci_legacy_ioport_unmap(struct virtio_hw *hw);
> +int vtpci_legacy_ioport_map(struct virtio_hw *hw);
> +
>  extern const struct virtio_pci_ops legacy_ops;
>  extern const struct virtio_pci_ops modern_ops;
>  extern const struct virtio_pci_ops virtio_user_ops;
> diff --git a/drivers/net/virtio/virtio_pci_ethdev.c
> b/drivers/net/virtio/virtio_pci_ethdev.c
> index a6d5e2e158..17342ae7d8 100644
> --- a/drivers/net/virtio/virtio_pci_ethdev.c
> +++ b/drivers/net/virtio/virtio_pci_ethdev.c
> @@ -60,7 +60,7 @@ virtio_remap_pci(struct rte_pci_device *pci_dev, struct
> virtio_pci_dev *dev)
>  			return -1;
>  		}
>  	} else {
> -		if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
> +		if (vtpci_legacy_ioport_map(hw) < 0)
>  			return -1;
>  	}
> 
> @@ -109,7 +109,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 (!dev->modern)
> -		rte_pci_ioport_unmap(VTPCI_IO(hw));
> +		vtpci_legacy_ioport_unmap(hw);
> 
>  	return ret;
>  }
> --
> 2.29.2

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  
David Marchand Jan. 6, 2021, 10:09 a.m. UTC | #2
On Sun, Dec 20, 2020 at 10:15 PM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
>
> This patch moves Virtio PCI legacy IO handling to
> virtio_pci.c. Two functions are created so that
> virtio_pci_ethdev does not have to care about it.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>

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

Patch

diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 8c62507a0a..230a438bf7 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -31,6 +31,15 @@ 
 #define VIRTIO_PCI_CONFIG(hw) \
 		(((hw)->use_msix == VIRTIO_MSIX_ENABLED) ? 24 : 20)
 
+
+struct virtio_pci_internal {
+	struct rte_pci_ioport io;
+};
+
+#define VTPCI_IO(hw) (&virtio_pci_internal[(hw)->port_id].io)
+
+struct virtio_pci_internal virtio_pci_internal[RTE_MAX_ETHPORTS];
+
 static inline int
 check_vq_phys_addr_ok(struct virtqueue *vq)
 {
@@ -838,3 +847,15 @@  vtpci_msix_detect(struct rte_pci_device *dev)
 
 	return VIRTIO_MSIX_NONE;
 }
+
+void vtpci_legacy_ioport_unmap(struct virtio_hw *hw)
+{
+	rte_pci_ioport_unmap(VTPCI_IO(hw));
+}
+
+int vtpci_legacy_ioport_map(struct virtio_hw *hw)
+{
+	struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+	return rte_pci_ioport_map(dev->pci_dev, 0, VTPCI_IO(hw));
+}
diff --git a/drivers/net/virtio/virtio_pci.h b/drivers/net/virtio/virtio_pci.h
index 15f68f141c..c3db36d2fc 100644
--- a/drivers/net/virtio/virtio_pci.h
+++ b/drivers/net/virtio/virtio_pci.h
@@ -297,15 +297,12 @@  struct virtio_pci_dev {
  */
 struct virtio_hw_internal {
 	const struct virtio_pci_ops *vtpci_ops;
-	struct rte_pci_ioport io;
 };
 
 #define VTPCI_OPS(hw)	(virtio_hw_internal[(hw)->port_id].vtpci_ops)
-#define VTPCI_IO(hw)	(&virtio_hw_internal[(hw)->port_id].io)
 
 extern struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
 
-
 /*
  * This structure is just a reference to read
  * net device specific config space; it just a chodu structure
@@ -380,6 +377,9 @@  uint8_t vtpci_isr(struct virtio_hw *);
 
 enum virtio_msix_status vtpci_msix_detect(struct rte_pci_device *dev);
 
+void vtpci_legacy_ioport_unmap(struct virtio_hw *hw);
+int vtpci_legacy_ioport_map(struct virtio_hw *hw);
+
 extern const struct virtio_pci_ops legacy_ops;
 extern const struct virtio_pci_ops modern_ops;
 extern const struct virtio_pci_ops virtio_user_ops;
diff --git a/drivers/net/virtio/virtio_pci_ethdev.c b/drivers/net/virtio/virtio_pci_ethdev.c
index a6d5e2e158..17342ae7d8 100644
--- a/drivers/net/virtio/virtio_pci_ethdev.c
+++ b/drivers/net/virtio/virtio_pci_ethdev.c
@@ -60,7 +60,7 @@  virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
 			return -1;
 		}
 	} else {
-		if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
+		if (vtpci_legacy_ioport_map(hw) < 0)
 			return -1;
 	}
 
@@ -109,7 +109,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 (!dev->modern)
-		rte_pci_ioport_unmap(VTPCI_IO(hw));
+		vtpci_legacy_ioport_unmap(hw);
 
 	return ret;
 }