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: Chenbo Xia <chenbo.xia@intel.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
---
drivers/net/virtio/virtio_pci.c | 28 ++++++++++++++++++++++++--
drivers/net/virtio/virtio_pci.h | 9 +++------
drivers/net/virtio/virtio_pci_ethdev.c | 6 ++----
3 files changed, 31 insertions(+), 12 deletions(-)
@@ -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)
{
@@ -300,7 +309,9 @@ legacy_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
static void
legacy_intr_detect(struct virtio_hw *hw)
{
- hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw));
+ struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+ hw->use_msix = vtpci_msix_detect(dev->pci_dev);
}
static int
@@ -558,7 +569,9 @@ modern_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
static void
modern_intr_detect(struct virtio_hw *hw)
{
- hw->use_msix = vtpci_msix_detect(VTPCI_DEV(hw));
+ struct virtio_pci_dev *dev = virtio_pci_get_dev(hw);
+
+ hw->use_msix = vtpci_msix_detect(dev->pci_dev);
}
static int
@@ -857,3 +870,14 @@ vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
return 0;
}
+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));
+}
@@ -298,18 +298,12 @@ struct virtio_pci_dev {
*/
struct virtio_hw_internal {
const struct virtio_pci_ops *vtpci_ops;
- struct rte_pci_ioport io;
- struct rte_pci_device *dev;
};
#define VTPCI_OPS(hw) (virtio_hw_internal[(hw)->port_id].vtpci_ops)
-#define VTPCI_IO(hw) (&virtio_hw_internal[(hw)->port_id].io)
-#define VTPCI_DEV(hw) (virtio_hw_internal[(hw)->port_id].dev)
-
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
@@ -382,6 +376,9 @@ void vtpci_read_dev_config(struct virtio_hw *, size_t, void *, int);
uint8_t vtpci_isr(struct virtio_hw *);
+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;
@@ -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;
}
@@ -75,8 +75,6 @@ eth_virtio_pci_init(struct rte_eth_dev *eth_dev)
struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
int ret;
- VTPCI_DEV(hw) = pci_dev;
-
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
if (ret) {
@@ -111,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;
}