Repository navigation
USB device mode: T6040 USB2 device sequence; device role keyed on the PHYs (host-only and SuperSpeed) - #2334
Closed
RyanTheTide wants to merge 13 commits into
Closed
RyanTheTide wants to merge 13 commits into
RyanTheTide wants to merge 13 commits into
Conversation
Describe the two optional tunable lists the T6040 USB2 PHY takes in place of apple,tunable-usb2-host when the port runs as a USB device: apple,tunable-usb2-default, applied first, and apple,tunable-usb2-device. The boot loader copies both from the platform's device tree, as it does for the host list. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T6040 USB2 PHY implemented host mode only, so dwc3-apple had to keep every T6040 controller a host and drop the port controller's USB_ROLE_DEVICE: a J616s cabled to another computer never shows up on it as a USB device. Device mode is the same eUSB2 power-on with three differences, found with the boot loader's USB2 device bring-up on a J616s cabled to a Mac host: - the default and device tunables are applied instead of the host one; - SIG[14:12] are cleared: the device tunables leave them set (SIG reads 0x01c0700f) and with them set the host never sees the device connect. The host tunable clears the same bits for host mode; - VBUS valid is forced: VBUS is seen by the Type-C port controller, not by this PHY, and the controller is only put in device mode after the port controller reported a USB data connection from a host. Accept PHY_MODE_USB_DEVICE in set_mode and power_on, check the device signal bits like the host ones, and add a validate op that reports both modes, so the controller glue can tell from the PHY whether it may follow a device role. power_off returns the PHY to host mode: dwc3-apple selects device mode before each device session, while xHCI asks for host mode only once the PHY runs, so a host session after a device one would otherwise power on as a device and then have xHCI's request refused. The USB3 PHY has no device sequence; a device port runs at high speed with its PIPE on the dummy PHY. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
atcphy_usb2_set_mode() serves both roles by setting or clearing the host signature. Say so through the validate op, so that a controller glue can ask the PHY whether it may run a port as a USB device instead of keeping a list of SoCs. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
dwc3_apple_host_only() kept T6040 and T6050 controllers hosts by compatible, because their USB2 PHYs could not run as a device. Ask the PHY instead: a controller follows USB_ROLE_DEVICE when its USB2 PHY validates PHY_MODE_USB_DEVICE. The T6040 PHY now does; the T6050 combo PHY does not, so those ports stay hosts for the hardware reason the compatible list stood for, and any PHY that gains a device sequence gets device mode without a change here. The ATC PHY validates both modes, so T8103 to T8142 controllers keep their device role. A port whose USB3 PHY has no device sequence (T6040: -EOPNOTSUPP) or that has no USB3 PHY leaves the PIPE on the dummy producer. Offer the gadget at high speed only there, and give the next session the core's own maximum speed back before the core is initialised. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
dwc3-apple selects device mode before it releases the controller reset. When the start fails before the PHY is powered (the reset, a runtime PM resume or the core probe fails), power_off never runs and the PHY kept device mode: the next host session then powered it on as a device and xHCI's host request was refused. Return to host mode when the controller reset is asserted with the PHY off, which every failed start does on its way out. Also apply the default tunable, when the boot loader provides it, before the host one, as the device sequence does, so that fields only the device tunable writes do not carry over into a host session. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
dwc3_core_init() picks GUCTL1.DEV_FORCE_20_CLK_FOR_30_CLK from the maximum speed, which the glue lowers to high speed only after the core init, once the USB3 PHY has refused the device role. Set the bit there too, so a gadget limited to high speed runs with the core set up as for one configured that way. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The glue now keeps the controller's maximum speed while a gadget runs clamped to high speed and puts it back in dwc3_apple_init(). The Neo stability harness and the apple-dcp dwc3-teardown model compile that function against their own struct dwc3 and struct dwc3_apple, which had no maximum_speed and no enum usb_device_speed, so both stopped building. Add both with the uapi values (USB_SPEED_UNKNOWN is 0, so the zeroed fixtures save nothing), and check in the Neo harness that a saved maximum is restored at the next core init and that nothing is restored before a clamp. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…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>
T8132 has no SuperSpeed device mode, and atcphy refuses a device role on
a port whose lanes run USB3: atcphy_usb3_set_mode() returns -EOPNOTSUPP,
dwc3-apple fails the role ("USB3 PHY setup failed, err=-95") and the
port controller's revalidation gives up. Before the boot loader passed
the T8132 USB3 calibration these ports ran USB2 only, and the same device
role worked there. So a Mac mini (J773g) rear port that a host connects
to as a device lost its USB when the calibration arrived.
Serve the device role on USB2 instead: when the controller asks for the
device role on a calibrated T8132 port, switch its lanes to the USB2 mode
(four-lane DisplayPort keeps its own USB2 wires) and keep them there for
later mux updates while the device role holds. The host role, and the
partner leaving (safe state), lift that again.
Signed-off-by: Diljit Singh <hey@djdev.me>
…apability The previous commit serves a T8132 device role on USB2 because that PHY has no SuperSpeed device mode. Describe that as what it is, a property of the PHY in its match data (no_ss_device), instead of the T8132 banks: the device-role USB2 limit (now usb2_device) applies to any ATC PHY with the flag, and the mux update keeps it outside the T8132 block. Also let the USB3 PHY answer .validate: host always, device unless the PHY has no SuperSpeed device mode. That is how dwc3-apple learns that it has to run as a high-speed device: its device speed and the USB2 clock for its USB3 logic are controller settings no PHY can make. Only T8132 sets the flag; every other ATC generation keeps its SuperSpeed device. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…lidate The USB3 PHY has no device sequence, which it reported by failing set_mode for a device role. Report it through .validate instead, as the ATC PHYs now do, and accept the device role in set_mode: it runs on USB2, with the PIPE left parked on its dummy producer where power_off put it. dwc3-apple then sets up the high-speed device from the capability rather than from an error. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
…lity The USB3 PHYs now say in .validate whether they can carry a SuperSpeed device (T8132 and T6040 cannot), and route their lanes for a device role on USB2 when they cannot. Set the high-speed gadget up from that answer, before phy_set_mode(), instead of from a set_mode error. This stays in the glue because the device speed and the USB2 clock for the USB3 logic are controller settings no PHY can make; the PHY decides, the glue applies it. No USB3 PHY at all is the same case. A set_mode -EOPNOTSUPP for a device role still means high speed: an ATC port can lack SuperSpeed on one connection (a T8103 port whose lanes are all DisplayPort, or without SuperSpeed tunables). The T6040 PIPE reset stays with the host role; a device role leaves the PIPE parked. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The ATC USB3 harness and the apple-dcp PHY, quiesce and dwc3 models compile atc.c functions against their own structs. The device role on a PHY without SuperSpeed device mode added a struct member (usb2_device), a helper (atcphy_usb2_device_mode()), a forward declaration of atcphy_mux_switch() and a dev_info() call, so they stopped building, including on linux#2434 alone. Add the member, extract the helper, emit the prototype and stub dev_info as the harnesses do for their neighbours, and check in the USB3 harness that a T8132 device role maps a USB partner to USB2 (and back to USB3 once the role is gone) while four-lane DisplayPort stays DisplayPort. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Contributor
Author
|
Superseded by #2632: the same commits rebased onto current integration/aurora. Assisted-by: LLM (Claude:Opus 5.5) |
Contributor
Author
|
Superseded by #2632, which carries this change on a current base. Branch kept. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On the M4 Pro (T6040) every USB-C controller is forced to stay a host, so a J616s cabled to another computer never appears on it as a USB device: no USB networking, no mass storage, no serial gadget. The gate was a compatible list (
apple,t6040-dwc3,apple,t6050-dwc3) indwc3_apple_host_only(), standing in for "this USB2 PHY has no device sequence".Change
phy-apple-t6040-usb2gets a USB2 device sequence: the same eUSB2 power-on with the default + device tunables in place of the host one,SIG[14:12]cleared and VBUS forced valid. These three facts come from the boot loader's USB2 device bring-up on a J616s cabled to a Mac (aura#245). It validatesPHY_MODE_USB_HOSTandPHY_MODE_USB_DEVICEand returns to host mode at power-off so a host session after a device session still starts.phy-apple-atcreports both USB2 modes through.validate(it already served both).dwc3-appledecides host-only from the USB2 PHY:phy_validate(usb2_phy, PHY_MODE_USB_DEVICE). The T6050 combo PHY has no device sequence and stays host-only for that reason; T8103 to T8142 keep their device role. Without a USB3 device PHY (T6040) the gadget is offered at high speed..validaterefusesPHY_MODE_USB_DEVICEwhen it has no SuperSpeed device mode. That's T6040, and in ATC it's a capability in the match data (no_ss_device, T8132 only), not a SoC check.set_mode(DEVICE)routes the lanes for the role. On T8132 that means Dj's phy: apple: atc: serve a T8132 device role on USB2 #2434: while the device role holds, the lanes run USB2 next to any four-lane DisplayPort. It's carried here unchanged, with Dj's authorship. On T6040 the PIPE stays parked.-EOPNOTSUPPfromset_modestill means high speed on every SoC (a T8103 port whose lanes are all DisplayPort). That check now runs ahead of the T8132/T6050 check that keeps a failed host handoff from starting xHCI.Testing
Builds clean (no warnings) as modules against the production fleet75 tree; checkpatch clean apart from the binding being its own commit, which it is.
M2 (T8112, ATC PHY), no-regression: one-shot of production fleet74 with these three modules built out of tree (a stock rebuild of the same files is byte-identical in
.textto the production modules). The new code was live (its symbols in/proc/kallsyms). Boot warnings matched the production boot plus only the out-of-tree taint line. SELinux enforcing, 0 failed units, 0 AVC, Type-C roles and port-controller registers unchanged, s2idle 1/1 with an RTC wake. This Mac has no USB device attached, so only probe and sleep ran.Host tests: the ATC USB3 harness and the apple-dcp PHY, quiesce and dwc3 models compile
atc.cfunctions against their own structs. They stopped building on phy: apple: atc: serve a T8132 device role on USB2 #2434's commit, and that PR's own CI shows it. Thetools:commit fixes them and checks the T8132 device-role mux mapping. The ATC KUnit suite isn't run by CI (its kunit job runs the SEP suite only); it passes 52/52 under qemu arm64, including phy: apple: atc: serve a T8132 device role on USB2 #2434's case and a new.validatecase. The CI DWC3/ATC compile profiles pass 3/3 locally.Host tests: the Neo stability harness and the apple-dcp dwc3-teardown model compile
dwc3_apple_init()against their own structs, so they broke on the newmaximum_speedfield (the first CI run's host-tests failure). The last commit adds the field to both and checks that a saved maximum comes back at the next core init. The whole host suite passes locally, 427/427 (at 055fed8 and at this head).Review follow-ups are in the commits before it: a failed device start no longer leaves the T6040 PHY in device mode; host sessions apply the default tunable first; a high-speed gadget gets the same GUCTL1 clock setting
dwc3_core_init()would give it.J616s (T6040), device mode: one-shot of production fleet75 with these modules, Left Back cabled to a Mac mini (macOS 26) as host. The controller registers its UDC at boot; the Mac enumerates the configfs gadget at 480 Mb/s and binds its own NCM, ACM and mass-storage drivers. Over NCM, iperf3 gives 277 Mbit/s into the J616s and 314 Mbit/s out of it, and ping averages 0.83 ms. ACM serial carries data both ways. One s2idle cycle with the gadget bound: the gadget is still configured after resume and the link comes back (ping 10/10). On the same boot, the host port still routes its USB3 PIPE to the PHY and a USB3 flash drive runs at 5 Gb/s, the same as production.
J616s, second session at this head (fleet75 one-shot, Left Back to the Mac mini): the UDC registers at boot. The high-speed setup now comes from the USB3 PHY's
.validate("No USB3 device PHY: gadget at high speed";set_modeno longer fails). The host port still routes its USB3 PIPE. The gadget runs at high speed. Over NCM a 1 GiB file copies at 40.8 MB/s out and 35.2 MB/s in, sha256 identical, with ping 20/20 at 1.0 ms. A fixed-disk image mounts on the Mac and reads at 40.8 MB/s. 0 kernel warnings. The same modules also ran another lane's 16 s2idle cycles with a gadget netconsole to the Mac.Still to run
Rule and hardware property
Old gate:
of_device_is_compatible(dev->of_node, "apple,t6040-dwc3") || ... "apple,t6050-dwc3".New gate: the USB2 PHY's own
validateanswer forPHY_MODE_USB_DEVICE. A PHY without.validategets-EOPNOTSUPPfrom the PHY core and keeps the controller a host, which is the safe default.Per generation:
fixed_hub, unchanged.phy-apple-t6040-usb2): device role new, USB2 only (high speed).Why the PHY returns to host mode at power-off
dwc3-apple selects
PHY_MODE_USB_DEVICEbefore releasing the controller reset for a device session. For a host session it leaves the mode to xHCI, which asks forPHY_MODE_USB_HOSTonly afterdwc3_core_init()powered the PHY on. Without the reset to host mode at power-off, the first host session after a device session would power the PHY on as a device andset_mode(HOST)would then return-EBUSY.Assisted-by: LLM (Claude:Opus 5.5)