Skip to content

thunderbolt: apple: let T6020/T6021 DP IN tunnels wait for a display pipeline - #2790

Open
RyanTheTide wants to merge 3 commits into
mainfrom
prfix/t6020-dp-in-retry-r2-20261122
Open

RyanTheTide wants to merge 3 commits into
mainfrom
prfix/t6020-dp-in-retry-r2-20261122

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A T6020/T6021 DP IN tunnel can hit a busy display pipeline after resume. The connection manager keeps the tunnel through the DPRX timeout, but the monitor stays dark because no retry is scheduled.

Change

Enable capacity retries for T6020/T6021. The existing sleep prepare path pauses retries for gated policies. On a full wake, non-deferred policies resume before the Thunderbolt domain completes, while deferred policies resume afterward. NHI teardown pauses the adapters before draining work so an in-flight attempt cannot rearm a retry.

Supersedes #2636. Thanks to nekolyanich for finding, fixing and testing the issue.

Testing

Arm64 KUnit at 921e43db230d8: 37/37 DP IN lifecycle tests passed. Across both Apple suites, 39 passed and one unrelated mailbox test was skipped. Host-test CI passed.

Still to run

Native T6020/T6021 dual-display resume on the default command line, plus boot, resume and active-tunnel NHI unbind/rebind regression rows on T8112 and a deferred-policy host.

Earlier hardware qualification

The earlier J416s hypervisor run exercised Thunderbolt and USB-C/HDMI displays together and recovered the monitor after 5 of 5 resumes across three boots, with 0 DPRX timeouts. This used a test DT and pm_test=platform. The native qualification will exercise real s2idle and report DPRX timeouts, SELinux denials, failed units and new kernel errors.

apple_dpin_m2, the T6020/T6021 (M2 Pro/Max) ACIO policy, leaves
capacity_retry off "pending M2 hardware qualification". A DP IN tunnel
that finds no free display pipeline gets -EBUSY once and that is final
("dpin0: DP tunnel setup failed: -16"). The connection manager keeps
the tunnel through the DPRX timeout (TB_HOST_DP_KEEP_DPRX_TIMEOUT), but
nothing asks for a pipeline again, so the display stays dark.

On a MacBook Pro 16" M2 Pro (j416s) with a monitor on a Thunderbolt
cable and a TV on a USB-C to HDMI adapter (DP Alt Mode), the fabric
moves the TV to dcpext1 at boot and gives the tunnel dcpext0. After a
system resume the TV comes back first on dcpext0 and the tunnel's
request is refused. The fabric moves the TV to the other pipeline
a few seconds later, too late for a request that is not retried.

Set capacity_retry on apple_dpin_m2. A refused tunnel then waits as on
M1: the DP IN work arms its retry and routes the tunnel once a pipeline
comes free. M2 needs no dp_tunnel_awaits_display hook, which is set up
for the APPLE_DPIN_CHANGED flow only: KEEP_DPRX_TIMEOUT already keeps
its tunnels. As on M1, -EAGAIN waits too: an attempt that prepare cut
short returns it and has to ask again after complete. A DCP service
that is never published then waits until unplug, with a 120 s readiness
wait per retry, where it used to fail once.

Pause these retries across system sleep and at NHI removal. The PM gate
(apple_dpin_pause_retries(), apple_dpin_resume_retries(),
apple_dpin_end_pm_gate()) now applies wherever the policy has
capacity_retry or defer_new_bringup, not defer_new_bringup only.
apple_nhi_prepare() already pauses the retries of a gated policy on
every sleep, so a waiting M2 tunnel stops asking at prepare, as M1 and
M3 do. Its pause ends when complete starts, before tb_domain_complete():
every device has resumed by then, and the tunnel that the domain's
complete brings back makes its first attempt there, since M2 does not
defer it. Its retries then run from the refusal on, as before, and do
not wait for the end of complete, which can take seconds. Policies with
defer_new_bringup (M1, M3 and later) still resume after
tb_domain_complete(), as before. Without the gate a waiting M2 tunnel
would keep calling into appledrm on the non-freezable dp_wq while the
DCPs power off, and after the NHI is removed. M2 does not get
defer_new_bringup: that would defer every first M2 handoff across sleep,
which has not been tested, and DPRX retention for a deferred handoff
goes through the hook M2 does not install.

apple_dpin_end_pm_gate() now pauses both adapters before it drains
them, as apple_dpin_pause_retries() does: work in flight at NHI removal
could otherwise get -EBUSY and rearm the retry it had just cancelled.
On M1 this is the only change: a bring-up in flight at NHI removal is
deferred and then dropped instead of attaching. Base M2 (T8112) uses
apple_dpin_m1, and M3 is unchanged.

Update the comments above apple_dpin_work_fn() and
apple_dpin_pause_retries(), which named M1-family hosts. Tests: the M2
row of apple_dpin_all_policy_fields; the t602x rearm trace, whose -EBUSY
now waits and recovers; the capacity trace run for M2 as well; terminal
errors end an M2 wait; apple_dpin_m2_capacity_suspend (pause, resume, a
refusal after the pause has ended, resume with no pause, -EAGAIN under
pause, unplug while waiting, end of the gate).

