Skip to content

wifi: brcmfmac: negotiate PCIe in-band device wake - #1261

Closed
RyanTheTide wants to merge 14 commits into
integration/aurorafrom
wifi/brcmf-wowlan-inband-ds
Closed

RyanTheTide wants to merge 14 commits into
integration/aurorafrom
wifi/brcmf-wowlan-inband-ds

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Summary

This is stacked on #1232 and must land after it.

  • advertise HOSTCAP_DS_INBAND_DW together with HOSTCAP_DS_NO_OOB_DW only when firmware reports PCIE_SHARED_INBAND_DS
  • serialize normal H2D publication with the active/device-sleep/device-wake state machine, including deferred DS_ENTER_REQ acknowledgement and bounded DS_EXIT_NOTE waits
  • order the DS transition around HOST_D3_INFORM and D0/HOSTREADY, with exact unwind on preparation, mailbox, timeout, IRQ-wake, and resume failures
  • preserve the legacy host-capability word and immediate DS acknowledgement when the firmware capability is absent
  • add host controls for capability selection, enter deferral, exit, timeout, the DS-enter/D3 race, unwind, H2D fencing, and resume ordering

Verification

Buildbox arm64 LLVM=1 W=1 with the PCIe transport explicitly enabled:

make O=$BUILD_OUT ARCH=arm64 LLVM=1 defconfig
scripts/config --file $BUILD_OUT/.config -m BRCMFMAC -e BRCMFMAC_PCIE
make O=$BUILD_OUT ARCH=arm64 LLVM=1 olddefconfig
make O=$BUILD_OUT ARCH=arm64 LLVM=1 W=1 -j8 drivers/net/wireless/broadcom/brcm80211/brcmfmac/

  CC [M]  drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.o
  CC [M]  drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.o
  CC [M]  drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.o
  LD [M]  drivers/net/wireless/broadcom/brcm80211/brcmfmac/brcmfmac.o

Result: rc 0, with no warning or error diagnostics.

Linux host tests:

tools/asahi/run-host-tests.py --only brcmf --jobs 8
...
ok brcmf-inband-ds-tests
ok brcmf-inband-ds-tests --mutation capability-gate
ok brcmf-inband-ds-tests --mutation early-ack
ok brcmf-inband-ds-tests --mutation exit-note
ok brcmf-inband-ds-tests --mutation wake-timeout
ok brcmf-inband-ds-tests --mutation d3-race
ok brcmf-inband-ds-tests --mutation unwind
ok brcmf-inband-ds-tests --mutation ring-fence
ok brcmf-inband-ds-tests --mutation d3-order
...
32/32 passed

M2 qualification plan

No target hardware was used for this implementation.

Use the existing RAM-only LPAS test flow on the M2, keeping the PCI function in D0 with MSI wake and the existing ASPM policy:

  1. Enable only magic-packet wake, arm an RTC fallback, and enter direct s2idle.
  2. Send a valid magic packet to the current station MAC at about two seconds; repeat for three cycles.
  3. Require wake within about two seconds, an incremented WLAN MSI count, successful D0/HOSTREADY without command timeouts, and the same association, keys, IP state, and flowrings.
  4. Run one wrong-MAC control and one no-packet RTC control; neither may wake early.
  5. Enable any and send one unicast ping to cover the type-0 filter path with the same association-retention checks.

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
Advertise in-band device wake only when firmware exposes the shared DS capability. Serialize active ring publication with deep-sleep enter and exit, and integrate the state with host D3 and D0 transitions.

Add host controls for capability-absent firmware, deferred DS acknowledgement, wake exit and timeout handling, D3 races, unwind, and transport ordering.

Signed-off-by: Ryan Murray <[email protected]>

Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

M2 (J413, BCM4387 firmware 20.96.31.0.8.7.148), 7.3.0 lab kernel with this branch as modules, module load only (no suspend): attach fails. The firmware reports boot complete, then the first ioctl (CLM load) returns -5, brcmf_fw_crashed fires and setup fails with no netdev. kprobes on the mailbox path: H2D 0x2 (HOST_DS_ACK) from the IRQ thread, then H2D 0x40 (DEVICE_WAKE_ASSERT) from brcmf_pcie_ring_prepare_write 0.3 ms later, then no D2H for 2.04 s until brcmf_fw_crashed. The setup error path also warns in brcmf_bus_cancel_reset_work (from brcmf_pcie_remove). Same kernel with #1232 alone attaches and advertises magic-packet WoWLAN. So the device-wake request is not reaching the endpoint once it is in device sleep; the sleep matrix was not run.

Keep in-band deep-sleep mailbox data in shared TCM, but notify
firmware through enumeration-core doorbell 1. Config-space SBMBX is not
serviced after the endpoint accepts device sleep, so using it for
DEVICE_WAKE_ASSERT leaves the first attach ioctl waiting for a DS exit
that never arrives.

Do not queue reset work from the setup failure path immediately before
unconditional driver removal, and cover both regressions in the host
model.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Advertising in-band device wake lets firmware request deep sleep before
HOSTREADY and the initial DCMDs have completed. The DS state machine
starts with no active host reference, so it acknowledges that request.
The first attach ring operation then has to wake a not-yet-ready endpoint.

Hold one host-active reference from negotiation through brcmf_attach().
This defers DS_ACK until HOSTREADY, CLM and initial ring setup complete.
Keep mailbox data in shared TCM and use enumeration-core DB1 for in-band
DS notifications, matching the public transport contract.

Mark reset removal under bus_reset_lock, but drop the mutex before
waiting for reset work. The removing flag still excludes new arming
without holding the arming mutex across cancel_work_sync().

Extend the host model with attach admission, DB1 delivery and
setup/reset unwind mutation controls.

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

Copy link
Copy Markdown
Contributor Author

M2 retests of the two new commits (modules on the running 7.3.0 lab kernels): 5f32b61 (DB1 notify) alone fails attach the same way as before: H2D 0x2, then 0x40 0.3 ms later, no DS_EXIT_NOTE, brcmf_fw_crashed after 2.04 s, and the setup-error WARN still fires. With 447963b on top, loading the module reset the whole machine within seconds, twice (once with the lab watchdog armed, once without); the journal of both boots was not flushed. Do not load this branch on hardware until the hang path is found.

Advertising in-band deep sleep during firmware attach can let the device enter DS before HOSTREADY and CLM complete. The attach-time host-active hold does not make that transition safe and exposes mailbox waits from the threaded IRQ path.

Keep in-band DS disabled by default and publish its host capability only after brcmf_attach() when explicitly requested. Defer D2H DS handling to bounded work, reject ring wake waits from the IRQ thread, and make an occupied IRQ-side H2D mailbox a nonblocking failure. Drain mailbox work before reset work during removal.

Extend the host control with safe-admission, occupied-mailbox, IRQ deferral and bounded-storm mutations.

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

Copy link
Copy Markdown
Contributor Author

M2 retest of 0408f61 (lab twin with the hardware watchdog armed): with the default inband_ds=0 the module attaches like #1232 (link in 1 s, WoWLAN any + magic, no crash, no WARN, no reset), so the earlier machine reset is gone. With inband_ds=1 it attaches, then every DCMD times out (brcmf_msgbuf_query_dcmd_len: Timeout on response for query command) and the link never comes up; no reset. The sleep matrix was not run. In-band device wake still does not work with BCM4387 firmware 20.96.31.0.8.7.148.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #1653.

@RyanTheTide
RyanTheTide deleted the wifi/brcmf-wowlan-inband-ds branch November 27, 2026 13:22
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