Repository navigation
wifi: brcmfmac: pcie: reset the chip when the firmware dies - #1729
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ctl_stall.ctl_stallchecks the dongle:TRAPsince the last check;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 debugfsresetentry uses. The FWHALT notice takes the same path. After 5 resets in 10 minutes the driver stops resetting and says so.brcmf_detach()frees its host buffers, as remove already does, so running firmware can't DMA into unmapped RX buffers;wiphy_unregister()freedwiphy.wowlan_configbut left the pointer set. brcmfmac registers the same wiphy again after a reset, so the nextNL80211_CMD_SET_WOWLANfreed the old config a second time and oopsed incfg80211_rdev_free_wowlan(). That function now clears the pointer.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 productionbrcmf_pcie_ctl_stall(),brcmf_pcie_console_trapped(),brcmf_pcie_fw_died()andbrcmf_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.pystubs the new field and hook. Thebrcmfhost tests pass 44/44 on the buildbox.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.