]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
PCI: Check pref compatible bit for mem64 resource of PCIe device
authorYinghai Lu <yinghai@kernel.org>
Thu, 8 Oct 2015 21:38:30 +0000 (14:38 -0700)
committerSantosh Shilimkar <santosh.shilimkar@oracle.com>
Mon, 19 Oct 2015 20:41:11 +0000 (13:41 -0700)
We still get "no compatible bridge window" warning on sparc T5-8
after we add support for 64bit resource parsing for root bus.

 PCI: scan_bus[/pci@300/pci@1/pci@0/pci@6] bus no 8
 PCI: Claiming 0000:00:01.0: Resource 15: 0000800100000000..00008004afffffff [220c]
 PCI: Claiming 0000:01:00.0: Resource 15: 0000800100000000..00008004afffffff [220c]
 PCI: Claiming 0000:02:04.0: Resource 15: 0000800100000000..000080012fffffff [220c]
 PCI: Claiming 0000:03:00.0: Resource 15: 0000800100000000..000080012fffffff [220c]
 PCI: Claiming 0000:04:06.0: Resource 14: 0000800100000000..000080010fffffff [220c]
 PCI: Claiming 0000:05:00.0: Resource 0: 0000800100000000..0000800100001fff [204]
 pci 0000:05:00.0: can't claim BAR 0 [mem 0x800100000000-0x800100001fff]: no compatible bridge window

All the bridges 64-bit resource have pref bit, but the device resource does not
have pref set, then we can not find parent for the device resource,
as we can not put non-pref mem under pref mem.

According to pcie spec errta
https://www.pcisig.com/specifications/pciexpress/base2/PCIe_Base_r2.1_Errata_08Jun10.pdf
page 13, in some case it is ok to mark some as pref.

Mark if the entire path from the host to the adapter is over PCI Express.
Then set pref compatible bit for claim/sizing/assign for 64bit mem resource
on that pcie device.

-v2: set pref for mmio 64 when whole path is PCI Express, according to David Miller.
-v3: don't set pref directly, change to UNDER_PREF, and set PREF before
     sizing and assign resource, and cleart PREF afterwards. requested by BenH.
-v4: use on_all_pcie_path device flag instead.

Fixes: commit d63e2e1f3df9 ("sparc/PCI: Clip bridge windows to fit in upstream windows")
Link: http://lkml.kernel.org/r/CAE9FiQU1gJY1LYrxs+ma5LCTEEe4xmtjRG0aXJ9K_Tsu+m9Wuw@mail.gmail.com
Reported-by: David Ahern <david.ahern@oracle.com>
Tested-by: David Ahern <david.ahern@oracle.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=81431
Tested-by: TJ <linux@iam.tj>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Orabug: 21826746

Signed-off-by: Khalid Aziz <khalid.aziz@oracle.com>
(cherry picked from commit 35991cd9512c91fb98156f21174b1e9218daebe9)

drivers/pci/pci.c
drivers/pci/pci.h
drivers/pci/probe.c
drivers/pci/setup-bus.c
drivers/pci/setup-res.c
include/linux/pci.h

index acc4b6ef78c4380273b1af144838582dde57f80a..f3fa21d3aa3f893f7f7b1dfd6889b0ae629f29f4 100644 (file)
@@ -414,6 +414,7 @@ EXPORT_SYMBOL_GPL(pci_find_ht_capability);
 struct resource *pci_find_parent_resource(const struct pci_dev *dev,
                                          struct resource *res)
 {
+       int flags = pci_resource_pref_compatible(dev, res);
        const struct pci_bus *bus = dev->bus;
        struct resource *r;
        int i;
@@ -428,7 +429,7 @@ struct resource *pci_find_parent_resource(const struct pci_dev *dev,
                         * not, the allocator made a mistake.
                         */
                        if (r->flags & IORESOURCE_PREFETCH &&
-                           !(res->flags & IORESOURCE_PREFETCH))
+                           !(flags & IORESOURCE_PREFETCH))
                                return NULL;
 
                        /*
index 9bd762c237abe2fd679e8c7163947c7a0453c46b..58019e4d94fcf1d5b87af69c024f579732c99dc6 100644 (file)
@@ -325,4 +325,6 @@ static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe)
 
 struct pci_host_bridge *pci_find_host_bridge(struct pci_bus *bus);
 
+int pci_resource_pref_compatible(const struct pci_dev *dev,
+                                struct resource *res);
 #endif /* DRIVERS_PCI_H */
index c91185721345b65f3e915a6539186f138c21781e..502ac894ec762a497356ae7a9b3468531cdc986d 100644 (file)
@@ -1508,6 +1508,36 @@ static void pci_init_capabilities(struct pci_dev *dev)
        pci_enable_acs(dev);
 }
 
