Skip to contentSkip to conversation

PCI: mvebu: Dynamically detect if the PEX link is up to enable hot plug

PATCH Superseded Jason Gunthorpe 2 participants 4 messages Sep 17, 2013 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: mvebu: Dynamically detect if the PEX link is up to enable hot plug

Otherwise hotplugging the PEX doesn't work at all since the driver detects the link state at probe time. Simply replacing the two tests of haslink with a register read is enough to fix discovery.

---
 drivers/pci/host/pci-mvebu.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/pci/host/pci-mvebu.c +2 -14
index 729d5a1..f2d61f5 100644
@@ -115,7 +115,6 @@ struct mvebu_pcie_port {
 	char *name;
 	void __iomem *base;
 	spinlock_t conf_lock;
-	int haslink;
 	u32 port;
 	u32 lane;
 	int devfn;
@@ -552,7 +551,7 @@ static int mvebu_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
 	if (bus->number == 0)
 		return mvebu_sw_pci_bridge_write(port, where, size, val);
 
-	if (!port->haslink)
+	if (!mvebu_pcie_link_up(port))
 		return PCIBIOS_DEVICE_NOT_FOUND;
 
 	/*
@@ -594,7 +593,7 @@ static int mvebu_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
 	if (bus->number == 0)
 		return mvebu_sw_pci_bridge_read(port, where, size, val);
 
-	if (!port->haslink) {
+	if (!mvebu_pcie_link_up(port)) {
 		*val = 0xffffffff;
 		return PCIBIOS_DEVICE_NOT_FOUND;
 	}
@@ -883,22 +882,11 @@ static int __init mvebu_pcie_probe(struct platform_device *pdev)
 
 		mvebu_pcie_set_local_dev_nr(port, 1);
 
-		if (mvebu_pcie_link_up(port)) {
-			port->haslink = 1;
-			dev_info(&pdev->dev, "PCIe%d.%d: link up\n",
-				 port->port, port->lane);
-		} else {
-			port->haslink = 0;
-			dev_info(&pdev->dev, "PCIe%d.%d: link down\n",
-				 port->port, port->lane);
-		}
-
 		port->clk = of_clk_get_by_name(child, NULL);
 		if (IS_ERR(port->clk)) {
 			dev_err(&pdev->dev, "PCIe%d.%d: cannot get clock\n",
 			       port->port, port->lane);
 			iounmap(port->base);
-			port->haslink = 0;
 			continue;
 		}
 
Signature · 1 line
1.8.1.2
#1 lore raw

Dear Jason Gunthorpe,

Quoted 5 lines · Jason Gunthorpe

Otherwise hotplugging the PEX doesn't work at all since the driver detects the link state at probe time. Simply replacing the two tests of haslink with a register read is enough to fix discovery.

I don't have the hardware to test, but this seems to make sense to me.

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#2 lore raw
Quoted 10 lines · Thomas Petazzoni

Dear Jason Gunthorpe,

Quoted 5 lines · Jason Gunthorpe

Otherwise hotplugging the PEX doesn't work at all since the driver detects the link state at probe time. Simply replacing the two tests of haslink with a register read is enough to fix discovery.

I don't have the hardware to test, but this seems to make sense to me.

FWIW, I have tested this on Kirkwood:

mvebu-pcie pex.1: PCI host bridge to bus 0000:00
pci_bus 0000:00: root bus resource [mem 0xe0000000-0xf0000000] pci_bus 0000:00: root bus resource [bus 00-ff]
pci_bus 0000:00: root bus resource [io 0x1000-0xffff]
pci 0000:00:01.0: [11ab:7846] type 01 class 0x060400
PCI: bus0: Fast back to back transfers disabled
pci 0000:00:01.0: bridge configuration invalid ([bus 00-00]), reconfiguring
PCI: bus1: Fast back to back transfers enabled
pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
pci 0000:00:01.0: PCI bridge to [bus 01]
[..]
Freeing unused kernel memory: 1096K (c02ee000 - c0400000)

.. hot plug the device ..

echo 1 > rescan

pci 0000:01:00.0: [170c:0001] type 00 class 0x058000 pci 0000:01:00.0: reg 0x10: [mem 0x00000000-0x0001ffff] pci 0000:01:00.0: PME# supported from D0 D1 D2 D3hot pci_bus 0000:01: busn_res: [bus 01] end is updated to 01 pci 0000:00:01.0: BAR 8: assigned [mem 0xe0000000-0xe00fffff] pci 0000:01:00.0: BAR 0: assigned [mem 0xe0000000-0xe001ffff] pci 0000:00:01.0: PCI bridge to [bus 01]
pci 0000:00:01.0: bridge window [mem 0xe0000000-0xe00fffff]
PCI: enabling device 0000:00:01.0 (0140 -> 0143)
PCI: enabling device 0000:01:00.0 (0000 -> 0002)

Jason

#3 lore raw

Dear Jason Gunthorpe,

Quoted 21 lines · Jason Gunthorpe
Quoted 1 line

I don't have the hardware to test, but this seems to make sense to me.

FWIW, I have tested this on Kirkwood:

mvebu-pcie pex.1: PCI host bridge to bus 0000:00
pci_bus 0000:00: root bus resource [mem 0xe0000000-0xf0000000] pci_bus 0000:00: root bus resource [bus 00-ff]
pci_bus 0000:00: root bus resource [io 0x1000-0xffff]
pci 0000:00:01.0: [11ab:7846] type 01 class 0x060400
PCI: bus0: Fast back to back transfers disabled
pci 0000:00:01.0: bridge configuration invalid ([bus 00-00]), reconfiguring
PCI: bus1: Fast back to back transfers enabled
pci_bus 0000:01: busn_res: [bus 01-ff] end is updated to 01
pci 0000:00:01.0: PCI bridge to [bus 01]
[..]
Freeing unused kernel memory: 1096K (c02ee000 - c0400000)

.. hot plug the device ..

echo 1 > rescan

Quoted 10 lines

pci 0000:01:00.0: [170c:0001] type 00 class 0x058000 pci 0000:01:00.0: reg 0x10: [mem 0x00000000-0x0001ffff] pci 0000:01:00.0: PME# supported from D0 D1 D2 D3hot pci_bus 0000:01: busn_res: [bus 01] end is updated to 01 pci 0000:00:01.0: BAR 8: assigned [mem 0xe0000000-0xe00fffff] pci 0000:01:00.0: BAR 0: assigned [mem 0xe0000000-0xe001ffff] pci 0000:00:01.0: PCI bridge to [bus 01]
pci 0000:00:01.0: bridge window [mem 0xe0000000-0xe00fffff]
PCI: enabling device 0000:00:01.0 (0140 -> 0143)
PCI: enabling device 0000:01:00.0 (0000 -> 0002)

Nice!

Good to see that the changes needed to get PCI hotplug working were not so large :)

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com