Skip to content

thunderbolt: apple: recover a USB4 port whose peer went away (pre-discovery events, recheck after restart) - #1245

Draft
RyanTheTide wants to merge 8 commits into
mainfrom
tb3/t6040-usb4-resume
Draft

RyanTheTide wants to merge 8 commits into
mainfrom
tb3/t6040-usb4-resume

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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):

  1. 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.
  2. 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).
  3. (dropped 12-05) The slow 120 s retry with its link_slow_retry=N module parameter is reverted on the branch: new module parameters are not allowed, and main's 77ed855 ("check a rate-limited lost link again after the window") now re-checks a port once its one-minute restart window ends.

The branch's old 11-24 watchdog commits are superseded by these (merged in without a force push; the diff against main is now only commits 1 and 2 above).

Tested

  • Builds clean: arm64 clang W=1 drivers/thunderbolt/apple.o + tb.o, checkpatch --strict 0/0/0 on all three commits.
  • K114s (T6050) on main-based bridge kernels: a forced USB4 port restart (ACIO unbind/bind) with the EG02 TB5 enclosure attached recovers the link (TBT5 40 Gb/s x2), the PCIe tunnel and the GPU, which rebinds by itself. This exercises the restart path itself, not the new triggers.

Risk

  • Only ports with the cable attached and no peer are restarted, within main's limits (3 consecutive cycles, 3 per minute).

Not yet

  • J616s row: partner reboot (J473 on the Left Back port) with the link down for over 10 s, then link back without a replug.
  • K114s row with these exact commits.

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 <81541646+RyanTheTide@users.noreply.github.com>
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 <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

TB3 results on test kernel tb3e (fleet36 + #1244 + both watchdog commits), which watches every 20 s and after resume:

  • 10/10 J616s reboots, each right after the M2 had been in a 60 s s2idle: the link came up every time. No Dead End and no restarts: a partner that is asleep keeps its lanes and its XDomain object, so the watchdog correctly leaves the port alone.
  • 3 M2 reboots with the J616s up: the J616s logged Dead End every time, but the link came back by itself in 21-27 s, so no restart was needed.
  • Forced test: the M2 powered its port off for sleep (s2idle_teardown=Y, 75 s rtcwake). The J616s logged 'host disconnected' and Dead End, then the watchdog restarted the port 5 times 20 s apart and switched to a 120 s retry. Every restart was clean, with no oops or warning.
  • Not shown: the link coming back after a restart. The M2 hung on resume from that teardown sleep (its own experimental path), so there was no partner to return.

Staying draft until a run shows a restart bringing the link back.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

TB3 09:10-09:25 on fleet42 (both Macs), with the M2 power-cycled and healthy:

  • Control on plain fleet42 (no watchdog): 3 M2 reboots. Dead End each time, link back by itself in 20-26 s.
  • tb3f = fleet42 + this PR: link at boot first try. 4 M2 reboots, Dead End each time, link back by itself in 26 s, 0 watchdog restarts and no false restarts.
  • The firmware leaves Dead End by itself in these runs: about 3 s after it, it re-enters lane-init Phase 1. The non-recovering variant (the firmware repeating 'ACIO was not powered off after N s in Dead-End state') happened 3 times last night, but not in these 7 partner reboots or yesterday's 13.

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 DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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.

@RyanTheTide RyanTheTide reopened this Nov 22, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
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.
@RyanTheTide RyanTheTide changed the title thunderbolt: apple: restart a port that gets no USB4 link after start (J616s Dead End, #1230) thunderbolt: apple: recover a USB4 port whose peer went away (pre-discovery events, recheck, slow retry) Nov 28, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Draft sweep 12-05: still parked, nothing to push yet.

  • Blocker: no failure that main does not already recover has been captured. The 11-28 baseline on main 933f822 showed the partner-reboot case from J616s USB4: thunderbolt-net wedges after repeated s2idle; ACIO unbind oopses in tbnet_login_work #1230 recovering by itself (~31 s); the K114s awake link loss that commit 2 targets is the remaining candidate and has no reproducer row yet.
  • Commit 3 adds a link_slow_retry=N module parameter, which the production rules no longer allow (no new cmdline/module params). When this comes back it should drop commit 3 (or fold the slow retry into the provider-owned recovery op from the 11-12 design note, with no switch).
  • The head conflicts with main in drivers/thunderbolt; I am not merging main into it until there is a reproducer to prove the series against.

This reverts commit 7fad8ca.

The slow retry adds a link_slow_retry module parameter, which new code
may not add, and no failure that main does not already recover has been
captured for it: on 11-28 a J473 partner reboot on the J616s recovered
on main by itself in about 31 s. If a reproducer turns up, the slow
retry comes back inside the port recovery itself, without a switch.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Conflict in drivers/thunderbolt/apple.c: keep main's per-port one-minute
restart window (APPLE_CIO_LINK_LOST_INTERVAL, link_lost_limit, the
check again after the window) next to this branch's post-restart peer
recheck (APPLE_CIO_LINK_LOST_RESTART_MS, link_lost_retry_*).

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide RyanTheTide changed the title thunderbolt: apple: recover a USB4 port whose peer went away (pre-discovery events, recheck, slow retry) thunderbolt: apple: recover a USB4 port whose peer went away (pre-discovery events, recheck after restart) Dec 5, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Second pass 12-05 (head 6c63124): commit 3 is reverted on the branch (8fc9efe; no module parameter left) and main (ef8a1bf) is merged. The apple.c conflict keeps main's one-minute restart window and its re-check after the window (77ed855) next to commit 2's recheck after a restart that comes up without a peer; tb.c merged cleanly. Local: LLVM W=1 drivers/thunderbolt/apple.o + tb.o clean, checkpatch --strict clean on the diff against main.

Not closing it: the 11-28 baseline (main 933f822, traces/kernel/20261129-tb1245-rows/) shows main recovers the partner-reboot case from #1230 on its own (~31 s), but two link losses with the cable in are still unexplained on main-based kernels: the K114s awake TB5 link drop with the EG02 (11-28 22:13, no recovery until 22:49) and the J473 far end not retraining after the J616s deep sleep link drop (SLEEP-2215, 11-28). Neither has been run with these commits. Stays draft until one row shows a failure main does not recover and this head does:

  • K114s + EG02 on TB5, awake: drop the link with the cable in (enclosure power cycle or forced router reset), main must stay without a link for > 60 s, this head must get 1-1 back without a replug.
  • or J616s deep s2r with the J473 host-to-host peer: J473 on main vs this head, link back without a replug.
    If both come back on main too, close this as not needed.

This branch has not been deployed

No deployments
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