Skip to content

Add WiFi resume hook for T2 MacBooks - #5140

Closed
fedesapuppo wants to merge 5 commits into
omacom:quattrofrom
fedesapuppo:t2-wifi-resume
Closed

fedesapuppo wants to merge 5 commits into
omacom:quattrofrom
fedesapuppo:t2-wifi-resume

Conversation

@fedesapuppo

@fedesapuppo fedesapuppo commented Mar 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Installs a systemd system-sleep hook that reloads the Broadcom WiFi driver after waking from suspend

The Broadcom WiFi driver (brcmfmac) on T2 MacBooks loses connection state after suspend and silently fails — WiFi appears connected but can't transmit data. This hook unloads and reloads the kernel module on resume, restoring connectivity.

Tested:

  • Run fix-t2.sh on a T2 MacBook
  • Suspend and resume the machine
  • WiFi reconnects automatically after wake

Copilot AI review requested due to automatic review settings March 27, 2026 21:37

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 an installer-time systemd sleep/resume hook for T2 MacBooks to reload the Broadcom (brcmfmac) WiFi module on resume, addressing post-suspend connectivity failures.

Changes:

  • Extend the T2 detection/install script to create a systemd/system-sleep resume hook.
  • On post resume, unload and reload brcmfmac and log outcomes via logger.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

KERNEL_CMDLINE[default]+=" intel_iommu=on iommu=pt pcie_ports=compat"
EOF

cat <<'HOOK' | sudo tee /usr/lib/systemd/system-sleep/wifi-resume >/dev/null

Copilot AI Mar 27, 2026

Copy link

Choose a reason for hiding this comment

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

This installs the system-sleep hook into /usr/lib/systemd/system-sleep, which is typically reserved for distribution/package-managed units and may be overwritten on upgrades. Elsewhere in this repo, locally-installed systemd artifacts are placed under /etc/systemd/... (e.g., install/config/hardware/apple/fix-suspend-nvme.sh:13). Consider writing the hook to /etc/systemd/system-sleep/wifi-resume instead (and ensure the target directory exists, e.g., via mkdir -p).

Copilot uses AI. Check for mistakes.
@dhh

dhh commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

We need a migration for this too, no?

@fedesapuppo

fedesapuppo commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor Author

We need a migration for this too, no?

We do! 😅 I'm on it David!

Copilot AI review requested due to automatic review settings April 1, 2026 16:11

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 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread migrations/1774703846.sh Outdated
Comment on lines +4 to +14
sudo mkdir -p /etc/systemd/system-sleep
cat <<'HOOK' | sudo tee /etc/systemd/system-sleep/wifi-resume >/dev/null
#!/bin/bash
if [[ $1 == "post" ]]; then
logger -t wifi-resume "Reloading brcmfmac after resume"
modprobe -r brcmfmac 2>/dev/null
modprobe brcmfmac || logger -t wifi-resume "Failed to reload brcmfmac"
fi
HOOK
sudo chmod +x /etc/systemd/system-sleep/wifi-resume
fi

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

The WiFi resume hook installation code is duplicated in both this migration file and in install/config/hardware/apple/fix-t2.sh (lines 36-45). This duplication creates a maintenance burden: any bugs or improvements to the hook logic must be made in both places, increasing the risk of inconsistency. Consider consolidating this logic into a shared function or having one location call the other to avoid divergence. Additionally, this migration lacks error handling - if the hook installation fails, there's no indication in the logs, and no way to recover.

Suggested change
sudo mkdir -p /etc/systemd/system-sleep
cat <<'HOOK' | sudo tee /etc/systemd/system-sleep/wifi-resume >/dev/null
#!/bin/bash
if [[ $1 == "post" ]]; then
logger -t wifi-resume "Reloading brcmfmac after resume"
modprobe -r brcmfmac 2>/dev/null
modprobe brcmfmac || logger -t wifi-resume "Failed to reload brcmfmac"
fi
HOOK
sudo chmod +x /etc/systemd/system-sleep/wifi-resume
fi
if [[ -x "install/config/hardware/apple/fix-t2.sh" ]]; then
if ! sudo "install/config/hardware/apple/fix-t2.sh"; then
echo "Error: fix-t2.sh failed while installing WiFi resume hook" >&2
fi
else
echo "Error: install/config/hardware/apple/fix-t2.sh not found or not executable; WiFi resume hook not installed" >&2
fi
if [[ ! -f /etc/systemd/system-sleep/wifi-resume ]]; then
echo "Error: WiFi resume hook was not created at /etc/systemd/system-sleep/wifi-resume" >&2
fi
fi

Copilot uses AI. Check for mistakes.
Comment thread install/config/hardware/apple/fix-t2.sh Outdated
Comment on lines +36 to +45
always_full_speed=false
EOF

sudo mkdir -p /etc/systemd/system-sleep

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

The WiFi resume hook installation code is duplicated in both this file and in migrations/1774703846.sh. Additionally, unlike the migration file, this location lacks the idempotency check ([[ ! -f /etc/systemd/system-sleep/wifi-resume ]]) that prevents reinstalling the hook if it already exists. If fix-t2.sh is run after the migration (or if the script is executed multiple times), the hook file will be unnecessarily overwritten. Consider adding the same guard condition used in the migration.

Copilot uses AI. Check for mistakes.
@dhh

dhh commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Did you or anyone else test this?

@dhh dhh added the mac label Apr 22, 2026
systemd-sleep only scans /usr/lib/systemd/system-sleep (confirmed in
the man page and the binary itself), so the hook in /etc/ was never
executed. Move it to the path systemd-sleep actually reads, and drop
the redundant mkdir since /usr/lib/systemd/system-sleep is shipped by
the systemd package.
@fedesapuppo

Copy link
Copy Markdown
Contributor Author

Hey David! I just tested on my T2 mac, and I caught a bug. I installed the hook to
/etc/systemd/system-sleep/, but systemd-sleep only scans
/usr/lib/systemd/system-sleep/ (confirmed in the man page and in the binary's
strings). The hook this PR installed never ran.

It appeared to work during my initial review because an older copy existed at
/usr/lib/systemd/system-sleep/wifi-resume.bak from a previous manual setup, and
systemd runs all executables in that directory regardless of extension. That stale
file was silently handling my resumes.

Pushed f25bb1f to install at the correct path and drop the redundant mkdir -p (the
directory ships with systemd).

Verified on my T2 MacBook Air:

  • Without the hook: brcmfmac reports bus is down on resume, traffic silently fails.
  • With the hook at the correct path: hook fires (wifi-resume[...]: Reloading brcmfmac
    after resume), module reloads, WiFi passes traffic.

@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Sep 27, 2026
omarchybot and others added 2 commits September 28, 2026 00:15
Apple's Broadcom chips load the brcmfmac_wcc vendor module, which depends on brcmfmac and holds a reference to it. With it loaded, `modprobe -r brcmfmac` fails with "Module brcmfmac is in use", the following `modprobe brcmfmac` is a no-op, and the hook exits 0 having logged "Reloading brcmfmac after resume" while reloading nothing. Removing both in one call takes the vendor module out first; modprobe returns 0 when brcmfmac_wcc is not loaded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AGENTS.md asks every migration to open with an echo describing what it does, so the migration runner names it on every machine rather than only on the ones the condition matches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at f25bb1f0, and I pushed two commits on top, so the head is now a2223945d7efaf573cc4c6aabda19d259ec71be2.

What was wrong. On Apple's Broadcom chips, brcmfmac loads the brcmfmac_wcc vendor module, which depends on brcmfmac and holds a reference to it. While it is loaded, modprobe -r brcmfmac fails with Module brcmfmac is in use, the modprobe brcmfmac after it does nothing because the module is still loaded, and the hook exits 0. The Reloading brcmfmac after resume line is logged before either command runs, so seeing it in the journal does not show that a reload happened.

I reproduced this on a disposable Omarchy VM (kmod 34.2, kernel 7.2.5). With brcmfmac_wcc loaded, running the hook as post left the module where it was, exited 0 and logged the line anyway.

What I pushed:

  • 8d92a76e changes the unload in both copies of the hook to modprobe -r brcmfmac_wcc brcmfmac. On the same VM, the fixed hook actually unloads and reloads brcmfmac, with or without brcmfmac_wcc loaded. pre is still a no-op.
  • a2223945 moves the migration's echo to the first line, as AGENTS.md asks.

Other checks. The PR merged onto current dev passes test/omarchy-cli-test.sh on the VM (60 ok). The migration does nothing without a T2 PCI ID. With lspci stubbed to report one, it installs a root-owned executable hook and does nothing on a second run.

Second opinion. Codex (medium effort) reviewed the head and agreed that the unload/reload is the right approach for this hardware and in proportion to a bug where resume succeeds but Wi-Fi passes no traffic. Its independence is not guaranteed. It raised two more cases:

  • If brcmfmac_cyw or brcmfmac_bca were also loaded, the unload could fail partway. Apple's chips use only brcmfmac_wcc, so this does not apply to T2 Macs.
  • If a non-executable wifi-resume already exists, the migration skips it. This only happens if an earlier install was interrupted, so I left it.

Not tested here. A VM has no T2 Wi-Fi, so the fix itself, Wi-Fi passing traffic again after resume, has not been reproduced. It needs a T2 owner to run a2223945 and check four things:

  • journalctl -b -k shows brcmfmac reinitialising after resume, not just the wifi-resume log line.
  • lsmod | grep brcmfmac shows the module was reloaded.
  • Traffic passes over Wi-Fi to the gateway, to an external host and over DNS.
  • This holds across several suspend cycles, including a long one.

Waiting on the maintainer. That confirmation is still needed. There is also a question only the maintainer can answer: this PR targets dev (3.x). Open PRs against quattro handle T2/Broadcom suspend differently: #12314 rebinds the device, and #9830 and #11536 unload before sleep, with #11536 deliberately delaying the reload. On a machine upgraded from 3.x to quattro, this hook's immediate reload after resume would run alongside whichever of those lands, unless the upgrade removes /usr/lib/systemd/system-sleep/wifi-resume.

@omarchybot
omarchybot changed the base branch from dev to quattro September 28, 2026 05:52
@omarchybot

Copy link
Copy Markdown
Collaborator

This PR now targets quattro, so I looked again. I have not ported it, and I don't think it should be ported.

It doesn't apply to quattro as it stands. install/config/hardware/apple/fix-t2.sh doesn't exist there. Hardware setup moved to install/hardware/apple/fix-t2.sh (d12d449, 75cb4f7), which omarchy-apply-hardware runs as root. quattro does not fix this bug yet: nothing there installs a Wi-Fi sleep hook on T2 Macs.

Other open PRs against quattro handle the same problem better:

This PR's hook runs only after resume and reloads the module straight away. It can't help when brcmfmac blocks the suspend itself, and it is the reload #11536 reports crashing a BCM4377 machine. It also sends the unload's errors to /dev/null. If the unload fails, the hook leaves the broken module loaded and still exits 0.

Who checked this. I compared the four PRs (Claude Opus 5.5). Codex, at medium effort, was given all four PRs without my conclusion and asked which one should be brought forward. It also ruled this one out, for the same reasons. Its independence is not guaranteed. Codex said none of the four should merge unchanged. It prefers #11536's approach for the BCM4377 and #12314's for older Macs. It also warned that the fixes will race each other if more than one lands, since #11536 retires known community hooks but not wifi-resume or rebind-brcmfmac. Nothing was run on a worker for this pass, because a port nobody should merge is not worth testing.

Waiting on the maintainer: which of these to take forward, and whether to close this one in its favour. @fedesapuppo, your T2 MacBook Air is exactly the hardware #12314 and #11536 need tested. A suspend/resume report on either would help settle it.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thank you for this, @fedesapuppo. #12314 and #11536 fixes the same problem in a way the review judged better, so this is closed in favour of it. If it does not cover your case, please say so there.

Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent.

@omarchybot omarchybot closed this Oct 1, 2026
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! mac

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants