Repository navigation
usb: typec: tipd: reset a controller through debugfs, and set the port up again - #4057
DjDeveloperr wants to merge 5 commits into
Conversation
cd321x_rearm_recover_contract() resets a controller that lost its partner's contract after a debug link cut, and only marks its setup pending. The attempts for that setup are handed out by the resume and by the first reset event, and the setup right after the wake has used them up, or left them at zero, by the time of that reset. The next run then fails with "controller setup recovery exhausted" without reading the controller, and no cable update is applied until the next sleep. Give a reset that the driver made its own attempts, with the code that the reset event uses. Signed-off-by: DjDeveloperr <hey@djdev.me>
tuxvdmtool's reset-controller writes "Gaid" to the controller's command register. An SN201202x is only reached through this driver's debugfs file, which does not take that command, so a stuck controller could only be reset by a module written for it, with the driver unbound. Take it there, for a CD321x too. A reset controller has lost its interrupt mask, its system power state and its partner, so the driver sends the command itself, waits until the firmware runs, and then sets the port up as after a reset it finds out about on its own, and connects what is attached from a fresh read. macOS's no-partner state (apple,cable-change-ssps) is applied again as at boot. The reset is refused while the controller is in DBMa, a command or a replug runs, or the system sleeps. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
The helper that hands them out is only used by the controller's setup, so move it to cd321x-setup.h and name it after that. The host tests build cd321x-pm.h on its own and refuse a helper that nothing in it uses. Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
A CMD1 write failure can report a successful controller reset and reconnect a port that never reset. If the initial reads succeed, the command write returns -EIO, and the next mode read still reports APP, cd321x_send_reset() swallows the original error, cd321x_wait_reset() succeeds on the old firmware state, and the driver reports success and forces a reconnect. Preserve the pre-submit error and only tolerate loss of completion reads once the command write succeeded.
…oller A bus error in the write of "Gaid" was taken for a controller that restarts and does not answer. Its mode still reads APP, so the reset was reported as done and the port reconnected, with nothing reset. Write the command apart from the wait for its end, return an error up to and including that write, and tolerate failed reads only after it. The controller counts as up again once its mode is APP and no command is left in CMD1. A firmware that rejects the command, or does not have it, is reported with nothing reset as well. -ETIMEDOUT is returned only for a reset whose end was not seen, which is what tuxvdmtool takes it for; a bus that times out before the write gives -EIO. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Fixed in 809b331: an error up to and including the write of the command is returned and nothing is set up again; only reads after it may fail. The wait also needs CMD1 to be empty, so a command that was never taken is not a reset. A rejected command is -EPERM, and -ETIMEDOUT is now only returned for a reset that was sent. KUnit has a case for each. |
RyanTheTide
left a comment
There was a problem hiding this comment.
The pre-submit error is fixed. One completion status still slips through: with CMD1 clear, DATA1 reporting TPS_TASK_TIMEOUT, and mode APP, cd321x_wait_reset() returns success and forces a reconnect. The base command helper already treats that reported task status as a timeout. Preserve the timeout status so the active controller is not reported as successfully reset.
A controller that gives up on "Gaid" clears CMD1 with the task status for a timeout in DATA1 and keeps running in APP, which counted as a reset. Report it as -EIO, with nothing set up again. Not as -ETIMEDOUT: that stands for a reset whose end was not seen, and tuxvdmtool then waits for APP and reports success. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Fixed in the last commit: a task status of "timeout" with CMD1 clear is now -EIO and nothing is set up again (KUnit case added). It is not -ETIMEDOUT because tuxvdmtool takes that for a reset that was sent, waits for APP and would report success. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Both reviewed failure paths now return before port setup: failure to write CMD1, and a completed task reporting timeout in DATA1. The latter returns EIO so userspace cannot mistake it for a reset whose completion is unknown. The added KUnit cases exercise these distinctions. A live reset row is still pending.
|
Hardware check on MacBook Pro 16" M3 Pro (J516s, T6030) at
|
What:
tuxvdmtool reset-controllercan reset a stuck port controller on M3 and later Macs. The debugfscommandfile now takesGaid, and the driver sets the port up again afterwards. Also fixes a port that stayed dead after the driver's own reset of a controller that had lost its contract.Tested: J516s (SN201202x) at this head with #4056: one
Gaidwith a partner on the port, controller set up again, partner and peer back, other ports untouched (PASS). KUnit on UML passes with five new cases, the tipd directory builds atW=1on arm64 without a new warning, and the host tests that build code from this driver pass.Risk: two-way · all Apple silicon Macs. A reset happens only when root writes
Gaid. The fix changes what follows the driver's own reset, on ports with a debug link after a sleep (M5 Pro).Not yet: One CD321x Mac (M2 Pro J414s) with
Gaidon a port with nothing plugged in. What the controllers report in the first second after the reset is taken from the driver's two existing resets, not measured here.Details
What a reset loses, and how the driver restores it. After
Gaidthe controller has its default interrupt mask and power state, is locked, and has dropped its partner and its liquid mitigation. The driver already handles a reset that it finds out about from a stray interrupt (cd321x_check_setup()): back to S0, the mask again, the liquid detector's state invalidated, and the cable state read afresh. The newcd321x_cold_reset()uses that path:Gaid. An error up to and including that write is returned, and nothing is changed. Only after the write may reads fail, as a controller that restarts need not answer. Then it waits until the mode is APP and no command is left in CMD1 (1 s, then up to 2 s).A controller that is not up in time gives -ETIMEDOUT, and is still set up once it answers.
Refused with -EBUSY: debug mode (DBMa, including one set up before Linux), a command still running, a replug in progress, system sleep. A firmware without the command gives -EINVAL, one that rejects it -EPERM, one that gives up on it -EIO, a bus that times out before the write -EIO (so -ETIMEDOUT always means a reset was sent), a controller that is not a CD321x or SN201202x -EOPNOTSUPP. Nothing is changed in those cases.
The fix.
cd321x_rearm_recover_contract()resets the controller too, but only marked its setup pending. The attempts were at zero by then, because the setup right after the wake had used or cleared them. So the next run failed withcontroller setup recovery exhaustedwithout reading the controller, and no cable update was applied until the next sleep. Both resets now go throughcd321x_setup_restart().Limits. A debug route that was armed before Linux but is not in DBMa is lost with the reset, as with any cold reset. The boot-only steps for a controller found outside S0 at the probe (HChk, then USBw after the host's start) are not repeated. A controller whose command register never becomes idle is not reset, as the command could not be sent.
Evidence
cd321x-irq(reset and set up again; after a setup that gave up; a controller that is late; every refusal, with the failed write, the rejected command and the timeout before the write) andcd321x-pm(attempts after a reset by the driver). 141/141 at this head, 143/143 together with usb: typec: tipd: debugfs commands and replug on every Mac #4056 before the review fix. With the setup only marked pending, as the old code did, all three reset cases fail (setup_pendingstays set, power state and mask are not restored). The SN201202x suite needs SUSPEND, which UML does not have, so it was only compiled.sn201202x1/1,j613-mux6/6,hardware-defaults1/1,apple-dcp(it builds functions taken from this driver) passes.W=1 drivers/usb/typec/tipd/with defconfig +asahi.configand the tipd KUnit modules: the one warning is the existingi2c.c:21enum cast.apple-dcp(its fixture compilescd321x-pm.halone and found the new helper unused); the third commit moves the helper tocd321x-setup.h.tuxvdmtoolside: tuxvdmtool: replug for a missing partner, check before every VDM, prove reboots tuxvdmtool#10 (merged) sends the command; reset-controller: document what the kernel refuses, test the whole run tuxvdmtool#11 documents and tests it.