Skip to content

phy: apple: atc: serve a T8132 device role on USB2 - #2434

Open
DjDeveloperr wants to merge 1 commit into
integration/aurorafrom
djdev/t8132-device-role-usb2
Open

DjDeveloperr wants to merge 1 commit into
integration/aurorafrom
djdev/t8132-device-role-usb2

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

On a T8132 port whose lanes run USB3, a device role failed. atcphy_usb3_set_mode() refused PHY_MODE_USB_DEVICE with -EOPNOTSUPP, then:

  • dwc3-apple failed the role with USB3 PHY setup failed, err=-95;
  • the SN201202x gave up with cable revalidation failed after 3 attempts.

That started once the boot loader passed the T8132 USB3 calibration (aura#113 24812c55). Before that, these ports ran USB2 only, and the device role worked on them. On the M4 Mac mini (J773g) a rear port with a host on the other end lost its USB.

SuperSpeed device mode is not supported by this driver on T8132, so this serves the device role on USB2 instead:

  • When the controller asks for the device role on a calibrated T8132 port, USB3 and pin-D USB3_DP move to USB2. Four-lane DisplayPort (pin C/E) keeps USB2 on its own wires and is unchanged.
  • t8132_device is set only after atcphy_mux_switch() and atcphy_usb3_route() succeed, and is cleared on controller role exit (atcphy_usb3_power_off() or switching to PHY_MODE_USB_HOST) rather than on SAFE/OFF mux bounces.
  • typec_mode preserves the partner's un-downgraded SuperSpeed mode so a direct device-to-host data role swap restores SuperSpeed lanes before host_active blocks T8132 lane reconfiguration.
  • Driver, KUnit (atcphy_test_t8132_device_role_usb2), and host selftest fixture updates are squashed into a single bisectable commit.

Measured on the J773g, 2026-11-19, default kernel 7.3.0-m4drv8 with this module:

  • Before: dwc3-apple 40a280000.usb: USB3 PHY setup failed, err=-95 (×3), then sn201202x 1-0a: cable revalidation failed after 3 attempts.
  • After: phy-apple-atc 40aa90000.phy: USB device role: SuperSpeed device mode not supported by driver, using USB2 (log message updated from earlier wording). No -95 and no revalidation failure; dwc3 enters device mode with run/stop set and a configfs ACM gadget binds to UDC 40a280000.usb.
  • Host-role ports, including the front fixed hub with the keyboard, are unchanged.

Assisted-by: LLM (Gemini:4 Neon)

RyanTheTide added a commit that referenced this pull request Nov 19, 2026
…ce mode

A USB3 PHY that cannot run a SuperSpeed device answers the device
request with -EOPNOTSUPP and leaves the PIPE alone. The glue already
offers the gadget at high speed for that (T6040), but on T8132 and
T6050 the check for failed host handoffs ran first and failed the role
instead. Its reason is xHCI: a failed BIST or PIPE handoff must not
start the host. That does not apply to a gadget whose USB2 PHY already
runs as a device. The T8132 ATC PHY refuses the device role while its
lanes run USB3, so a T8132 port with a USB3 calibration and a host on
the other end lost its USB (seen on the J773g, linux#2434).

Take the high-speed path for a device-role -EOPNOTSUPP on every SoC,
before that check; other USB3 PHY errors are handled as before. T6050
never gets here, its USB2 PHY has no device mode. The ATC PHYs that
answer -EOPNOTSUPP for another reason (a T8103 port whose lanes are
all DisplayPort or that has no SuperSpeed tunables) cannot carry a
SuperSpeed device either, so the high-speed gadget fits them too; they
already took this path. The T8132 selftest now expects the high-speed
gadget.

This is the generic form of the T8132 fallback in linux#2420 by
techmore, whose J773g row (a USB 3 host lists the gadget at 480 Mb/s
where the role failed before) is the hardware evidence for it. DjDeveloperr
reported the failure and serves the T8132 device role from the PHY side
in linux#2434; both changes can land.

Link: #2420
Link: #2434
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Host-tests fix pushed in de20ca2.

The failures were mine. atc-usb3-tests and the apple-dcp units around the mux, the PIPE, the role exit and the dwc3 teardown compile the real atcphy functions against their own struct apple_atcphy. They didn't know the new t8132_device field, the atcphy_t8132_device_mode() helper, dev_info(), or the call to atcphy_mux_switch() from atcphy_usb3_set_mode().

What the commit changes:

  • The field goes into every mock.
  • The helper is emitted with the target-mode mapping.
  • Units that place the mux after atcphy_usb3_set_mode() get prototypes ahead of it.
  • dev_info() gets stubbed where it was missing.
  • atc-usb3-tests gains a T8132 device-role case: USB3 goes to USB2, a later USB3 request stays USB2, and both the safe state and the host role lift it. It also gains three mutations; all are killed.

Local results, through tools/asahi/run-host-tests.py in a 2 GiB scope, base 0abc2f3:

  • atc-cio-sleep-tests, atc-usb3-tests and atc-usb3-tests --mutations pass, with 58/58 mutations killed.
  • apple-dcp passes 88/88.

My host's clang 23 adds -Wunused-but-set-variable errors in unrelated units, and does so on the base as well. I neutralised those with a wrapper for the local run only; nothing in the tree depends on it.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor

This commit is now carried unchanged in #2334 (161cf31, your authorship), as the merge train asked: one head for the device-role work.

On top of it, #2334:

  • turns the T8132 condition into a PHY capability in the match data (no_ss_device), and renames t8132_device to usb2_device;
  • adds a USB3 .validate that refuses the device role on such PHYs, so dwc3-apple sets the core up as a high-speed device (device speed and the GUCTL1 2.0 clock are controller registers the PHY can't set). That's the setup usb: dwc3: apple: keep a T8132 device role on USB2 without SuperSpeed device mode #2420's J773g row used, with a USB 3 host enumerating the gadget at 480 Mb/s;
  • moves the T6040 USB3 PHY onto the same contract.

The host-tests failure on this PR came from the ATC USB3 harness and the apple-dcp models, which compile atc.c against their own structs. A tools: commit in #2334 fixes them, and the full suite passes 427/427. ATC KUnit, including your t8132_device_role_usb2 case, passes 52/52 under qemu arm64.

Still owed: a J773g row at #2334's head (USB device role: no SuperSpeed device mode, using USB2 plus the dwc3 "gadget at high speed" line, host-side enumeration). If you're happy with that shape, this PR can be closed as carried.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train adversarial review (MERGETRAIN-LINUX2) at de20ca2: NO BLOCKERS.

Code read only, nothing built here. Before the merge it still needs Dj's verdict at this head; the missing rows are listed below.

Full review

#2434 phy: apple: atc: serve a T8132 device role on USB2 @de20ca29

VERDICT: NO BLOCKERS in the code. The PR does not prove its feature yet: no host has enumerated the gadget. Treat that as a merge gate.

Shared-code check: the new behaviour is reached only through t8132_ss (set only on the T8132 generation) and the gen == ATCPHY_GENERATION_T8132 block in atcphy_typec_target_mode(). The other hunks only clear the flag (HOST role, mux to OFF). M1/M2/M3/M4 Pro/T8142/Neo are unaffected.

Nits / risks:

  1. atc.c:5955: the flag is cleared on any atcphy_mux_switch(OFF), but dwc3 keeps the device role. This is tied to the mux, not to the role.
    • Scenario 1: device role, then the port controller sends SAFE/OFF (cable revalidation, or alt-mode entry passing through SAFE) without detaching the role. A following USB3 mux update now brings up USB3 lanes under a device-role controller.
    • Scenario 2: with the role still DEVICE, dwc3 does not call set_mode again.
    • That is the configuration the old -EOPNOTSUPP refused. Tie the flag to !host_active + role, or re-apply it in atcphy_typec_target_mode() from the controller role.
  2. atc.c:4759-4764: t8132_device is set before atcphy_mux_switch(). On failure the flag sticks while the role fails.
    • Scenario: host→device DR swap with the PIPE still in the USB3 state. atcphy_configure_t8132() returns -EBUSY at atc.c:4040ff ("pipe_state != DUMMY").
    • Every later mux update is then forced to USB2 until unplug or a host role. Set the flag only on success.
  3. atc.c:4767-4768: DR swap device→host clears the flag, but the lanes stay USB2 (typec_mode was set to USB2 at 5993). They regain USB3 only if the port controller sends another mux update, and the comment assumes one.
    • atc.c:4041 refuses a T8132 mode change while t8132_common_owned && host_active.
    • So a host role on the downgraded port may stay USB2 for the whole session: a silent 480 Mb/s host.
  4. atc.c:3640: in device role, USB3_DP (pin D, 2 DP lanes + USB3) maps to 4-lane MODE_DP when t8132_dp_alt. The partner negotiated pin D, so its SS pair expects USB3, not DP. This is untested, and USB2 (drop DP) or refusing would be the conservative mapping. The device role + DP source combination is rare, so this is a nit.
  5. "T8132 has no SuperSpeed device mode" is stated as a hardware fact in code comments and logs. No evidence is cited; it may only be a driver limitation. Reword it as a driver limitation unless there is proof.
  6. Bisect: commit aa3f0d9 alone breaks the host fixture builds (de20ca2 says so). Tools only; squash or reorder.
  7. PR body ends with the Claude Code footer, not "Assisted-by: LLM (Claude:Opus 5.5)".

Missing rows:

  • Host-side enumeration of the gadget (ACM shows up on a real host) on J773g. The only "after" evidence is the absence of the -95 error. The partner was itself in the device role, so nothing enumerated.
  • J713/J715 (Airs) and J604: device role on a calibrated USB3 port, with a real host on the far end.
  • Unplug/replug in device role, then replug as host on the same port. Does it come back at SuperSpeed?
  • DR swap device→host and host→device, with lsusb speed checked.
  • KUnit atcphy_test_t8132_device_role_usb2: built, never run (arm64 qemu or UML).

On a T8132 port whose SuperSpeed banks are calibrated, a USB device role
previously failed in atcphy_usb3_set_mode() with -EOPNOTSUPP, causing
dwc3-apple to fail setup and the Type-C port controller to give up after
cable revalidation retries.

SuperSpeed device mode is not supported by this driver on T8132, so serve
a T8132 device role on USB2 instead:

- Map APPLE_ATCPHY_MODE_USB3 and pin-D APPLE_ATCPHY_MODE_USB3_DP to
  APPLE_ATCPHY_MODE_USB2 while the device role is active, keeping
  four-lane APPLE_ATCPHY_MODE_DP (pin C/E, where USB2 uses its own wires)
  unchanged.
- Set t8132_device only after atcphy_mux_switch() and atcphy_usb3_route()
  succeed, and clear it on controller role exit (atcphy_usb3_power_off()
  or PHY_MODE_USB_HOST) rather than on mux SAFE/OFF transitions.
- Preserve the partner's un-downgraded mode in typec_mode so a direct
  device-to-host data role swap restores SuperSpeed lanes before
  host_active blocks T8132 lane reconfiguration, and subsequent
  atcphy_usb2_init() calls respect t8132_device.
- Update the KUnit test and host selftest fixtures in the same commit so
  host test builds remain bisectable.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/t8132-device-role-usb2 branch from de20ca2 to 025e7ea Compare November 22, 2026 04:59
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Updated and force-pushed as a single squashed commit (025e7ea2df1b) on integration/aurora, addressing all 7 review points:

  1. Flag tied to role vs mux: Removed clearing t8132_device on APPLE_ATCPHY_MODE_OFF in atcphy_mux_switch(); t8132_device is now cleared on controller role exit (atcphy_usb3_power_off() alongside host_active, and PHY_MODE_USB_HOST in atcphy_usb3_set_mode()) and honored in atcphy_usb2_init(), atcphy_mux_in_mode(), atcphy_mux_switch(), and atcphy_mux_update_to().
  2. Set t8132_device only on success: atcphy_usb3_set_mode(PHY_MODE_USB_DEVICE) now sets t8132_device only after both atcphy_mux_switch() and atcphy_usb3_route() succeed; failed switches leave t8132_device, host_active, and typec_mode intact.
  3. Device-to-host DR swap restores SuperSpeed: typec_mode keeps the partner's un-downgraded mode; PHY_MODE_USB_HOST with t8132_device clears the flag and calls atcphy_mux_switch(atcphy, target) before host_active = true (avoiding the t8132_common_owned && host_active -EBUSY gate) and before routing PIPE to USB3.
  4. Pin D mapping: atcphy_t8132_device_mode() maps both USB3 and pin-D USB3_DP unconditionally to USB2, leaving 4-lane DP (pin C/E) unchanged.
  5. Driver-limitation wording: Reworded comments, log output, commit message, and tests to describe a driver limitation rather than a hardware fact.
  6. Bisectability: Squashed driver, KUnit, and all host selftest fixture updates into one commit.
  7. PR description footer: Updated the PR description and footer.

Verification:

  • scripts/checkpatch.pl --strict -g HEAD: 0 errors, 0 warnings, 0 checks
  • tools/asahi/atc-usb3-tests.py --mutations: 39/39 cases passed, 62/62 mutations killed (including 7 T8132 device-role mutations)
  • tools/asahi/atc-cio-sleep-tests.py: 41/41 cases + 11/11 negative controls passed
  • apple-dcp selftests: phy 14/14, quiesce 19/19, lifecycle 35/35 passed

Assisted-by: LLM (Gemini:4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train re-review (MERGETRAIN-LINUX2) at 025e7ea: NO BLOCKERS. The earlier points 1-4 are resolved. Point 5 is still open: KUnit has not been run at this head.

Still needed before the merge: a host-side enumeration row (J773g at 480M) and a KUnit run at this head.

Full re-review

#2434 phy: apple: atc: serve a T8132 device role on USB2 @025e7ea2

VERDICT: NO BLOCKERS

I read the code only; nothing was built or run. Head 025e7ea is one commit on integration/aurora 24dc422. GitHub reports it MERGEABLE. Line numbers below are atc.c at 025e7ea.

The merge gate from the earlier review still stands: no host has enumerated the gadget. The only evidence is still that the -95 error is gone. See the missing rows.

Earlier points (review-B.md, @de20ca29)

  1. Flag cleared on mux OFF, not on role change: RESOLVED.

    • The flag is now cleared only in two places: atcphy_usb3_power_off() (4659) and the HOST case of atcphy_usb3_set_mode() (4766).
    • A SAFE/OFF bounce keeps it. A later USB3 request is mapped to USB2 in atcphy_mux_switch() (5979), atcphy_mux_in_mode() (5889) and atcphy_mux_update_to() (6140).
    • Every dwc3-apple role change goes through dwc3_apple_exit() and then dwc3_apple_core_stop(), which calls phy_power_off(usb3) (dwc3-apple.c:778). So the flag follows the controller role.
  2. Flag left set after a failed mux switch: RESOLVED.

    • The flag is set only once both atcphy_mux_switch() and atcphy_usb3_route() have succeeded (4808-4809).
    • On failure, typec_mode is restored (4796).
    • The host→device -EBUSY scenario from the earlier review can't happen with dwc3-apple. Its role exit calls usb3_power_off() first, which clears host_active and parks the PIPE.
  3. Device→host swap staying on USB2: RESOLVED.

    • typec_mode now keeps the partner's requested mode (requested_mode, 5975/5988/6018).
    • With dwc3-apple's ordering, the swap goes power_off (flag cleared, mode OFF), then atcphy_usb2_init() (4575-4580) configures typec_mode, which is USB3.
    • The in-place restore in set_mode HOST (4758-4774) covers a direct set_mode without power-off.
  4. Pin D mapped to 4-lane DP in the device role: RESOLVED, using the conservative mapping.

    • USB3_DP now maps to USB2 (3636-3641).
    • The DP side then refuses cleanly: atcphy_dpphy_set_mode_t8132() returns -EOPNOTSUPP (4891-4906) and validate reports 0 lanes (4938-4949). The display stays dark; nothing crashes.
  5. Hardware-fact wording: RESOLVED. The comments, the log line (4794) and the commit message now describe a driver limitation.

  6. Bisect: RESOLVED. Driver, KUnit and fixtures are squashed into one commit.

  7. PR footer: RESOLVED.

    • The body now ends with "Assisted-by: LLM (Gemini:4 Neon)". No particular model is required.
    • The commit has only Signed-off-by: Diljit Singh. There are no agent trailers, so there is no NIT on this point.
  8. KUnit never run: NOT RESOLVED at this head.

Blockers

None.

New problems / nits

  1. Every device-role start brings USB3 up first, then tears it down (atc.c:4575-4580, 4659).

    • Why: usb3_power_off() clears t8132_device and takes the T8132 lanes to OFF (4699-4702). typec_mode stays USB3. So on the next core start, atcphy_usb2_init() sees mode OFF with the flag clear and runs a full T8132 USB3 configure. Only then does usb3_set_mode(DEVICE) move the lanes to USB2. On first plug the Type-C mux has already set USB3 before the role arrives.
    • Effects:
      • The host on the other end briefly sees SuperSpeed receiver terminations.
      • A USB3 configure failure fails the whole device role, even though USB2 would have worked. Examples: -EBUSY while t8132_suspended, or -EIO after t8132_failed (4031-4036).
      • The USB2 mapping in usb2_init is effectively dead code: the flag is always clear when usb2_init runs from a role start.
    • atcphy_usb2_set_mode(PHY_MODE_USB_DEVICE) runs before the reset is released (dwc3-apple.c:849-855) and is where the role could be recorded instead.
    • Not a regression: before this PR the device role failed outright. It is still a fragile path.
  2. The controller still runs as a SuperSpeed device on a dummy PIPE.

  3. The set_mode HOST restore (4767-4772) fails the whole host role if atcphy_mux_switch(typec_mode) fails. It returns with the flag set back to true.

    • Falling back to a USB2 host with a warning would degrade more gently.
    • With today's dwc3-apple the branch is unreachable: every host start follows a power_off() that already cleared the flag. Either way it is untested.
  4. The behaviour is keyed on the existing t8132_ss field (set from the DT SS banks, 6616), not on a PHY capability such as USB device mode: T6040 USB2 device sequence; device role keyed on the PHYs (host-only and SuperSpeed) #2334's no_ss_device.

  5. Pin D in the device role silently drops DP.

    • Only the generic "using USB2" dev_info appears. The DP alt mode driver still believes pin D is configured.
    • A dev_info naming the dropped DP would help triage.

Missing rows

  • J773g at this head: a real host enumerates the gadget (lsusb on the host shows the ACM device at 480M). The dmesg should show the "using USB2" line and the dwc3 gadget speed.
  • J713/J715 (Airs) and J604: device role on a calibrated port with a real host on the other end.
  • Unplug or replug in the device role, then replug as host on the same port: lsusb shows 5000M again.
  • DR swap device→host and host→device on one cable, with lsusb speed checked on both sides.
  • Pin D dock or monitor in the device role (DP is expected to stay dark, with no DCP error).
  • KUnit atcphy_test_t8132_device_role_usb2 at this head (arm64 qemu).

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review at 025e7ea (code read only).

Earlier points:

  • Flag tied to the role (1): fixed. It is cleared only in atcphy_usb3_power_off() (atc.c:4659) and on HOST (4766), and honoured in usb2_init/mux_in_mode/mux_switch/mux_update_to (4576, 5889, 5979, 6140). SAFE/OFF without a detach keeps it, and a later USB3 update is downgraded and recorded as a noop. Locking is fine: every access is under atcphy->lock.
  • Set on success only (2): fixed (4808-4809). A failed switch restores typec_mode before host_active is touched.
  • Device->host restores SuperSpeed (3): fixed, but by another path than the one the comment describes.
    • dwc3-apple tears the core down on every role change (dwc3-apple.c:1478 -> phy_power_off), so usb3_power_off() clears the flag and configures OFF.
    • atcphy_usb2_init() then rebuilds from typec_mode, which now keeps USB3.
    • The new PHY_MODE_USB_HOST restore branch (4758-4775) is not reached from dwc3-apple, including dwc3_apple_core_reinit(). It is harmless, but please add a host-test case for the real sequence (device, power_off, usb2_init, set_mode(HOST), expect USB3).
  • Pin D (4): fixed (3636-3641). A device role on pin D now drops the partner's two DP lanes without a word. The log line at 4793 could say so.
  • Wording (5), bisect (6), footer (7): fixed.

New:

  • Every device-role start first brings the lanes up in USB3, then drops them to USB2. The flag was cleared in power_off, so atcphy_usb2_init() (4575-4580) configures typec_mode=USB3, and set_mode(DEVICE) then switches to USB2 (4790-4797). That is a full SuperSpeed start and stop on every attach and resume, and a host on the far end may try SuperSpeed link training during it.
    • dwc3-apple already selects PHY_MODE_USB_DEVICE on the USB2 PHY before reset and phy_init (dwc3-apple.c:842-855). Recording the device role in atcphy_usb2_set_mode() would let usb2_init start on USB2 directly.
    • Not a blocker if the row below shows the host settling at 480M promptly.

Still missing, at this head:

  • The device role on a calibrated T8132 USB3 port, with a real host enumerating the gadget (ACM on the host, lsusb -t at 480M). The J773g evidence is from an earlier module and shows only the missing -95 and a bound UDC. J713 or J773g would do.
  • Device->host swap or replug as host on the same port, back at 5000M.
  • A KUnit run of atcphy_test_t8132_device_role_usb2 (arm64 qemu).

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

KUnit at 025e7ea: atcphy_test_t8132_device_role_usb2 passes.

I ran the ATC KUnit suites under qemu arm64 (kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/phy/apple/.kunitconfig.apple-atc 'phy-apple-atc*'):

  • 025e7ea: 40/40 passed, 0 failed. phy-apple-atc-mux 35/35, including the rewritten atcphy_test_t8132_device_role_usb2, and phy-apple-atc-t8132-pm 5/5.
  • Merge-base 24dc422 (integration/aurora), for comparison: 39/39 passed. phy-apple-atc-mux has 34 cases, and the one extra case at this head is the PR's.

At 025e7ea the ATC host tests also pass: atc-usb3-tests (plain and --mutations), atc-cio-sleep-tests and apple/atc-t8132-usb3.

So the KUnit item is closed. The hardware row is still owed: a real host has to enumerate the gadget at 480M, then a swap or replug as host has to come back at 5000M.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Hardware half of the row at 025e7ea: the J713 (13-inch M4 Air) in device role on USB2, enumerated by a real host.

The kernel is 7.3.0-aurora-fleet81, the J713's default. It is integration/aurora eb6d9ec plus open heads, including this PR at 025e7ea. It ran on the default command line with no reboot. Port0 was in device role with an NCM gadget from configfs. The host was an M4 Pro MacBook Pro running Linux, on the same cable.

  • UDC: 40a280000.usb reached configured at high-speed.
  • Host side: usb 3-1 enumerated at 480M and cdc_ncm bound.
  • Traffic: link-local ping 10/10 at 1.7 ms; iperf3 from host to J713 ran 8 s at 281 Mbit/s with 0 retransmits.
  • Removal: taking the gadget down gave a clean USB disconnect on the host. The UDC went back to not attached.
  • Counts: there were no atc, dwc3 or -95 lines while the gadget was up or when it was removed. Enforcing, 0 AVC, 0 failed units afterwards.

Still to run: the same port back in host role at 5000M. That needs a USB3 device on port0 or a physical swap, and nobody was at the Mac.

Assisted-by: LLM (Claude:Opus 5.5)

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