Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: mvebu: Reset Root Ports with PERST#
@ 2026-12-04  6:07 Rosen Penev
  2026-12-04  6:31 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread

* Re: [PATCH] PCI: mvebu: Reset Root Ports with PERST#
  2026-12-04  6:07 [PATCH] PCI: mvebu: Reset Root Ports with PERST# Rosen Penev
@ 2026-12-04  6:31 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04  6:31 UTC (permalink / raw)
  To: Rosen Penev, linux-pci

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] PCI: mvebu: stale pci_restore_state() clears Root Port
  PCIE_CMD_OFF
- [High] PCI: mvebu: unexported pci_reset_secondary_bus() breaks modular
  build
--

commit 90009b7c04d34fd6a20b51652628a203f71fd40f
Author: Rosen Penev <rosenp@gmail.com>

PCI: mvebu: Reset Root Ports with PERST#

This commit implements the reset_root_port() callback for mvebu PCIe
Root Ports to pulse PERST# via the port reset GPIO, falling back to
pci_reset_secondary_bus() when no reset GPIO is present.

> diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c
> index 4e9544d616226..d5c874d6c2b3a 100644
> --- a/drivers/pci/controller/pci-mvebu.c
> +++ b/drivers/pci/controller/pci-mvebu.c

[ ... ]

> @@ -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;
> +	}

[Severity: High]
Does this break modular builds with CONFIG_PCI_MVEBU=m?

CONFIG_PCI_MVEBU is tristate, but pci_reset_secondary_bus() in
drivers/pci/pci.c is not exported, so building pci-mvebu as a module
fails at modpost with an undefined symbol error.

[ ... ]

> @@ -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);
>  }

[Severity: High]
Can registering reset_root_port here cause pcibios_reset_secondary_bus()
to clear PCIE_CMD_OFF on the Root Port with stale boot-time state?

Whenever host->reset_root_port() returns 0, the PCI core restores the
Root Port's saved config space:

drivers/pci/pci.c:pcibios_reset_secondary_bus() {
    ...
	if (pci_is_root_bus(dev->bus) && host->reset_root_port) {
		ret = host->reset_root_port(host, dev);
		if (ret)
			pci_err(dev, "Failed to reset Root Port: %d\n", ret);
		else
			pci_restore_state(dev);

		return;
	}
    ...
}

During probe, mvebu_pcie_setup_hw() clears PCI_COMMAND_IO,
PCI_COMMAND_MEMORY, and PCI_COMMAND_MASTER in PCIE_CMD_OFF before
pci_bus_add_device() captures the initial pci_save_state() snapshot.
Even with CONFIG_PCIEPORTBUS enabled, pcie_port_device_register() calls
pci_clear_master() right before pcie_portdrv_probe() saves state because
mvebu_pcie_map_irq() returns 0 for bus 0 and service IRQ allocation
fails.

Later, pci_enable_bridge() enables those bits in hardware and sets
enable_cnt and is_busmaster on the Root Port without updating its saved
state.  On any subsequent function or bus reset (including on ports
without reset_gpio), pci_restore_state() writes the stale PCI_COMMAND
back to PCIE_CMD_OFF via mvebu_pci_bridge_emul_base_conf_write(),
clearing bus mastering (and IO/memory decoding when CONFIG_PCIEPORTBUS
is disabled).

Because enable_cnt and is_busmaster remain set in software,
pci_enable_bridge() returns early on endpoint driver rebind and never
re-enables PCIE_CMD_OFF, breaking downstream DMA/MSI and MMIO until
reboot.  Calling pci_save_state(dev) before returning from
mvebu_pcie_reset_root_port() would keep the live Root Port state from
being overwritten.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204060752.1243189-1-rosenp@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04  6:31 UTC | newest]

Thread overview: 2+ messages (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
2026-12-04  6:31 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox