Repository navigation
thunderbolt: apple: recover a USB4 port whose peer went away (pre-discovery events, recheck, slow retry) - #1245
RyanTheTide wants to merge 6 commits into
Conversation
The router firmware gives up on a link whose sideband drops during
training: it logs "SBX disconnected!", enters its Dead End state and
waits for the host to power the port off ("ACIO was not powered off
after N seconds in Dead End state"). Nothing tells the driver, so the
port stays dead until the cable is replugged.
The J616s (T6040) gets there on about every second reboot while the M2
on the other end of the cable is still recovering from the dropped link:
the M2's router retrains its lanes a minute later, but the J616s never
tries again.
Check the domain 20 s after a start with a USB4/Thunderbolt cable. When
no remote discovery exchange has happened since the start, power the
port off and start it again, up to five times per cable connection. A
cable unplug resets the count. Can be turned off with link_watch=N.
Link: #1230
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The first version only looked once, 20 s after a start. The J616s also ends up in its router's Dead End state when the partner goes away while linked: the M2 rebooting gave 'host disconnected' and then 'Port Group - entering Dead End state', and the link never came back after the M2 was up again. Check every 20 s while a USB4/Thunderbolt cable is applied, and also after resume, whether the domain has a partner (a device router or an XDomain host on a root lane adapter). Without one, restart the port: five times 20 s apart, then every 120 s for as long as the cable is in. A partner found resets the count. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
|
TB3 results on test kernel tb3e (fleet36 + #1244 + both watchdog commits), which watches every 20 s and after resume:
Staying draft until a run shows a restart bringing the link back. |
|
TB3 09:10-09:25 on fleet42 (both Macs), with the M2 power-cycled and healthy:
Result: the watchdog is safe (0 false restarts across 17 reboots and partner reboots) and its restart path is clean (forced test 04:20). A restart bringing the link back from the non-recovering Dead End has still not been shown, so this stays draft. A repro needs a partner that stays absent longer than a reboot. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Codex (GPT-6.1 Sol), on @DjDeveloperr’s behalf, relaying the requested maintainer design direction from Ryan via his delegated agent in Aurora Agents coordination.
The link watch should invoke one provider-owned recovery operation: a T6040 router restart, or board-gated J775c PD recovery. Timeout owns escalation, with deterministic/testable behavior; remote activity resets the timer rather than owning escalation. Board-specific port-graph data remains with its owners, including Erik for J775c; no values are inferred here.
This answers the proposed recovery-interface coordination question. Implementation review and this PR’s existing hardware requirement—a restart demonstrably restoring a stuck link—remain separate. No source changes, new hardware run or merge approval are made by this relay.
|
More detail on the recovery design, checked against integration/aurora. The watch here shouldn't restart the router itself. It should call typec_thunderbolt_switch_notify(), the same path apple_cio_link_lost_work() uses today, so the event lands in cd321x_tbt_notify() and the PD driver owns the recovery. That driver keeps one escalation ladder per port. Router restart first, and if restarts don't bring the peer back, the board-gated unlock and disconnect for J775c and J716c, from a per-board key table that cd321x_reset_inherited_connection() grows into. One counter and one timer, and nothing fires while suspend/resume recovery has the port (sleep_phase != APPLE_CIO_SLEEP_OPEN or resume_recovery_failed, the same checks link_lost_work makes now). For escalation, the remote activity check makes the call, as it does in link_lost_work. The delay (APPLE_CIO_LINK_LOST_MS) only sets when we look again. If there's still no remote activity once the restart budget (APPLE_CIO_LINK_LOST_CYCLES) is spent, move to the next step. Any remote activity resets the budget, like apple_nhi_link_lost() does with link_lost_cycle_activity. KUnit can drive remote_activity directly, so this stays deterministic to test. Right now the ladder stops after the third restart ("leaving the port alone"), so the unlock/disconnect step is the new part. |
|
Closing: the restart watch needs a module switch and a fixed timer; integration's link-lost recovery is the place to handle a non-recovering Dead End if it comes back. |
|
Reopened and kept as a draft; the comment above lists what it still needs before review. cc @niteria |
After an awake USB4 link loss, the host restarts ACIO and the NHI. If the new domain comes up without discovering a peer, there is no unplug notification to schedule the next attempt. A K114s link loss exhausted only the first of the available restart attempts this way. Remember the cable parameters for a short recovery window and check for a peer after a successful restart with the same parameters. Schedule the existing generation-checked worker and keep its three-attempt budget. A system sleep cancels the outstanding awake check. Signed-off-by: Ryan Murray <[email protected]>
A host router lane adapter can report unplug events while its link is still training, before any peer was discovered. The J616s sent three of them while the router firmware gave up on the link and entered its Dead End state. The handler dropped those events, so the Apple NHI never got the link-loss callback that restarts the port. Pass them to the existing host link-loss hook as well. Only host router null adapters reach the callback, and the NHI's own restart budget applies. Signed-off-by: Ryan Murray <[email protected]>
After a peer drops the link with the cable still attached, the port is restarted three times, 3 s apart, and then left alone. A partner that is rebooting answers later than that: a J616s whose M2 partner rebooted stayed in the router firmware's Dead End state until the cable was replugged, although the M2 was back a minute later. Once the three restarts are spent, keep restarting the port every 120 s for as long as the cable stays attached. A found peer, a cable change or a system sleep ends the slow retry; link_slow_retry=N restores the old behaviour. Link: #1230 Signed-off-by: Ryan Murray <[email protected]>
The branch's 11-24 link watchdog no longer applies to main, which has its own link-loss restart budget since #3109. Replace it with three commits on current main: pass link-loss events seen before peer discovery to the NHI, recheck the peer after a requested restart, and keep restarting the port slowly while the cable stays attached.
|
Baseline on current main before asking for review (J616s on the Edge build of main 933f822, no commits from this PR): the J473 on the J616s Left Back port was rebooted with the cable left in. The J616s router reported "SBX disconnected" and Dead End, main's restart ran, the router firmware kept retraining, and the link came back by itself about 31 s later (XDomain partner found again, no replug). So the reboot case from #1230 is already handled on main; commit 3 (slow retry) has no reproducer right now. This stays a draft until a failure that main does not recover is captured (the K114s awake link loss that commit 2 describes is the candidate). Commit 3 will be dropped from the series if no such case turns up. |
What
Recover a USB4 port whose peer went away while the cable stays attached, on current main (which already restarts such a port three times, 3 s apart, since #3109):
thunderbolt: notify host link loss before peer discovery: unplug events on a host router lane adapter that arrive while the link is still training (no peer discovered yet) now reach the NHI's link-loss hook. The J616s sent three of these while its router firmware entered Dead End; main dropped them.thunderbolt: apple: Recheck the peer after a port restart: after a requested restart that comes up without a peer, schedule the existing generation-checked check again (an absent peer cannot raise a new event).thunderbolt: apple: keep retrying a port whose peer stays away: once the three fast restarts are spent, restart the port every 120 s while the cable stays attached. A found peer, a cable change or a system sleep ends it;link_slow_retry=Ngives the old behaviour.The branch's old 11-24 watchdog commits are superseded by these (merged in without a force push; the diff against main is only the three commits above).
Tested
drivers/thunderbolt/apple.o+tb.o,checkpatch --strict0/0/0 on all three commits.Risk
Not yet