Skip to content

thunderbolt: apple: opt-in port power-off for s2idle with CD321x restore - #92

Merged
4 commits merged into
omacom:integration/aurorafrom
maralcbr:pr/usb4-sleep-teardown
Oct 15, 2026
Merged

4 commits merged into
omacom:integration/aurorafrom
maralcbr:pr/usb4-sleep-teardown

Conversation

@maralcbr

Copy link
Copy Markdown
Member

Summary

A connected Thunderbolt/USB4 port keeps its link trained through s2idle. On a 14-inch M1 Pro with a peer attached, that costs about 1.3 W of the 4.0 W sleep draw. This series adds an opt-in way to power the port off for sleep, plus the CD321x support it needs. Every new behaviour defaults to off.

  1. thunderbolt: apple: gate resume recovery on missing stock discovery (resume_recovery, default N). Recovers a port that the stock driver never rediscovers after resume, at most once per driver load.
  2. thunderbolt: apple: keep router sleep opt-in pending resume qualification (router_sleep stays N). Router sleep saves 1 W but lost the link on every wake in testing.
  3. usb: typec: tipd: add a sleep restore request for Thunderbolt providers. Adds a new TYPEC_THUNDERBOLT_SWITCH_RESTORE request. CD321x answers it with one bounded fresh cable read that isn't charged to the link-fault budget. Includes a KUnit case.
  4. thunderbolt: apple: optionally power off connected ports for system sleep (s2idle_teardown, default N). Connected ports without a PCIe tunnel are stopped before tasks freeze. The CD321x post-resume revalidation then restarts them with a fresh cable snapshot. A 10 s fallback sends the restore request instead of starting from state recorded before sleep.

Measurements

j314s, M4 Mac attached over Thunderbolt, 5 V input power:

  • s2idle: 4.03 W → 2.71 W with s2idle_teardown=Y.
  • 21 of 21 normal wakes with the link back and traffic flowing at +15 s, every restart through CD321x and no fallbacks.
  • 5 of 5 aborted suspends (pm_test=freezer) and 5 of 5 back-to-back sleeps with a restart still pending, link back each time.
  • CD321x KUnit: 35 of 35 pass.

Limits

  • Tunnels don't survive. The network interface and dock displays reconnect a few seconds after wake.
  • Ports carrying PCIe tunnels are skipped. Their endpoint drivers can deadlock in the PM notifier chain, and storage must not disappear under running apps.
  • Not tested yet: unplugging the cable during sleep, or a real dock.
  • Most docks charge the Mac, so this mainly helps setups that don't: non-charging docks and displays, and Mac-to-Mac links.

@iconidentify @DjDeveloperr, could you review? The CD321x restore request in commit 3 is the part I'd most like eyes on.

Observe successful stock XDomain UUID/property exchanges and remote-
router reads instead of issuing a second, sequence-sensitive UUID probe.
Snapshot activity before resume and watch only cables with a pre-suspend
peer. Fresh activity cancels the watchdog even while downstream
enumeration continues.

Keep resume_recovery disabled by default. Allow 90 seconds for peer
resume, then confirm the absence of fresh discovery three times five
seconds apart. Missing discovery suggests a stall but cannot prove a
cached UP lane dead; qualification is required before enabling automatic
recovery.

Share a single cable-revalidation budget across all ACIO instances for
the driver lifetime. Suspend and cable changes never refill it. A manual
module reload starts a new lifetime and must not be used to refill the
lab budget. Do not issue verification probes or a second revalidation
after recovery.

Try a recovery start only once. On failure, unwind children and power-
domain links, clear the RTKit handle, latch the port down and return
ESHUTDOWN. Stop CD321x's automatic retry cascade for a terminal provider
shutdown. Make OFF idempotent when ACIO never started, so later teardown
cannot dereference the absent RTKit instance. Put the PHY in safe mode
and release the USB role on a terminal provider failure. Ordinary start
retries are unchanged.

Signed-off-by: Marcelo Alcantara <[email protected]>
…tion

