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 4 commits into
mainfrom
sweep/delays-soc-atc
Draft

RyanTheTide wants to merge 4 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 <ryan@aurorasilicon.org>
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 <ryan@aurorasilicon.org>
@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 <ryan@aurorasilicon.org>
@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.

# Conflicts:
#	drivers/phy/apple/atc-test.c
#	tools/asahi/atc-usb3-tests.py
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Draft sweep 12-05: merged main @ f02bd68 (aca4e95). Conflicts were only in the tests: atc-test.c keeps this PR's generation-scope case next to main's new atcphy_test_idle_power_off_dt; the host harness takes main's new hw fields (pipe_lock_unacked, no_ss_device), allows main's 6000 us T8132 lock window next to the 1 ms and 100 ms ones, and keeps main's new mutations while dropping the three that targeted the removed retry loop (no-live-retry, retry-later-generations, sleep-after-last). atc.c merged cleanly; atcphy_pipehandler_lock() keeps main's pipe_lock_unacked and T8132 paths.

Local: tools/asahi/atc-usb3-tests.py --mutations 40 cases pass, 66/66 mutations killed; run-host-tests.py --only apple-dcp 12/12, --only atc 22/22; arm64 LLVM W=1 build of drivers/phy/apple/ clean (only main's existing kernel-doc warnings).

Still a draft: the 11-23 review's hardware ask (repeated USB3 <-> DP-alt changes with a linked SuperSpeed device on both J473 ports and a J413 port, SuperSpeed back after s2idle with the cable attached, plus M1 Pro) is queued in HWROWS-QUEUE; it leaves draft once that row is in.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Hardware row at exact head aca4e954e21c on the M1 Pro (J316s): PARTIAL (regression only).

  • No USB device or DP-alt adapter is attached to this Mac, so the SuperSpeed link and the adapter swaps were not run.
  • Over boot, 3x s2idle and 3 warm reboots of the test kernel: 0 Pipehandler lock not acked / Failed to switch PIPE / atcphy_mux_switch lines; all four Type-C ports present.
  • Still needed: the J473/J413 swap rows with a USB3 device and an adapter.

How: one combined test kernel for six PRs, not this PR alone. Kernel 7.3.0-aurora-ci = main d0684a06 + merge commits of linux#2804 95b14b2c, #3913 35141126, #2802 fd2472c2, #2403 aca4e954, #1814 775f31d2, #2398 75b30c6c (all merged clean, test commit 837c6334, cloud build https://github.com/aurora-silicon/linux/actions/runs/47474056828). Booted as a one-shot on the lab M1 Pro (J316s, T6000, 13.5 stub) with this kernel's own DTBs in a trial Stage 2 (live aura 1.0.0b19 + U-Boot, only the DTBs swapped), default cmdline. Boot health on the test kernel: 0 error-level kernel lines (base 0), 0 AVC, 0 failed units. Saved default restored after.

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