PCI: mediatek: Add support for EcoNet SoCs
Subsystems (6)
v2 cover PCI: mediatek: Add support for EcoNet SoCs
Add EcoNet EN7528 (and EN751221) PCIe support.
Changes from v1:
* mediatek-pcie.yaml slot0 needs device-type = "pci", fix dt_binding_check
This was split from a larger PCIe patchset which crossed multiple subsystems. I'm not labeling this a v3 because it's a new patchset, but I'm keeping the historical record anyway.
Changes from econet-pcie v2:
* mediatek-pcie.yaml add missing constraints to PCI node properties
* econet-pcie v2: https://lore.kernel.org/linux-mips/[email protected]
Changes from econet-pcie v1:
* pcie-mediatek.c Exclude pcie_retrain_link() when building as a module
* econet-pcie v1: https://lore.kernel.org/linux-mips/[email protected]/
Caleb James DeLisle (3):
dt-bindings: PCI: mediatek: Add support for EcoNet EN7528
PCI: mediatek: Add support for EcoNet EN7528 SoC
PCI: Skip bridge window reads when window is not supported
.../bindings/pci/mediatek-pcie.yaml | 82 ++++++++++++ drivers/pci/controller/Kconfig | 2 +- drivers/pci/controller/pcie-mediatek.c | 118 ++++++++++++++++++ drivers/pci/probe.c | 6 + 4 files changed, 207 insertions(+), 1 deletion(-)
base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
Signature · 1 line
2.39.5
PATCH v2 1/3 dt-bindings: PCI: mediatek: Add support for EcoNet EN7528
Introduce EcoNet EN7528 SoC compatible in MediaTek PCIe controller binding.
EcoNet PCIe controller has the same configuration model as Mediatek v2 but is initiallized more similarly to an MT7621 PCIe.
--- .../bindings/pci/mediatek-pcie.yaml | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+)
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +82 -0
@@ -14,6 +14,7 @@ properties: oneOf: - enum: - airoha,an7583-pcie + - econet,en7528-pcie - mediatek,mt2712-pcie - mediatek,mt7622-pcie - mediatek,mt7629-pcie
@@ -226,6 +227,31 @@ allOf: mediatek,pbus-csr: false + - if: + properties: + compatible: + contains: + const: econet,en7528-pcie + then: + properties: + clocks: + maxItems: 1 + + clock-names: + maxItems: 1 + + reset: false + + reset-names: false + + power-domain: false + + mediatek,pbus-csr: false + + required: + - phys + - phy-names + unevaluatedProperties: false examples:
@@ -436,3 +462,59 @@ examples: }; }; }; + + # EN7528 + - | + #include <dt-bindings/interrupt-controller/mips-gic.h> + #include <dt-bindings/clock/en7523-clk.h> + #include <dt-bindings/reset/airoha,en7523-reset.h> + + soc_3 { + #address-cells = <1>; + #size-cells = <1>; + + pcie@1fb81000 { + compatible = "econet,en7528-pcie"; + device_type = "pci"; + linux,pci-domain = <0>; + #address-cells = <3>; + #size-cells = <2>; + + reg = <0x1fb81000 0x1000>; + reg-names = "port0"; + + clocks = <&scuclk EN7523_CLK_PCIE>; + clock-names = "sys_ck0"; + + phys = <&pcie_phy0>; + phy-names = "pcie-phy0"; + + ranges = <0x01000000 0 0x00000000 0x1f600000 0 0x00010000>, + <0x82000000 0 0x20000000 0x20000000 0 0x08000000>; + + interrupt-parent = <&intc>; + interrupts = <23>; + interrupt-names = "pcie_irq"; + bus-range = <0x00 0xff>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_intc 0>, + <0 0 0 2 &pcie_intc 1>, + <0 0 0 3 &pcie_intc 2>, + <0 0 0 4 &pcie_intc 3>; + + pcie_intc: interrupt-controller { + interrupt-controller; + #address-cells = <0>; + #interrupt-cells = <1>; + }; + + slot0: pcie@0,0 { + device_type = "pci"; + reg = <0x0000 0 0 0 0>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + }; + }; + };
Signature · 1 line
2.39.5
Re: [PATCH v2 1/3] dt-bindings: PCI: mediatek: Add support for EcoNet EN7528
Quoted 11 lines · Caleb James DeLisle
mediatek,pbus-csr: false
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +8
-0+ - if: + properties: + compatible: + contains: + const: econet,en7528-pcie + then: + properties: + clocks:
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml allOf: · line 247
Quoted 10 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +10
-0+ maxItems: 1 + + clock-names: + maxItems: 1 + + reset: false + + reset-names: false + + power-domain: false
Wrong property.
Quoted 12 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +7
-0+ + mediatek,pbus-csr: false + + required: + - phys + - phy-names + unevaluatedProperties: false examples:@@ -436,3 +462,59 @@ examples: };
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml examples: · line 472
Quoted 10 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +8
-0}; }; + + # EN7528 + - | + #include <dt-bindings/interrupt-controller/mips-gic.h> + #include <dt-bindings/clock/en7523-clk.h> + #include <dt-bindings/reset/airoha,en7523-reset.h> + + soc_3 {
soc
Underscores are not allowed, but honestly neither soc node is needed nor the example. There are already 3 examples, it's enough, especially that there are no new properties here.
Quoted 51 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +48
-0+ #address-cells = <1>; + #size-cells = <1>; + + pcie@1fb81000 { + compatible = "econet,en7528-pcie"; + device_type = "pci"; + linux,pci-domain = <0>; + #address-cells = <3>; + #size-cells = <2>; + + reg = <0x1fb81000 0x1000>; + reg-names = "port0"; + + clocks = <&scuclk EN7523_CLK_PCIE>; + clock-names = "sys_ck0"; + + phys = <&pcie_phy0>; + phy-names = "pcie-phy0"; + + ranges = <0x01000000 0 0x00000000 0x1f600000 0 0x00010000>, + <0x82000000 0 0x20000000 0x20000000 0 0x08000000>; + + interrupt-parent = <&intc>; + interrupts = <23>; + interrupt-names = "pcie_irq"; + bus-range = <0x00 0xff>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_intc 0>, + <0 0 0 2 &pcie_intc 1>, + <0 0 0 3 &pcie_intc 2>, + <0 0 0 4 &pcie_intc 3>; + + pcie_intc: interrupt-controller { + interrupt-controller; + #address-cells = <0>; + #interrupt-cells = <1>; + }; + + slot0: pcie@0,0 { + device_type = "pci"; + reg = <0x0000 0 0 0 0>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + }; + }; + };Signature · 1 line
2.39.5
Re: [PATCH v2 1/3] dt-bindings: PCI: mediatek: Add support for EcoNet EN7528
Quoted 48 lines · Krzysztof Kozlowski
Quoted 11 lines · Caleb James DeLisle
mediatek,pbus-csr: false
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +8
-0+ - if: + properties: + compatible: + contains: + const: econet,en7528-pcie + then: + properties: + clocks:Documentation/devicetree/bindings/pci/mediatek-pcie.yaml allOf: · line 247
Quoted 10 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +10
-0+ maxItems: 1 + + clock-names: + maxItems: 1 + + reset: false + + reset-names: false + + power-domain: falseWrong property.
Quoted 12 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +7
-0+ + mediatek,pbus-csr: false + + required: + - phys + - phy-names + unevaluatedProperties: false examples:@@ -436,3 +462,59 @@ examples: };Documentation/devicetree/bindings/pci/mediatek-pcie.yaml examples: · line 472
Quoted 10 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +8
-0}; }; + + # EN7528 + - | + #include <dt-bindings/interrupt-controller/mips-gic.h> + #include <dt-bindings/clock/en7523-clk.h> + #include <dt-bindings/reset/airoha,en7523-reset.h> + + soc_3 {soc
Quoted 3 lines
Underscores are not allowed, but honestly neither soc node is needed nor the example. There are already 3 examples, it's enough, especially that there are no new properties here.
Ok, will remove the example then.
Thanks,
Caleb
Quoted 52 lines
Quoted 52 lines
Documentation/devicetree/bindings/pci/mediatek-pcie.yaml +48
-0+ #address-cells = <1>; + #size-cells = <1>; + + pcie@1fb81000 { + compatible = "econet,en7528-pcie"; + device_type = "pci"; + linux,pci-domain = <0>; + #address-cells = <3>; + #size-cells = <2>; + + reg = <0x1fb81000 0x1000>; + reg-names = "port0"; + + clocks = <&scuclk EN7523_CLK_PCIE>; + clock-names = "sys_ck0"; + + phys = <&pcie_phy0>; + phy-names = "pcie-phy0"; + + ranges = <0x01000000 0 0x00000000 0x1f600000 0 0x00010000>, + <0x82000000 0 0x20000000 0x20000000 0 0x08000000>; + + interrupt-parent = <&intc>; + interrupts = <23>; + interrupt-names = "pcie_irq"; + bus-range = <0x00 0xff>; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &pcie_intc 0>, + <0 0 0 2 &pcie_intc 1>, + <0 0 0 3 &pcie_intc 2>, + <0 0 0 4 &pcie_intc 3>; + + pcie_intc: interrupt-controller { + interrupt-controller; + #address-cells = <0>; + #interrupt-cells = <1>; + }; + + slot0: pcie@0,0 { + device_type = "pci"; + reg = <0x0000 0 0 0 0>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + }; + }; + };Signature · 1 line
2.39.5
PATCH v2 2/3 PCI: mediatek: Add support for EcoNet EN7528 SoC
In reply to Caleb James DeLisleAdd support for the PCIe present on the EcoNet EN7528 (and EN751221) SoCs.
These SoCs have a mix of Gen1 and Gen2 capable ports, but the Gen2 ports require re-training after startup.
--- drivers/pci/controller/Kconfig | 2 +- drivers/pci/controller/pcie-mediatek.c | 118 +++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 1 deletion(-)
drivers/pci/controller/Kconfig +1 -1
@@ -209,7 +209,7 @@ config PCI_MVEBU config PCIE_MEDIATEK tristate "MediaTek PCIe controller" - depends on ARCH_AIROHA || ARCH_MEDIATEK || COMPILE_TEST + depends on ARCH_AIROHA || ARCH_MEDIATEK || ECONET || COMPILE_TEST depends on OF depends on PCI_MSI select IRQ_MSI_LIB
drivers/pci/controller/pcie-mediatek.c +118 -0
156 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH v2 3/3 PCI: Skip bridge window reads when window is not supported
In reply to Caleb James DeLislepci_read_bridge_io() and pci_read_bridge_mmio_pref() read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows() already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start of pci_read_bridge_io() and pci_read_bridge_mmio_pref() to skip reading registers when the window is not supported.
--- drivers/pci/probe.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/pci/probe.c +6 -0
@@ -395,6 +395,9 @@ static void pci_read_bridge_io(struct pci_dev *dev, struct resource *res,unsigned long io_mask, io_granularity, base, limit;struct pci_bus_region region; +if (!dev->io_window) +return ; + io_mask =PCI_IO_RANGE_MASK ; io_granularity =0x1000 ;if (dev->io_window_1k) {
@@ -465,6 +468,9 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res,pci_bus_addr_t base, limit;struct pci_bus_region region; +if (!dev->pref_window) +return ; +pci_read_config_word (dev,PCI_PREF_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_PREF_MEMORY_LIMIT , &mem_limit_lo); base64 = (mem_base_lo &PCI_PREF_RANGE_MASK ) <<16 ;
Signature · 1 line
2.39.5
Re: [PATCH v2 3/3] PCI: Skip bridge window reads when window is not supported
Quoted 11 lines · Caleb James DeLisle
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported.
The fundamental problem here is that assigned space to a bridge window that isn't implemented. I wish we understood the connection between this "read window" path and the assignment path.
Maybe this patch fixes it because we enter pci_read_bridge_mmio_pref() with res->flags being NULL, and we set IORESOURCE_MEM | IORESOURCE_PREFETCH again, which makes it look like we can assign space for it?
If that's the case, I think it would improve the commit log to mention the actual mechanism by which we avoid assigning space.
Quoted 35 lines
Suggested-by Bjorn Helgaas <[email protected]>Signed-off-by Ahmed Naseef <[email protected]>Signed-off-by Caleb James DeLisle <[email protected]>--- drivers/pci/probe.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/pci/probe.c +6
-0@@ -395,6 +395,9 @@ static void pci_read_bridge_io(struct pci_dev *dev, struct resource *res,unsigned long io_mask, io_granularity, base, limit;struct pci_bus_region region; +if (!dev->io_window) +return ; + io_mask =PCI_IO_RANGE_MASK ; io_granularity =0x1000 ;if (dev->io_window_1k) {@@ -465,6 +468,9 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res,pci_bus_addr_t base, limit;struct pci_bus_region region; +if (!dev->pref_window) +return ; +pci_read_config_word (dev,PCI_PREF_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_PREF_MEMORY_LIMIT , &mem_limit_lo); base64 = (mem_base_lo &PCI_PREF_RANGE_MASK ) <<16 ;Signature · 1 line
2.39.5
Re: [PATCH v2 3/3] PCI: Skip bridge window reads when window is not supported
Quoted 13 lines · Bjorn Helgaas
Quoted 11 lines · Caleb James DeLisle
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported.
Quoted 8 lines
The fundamental problem here is that assigned space to a bridge window that isn't implemented. I wish we understood the connection between this "read window" path and the assignment path.
Maybe this patch fixes it because we enter
pci_read_bridge_mmio_pref()withres->flagsbeing NULL, and we setIORESOURCE_MEM|IORESOURCE_PREFETCHagain, which makes it look like we can assign space for it?
Yes, that's exactly right.
Quoted 4 lines
If that's the case, I think it would improve the commit log to mention the actual mechanism by which we avoid assigning space.
How about this:
pci_read_bridge_io() and pci_read_bridge_mmio_pref() read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, these functions set IORESOURCE_IO or IORESOURCE_MEM | IORESOURCE_PREFETCH on the bridge resource. This causes the allocator to assign space for the window even though the hardware can't implement it.
pci_read_bridge_windows() already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start of pci_read_bridge_io() and pci_read_bridge_mmio_pref() to skip reading registers when the window is not supported, so the resource flags remain clear and the allocator does not assign space for non-existent windows.
Ahmed Naseef
Quoted 35 lines
Quoted 35 lines
Suggested-by Bjorn Helgaas <[email protected]>Signed-off-by Ahmed Naseef <[email protected]>Signed-off-by Caleb James DeLisle <[email protected]>--- drivers/pci/probe.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/pci/probe.c +6
-0@@ -395,6 +395,9 @@ static void pci_read_bridge_io(struct pci_dev *dev, struct resource *res,unsigned long io_mask, io_granularity, base, limit;struct pci_bus_region region; +if (!dev->io_window) +return ; + io_mask =PCI_IO_RANGE_MASK ; io_granularity =0x1000 ;if (dev->io_window_1k) {@@ -465,6 +468,9 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res,pci_bus_addr_t base, limit;struct pci_bus_region region; +if (!dev->pref_window) +return ; +pci_read_config_word (dev,PCI_PREF_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_PREF_MEMORY_LIMIT , &mem_limit_lo); base64 = (mem_base_lo &PCI_PREF_RANGE_MASK ) <<16 ;Signature · 1 line
2.39.5
Re: [PATCH v2 3/3] PCI: Skip bridge window reads when window is not supported
Quoted 41 lines · Ahmed Naseef
Quoted 13 lines · Bjorn Helgaas
Quoted 11 lines · Caleb James DeLisle
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported.Quoted 8 lines
The fundamental problem here is that assigned space to a bridge window that isn't implemented. I wish we understood the connection between this "read window" path and the assignment path.
Maybe this patch fixes it because we enter
pci_read_bridge_mmio_pref()withres->flagsbeing NULL, and we setIORESOURCE_MEM|IORESOURCE_PREFETCHagain, which makes it look like we can assign space for it?Yes, that's exactly right.
Quoted 4 lines
If that's the case, I think it would improve the commit log to mention the actual mechanism by which we avoid assigning space.
How about this:
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, these functions setIORESOURCE_IOorIORESOURCE_MEM|IORESOURCE_PREFETCHon the bridge resource. This causes the allocator to assign space for the window even though the hardware can't implement it.
Quoted 7 lines
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported, so the resource flags remain clear and the allocator does not assign space for non-existent windows.
At least to me the proposed text reads much better than the original. The original text required reading between the lines to connect the dots, whereas this new one clearly explains what causes what.
--
i.
Quoted 38 lines
Ahmed Naseef
Quoted 35 lines
Quoted 35 lines
Suggested-by Bjorn Helgaas <[email protected]>Signed-off-by Ahmed Naseef <[email protected]>Signed-off-by Caleb James DeLisle <[email protected]>--- drivers/pci/probe.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/pci/probe.c +6
-0@@ -395,6 +395,9 @@ static void pci_read_bridge_io(struct pci_dev *dev, struct resource *res,unsigned long io_mask, io_granularity, base, limit;struct pci_bus_region region; +if (!dev->io_window) +return ; + io_mask =PCI_IO_RANGE_MASK ; io_granularity =0x1000 ;if (dev->io_window_1k) {@@ -465,6 +468,9 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res,pci_bus_addr_t base, limit;struct pci_bus_region region; +if (!dev->pref_window) +return ; +pci_read_config_word (dev,PCI_PREF_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_PREF_MEMORY_LIMIT , &mem_limit_lo); base64 = (mem_base_lo &PCI_PREF_RANGE_MASK ) <<16 ;Signature · 1 line
2.39.5
Re: [PATCH v2 3/3] PCI: Skip bridge window reads when window is not supported
Quoted 51 lines · Ilpo Järvinen
Quoted 41 lines · Ahmed Naseef
Quoted 13 lines · Bjorn Helgaas
Quoted 11 lines · Caleb James DeLisle
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported.Quoted 8 lines
The fundamental problem here is that assigned space to a bridge window that isn't implemented. I wish we understood the connection between this "read window" path and the assignment path.
Maybe this patch fixes it because we enter
pci_read_bridge_mmio_pref()withres->flagsbeing NULL, and we setIORESOURCE_MEM|IORESOURCE_PREFETCHagain, which makes it look like we can assign space for it?Yes, that's exactly right.
Quoted 4 lines
If that's the case, I think it would improve the commit log to mention the actual mechanism by which we avoid assigning space.
How about this:
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, these functions setIORESOURCE_IOorIORESOURCE_MEM|IORESOURCE_PREFETCHon the bridge resource. This causes the allocator to assign space for the window even though the hardware can't implement it.Quoted 7 lines
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported, so the resource flags remain clear and the allocator does not assign space for non-existent windows.
Quoted 3 lines
At least to me the proposed text reads much better than the original. The original text required reading between the lines to connect the dots, whereas this new one clearly explains what causes what.
Hi again,
Reading the code I think the entire 0 <= 0 part is a red herring when it comes to the current code, the flags are always set by the functions!
The code would only add IORESOURCE_UNSET | IORESOURCE_DISABLED if the base <= limit check fails but that's still wrong because it says to the resource allocation code that it can enable that bridge window if it needs to.
Prior to the commit 8278c6914306 ("PCI: Preserve bridge window resource type flags") the base <= limit check did play some role (maybe the original commit message was based on some older tree than the most current one).
Signature · 1 line
i.
Re: [PATCH v2 3/3] PCI: Skip bridge window reads when window is not supported
Quoted 68 lines · Ilpo Järvinen
Quoted 51 lines · Ilpo Järvinen
Quoted 41 lines · Ahmed Naseef
Quoted 13 lines · Bjorn Helgaas
Quoted 11 lines · Caleb James DeLisle
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported.Quoted 8 lines
The fundamental problem here is that assigned space to a bridge window that isn't implemented. I wish we understood the connection between this "read window" path and the assignment path.
Maybe this patch fixes it because we enter
pci_read_bridge_mmio_pref()withres->flagsbeing NULL, and we setIORESOURCE_MEM|IORESOURCE_PREFETCHagain, which makes it look like we can assign space for it?Yes, that's exactly right.
Quoted 4 lines
If that's the case, I think it would improve the commit log to mention the actual mechanism by which we avoid assigning space.
How about this:
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, these functions setIORESOURCE_IOorIORESOURCE_MEM|IORESOURCE_PREFETCHon the bridge resource. This causes the allocator to assign space for the window even though the hardware can't implement it.Quoted 7 lines
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported, so the resource flags remain clear and the allocator does not assign space for non-existent windows.Quoted 3 lines
At least to me the proposed text reads much better than the original. The original text required reading between the lines to connect the dots, whereas this new one clearly explains what causes what.
Hi again,
Reading the code I think the entire 0 <= 0 part is a red herring when it comes to the current code, the flags are always set by the functions!
The code would only add
IORESOURCE_UNSET|IORESOURCE_DISABLEDif the base <= limit check fails but that's still wrong because it says to the resource allocation code that it can enable that bridge window if it needs to.
Quoted 4 lines
Prior to the commit
8278c6914306("PCI: Preserve bridge window resource type flags") the base <= limit check did play some role (maybe the original commit message was based on some older tree than the most current one).
Thank you for catching that. We were testing on LTS kernel 6.12 (downstream OpenWrt) where the commit 8278c6914306 ("PCI: Preserve bridge window resource type flags") is not present . In that tree the flags are still only set inside the base <= limit check, which is why the commit message focused on that path.
For current mainline, how about this for the commit message:
pci_read_bridge_io() and pci_read_bridge_mmio_pref() unconditionally set resource type flags (IORESOURCE_IO or IORESOURCE_MEM | IORESOURCE_PREFETCH) when reading bridge window registers. For windows that are not implemented in hardware, this causes the allocator to assign space for a window that doesn't exist.
pci_read_bridge_windows() already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start of pci_read_bridge_io() and pci_read_bridge_mmio_pref() to skip them entirely when the window is not supported, so the resource flags remain clear and the allocator does not assign space for non-existent windows.
Ahmed Naseef
Quoted 3 lines
Signature · 2 lines
-- i.
Re: [PATCH v2 3/3] PCI: Skip bridge window reads when window is not supported
In reply to Caleb James DeLisleQuoted 12 lines · Caleb James DeLisle
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported.
Quoted 4 lines
Suggested-by Bjorn Helgaas <[email protected]>Signed-off-by Ahmed Naseef <[email protected]>Signed-off-by Caleb James DeLisle <[email protected]>
I applied this to pci/resource for v7.1 with the following commit log:
PCI: Prevent assignment to unsupported bridge windows
Previously, pci_read_bridge_io() and pci_read_bridge_mmio_pref() unconditionally set resource type flags (IORESOURCE_IO or IORESOURCE_MEM | IORESOURCE_PREFETCH) when reading bridge window registers. For windows that are not implemented in hardware, this may cause the allocator to assign space for a window that doesn't exist.
For example, the EcoNET EN7528 SoC Root Port doesn't support the prefetchable window, but since a downstream device had a prefetchable BAR, the allocator mistakenly assigned a prefetchable window:
pci 0001:00:01.0: [14c3:0811] type 01 class 0x060400 PCIe Root Port
pci 0001:00:01.0: PCI bridge to [bus 01-ff]
pci 0001:00:01.0: bridge window [mem 0x28000000-0x280fffff]: assigned
pci 0001:00:01.0: bridge window [mem 0x28100000-0x282fffff pref]: assigned
pci 0001:01:00.0: BAR 0 [mem 0x28100000-0x281fffff 64bit pref]: assigned pci_read_bridge_windows() already detects unsupported windows by testing register writability and sets dev->io_window/pref_window accordingly.
Check dev->io_window/pref_window so we don't set the resource flags for unsupported windows, which prevents the allocator from assigning space to them.
After this commit, the prefetchable BAR is correctly allocated from the non-prefetchable window:
pci 0001:00:01.0: bridge window [mem 0x28000000-0x281fffff]: assigned
pci 0001:01:00.0: BAR 0 [mem 0x28000000-0x280fffff 64bit pref]: assignedI also set the author to "Ahmed Naseef <[email protected]>" per
https://lore.kernel.org/all/abRQYM1If/6Vv/[email protected]
You can make this work correctly next time by including a "From: Ahmed Naseef <[email protected]>" line as the very first line in the message body; see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=v6.19#n723
Quoted 31 lines
--- drivers/pci/probe.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/pci/probe.c +6
-0@@ -395,6 +395,9 @@ static void pci_read_bridge_io(struct pci_dev *dev, struct resource *res,unsigned long io_mask, io_granularity, base, limit;struct pci_bus_region region; +if (!dev->io_window) +return ; + io_mask =PCI_IO_RANGE_MASK ; io_granularity =0x1000 ;if (dev->io_window_1k) {@@ -465,6 +468,9 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res,pci_bus_addr_t base, limit;struct pci_bus_region region; +if (!dev->pref_window) +return ; +pci_read_config_word (dev,PCI_PREF_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_PREF_MEMORY_LIMIT , &mem_limit_lo); base64 = (mem_base_lo &PCI_PREF_RANGE_MASK ) <<16 ;Signature · 1 line
2.39.5
Re: [PATCH v2 3/3] PCI: Skip bridge window reads when window is not supported
Quoted 50 lines · Bjorn Helgaas
Quoted 12 lines · Caleb James DeLisle
pci_read_bridge_io()andpci_read_bridge_mmio_pref()read bridge window registers unconditionally. If the registers are hardwired to zero (not implemented), both base and limit will be 0. Since (0 <= 0) is true, a bogus window [mem 0x00000000-0x000fffff] or [io 0x0000-0x0fff] gets created.
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets io_window/pref_window flags accordingly. Check these flags at the start ofpci_read_bridge_io()andpci_read_bridge_mmio_pref()to skip reading registers when the window is not supported.Quoted 4 lines
Suggested-by Bjorn Helgaas <[email protected]>Signed-off-by Ahmed Naseef <[email protected]>Signed-off-by Caleb James DeLisle <[email protected]>I applied this to pci/resource for v7.1 with the following commit log:
PCI: Prevent assignment to unsupported bridge windows
Previously,
pci_read_bridge_io()andpci_read_bridge_mmio_pref()unconditionally set resource type flags (IORESOURCE_IOorIORESOURCE_MEM|IORESOURCE_PREFETCH) when reading bridge window registers. For windows that are not implemented in hardware, this may cause the allocator to assign space for a window that doesn't exist.For example, the EcoNET EN7528 SoC Root Port doesn't support the prefetchable window, but since a downstream device had a prefetchable BAR, the allocator mistakenly assigned a prefetchable window:
pci 0001:00:01.0: [14c3:0811] type 01 class 0x060400 PCIe Root Port pci 0001:00:01.0: PCI bridge to [bus 01-ff] pci 0001:00:01.0: bridge window [mem 0x28000000-0x280fffff]: assigned pci 0001:00:01.0: bridge window [mem 0x28100000-0x282fffff pref]: assigned pci 0001:01:00.0: BAR 0 [mem 0x28100000-0x281fffff 64bit pref]: assigned
pci_read_bridge_windows()already detects unsupported windows by testing register writability and sets dev->io_window/pref_window accordingly.Check dev->io_window/pref_window so we don't set the resource flags for unsupported windows, which prevents the allocator from assigning space to them.
After this commit, the prefetchable BAR is correctly allocated from the non-prefetchable window: pci 0001:00:01.0: bridge window [mem 0x28000000-0x281fffff]: assigned pci 0001:01:00.0: BAR 0 [mem 0x28000000-0x280fffff 64bit pref]: assigned
Quoted 7 lines
I also set the author to "Ahmed Naseef <[email protected]>" per
https://lore.kernel.org/all/abRQYM1If/6Vv/[email protected]You can make this work correctly next time by including a "From: Ahmed Naseef <[email protected]>" line as the very first line in the message body; see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=v6.19#n723
Thank you very much. I wasn't quite sure how to submit this so thanks and I will keep that in mind.
Thanks,
Caleb
Quoted 31 lines
Quoted 31 lines
--- drivers/pci/probe.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/pci/probe.c +6
-0@@ -395,6 +395,9 @@ static void pci_read_bridge_io(struct pci_dev *dev, struct resource *res,unsigned long io_mask, io_granularity, base, limit;struct pci_bus_region region; +if (!dev->io_window) +return ; + io_mask =PCI_IO_RANGE_MASK ; io_granularity =0x1000 ;if (dev->io_window_1k) {@@ -465,6 +468,9 @@ static void pci_read_bridge_mmio_pref(struct pci_dev *dev, struct resource *res,pci_bus_addr_t base, limit;struct pci_bus_region region; +if (!dev->pref_window) +return ; +pci_read_config_word (dev,PCI_PREF_MEMORY_BASE , &mem_base_lo);pci_read_config_word (dev,PCI_PREF_MEMORY_LIMIT , &mem_limit_lo); base64 = (mem_base_lo &PCI_PREF_RANGE_MASK ) <<16 ;Signature · 1 line
2.39.5