Skip to content

wifi: brcmfmac: pcie: reset the chip when the firmware dies - #1729

Merged
RyanTheTide merged 4 commits into
integration/aurorafrom
brcmrecov/pcie-fw-trap-recovery
Nov 13, 2026
Merged

RyanTheTide merged 4 commits into
integration/aurorafrom
brcmrecov/pcie-fw-trap-recovery

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

brcmfmac on PCIe only notices a dead firmware when the firmware sends a halt notice (D2H FWHALT). The BCM4387 firmware on the M1 Pro can trap without sending one: it starts a fatal-error reinit after a stuck TX FIFO, traps inside it, and the trap only shows up in its console ring. After that every control request times out ("Timeout on response for query command", then "Failed to reserve space in commonring") and Wi-Fi is gone until reboot. #1722 removed the trigger we know about. This PR covers whatever is left: the driver now notices a dead dongle and resets it.

What changes

  • msgbuf counts stalled control requests: a response timeout, or a control submit ring with no room. A completed request clears the count. Each stall calls a new optional bus hook, ctl_stall.
  • On PCIe, ctl_stall checks the dongle:
    • shared RAM reads back all ones: the device is gone;
    • the shared flags carry the trap bit (the trap type and pc get logged) or the assert bit (the same bits the SDIO bus already decodes);
    • the console printed a line starting with TRAP since the last check;
    • 3 stalls in a row with none of the above.
  • Any of these logs firmware died (<reason>), resetting the chip, marks the bus down so later commands fail at once instead of waiting 2 s each, and runs the existing crash path: brcmf_fw_crashed() takes a devcoredump and schedules the bus reset that the debugfs reset entry uses. The FWHALT notice takes the same path. After 5 resets in 10 minutes the driver stops resetting and says so.
  • Fixes to the reset path so it is safe on a live device:
    • the dongle is stopped before brcmf_detach() frees its host buffers, as remove already does, so running firmware can't DMA into unmapped RX buffers;
    • the bus is marked down and the interrupt thread is synced first, and a control request already waiting for its response (FWHALT or debugfs reset) gets to finish before the rings are freed;
    • the flowring array is freed before setup allocates a new one.
  • cfg80211: wiphy_unregister() freed wiphy.wowlan_config but left the pointer set. brcmfmac registers the same wiphy again after a reset, so the next NL80211_CMD_SET_WOWLAN freed the old config a second time and oopsed in cfg80211_rdev_free_wowlan(). That function now clears the pointer.
  • The reset work runs on system_freezable_wq, so a reset armed while devices suspend waits for resume instead of racing it.

Tests

  • tools/asahi/brcmf-recovery-tests.py (new, in run-host-tests): runs the production brcmf_pcie_ctl_stall(), brcmf_pcie_console_trapped(), brcmf_pcie_fw_died() and brcmf_msgbuf_query_dcmd_len() against a fake dongle RAM and console. 14 controls pass, and each of the 8 mutations (one per check) makes it fail. brcmf-assoc-tests.py stubs the new field and hook. The brcmf host tests pass 44/44 on the buildbox.
  • Hardware: M1 Pro (J316s, BCM4387 firmware 20.131.4) and M2 (BCM4387 firmware 20.140.13). One-shot kernel = integration 028d762 + this branch + a test-only debugfs/module-param knob that is not part of this PR. The knob kills the dongle in four ways: a firmware trap requested through the H2D mailbox with the halt notice ignored, a silent halt of the dongle CPU, a trap with the shared flags ignored (console marker only), and a trap with the halt notice handled. 10 kills per Mac, spaced about 2 minutes apart, WoWLAN magic enabled:
M1 Pro M2
recovered to a working association and the gateway 10/10 10/10
trap flag path: detect / gateway (s) 2.5–6.6 / 8.1–12.2 2.6–7.1 / 8.1–12.7
console marker path: detect / gateway (s) 3.1–7.7 / 8.7–13.3 3.6–6.1 / 9.1–11.7
silent halt (3 stalled requests): detect / gateway (s) 15.3–18.5 / 20.9–24.1 14.3–16.4 / 19.8–21.9
s2idle on the recovered driver 20/20, 0 ioctl timeouts 20/20, 0 ioctl timeouts
DART faults, AVCs, oops/WARN, failed units 0 0

