Repository navigation
Fix Mac suspend loop after the first resume from sleep - #7589
marcindyguda wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a BCM43602 suspend workaround for affected Macs by cycling the brcmfmac PCI binding across sleep.
Changes:
- Adds and installs a brcmfmac system-sleep hook.
- Integrates installation into Apple hardware setup.
- Documents the new hook.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
install/hardware/apple/fix-brcmfmac-suspend.sh |
Detects BCM43602 hardware and installs the hook. |
install/hardware/all.sh |
Runs the new installer during hardware setup. |
default/systemd/system-sleep/brcmfmac-suspend |
Unbinds and rebinds brcmfmac across sleep. |
docs/file-layout.md |
Lists the new system-sleep hook. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| # Install a sleep hook that detaches the PCI device from brcmfmac before sleep | ||
| # and rebinds it on wake, forcing a clean firmware load. The T2 Macs from 2018 | ||
| # on are deliberately out of scope: their Wi-Fi sits on a different PCI bus. | ||
| if lspci -nn -s 03:00.0 | grep -q "14e4:43ba"; then |
There was a problem hiding this comment.
Added. The leaf now gates on the DMI vendor first ([[ $sys_vendor == Apple* ]]) exactly like fix-brcmfmac-supplicant.sh, so non-Apple BCM43602 systems are left alone. Also swapped grep -q for a full-read grep to avoid the #6608 pipefail/SIGPIPE false-negative pattern, and covered both cases in the new test file (test/shell.d/brcmfmac-suspend-test.sh), including non-Apple and wl-driven Mac hardware.
| bound() { | ||
| readlink "$pci/driver" 2>/dev/null | grep -q brcmfmac | ||
| } | ||
|
|
||
| if [[ -d $pci ]]; then | ||
| if [[ $1 == "pre" ]] && bound; then | ||
| echo "0000:03:00.0" > "$driver/unbind" | ||
| fi | ||
|
|
||
| if [[ $1 == "post" ]] && ! bound; then | ||
| # Bind again until the driver returns, or give up after 40 seconds. The | ||
| # kernel can re-enumerate the card itself through brcmfmac's rfkill, in | ||
| # which case the device races the loop back onto the bus and the retries | ||
| # all fail harmlessly. | ||
| for attempt in {1..20}; do | ||
| echo "0000:03:00.0" > "$driver/bind" 2>/dev/null | ||
| if bound; then | ||
| break | ||
| fi | ||
| (( attempt < 20 )) && sleep 2 | ||
| done | ||
| fi | ||
| fi |
There was a problem hiding this comment.
Fixed. pre now writes a marker (/run/omarchy-brcmfmac-suspend) only after a successful unbind, and post runs the bind loop only when the marker exists (removing it afterwards). A device that was already off or not driven by brcmfmac at 03:00.0 stays untouched, and an intentionally disabled Wi-Fi is not re-enabled. The new test exercises all four paths: bound pre, marker-gated post, non-brcmfmac device, and post without a prior unbind.
|
Automated duplication check: this pull request looks similar to #10332, which covers the same BCM43602 suspend hook. I keep that one open and close this one to consolidate review. If you feel this is the wrong decision, please open the PR again with a note on the difference. |
Problem
On Macs with Broadcom BCM43602 Wi-Fi driven by brcmfmac (MacBook Pro 2015–2017, MacBook 2016+, same-era iMacs), the firmware wedges on the first resume from S3:
brcmf_msgbuf_query_dcmdtimes out forever, and wpa_supplicant blocks in D state.From then on every suspend fails when
brcmf_pcie_pm_enter_D3returns-EIO(PM: failed to suspend async: error -5). systemd-logind retries the suspend every ~30 seconds indefinitely — 338 failed attempts were logged over a two-hour lid-closed window on the machine that motivated this change. Each retry powers the panel back up, so a closed laptop visibly "wakes" in a loop.rmmodcannot cleanly unloadbrcmfmac(its refcount never returns to zero while the driver is bound), so the reliable workaround is to detach the PCI device itself.Change
default/systemd/system-sleep/brcmfmac-suspend— sleep hook that unbinds0000:03:00.0frombrcmfmacinpreand rebinds it inpost(with a retry loop for the rfkill re-enumeration race), forcing a clean firmware load on every wake. It is a strict no-op unless it did the work itself:preonly acts when the device is bound tobrcmfmacand records the unbind in a/runmarker, andpostonly rebinds when that marker exists — an intentionally disabled Wi-Fi stays off.install/hardware/apple/fix-brcmfmac-suspend.sh— installs the hook at install time, gated on the DMI vendor (Apple*) andlspcifinding a BCM43602 (14e4:43ba) at03:00.0, mirroring the WPA-handshake quirk beside it. T2 Macs (2018+) are out of scope: their Wi-Fi sits on a different PCI bus.install/hardware/all.sh— runs the new leaf as part of hardware setup.docs/file-layout.md— documents the new hook.test/shell.d/brcmfmac-suspend-test.sh— new tests covering the installer gate (Apple/BCM43602, older Apple vendor string, non-Apple same part, wl-driven part, no Wi-Fi), the hook's executable bit, and all four hook paths (bound pre, marker-gated post, non-brcmfmac device, post without a prior unbind) against a sandbox sysfs.Verification
/sys/bus/pci/devices/0000:03:00.0/driver, post → device re-bound and NetworkManager reconnected within seconds)../test/allpasses except four pre-existing environment-dependent test files that also fail on a clean tree (config-test,snapper-test,unowned-system-paths-testneed the private omarchy-pkgs checkout;bar-icon-geometry-testfails in test rendering)./usr/lib/systemd/system-sleep, which is the recorded hardware-conditional-hooks exception inunowned-system-paths-test.Notes
force-igpuandkeyboard-backlighthooks.sudo cp -p /usr/share/omarchy/default/systemd/system-sleep/brcmfmac-suspend /usr/lib/systemd/system-sleep/ && sudo chmod +x /usr/lib/systemd/system-sleep/brcmfmac-suspend(after the next
omarchy updatethat ships this file).