Repository navigation
wifi: apple: centauri: t6050: recover stopped N1 firmware via warm reset - #3346
Conversation
apple_smc_warm_reset() previously read platform_get_drvdata(wr->smc) without holding device_lock(&wr->smc->dev), leaving runtime (!noirq) callers racing concurrent macsmc driver unbind and devm freeing of struct apple_smc across the multi-write reset sequence. Export apple_smc_warm_reset_lock(), apple_smc_warm_reset_unlock(), apple_smc_warm_reset_locked(), and apple_smc_warm_reset_ready() so callers can pin the SMC binding across both preflight and runtime reset transactions, and use the same device_lock exclusion inside runtime apple_smc_warm_reset(). Signed-off-by: Erik Bourget <[email protected]>
apple_sleep_radio_port_down(), apple_sleep_radio_rc_ready(), and apple_sleep_radio_port_wake() previously relied on r->n1_host (populated only during t6050_sleep_begin()) and !r->committed (which stays false only until the first committed deep sleep). Calling apple_pcie_t6050_port_recycle() outside a suspend cycle either failed with -ENODEV before the first sleep or left the APCIE0 DART GAPF slice gated after a prior committed sleep. Check t6050_n1_host_bound() directly in the radio port helpers, track r->n1_gapf_gated explicitly across port down/ready, clear the APCIE0 bit in r->dart_slice_written when restoring the slice, keep pins_saved updates scoped to live sleep attempts (r->attempt_active), and export apple_sleep_radio_port_ready() so callers can preflight sleep-helper support before destructive teardown. Signed-off-by: Erik Bourget <[email protected]>
On T6050, pcie-apple probes before apple-dart, so pcie->t6050_dart is only resolved lazily. Previously that lookup happened only on PM_SUSPEND_PREPARE, causing runtime apple_pcie_t6050_port_recycle() calls before the first sleep to fail with -EBUSY. On boards with a sibling port on the same controller (such as the J714s SD reader), t6050_down also gated config access across the whole host, failure handling marked the entire host bus disconnected, shutdown skipped live sibling ports when t6050_down was set, deferred cold-port wake could race a concurrent port recycle, and a later deep suspend could park the sibling port without being able to restore it. Extract apple_pcie_t6050_ensure_dart() under pcie->lock, keep non-noirq warm-reset status local to apple_pcie_t6050_port_recycle(), assert PERST# before the warm reset, scope t6050_down config gating, lost-port disconnection, and shutdown skipping to the radio port hierarchy, serialize port recycle against deferred sibling cold-port wake via t6050_recycle_lock, refuse deep sleep before parking a sibling cold port if the radio port is lost, and export apple_pcie_t6050_can_recycle() plus apple_pcie_t6050_recycle_lock()/unlock() (all properly IS_REACHABLE(CONFIG_MFD_MACSMC)-guarded) to pin the SMC binding across teardown and port recycle. Signed-off-by: Erik Bourget <[email protected]>
When the T6050 N1 Wi-Fi Alpha firmware unexpectedly leaves execution stage 2 at runtime, commands fail with -EIO and wlan0 stays wedged until reboot (often surfacing later as 'firmware country update failed: -5' when cfg80211 updates regulatory state after a disconnect). Detect runtime transport stops across link_worker(), command_reply(), scan_transport_stopped(), connect_worker(), wait_disconnect(), and hardware startup failures (set specifically at firmware/transport failure sites in rom_boot, start_ipc_locked, and radio_start, never on host allocation or registration errors), and schedule a delayed re-check (2 s) on the ordered recovery workqueue when the port describes warm-reset properties in DT. Keep observed stage!=2 separate from sticky command_failed so transient stage blips clear cleanly without restarting while preserving the DMA fence for submitted commands with unknown completion. Serialize both fault_worker() and rewake_worker() against system sleep and reboot via lock_system_sleep() (with cen_rewake_wq non-freezable) and cen_active_lock before taking pci_lock_rescan_remove(), eliminating the AB-BA deadlock between pci_rescan_remove_lock and the PM notifier chain, preventing concurrent port recycles from racing sibling cold-port parking, protecting bridge->subordinate lookups against PCI removal, and letting reboot_notify() drain in-flight workers on direct restart paths (such as deferred_cad) without deadlocking sys_reboot(). Pin the SMC binding via apple_pcie_t6050_recycle_lock() for every recovery path that requires port recycle (both runtime faults and sleep fallback), revalidate generation and active stall inside rewake_teardown() before quiescing or charging/latching the 3-in-30-minute rate limit, block replacement F0 bindings via teardown_active until PCI removal completes, and rescan if a non-ENOLINK recycle failure leaves the link active. Give .shutdown its own quiesce-only callback and skip firmware country update (command 9) in wifi_regulatory() when stopping, faulted, or outside stage 2. Signed-off-by: Erik Bourget <[email protected]>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict at 04228e796271: no code blockers. It isn't ready to merge yet: CI is still running, and the rows and the Risk line need updating (see below).
Checked
- SMC lock (
cb8fd175d548):- Runtime
apple_smc_warm_reset()now holds the SMCdevice_lockand re-checksdevice_is_bound()across the writes. The noirq path stays lockless, as before. - The only runtime caller that holds the lock longer is the T6050 recovery worker, through
apple_pcie_t6050_recycle_lock().apple_pcie_t6050_warm_reset()then usesapple_smc_warm_reset_locked(), so the lock is never taken twice. apple_pcie_t6050_port_recycle()has no other caller.
- Runtime
- Lock order in the recovery worker:
- The order is
lock_system_sleep()→cen_active_lock→pci_lock_rescan_remove()→ the SMC device lock → F0's device lock (teardown) →t6050_recycle_lock→pcie->lock. - I found nothing that takes these in reverse:
- macsmc's own bind and unbind don't touch the PCI functions;
apple_pcie_t6050_unpark_cold()takest6050_recycle_lockbeforepcie->lock, asport_recycle()does;boot_lockis always taken beforewifi->lock(fault worker, teardown, PM callbacks).
- The SMC lock is dropped before the rescan, so the new F0's probe never runs under it.
centauri_t6050_fault_report()takes onlycen_recovery_lock, and every call site is in sleeping context.
- The order is
- Sleep exclusion:
- Both workers hold
lock_system_sleep(). So a recycle can't overlap a suspend, the PCIe PM notifier, or the sleep driver's state changes. - The reboot notifier drains
cen_active_lockfor the direct restart paths. - Dropping
WQ_FREEZABLEis consistent with that.
- Both workers hold
- Sleep helpers (
ca94dc057ee6):- The radio-port helpers now check
t6050_n1_host_bound()live, andrc_ready()restores the slice from the explicitn1_gapf_gatedflag, clearing the APCIE0 bit indart_slice_written. Together these give the GAPF slice back after a runtime down/up, both before and after the first committed sleep. pins_savedis only touched inside a live sleep attempt.
- The radio-port helpers now check
- PCIe (
0960ced52724):- The
t6050_downand lost-port handling is now scoped to the radio port, so the J714s SD reader on the same host stays reachable. - PERST# is asserted before the warm reset.
- The runtime result stays local (
warm_done), so the noirqt6050_warm_doneisn't overwritten. - On hosts without a
t6050_port,map_bus()andshutdown()behave as before.
- The
- Recovery policy (
04228e796271):- It runs only when the bridge describes
apple,function-warm-resetandapple,warm-reset-writes, whenapple_pcie_t6050_can_recycle()passes, and for the current generation. - It re-checks after 2 s and caps restarts at 3 per 30 min.
centauri_t6050_stop_recovery()walks the owner list without the lock, which is safe:cen_exitingstops new owners first, and the list holds its own reference.
- It runs only when the bridge describes
- Commits:
- All four are signed off by the author, with no attribution.
checkpatch --strictfinds nothing in the kernel files. The three non-Centauri commits each have one commit-message line over 75 columns.- In
04228e796271, the 1 error, 83 warnings and 6 checks are all intools/asahi/centauri-physical-recovery-tests.c: space indentation, long lines, andif (recycle_ret) return recycle_ret;on one line. So the body's "0/0/0" doesn't hold for that file.
Not blocking
- The comment on
centauri_t6050_fault_report()still says "freezable recovery workqueue", but the queue is no longer freezable. apple_pcie_t6050_recycle_lock()takes the SMC binding, nott6050_recycle_lock, so the two names suggest the opposite of what each does.
Before merge
- CI: most checks were still running when I posted, including
KUnit macsmc,rust-buildandhost-tests. They need to finish green. - The
Riskline:- It says non-T6050 Macs don't call
apple_smc_warm_reset*(). Butcentauri/centauri_port.cdoes, for J813, J815 and J873g, and its runtime warm reset now takes the SMC device lock. - So the shared macsmc change needs a row on one of those boards: a Centauri warm-reset restart.
- J313 and J713 run none of the changed code. They have no Centauri driver, and the PCIe changes only act on T6050.
- It says non-T6050 Macs don't call
- Rows at the exact head:
- J716c: the row at this head covers a clean boot and normal Wi-Fi and Bluetooth use. The recovery sequence ran on a build with a local fault hook. Either run one forced recovery at this head, or name the exact tree of the injection build (this head plus the hook only).
- J714s: a runtime recycle while the SD reader on port 1 is in use, then a deep sleep (already under
Not yet).
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Updated the PR body at
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Approved at this head. The earlier pass here found no code blockers: the SMC warm reset now runs under the SMC device lock, with a locked variant for the T6050 recovery worker; the worker's lock order has no reversal; and the sleep exclusion holds. The body now names J813, J815 and J873g in Risk. Rows at this head:
- J714s (M5 Pro), kernel main
07cb39a2+ this PR: Wi-Fi associated with 0 % loss and Bluetooth powered. After a deep sleep the link came back in 281 ms, the same as the default kernel. The forced firmware stop wasn't exercised (no trigger in a clean build). - Neo (J700), a second generation for the shared SMC and PCIe code, in a candidate carrying this head unchanged: Wi-Fi and Bluetooth up before and after one deep sleep, 0 SMC or PCIe errors, no new message types.
|
J700 (Neo, G17P) row at combined SHA Kernel: one-shot trial boot
Results
This PR: Wi-Fi was up and listed networks before and after the test sleep, with 0 PCIe or SMC error lines. The N1 warm-reset recovery path itself (a stopped firmware) was not triggered on this run. |
What: Recover T6050 N1 Wi-Fi firmware runtime stops (
stage != 2/ transport loss, often surfacing asfirmware country update failed: -5) via SMC warm reset and PCIe radio port recycle instead of leavingwlan0wedged until reboot or deep sleep.Tested: J716c (M5 Max) at
04228e796271: boots cleanly on the default command line (wlan0connected, 0% ping loss to LAN and gateway, active scan,iw reg set US,hci0powered, disconnect/reconnect clean, 0firmware country update failed, 0WARNING/BUG/Oops, 0 new failed units); in candidate3e4078f656d5(mainfcb124279183plus unchanged04228e796271and sibling PRs, default command line): clean boot (wlan0associated at 5 GHz with0%packet loss to the gateway,hci0powered,0new failed units,0LSM denials,0Centauri/PCIe/SMC kernel errors; after manual wake from a 4h52ms2idle,wlan0reassociated with0%loss and Bluetooth scanned cleanly, while forced runtime recovery did not run because the clean build carries no fault-injection hook, and unattendeddeepsleep did not run becauseapple,t6050-pmu-rtchas nointerruptsint6050-j716c-sleep.dtsi/rtc-apple-pmu.c, confirmed byrtcwake -m no -s 5leavingwakealarmset withalrm_pending: no); all 6 Centauri host test suites (plus negative controls and all 8 physical mutations),W=1 KCFLAGS="-Werror", andcheckpatch.pl --strictondrivers/andinclude/pass.Risk: two-way door · M5 (T6050: J716c, J714s) and Centauri SMC warm-reset boards (J813, J815, J873g via
centauri_port.ccallingapple_smc_warm_reset()); J313, J713, and other Macs without Centauri do not execute the changed pathsNot yet: J716c forced runtime N1 recovery and committed deep sleep + post-sleep recovery check at
04228e796271(clean build has no fault-injection hook, and unattendeddeepsleep wake is blocked becauseapple,t6050-pmu-rtchas nointerruptsint6050-j716c-sleep.dtsi/rtc-apple-pmu.c, confirmed byrtcwake -m no -s 5leavingwakealarmset withalrm_pending: no; earlier temporary fault-injection testing is in Evidence); J714s (M5 Pro, runtime recycle with sibling SD reader on port 1 active, then deep sleep) and J813/J815/J873g (Centauri SMC warm-reset restart path) at04228e796271(external hardware not in lab).Details
Problem
When the T6050 N1 Wi-Fi Alpha firmware unexpectedly leaves execution stage 2 at runtime (for example
stage=0x3),apple_centauri_t6050fails commands with-EIO(-5) and leaveswlan0wedged until a full reboot or deep sleep cycle. Regulatory country updates (command 9) continue failing withfirmware country update failed: -5against the dead transport.Design
Four scoped commits enable safe runtime radio recovery without affecting sleep/resume or sibling PCIe devices:
mfd: macsmc: serialize runtime warm reset against unbind(cb8fd175d548)device_lock(&wr->smc->dev)and checksdevice_is_bound()across runtime (!noirq) warm-reset transactions.apple_smc_warm_reset_lock(),apple_smc_warm_reset_unlock(),apple_smc_warm_reset_locked(), andapple_smc_warm_reset_ready().soc: apple: sleep: allow runtime T6050 radio port recycle(ca94dc057ee6)t6050_n1_host_bound()directly instead of relying onr->n1_host/!r->committed(which failed before the first sleep or left the APCIE0 DART GAPF slice gated after a prior committed sleep).r->n1_gapf_gated, clearsBIT(T6050_DART_APCIE0)inr->dart_slice_writtenon restore, keepspins_savedscoped to live sleep attempts (r->attempt_active), and exportsapple_sleep_radio_port_ready().PCI: apple: allow runtime T6050 radio port recycle(0960ced52724)pcie->t6050_dartlazily viaapple_pcie_t6050_ensure_dart()underpcie->lockso runtime recycles work before the first deep sleep.apple_pcie_t6050_port_recycle(), asserts PERST# before warm reset, scopest6050_downconfig gating, lost-port disconnection, andapple_pcie_shutdown()skipping to the radio port hierarchy (keeping the J714s sibling SD reader live), serializes port recycle against deferred sibling cold-port wake viat6050_recycle_lock, refuses deep sleep before parking a sibling cold port if the radio port is lost, and exportsapple_pcie_t6050_can_recycle()andapple_pcie_t6050_recycle_lock()/unlock()(guarded byIS_REACHABLE(CONFIG_MFD_MACSMC)).wifi: apple: centauri: t6050: recover stopped N1 firmware via warm reset(04228e796271)link_worker(),command_reply(),scan_transport_stopped(),connect_worker(),wait_disconnect(), and hardware boot failures (boot_hw_failedset only at firmware/transport failure sites, never on-ENOMEMor registration errors).stage != 2(stage_fault_logged) from stickycommand_failedso transient stage blips clear cleanly without restarting while preserving the DMA fence for submitted commands with unknown completion.cen_rewake_wq), gated on DT warm-reset properties (apple,function-warm-reset/apple,warm-reset-writes) and host readiness (apple_pcie_t6050_can_recycle()), rate-limited to 3 restarts in 30 minutes.lock_system_sleep()+cen_active_lockbeforepci_lock_rescan_remove()(preventingpci_rescan_remove_lock<-> PM notifier chain AB-BA deadlock and draining in-flight workers on direct restart paths such asdeferred_cad), pins SMC across teardown and recycle, revalidates generation and active stall inrewake_teardown(), blocks replacement F0 bindings viateardown_activeuntil PCI removal finishes, allows replacement-generation startup faults to queue a check while the prior generation's rewake cleans up, uses a dedicated quiesce-only.shutdown, and skipscommand 9country updates inwifi_regulatory()when stopping, faulted, or outside stage 2.Evidence
Host Tests & Static Checks (at
04228e796271)python3 tools/asahi/centauri-recovery-tests.py(+--negative-controls): PASSpython3 tools/asahi/centauri-physical-recovery-tests.py(+ all 8--mutationcontrols): PASSpython3 tools/asahi/centauri-wifi-pm-tests.py(+--negative-controls): PASSpython3 tools/asahi/centauri-scan-tests.py(+--negative-controls): PASSpython3 tools/asahi/centauri-bt-arena-tests.py(+--negative-controls): PASSpython3 tools/asahi/centauri-wifi-avoid-tests.py(+--negative-control): PASSmake ARCH=arm64 LLVM=1 W=1 KCFLAGS="-Werror"ondrivers/mfd/macsmc.o,drivers/soc/apple/sleep.o,drivers/pci/controller/pcie-apple.o,drivers/net/wireless/apple/centauri/t6050/: 0 warnings, 0 errorsgit diff 5a5531a6e45b..04228e796271 -- drivers/ include/ | ./scripts/checkpatch.pl --strict --no-signoff -: 0 errors, 0 warnings, 0 checks (1376 lines checked)./scripts/checkpatch.pl --strict --no-signoff --git 5a5531a6e45b..04228e796271: on the first 3 commits (cb8fd175d548,ca94dc057ee6,0960ced52724),0errors,1commit-description>75-col warning each,0checks; on04228e796271,1commit-description>75-col warning plus1error,82warnings,6checks intools/asahi/centauri-physical-recovery-tests.c(total1error,83warnings,6checks: space indentation / line length / single-line statement in test fixture)J716c (M5 Max) Hardware Verification
Clean production build at
04228e796271(default command line, no debug knobs):wlan0(192.168.1.110) associated on 5240 MHz:ping -I wlan0 -c 5 192.168.0.97: 5/5 received, 0% loss, avg 4.216 msping -I wlan0 -c 3 192.168.0.1: 3/3 received, 0% loss, avg 2.510 msiw dev wlan0 scan: returned 2.4 GHz and 5 GHz SSIDs cleanlyiw reg set US: appliedcountry US: DFS-FCC, 0firmware country update failedbtmgmt info:hci0powered ssp br/edr le secure-conn cis-centralnmcli dev disconnect wlan0 && nmcli dev connect wlan0: re-associated cleanly, post-reconnectping -I wlan0 -c 3 192.168.0.973/3 (0% loss)dmesg: 0Oops/BUG:/WARNING:/Call Trace/firmware country update failedsystemctl --failed: 0 new failed units (only pre-existingaurora-peripherals.service)Earlier fault-injection build (
04228e796271+ temporary local fault hook, prior to clean04228e796271build):injected-transient): loggedchecking again in 2 s->N1 firmware fault cleared; no restart.injected-stalled): warm reset ->link up again after the sleep in 293 ms.injected-stalled): warm reset ->link up again after the sleep in 288 ms.PM: suspend entry (s2idle)): aborted atdwc3-apple 382280000.usb: PM: device_prepare(): genpd_prepare returns -11(PM: suspend exit; not a committeddeepsleep).injected-stalled): warm reset ->link up again after the sleep in 288 ms.N1 firmware stopped again after 3 restarts in 30 min; leaving Wi-Fi downwith no 4th restart.