PCI/IOV: Use VF0 cached config space size for other VFs
authorKarimAllah Ahmed <karahmed@amazon.de>
Thu, 11 Oct 2018 16:49:58 +0000 (11:49 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 11 Oct 2018 16:49:58 +0000 (11:49 -0500)
Cache the config space size from VF0 and use it for all other VFs instead
of reading it from the config space of each VF.  We assume that it will be
the same across all associated VFs.

This is an optimization when enabling SR-IOV on a device with many VFs.

Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
[bhelgaas: use CONFIG_PCI_IOV (not CONFIG_PCI_ATS)]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/iov.c
drivers/pci/pci.h
drivers/pci/probe.c

index c5f3cd4..4238b53 100644 (file)
@@ -133,6 +133,8 @@ static void pci_read_vf_config_common(struct pci_dev *virtfn)
                             &physfn->sriov->subsystem_vendor);
        pci_read_config_word(virtfn, PCI_SUBSYSTEM_ID,
                             &physfn->sriov->subsystem_device);
+
+       physfn->sriov->cfg_size = pci_cfg_space_size(virtfn);
 }
 
 int pci_iov_add_virtfn(struct pci_dev *dev, int id)
index 6e0d152..2f14542 100644 (file)
@@ -285,6 +285,7 @@ struct pci_sriov {
        u16             driver_max_VFs; /* Max num VFs driver supports */
        struct pci_dev  *dev;           /* Lowest numbered PF */
        struct pci_dev  *self;          /* This PF */
+       u32             cfg_size;       /* VF config space size */
        u32             class;          /* VF device */
        u8              hdr_type;       /* VF header type */
        u16             subsystem_vendor; /* VF subsystem vendor */
index 201f9e5..575315b 100644 (file)
@@ -1438,12 +1438,29 @@ static int pci_cfg_space_size_ext(struct pci_dev *dev)
        return PCI_CFG_SPACE_EXP_SIZE;
 }
 
+#ifdef CONFIG_PCI_IOV
+static bool is_vf0(struct pci_dev *dev)
+{
+       if (pci_iov_virtfn_devfn(dev->physfn, 0) == dev->devfn &&
+           pci_iov_virtfn_bus(dev->physfn, 0) == dev->bus->number)
+               return true;
+
+       return false;
+}
+#endif
+
 int pci_cfg_space_size(struct pci_dev *dev)
 {
        int pos;
        u32 status;
        u16 class;
 
+#ifdef CONFIG_PCI_IOV
+       /* Read cached value for all VFs except for VF0 */
+       if (dev->is_virtfn && !is_vf0(dev))
+               return dev->physfn->sriov->cfg_size;
+#endif
+
        if (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_EXTCFG)
                return PCI_CFG_SPACE_SIZE;