Skip to content

Fix Mac suspend loop after the first resume from sleep - #7589

Closed
marcindyguda wants to merge 2 commits into
omacom:quattrofrom
marcindyguda:brcmfmac-suspend-fix
Closed

marcindyguda wants to merge 2 commits into
omacom:quattrofrom
marcindyguda:brcmfmac-suspend-fix

Conversation

@marcindyguda

@marcindyguda marcindyguda commented Aug 20, 2026 •

Copy link
Copy Markdown

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_dcmd times out forever, and wpa_supplicant blocks in D state.

From then on every suspend fails when brcmf_pcie_pm_enter_D3 returns -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.

rmmod cannot cleanly unload brcmfmac (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 unbinds 0000:03:00.0 from brcmfmac in pre and rebinds it in post (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: pre only acts when the device is bound to brcmfmac and records the unbind in a /run marker, and post only 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*) and lspci finding a BCM43602 (14e4:43ba) at 03: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

  • Hook exercised end-to-end on a MacBookPro13,2 (pre → unbind confirmed via /sys/bus/pci/devices/0000:03:00.0/driver, post → device re-bound and NetworkManager reconnected within seconds).
  • ./test/all passes except four pre-existing environment-dependent test files that also fail on a clean tree (config-test, snapper-test, unowned-system-paths-test need the private omarchy-pkgs checkout; bar-icon-geometry-test fails in test rendering).
  • The new install script writes /usr/lib/systemd/system-sleep, which is the recorded hardware-conditional-hooks exception in unowned-system-paths-test.

Notes

  • The underlying firmware hang is a brcmfmac/kernel issue; this is a distro-side mitigation in the spirit of the existing force-igpu and keyboard-backlight hooks.
  • For already-installed systems the hook can be applied manually:
    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 update that ships this file).

Copilot AI balanced review requested due to automatic review settings August 20, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +17 to +39
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI review requested due to automatic review settings August 20, 2026 09:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

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.

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.

3 participants