Skip to content

apple: rebind brcmfmac across suspend - #12314

Open
teomurgi wants to merge 1 commit into
omacom:quattrofrom
teomurgi:fix-brcmfmac-suspend
Open

teomurgi wants to merge 1 commit into
omacom:quattrofrom
teomurgi:fix-brcmfmac-suspend

Conversation

@teomurgi

Copy link
Copy Markdown

Problem

On Macs whose Wi-Fi is driven by brcmfmac (BCM4350 and relatives), a long suspend wedges the Broadcom firmware. After wake the kernel logs brcmf_msgbuf_query_dcmd: Timeout on response for query command for every request, NetworkManager sees do-change-link: failure 5 (Input/output error), and the interface never recovers — only a reboot brings Wi-Fi back. Short suspends (seconds) resume fine; the failure shows up after hours asleep.

Observed on a MacBook10,1 (BCM4350, 14e4:43a3): suspended 16:53, resumed 19:55, firmware dead from the first msgbuf command after wake.

Fix

A systemd/system-sleep hook unbinds the Wi-Fi PCI device from brcmfmac before sleep and rebinds it after wake, forcing a clean firmware reload. NetworkManager then sees a fresh interface and reconnects on its own (~seconds after wake). Devices unbound at pre are recorded under /run and only those are rebound at post; a post with no matching pre is a no-op.

Gating

Mirrors fix-brcmfmac-supplicant.sh: T2 Macs via the T2 PCI ID, older Macs via the brcmfmac PCI IDs from brcm_hw_ids.h. Hardware brcmfmac doesn't drive is left alone.

Rollout

  • New installs: install/hardware/apple/fix-brcmfmac-suspend.sh runs from install/hardware/all.sh.
  • Existing installs: migration installs the hook. No reboot needed — systemd-sleep runs every executable in system-sleep on the next suspend. Idempotent: an identical hook is left untouched, a locally modified one is refreshed.

Tests

test/shell.d/brcmfmac-suspend-test.sh (13 assertions): hardware gating for the leaf and migration, idempotency, refresh of a modified hook, and the hook's own pre/post/no-op behavior against a stub sysfs. brcmfmac-supplicant-test.sh and system-sleep-ownership-migration-test.sh still pass.

The Broadcom Wi-Fi firmware on Macs driven by brcmfmac (BCM4350 and
relatives) does not reliably survive a long suspend: after wake it stops
answering msgbuf commands, the kernel logs 'Timeout on response for
query command' for every request, and the interface never recovers --
only a reboot brings Wi-Fi back.

A system-sleep hook now unbinds the device before sleep and rebinds it
after wake, forcing a clean firmware reload. NetworkManager sees a fresh
interface and reconnects on its own.

Gated like the WPA-handshake quirk: T2 Macs by the T2 PCI ID, older
Macs by the brcmfmac PCI IDs from brcm_hw_ids.h. A migration installs
the hook on existing installs; no reboot is needed because systemd-sleep
runs every executable in system-sleep on the next suspend.
@teomurgi
teomurgi changed the base branch from dev to quattro September 17, 2026 18:44
@sprajs

sprajs commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Related: #11434 is still open and targets the same brcmfmac firmware timeout on these Apple/Broadcom devices. The lifecycle differs: that PR unbinds/rebinds through a post-resume service, while this one unbinds before sleep and records which devices to rebind afterward.

These look like alternative fixes to coordinate before landing both migrations. A long-suspend test on the BCM4350 case here and the BCM43602 case in #11434 would help establish which lifecycle covers both reports.

@teomurgi

Copy link
Copy Markdown
Author

Agreed these shouldn't both land — but I think the lifecycle difference settles it rather than test coverage alone. Unbinding pre-sleep means the firmware never executes its S3 suspend/resume path at all: the wedge is avoided, not recovered from. The post-resume service in #11434 still lets the firmware suspend normally and bets the rebind heals it afterward — which is exactly the assumption that fails in the long-suspend case here.

The hardware gate and device table are identical in both PRs, so this hook should cover the BCM43602 population as-is. @TheoAndersen — could you try the system-sleep hook from this PR on your MacBookPro11,5 instead of the resume service? Your lid-close repro is quick to run. If it fixes your case, I'd propose closing #11434 in favor of this one.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 84e001d85936f8f15b5a65bd41f90e4f8ca29984 against quattro, by Claude Opus 5.5 with a second opinion from Codex Medium.

Tests. On a disposable Omarchy worker: ./test/cli passed, and brcmfmac-suspend-test.sh (13), brcmfmac-supplicant-test.sh (13) and system-sleep-ownership-migration-test.sh (23) all passed. A worker has no Broadcom Wi-Fi, so those tests show the hook and migration install and act on a stub sysfs. They cannot show that a rebind brings the firmware back after a long suspend; only a Mac can.

Against #10332. That is the other open fix for this bug. This one is the better of the two, and both reviewers reached that conclusion. Codex was given both diffs without my answer, but it can read this session, so its agreement is not guaranteed to be independent. In #10332, the pre-sleep modprobe -r brcmfmac fails silently when NetworkManager still holds the module (2>/dev/null and exit 0), so post reloads nothing; that is the failure reported on a MacBookPro11,5 in that thread. Sysfs unbind does not depend on the module's reference count. #10332 also has no migration, so existing installs never get it, and it leaves out the BCM4350 (14e4:43a3) this PR was reported on.