The firmware sent no FWHALT notice for any of these traps, including the run that handled it, so without this change every one of them would have ended with Wi-Fi gone until reboot. A reset takes about 1.7 s from detection to the reloaded firmware. Bluetooth (hci0, same chip) stayed up throughout. Before the cfg80211 fix, the first reset on the M1 Pro oopsed when userspace set WoWLAN on the re-registered wiphy.

When the dongle firmware traps, brcmfmac only notices if the firmware
sends a halt notice (D2H FWHALT). BCM4387 firmware on Apple machines
can trap without one: after a stuck TX FIFO it starts a fatal-error
reinit, traps inside it, and records the trap only in its console ring.
From then on every control request times out ("Timeout on response for
query command", then "Failed to reserve space in commonring" once the
control ring fills) and Wi-Fi stays dead until reboot.

Check the dongle whenever a control request stalls, meaning it timed out
or the control submit ring had no room:

 - shared RAM reads back all ones: the device is gone;
 - the shared flags carry the trap or assert bit (the same bits the SDIO
   bus already decodes);
 - the console printed a line starting with "TRAP " since the last
   check;
 - BRCMF_PCIE_CTL_STALL_MAX (3) requests in a row stalled.

On any of these, log the reason, stop issuing firmware commands and run
the existing crash path: brcmf_fw_crashed() takes a coredump and
schedules the bus reset that the debugfs "reset" entry uses. That
reloads the firmware and registers the interfaces again. The FWHALT
notice now takes the same path. A firmware that dies more than
BRCMF_PCIE_RECOVERY_MAX (5) times in 10 minutes is left alone.

The reset path needs three fixes to run on a live device:

 - stop the dongle before brcmf_detach() frees its host buffers, as
   remove already does; running firmware otherwise DMAs into RX buffers
   that are being unmapped, which faults in the IOMMU;
 - mark the bus down and wait for the interrupt thread first;
 - free the flowring array before setup allocates a new one.

The reset work now runs on the freezable workqueue, so a reset armed
while devices suspend waits until resume instead of racing it.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
brcmf-recovery-tests.py runs the production brcmf_pcie_ctl_stall(),
brcmf_pcie_console_trapped(), brcmf_pcie_fw_died() and
brcmf_msgbuf_query_dcmd_len() against a fake dongle RAM and console:
stall limit, trap and assert flags, a device reading all ones, the
console marker (line start only, across the ring end and across two
scans, text from before the scan start ignored), one reset per firmware
instance, the reset limit per window, and the stall count kept by
msgbuf. Eight mutations, one per check, must fail it.

brcmf-assoc-tests.py stubs the new msgbuf field and bus hook.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
A reset that starts from the FWHALT notice or the debugfs entry can find
a control request still waiting for its response in msgbuf, and
brcmf_detach() then frees the rings and the wait queue under it. Mark
the bus down first, so new firmware commands fail at once, and take
proto_block once so a request in flight finishes before the rings go.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
wiphy_unregister() frees wiphy.wowlan_config but leaves the pointer
set. A driver that registers the same wiphy again, as brcmfmac does
when it resets a dead dongle, then has cfg80211 treat the freed config
as live: the next NL80211_CMD_SET_WOWLAN frees it a second time and
walks its freed pattern array.

  Unable to handle kernel paging request at virtual address 00000000030210f0
  pc : cfg80211_rdev_free_wowlan+0x38/0xb8 [cfg80211]
  lr : nl80211_set_wowlan+0x584/0x678 [cfg80211]

Clear the pointer in cfg80211_rdev_free_wowlan(). The nl80211 callers
already overwrite it right after the call.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit 793358e into integration/aurora Nov 13, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the brcmrecov/pcie-fw-trap-recovery branch November 13, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant