Skip to content

drm/apple: dcp: give each Type-C reconnect request its whole budget - #2364

Draft
RyanTheTide wants to merge 1 commit into
mainfrom
hack/drm-connect-retry
Draft

RyanTheTide wants to merge 1 commit into
mainfrom
hack/drm-connect-retry

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

dcp_typec_reconnect_work() (drivers/gpu/drm/apple/dcp.c, added in ef24bbb "drm: apple: recover Type-C displays across link interruptions" by DjDeveloperr) connects the DPTX link of an attached Type-C display and, when that fails, re-arms itself up to DPTX_RECONNECT_RETRIES (5) times, 1 s apart, then logs "Type-C DPTX reconnect failed after N retries".

The attempt counter typec_reconnect_tries was reset by some of the paths that queue the work (attach, DPMS power-on, a port announced by a native external processor, a Thunderbolt tunnel, the bounded display retry) but not by others (component bind with a cable already routed, an ext26 layout stop, a failed connect of an attached display). The work also counted without the hpd_mutex the resets are made under. A request from a non-resetting path, after an earlier ladder had used its attempts, got one attempt instead of five.

A J700 (MacBook Neo) log shows this after s2idle: a ladder ends with "after 5 retries: -110" before suspend, and the first reconnect after the wake makes a single attempt and stops with "after 6 retries: -110".

Change

  • dcp_queue_typec_reconnect_locked(), which every request goes through, resets the counter. The work keeps re-arming itself directly with mod_delayed_work(), so its retries count against the request that started them. Nothing reachable from the work queues a new request, so the ladder stays bounded.
  • The work counts a failure, and decides whether to re-arm, under hpd_mutex.
  • The two resets callers did just before queueing are dropped.
  • The final message reads "failed after N attempts", which is what N counts.

The retry ladder itself stays: it runs only after a reported connect failure (link-configuration timeout, link fault, service not published), each attempt's failure is logged by the connect path, and running out is a dev_err.

Testing

  • arm64 LLVM build of drivers/gpu/drm/apple/dcp.o with W=1 on the release config: 0 warnings.
  • tools/testing/selftests/drivers/gpu/apple-dcp host suite: 88/88 ok.
  • KUnit not run: the apple DRM KUnit suites run on target only (no UML/QEMU config for them) and none covers the reconnect work.

Still to run

Hardware rows
  • Neo (T8140 J700), USB-C DP monitor: boot, dmesg | grep -c "Type-C DPTX reconnect failed" = 0 with the monitor up. Then 3 s2idle cycles with the dock that showed the failure: any "reconnect failed" line must read "after 5 attempts" (never 6 or more), and before it there must be 5 "timed out waiting for port 0 link configuration" lines for that ladder. Expected A/B: DP-1 back after wake at least as often as on the base kernel; the 0/3 wakes of the earlier k36 row were the separate drm/apple: park the DCPEXT crossbar output for s2idle too #1723 wake bug, so compare on a kernel that has that fix.
  • J616s (T6040), USB-C DP: plug, DPMS off/on 3x, unplug/replug 3x: DP-1 up each time, 0 "reconnect failed" lines.
  • M2 (T8112 J413), USB-C DP: plug, DPMS off/on 3x: DP-1 up each time, 0 "reconnect failed" lines.
  • M1 Pro (T6000 J316s) and J616s HDMI: not on this path (no Type-C reconnect work); boot and HDMI up, as a no-regression check.

Every SoC: the counter and the work are shared by all Type-C outputs; a request that previously got its budget gets the same one, and only requests that previously inherited a used-up count change behaviour (they get the documented five attempts, or one on T8132 and the T6020 tunnel flow, as before).

Hardware rows (combined test kernel, 2026-11-20)

This change was booted in a combined test kernel: integration/aurora 0abc2f3 plus the open gate-sweep drafts plus this and the related drafts (7.3.0-aurora-hk2/pwr1/hk3). It ran once on each lab Mac (M1 Pro J316s, M2 J413, J616s, Neo J700) and was compared against the production kernel on the same Mac, using the same silent row script:

  • kernel errors, failed units and SELinux denials;
  • microphone capture byte counts;
  • camera frame counts;
  • USB speeds;
  • panel brightness steps;
  • every retry/refusal message these drafts touch;
  • 2 s2idle cycles on M1 Pro, M2 and J616s.