What still stands, for the maintainer:

  • default/systemd/system-sleep/rebind-brcmfmac:20: unbind still runs brcmf_pcie_remove → brcmf_detach, the same teardown that hit a general protection fault in _cfg80211_unregister_wdev in Fix Wi-Fi dying after suspend on BCM43602 MacBooks #10332's thread when the firmware was already timing out before sleep. This PR shares that exposure with Fix Wi-Fi dying after suspend on BCM43602 MacBooks #10332; it does not avoid it.
  • default/systemd/system-sleep/rebind-brcmfmac:26: if bind fails after wake, the error is discarded and the state file deleted, so the device stays unbound and nothing retries it. Wi-Fi is down either way in that case, but nothing in the log says why.
  • install/hardware/apple/fix-brcmfmac-suspend.sh:11: the gate copies fix-brcmfmac-supplicant.sh exactly, so every T2 Mac (BCM4364/4377/4378/4387) gets the hook too. The reports so far are BCM43602 and BCM4350. Whether the T2 chips need it is the maintainer's call.

Not yet verified. This is a hardware bug, so it is verified by someone who has it, on this exact commit. @hanscnelson (MacBookPro14,2), @makoni (MacBookPro14,3) and @rand0mdud3 (MacBookPro11,5) reported this signature on #10332. If any of you can run this hook through a long suspend, that is the confirmation this PR waits on. Remove #10332's /usr/lib/systemd/system-sleep/brcmfmac-suspend.sh first if you installed it, then install this one:

curl -fsSL https://raw.githubusercontent.com/teomurgi/omarchy/84e001d85936f8f15b5a65bd41f90e4f8ca29984/default/systemd/system-sleep/rebind-brcmfmac | sudo install -Dm 0755 /dev/stdin /usr/lib/systemd/system-sleep/rebind-brcmfmac

After a suspend of an hour or more, please report the machine model, whether Wi-Fi reconnected on its own, and what journalctl -k -b | grep -c 'Timeout on response for query command' prints (it should be 0). A confirmation from the PR author does not count here.

Next: this waits on that confirmation, and then on the maintainer to choose between this PR and #10332.

@jandrusk

Copy link
Copy Markdown

Looks solid — pre-sleep unbind is a cleaner lifecycle than post-resume reload (#11434, now closed), and the PCI-ID gate + migration for existing installs are the right shape.

Overlaps the broader Apple suspend cluster (#9830, #7180, #11377). If maintainers want one brcmfmac path, this seems the stronger candidate for the wedge-after-long-suspend case. Happy for a maintainer pass.

@omarchybot

Copy link
Copy Markdown
Collaborator

Checked again at 84e001d85936f8f15b5a65bd41f90e4f8ca29984 against quattro by Claude Opus 5.5, with Codex Medium as a second opinion. The code has not changed since my last comment, so nothing was rerun on a worker. Two things around it have changed, and they change my earlier conclusion.

Please don't install this hook on a stock Omarchy kernel yet. My last comment asked owners of affected Macs to try it. Since then, @makoni traced a kernel oops on #7333 to a P2P interface removal race in brcmfmac's own teardown. It is fixed upstream by "wifi: brcmfmac: fix P2P device removal race in brcmf_detach()" (08a3f02fea63), which is in mainline as of v7.3-rc7 but not in linux-7.2.y or in the linux-omarchy Omarchy ships. The unbind at default/systemd/system-sleep/rebind-brcmfmac:20 runs brcmf_pcie_remove → brcmf_detach, the same path. Unbinding before sleep avoids the firmware's suspend path, but it does not avoid this race. On today's kernel, the hook can oops the machine on the way into suspend and leave it needing a hard power-off, which is worse than Wi-Fi staying dead until a reboot. This blocks every fix in this group equally.

Which fix to carry forward. There are now four open fixes for this bug: #7180 (draft), #7333, #10332 and this one. I compared them again, and Codex was given all four diffs separately, without my answer. Both chose #7333. It is older than this PR, it covers BCM4350 and BCM43602, it reaches existing installs, and it records the device before unbinding. Codex can read this session, so its agreement is not guaranteed to be independent. Compared with #10332, this PR is still better: it uses sysfs unbind instead of modprobe -r, and it has a migration. Neither reviewer found anything here that #7333 lacks and should take over.

Still open at this head, beyond the kernel race. Codex raised the first two, and I checked both against the diff:

  • rebind-brcmfmac:14 checks only $1, so the hook also unbinds on s2idle, hibernate and suspend-then-hibernate. The dead-firmware failure has only been reported after S3, and the oops on Reset Apple BCM4350/BCM43602 Wi-Fi around sleep #7333 happened on s2idle.
  • rebind-brcmfmac:17 unbinds every brcmfmac device in PCI domain 0000, with no chip check of its own. The gate in install/hardware/apple/fix-brcmfmac-suspend.sh:11 and migrations/1789668939.sh:12 installs the hook on any machine with the T2 controller (106b:1801/1802). That includes BCM4364/4377/4378/4387, which nobody has reported this failure on.
  • rebind-brcmfmac:26: if bind fails after wake, the error is discarded and the state file deleted, so nothing ever retries the device.

Since this one is not the fix to carry forward, it was not run on a worker again. The earlier run at this commit (./test/cli and the three brcmfmac and system-sleep test files) still stands.

What it waits on: the maintainer, who chooses among #7180, #7333, #10332 and this PR. Whichever is chosen, it also needs a linux-omarchy that carries the brcmfmac fix before it is safe to enable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants