* [PATCH v2 1/3] PCI: Save Root Port state before resetting it with reset_root_port()
2026-12-06 9:40 [PATCH v2 0/3] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
@ 2026-12-06 9:40 ` Rosen Penev
2026-12-06 9:40 ` [PATCH v2 2/3] PCI: Export pci_reset_secondary_bus() Rosen Penev
2026-12-06 9:40 ` [PATCH v2 3/3] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-12-06 9:40 UTC (permalink / raw)
To: Thomas Petazzoni, Pali Rohár, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam, Bjorn Helgaas,
Frank Li
Cc: Rob Herring, Manivannan Sadhasivam, linux-pci, linux-arm-kernel
pcibios_reset_secondary_bus() restores the Root Port's config space after
host->reset_root_port(), but doesn't save it first, so it restores
whatever was saved last. For a Root Port that is the state saved when
portdrv probed it, before a device below it was enabled, which turns
memory decoding and bus mastering of the port off again: a function
reset of the device through its parent bus (e.g. pci_reset_function()
on a device whose only reset method is "bus") leaves the device
unreachable.
Save the Root Port's state right before resetting it. If a reset fails,
don't save again on the next attempt: the port may be left with reset
defaults (e.g. cleared bridge windows) that a successful retry would then
restore, or with its clocks off, where reading its config space can abort.
Keep the state saved before the failed reset instead.
Fixes: 3fc686d550f6 ("PCI/ERR: Add support for resetting the Root Ports in a platform-specific way")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/pci/pci.c | 16 ++++++++++++++--
drivers/pci/pci.h | 1 +
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e2607cc84ff1..66ed89142a65 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5100,11 +5100,23 @@ void __weak pcibios_reset_secondary_bus(struct pci_dev *dev)
int ret;
if (pci_is_root_bus(dev->bus) && host->reset_root_port) {
+ /*
+ * The state saved when the port was enumerated or probed may
+ * predate changes made since, e.g. memory decoding enabled
+ * once a device below the port was enabled. After a failed
+ * reset, keep the state saved before it instead: the port may
+ * be left with reset defaults or with its clocks off.
+ */
+ if (!test_bit(PCI_ROOT_PORT_RESET_FAILED, &dev->priv_flags))
+ pci_save_state(dev);
ret = host->reset_root_port(host, dev);
- if (ret)
+ if (ret) {
+ set_bit(PCI_ROOT_PORT_RESET_FAILED, &dev->priv_flags);
pci_err(dev, "Failed to reset Root Port: %d\n", ret);
- else
+ } else {
+ clear_bit(PCI_ROOT_PORT_RESET_FAILED, &dev->priv_flags);
pci_restore_state(dev);
+ }
return;
}
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 202c52c0a83b..972ca609458b 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -825,6 +825,7 @@ static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
#define PCI_LINK_CHANGING 5
#define PCI_LINK_LBMS_SEEN 6
#define PCI_DEV_ALLOW_BINDING 7
+#define PCI_ROOT_PORT_RESET_FAILED 8
static inline void pci_dev_assign_added(struct pci_dev *dev)
{
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/3] PCI: Export pci_reset_secondary_bus()
2026-12-06 9:40 [PATCH v2 0/3] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
2026-12-06 9:40 ` [PATCH v2 1/3] PCI: Save Root Port state before resetting it with reset_root_port() Rosen Penev
@ 2026-12-06 9:40 ` Rosen Penev
2026-12-06 9:40 ` [PATCH v2 3/3] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-12-06 9:40 UTC (permalink / raw)
To: Thomas Petazzoni, Pali Rohár, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam, Bjorn Helgaas,
Frank Li
Cc: Rob Herring, Manivannan Sadhasivam, linux-pci, linux-arm-kernel
A host bridge's reset_root_port() callback may only need a reset other
than the in-band hot reset for some of its Root Ports, and fall back to
pci_reset_secondary_bus() for the others. pci-mvebu, the next user, can
be built as a module, so export the function.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/pci/pci.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 66ed89142a65..99b1ded27e83 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5093,6 +5093,7 @@ void pci_reset_secondary_bus(struct pci_dev *dev)
ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl);
}
+EXPORT_SYMBOL_GPL(pci_reset_secondary_bus);
void __weak pcibios_reset_secondary_bus(struct pci_dev *dev)
{
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 3/3] PCI: mvebu: Reset Root Ports with PERST#
2026-12-06 9:40 [PATCH v2 0/3] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
2026-12-06 9:40 ` [PATCH v2 1/3] PCI: Save Root Port state before resetting it with reset_root_port() Rosen Penev
2026-12-06 9:40 ` [PATCH v2 2/3] PCI: Export pci_reset_secondary_bus() Rosen Penev
@ 2026-12-06 9:40 ` Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-12-06 9:40 UTC (permalink / raw)
To: Thomas Petazzoni, Pali Rohár, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam, Bjorn Helgaas,
Frank Li
Cc: Rob Herring, Manivannan Sadhasivam, linux-pci, linux-arm-kernel
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, through
pci_reset_secondary_bus().
With the callback registered, pcibios_reset_secondary_bus() also
restores the Root Port's config space after the reset, on every port.
It saves that state right before the reset, so this restores the
current PCI_COMMAND rather than the one saved at enumeration, which
has memory decoding and bus mastering off.
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 4e9544d61622..d5c874d6c2b3 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>
@@ -1358,6 +1359,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
@@ -1372,15 +1383,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;
@@ -1397,6 +1403,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
@@ -1622,6 +1665,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] 4+ messages in thread