The j314s lab observed firmware lane-initialization timeouts with router
sleep enabled, including the first system suspend after boot. The root
lane registers remained UP, so the previous recovery detector missed the
failure. Observation of stock rediscovery and forced recovery still need
hardware qualification before changing the default on any SoC.

Leave router_sleep disabled by default, including t6000 and t6001, while
retaining explicit Y/N and runtime parameter writes for qualification.
Replace the inaccurate claim that ACIO links remain trained across
sleep.

An explicit Y clears QUIRK_KEEP_TUNNELS along with
QUIRK_NO_SYSTEM_SLEEP. tb_resume_noirq() then rediscovers, deactivates
and reactivates tunnels instead of taking the retained-tunnel path. Dock
and PCIe-storage suspend behaviour is unqualified; automatic router
sleep remains deferred.

Signed-off-by: Marcelo Alcantara <[email protected]>
A Thunderbolt provider that powers itself down for system sleep needs
the current cable state reapplied afterwards. CD321x only rereads the
cable when its own resume runs, on a link fault, or on a completed
deferred activation. Link faults draw on a small per-connection budget,
so a provider cannot rely on them for routine restores: once a session
has used its budget, the request is refused and the port stays down.

Add TYPEC_THUNDERBOLT_SWITCH_RESTORE and
typec_thunderbolt_switch_notify_restore(). CD321x answers it with one
bounded fresh read that is not charged to the fault budget, and drops
its cached state so the provider's switch is called again even when the
mode is unchanged. A port that is still prepared for sleep ignores the
request, because its own resume revalidates it.

Signed-off-by: Marcelo Alcantara <[email protected]>
…leep

A connected ACIO port keeps its USB4 link trained through s2idle. On a
t6000 MacBook Pro with a Thunderbolt peer attached this costs about
1.3 W of the 4.0 W sleep draw; with the port powered off for the sleep,
sleep power drops to 2.7 W.

Add an opt-in s2idle_teardown parameter. When set, each connected port
without a PCIe tunnel is stopped from the PM_SUSPEND_PREPARE notifier,
before tasks freeze, so the NHI and its children are removed while their
workers can still run. Ports carrying PCIe tunnels are left alone: an
endpoint driver may unregister a PM notifier on removal, which would
deadlock inside the notifier chain, and storage must not disappear under
running applications. The PCIe check and the closing of PCIe admission
happen in one critical section, so no tunnel can appear in between.

From teardown until devices resume, cable changes are only recorded.
CD321x drops its cached state in prepare and reapplies the cable state
after resume, once tasks have thawed; that call restarts the port with a
fresh snapshot of the cable, and a start failure goes back to CD321x as
an error. If no successful restart follows, as after a suspend that
aborted before devices suspended, a worker sends CD321x a restore
request for a fresh cable read: at once after an abort, otherwise after
10 s. The port is never started from the state recorded before sleep.
Only a successful start settles the restart, since CD321x also sends OFF
as an intermediate step of a reconnect; a restart still owed when the
next suspend begins keeps cable changes recorded-only again.

Apple Silicon only offers s2idle, so PM_SUSPEND_PREPARE implies it.
Tunnels do not survive: the network interface and dock displays are
removed and rediscovered after resume. The parameter defaults to N.

Signed-off-by: Marcelo Alcantara <[email protected]>
@chriskearney

Copy link
Copy Markdown

Thanks @maralcbr, this is merged through #124 with your four commits unchanged and one review-fix commit on top.

The fixes:

  • Default path: with every parameter off, the PM notifier and the NHI prepare now take no locks.
  • Errno: a port disabled after a failed resume recovery now returns -EHOSTDOWN, and only that stops CD321x's retries. An ordinary unbind's -ESHUTDOWN is retried again.
  • Recovery flag: an unclaimed recovery cycle now expires after 30 s.
  • Parameter description: s2idle_teardown now says it also drops USB devices tunnelled through a USB4 dock.
  • Core export: the debug-only tb_port_state() export is gone.

On the M1 Air with the Kensington dock, every parameter reads off, the dock's tunnel comes up and there are 0 regressions. CD321x KUnit is 35/35. Details are in #124.

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.

2 participants