* Return 0 on success.
*/
int
-vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw)
+vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
{
+ struct virtio_hw *hw = &dev->hw;
+
RTE_BUILD_BUG_ON(offsetof(struct virtio_pci_dev, hw) != 0);
/*
* only on modern pci device. If failed, we fallback to legacy
* virtio handling.
*/
- if (virtio_read_caps(dev, hw) == 0) {
+ 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;
}
PMD_INIT_LOG(INFO, "trying with legacy virtio pci.");
- if (rte_pci_ioport_map(dev, 0, VTPCI_IO(hw)) < 0) {
- rte_pci_unmap_device(dev);
- if (dev->kdrv == RTE_PCI_KDRV_UNKNOWN &&
- (!dev->device.devargs ||
- dev->device.devargs->bus !=
+ if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0) {
+ rte_pci_unmap_device(pci_dev);
+ if (pci_dev->kdrv == RTE_PCI_KDRV_UNKNOWN &&
+ (!pci_dev->device.devargs ||
+ pci_dev->device.devargs->bus !=
rte_bus_find_by_name("pci"))) {
PMD_INIT_LOG(INFO,
"skip kernel managed virtio device.");
virtio_hw_internal[hw->port_id].vtpci_ops = &legacy_ops;
hw->bus_type = VIRTIO_BUS_PCI_LEGACY;
+ dev->modern = false;
msix_detect:
VTPCI_OPS(hw)->intr_detect(hw);
struct virtio_pci_dev {
struct virtio_hw hw;
+ bool modern;
};
#define virtio_pci_get_dev(hwp) container_of(hwp, struct virtio_pci_dev, hw)
/*
* Function declaration from virtio_pci.c
*/
-int vtpci_init(struct rte_pci_device *dev, struct virtio_hw *hw);
+int vtpci_init(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev);
void vtpci_reset(struct virtio_hw *);
void vtpci_reinit_complete(struct virtio_hw *);
* could have the PCI initiated correctly.
*/
static int
-virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
+virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_pci_dev *dev)
{
- if (hw->bus_type == VIRTIO_BUS_PCI_MODERN) {
+ struct virtio_hw *hw = &dev->hw;
+
+ if (dev->modern) {
/*
* We don't have to re-parse the PCI config space, since
* rte_pci_map_device() makes sure the mapped address
PMD_INIT_LOG(DEBUG, "failed to map pci device!");
return -1;
}
- } else if (hw->bus_type == VIRTIO_BUS_PCI_LEGACY) {
+ } else {
if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
return -1;
}
VTPCI_DEV(hw) = pci_dev;
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
- ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
+ ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), dev);
if (ret) {
PMD_INIT_LOG(ERR, "Failed to init PCI device\n");
return -1;
}
} else {
- ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
+ 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");
return -1;