* [PATCH] PCI: mvebu: Reset Root Ports with PERST#
@ 2026-12-04 6:07 Rosen Penev
0 siblings, 0 replies; only message in thread
From: Rosen Penev @ 2026-12-04 6:07 UTC (permalink / raw)
To: linux-pci
Cc: Thomas Petazzoni, Pali Rohár, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam, Rob Herring,
Bjorn Helgaas,
moderated list:PCI DRIVER FOR MVEBU (Marvell Armada 370 and Ar...)
A function reset of a device whose only reset method is "bus" ends up in
pcibios_reset_secondary_bus() on its Root Port. Without a
reset_root_port() callback, that triggers an in-band hot reset through
the emulated bridge (PCIE_CTRL_MASTER_HOT_RESET). Some devices don't
reset fully on a hot reset: the Marvell 88W8864 and 88W8964 Wi-Fi chips
only return to their boot ROM on PERST# or power-on, so once their
firmware has run, the driver can't be bound to them again until the
board is rebooted.
When the port has a reset GPIO, implement reset_root_port() by pulsing
PERST# instead: assert it for 1-2 ms (more than the 100 us Tperst
minimum), release it, wait the same time as at power-up (reset-delay-us,
by default PCI_PM_D3COLD_WAIT), and wait up to a second for the link to
come back. Ports without a reset GPIO keep the hot reset.
Factor the reset-delay-us lookup out of mvebu_pcie_powerup() so both
use the same delay.
Tested on a Linksys WRT3200ACM (two 88W8964 radios, PERST# on MPP45 and
MPP46): unbinding and binding mwlwifi again, with mwlwifi calling
pci_reset_function_locked() when the boot ROM doesn't answer, now
reloads the firmware of either radio.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/pci/controller/pci-mvebu.c | 56 ++++++++++++++++++++++++++----
1 file changed, 50 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
index 00b88b859dfd..6dcecbdba377 100644
--- a/drivers/pci/controller/pci-mvebu.c
+++ b/drivers/pci/controller/pci-mvebu.c
@@ -14,6 +14,7 @@
#include <linux/gpio/consumer.h>
#include <linux/init.h>
#include <linux/irqchip/chained_irq.h>
+#include <linux/iopoll.h>
#include <linux/irqdomain.h>
#include <linux/mbus.h>
#include <linux/slab.h>
@@ -1356,6 +1357,16 @@ static int mvebu_pcie_parse_port(struct mvebu_pcie *pcie,
return ret;
}
+/* Time to wait after releasing PERST# before the device is accessed. */
+static unsigned int mvebu_pcie_port_reset_delay_ms(struct mvebu_pcie_port *port)
+{
+ u32 reset_udelay = PCI_PM_D3COLD_WAIT * 1000;
+
+ of_property_read_u32(port->dn, "reset-delay-us", &reset_udelay);
+
+ return reset_udelay / 1000;
+}
+
/*
* Power up a PCIe port. PCIe requires the refclk to be stable for 100µs
* prior to releasing PERST. See table 2-4 in section 2.6.2 AC Specifications
@@ -1370,15 +1381,10 @@ static int mvebu_pcie_powerup(struct mvebu_pcie_port *port)
return ret;
if (port->reset_gpio) {
- u32 reset_udelay = PCI_PM_D3COLD_WAIT * 1000;
-
- of_property_read_u32(port->dn, "reset-delay-us",
- &reset_udelay);
-
udelay(100);
gpiod_set_value_cansleep(port->reset_gpio, 0);
- msleep(reset_udelay / 1000);
+ msleep(mvebu_pcie_port_reset_delay_ms(port));
}
return 0;
@@ -1395,6 +1401,43 @@ static void mvebu_pcie_powerdown(struct mvebu_pcie_port *port)
clk_disable_unprepare(port->clk);
}
+/*
+ * Reset the device below a Root Port. The in-band hot reset that
+ * pci_reset_secondary_bus() triggers through the emulated bridge does not
+ * reset every device (some only return to their boot ROM on PERST#), so
+ * pulse PERST# when the port has a reset GPIO.
+ */
+static int mvebu_pcie_reset_root_port(struct pci_host_bridge *bridge,
+ struct pci_dev *dev)
+{
+ struct mvebu_pcie *pcie = pci_host_bridge_priv(bridge);
+ struct mvebu_pcie_port *port;
+ bool up;
+ int ret;
+
+ port = mvebu_pcie_find_port(pcie, dev->bus, dev->devfn);
+ if (!port)
+ return -ENODEV;
+
+ if (!port->reset_gpio) {
+ pci_reset_secondary_bus(dev);
+ return 0;
+ }
+
+ gpiod_set_value_cansleep(port->reset_gpio, 1);
+ /* PERST# must stay asserted for at least 100 us (Tperst) */
+ usleep_range(1000, 2000);
+ gpiod_set_value_cansleep(port->reset_gpio, 0);
+ msleep(mvebu_pcie_port_reset_delay_ms(port));
+
+ ret = read_poll_timeout(mvebu_pcie_link_up, up, up, 1000,
+ USEC_PER_SEC, false, port);
+ if (ret)
+ dev_warn(&dev->dev, "link down after PERST#\n");
+
+ return ret;
+}
+
/*
* devm_of_pci_get_host_bridge_resources() only sets up translatable resources,
* so we need extra resource setup parsing our special DT properties encoding
@@ -1615,6 +1658,7 @@ static int mvebu_pcie_probe(struct platform_device *pdev)
bridge->child_ops = &mvebu_pcie_child_ops;
bridge->align_resource = mvebu_pcie_align_resource;
bridge->map_irq = mvebu_pcie_map_irq;
+ bridge->reset_root_port = mvebu_pcie_reset_root_port;
return pci_host_probe(bridge);
}
--
2.56.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-04 6:08 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 6:07 [PATCH] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox