]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/pci/probe.c
Merge tag 'pci-v4.14-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[mirror_ubuntu-bionic-kernel.git] / drivers / pci / probe.c
index e6a917b4acd3f3c63dff5d57b905ab093d7d0487..ff94b69738a87a8ec5b77e57624e1412c7ab4916 100644 (file)
@@ -1745,21 +1745,50 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
         */
 }
 
-static void pci_configure_extended_tags(struct pci_dev *dev)
+int pci_configure_extended_tags(struct pci_dev *dev, void *ign)
 {
-       u32 dev_cap;
+       struct pci_host_bridge *host;
+       u32 cap;
+       u16 ctl;
        int ret;
 
        if (!pci_is_pcie(dev))
-               return;
+               return 0;
 
-       ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &dev_cap);
+       ret = pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap);
        if (ret)
-               return;
+               return 0;
+
+       if (!(cap & PCI_EXP_DEVCAP_EXT_TAG))
+               return 0;
+
+       ret = pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl);
+       if (ret)
+               return 0;
+
+       host = pci_find_host_bridge(dev->bus);
+       if (!host)
+               return 0;
 
-       if (dev_cap & PCI_EXP_DEVCAP_EXT_TAG)
+       /*
+        * If some device in the hierarchy doesn't handle Extended Tags
+        * correctly, make sure they're disabled.
+        */
+       if (host->no_ext_tags) {
+               if (ctl & PCI_EXP_DEVCTL_EXT_TAG) {
+                       dev_info(&dev->dev, "disabling Extended Tags\n");
+                       pcie_capability_clear_word(dev, PCI_EXP_DEVCTL,
+                                                  PCI_EXP_DEVCTL_EXT_TAG);
+               }
+               return 0;
+       }
+
+       if (!(ctl & PCI_EXP_DEVCTL_EXT_TAG)) {
+               dev_info(&dev->dev, "enabling Extended Tags\n");
                pcie_capability_set_word(dev, PCI_EXP_DEVCTL,
                                         PCI_EXP_DEVCTL_EXT_TAG);
+       }
+       return 0;
 }
 
 /**
@@ -1810,7 +1839,7 @@ static void pci_configure_device(struct pci_dev *dev)
        int ret;
 
        pci_configure_mps(dev);
-       pci_configure_extended_tags(dev);
+       pci_configure_extended_tags(dev, NULL);
        pci_configure_relaxed_ordering(dev);
 
        memset(&hpp, 0, sizeof(hpp));
@@ -1867,42 +1896,69 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
 }
 EXPORT_SYMBOL(pci_alloc_dev);
 
-bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l,
-                               int crs_timeout)
+static bool pci_bus_crs_vendor_id(u32 l)
+{
+       return (l & 0xffff) == 0x0001;
+}
+
+static bool pci_bus_wait_crs(struct pci_bus *bus, int devfn, u32 *l,
+                            int timeout)
 {
        int delay = 1;
 
-       if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, l))
-               return false;
+       if (!pci_bus_crs_vendor_id(*l))
+               return true;    /* not a CRS completion */
 
-       /* some broken boards return 0 or ~0 if a slot is empty: */
-       if (*l == 0xffffffff || *l == 0x00000000 ||
-           *l == 0x0000ffff || *l == 0xffff0000)
-               return false;
+       if (!timeout)
+               return false;   /* CRS, but caller doesn't want to wait */
 
        /*
-        * Configuration Request Retry Status.  Some root ports return the
-        * actual device ID instead of the synthetic ID (0xFFFF) required
-        * by the PCIe spec.  Ignore the device ID and only check for
-        * (vendor id == 1).
+        * We got the reserved Vendor ID that indicates a completion with
+        * Configuration Request Retry Status (CRS).  Retry until we get a
+        * valid Vendor ID or we time out.
         */
-       while ((*l & 0xffff) == 0x0001) {
-               if (!crs_timeout)
+       while (pci_bus_crs_vendor_id(*l)) {
+               if (delay > timeout) {
+                       pr_warn("pci %04x:%02x:%02x.%d: not ready after %dms; giving up\n",
+                               pci_domain_nr(bus), bus->number,
+                               PCI_SLOT(devfn), PCI_FUNC(devfn), delay - 1);
+
                        return false;
+               }
+               if (delay >= 1000)
+                       pr_info("pci %04x:%02x:%02x.%d: not ready after %dms; waiting\n",
+                               pci_domain_nr(bus), bus->number,
+                               PCI_SLOT(devfn), PCI_FUNC(devfn), delay - 1);
 
                msleep(delay);
                delay *= 2;
+
                if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, l))
                        return false;
-               /* Card hasn't responded in 60 seconds?  Must be stuck. */
-               if (delay > crs_timeout) {
-                       printk(KERN_WARNING "pci %04x:%02x:%02x.%d: not responding\n",
-                              pci_domain_nr(bus), bus->number, PCI_SLOT(devfn),
-                              PCI_FUNC(devfn));
-                       return false;
-               }
        }
 
+       if (delay >= 1000)
+               pr_info("pci %04x:%02x:%02x.%d: ready after %dms\n",
+                       pci_domain_nr(bus), bus->number,
+                       PCI_SLOT(devfn), PCI_FUNC(devfn), delay - 1);
+
+       return true;
+}
+
+bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l,
+                               int timeout)
+{
+       if (pci_bus_read_config_dword(bus, devfn, PCI_VENDOR_ID, l))
+               return false;
+
+       /* some broken boards return 0 or ~0 if a slot is empty: */
+       if (*l == 0xffffffff || *l == 0x00000000 ||
+           *l == 0x0000ffff || *l == 0xffff0000)
+               return false;
+
+       if (pci_bus_crs_vendor_id(*l))
+               return pci_bus_wait_crs(bus, devfn, l, timeout);
+
        return true;
 }
 EXPORT_SYMBOL(pci_bus_read_dev_vendor_id);
@@ -2331,6 +2387,15 @@ void pcie_bus_configure_settings(struct pci_bus *bus)
 }
 EXPORT_SYMBOL_GPL(pcie_bus_configure_settings);
 
+/*
+ * Called after each bus is probed, but before its children are examined.  This
+ * is marked as __weak because multiple architectures define it.
+ */
+void __weak pcibios_fixup_bus(struct pci_bus *bus)
+{
+       /* nothing to do, expected to be removed in the future */
+}
+
 unsigned int pci_scan_child_bus(struct pci_bus *bus)
 {
        unsigned int devfn, pass, max = bus->busn_res.start;