Skip to content

wifi: brcmfmac: Wake-on-WLAN in s2idle for the BCM4387/BCM4388 Apple laptops - #1653

Merged
RyanTheTide merged 11 commits into
integration/aurorafrom
wifi/brcmf-wowlan-s2idle
Nov 12, 2026
Merged

RyanTheTide merged 11 commits into
integration/aurorafrom
wifi/brcmf-wowlan-s2idle

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Wake-on-WLAN (magic packet) for the BCM4387/BCM4388 Apple laptops in s2idle, with the association kept across the sleep.

Wake currently needs repeated magic packets. A single packet is often not delivered to the sleeping firmware (rates below); repeating it a few times a second apart raises the rate (M1 Pro 9/11, M2 5/14, J616s 8/8). WoWLAN stays opt-in: nothing changes unless wake-on-WLAN is enabled (iw phy <phy> wowlan enable magic-packet or NetworkManager's wake-on-wlan). With it off, suspend leaves the network as before. The aurora wake-for-network policy in the distributions enables it while on AC, matching the macOS default.

This carries the #1232 series rebased onto integration/aurora and adds the change that makes the firmware wake the host at all. It replaces #1232 and #1261.

What was wrong. #1232 sent HOST_D3_INFORM and then kept the function in D0 with its MSI wake-armed. After the D3 inform the firmware raised nothing for a matched frame: no MSI, no PME, and on the M4 Pro no edge on the WLAN WAKE# GPIO. #1261 (in-band device wake) failed at attach on the M2.

The change (wifi: brcmfmac: keep the firmware awake for WoWLAN in s2idle): with WoWLAN armed, skip the D3 inform. The firmware stays in LPAS with the wake filters and ARP/ND offloads and delivers a matched frame as an ordinary D2H interrupt on the wake-armed MSI. Resume is hot (no D0 inform). The sleeping event mask now holds only link loss and supplicant events, since every event is a wake.

Results (fleet67 base, brcmfmac swapped at runtime, RAM-only wakeup-source overlay on the WLAN node, rtcwake -d rtc1 -m freeze -s 45 per sleep, packets sent from a wired host ~16 s into the sleep):

M1 Pro (BCM4387 fw 20.96.31.0.8.7.148) M2 (same chip and firmware) M4 Pro J616s (BCM4388)
no packet: slept to the RTC alarm 4/4 3/3 2/2
association kept (same BSSID, connected time continues), disconnects all sleeps, 0 all sleeps, 0 all sleeps, 0
magic wake, broadcast only, 5 packets 1 s apart 6/8 (0.46-3.5 s) 5/11 (1.4-5.7 s) 8/8 (0.57-4.5 s)
magic wake, one broadcast + one unicast packet, all variants 3/17 (0.46-0.57 s) 0/26 not run
unicast-only magic 0/11 0/11 not run
wake source brcmfmac MSI (pm_wakeup_irq) brcmfmac MSI brcmfmac MSI
AVC denials 0 0 0

With these commits built against the fleet67 kernel: WoWLAN off, plain s2idle slept to the RTC alarm and associated again after resume, M1 Pro 3/3, M2 3/3 and J616s 3/3 (reconnect 4-27 s after the wake, the same disconnect-and-reconnect as today), 0 AVC; WoWLAN on, broadcast bursts M1 Pro 3/3 (0.49-1.4 s), M2 0/3, association kept. J616s 3/3 (0.57-3.6 s), association kept.

A trace of the first frames after each wake shows the magic packet itself as the wake frame. When a sleep misses the packet, the frames the firmware flushes after the RTC wake do not include it, so the firmware never received it. wowlan any with unicast pings wakes the M2 in about 1.2 s, so the MSI wake path is sound.

Known gaps:

  • A single magic packet is often not delivered to the sleeping firmware, and a unicast magic packet has not matched once. Beacon-listen settings (bcn_li_dtim/bcn_li_bcn = 1), PM_FAST, PM_OFF and fixed-offset pattern filters instead of the magic-search filter did not help. Without the lpas iovar the filters still wake the host at the same low rate.
  • The M1 Pro and M4 Pro DT wakeup-source nodes are not added yet (tested with a RAM-only overlay).
  • Sleep power with and without WoWLAN has not been measured yet.

Host tests: run-host-tests.py --only brcmf 30/30, with new controls for the WoWLAN s2idle path (no D3 inform, hot resume, arm-failure rollback). W=1 build of brcm80211 is clean.

🤖 Generated with Claude Code

RyanTheTide and others added 11 commits November 12, 2026 17:09
The BCM4378 and BCM4387 on Apple Arm systems retain firmware across the existing D3 path, but their endpoint does not advertise standard D3hot PME. The platform has a separate wake route, so using PME as the firmware feature-probe gate prevents cfg80211 from ever keeping an association.

Split transport retention from host wake routing, retain the standard PME test, and opt only the public Apple Arm BCM4378/4387 identities into the platform wake route. Require successful wowl and wowl_cap probes before advertising anything.

Make WoWLAN setup transactional. Check each retained-state operation and unwind to cfg80211's ordinary disconnect fallback on failure. Restore the bus WoWLAN state on resume. Firmware without the public capability therefore keeps the previous behavior.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Replace the Apple machine quirk with wakeup-source permission and an
allocated MSI. Keep the firmware capability gate and the ordinary PCI
PME path.

After the firmware host-sleep acknowledgment, arm the IRQ and keep the
PCI function in D0 using pci_save_state(), so PCI PM also retains its
upstream bridges. Limit this in-band route to s2idle. Account for an
early interrupt before suspend_device_irqs(), and balance wake arming on
resume, thaw, suspend failure and IRQ teardown.

Use explicit enable_irq_wake() rather than automatic wakeirq arming so
an arming failure can refuse suspend and restore the bus. The wiphy
resume callback then clears the firmware policy on the PM unwind.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Track the wakeup source created for a DT-selected MSI separately from
pre-existing PCI wake capability. On IRQ teardown, remove only the
source we created and restore the original capability. Leave an already
enabled source owned by the bus or platform intact.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Firmware with the lpas capability can retain an association without the
standard wowl iovar. Advertise only the generic WoWLAN any trigger when
retained transport and a wake route are both available.

Save PM, ARP/ND, packet-filter, event-mask and link-event policy, install
a minimal public unicast filter, and enable lpas last. Unwind every
completed step on failure so cfg80211 can use its ordinary disconnect
fallback. Restore the saved policy after the existing D0/HOSTREADY path
and report an unspecified wake reason.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The LPAS branch of brcmf_cfg80211_resume() returned straight after
restoring the firmware policy, so cfg->suspended stayed set. Country
updates deferred across the sleep were then never applied and every
later hint stayed pending.

Fall through to the common tail instead: clear the suspended state,
replay the deferred country update, then return the restore result.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Stub the in-band wake fields and helpers that brcmf_pcie_pm_enter_D3()
and the LPAS resume path now use, and add an LPAS resume control: the
restore runs with the bus up, the wake is reported, the suspended state
clears and a country hint deferred across the sleep is applied, also
when the restore fails. The lpas-resume mutation (early return) fails
the control.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The LPAS fallback only knew the "any" trigger, which passes every unicast
frame and so wakes the host for any traffic addressed to it. That is too
broad for a default Wake-on-WLAN setting.

Advertise WIPHY_WOWLAN_MAGIC_PKT as well and, for that trigger, install
forward-on-match packet filters that match the magic sequence (six 0xff
bytes, then the interface address sixteen times) at the UDP payload start
over IPv4 and IPv6 and after EtherType 0x0842. Every other frame stays in
the firmware; ARP and neighbour discovery are still answered by their
offloads. "any" keeps its single unicast filter.

Track the installed filters in a bitmap so the rollback and the resume
path remove exactly what was added.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Allow boards to describe WLAN wake capability. PCIe devices without a
host-wake line can use their in-band interrupt.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The BCM4387 on the M2 MacBook Air (J413, J415) has no separate host-wake
line; its firmware wakes the host with the endpoint's allocated MSI.
Mark the WLAN node as a wakeup source so brcmfmac arms that MSI for
Wake-on-WLAN and keeps the function in D0 across s2idle.

Leave the other Apple laptops unchanged until their wake path is tested.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
…offset

On BCM4387 firmware the LPAS sleep packet filters only become host-wake
sources when they are added and enabled while lpas is already on. The
fallback set lpas last, so the association was kept but no frame woke the
host: after the D3 handshake the firmware raised no interrupt at all.

Set the forward-on-match mode, then lpas, then add and enable the filters,
and only then apply nolinkup and the sleep event mask. Use the firmware's
magic pattern filter type (variable offset, public
WL_PKT_FILTER_TYPE_MAGIC_PATTERN_MATCH) from the start of the Ethernet
payload instead of three fixed-offset pattern filters; it covers UDP over
IPv4 and IPv6 and EtherType 0x0842. "any" keeps its fixed-offset unicast
pattern filter.

Also make sure the D2H doorbell/mailbox interrupt mask is enabled when the
wake IRQ is armed after the D3 acknowledgement, since that interrupt is the
wake signal.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
With WoWLAN armed, suspend sent HOST_D3_INFORM and then kept the
function in D0 with its MSI wake-armed. After the D3 inform the BCM4387
firmware (M1 Pro, M2) and the BCM4388 firmware (M4 Pro) raise nothing for
a matched frame: no MSI, no PME, and on the M4 Pro no edge on the WLAN
WAKE# GPIO either. The association survived the sleep but no packet
woke the host.

Skip the D3 inform when WoWLAN is armed. The firmware stays in LPAS with
the wake filters and the ARP/ND offloads in place and delivers a matched
frame as an ordinary D2H interrupt, so the wake-armed MSI ends the
sleep. The rings, the bus state and the interrupt mask stay as they are
and the resume is a hot one with no D0 inform. A frame that matches
before suspend_device_irqs() reports a hard wakeup event, so it aborts
the suspend instead of being lost.

Every event the firmware sends during the sleep is an interrupt and so a
wake, so the sleeping event mask now holds only the link loss and
supplicant events instead of adding them to the running mask.

Tested on an M1 Pro and an M2 (BCM4387, firmware 20.96.31.0.8.7.148) in
s2idle with a 45 s RTC alarm as the backstop: a broadcast magic packet
ends the sleep 0.46-3.5 s after it is sent, through the brcmfmac MSI,
with the association kept, and a trace of the first frames after the
wake shows the magic packet itself as the wake frame. Sleeps with no
packet run to the RTC alarm. A single packet is not always delivered to
the sleeping firmware yet (see the pull request for the rates).

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 12, 2026 10:24
@RyanTheTide
RyanTheTide merged commit 40f1e39 into integration/aurora Nov 12, 2026
2 checks passed
@RyanTheTide
RyanTheTide deleted the wifi/brcmf-wowlan-s2idle branch November 12, 2026 10:24
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.

1 participant