In omacom/linux-aurora, commit 068fd09 ("thunderbolt: apple: let
T6030 DP IN tunnels wait for a display pipeline") restores the same
flag for M3 after the #139 merge dropped it; M2 never had it.

Testing: j416s, DCP firmware 13.5, under the m1n1 hypervisor,
pm_test=platform, with a bench-only DT change that keeps the
hypervisor's USB-C port out of the DCP routes. Monitor and TV: the
monitor came back after 6 of 6 resumes with this change (0 of 2 without,
on aurora 7.3 ac6b017, same thunderbolt and appledrm code), routed
6.2-6.5 s after the refusal and 3.4-3.8 s ahead of the DPRX timeout; no
DPRX timeout, no kernel WARNINGs. Monitor alone: back after 4 of 4
resumes, no wait. KUnit apple-dpin-lifecycle 35 of 35.
Not tested: natively, a suspend while a tunnel waits (KUnit only),
j414s, j414c, j416c, other firmware, a wait past the DPRX timeout, NHI
removal while waiting.

Signed-off-by: nekolyanich <me@nekolyanich.com>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 921e43d (non-author, draft). No blocker found in the code; ready once the native rows listed in the description are in.

  • Merges cleanly onto integration/aurora 6748d83. One commit, human sign-offs only. thunderbolt: apple: let T6020 DP IN tunnels wait for a display pipeline #2636 is closed, no other open PR touches this policy.
  • The policy is selected by the block's compatible (apple_dpin_m2), and the new gate is a policy predicate (apple_dpin_pm_gated(): capacity_retry || defer_new_bringup), so nothing is keyed on a board. M1, M3, M4 and T6050 policies all have defer_new_bringup, so for them pause/resume/complete take the same branches as before; the only change they see is the extra PAUSE pass in apple_dpin_end_pm_gate().
  • State machine with capacity_retry and no defer_new_bringup (the new combination): -EBUSY/-EAGAIN go to WAITING_PIPELINE and arm the retry only when not paused; PAUSE never sets deferred_first; apple_dpin_admission_blocked() stays false, so a first attempt during resume is still made; RESUME rearms a waiting tunnel. I found no path that leaves a waiting M2 tunnel paused: prepare failure calls apple_dpin_resume_retries(), complete runs for every prepared device, and a dark wake is paused again by the next prepare.
  • apple_dpin_end_pm_gate(): pausing both adapters before cancel_delayed_work_sync() + flush_work() closes the window where in-flight work gets -EBUSY and rearms a retry that was just cancelled. tb_stop() sends the host-side deactivate for active DP tunnels before this runs, so no adapter is left alive && waiting after removal.
  • Ordering in apple_nhi_complete(): resuming M2 retries before tb_domain_complete() is consistent with M2 not deferring first attempts; the deferred policies keep the old order.

Small points, not blocking:

  • Behaviour change on M2 that the message only half says: with the pause now set on M2, apple_dpin_connect() gives up a readiness wait (-ENODEV/-EAGAIN from the display side) as soon as paused is seen, where it used to keep polling through the resume. That attempt now becomes a wait and is retried APPLE_DPIN_RETRY_MS after complete. Worth one line in the row: time from resume to "DP tunnel up" with and without the change on a single-display resume.
  • A display service that is never published now keeps one ordered dp_wq busy for up to 120 s per retry, every 2 s, until unplug. The other DP IN adapter of the same port queues behind it. The message says so; a row with a two-display dock where one pipeline never comes up would show whether the second display's plug/unplug is delayed.
  • Rows still open, as listed: native T6020/T6021 dual-display s2idle on the default command line (the existing run was under the hypervisor with pm_test=platform and a test DT), suspend while a tunnel is waiting, NHI unbind/rebind with an active and with a waiting tunnel, and a regression row on a T8112 and on one deferred-policy host.
  • The title says T6020; the policy also serves T6021 (and whatever else selects apple_dpin_m2).

Assisted-by: LLM (Claude:Opus 5.5)

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide RyanTheTide changed the title thunderbolt: apple: let T6020 DP IN tunnels wait for a display pipeline thunderbolt: apple: let T6020/T6021 DP IN tunnels wait for a display pipeline Dec 5, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Updated: merged main @f02bd68a08cb (1734aa5, clean; main's changes to apple.c and apple-dpin-test.c auto-merged). Title now says T6020/T6021, since the policy (apple_dpin_m2) serves the apple,t6020-usb4-acio hosts on both, as the review noted. No code change.

Local: aurora_defconfig (RUST off) LLVM=1 ARCH=arm64 W=1 build of thunderbolt apple.o, apple-dpin-state.o and apple-dpin-test.o (CONFIG_USB4_APPLE_DPIN_KUNIT_TEST=y): no compiler warnings. The DP IN KUnit suite runs in CI.

Still needed (queued in HWROWS): the native T6020/T6021 dual-display s2idle row on the default command line (we have no M2 Pro/Max in the lab), with the resume-to-tunnel-up time the review asked for, suspend with a waiting tunnel and NHI unbind/rebind; plus regression rows on J473 (T8112) and J616s (a deferred-policy host).

@RyanTheTide
RyanTheTide marked this pull request as ready for review December 5, 2026 01:29
@RyanTheTide
RyanTheTide requested review from a team as code owners December 5, 2026 01:29
@github-actions github-actions Bot added area:usb Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 5, 2026
@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Merge readiness at 869e4f5e: not ready yet

Check Detail
CI at head ok 9 checks passed
Review no approved by aurora-silicon-review, but GitHub does not count it yet (code owner from Core, Omarchy Mac or Aurora Maintainers needed, or approval went stale)
Requested changes ok none
Hardware row at head no no line with the head SHA 869e4f5e, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:usb

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 869e4f5

Checked: The exact M2 suspend state test passed 26 assertions under GCC and Clang in a host replay. It covers capacity refusal, pause and retry, early resume, interrupted readiness wait, unplug and removal. The NHI path pauses both adapters before cancelling delayed retry and draining work, and the deferred policies still resume after domain complete. The M2 tunnel keeps the existing DPRX retention policy.

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

area:usb Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant