Skip to content

wifi: brcmfmac: Wake-on-WLAN (magic packet) over LPAS associated sleep on the M2 (supersedes #1218) - #1232

Closed
RyanTheTide wants to merge 10 commits into
integration/aurorafrom
wifi/brcmf-wowlan-magic
Closed

RyanTheTide wants to merge 10 commits into
integration/aurorafrom
wifi/brcmf-wowlan-magic

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #1218 (and #1216). Wake-on-WLAN for the M2's BCM4387 over LPAS associated sleep, with a magic-packet trigger and the in-band MSI wake route.

Commits

1-4. #1218's series: WoWLAN on retained Apple PCIe; DT-selected (wakeup-source) in-band MSI wake with D0 retention, s2idle only; PCI wakeup ownership; LPAS fallback gated on the firmware cap token lpas
5. LPAS resume leaves the suspended state (fix found on #1218)
6. tools/asahi brcmf-suspend-tests: stubs + LPAS resume control + lpas-resume mutation
7. magic packet: advertise WIPHY_WOWLAN_MAGIC_PKT; for that trigger install forward-on-match filters for the magic sequence (6x 0xff + interface MAC x16) at the UDP payload over IPv4/IPv6 and after EtherType 0x0842, so only magic packets reach (and wake) the host; any keeps the unicast filter
8. dt-bindings: wakeup-source for brcm,bcm4329-fmac
9. DT: wakeup-source on the J413/J415 WLAN node (BCM4387 M2 Air); other boards unchanged until tested

NetworkManager part (keep a WoWLAN device that is still activated at wake): aurora-silicon/fedora-aurora#220.

Hardware receipts (M2 J413, fleet36, 2026-11-09)

Test modules were built against fleet36 (6cf0ab0 + this branch's brcm80211 dir) and swapped in without a reboot. The DT wakeup-source came from a RAM-only overlay (no Stage 2 change). Stock state was restored after each session. systemctl suspend is masked on this ref Mac, so the NM half of the lid path was driven by NM Sleep(true/false) (same do_sleep_wake() code) around rtcwake -d rtc1 -m freeze.

  • Arming works. iw phy wowlan lists any and magic packet. iw phy wowlan enable magic-packet succeeds, PCI power/wakeup is enabled, and a debug build confirms the filters install (return 0), LPAS is armed, and the MSI is wake-armed after the D3 ack.
  • Association kept on the NM sleep path with fedora-aurora#220's NetworkManager: 3/3 cycles (same BSSID, connected time keeps counting), first ping 24-31 ms after resume. With Fedora's NM it was 5.6-7.6 s (NM drops it at wake), and 4.1 s with WoWLAN off.
  • Packet wake does NOT work yet. Magic x1 and any + unicast pings x3 all slept to the 120 s RTC alarm. Neither "Triggering wakeup from IRQ" nor an ISR in D3 shows up with pm_debug_messages, and both the device's PMCSR PME_Status and the root port's RootSta stay 0. So after HOST_D3_INFORM/ACK the firmware raises neither MSI nor PME. A test-only variant that skipped D3_INFORM woke immediately on the MSI (the firmware stays busy) and then timed out firmware commands on resume, so that is not the design either.
  • 0 AVC in all sessions.

The missing firmware wake-enable step is with Daybreak (t-5811). Until it's found, the magic trigger is advertised but doesn't wake, so this stays a draft and is not for merge.

🤖 Generated with Claude Code

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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

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

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
…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.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

t-5811 follow-up: 592f5f2 sets the filter mode, then lpas=1, then adds and enables the wake filters, and only then nolinkup and the event mask. Magic now uses one type-1 variable-offset magic-pattern filter at ETH_HLEN; any keeps the type-0 unicast filter. The D2H mailbox mask is checked again once the D3 ack arrives. host-tests brcmf 23/23 locally.

M2 retest (fleet37, RAM-only wakeup-source overlay, rtcwake -d rtc1 -s 120 armed every cycle): still no packet wake. Magic x1 and any + unicast pings x3 all slept to the RTC alarm, with 0 AVC. Live kmsg from a debug build shows the arming does happen: lpas on, filters install 0 map 1 any 1, and after the D3 ack mailboxmask 0000ffff mailboxint 0 intmask 39008fcb. The MSI is wake-armed, yet the firmware raises no D2H interrupt. Still a draft; traces are in the lab under traces/wifi-bt/20261109-m2-wowl/t5811.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #1653.

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