* [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors
@ 2026-11-05 21:59 Soeren Coremans
2026-11-05 21:59 ` [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index Soeren Coremans
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Soeren Coremans @ 2026-11-05 21:59 UTC (permalink / raw)
To: linux-wireless
Cc: arend.vanspriel, brcm80211, brcm80211-dev-list.pdl,
Soeren Coremans
On a desktop board with a BCM4366/4 (14e4:43c3, firmware 10.28.2), the
firmware traps every few days, at the same address in every trap I
checked. The driver's reset recovered from 10 of 12 traps in five
weeks. In the other two, the downstream port reported a fatal FCP error
about 0.7 s after the trap:
pcieport 0000:16:01.0: PCIe Bus Error: severity=Uncorrectable (Fatal)
pcieport 0000:16:01.0: [13] FCP (First)
brcmfmac 0000:18:00.0: AER: can't recover (no error_detected callback)
brcmfmac: brcmf_chip_get_raminfo: RAM size is incorrect
brcmfmac 0000:18:00.0: brcmf_pcie_setup: Dongle setup failed
WiFi then stayed dead until reboot, and brcmf_pcie_bus_console_read()
kept logging 0xff characters at about 2,800 lines per second.
Patch 1 stops that console loop. Patch 2 fixes a fault in the memdump
that patch 1 uncovers on CONFIG_BRCMDBG builds. Patch 3 adds PCI error
handlers and re-probes the device after the link reset.
Patches 1 and 2 are fixes and could go through wireless instead. Patch 3
depends on patch 1: without it, error_detected() waits forever for a
reset that is stuck in the console loop. I sent them together against
wireless-next for that reason, and am happy to split them if you prefer.
Testing
-------
All runs used a test kernel built from the Ubuntu 7.0.0-42 source (based
on v7.0.14), with CONFIG_PCIEAER_INJECT and, unless noted, CONFIG_BRCMDBG.
On the stock Ubuntu kernel the series has only run for about an hour,
which did not exercise the error paths. Results on the test kernel:
- aer_inject with FCP on the downstream port 0000:16:01.0, alone (5
runs) and 0.3 s after a debugfs-triggered bus reset, which mimics the
trap-then-FCP order seen in the field (10 runs), plus one plain reset:
WiFi back within 6-12 s in 16 of 16 runs.
- The final series, built without CONFIG_BRCMDBG: 5 of 5 injected-only
runs recovered in 6-12 s. The combined reset-and-inject case needs the
debugfs reset file, so it only ran on the debug build, shortly before
two small cleanups (no markers, kzalloc_obj()).
- Real FCP errors, no injection (aer_inject unloaded): debugfs-triggered
resets under a ping flood over WiFi produced 3 real fatal errors in 47
resets. All 3 recovered: "device recovery successful", one re-probe, and
WiFi back within 4-11 s of the error. The log order matches the field
failures, including the "delete_flowring: timed out" about 60 ms before
the error. These runs used the debug build.
- Without the series, the injected error reproduces the dead device and
the log flood.
Not done:
- No runtime test on wireless-next. I only compiled pcie.c from
wireless-next with the series applied (W=1, no new warnings), against
7.0 headers; the rest of the driver does not build against those.
- The real errors above came from resets on healthy firmware. I have only
run the series for about a day, so a firmware trap followed by an FCP
error is still unverified.
Open points
-----------
1. Patch 3 re-probes because brcmf_pcie_reset() alone was not enough
after a link reset: in 5 of 9 runs the firmware came up, but scan
results showed the guest network's SSID under the main network's
BSSID, and association failed with status 16. I did not find which
part of the probe-time setup is missing.
2. The FCP error may come from the driver's own chip reset. It arrived
0.6-0.7 s after teardown started in every real case, about when
brcmf_pcie_reset_device() writes the watchdog register. That is timing
only, I have no proof of the cause. Frequency: 2 of 12 firmware traps,
3 of 47 debugfs resets, 2 of 20 module unloads. An error during unload
leaves the device dead, as no driver is bound to recover it; this series
does not address that.
3. brcmf_pcie_reset() and brcmf_pcie_remove() free the DMA rings before
brcmf_pcie_reset_device() stops the chip. In one of those unloads, the
device wrote into freed buffers first (8 AMD-Vi IO_PAGE_FAULTs). The
other real errors showed no such faults, so this looks separate. This
series does not touch the order; you may know whether it is deliberate.
Tool use
--------
I developed this series with an AI coding assistant, Claude Opus 5.5
(Anthropic), in one long session. I asked it why my WiFi kept
disappearing. It read the logs and the driver source, proposed the
analysis and the fixes, wrote the code, commit messages and test
scripts, and set up the aer_inject test kernel. I ran every test on my
hardware, chose between the options it offered (for example re-probing
after the internal reset failed the tests), and reviewed the patches
before sending.
Soeren Coremans (3):
wifi: brcmfmac: pcie: stop console read on invalid write index
wifi: brcmfmac: pcie: bound memdump to the mapped TCM window
wifi: brcmfmac: pcie: recover from fatal PCIe errors
.../broadcom/brcm80211/brcmfmac/pcie.c | 144 +++++++++++++++++-
1 file changed, 143 insertions(+), 1 deletion(-)
base-commit: b8e5b0ae8ff47240366d38e5d12c65f878724316
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index 2026-11-05 21:59 [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans @ 2026-11-05 21:59 ` Soeren Coremans 2026-11-26 14:29 ` Arend van Spriel 2026-11-05 21:59 ` [PATCH wireless-next 2/3] wifi: brcmfmac: pcie: bound memdump to the mapped TCM window Soeren Coremans ` (2 subsequent siblings) 3 siblings, 1 reply; 8+ messages in thread From: Soeren Coremans @ 2026-11-05 21:59 UTC (permalink / raw) To: linux-wireless Cc: arend.vanspriel, brcm80211, brcm80211-dev-list.pdl, Soeren Coremans, stable When the device drops off the bus, MMIO reads return all ones. The console write index then never matches read_idx, which wraps at bufsize, so brcmf_pcie_bus_console_read() loops forever and floods the kernel log with 0xff characters at several thousand lines per second. Seen on a BCM4366 after a firmware trap followed by a fatal PCIe error (FCP): the reset path and the failed dongle setup both entered the loop and never reached device_release_driver(). Return early when the write index lies outside the console buffer. Found and written with the help of an AI coding assistant (Claude Opus 5.5); the cover letter describes how. Fixes: 9e37f045d5e7 ("brcmfmac: Adding PCIe bus layer support.") Cc: stable@vger.kernel.org Signed-off-by: Soeren Coremans <sorencoremans@gmail.com> --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index eca5f5f63bce..02c58de67b82 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -992,6 +992,14 @@ static void brcmf_pcie_bus_console_read(struct brcmf_pciedev_info *devinfo, return; addr = console->base_addr + BRCMF_CONSOLE_WRITEIDX_OFFSET; newidx = brcmf_pcie_read_tcm32(devinfo, addr); + /* A dead device reads back as all ones, an index read_idx never + * reaches; without this check the loop below never terminates. + */ + if (newidx >= console->bufsize) { + brcmf_dbg(PCIE, "invalid console write index %u (bufsize %u)\n", + newidx, console->bufsize); + return; + } while (newidx != console->read_idx) { addr = console->buf_addr + console->read_idx; ch = brcmf_pcie_read_tcm8(devinfo, addr); -- 2.53.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index 2026-11-05 21:59 ` [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index Soeren Coremans @ 2026-11-26 14:29 ` Arend van Spriel 0 siblings, 0 replies; 8+ messages in thread From: Arend van Spriel @ 2026-11-26 14:29 UTC (permalink / raw) To: Soeren Coremans Cc: linux-wireless, arend.vanspriel, brcm80211, brcm80211-dev-list.pdl, stable On Thu, 5 Nov 2026 22:59:52 +0100, Soeren Coremans <sorencoremans@gmail.com> wrote: > When the device drops off the bus, MMIO reads return all ones. The > console write index then never matches read_idx, which wraps at > bufsize, so brcmf_pcie_bus_console_read() loops forever and floods the > kernel log with 0xff characters at several thousand lines per second. > > Seen on a BCM4366 after a firmware trap followed by a fatal PCIe error > (FCP): the reset path and the failed dongle setup both entered the loop > and never reached device_release_driver(). > > Return early when the write index lies outside the console buffer. > > Found and written with the help of an AI coding assistant (Claude Opus > 5.5); the cover letter describes how. > > Fixes: 9e37f045d5e7 ("brcmfmac: Adding PCIe bus layer support.") > Cc: stable@vger.kernel.org > Signed-off-by: Soeren Coremans <sorencoremans@gmail.com> > --- > drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 8 ++++++++ > 1 file changed, 8 insertions(+) You may add my acknowledgement in v2. Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com> Regards, Arend ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH wireless-next 2/3] wifi: brcmfmac: pcie: bound memdump to the mapped TCM window 2026-11-05 21:59 [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans 2026-11-05 21:59 ` [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index Soeren Coremans @ 2026-11-05 21:59 ` Soeren Coremans 2026-11-26 14:29 ` Arend van Spriel 2026-11-05 21:59 ` [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans 2026-11-26 14:29 ` [PATCH wireless-next 0/3] " Arend van Spriel 3 siblings, 1 reply; 8+ messages in thread From: Soeren Coremans @ 2026-11-05 21:59 UTC (permalink / raw) To: linux-wireless Cc: arend.vanspriel, brcm80211, brcm80211-dev-list.pdl, Soeren Coremans brcmf_chip_get_raminfo() reports "RAM size is incorrect" on a dead device but leaves the bogus value in ci->ramsize. A following brcmf_fw_crashed() then dumps that many bytes from the TCM mapping, which is only as large as BAR2, and faults in ioread32(): memdump 0x00200000+15728640 exceeds TCM window 0x800000 Remember the BAR2 size and refuse dumps that do not fit. Only builds with CONFIG_BRCMDBG create the memdump, so only they are affected. Found and written with the help of an AI coding assistant (Claude Opus 5.5); the cover letter describes how. Fixes: ff4445a8502c ("brcmfmac: expose device memory to devcoredump subsystem") Signed-off-by: Soeren Coremans <sorencoremans@gmail.com> --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 02c58de67b82..5abc85013110 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -343,6 +343,7 @@ struct brcmf_otp_params { struct brcmf_pciedev_info { enum brcmf_pcie_state state; + resource_size_t tcm_size; bool in_irq; struct pci_dev *pdev; char fw_name[BRCMF_FW_NAME_LEN]; @@ -1669,6 +1670,12 @@ static int brcmf_pcie_get_memdump(struct device *dev, void *data, size_t len) struct brcmf_pciedev_info *devinfo = buspub->devinfo; brcmf_dbg(PCIE, "dump at 0x%08X: len=%zu\n", devinfo->ci->rambase, len); + if (devinfo->ci->rambase > devinfo->tcm_size || + len > devinfo->tcm_size - devinfo->ci->rambase) { + brcmf_err(bus_if, "memdump 0x%08X+%zu exceeds TCM window %pa\n", + devinfo->ci->rambase, len, &devinfo->tcm_size); + return -EINVAL; + } brcmf_pcie_copy_dev_tomem(devinfo, devinfo->ci->rambase, data, len); return 0; } @@ -2145,6 +2152,7 @@ static int brcmf_pcie_get_resource(struct brcmf_pciedev_info *devinfo) devinfo->regs = ioremap(bar0_addr, BRCMF_PCIE_REG_MAP_SIZE); devinfo->tcm = ioremap(bar1_addr, bar1_size); + devinfo->tcm_size = bar1_size; if (!devinfo->regs || !devinfo->tcm) { brcmf_err(bus, "ioremap() failed (%p,%p)\n", devinfo->regs, -- 2.53.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH wireless-next 2/3] wifi: brcmfmac: pcie: bound memdump to the mapped TCM window 2026-11-05 21:59 ` [PATCH wireless-next 2/3] wifi: brcmfmac: pcie: bound memdump to the mapped TCM window Soeren Coremans @ 2026-11-26 14:29 ` Arend van Spriel 0 siblings, 0 replies; 8+ messages in thread From: Arend van Spriel @ 2026-11-26 14:29 UTC (permalink / raw) To: Soeren Coremans Cc: linux-wireless, arend.vanspriel, brcm80211, brcm80211-dev-list.pdl On Thu, 5 Nov 2026 22:59:53 +0100, Soeren Coremans <sorencoremans@gmail.com> wrote: > brcmf_chip_get_raminfo() reports "RAM size is incorrect" on a dead > device but leaves the bogus value in ci->ramsize. A following > brcmf_fw_crashed() then dumps that many bytes from the TCM mapping, > which is only as large as BAR2, and faults in ioread32(): > > memdump 0x00200000+15728640 exceeds TCM window 0x800000 > > Remember the BAR2 size and refuse dumps that do not fit. Only builds > with CONFIG_BRCMDBG create the memdump, so only they are affected. > > Found and written with the help of an AI coding assistant (Claude Opus > 5.5); the cover letter describes how. > > Fixes: ff4445a8502c ("brcmfmac: expose device memory to devcoredump subsystem") > Signed-off-by: Soeren Coremans <sorencoremans@gmail.com> > --- > drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 8 ++++++++ > 1 file changed, 8 insertions(+) [...] > @@ -1669,6 +1670,12 @@ static int brcmf_pcie_get_memdump(struct device *dev, void *data, size_t len) > struct brcmf_pciedev_info *devinfo = buspub->devinfo; > > brcmf_dbg(PCIE, "dump at 0x%08X: len=%zu\n", devinfo->ci->rambase, len); > + if (devinfo->ci->rambase > devinfo->tcm_size || > + len > devinfo->tcm_size - devinfo->ci->rambase) { > + brcmf_err(bus_if, "memdump 0x%08X+%zu exceeds TCM window %pa\n", > + devinfo->ci->rambase, len, &devinfo->tcm_size); > + return -EINVAL; > + } > brcmf_pcie_copy_dev_tomem(devinfo, devinfo->ci->rambase, data, len); > return 0; > } The bogus size is left in ci->ramsize because brcmf_chip_get_raminfo() does not clear it when it returns -EINVAL for "RAM size is incorrect". Clearing it there would fix the source for every get_ramsize() user. The check here is fine as a safeguard though. You may add my acknowledgement in v2. Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com> Regards, Arend ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors 2026-11-05 21:59 [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans 2026-11-05 21:59 ` [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index Soeren Coremans 2026-11-05 21:59 ` [PATCH wireless-next 2/3] wifi: brcmfmac: pcie: bound memdump to the mapped TCM window Soeren Coremans @ 2026-11-05 21:59 ` Soeren Coremans 2026-11-26 14:29 ` Arend van Spriel 2026-11-26 14:29 ` [PATCH wireless-next 0/3] " Arend van Spriel 3 siblings, 1 reply; 8+ messages in thread From: Soeren Coremans @ 2026-11-05 21:59 UTC (permalink / raw) To: linux-wireless Cc: arend.vanspriel, brcm80211, brcm80211-dev-list.pdl, Soeren Coremans brcmfmac registers no pci_error_handlers, so a fatal AER error leaves the device dead until reboot ("AER: can't recover (no error_detected callback)"). On a BCM4366 this happens after some firmware traps: the trap starts a driver reset, and about 0.7 s later the downstream port reports an FCP error. Add error handlers: - error_detected: mark the bus down, block the driver's own reset work and request a link reset. - slot_reset: restore the config space saved at probe, then check that the backplane answers; a wedged card would stall the CPU on every MMIO read during firmware download. - resume: re-probe the device from a work item. The link reset returns the chip to its power-on state, which brcmf_pcie_reset() does not fully re-initialise: after it, association failed in 5 of 9 runs, while 16 of 16 re-probes recovered. A dongle setup that fails while recovery is in progress no longer releases the driver, as that would race with the re-probe. Tested with aer_inject (FCP on the downstream port), alone and 0.3 s after a debugfs-triggered reset: WiFi back within 6-12 s in 16 of 16 runs, on a BCM4366/4 (14e4:43c3) with a kernel built from the Ubuntu 7.0.0-42 source, which is based on v7.0.14. Also tested against real FCP errors, without injection: resets under WiFi traffic caused 3 in 47 runs, and all 3 recovered within 4-11 s. This relies on the console read fix earlier in this series: without it, a reset that is already running on the dead device never finishes, and error_detected() waits for it forever. Found and written with the help of an AI coding assistant (Claude Opus 5.5); the cover letter describes how. Signed-off-by: Soeren Coremans <sorencoremans@gmail.com> --- .../broadcom/brcm80211/brcmfmac/pcie.c | 128 +++++++++++++++++- 1 file changed, 127 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c index 5abc85013110..9c23e5b83b73 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c @@ -344,6 +344,7 @@ struct brcmf_otp_params { struct brcmf_pciedev_info { enum brcmf_pcie_state state; resource_size_t tcm_size; + bool in_pci_recovery; bool in_irq; struct pci_dev *pdev; char fw_name[BRCMF_FW_NAME_LEN]; @@ -2137,6 +2138,7 @@ static int brcmf_pcie_get_resource(struct brcmf_pciedev_info *devinfo) } pci_set_master(pdev); + pci_save_state(pdev); /* Bar-0 mapped address */ bar0_addr = pci_resource_start(pdev, 0); @@ -2598,6 +2600,11 @@ static void brcmf_pcie_setup(struct device *dev, int ret, fail: brcmf_err(bus, "Dongle setup failed\n"); + /* PCIe error recovery is in progress and re-probes the device once + * the link is back; releasing the driver here would race with it. + */ + if (READ_ONCE(devinfo->in_pci_recovery)) + return; brcmf_pcie_bus_console_read(devinfo, true); brcmf_fw_crashed(dev); device_release_driver(dev); @@ -3153,11 +3160,117 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = { MODULE_DEVICE_TABLE(pci, brcmf_pcie_devid_table); +static pci_ers_result_t brcmf_pcie_error_detected(struct pci_dev *pdev, + pci_channel_state_t state) +{ + struct brcmf_bus *bus = dev_get_drvdata(&pdev->dev); + struct brcmf_pciedev_info *devinfo; + + if (!bus) + return PCI_ERS_RESULT_DISCONNECT; + if (state == pci_channel_io_perm_failure) + return PCI_ERS_RESULT_DISCONNECT; + if (state == pci_channel_io_normal) + return PCI_ERS_RESULT_CAN_RECOVER; + + devinfo = bus->bus_priv.pcie->devinfo; + brcmf_err(bus, "PCIe link frozen, resetting\n"); + WRITE_ONCE(devinfo->in_pci_recovery, true); + devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; + brcmf_bus_cancel_reset_work(bus); + + return PCI_ERS_RESULT_NEED_RESET; +} + +static pci_ers_result_t brcmf_pcie_slot_reset(struct pci_dev *pdev) +{ + struct brcmf_bus *bus = dev_get_drvdata(&pdev->dev); + struct brcmf_pciedev_info *devinfo; + u16 vendor; + + if (!bus) + return PCI_ERS_RESULT_DISCONNECT; + devinfo = bus->bus_priv.pcie->devinfo; + + pci_restore_state(pdev); + pci_save_state(pdev); + pci_set_master(pdev); + + pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor); + if (vendor != pdev->vendor) + return PCI_ERS_RESULT_DISCONNECT; + + /* Config space can answer while the backplane is wedged; reloading + * firmware into such a card stalls the CPU on every MMIO read. + */ + if (devinfo->ci) { + u32 chipid; + + brcmf_pcie_select_core(devinfo, BCMA_CORE_CHIPCOMMON); + chipid = READCC32(devinfo, chipid); + brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2); + if (chipid == 0xffffffff) { + brcmf_err(bus, "card not responding after link reset\n"); + return PCI_ERS_RESULT_DISCONNECT; + } + } + + return PCI_ERS_RESULT_RECOVERED; +} + +static struct workqueue_struct *brcmf_pcie_err_wq; + +struct brcmf_pcie_reprobe { + struct work_struct work; + struct pci_dev *pdev; +}; + +static void brcmf_pcie_reprobe_worker(struct work_struct *work) +{ + struct brcmf_pcie_reprobe *rp = + container_of(work, struct brcmf_pcie_reprobe, work); + int err; + + err = device_reprobe(&rp->pdev->dev); + if (err) + pci_err(rp->pdev, "re-probe after PCIe error failed: %d\n", err); + pci_dev_put(rp->pdev); + kfree(rp); +} + +/* A link reset returns the chip to its power-on state, which only a full + * probe initialises correctly. The re-probe frees all driver data, so it + * runs from a work item that holds nothing but the PCI device. + */ +static void brcmf_pcie_resume_from_error(struct pci_dev *pdev) +{ + struct brcmf_bus *bus = dev_get_drvdata(&pdev->dev); + struct brcmf_pcie_reprobe *rp; + + if (!bus || !READ_ONCE(bus->bus_priv.pcie->devinfo->in_pci_recovery)) + return; + + rp = kzalloc_obj(*rp); + if (!rp) + return; + brcmf_err(bus, "PCIe link recovered, re-probing\n"); + INIT_WORK(&rp->work, brcmf_pcie_reprobe_worker); + rp->pdev = pci_dev_get(pdev); + queue_work(brcmf_pcie_err_wq, &rp->work); +} + +static const struct pci_error_handlers brcmf_pcie_err_handler = { + .error_detected = brcmf_pcie_error_detected, + .slot_reset = brcmf_pcie_slot_reset, + .resume = brcmf_pcie_resume_from_error, +}; + static struct pci_driver brcmf_pciedrvr = { .name = KBUILD_MODNAME, .id_table = brcmf_pcie_devid_table, .probe = brcmf_pcie_probe, .remove = brcmf_pcie_remove, + .err_handler = &brcmf_pcie_err_handler, #ifdef CONFIG_PM .driver.pm = &brcmf_pciedrvr_pm, #endif @@ -3167,8 +3280,17 @@ static struct pci_driver brcmf_pciedrvr = { int brcmf_pcie_register(void) { + int err; + brcmf_dbg(PCIE, "Enter\n"); - return pci_register_driver(&brcmf_pciedrvr); + brcmf_pcie_err_wq = alloc_workqueue("brcmf_pcie_err", 0, 0); + if (!brcmf_pcie_err_wq) + return -ENOMEM; + + err = pci_register_driver(&brcmf_pciedrvr); + if (err) + destroy_workqueue(brcmf_pcie_err_wq); + return err; } @@ -3176,4 +3298,8 @@ void brcmf_pcie_exit(void) { brcmf_dbg(PCIE, "Enter\n"); pci_unregister_driver(&brcmf_pciedrvr); + /* Unregistered first so no new re-probe can be queued; this drains + * a pending one before the module text goes away. + */ + destroy_workqueue(brcmf_pcie_err_wq); } -- 2.53.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors 2026-11-05 21:59 ` [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans @ 2026-11-26 14:29 ` Arend van Spriel 0 siblings, 0 replies; 8+ messages in thread From: Arend van Spriel @ 2026-11-26 14:29 UTC (permalink / raw) To: Soeren Coremans Cc: linux-wireless, arend.vanspriel, brcm80211, brcm80211-dev-list.pdl On Thu, 5 Nov 2026 22:59:54 +0100, Soeren Coremans <sorencoremans@gmail.com> wrote: > brcmfmac registers no pci_error_handlers, so a fatal AER error leaves > the device dead until reboot ("AER: can't recover (no error_detected > callback)"). On a BCM4366 this happens after some firmware traps: the > trap starts a driver reset, and about 0.7 s later the downstream port > reports an FCP error. > > Add error handlers: > > - error_detected: mark the bus down, block the driver's own reset work > and request a link reset. > - slot_reset: restore the config space saved at probe, then check that > the backplane answers; a wedged card would stall the CPU on every > MMIO read during firmware download. > - resume: re-probe the device from a work item. The link reset returns > the chip to its power-on state, which brcmf_pcie_reset() does not > fully re-initialise: after it, association failed in 5 of 9 runs, > while 16 of 16 re-probes recovered. > > A dongle setup that fails while recovery is in progress no longer > releases the driver, as that would race with the re-probe. > > Tested with aer_inject (FCP on the downstream port), alone and 0.3 s > after a debugfs-triggered reset: WiFi back within 6-12 s in 16 of 16 > runs, on a BCM4366/4 (14e4:43c3) with a kernel built from the > Ubuntu 7.0.0-42 source, which is based on v7.0.14. > > Also tested against real FCP errors, without injection: resets under WiFi > traffic caused 3 in 47 runs, and all 3 recovered within 4-11 s. > > This relies on the console read fix earlier in this series: without it, > a reset that is already running on the dead device never finishes, and > error_detected() waits for it forever. > > Found and written with the help of an AI coding assistant (Claude Opus > 5.5); the cover letter describes how. > > Signed-off-by: Soeren Coremans <sorencoremans@gmail.com> > --- > .../broadcom/brcm80211/brcmfmac/pcie.c | 128 +++++++++++++++++- > 1 file changed, 127 insertions(+), 1 deletion(-) [...] > @@ -3153,11 +3160,117 @@ static const struct pci_device_id brcmf_pcie_devid_table[] = { > MODULE_DEVICE_TABLE(pci, brcmf_pcie_devid_table); > > > +static pci_ers_result_t brcmf_pcie_error_detected(struct pci_dev *pdev, > + pci_channel_state_t state) > +{ > + struct brcmf_bus *bus = dev_get_drvdata(&pdev->dev); > + struct brcmf_pciedev_info *devinfo; > + > + if (!bus) > + return PCI_ERS_RESULT_DISCONNECT; > + if (state == pci_channel_io_perm_failure) > + return PCI_ERS_RESULT_DISCONNECT; > + if (state == pci_channel_io_normal) > + return PCI_ERS_RESULT_CAN_RECOVER; > + > + devinfo = bus->bus_priv.pcie->devinfo; > + brcmf_err(bus, "PCIe link frozen, resetting\n"); > + WRITE_ONCE(devinfo->in_pci_recovery, true); > + devinfo->state = BRCMFMAC_PCIE_STATE_DOWN; > + brcmf_bus_cancel_reset_work(bus); > + > + return PCI_ERS_RESULT_NEED_RESET; > +} This only drains the bus reset work. The firmware callback brcmf_pcie_setup() queued by brcmf_pcie_reset() runs from the firmware loader and nothing here waits for it. It can be in flight, e.g. polling for firmware init in brcmf_pcie_download_fw_nvram(), or not have started yet. It then uses the BAR0 window concurrently with slot_reset(), and the re-probe can free devinfo and bus underneath it. Please make sure that callback has finished (or cannot start) before the link is reset and the device re-probed. Also, the setup failure path only tests in_pci_recovery before calling device_release_driver(). If error_detected() runs after that test, the device gets released between error_detected() and slot_reset(), which then finds no drvdata and gives up. [...] > +static struct workqueue_struct *brcmf_pcie_err_wq; > + > +struct brcmf_pcie_reprobe { > + struct work_struct work; > + struct pci_dev *pdev; > +}; > + > +static void brcmf_pcie_reprobe_worker(struct work_struct *work) > +{ > + struct brcmf_pcie_reprobe *rp = > + container_of(work, struct brcmf_pcie_reprobe, work); > + int err; > + > + err = device_reprobe(&rp->pdev->dev); > + if (err) > + pci_err(rp->pdev, "re-probe after PCIe error failed: %d\n", err); > + pci_dev_put(rp->pdev); > + kfree(rp); > +} > + > +/* A link reset returns the chip to its power-on state, which only a full > + * probe initialises correctly. The re-probe frees all driver data, so it > + * runs from a work item that holds nothing but the PCI device. > + */ > +static void brcmf_pcie_resume_from_error(struct pci_dev *pdev) > +{ > + struct brcmf_bus *bus = dev_get_drvdata(&pdev->dev); > + struct brcmf_pcie_reprobe *rp; > + > + if (!bus || !READ_ONCE(bus->bus_priv.pcie->devinfo->in_pci_recovery)) > + return; > + > + rp = kzalloc_obj(*rp); > + if (!rp) > + return; > + brcmf_err(bus, "PCIe link recovered, re-probing\n"); > + INIT_WORK(&rp->work, brcmf_pcie_reprobe_worker); > + rp->pdev = pci_dev_get(pdev); > + queue_work(brcmf_pcie_err_wq, &rp->work); > +} > + If recovery is abandoned (slot_reset() returns DISCONNECT, or the allocation above fails) in_pci_recovery stays set, so later dongle setup failures are ignored without releasing the driver, and the allocation failure is not even logged. brcmf_pcie_pm_leave_D3() already calls brcmf_pcie_remove() and brcmf_pcie_probe() directly from a callback that runs under the device lock. Is there a reason resume() cannot do the same instead of using a work item, a dedicated workqueue and device_reprobe()? The series "wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips" (https://patchwork.kernel.org/series/1208304/) changes the same code. Its last patch adds deep sleep state handling to brcmf_pcie_remove() and hooks on the ring lock that wake the device. A re-probe after a link reset runs that remove path on a device that does not answer, and error_detected() only sets devinfo->state to DOWN and leaves the deep sleep state alone. The series also adds its own re-probe after a resume through platform firmware. Please check recovery with that series applied, and make sure an error during resume cannot start both re-probes. Whichever series is applied second will need a rebase. The commit message says brcmf_pcie_reset() is not enough after a link reset and the cover letter leaves the cause open. I would like to know which part of the probe-time setup is missing before settling on a full re-probe. The pci_err() line in brcmf_pcie_reprobe_worker() and the brcmf_err() line in brcmf_pcie_slot_reset() are 81 columns, see the checkpatch warning. Regards, Arend ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors 2026-11-05 21:59 [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans ` (2 preceding siblings ...) 2026-11-05 21:59 ` [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans @ 2026-11-26 14:29 ` Arend van Spriel 3 siblings, 0 replies; 8+ messages in thread From: Arend van Spriel @ 2026-11-26 14:29 UTC (permalink / raw) To: Soeren Coremans Cc: linux-wireless, arend.vanspriel, brcm80211, brcm80211-dev-list.pdl On Thu, 5 Nov 2026 22:59:51 +0100, Soeren Coremans <sorencoremans@gmail.com> wrote: > Open points > ----------- [...] > 3. brcmf_pcie_reset() and brcmf_pcie_remove() free the DMA rings before > brcmf_pcie_reset_device() stops the chip. In one of those unloads, the > device wrote into freed buffers first (8 AMD-Vi IO_PAGE_FAULTs). The > other real errors showed no such faults, so this looks separate. This > series does not touch the order; you may know whether it is deliberate. I see no reason for that order. Freeing the DMA memory while the chip may still be running looks wrong. A separate patch that stops the chip before the buffers are released, in both brcmf_pcie_reset() and brcmf_pcie_remove(), would be welcome. Regards, Arend ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-26 14:29 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-05 21:59 [PATCH wireless-next 0/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans 2026-11-05 21:59 ` [PATCH wireless-next 1/3] wifi: brcmfmac: pcie: stop console read on invalid write index Soeren Coremans 2026-11-26 14:29 ` Arend van Spriel 2026-11-05 21:59 ` [PATCH wireless-next 2/3] wifi: brcmfmac: pcie: bound memdump to the mapped TCM window Soeren Coremans 2026-11-26 14:29 ` Arend van Spriel 2026-11-05 21:59 ` [PATCH wireless-next 3/3] wifi: brcmfmac: pcie: recover from fatal PCIe errors Soeren Coremans 2026-11-26 14:29 ` Arend van Spriel 2026-11-26 14:29 ` [PATCH wireless-next 0/3] " Arend van Spriel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox