Skip to content

phy: apple: atc: one held PIPE lock for the live USB3 handoff, on every T8103-generation PHY - #2403

Draft
RyanTheTide wants to merge 3 commits into
mainfrom
sweep/delays-soc-atc
Draft

RyanTheTide wants to merge 3 commits into
mainfrom
sweep/delays-soc-atc

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

drivers/phy/apple/atc.c:1390 (0287dbe, bb71dfa): before a lane change, a live USB3 PIPE is parked under the PIPE handler's lock. On base M1 the lock was asked for up to ten times. Each request was polled for 1 ms, dropped, and followed by usleep_range(5000, 10000). bb71dfa also limited this whole handoff (live park, no host BIST, early dwc3 role) to an apple,t8103 machine. The reason given was qualification, not a hardware difference.

Change

  • One request, held, with the ACK polled for 100 ms in 100 us steps. That window covers the same span as the ten tries. The ACK is the controller's own signal that it has released the PIPE. Dropping and re-asking adds nothing to wait for.
  • If the controller is held in reset or clamped (PIPEHANDLER_AON_GEN), it clocks no ACK. The lock is then refused at once.
  • The handoff is now selected by the PIPE handler generation (atcphy_hw_t8103), not by the machine compatible. T600x, T8112 and T602x DTs list "apple,t60x0/t8112-atcphy", "apple,t8103-atcphy" and bind the same hardware row. T8122, T8132, T8140 and T8142 are a different generation and stay out.

The handoff is Chris Kearney's work, following milijan's AsahiLinux/linux#503.

Testing

  • make W=1 drivers/phy/apple/atc.o with the release config: builds, no new warnings.

  • tools/asahi/atc-usb3-tests.py --mutations (host harness that compiles the real driver bodies): 39 cases pass, every mutation is killed. The harness was updated in the same commits (single-request cases, held-controller case, generation admission).

  • KUnit admission case updated (atcphy_test_t8103_usb3_generation_scope). KUnit was not run.

  • Hardware (one-shot test kernel 7.3.0-aurora-swl1 = integration 0abc2f3 + this and the other open sweep PRs, 2026-11-20):

    • T8112 J413 and T6000 J316s (first runs of the generation-keyed USB3 handoff): boot + 20 s idle + 3 s2idle cycles (rtcwake, ~20 s each, rc=0): 0 kernel errors, 0 SError, 0 failed units, 0 AVC; 0 'Pipehandler lock not acked' / 'Failed to switch PIPE' / atcphy errors. No SuperSpeed device was attached, so the 5000M + DP-alt switching row is still to run.

Still to run

  • M1 Pro (T6000 J316s) and M2 (T8112 J413): with a SuperSpeed device on a Type-C port, lsusb -t shows 5000M. Then switch that port between USB3 and a DP-alt adapter three times. dmesg must show no Pipehandler lock not acked, no Failed to switch PIPE, and no WARN from atcphy_mux_switch, and USB3 must come back at 5000M. Then s2idle three times (rtcwake -d rtc1 -m freeze -s 20) with the device still enumerated at 5000M. These are the first rows of the handoff on these SoCs, because the second commit enables it there.
  • Neo and J616s: not reached (other PHY generation or driver). Run the usual USB rows as a no-change check.
  • Base M1, M1 Max/Ultra, M2 Pro/Max/Ultra: not in the fleet. Same apple,t8103-atcphy row and PIPE handler as M1 Pro/M2. If the M1 Pro or M2 row fails, drop the second commit.
Commits
  1. phy: apple: atc: hold one PIPE lock request for a live USB3 handoff. Behaviour changes only on base M1.
  2. phy: apple: atc: take the USB3 handoff on every T8103-generation PHY. Widens the handoff to M1 Pro/Max/Ultra, M2, M2 Pro/Max/Ultra. Can be dropped on its own.

Before a lane change, a live T8103-generation USB3 PIPE is parked on the
dummy backend under the PIPE handler's lock. The lock was asked for up
to ten times: each request polled for 1 ms, dropped, then
usleep_range(5000, 10000) before the next.

The ACK is the controller's own signal that it has let go of the PIPE.
Dropping the request and asking again adds nothing it waits for. Ask
once, keep the request up, and poll the ACK for 100 ms, the span the ten
tries covered. Poll in 100 us steps over a window that long.

A controller held in reset or clamped (PIPEHANDLER_AON_GEN) clocks no
ACK. Refuse the lock at once then, instead of waiting out the window.

Update the host harness (tools/asahi/atc-usb3-tests.py): the retry cases
become single-request cases, a held controller is never asked, and the
mutations follow the new body. 39 cases pass and every mutation is
killed.

The handoff is Chris Kearney's, after milijan's AsahiLinux/linux#503.

Fixes: 0287dbe ("phy: apple: make legacy USB3 handoff completion retryable")
Signed-off-by: Ryan Murray <[email protected]>
The USB3 handoff of the T8103-generation PIPE handler parks a live PIPE
under a held lock before a lane change, skips host BIST, and routes USB3
for an early dwc3 role once Type-C asks for it. bb71dfa admitted it
only on an apple,t8103 machine, because M1 Pro/Max/Ultra, M2 and M2
Pro/Max/Ultra had not been qualified.

Those SoCs bind the same apple,t8103-atcphy fallback and get the same
PIPE handler (atcphy_hw_t8103). The handoff is a property of that block,
so select it by the PHY generation, as 0287dbe first did. T8122,
T8132, T8140 and T8142 PHYs are another generation and stay out.

Update the KUnit admission case and the host harness to the generation
rule; the mutations that equated machine and generation become
equivalent and are dropped.

Fixes: bb71dfa ("phy: apple: restrict the USB3 handoff workaround to base M1")
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 2.

  1. drivers/phy/apple/atc.c:545 and :1379: USEC_PER_MSEC is not defined in the apple-dcp selftest host fixture, which compiles these function bodies. The host-tests job fails 11 cases on this head: pm-ownership, controller-lifecycle, usb-unreachable, parking, adverse-retry, masked-context, off-hardening, warm-reset, pipe, probe-mux-pm-dispatch and dwc3-teardown. Each fails with host.c: error: use of undeclared identifier 'USEC_PER_MSEC'. I reproduced this locally from the head tree. With the two uses replaced by 1000U, all 88 apple-dcp cases pass, so the behaviour change itself does not break those fixtures. Fix: define USEC_PER_MSEC in the apple-dcp host prelude (tools/testing/selftests/drivers/gpu/apple-dcp/), or spell the constants without it.
  2. Commit 2 (atc.c:6900-6903) widens the handoff to T600x, T8112 and T602x PHYs. On those SoCs that changes three things: no host BIST on the USB3 route (:1949), an early dwc3 role routing USB3 while the mode is still OFF (:4709), and the live park before every USB3-to-DP lane change (:6010). Selecting by PIPE handler generation instead of the machine compatible is the right shape. But none of the three paths has run on M1 Pro or M2 with a SuperSpeed device attached: the rows so far are idle and s2idle only. This needs the row below before the second commit can merge.

Commit 1 is sound. atcphy_pipehandler_lock_live() is reached only from atcphy_park_live_t8103_pipehandler() (:2014), so the 100 ms window and the AON_GEN early refusal do not touch the T8122/T8132/T8140/T8142 lock paths. The caller restores the overrides on the early -ETIMEDOUT too. Commits carry a human Signed-off-by with no agent trailers. The body ends with the Assisted-by line.

Nit: the IS_ENABLED(CONFIG_PHY_APPLE_ATC_KUNIT_TEST) guard around KUNIT_STATIC_STUB_REDIRECT (:1416) is redundant, because the macro is already a no-op without KUnit.

HW row: on this head, M1 Pro J316s and M2 J413, each with a SuperSpeed device on a Type-C port. lsusb -t shows 5000M. Switch between USB3 and a DP-alt adapter 3 times: USB3 comes back at 5000M, with no "Pipehandler lock not acked", no "Failed to switch PIPE" and no WARN from atcphy_mux_switch. Then 3 s2idle cycles on rtc1 with the device still at 5000M. Pass criteria: 0 AVC, 0 failed units, no new kernel errors. Also run KUnit phy-apple-atc*.

Assisted-by: LLM (Claude:Opus 5.5)

The live PIPE lock window in drivers/phy/apple/atc.c is written with
USEC_PER_MSEC. The host units that compile the extracted atc.c bodies
had no definition, so eleven cases stopped building:

  host.c: error: use of undeclared identifier 'USEC_PER_MSEC'

(pm-ownership, controller-lifecycle, usb-unreachable, parking,
adverse-retry, masked-context, off-hardening, warm-reset, pipe,
probe-mux-pm-dispatch and dwc3-teardown).

Define it, with the kernel's value from include/vdso/time64.h, next to
the usleep_range() stub in the three phy.py preludes and in
dwc3/prefix.c. The driver keeps the named constant.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Host-test blocker fixed in 1adc1d7: the atc host preludes (three phy.py preludes + dwc3/prefix.c) now define USEC_PER_MSEC like include/vdso/time64.h; atc.c is unchanged.

Testing: apple-dcp phy group 5/14 -> 14/14, lifecycle 33/35 -> 35/35 (the 11 failing cases); run-host-tests.py --only apple-dcp 88/88 TAP ok; --only atc 5/5 incl. atc-usb3-tests --mutations.
Still to run: KUnit, M1 Pro (J316s) + M2 (J413) SuperSpeed + DP-alt rows.

@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.

Independent source review at 1adc1d7acc1c. The PHY-compatible selector expands this path to the M2, where the posted tests had no SuperSpeed consumer. Please verify repeated USB3 ↔ DP Alt Mode changes with a linked device on both J473 ports and a J413 port, and confirm SuperSpeed re-enumerates after s2idle while the cable remains attached.

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