+static bool pci_up_path_over_pcie(struct pci_bus *bus)
+{
+       if (pci_is_root_bus(bus))
+               return true;
+
+       if (bus->self && !pci_is_pcie(bus->self))
+               return false;
+
+       return pci_up_path_over_pcie(bus->parent);
+}
+
+/*
+ * According to
+ * https://www.pcisig.com/specifications/pciexpress/base2/PCIe_Base_r2.1_Errata_08Jun10.pdf
+ * page 13, system firmware could put some 64bit non-pref under 64bit pref,
+ * on some cases.
+ * Let's mark if entire path from the host to the adapter is over PCI
+ * Express. later will use that compute pref compaitable bit.
+ */
+static void pci_set_on_all_pcie_path(struct pci_dev *dev)
+{
+       if (!pci_is_pcie(dev))
+               return;
+
+       if (!pci_up_path_over_pcie(dev->bus))
+               return;
+
+       dev->on_all_pcie_path = 1;
+}
+
 void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 {
        int ret;
@@ -1538,6 +1568,9 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
        /* Initialize various capabilities */
        pci_init_capabilities(dev);
 
+       /* After pcie_cap is assigned */
+       pci_set_on_all_pcie_path(dev);
+
        /*
         * Add the device to our list of discovered devices
         * and the bus list for fixup functions, etc.
index 508cc56130e3f88d1b01716a7a00fead250fdf1c..6c43c43d5d610eda21a409b10a0df063a5f3ea06 100644 (file)
@@ -739,6 +739,20 @@ int pci_claim_bridge_resource(struct pci_dev *bridge, int i)
        return -EINVAL;
 }
 
+int pci_resource_pref_compatible(const struct pci_dev *dev,
+                                struct resource *res)
+{
+       if (res->flags & IORESOURCE_PREFETCH)
+               return res->flags;
+
+       if ((res->flags & IORESOURCE_MEM) &&
+           (res->flags & IORESOURCE_MEM_64) &&
+           dev->on_all_pcie_path)
+               return res->flags | IORESOURCE_PREFETCH;
+
+       return res->flags;
+}
+
 /* Check whether the bridge supports optional I/O and
    prefetchable memory ranges. If not, the respective
    base/limit registers must be read-only and read as 0. */
@@ -1036,10 +1050,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,
                for (i = 0; i < PCI_NUM_RESOURCES; i++) {
                        struct resource *r = &dev->resource[i];
                        resource_size_t r_size;
+                       int flags = pci_resource_pref_compatible(dev, r);
 
-                       if (r->parent || ((r->flags & mask) != type &&
-                                         (r->flags & mask) != type2 &&
-                                         (r->flags & mask) != type3))
+                       if (r->parent || ((flags & mask) != type &&
+                                         (flags & mask) != type2 &&
+                                         (flags & mask) != type3))
                                continue;
                        r_size = resource_size(r);
 #ifdef CONFIG_PCI_IOV
index 232f9254c11acf5b45d9b20f9fc4169dfad79084..b19aa5bec47e5e8bae898ade703a1aeda2e5a70d 100644 (file)
@@ -250,15 +250,19 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
 static int _pci_assign_resource(struct pci_dev *dev, int resno,
                                resource_size_t size, resource_size_t min_align)
 {
+       struct resource *res = dev->resource + resno;
+       int old_flags = res->flags;
        struct pci_bus *bus;
        int ret;
 
+       res->flags = pci_resource_pref_compatible(dev, res);
        bus = dev->bus;
        while ((ret = __pci_assign_resource(bus, dev, resno, size, min_align))) {
                if (!bus->parent || !bus->self->transparent)
                        break;
                bus = bus->parent;
        }
+       res->flags = old_flags;
 
        return ret;
 }
index 956f74bad37acd3b880ff342d7d3fcb6c59d7c9c..52d8a9060ee8c3b6fe99cd6d7948f7cfa3410626 100644 (file)
@@ -309,6 +309,7 @@ struct pci_dev {
                                                   powered on/off by the
                                                   corresponding bridge */
        unsigned int    ignore_hotplug:1;       /* Ignore hotplug events */
+       unsigned int    on_all_pcie_path:1;     /* up to host-bridge all pcie */
        unsigned int    d3_delay;       /* D3->D0 transition time in ms */
        unsigned int    d3cold_delay;   /* D3cold->D0 transition time in ms */