Skip to content

wifi: apple: centauri: t6050: keep N1 firmware, Bluetooth, and Wi-Fi alive across deep sleep - #2718

Merged
DjDeveloperr merged 2 commits into
integration/aurorafrom
djdev/m5-n1-keep-assoc
Nov 21, 2026
Merged

DjDeveloperr merged 2 commits into
integration/aurorafrom
djdev/m5-n1-keep-assoc

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On T6050 Macs, macOS keeps the N1 radio powered and running firmware across deep sleep, preserving PCI functions 0..2, Bluetooth, and Wi-Fi association (measured median 0.44 s wake-to-gateway reply across 14 deep sleeps on J714s, 0 dropped ping sequences), and reserves the SMC bpli warm reset for crash recovery.

Previously, apple_centauri_t6050, btcentauri_t6050, and pcie-apple tore down Wi-Fi, Bluetooth, and IPC and replayed bpli before and after every firmware sleep, forcing PCI removal, bus rescan, ROM cold boot (~3.3 s), and full Wi-Fi reassociation on every wake.

This 2-commit series matches macOS's healthy sleep/wake path with no runtime switches or board gates, keeping N1 firmware, Bluetooth, and STA association alive across deep sleep (without claiming magic-packet or disconnect host-wake triggers that are not yet programmed into firmware; J714s macsmc currently takes wifibt-only wakes as dark wakes):

  1. PCI: apple: T6050: allow endpoint to skip wake warm reset on keep-alive sleep (261a2e063cc5)
    • Keep the wake warm reset enabled by default for every state an endpoint driver does not explicitly claim (unbound, probe failed, teardown sleep, or .suspend not reached).
    • Export apple_pcie_t6050_sleep_keep_alive() so an endpoint driver that entered firmware host-sleep can opt out of the wake warm reset for that sleep cycle (cleared at the next PM_SUSPEND_PREPARE and by apple_pcie_t6050_sleep_reset()).
  2. wifi: apple: centauri: t6050: keep N1 firmware and Wi-Fi alive across deep sleep (b8fce260d6be)
    • Run the ACIPC host-sleep handshake across Beta (BAR0 + 0x1078), Alpha (firmware command 6 host-power sleep + BAR0 + 0x1024), and Control (BAR0 + 0x9078), polling each function's peripheral_info sleep status (context + 0x70) to 3 on suspend and <= 1 on wake.
    • Pause TX/RX ring producers and drain in-flight Alpha data TX within a 100 ms bound before entering host sleep; if descriptors are still in flight at the deadline, return -EBUSY so suspend falls back to DMA-fenced warm-reset teardown rather than sleeping with DMA in flight.
    • Save PCI config state and live pre-sleep PCI IDs on Control/Alpha (fn 0 switches in-place from ROM 0x1900 to firmware 0x1901 after boot; fn 1's empty dev_pm_domain skips PCI core save/restore), call apple_pcie_t6050_sleep_keep_alive(), place fn 0..2 into D3hot with PME_En before PME_Turn_Off, and verify each function against its pre-sleep/probed PCI ID while restoring config, MSI vectors, bus mastering, and memswap registers on resume.
    • Advertise only WIPHY_WOWLAN_ANY and check wowlan->any in wifi_suspend() so cfg80211 keeps the STA association across suspend when generic WoWLAN is armed (host-power state 1 when associated, state 3 LPNA when disconnected), without advertising unbacked magic-packet or disconnect triggers.
    • Keep the existing teardown + bpli warm-reset + re-enumeration path as automatic fault recovery if any function fails sleep/wake or firmware traps.
    • Update tools/asahi/centauri-{wifi-pm,bt-arena,recovery}-tests.py to cover WoWLAN trigger gating and ACIPC keep-alive suspend/fallback paths.

Testing

Host verification (261a2e063cc5 + b8fce260d6be)

  • scripts/checkpatch.pl --strict --no-tree: 0 errors, 0 warnings, 0 checks on both commits.
  • Clean arm64 compile check (0 warnings/errors) for pcie-apple.o, btcentauri_t6050.o, centauri_ipc.o, centauri_pci.o, and centauri_wifi.o.
  • Host test suites:
    • tools/asahi/centauri-wifi-pm-tests.py --negative-controls: PASS (production + 8 negative controls, including wowlan-ignores-trigger)
    • tools/asahi/centauri-bt-arena-tests.py --negative-controls: PASS (production + probe + 5 negative controls)
    • tools/asahi/centauri-recovery-tests.py --negative-controls: PASS (baseline + ownership + remove-interleaving + 7 negative controls)
    • tools/asahi/centauri-physical-recovery-tests.py: PASS
    • tools/asahi/radio-{pm,sleep-fence,sleep-power,sleep-snapshot}-tests.py: PASS

Hardware verification on MacBook Pro M5 Pro (J714s, T6050)

  • Kernel: 7.3.0-m5-n1k6 (integration/aurora a84637dca209 + this PR head b8fce260d6be), default cmdline, SEP writes on, 5 × real deep sleeps (30 s PMU RTC alarm).
  • Trigger gating: iw phy phy0 wowlan enable magic-packet and disconnect both rejected (-EINVAL); iw phy phy0 wowlan enable any accepted.
  • N1 firmware & PCI persistence: Passes 1–4 kept N1 firmware, PCI functions 01:00.0/1/2, and Bluetooth (Powered: yes) alive with 0 PCI remove/rescan, 0 bpli warm resets, and 0 spurious wifibt wakes (MBSW 00 00 00 00 00 00 00 00 on all 5 sleeps); pcie-apple port 0 link up in 116–119 ms on keep-alive wakes and 282 ms (with default bpli warm reset) when apple_centauri_t6050 was unbound.
  • Per-pass measurements (5 Hz ICMP ping to gateway 10.0.0.1):
Pass Mode Port 0 link exit_to_dev exit_to_disc exit_to_con First post-wake gateway reply seq_gap Result
1 wow=any, mem 116 ms - - - exit+0.13 s (seq 32->33, 3.97 ms RTT) 0 Stayed associated, 0 iwevent, BT Powered: yes
2 wow=any, mem 117 ms - - - exit+0.16 s (seq 32->33, 3.77 ms RTT) 0 Stayed associated, 0 iwevent, BT Powered: yes
3 wow=any, mem + 138.35 Mbps UDP TX stream (198,096 tx pkts / 285.5 MB into suspend) 119 ms - - - exit-0.05 s (seq 34->36) 1 TX drained within 100 ms bound (0 fallback), stayed associated, 0 iwevent, BT Powered: yes
4 wow=off, logind 118 ms - - (pre-sleep) 4.57 s exit+5.10 s 27 LPNA state 3 keep-alive (0 PCI rescan, 0 bpli), BT Powered: yes
5 apple_centauri_t6050 unbound, mem 282 ms - - - n/a (unbound) n/a Default pcie-apple wake warm reset ran cleanly (status 0x9b001001, 01:00.0 [106b:1900] visible)
  • Boot: Wi-Fi up and connected in 4.7 s from device probe (scans=0).
  • Regressions: 0 new kernel errors (7 baseline DCP/HID lines unchanged vs default), 0 SELinux AVC denials, 0 new failed systemd units, 0 centauri/btcentauri warnings or errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Strong result. Taking away the cold N1 boot on every wake, with the warm-reset path kept as the fallback, is the right design, and the per-pass table is clear. An adversarial read of aebdeba:

  1. WoWLAN triggers are advertised but not honoured. wiphy->wowlan advertises MAGIC_PKT | DISCONNECT, but wifi_suspend() only decides keep-or-disconnect from the link state. The triggers in struct cfg80211_wowlan are never read, and alpha_host_power() sends the same fixed event list whatever userspace asked for. So iw phy ... wowlan enable magic-packet (or NetworkManager's wake-on-wlan) reports magic-packet wake as working, and nothing shows the Mac waking on one: all five passes report 0 wifibt wakes. Either add a row where a magic packet from another host wakes a sleeping J714s (and one for an AP disconnect), or advertise only what is backed. If the goal is just "stay associated", say so in the commit, and keep userspace from relying on a wake the firmware may not deliver.

  2. The wake reset is now opt-in, and the safe default is the other way. In pcie-apple, bpli on wake now runs only if apple_pcie_t6050_sleep_reset() was called during this sleep. Every endpoint state the centauri driver doesn't explicitly cover now wakes without a reset: centauri not bound (module missing, probe failed, unbound by hand), or its .suspend not reached. Before, that case always got the reset. Inverting it (reset unless the endpoint driver says it kept the firmware alive this sleep) keeps today's behaviour for every unknown state, and the keep-alive path stays exactly as tested.

  3. The TX drain proceeds when it times out. centauri_t6050_wifi_suspend() waits up to 100 ms for in-flight data TX, then sends host sleep anyway with descriptors possibly still owned by the firmware. If TX is still busy at the deadline, falling back to the warm-reset sleep (return an error so .suspend takes the existing teardown) is safer than sleeping with DMA in flight. That also turns the 100 ms from a guess into a bound.

  4. Small: the resume paths compare against the constants 0x1901106b / 0x1902106b. Comparing against the IDs the functions had at probe (pdev->vendor/device) keeps a future N1 ID from always looking like a lost chip.

Rows besides (1): one deep sleep with Wi-Fi associated and an iperf3 TX stream running into the suspend, to exercise (3). And one deep sleep with apple_centauri_t6050 unbound, to show the PCI side still wakes the port cleanly (2).

Assisted-by: LLM (Claude:Opus 5.5)

…ve sleep

apple_pcie_t6050_sleep_up() unconditionally ran the endpoint SMC warm
reset (bpli) before training the link on every wake. When the N1
endpoint keeps its firmware alive across firmware sleep via ACIPC
host-sleep, issuing bpli on wake destroys the live firmware and forces a
cold ROM re-boot.

Keep the wake warm reset enabled by default for every state the endpoint
driver does not explicitly claim (unbound, probe failed, teardown sleep,
or suspend not reached), and export apple_pcie_t6050_sleep_keep_alive()
so an endpoint driver that successfully entered firmware host-sleep can
opt out of the wake warm reset for that sleep cycle. The flag is cleared
on the next PM_SUSPEND_PREPARE and by apple_pcie_t6050_sleep_reset().

Signed-off-by: Diljit Singh <hey@djdev.me>
… deep sleep

On T6050 Macs, macOS keeps the N1 radio powered and running firmware
across deep sleep, preserving PCI functions 0..2, Bluetooth, and Wi-Fi
association (median 0.44 s wake-to-gateway reply across 14 sleeps on
J714s), and reserves the SMC bpli warm reset for crash recovery.

Previously, apple_centauri_t6050 and btcentauri_t6050 tore down Wi-Fi,
Bluetooth, and IPC on every firmware sleep and replayed bpli before and
after sleep, forcing PCI removal, rescan, ROM firmware boot, and full
Wi-Fi re-association on every wake.

Match macOS's healthy sleep path so the N1 firmware, Bluetooth, and STA
association survive deep sleep (without claiming magic-packet or
disconnect host-wake triggers that are not yet programmed into firmware;
J714s macsmc currently takes wifibt-only wakes as dark wakes):
- Run the ACIPC host-sleep handshake on Beta (BAR0 + 0x1078), Alpha
  (firmware command 6 host-power sleep + BAR0 + 0x1024), and Control
  (BAR0 + 0x9078), polling each function's peripheral_info sleep_status
  at context + 0x70 to 3 on suspend and <= 1 on wake.
- Pause TX/RX ring producers and drain in-flight Alpha data TX within a
  100 ms bound before entering host sleep; if TX descriptors are still
  in flight at the deadline, return -EBUSY so suspend falls back to the
  existing DMA-fenced warm-reset teardown rather than sleeping with DMA
  in flight.
- Save PCI config state and live firmware PCI IDs on Control/Alpha
  (fn 0 switches in-place from ROM 0x1900 to firmware 0x1901 after boot,
  and fn 1's empty dev_pm_domain skips PCI core save/restore), opt out
  of the pcie-apple wake warm reset via
  apple_pcie_t6050_sleep_keep_alive(), place fn 0..2 into D3hot with
  PME_En before PME_Turn_Off, and verify each function against its
  pre-sleep/probed PCI ID while restoring config, MSI vectors, bus
  mastering, and memswap registers on resume.
- Advertise only WIPHY_WOWLAN_ANY and check wowlan->any in
  wifi_suspend() so cfg80211 can keep the STA association across suspend
  when generic WoWLAN is armed (host-power state 1 when associated,
  state 3 LPNA when disconnected), without advertising unbacked
  magic-packet or disconnect wake triggers to userspace.
- Preserve the existing teardown + bpli warm-reset + re-enumeration path
  strictly as automatic fault recovery if any function fails sleep/wake
  or firmware traps.
- Update the Centauri Wi-Fi, Bluetooth, and recovery host tests to cover
  WoWLAN trigger checks and ACIPC keep-alive suspend/fallback paths.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/m5-n1-keep-assoc branch from aebdeba to b8fce26 Compare November 21, 2026 18:35
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Addressed all four points in 261a2e063cc5 + b8fce260d6be:

  1. WoWLAN triggers: Dropped WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT from centauri_t6050_wowlan_support. The driver now advertises only WIPHY_WOWLAN_ANY and explicitly checks wowlan->any in wifi_suspend() (with a new wowlan-ignores-trigger negative control in centauri-wifi-pm-tests.py). The commit message states directly that the scope is keeping N1 firmware, Bluetooth, and STA association alive across deep sleep rather than waking the host on magic packets or disconnects (on J714s, macsmc currently treats wifibt-only wakes as dark wakes). On J714s, iw phy phy0 wowlan enable magic-packet and disconnect now fail with -EINVAL, while any is accepted.

  2. Inverted pcie-apple wake reset default (261a2e063cc5): Kept the wake warm reset enabled by default for every state not claimed by an endpoint driver (unbound, failed probe, teardown sleep, .suspend not reached). Added apple_pcie_t6050_sleep_keep_alive(bridge) (cleared on the next PM_SUSPEND_PREPARE and by apple_pcie_t6050_sleep_reset()), which centauri_t6050_suspend() calls only after all keep-alive suspend steps succeed.

  3. Bounded TX drain fallback: centauri_t6050_wifi_suspend() now checks data_tx_in_flight(wifi) (and firmware/transport health) after a final drain(wifi) at the 100 ms deadline. If descriptors are still in flight, it unwinds tx_paused, wakes the TX queue if appropriate, and returns -EBUSY (-EIO on fault) so centauri_t6050_suspend() falls back to the DMA-fenced warm-reset teardown rather than sleeping with TX DMA in flight.

  4. No hardcoded PCI IDs: btcentauri_t6050 now compares against probed ((u32)pdev->device << 16) | pdev->vendor. On fn 0 Control, pdev->device stays at the ROM ID 0x1900 even after firmware boot switches config space in-place to 0x1901, so centauri_t6050_suspend() validates and saves the live pre-sleep PCI_VENDOR_ID dwords for fn 0 and fn 1 (c->saved_pci_id[0..1]) and both noirq/normal resume paths verify against those saved IDs.

Re-verified on MacBook Pro M5 Pro (J714s, T6050)

  • Kernel: 7.3.0-m5-n1k6 (integration/aurora a84637dca209 + b8fce260d6be), default cmdline, SEP writes on, 5 × 30 s deep sleeps (PMU RTC alarm).
  • All 5 sleeps: MBSW 00 00 00 00 00 00 00 00 (0 spurious wifibt wakes), 0 centauri/btcentauri warnings or errors, 0 new kernel errors (7 baseline DCP/HID lines unchanged), 0 SELinux AVC denials, 0 new failed systemd units.
Pass Mode Port 0 link exit_to_dev exit_to_disc exit_to_con First post-wake gateway reply seq_gap Result
1 wow=any, mem (magic-packet/disconnect rejected -EINVAL) 116 ms - - - exit+0.13 s (seq 32->33, 3.97 ms RTT) 0 Stayed associated, 0 iwevent, 0 PCI rescan, 0 bpli, BT Powered: yes
2 wow=any, mem (magic-packet/disconnect rejected -EINVAL) 117 ms - - - exit+0.16 s (seq 32->33, 3.77 ms RTT) 0 Stayed associated, 0 iwevent, 0 PCI rescan, 0 bpli, BT Powered: yes
3 wow=any, mem + 138.35 Mbps UDP TX stream (198,096 tx pkts / 285.5 MB via wlp1s0f0 into suspend) 119 ms - - - exit-0.05 s (seq 34->36) 1 TX drained within 100 ms bound (0 fallback), stayed associated, 0 iwevent, 0 PCI rescan, 0 bpli, BT Powered: yes
4 wow=off, logind 118 ms - - (pre-sleep) 4.57 s exit+5.10 s 27 LPNA state 3 keep-alive (0 PCI rescan, 0 bpli), BT Powered: yes
5 apple_centauri_t6050 unbound (drivers_autoprobe=0), mem 282 ms - - - n/a (unbound) n/a pcie-apple ran default wake warm reset cleanly (status 0x9b001001, 01:00.0 [106b:1900] reachable)

Host verification on b8fce260d6be: checkpatch.pl --strict --no-tree 0/0/0 on both commits; all 8 Centauri/radio host test suites (+ 20 negative controls) PASS.

@RyanTheTide

RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Checked 261a2e0 + b8fce26. All four points are fixed:

  • pcie-apple now resets on wake unless apple_pcie_t6050_sleep_keep_alive() was called this sleep. It is called only after every keep-alive step succeeded, and cleared at the next PM_SUSPEND_PREPARE and by sleep_reset(). Pass 5 shows the unbound case taking the default reset cleanly. A chip that lost its firmware anyway still fails the saved-ID check on resume and goes through the warm-reset recovery.
  • WoWLAN advertises only ANY and checks wowlan->any. The commit states the scope (stay associated), and magic-packet/disconnect are refused.
  • The TX drain does a final drain() at the deadline and falls back to the fenced teardown if anything is still in flight. Pass 3 drained a 138 Mbps stream within the bound.
  • The IDs are saved live before the sleep (the fn 0 ROM-to-firmware ID switch explains why pdev->device alone wouldn't do).

No remaining concerns from my side at b8fce26.

On selection: nothing new keys on the SoC, board or firmware version. The keep-alive runs when the N1 functions bind by PCI ID (106b:1900/1901/1903) and the host port is the one whose DT carries the warm-reset properties (t6050_port / t6050_warm_count). t6050 only names the existing T6050 host path. Non-blocking: since #2711 reads the same warm-reset properties for the T8142 N1, a block-named export (apple_pcie_sleep_keep_alive()) would let that driver share the API later.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

A correction to the selection note in my last comment. I wrote that the keep-alive is keyed on "the host port whose DT carries the warm-reset properties". That is not quite right. pcie->t6050_port is only set by apple_pcie_t6050_sleep_probe(), and that function returns early unless the machine is apple,j714s or apple,j716c. So the keep-alive (like the existing T6050 firmware sleep) inherits that board gate. This PR doesn't add the gate, so it isn't a blocker here, and my verdict on b8fce26 stands. But a follow-up that keys apple_pcie_t6050_sleep_probe() on the port's DT (the apple,function-warm-reset / apple,warm-reset-writes it already reads, or a sleep property) would let other T6050 boards with an N1 get this without a board list.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr
DjDeveloperr merged commit 943a18e into integration/aurora Nov 21, 2026
1 check passed
@axboe

axboe commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

DjDeveloperr, a K116s (16-inch M5 Pro, firmware 27.2) resets when it enters deep sleep with Wi-Fi still associated on a kernel that has this change. With Wi-Fi taken down before the entry it sleeps and wakes as before.

Kernel: integration/aurora bb9f8ec plus #2187, #2201 (v6, not pushed yet), #2309, #2191 and my other K116s commits. The K116s only deep-sleeps with #2201, so I can't run this change without that stack; the fault may be in the interaction and not here. Two boots, the first ended by the first reset:

Sleep Wi-Fi at entry Result
Lid close, 35 s down (NetworkManager, through logind) resumed
Lid close, charger plugged (dark wake) down resumed
systemctl suspend, lid open, key wake down resumed
30 s RTC alarm, systemctl suspend down resumed
30 s RTC alarm, raw rtcwake -m mem, nmcli device disconnect first down resumed
30 s RTC alarm, raw rtcwake -m mem associated reset, 2 of 2

On both resets the panel stayed dark past the alarm and the machine then restarted by itself, the first time about two minutes after the entry. Nothing reached the journal after the entry and pstore is empty; I had no serial capture attached, so I can't say whether it died going down or coming up. The same raw rtcwake with Wi-Fi associated resumed on a84637d, the base before this merged.

Bluetooth is off on this machine. #2191's commits needed two test fixture conflicts resolved against this change; its driver hunks applied cleanly.

I can run a build of your choosing on the K116s (with a serial capture next time) if you have a patch or want specific lines logged.

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.

3 participants