Repository navigation
usb: dwc3: apple: defer host USB3 PHY routing until xHCI reset completes - #3144
Conversation
dwc3_apple_set_role() currently enables SUSPHY and calls phy_set_mode(usb3_phy, PHY_MODE_USB_HOST) before dwc3_host_init(). Routing the PIPE mux from the dummy producer to the live USB3 PHY before xhci_plat_probe() runs allows the SuperSpeed link to start Rx.Detect / Polling.LFPS immediately, and xhci_reset() (USBCMD.HCRST) then hits milliseconds later in the middle of that handshake. With a quiet console (dmesg -n 5), HCRST lands inside the partner's initial LFPS window often enough to leave downstream SuperSpeed hubs (such as the Dell S2725QC's 0bda:0409 hub on DP alt mode) wedged with PORTSC stuck at 0x0a0002b0 (PR=1, PLS=Rx.Detect) and no receiver termination, triggering a Type-C DISC replug that drops DP HPD and restarts the external display. Even on wakes that survive HCRST, link training stalls ~100 ms before retrying Polling instead of completing on the first handshake. Leave host-mode USB3 PHY routing to xHCI's shared SuperSpeed root hub (usb_add_hcd() on xhci->shared_hcd), mirroring how USB2 host mode is already left to the primary root hub. Keep SUSPHY clear while usb_add_hcd(primary) executes xhci_reset() on the dummy PIPE producer; dwc3_xhci_plat_start() enables SUSPHY once HCRST completes and before usb_add_hcd(shared) calls phy_set_mode(usb3_phy, PHY_MODE_USB_HOST) and xhci_run() starts the controller. Add a post_usb3_host_start glue hook in dwc3_xhci_plat_start() so controllers that must keep their USB3 PHY out of P3 (T8132/T8142) still disable U3 SUSPHY right after the shared HCD finishes routing the PIPE, including when xhci-plat is loaded as a module. Preserve pre-xHCI routing for gadget mode and for T6040, which pulses GUSB3PIPECTL.PHYSOFTRST before xHCI starts. Extend dwc3-apple-state-test and atc-t8132-usb3 (with a negative control) to cover the deferred host USB3 routing policy. Signed-off-by: Diljit Singh <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 79bbbb3580ec
Blockers:
drivers/usb/dwc3/dwc3-apple.c(dwc3_apple_set_role()/dwc3_apple_init()): deferring hostphy_set_mode(usb3_phy, PHY_MODE_USB_HOST)intoxhci_plat_probe()->usb_add_hcd(xhci->shared_hcd)silently breaks error propagation andcore_exitteardown on T8132 and T6050.dwc3_host_init()(drivers/usb/dwc3/host.c) only callsplatform_device_add(xhci), whosedevice_add()->bus_probe_device()->device_initial_probe()(drivers/base/dd.c) returnsvoidand swallows anyxhci_plat_probe()failure. Whenusb_phy_roothub_set_mode()fails onxhci->shared_hcd(for example a T8132 BIST/PIPE timeout, a T6050 PIPE fault-EIO, or-ENOLINKfromcombo_usb3_mode()),xhci_plat_probe()tears down both HCDs and leavesdwc->xhciunbound, yetdwc3_host_init()still returns0.dwc3_apple_init()then skipsdwc3_apple_core_stop(), callsphy_reset(appledwc->usb2_phy), recordsappledwc->state = DWC3_APPLE_HOST, votesapple_sleep_usb_slp_ddr(true), and registers syscore while the controller has no bound xHCI driver and an undefined PIPE state; post-sleep-ENOLINKalso stops reachingdwc3_apple_start_after_sleep()to armsleep_phy_pending.tools/testing/selftests/drivers/apple/atc-t8132-usb3.py: the updateddwc3_host_init()mock hides blocker 1 by returningphy_set_mode()'s error directly instead of modelingplatform_device_add()returning0onxhci_plat_probe()failure, and theapple,t8103-dwc3fallback case was switched fromDWC3_APPLE_HOSTtoDWC3_APPLE_DEVICE. On older non-fixed Type-C ports (t8103/t6000/t6020/t8112/t8122), bypassingdwc3_apple_set_role()'s host-mode USB2-only warning means any persistentphy_set_mode()error insideusb_add_hcd(xhci->shared_hcd)tears down the primary USB2 HCD as well (xhci-plat.cgoto put_usb3_hcd) whiledwc3_host_init()still returns0.
Checked: diff, USB core HCD and xhci-plat probe ordering, driver core platform_device_add error semantics, atcphy_usb3_set_mode and T6050 combo_usb3_mode error paths, dwc3_apple_init and post-sleep -ENOLINK handling, and host-test harness assumptions.
Evidence
drivers/usb/dwc3/host.c:dwc3_host_init()callsplatform_device_add(xhci);bus_probe_device()->device_initial_probe()(drivers/base/dd.c) returnsvoid, so a failedxhci_plat_probe()does not return an error fromdwc3_host_init().drivers/usb/host/xhci-plat.c+drivers/usb/core/hcd.c:usb_add_hcd(xhci->shared_hcd)callsusb_phy_roothub_set_mode(..., PHY_MODE_USB_HOST_SS)thenPHY_MODE_USB_HOST; any non-zero error jumps toerr_usb_phy_roothub_power_onandxhci-plat.cjumps toput_usb3_hcd, tearing down both HCDs and failingxhci_plat_probe().drivers/usb/dwc3/dwc3-apple.c:dwc3_apple_init()relies on a non-zero return beforedwc3_host_init()(or fromdwc3_host_init()) to rundwc3_apple_core_stop(), avoidappledwc->state = DWC3_APPLE_HOST/apple_sleep_usb_slp_ddr(true)/dwc3_apple_syscore(true), and propagate-ENOLINKtodwc3_apple_start_after_sleep().drivers/usb/dwc3/host.cdwc3_xhci_plat_start(): note that ifxhci-platis built as a loadable module and probes asynchronously afterdwc3_apple_init()returns,dwc3_apple_post_usb3_host_start()also updatesdwc->dis_u3_susphy_quirkwithout holdingappledwc->lock.tools/testing/selftests/drivers/apple/atc-t8132-usb3.py:dwc3_host_init()returnsretfromphy_set_mode()directly, soassert(dwc3_apple_init(&a, DWC3_APPLE_HOST) == -ETIMEDOUT)passes only in the mock, not against realplatform_device_add().
|
PASS on J773g (M4, T8132, G16G B0) at
The tether stayed connected throughout. Both downstream devices were USB2, so downstream SuperSpeed link recovery remains unverified on this setup. The candidate exposed only |
Leaving the host USB3 PHY routing to usb_add_hcd() on xHCI's shared HCD moved it into xhci_plat_probe(), whose result platform_device_add() does not report. A failed routing tore down both root hubs while dwc3_host_init() returned 0: dwc3_apple_init() then recorded a host with no bound xHCI, skipped dwc3_apple_core_stop(), voted USB_SLP_DDR, and an -ENOLINK after a sleep no longer reached dwc3_apple_start_after_sleep(). On older Type-C ports, a USB3 PHY error took the USB2 root hub down with it instead of leaving the port on USB2. The T8132/T8142 P3 quirk also ran from a probe that a modular or asynchronous xhci-plat may run outside the glue lock. Keep the USB3 PHY off the SuperSpeed root hub instead: let a shared HCD skip its PHYs when it asks for it, and let xhci-plat ask for that when the platform glue sets up the USB3 PHY itself. dwc3 asks for it when its glue has a usb3_host_route op, which replaces post_usb3_host_start and runs from xHCI's init_quirk for the shared HCD: after xhci_reset() and dwc3_xhci_plat_start(), before xhci_run(), the same point the routing ran at before. Its error fails the probe before the controller runs. In the Apple glue, that op routes with the error policy dwc3_apple_set_role() had: T8132 and T6050 failures stop the host, other ports warn and run USB2 only with both root hubs up. It acts only in the task that runs dwc3_apple_host_start() under the glue lock. dwc3_apple_host_start() binds xHCI itself when the driver core left the probe asynchronous, does not probe again once the PIPE has moved, and returns the routing's result, so that dwc3_apple_init() stops the core on any failure. Model platform_device_add() and xhci_plat_probe() in atc-t8132-usb3 the way they behave, with T8132 -ETIMEDOUT, T6050 -EIO and -ENOLINK, the T8103 USB2-only fallback, asynchronous and late probes, and negative controls for routing before xhci_reset(), routing from the root hub, a lost error, a probe repeated on the live PIPE and a probe outside the glue lock. Signed-off-by: Diljit Singh <[email protected]>
|
Thanks for the review, satchlj. Both blockers are fixed in 1. Error propagation,
Locking with a modular or asynchronous xhci-plat: 2. Tests
J714s at Evidence
|
satchlj
left a comment
There was a problem hiding this comment.
Verdict: MERGE at 40f74425e1a9
Blockers: none
Checked: Full diff across all 11 files (+472/-52), follow-up commit 40f74425e1a9 addressing both prior requested changes on 79bbbb3580ec, synchronous xHCI attach and routing error propagation in dwc3_apple_host_start(), shared HCD skip_phy_initialization opt-in in hcd.c / xhci-plat.c / dwc3/host.c, dwc3_apple_route_usb3() policy preserving T8132/T6050 strict failures and older-port USB2-only fallback, T6040/gadget pre-start routing preservation, updated host tests, exact-head J714s 10/10 deep-sleep verification row, and live CI status. Untested scope: no local kernel boot on Apple Silicon hardware (userspace code and CI audit only).
Evidence
- Follow-up commit
40f74425e1a9resolves both blockers from79bbbb3580ec:dwc3_apple_host_start()ensures synchronous xHCI probe (device_attach()if left async) and returns the storedusb3_host_routeresult, callingdwc3_host_exit()when xHCI fails to bind sodwc3_apple_init()cleanly tears down the core and propagates-ENOLINK/-EIO/-ETIMEDOUT.dwc3_apple_route_usb3()runs from xHCI'sinit_quirkfor the shared HCD afterxhci_reset()anddwc3_xhci_plat_start()and beforexhci_run(), preserving USB2-only fallback on older ports (t8103/t6000/t6020/t8112/t8122), strict failure ont8132/t6050, and P3 avoidance ont8132/t8142.tools/testing/selftests/drivers/apple/atc-t8132-usb3.pyanddrivers/usb/dwc3/dwc3-apple-state-test.ccover both sync/async attach and error teardown paths.
- Live CI at
40f74425e1a9: 9/9 checks passing (0active,0failing), includingDWC3/ATCbuilds,host-tests,kunit,rust-build,source-checks,pr-text, andreadiness. - Exact-head J714s (M5 Pro, T6050) 10/10 RTC deep-sleep cycle verification reported in PR body at
40f74425e1a9.
|
J773g (T8132, G16G B0) at
Only |
What: Route the host USB3 PHY only after xHCI's reset (
USBCMD.HCRST) has completed on the dummy PIPE producer, instead of beforedwc3_host_init(). HCRST landing in a live SuperSpeed handshake wedged downstream hubs after deep sleep (PORTSC 0x0a0002b0,PR=1,PLS=Rx.Detect). That triggered#2274Type-C replugs and restarted the external DP alt-mode display on 5/10 J714s wakes. The glue now routes from xHCI's SuperSpeed setup and gets the result back, so a failure still stops the core and the USB2-only fallback keeps working.Tested:
J714s(M5 Pro, T6050) at40f74425e1a92ab6d7684113b518933c461c0c31: 10/10 RTC deep-sleep cycles atdmesg -n 5with WD2 held. 0/10 stuck0x0a0002b0warm resets, 0/10#2274replugs, 0/10DP-2restarts; Dell0bda:0409+0bda:5409back first try 10/10;eDP-1,DP-2,DP-5connected 10/10; GPU live before and after 10/10; no error-priority kernel line that a control at79bbbb35on the same kernel config and DTB doesn't also log. Host tests (atc-t8132-usb3,dwc3-initial-role,atc-usb3-tests+ mutations,neo-stability-tests+ mutations,atc-cio-sleep-tests,apple-dcp) andcheckpatch.pl --strictpass.Risk: two-way · all Apple DWC3 hosts (M1–M5:
t8103/t6000/t6020/t8112/t8122/t8132/t6040/t8142/t6050). Gadget mode and T6040 still route before xHCI, as before. The usbcore/xhci-plat part is an opt-in used only by a dwc3 glue withusb3_host_route; other platforms are unchanged.Not yet: hardware at this head on M1–M4 and base M5 (T8103/T6000/T6020/T8112/T8122/T8132/T8142). The J773g (M4, T8132) row in the comments is at
79bbbb35, before the follow-up. The older ports' USB2-only fallback and the T8132/T8142 P3 quirk are covered by host tests only.Details
Root cause
dwc3_apple_set_role()enabledSUSPHYand calledphy_set_mode(usb3_phy, PHY_MODE_USB_HOST)beforedwc3_host_init(). That moved the PIPE mux from the dummy producer (0x42) to the live USB3 PHY (0x10) beforexhci_plat_probe()ran, so the SuperSpeed port went straight intoRx.Detect/Polling.LFPSwith the partner. Milliseconds later,usb_add_hcd(primary)ranxhci_reset()in the middle of that handshake.dmesg -n 5, as on normal desktop boots), HCRST landed inside the Dell S2725QC Realtek0bda:0409hub's handshake on about 40% of wakes. The hub stayed atPORTSC2 = 0x0a0002b0with no receiver termination until#2274replugged the port, which droppedDP-2HPD.loglevel=7, synchronous console output shifted HCRST out of that window (0/56 failures), which hid the race.Fix
dwc3_apple_set_role()leaves a host's USB3 routing owed (dwc3_apple_usb3_mode_before_start()) and keepsSUSPHYclear, soxhci_reset()runs on the dummy PIPE. Gadget mode and T6040, which pulsesGUSB3PIPECTL.PHYSOFTRSTbefore xHCI, still route first.usb_add_hcd()honors a shared HCD's ownskip_phy_initialization, and xhci-plat sets it fromxhci_plat_priv.skip_usb3_phy_init. dwc3 sets that for a glue with theusb3_host_routeop.usb3_host_routefrom xHCI'sinit_quirkfor the shared HCD. That is afterxhci_reset()anddwc3_xhci_plat_start()(SUSPHYon) and beforexhci_run()setsUSBCMD.RS. An error fails the probe before the controller runs.dwc3_apple_route_usb3()keeps the old policy: T8132/T6050 errors stop the host, other ports warn and run USB2 only with both root hubs up, and T8132/T8142 stay out of P3.dwc3_apple_host_start()makes xHCI's probe synchronous (device_attach()when the driver core left it asynchronous) and returns the routing result. When xHCI didn't bind, it callsdwc3_host_exit(), sodwc3_apple_init()stops the core, skips the host state, theUSB_SLP_DDRvote and syscore, and-ENOLINKstill armssleep_phy_pending. The op routes only in the task holding the glue lock there, so an asynchronous, late or rebind probe routes nothing, and a probe is never repeated once the PIPE has moved.#2274'sdwc3_apple_ss_check()/tipd_port_replug()fallback is unchanged, for hubs that really are dead.atc-t8132-usb3modelsplatform_device_add()andxhci_plat_probe()as they behave, with five negative controls.dwc3-apple-state-testcovers the routing policy helper.Evidence
J714s RTC deep sleep (
rtc0+25 s,mem=deep,dmesg -n 5, WD2 held)0x0a0002b0/#2274replugsDP-2restarts0409+5409first tryorigin/mainbaseline79bbbb35(first commit), earlier run79bbbb35, control on this setup40f74425(head)Head run, per wake: the SuperSpeed hub (
usb 4-1,0bda:0409) enumerated +0.27–0.32 s after suspend exit,DP-2was back at +0.97–1.31 s and never dropped again, anddwc3_apple_ss_check()found the SuperSpeed device at +5.3–5.5 s (TEST: SuperSpeed device back after the sleep10/10). Suspend counters: 10 successes, 0 failures. Wi-Fi associated +8.0–8.2 s after every wake. Bluetooth was powered 10/10. WD2 (wdt+reconfig) came back armed with 29 of 30 s after every sleep and closed cleanly. GPU:LIVE vulkaninfo=1 dispatch=1 kernel=okbefore and after every cycle,crashed=0,quarantined=0.-j18, incremental. Configuration: the default kernel's/proc/config.gz. 0 errors, and no warnings in the changed files. The follow-up hooks (dwc3_apple_usb3_host_route,dwc3_xhci_plat_init_quirk) are in the build, andpost_usb3_host_startis gone. The trial booted the head'st6050-j714s.dtb(WD2wdt+reconfig) with the default Stage 2 and command line, MTE on and SEP writes enabled.79bbbb35control with the same configuration and DTB. They are DCP provider clock index 0 and AFK service-matching lines,mmc0card power, PCIe and Centauri D0 power-state lines, the glue'sgenpd_prepare returns -11syscore retry on the dock's controller, the Centauri country update (-125), and Realtek HID "no listeners".Host tests at
40f74425tools/asahi/run-host-tests.py:apple/atc-t8132-usb3(13/13, including five negative controls that each have to fail on their own check),apple/dwc3-initial-role(1/1),atc-usb3-tests+--mutations(2/2),neo-stability-tests+ mutations and old-revision controls (11/11),atc-cio-sleep-tests(1/1).apple-dcp: 95/95 (on clang 23, which needs-Wno-unused-but-set-globalfor existing test globals).scripts/checkpatch.pl --strict --git origin/main..HEAD: 0 errors, 0 warnings, 0 checks for both commits.