Repository navigation
thunderbolt: apple: opt-in port power-off for s2idle with CD321x restore (carries #92, with review fixes) - #124
Merged
Conversation
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]>
Review fixes on top of the s2idle port power-off series (#92): - Default path: with s2idle_teardown off and no restart owed from an earlier sleep, the PM notifier returns at once, and the NHI prepare callback no longer takes the domain lock to record peers unless resume_recovery is on. Before, every suspend took both locks for nothing, and a lock already stuck on a dead peer made suspend block in the notifier instead of failing at the freezer timeout. sleep_restart_owed is now written with WRITE_ONCE for that unlocked check. - CD321x stopped retrying, and set the port's PHY safe and its USB role to none, on any -ESHUTDOWN from the Thunderbolt provider. The provider also returns -ESHUTDOWN while it unbinds, which used to be retried. The port disabled for good after a failed resume recovery now returns -EHOSTDOWN, and only that stops CD321x's retries. - Resume recovery: a forced cable cycle that CD321x did not take up (it refused, or a suspend came first) left resume_recovery_active set, so a much later unrelated start got one attempt instead of five and could disable the port. The cycle now counts for 30 s, and prepare clears it. - s2idle_teardown also drops USB devices tunnelled through a USB4 dock; only PCIe tunnels are skipped. The parameter description says so. - The resume debug line read each lane's port state from the hardware, which needed tb_port_state() exported from the core. It now logs only the software state, and the export is dropped. Also drop a duplicate acio->rtk = NULL and an atomic64_set() after kzalloc(). Signed-off-by: Chris Kearney <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #92 by @maralcbr. His four commits are carried unchanged, with one review-fix commit on top. We can't push to his fork, so the fix commit is on an omacom branch.
What #92 does. All of it is opt-in and off by default:
resume_recovery: recovers a port the stock driver never rediscovers after resume, once per driver load.router_sleep: stays off; only its comment and description change.TYPEC_THUNDERBOLT_SWITCH_RESTORErequest, answered with one bounded fresh cable read, with a KUnit case.s2idle_teardown: powers off connected ports without PCIe tunnels for s2idle, and restarts them through CD321x on resume. A 10 s fallback sends the restore request.Review fixes (the last commit):
s2idle_teardownoff and no restart owed, the PM notifier returns at once, and the NHI prepare takes no domain lock unlessresume_recoveryis on.-ESHUTDOWNas terminal:-ESHUTDOWNwhile it unbinds, and that case used to be retried.-EHOSTDOWN, and only that stops the retries.s2idle_teardown's description: it now says USB devices tunnelled through a USB4 dock go too; only PCIe tunnels are skipped.tb_port_state()is no longer exported from the core.acio->rtk = NULL, and anatomic64_set()after kzalloc.Default path after the fixes. The only effect left on the shared Thunderbolt core is three counter increments in
tb_switch_alloc(),tb_switch_resume()and XDomain discovery, plus a field instruct tb. The Type-C core gains one exported function; CD321x is its only listener, and it isn't reached at default.Tests:
KUnit on the combined tree with pmgr-misc: PMP resume fix, idle fabric governor and PMP for j314s #91's carry:
apple-dpin+USB4_KUNIT_TEST): 84/84.cd321x-pm: 35/35, includingcd321x_restore_ignores_fault_budget_test.Build: release-config W=1 builds of
drivers/thunderbolt/anddrivers/usb/typec/show no warnings in the changed files.M1 Air lab job on the combined tree (Kensington TB3 dock with a 4K display): job
j1015-004326-2f04, package7.1.12-2-20261015.992built from this combined tree, passed:idle_fabric_pstate=0,s2idle_teardown,resume_recoveryandrouter_sleepall N);No external display was attached for this run, so the M1 external-pipe hold path was not driven. It returns early on t8103, because pmgr-misc is not bound there.
Author's measurements: the j314s numbers in thunderbolt: apple: opt-in port power-off for s2idle with CD321x restore #92: 21/21 wakes, aborted and back-to-back sleeps.
Keeping these opt-in is right.
s2idle_teardowndrops every tunnel on each sleep: displays, network and USB storage behind USB4.resume_recoverycan't prove a link is dead and spends a one-shot budget per load. Both have run on one t6000 only.🤖 Generated with Claude Code