Repository navigation
J700: keep rear SuperSpeed through a PD re-election (ATC PIPE park + USB3 handover v3) - #353
Merged
Merged
Conversation
A Type-C PHY that switches the PIPE interface of a SuperSpeed root port between its USB3 lanes and a dummy backend needs the controller to have stopped using that interface first. A dual-role port gets that from a role change, which takes the whole controller down. On Apple's T8140 (J700) the controller's USB2 port serves a fixed hub on the board, behind which sit both USB-C connectors and whatever keyboard is plugged in, so the controller has to stay up and only its SuperSpeed root port can be taken down. The port's "disable" attribute already does that for userspace: it disconnects the device on the port and switches the port power off, recorded in power_bits. Give a driver that holds the hub the same, and a counterpart that powers the port on again and has hub_wq look at it. hub_wq warm resets a SuperSpeed port before that, as toggling the port power can leave the two ends of a link out of sync, see usb_port_runtime_resume(). The driver relies on the port staying off until it powers it on, but the hub lock it holds does not keep everyone else away from the port power: - Port runtime PM switches it without the hub lock. Once userspace lets a port power off, its runtime suspend and resume can run at any time, and the resume of its USB2 peer resumes it too. Power-off therefore resumes the port and keeps a runtime PM reference until power-on. Resuming first also tells a port that runtime PM had switched off, which is then held off for the caller, from one that someone switched off on purpose, which is reported and left alone. Taking the hub lock in the runtime PM callbacks instead would deadlock, as hub_event() waits for port runtime PM with that lock held. A port that was switched off through "disable" is recorded as such, so that runtime PM suspending it later does not make it the driver's, and a port whose runtime PM failed earlier is held as it is. - A connect change queued for the port, say by a failed reset of the device just disconnected, made hub_port_connect() power it on again. Power-off drops the connect change and warm reset requests still queued for the port once it is off, and hub_port_connect() no longer switches on a port whose power_bits bit is clear, as hub_power_on() already does not. That changes hub_port_connect() for every hub: a port switched off through the "disable" attribute now stays off through such a change as well. - Writing 0 to the "disable" attribute powers the port on. For a port that a driver holds off, that write now fails with -EBUSY. Writing 1 takes the port over from the driver: the hold ends, and power-on then reports that the port is no longer held and leaves it off. The ABI description of the attribute says so. Only hubs that switch the power of each port on its own are supported, so that nothing but the given port is touched. On an xHCI root hub with port power control that is the port's PORTSC power bit, which the hub driver already toggles for its "attempt power cycle" recovery. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
usb_hub_port_power_off() promises that a port stays off until usb_hub_port_power_on(), whatever its runtime PM, the runtime PM of its USB2 peer and its "disable" attribute do in between. A mocked hub cannot show that. Run the real hub driver instead, on the two root hubs of a host controller made of software: a USB2 and a SuperSpeed root hub with one port each, peered as on an xHCI. The controller keeps the port status and nothing else, and no device ever connects. The tests write port attributes through sysfs, as userspace does, and check that: - the port is held off, and only the given port is switched; - with port power-off allowed, neither the port's runtime suspend and resume nor the resume of its USB2 peer power it on while it is held; - a port that runtime PM had switched off is held for the caller, not reported as someone else's; - the "disable" attribute cannot power a held port on, and can take it over, after which power-on leaves it off. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
On a port behind a fixed hub the controller stays in host mode, so the Type-C mux callback parks the PIPE, rebuilds the lanes and routes the PIPE back to the USB3 PHY underneath a running controller. dwc3-apple.c documents the order the hardware expects instead: the controller stops using the PIPE, then the PHY switches it to the dummy backend, then the lanes change, and in reverse on the way up. Get it wrong and the port "is just broken until a phy+dwc3 reset". On a J700 the PIPE lock is not acknowledged while the controller's SuperSpeed port still has a device, so unplugging a USB-C dock with DisplayPort and USB3 failed to park the PIPE until hub_wq had processed the SuperSpeed disconnect, seconds later: 22:05:35 usb 1-1.2: USB disconnect, device number 17 22:05:36 phy-apple-atc 40b000000.phy: Pipehandler lock not acked. 22:05:36 sn201202x 1-0c: failed to place Type-C mux in safe mode: -110 ... 22:05:39 sn201202x 1-0c: cable revalidation failed after 3 attempts 22:05:48 usb 2-1: USB disconnect, device number 9 After a run of these, the dock's SuperSpeed hub trained at 10 Gb/s on every following plug but never enumerated, until a reboot. What kept it there is not established, but it followed PIPE moves under a live link. Stopping the controller is no option here: its USB2 port serves the hub on the board, and with it both USB-C connectors and the keyboard. Follow the order for the SuperSpeed side only. Before a mux update touches the PIPE or the lanes, have the USB core disconnect the device on the controller's SuperSpeed root port and power the port off. That is the port power the hub driver toggles for its "attempt power cycle" recovery, which the same logs show leaving the USB2 devices alone. Power the port on again only once the PIPE is on the USB3 backend of the running host with no change left unfinished, and let hub_wq warm reset it before enumerating. After a failed change, or in a mode without USB3, the port stays off, so that the controller does not train a link against a half-configured PHY. A mode that the PHY cannot run, such as USB4 on a T8140, is turned down before the port goes down for it, so that a working USB3 link is not disconnected for nothing. When the port cannot be restored after a failed change, that error is returned rather than -EOPNOTSUPP, which the Type-C core takes for success. A port that someone else switched off, through its "disable" attribute, stays theirs: the USB core reports it when the PHY takes the port down or brings it up, and the PHY then owes it nothing. A mux update that keeps the mode still skips all of this, unless an earlier update left the port off; then it only powers the port on, and a USB failure on the way does not fail what may be a DisplayPort update. A host that starts up powers its ports itself, so starting one clears the record of a port left off. The device on the port used to be resumed and held across the change instead. It is now disconnected, as it would be anyway once its lanes change. Ports without a fixed hub, which includes every M1 and M2 port, take no root hub and are unchanged. Fixes: 70f7c21 ("phy: apple: atc: Route the PIPE from the Type-C mux on a fixed-hub port") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A PIPE handoff that did not complete leaves pipe_pending set, and the dummy handoff then insists on the PIPE lock being acknowledged before it moves the PIPE, as it must while a host is running. dwc3 powers the USB3 PHY off and asserts its reset only after its xHCI has gone, though. On a port behind a fixed hub a missing acknowledgment then fails both; the glue keeps the power-off and the reset pending, and its next start retries the same park before anything else. Unbinding and binding dwc3-apple, the way to restart a fixed-hub controller by hand, could then leave the board without USB until a reboot. Clear host_active as the USB3 PHY is powered off or the reset asserted, before the PIPE is parked, and treat the PIPE of a fixed-hub controller as driven only while that controller is in host mode, pending handoff or not. A stopped controller's park then warns about the missing acknowledgment and goes on, as the park does on other ports once no handoff is pending. A running host still has to acknowledge. Ports without a fixed hub keep their check. The new tests run the power-off and the reset on registers that never acknowledge; both failed with -ETIMEDOUT before. Fixes: f5afac9 ("drm/apple: compose lean J700 display and automatic recovery candidate") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
dwc3 calls phy_set_mode(PHY_MODE_USB_HOST) on the USB3 PHY as it brings its host up, and usb_add_hcd() calls it again for the SuperSpeed root hub of the xHCI it registers. The PHY routes the PIPE to the USB3 backend there. It fails with -EBUSY while a lane change is unfinished, or with the error of a PIPE lock or BIST that did not complete. A failure in usb_add_hcd() fails the whole xHCI registration: xhci-plat removes its USB2 HCD again as well. On a port behind a fixed hub that takes down the USB2 root hub, the hub on it and everything behind both USB-C connectors. A cable flip that arrives while the host starts, which only marks the lanes for a rebuild, is enough. For a fixed-hub host, a PIPE that cannot be routed no longer fails the call: park it if that works, and return 0. The Type-C mux update that follows a flip, or retries a failed change, restores the lanes and routes the PIPE with the controller's SuperSpeed port off. If the PIPE cannot even be parked, say so: the SuperSpeed port then faces a PIPE in an unknown state until that update. Other ports keep the error: their controller only starts after the mux has configured the lanes. Fixes: f5afac9 ("drm/apple: compose lean J700 display and automatic recovery candidate") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A mux update that keeps the mode, but still owes the SuperSpeed root port of a fixed-hub controller its power, does not fail on the USB side, so that the display it may carry stays up. The Type-C driver then records the mode as applied, and nothing brings the port up later: with a USB3 dock that sends no further event, USB3 stays off although the host and the PHY are ready for it. The request to the root hub can fail for want of memory, which leaves the controller running. Retry the power-on from delayed work, five times over about three seconds. Each try takes the locks of a mux update, looks up the current root hub, and powers the port on only while it is still owed and the PIPE is on the USB3 backend of a running host; a mux update, a host stop or a new host in between ends the retries. A mode change that fails only in that last power-on still returns the error, and its power-on is retried the same way. The work is freezable, so it waits across system sleep, and it is cancelled when the PHY goes away. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The comment at the top of the driver lays down the order in which dwc3 and its USB3 PHY have to be brought down and up around a PHY change, and that a controller behind a fixed hub never sees a role change. It does not say how such a controller keeps to that order when the SuperSpeed lanes change underneath it. Add that the USB core holds the controller's SuperSpeed root port powered off for the PHY, port runtime PM included, from before the PIPE moves until it is back on the USB3 PHY, while the USB2 side stays up. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A disable=1 write can take over a port held off for a PHY lane change.
Dropping the hold before ClearPortFeature(POWER) succeeds loses both the
runtime PM exclusion and the obligation to restore power if that request
fails. A later PHY update then treats the unpowered port as someone else's.
Publish administrative ownership and release the hold only after the
power request succeeds. Keep the hold and its PM reference on failure,
and retain the rejection of disable=0 while the PHY owns the port.
Add a software-HCD regression test with an injected failed power request.
Fixes: 8ccb06392f04 ("usb: hub: Add helpers to power a port off and on for a lane change")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
…sume
A PHY may move lanes after usb_hub_port_power_off() returns a nonnegative
result. An administrative disable used to return early without excluding
the port runtime-resume writer. Resuming its USB2 peer could then power the
SuperSpeed port while the PHY changed lanes, even under the root-hub lock.
Serialize disable and the runtime-resume power writer with a per-port
mutex. Once disable succeeds, runtime resume leaves the port off, including
the hub-reset path that records the desired power state. Take this mutex
after resuming the peer and hub interface, never the hub device lock: the
hub worker waits for port PM while holding that lock.
Reassert power-off for administrative ports before allowing the lane
change, since a disabled flag alone does not establish the physical state.
Leave their ownership with sysfs and propagate any failed power request.
Every other port now acquires a PHY hold, even if already unpowered, so
there is no other successful path without runtime-PM exclusion.
Retain the peer-resume counterexample and test a previously repowered
administrative port, failed reassertion, retry, and explicit enable.
Fixes: 8ccb06392f04 ("usb: hub: Add helpers to power a port off and on for a lane change")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The host runner fails 31 of 55 cases on the fixed-hub SuperSpeed handover and the PIPE park retry, because their units no longer compile. The ATC mux body moved to atcphy_mux_switch(), with atcphy_mux_check(), atcphy_mux_park() and atcphy_usb3_port_ready() split out, and atcphy_mux_set_locked() takes a third argument. The dummy handoff and the USB3 set_mode now call atcphy_pipe_live() and atcphy_usb3_route(). The PHY state has usb3_port_off and park_owed, and the mux update powers the SuperSpeed root port off and on and queues retries. Extract the split helpers wherever the fixtures extract their callers, and add the new state to the fixtures' copies of the PHY. The lane adapter now runs the actual atcphy_mux_switch() under atcphy_mux_set_locked(), as the ordinary-port quiesce unit does. Both check that no SuperSpeed port comes up, since they take none down. The PM fixtures extract the actual port power steps, retries and atcphy_mux_change(). They model the root port's power: powering it off disconnects the device on it, and the PIPE mux may not be written while the held root's port is up. A power-on asserts that the PIPE is on the USB3 backend of a clean running host. Three behaviours change on purpose, and the assertions that check them follow the source: - The link on the port is disconnected rather than resumed. The selective-suspend link checks still run for sources that resume the link. With the handover, the same scenarios check instead that SAFE takes the port down and keeps it down, and that a USB3 mode brings it back. They also check that a port that fails to go down stops the change before any PHY write, that a port someone else switched off stays theirs, and that a failed power-on fails the change, queues a retry and is completed by the same mode. The root state changes that were injected at the child lookup are injected at the root resume. That resume also starts the controller-lifecycle removal race. - dwc3 has left host mode once a USB3 power-off or controller reset fails, so the parking checks expect host_active cleared, and no lane rebuild from a stopped fixed-hub controller. - A fixed-hub host whose PIPE cannot be routed still starts. The orientation and warm-reset checks expect 0 there. The retry check expects a parked PIPE that the next mux update routes, or, if the lock stays held, the existing pending/acknowledged-retry sequence. Keep the existing assertions: for sources without the handover the expectations are the same as before. The new runner passes 55 of 55 on the drivers of 3abf4a5, on the handover alone and with the park retry. Reverting each of five handover behaviours in atc.c fails it. No production driver changes are needed. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A mux provider can time out on a change that its hardware holds up for a while, and that goes through later unchanged. On a J700 the ATC PHY cannot park the PIPE of the controller behind the fixed hub while that controller still drives it, which a partner renegotiating power can keep up for several seconds. Such a timeout says nothing wrong about the state asked for, and a Type-C driver that gives the state up after a few quick retries leaves the port in the wrong mode until the next cable event. Let a provider declare that -ETIMEDOUT from its set callback is such a hold-up. That is a property of the provider, not of a mux handle: one handle can hold several providers, and on the rear connector of a J700 it holds the PHY and a DCP display route, whose own timeouts can be permanent. So note, for each request, whether the provider that failed it timed out having declared its timeouts transient, and let the consumer ask with typec_mux_timeout_transient() after a request that timed out. Nothing declares it yet, so no consumer changes. The apple-dcp host selftests extract the transaction code; their mux shims gain the two new fields. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
On a J700 the rear port's controller keeps running across Type-C mode changes, so the PHY parks its PIPE itself, after taking the controller's SuperSpeed root port down. The PIPE lock is only acknowledged once the controller lets go of the PIPE. With a Mac on the rear port that did not happen within the lock timeout twice in one day, both times in a burst of SMC power source elections, 11 and 18 "Elec Cause" lines over a few seconds, through which the Mac took the device role: phy-apple-atc 40b000000.phy: Pipehandler lock not acked. phy-apple-atc 40b000000.phy: Failed to switch PIPE to dummy: -110 sn201202x 1-0c: failed to place Type-C mux in safe mode: -110 The Mac then stayed on USB2 behind the fixed hub for the rest of the boot. A refused change leaves the lanes dirty and the SuperSpeed port down, and the next mux update that gets through puts both right: the safe state parks the PIPE, and the USB state routes it to USB3 and powers the port on. But the Type-C driver tries its whole state only a few times, about a second apart, which such a burst outlasts, and then waits for the next cable event, which need not come. Declare the mux timeouts of a J700 fixed-hub port transient, so that the Type-C driver keeps applying its whole state until it goes through. Ports without a fixed hub, every M1 and M2 port among them, and fixed-hub ports on other PHYs do not declare it. Only the PHY's own timeouts count: the DCP display route on the same connector declares nothing, and its timeouts keep the bounded retries. The declaration covers the PHY's other timeouts too, those of its power and PLL polls, which retrying does not clear. Telling them apart from a refused lock would mean changing what the shared poll helpers return to every other caller, and the Type-C driver stops retrying after about two minutes, which bounds them as well. The new tests run the safe state of a data role swap, and the USB state after it, against a PIPE lock that is refused until the elections settle, with the real mode change between stubbed USB steps. However often the lock was refused, a refusal leaves the port down with nothing queued, and the safe state and then the USB state applied again bring SuperSpeed back. They also check which PHYs declare the timeouts transient. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
When a mux update fails, the CD321x update work hands the port to the cable-state recovery: a fresh read and a new attempt at the whole state, three times, then nothing until the next controller interrupt. Each attempt takes about a second, the resume read and the update being debounced by half a second each. On the rear port of a J700 that is not enough. The PHY cannot park its PIPE while the controller behind the fixed hub still drives it, and a Mac renegotiating power, in bursts of up to about 5.5 s, kept that up past the last attempt. Its safe state failed with -ETIMEDOUT each time, so the USB state of the new data role was never asked for, and with no further interrupt the Mac stayed on USB2 for the rest of the boot. Such a failure says nothing about the cable state, which was read fine. When the mux provider that failed a change timed out having declared its timeouts transient, do as for events that could not be acknowledged: do not charge the attempt to the cable-state budget. Apply the whole state again from a fresh read, starting with the safe state, after a delay that doubles from 500 ms up to 10 s. A controller event during the backoff brings the retry forward to the usual debounce, so that its state is applied promptly and the retry that was due later finds nothing left to do. Sleep cancels the retry and the resume read takes it over; removal, or any failure that is not such a hold-up, ends it, the latter going back to the bounded retries with no backoff left over. Only the first failure of such a series is reported, and the change that finally goes through is logged. The provider cannot tell a held-up lock from its other timeouts, so a PHY that stays stuck is not retried for good: after 16 retries, some two minutes and over twenty times the longest burst seen, the port gives up with one warning, as the budget does, and the next controller event starts over. The rear connector's mux handle holds the DCP display route as well as the PHY, and the route declares nothing, so whether a change was held up is asked of the provider that failed it, right after each mux request. The safe state of the update work now goes through the driver's own handle too, the one it asks, rather than the port's: both are the connector's, with the same providers, and the state is the same. Only the PHY of a J700 fixed-hub port declares its timeouts transient. For every other provider, any M1 or M2 port's among them and the DCP display routes, and for any other error, the driver behaves as before. The new tests drive the interrupt, resume read and update work of a port whose mux is refused for longer than the budget lasts, and expect the safe state and then the USB state once it lets go, with no further event, also on a J700 rear connector, where the display route follows the PHY on the handle. They also cover the backoff and its limit, an event that takes over from the backoff, sleep and removal during the retries, giving up on a PHY that stays stuck until the next event, a series that another error ends, and that other muxes, the display route on the J700 connector, and other errors keep the bounded retries. The apple-dcp host selftests follow: the units that extract the update work extract the new helpers with it, against a mux that does not declare its timeouts transient, and the probe unit runs the new state transitions. Fixes: 70f7c21 ("phy: apple: atc: Route the PIPE from the Type-C mux on a fixed-hub port") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
added a commit
that referenced
this pull request
Oct 17, 2026
Bring the 7.2.10 assembly to the tree of the canonical top-up #6a assembly, stacked on top-up #6 a8d71c8 so that it is a fast-forward of that publish head. The second parent is that canonical assembly; the tree is identical to it. Ported from aurora-wip #353 (j700/atc-pipe-park-v3), 13 commits, each with cherry-pick -x and its original author: - the USB3 SuperSpeed handover v3 (9): hub port power helpers and their KUnit tests, the ATC fixed-hub PIPE move with the SuperSpeed port off and the park of a stopped controller, a fixed-hub host that USB3 PHY trouble does not stop, the retried SuperSpeed port power-on, the dwc3-apple handover comment, and the administrative-disable holds of the USB core (170-usb); - the apple-dcp selftests that follow the handover (200-dcp); - Type-C mux providers can declare their timeouts transient, the ATC PHY declares the J700 fixed-hub ones, and tipd keeps applying a Type-C state that a busy mux holds up (170-usb; their apple-dcp selftest parts in 200-dcp). Adaptations, each with a [ryan: ...] note in its commit: - atc.c: context only, atcphy_mux_switch() asserts the lock without the mux debug message 7.2.10 already removed; - the apple-dcp selftests keep ATC_POST_TUNABLE, the 7.2.10 per-SoC post-tunable callbacks, next to the new ATC_SPLIT helpers; - the mux and tipd commits are split between 170-usb and 200-dcp. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
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.
On the MacBook Neo, the rear port can lose SuperSpeed after the host Mac starts a USB-C power re-negotiation. The rear's Type-C mux has to park the ATC PHY's PIPE while the burst lasts, and the PHY refuses: "Pipehandler lock not acked", PIPE to dummy -110. tipd counted each refusal against its 3-attempt cable revalidation budget, went STALE before the burst ended, and left the Mac on USB2 at 480 Mb/s until the next unplug.
This series is the USB3 SuperSpeed handover v3 for the fixed-hub topology (10 commits, reviewed earlier) plus 3 commits that let tipd wait for a busy PHY.
The 3 new commits
-ETIMEDOUTas transient (typec_mux_desc.transient_timeouts).set()actually failed, per request, andtypec_mux_timeout_transient()reports it.set,prepareorfinish, is never transient.Testing
0daed2db+ this): tipd 63/63 and tipd-spmi 69/69 (0 lockdep/WARN, W=1 0 warnings), and apple-dcprun.py55/55.7.1.12-aurora-t2461-ged289aab):🤖 Generated with Claude Code