M1 Pro, M2 and J616s matched production on every row, apart from the new counters and lines the drafts add. The Neo row found the old-DTB display regression that #2358's follow-up commit fixes.

This PR: No external display on the lab Macs during these boots: "reconnect failed" count 0 on all four; the plug-cycle rows are still to run.

dcp_typec_reconnect_work() connects the DPTX link of an attached
Type-C display and, on failure, re-arms itself up to
DPTX_RECONNECT_RETRIES (5) times, 1 s apart, before it reports
"Type-C DPTX reconnect failed after N retries". The attempt counter,
typec_reconnect_tries, was reset only by some of the paths that queue
the work (an attach, a DPMS power-on, a port announced by a native
external processor, a Thunderbolt tunnel, the bounded display retry),
and not by others (component bind enabling the work with a cable
already routed, an ext26 layout stop, a failed connect of an attached
display). The work also counted without the hpd_mutex those resets
are made under.

A request from a path that does not reset after an earlier request had
used up its attempts gets one attempt instead of five. That is what a
J700 log shows after s2idle: a reconnect ladder ends with "after 5
retries: -110" before suspend, the first reconnect after the wake makes
one attempt and gives up with "after 6 retries: -110".

Reset the counter where every request is made, in
dcp_queue_typec_reconnect_locked(), and have the work count its
failures under hpd_mutex. The work still re-arms itself directly with
mod_delayed_work(), so its own retries keep counting against the
request that started them; nothing reachable from the work queues a new
request, so the ladder stays bounded. The resets the callers did right
before queueing are dropped. The message now counts what it counts:
"failed after N attempts".

Nothing changes for a request whose path already reset the counter,
which covers all first connects. Sessionless (H17P) work now takes
hpd_mutex once on failure, as the session path of the same work
already does, so no new lock order is introduced.

Fixes: ef24bbb ("drm: apple: recover Type-C displays across link interruptions")
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Looks good; approve once the Neo s2idle reconnect row has run on this head.

I checked that every request still goes through dcp_queue_typec_reconnect_locked() (drivers/gpu/drm/apple/dcp.c:2177-2195) and that the work re-arms only with its own mod_delayed_work() (:3529-3534). So the ladder stays bounded at limit per request. Nothing the work calls (dcp_dptx_connect*, dcp_announce_kick() at :1018, which only schedules the hotplug work) queues a new request. Moving the count under hpd_mutex closes the unlocked ++ against the locked resets at :3585 and :5101. Dropping the reset on success is safe, because every new request now resets. "after N attempts" matches tries. The commit carries only a human Signed-off-by.

  1. Nit, drivers/gpu/drm/apple/dcp-fabric.c:2181 and :3047 (dcp_tb_queue_reconnect()): these still set typec_reconnect_tries = 0 without hpd_mutex, right before dcp_queue_typec_reconnect(). That call now resets the counter under the lock itself. The writes are redundant, and they are the one unlocked writer of a field the commit message now says is counted under hpd_mutex. Drop them as you did the two in dcp.c.

HW row: the combined-kernel boots had no external display, so the reconnect work never ran. Neo (J700) on this head with the dock that showed the failure, on a kernel that has the #1723 wake fix: boot with the USB-C DP monitor up, then 3 s2idle cycles. Pass:

  • every "reconnect failed" line reads "after 5 attempts", never 6 or more, and has 5 connect-failure lines in front of it;
  • DP-1 comes back at least as often as on the base kernel.

Then one J616s USB-C DP plug x3 and DPMS off/on x3 as a no-regression row: DP-1 up each time, 0 "reconnect failed" lines. Both rows: 0 AVC, 0 failed units, no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The lock serializes writes to the retry count, but the current worker can still charge an attempt to the next request. If a new event queues an immediate reconnect while the worker is inside dcp_dptx_connect*(), enqueue resets the counter and requests zero delay. If the older call then fails, its completion increments the new counter and changes that queued work to the retry delay. The attachment/session can legitimately be the same across both requests.

I compiled the exact enqueue and worker bodies with a host stub that queues one new request inside the connect call. Both same-session and sessionless interleavings replaced the new request's immediate work and consumed an attempt. The two ordinary-retry controls passed.

A request generation under hpd_mutex lets the older worker leave the counter and schedule alone when a new request arrived. With this change the projected test passed 4/4, including the ordinary retries. Please also check the direct cancellation/reset in the synchronous power-on path when deciding where to invalidate an in-flight worker.

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.

1 participant