Skip to content

Add WiFi resume hook for T2 MacBooks#5140

Open
fedesapuppo wants to merge 3 commits intobasecamp:devfrom
fedesapuppo:t2-wifi-resume
Open

Add WiFi resume hook for T2 MacBooks#5140
fedesapuppo wants to merge 3 commits intobasecamp:devfrom
fedesapuppo:t2-wifi-resume

Conversation

@fedesapuppo
Copy link
Copy Markdown
Contributor

@fedesapuppo fedesapuppo commented Mar 27, 2026

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
Copy link

Copilot AI Mar 27, 2026

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
Copy link
Copy Markdown
Member

dhh commented Apr 1, 2026

We need a migration for this too, no?

@fedesapuppo
Copy link
Copy Markdown
Contributor Author

fedesapuppo commented Apr 1, 2026

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
Copy link

Copilot AI Apr 1, 2026

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
Copy link

Copilot AI Apr 1, 2026

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
Copy link
Copy Markdown
Member

dhh commented Apr 22, 2026

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.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants