From: Rosen Penev <rosenp@gmail.com>
To: linux-pci@vger.kernel.org
Cc: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Pali Rohár" <pali@kernel.org>,
"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
linux-arm-kernel@lists.infradead.org (moderated list:PCI DRIVER
FOR MVEBU (Marvell Armada 370 and Ar...))
Subject: [PATCH] PCI: mvebu: Reset Root Ports with PERST#
Date: Thu, 3 Dec 2026 22:07:51 -0800 [thread overview]
Message-ID: <20261204060752.1243189-1-rosenp@gmail.com> (raw)
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
next reply other threads:[~2026-12-04 6:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:07 Rosen Penev [this message]
2026-12-04 6:31 ` [PATCH] PCI: mvebu: Reset Root Ports with PERST# sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204060752.1243189-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=bhelgaas@google.com \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=pali@kernel.org \
--cc=robh@kernel.org \
--cc=thomas.petazzoni@bootlin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.