Repository navigation
usb: typec: tipd: survive probe-time read errors and liquid measurements, recover lost plug events - #3280
Conversation
With a hub plugged in at boot, a J716s (SN201202x on SPMI) has failed its left port controller's probe on 2 of 25 boots: one frame failed its SPMI parity check, the power status read that follows a present plug returned -EIO, and tipd_init() rolled the whole port back with -EINVAL. The port then had no driver, no USB controller and no hotplug for the rest of the boot; binding the driver again by hand brought it up at once. Retry the power and data status reads of a plug present at probe a few times. On variants with a ->ready() hook (CD321x and SN201202x), which reads the whole cable state again with its own bounded retries once the port is ready, a read that still fails no longer fails the probe: the partner is registered by that revalidation instead, and the plug is left out of the snapshot so that it still counts as new when it is read. The other variants keep failing the probe as before. Likewise, when the best-effort renegotiation of an inherited connection fails, a failed status read after it keeps the status read before instead of failing the probe. Both status reads of the renegotiation go into a copy that replaces the caller's status only on success: the Apple SPMI controller stores a frame before it checks its parity, so a failed read leaves garbage behind, which the probe would otherwise have connected with. The apple-dcp host test that runs the real tipd_init() (probe-transaction-rollback) takes the new read helper and checks that a plug present at probe is read again after a failed read, still fails the probe without a ->ready() hook, and with one probes and leaves the plug out of the snapshot. Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
On a J716s, the left port controller (polled SN201202x on SPMI) lost the port for good after an unbind and bind with a hub plugged in: every later probe logged "connector contaminant state unavailable: -11", and the hub was never seen again, replugged or not. The controller showed the plug (STATUS 03: plug present, connection state "disabled"), no partner and no pending event, with its liquid detector in state 3 (LDCM status 09 06 00 00) instead of idle. sn201202x_ldcm_update_state() keeps the last result while a measurement runs, but at probe (and after a reset) there is no last result, so a running measurement was handled as an unknown connector state: liquid mitigation was forced on, "unknown" was published and -EAGAIN returned. The mitigation disables the port, the measurement it interrupted never finished, and the retry every 500 ms found it still running, forever. Nothing in the driver removes the mitigation either: cd321x_reset() does nothing, so the controller kept it across unbind and bind, and each new probe found the same measurement and mitigated again. The same forced mitigation at boot ran an LDCM command for over two seconds right before the SPMI parity errors that failed the boot-time probe. With no earlier result, leave the mitigation as it is while the controller measures. The port stays down meanwhile, as before: the cable state is applied only for a dry connector. The wait is bounded: - A measurement still running after SN201202X_LDCM_STUCK_MS (5 s) is made to start again: LDCM 0 is sent even if the controller is taken to be unmitigated already, which is what gets it out of the stuck state. The port stays down, and "unknown" stays published. - Only if the measurement run again overruns its own 5 s wait too is it ended toward a working port: handled as a dry result, so that the port is enabled while the controller measures on. Liquid it then reports is mitigated as always. - Once a wait has been overrun, the 55-byte status is read every 2 s instead of every 500 ms until a result comes. A port reported wet is never enabled by these waits. Liquid is now remembered until the controller reports a dry result or is reset, not only through what was last published: a mitigation command that fails publishes "unknown", and the measurement that followed would otherwise have taken the waits above as if there had been no result. While wet, such a measurement mitigates and reports the liquid again instead. A failed read or mitigation command after a liquid result also keeps the liquid published instead of "unknown". A measurement that follows a result still keeps that result and its mitigation however long it runs. Known limit: the wet state lives in the driver's data, so an unbind and bind forgets it, and the new probe starts without a result. A bus error is no evidence of liquid either. A failed status read of a port reported dry, which may carry a live dock or display, no longer mitigates it and publishes "unknown" at once, which tore its data paths down and, with a measurement still stuck, cost a mitigation on and off each time: the read is retried every 2 s, and only SN201202X_LDCM_READ_TRIES (3) failures in a row mitigate. The system sleep may be entered with the dry result kept meanwhile. A port without a result, or reported wet, is mitigated at the first failure as before. The suspend-to-idle event path (sn201202x_sleep_event()) busy-waits, and never removes mitigation there: no wait runs out in it, and a dry result that would need LDCM 0 is refused there, which wakes the system so that the update after the resume sends it. Entering system sleep while a measurement without a result runs mitigates first, also right after a measurement was started again, so the sleep keeps its "dry snapshot or mitigation" rule, and the waits go on after the resume. The exception is a second overrun that runs out in system sleep preparation's own update: the port is then enabled and the sleep entered with it, as anywhere else. A result read on a retry comes with no controller event, and the resume work that was queued to apply it does nothing while the port is running: it reads only in a revalidation. Ask for one instead, through the new cd321x_revalidate(), so that a port enabled by the second overrun wait is also applied. Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
…lers A J716s port whose controllers have no interrupt line (both of its SN201202x on SPMI are polled every 500 ms) has been seen with the plug present in STATUS, nothing pending in INT_EVENT1 and no partner in the driver: the hub plugged into it was never enumerated. The plug event is an edge. Once it has been acknowledged without the cable state behind it being applied, or lost altogether, cd321x_interrupt() returns at once on every poll that finds no event, and nothing compares the plug state again until the next replug. On every poll without an event, read STATUS and take its plug bit, masked as cd321x_connect() masks it for a connector not known to be dry. Compare it with the last snapshot and with whether a partner is registered: cd321x_connect() takes the snapshot before the update work applies it, so an update that gave up leaves the snapshot right and the partner missing. If either differs, in either direction, request the same fresh read that recovers events an interrupt could not read (cd321x_event_lost()). This also applies a plug that a liquid-detection result unmasked without an event of its own. The comparison is skipped while a revalidation or an update is already under way, which settles the state anyway: requeueing debounced work on every 500 ms poll could keep pushing it back. It requests one read for each plug state that is not applied: a revalidation that gives up again waits for the next controller event or plug change, as before, instead of being restarted with a full budget (and its error) on every poll. A failed STATUS read only skips one comparison. Interrupt-driven controllers are not affected; on the J716s the polled controllers never sleep while idle (idle sleep needs the event interrupt), so a poll does not read a sleeping controller. Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9baf5ec96f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case 1: | ||
| ret = ops->rerun(ctx); | ||
| return ret ?: -EINPROGRESS; |
There was a problem hiding this comment.
Retry failed LDCM restarts before advancing the timeout
When the first rerun fails before the command is sent (for example, an SPMI read error or -EBUSY in tps6598x_exec_cmd_gap()), ops->overdue() has already advanced the wait counter to 1. Nothing rolls that back, so subsequent retries skip rerun() and eventually enter the default branch. If mitigation removal then succeeds, the first successfully restarted measurement can still return UNKNOWN, yet the function immediately publishes TYPEC_CONTAMINANT_NONE and allows the cable to be enabled without the intended second 5-second measurement window. Keep the restart pending on failure, and begin its second wait only once rerunning succeeds.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, this was reachable: the second wait started when the first ran out, before LDCM 0 was sent, so a failed restart (bus error, -EBUSY, timeout) left the next updates waiting instead of retrying, and the port could be enabled without the restarted measurement ever getting its 5 s. Fixed in 15cd37c: after the first overrun the restart stays due, and every update sends it again until it goes through; the second wait runs from the restart that succeeded. Enabling the port takes the same LDCM 0 command, so this never keeps the port down longer than before. The new KUnit case sn201202x_ldcm_wait_rerun_failure_test covers it (tipd.kunitconfig: 180 run, 179 passed, 1 skipped; host tests 696/696; checkpatch --strict clean).
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Plug/unplug row at 9baf5ec (J716s, 16" MacBook Pro M5 Pro, macOS 27.3 beta stub; same test kernel as in Tested). A person plugged and unplugged a USB-C device, 3 cycles per port, while the port state was sampled every second for 180 s:
Still not covered: a hub plugged in at probe (commit 1's retry path) and a second polled board (J714s, J716c). |
A liquid measurement without an earlier result that overruns its 5 s wait is made to start again (LDCM 0), and the port is enabled only if the measurement run again overruns its own 5 s wait too. The second wait started when the first one ran out, before the restart was sent, and nothing undid that when the command failed: a bus error before or while it was sent, a controller still busy with another command (-EBUSY), or no completion. The next updates then found the wait running instead of restarting, and 5 s later took the second overrun: mitigation was removed and the port enabled with no measurement ever restarted, or right after the removal itself restarted it, without the 5 s that measurement was meant to get. Keep the restart due until it goes through. After the first overrun, sn201202x_ldcm_wait_overdue() answers 1 again, so every update (every 2 s, as after any overrun) sends LDCM 0 again, and the second wait runs from the restart that succeeded, timed from its completion. A restart refused in the suspend-to-idle busy-wait stays due as well. "Measuring again" is logged once, not on each attempt. The port is not held down longer by this than by the old path: enabling it after the second overrun takes the same LDCM 0 command, which could not succeed where the restart failed either. The sn201202x-pm KUnit wait test now marks the restart, and a new case keeps a failed restart due across what used to be the second wait and checks the second wait from the restart that went through. Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: FINISH, then merge at 15cd37c462a9722be2650a9a7b80e17df36378dd
Blocker: sn201202x_ldcm_update_state() converts an unknown result into TYPEC_CONTAMINANT_NONE when the second wait expires. The earlier wet() guard only protects a connector which has already reported liquid. A connector that is wet at first probe and never produces a valid result can take the timeout branch and have mitigation removed and cable state applied. Keep the connector unavailable after timeout until a valid dry result, or document and demonstrate an independent controller interlock which covers this unknown-result case. Test the permanent-unknown path with no prior reading.
Checked: Read the actual timeout branch, wet latch, dry-read retry and polled plug recovery. The current hardware comments refer to the earlier 9baf5ec9 head. Please identify matching tested blobs at this head or post an exact-head feature/peer row. Perform any moisture-interlock validation with an approved test setup. No bindings or per-board gating added.
|
J716s row at the new head 15cd37c (16" MacBook Pro M5 Pro, macOS 27.3 beta stub; test kernel = the J716s tree with this PR's diff vs main in place of its own copy, release 7.3.0-g61cf7df262b7):
The plug/unplug cycles above were at 9baf5ec; 15cd37c changes only the path after a failed liquid-measurement restart, which no cycle reached (0 "measuring again" lines in either run). |
A port without an earlier liquid-detection result (at probe, after a controller reset) whose measurement overran its 5 s wait, was made to measure again (LDCM 0) and overran its 5 s again was handled as dry: the cable state was applied and the port enabled. The wet() guard only covers a port that has reported liquid, so a connector wet at probe whose measurement never gives a result was enabled 10 s later. No length of time now turns a missing result into "dry". After the second overrun the port is held: mitigation is enabled and "unknown" stays published, so the cable state stays masked (cd321x_connect() keeps every role and data path down for anything but "none"). At the end of each hold the controller is made to measure again with LDCM 0, and that measurement gets a whole 5 s wait, with the port still down; if it gives no result either, the next hold starts. Holds last 10 s, doubled each time up to 5 min. Only a result read from the controller ends this: dry enables the port through the usual dry path, liquid is mitigated and reported. A hold is not polled, its retry is set for its end (a controller event still runs an update at once), so a port that never gets a result costs 16 restarts in the first hour and one every 5 min after that. Two warnings per such port, the rest at debug level; a result that ends a hold is logged once. This does not rely on a controller-side interlock. Nothing the driver documents, and nothing seen on the hardware, shows the SN201202x keeping its port off while a measurement is pending: the LDCM status register reports only the state, the result and the mitigation, and the LDCM command is the only mitigation the driver has. The J716s case this series fixed stays fixed. That port was lost because mitigation was forced on in the middle of the measurement running at probe, and nothing removed it: the controller stayed in LDCM state 3, every update read "measuring" and sent nothing, and the port stayed down for good. The two waits are unchanged (no mitigation while the first measurement runs, the restart after 5 s), so a slow measurement that ends within them enables the port as before; on the J716s none needed even the restart. A hold mitigates, but every hold ends with LDCM 0, the command that got that controller out of state 3, and a dry result read at any time, in a wait or in a hold, enables the port. The only change is for a measurement that never ends: the port stays down instead of being enabled. The work now sets its retry under the port lock, as the retry delay is taken from the wait, which changes under that lock. KUnit (sn201202x-pm): the cases for a second overrun now expect the hold (mitigation on, "unknown", -EAGAIN, nothing else read); new cases read dry or liquid during a hold, check a failed hold command, and the backoff (10 s to 300 s, the retry at the end of a hold, a failed restart at the end of a hold kept due). Two cases run sn201202x_ldcm_update_state() with the driver's wait on a clock driven by the driver's retry delays: a port with no earlier reading whose measurement never ends (one hour: never published dry, held mitigated, 16 restarts, fewer than 200 updates; then a dry result enables it within one hold), and slow results at 3, 7, 12 and 60 s, each enabling the port when it is read. Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
|
Agreed. Nothing in the driver or the hardware shows an interlock in the controller: the LDCM status register only reports state, result and mitigation, and the port is kept down by the driver alone while the published state isn't "none". Fixed in 10c960b: no amount of time turns a missing result into dry any more. After the second overrun the port is held with mitigation on and stays "unknown", so the cable state is not applied; after each hold (10 s, doubling up to 5 min) the controller is made to measure again with LDCM 0, with the port still down. Only a dry result read from the controller enables it. The two waits before that are unchanged, so a slow measurement that finishes inside them still enables the port, and each hold ends with the command that got the J716s controller out of its stuck state. New KUnit cases: the permanent-unknown path with no prior reading (an hour simulated: never dry, held mitigated, 16 restarts in fewer than 200 updates; a later dry result enables it), dry and liquid results read during a hold, a failed hold command, the backoff, and slow results at 3/7/12/60 s. tipd.kunitconfig 183 run, 182 passed, 1 skipped; host tests 696/696; checkpatch --strict clean; W=1 adds no warning in changed code. The J716s row at this head follows. |
There was a problem hiding this comment.
The old timeout-to-dry defect is fixed. One failure path still blocks this head. The second overrun changes the wait state to hold before set_mitigation(true) succeeds. When that command fails, sn201202x_ldcm_retry() still computes its delay from the hold state and can wait up to five minutes before another attempt. At expiry it can send a rerun command without ever successfully enabling protection for that hold. Publishing UNKNOWN guards the Linux partner path, and the prior review established that no independent hardware interlock is known. Please start the long hold only after successful mitigation, keep failed commands on a short retry, and add a test that checks the next action and delay after command failure. The exact-head feature and peer rows also remain pending.
…gated A port without a liquid result whose measurement overran both waits is held: mitigation is enabled, "unknown" is published, and at the end of the hold the controller is made to measure again with LDCM 0. The hold began at the second overrun, before the mitigation command was sent, and nothing undid that when the command failed. The retry was then timed from the hold (up to 5 min away), and at the hold's end the restart removed the mitigation of a hold that had never been mitigated. "Unknown" kept the port's roles and data paths down meanwhile, but no controller-side interlock is known to cover a pending measurement. A hold now starts only when its mitigation went through. Until then the port stays down and "unknown", every update sends the mitigation again, and the retry comes every 2 s, as after a failed restart. However late an update comes, it never restarts the measurement from a hold that was not mitigated. The hold's time runs whole from the command that went through; later ones in the same hold do not stretch it, and a failed one makes the hold wait for the next success. A new ->held() op tells the wait whether the hold's command went through. KUnit (sn201202x-pm): the two hold cases also check that ->held() is told of the command's result; the wait and backoff cases check that a hold whose mitigation failed is retried every 2 s and does not run out, and that the hold runs from the mitigation that went through. A new table-driven case drives sn201202x_ldcm_update_state() through the second overrun with 0, 1 or 3 failed mitigation commands, retried on time or only after 5 min each: each failure is followed by a 2 s retry that sends the mitigation again and no restart; the success by a whole 10 s hold, nothing restarted 1 jiffy before its end, and a restart at its end. Signed-off-by: Rolando Trevino <122947376+rolotrealanis98@users.noreply.github.com>
|
Fixed in 427f46d. A hold now starts only after set_mitigation(true) succeeds. At the second overrun the port is published "unknown" and the mitigation command is sent. If it fails, the hold has not started: the retry comes after 2 s, the same delay as a failed restart, and every update sends the mitigation again. The wait never moves to the restart, however late the update comes, so LDCM 0 is never sent from a hold that was never mitigated. The hold's 10 s (doubling to 5 min) is timed from the command that succeeded. Later successful commands in the same hold don't extend it. A failed one makes the hold wait for the next success. The update path reports the command's result to the wait through a new Tests (sn201202x-pm): a new table-driven case, tipd.kunitconfig: 184 run, 183 passed, 1 skipped (dbma_held, needs DEBUG_FS). Host tests 696/696. checkpatch --strict clean. W=1 shows no warnings in drivers/usb/typec/tipd/ beyond the two already on main (i2c.c enum cast, tipd_port_replug prototype). |
|
Merge-train re-review of |
There was a problem hiding this comment.
Verdict: MERGE at 427f46d after required CI and exact hardware evidence.
Checked: Failed mitigation leaves held clear, keeps the port unknown, and uses the two-second retry. Even a late update cannot rerun the measurement before a successful command and a full hold. A failure during the hold clears the latch, and the next success starts a fresh hold. The fixture checks failed, delayed and successful commands and the expiry boundary. The author reports 183 KUnit passes with one skip and 696 host tests. Keep the SPMI feature and peer checks on this exact head.
|
Row (J616s, M4 Pro) at exact head 427f46d in combined candidate cedaeff9ee2fe5396733351bb571d0a6049bd7fc on main aa76613: boot + 2 rtc1 s2idle with the existing tether and charger -> PASS (0 tipd/tps6598x/cd321x warn/err lines, typec ports and partners same as production, AC online, USB4 tether 20 Gb/s both ways before and after sleep). Evidence: traces/kernel/20261129-closeout-j616s-combo/. Saved boot restored. |
|
J716s row at 427f46d (16" MacBook Pro M5 Pro, macOS 27.3 beta stub; test kernel = the J716s tree with this PR's diff vs main in place of its own copy, release 7.3.0-g0156de1b2b9b):
Not run at this head: plug/unplug cycles (the 3-cycle row is at 9baf5ec above; nothing on that path changed since). Not from this change, for the record: unbinding the left-front controller with the USB4 dock attached logs main's |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict MERGE at 427f46d7d27abb06ab0c8f1f1e39dc311e867bb1
Blockers None.
Checked Probe defers cable application after transient read errors and revalidates when ready. The liquid-detection retry keeps a known wet result and requires a completed mitigation command before starting a hold. The KUnit cases cover failed mitigation, hold expiry and a later dry result. The J716s boot and port rebinds and the J616s boot and two suspend cycles passed at this head. Hosted build and host tests passed.
What: keep a USB-C port usable through three failures seen on a J716s (polled SN201202x on SPMI): a bus error on the status read of a plug present at probe no longer fails the probe; a liquid measurement running at probe is waited for instead of forcing mitigation for good; a plug change whose event was lost is noticed on the next poll.
Tested: J716s (16" MacBook Pro, M5 Pro, macOS 27.3 beta stub) at 15cd37c (test kernel: the J716s tree with this PR's diff vs main in place of its own copy): all three port controllers bound, controller plug bit = registered partner on both USB-C ports, contaminant none, liquid detection idle with mitigation off, 0 probe failures; unbind/bind of both USB-C port controllers: bound again within 1 s, contaminant none, no -EAGAIN loop; 0 failed units, 0 SError, 0 new kernel errors. KUnit, host tests and checkpatch --strict pass (Evidence).
Risk: two-way door · Macs with CD321x/SN201202x port controllers. The liquid changes act only on SN201202x ports with liquid detection (M3 and later, not MagSafe); the poll comparison only on controllers without an interrupt line (the J716s's); the probe change only when a status read fails with a plug present.
Not yet: a hub plugged in at probe on this head; a second polled board (J714s, J716c). Plug/unplug cycles on both USB-C ports: in the comments.
Details
usb: typec: tipd: survive a transient status read at probe: with a hub plugged in at boot, a J716s failed its left port controller's probe on 2 of 25 boots: one SPMI frame failed its parity check, the power status read after a present plug returned -EIO, andtipd_init()rolled the port back. The port then had no driver, no USB controller and no hotplug until the next boot. The power and data status reads of a plug present at probe are now retried a few times; on variants with->ready()(CD321x, SN201202x), which revalidates the cable state with its own bounded retries, a read that still fails no longer fails the probe, and the plug is left out of the snapshot so that it counts as new. The best-effort renegotiation of an inherited connection keeps the status read before on a failed read after it; both reads go into a copy (the Apple SPMI controller stores a frame before it checks parity, so a failed read leaves garbage). Variants without->ready()fail the probe as before. The apple-dcp host test that runs the realtipd_init()takes the new helper and three cases for this.usb: typec: tipd: sn201202x: leave a running liquid measurement at probe: after an unbind/bind with a hub plugged in, the port was lost for good: every probe logged "connector contaminant state unavailable: -11". With no earlier result, a running measurement was treated as unknown and mitigation forced on, which disables the port and interrupts the measurement, and nothing removed it again. Now, with no earlier result, mitigation is left as it is while the controller measures (the port stays down meanwhile, as before), with two 5 s waits: after the first the measurement is made to start again; if that one overruns too, the port is held down with mitigation on and the state stays unknown, and the measurement is restarted after each hold (10 s, doubling up to 5 min). Only a dry result read from the controller enables the port; no amount of time without a result does. A port reported wet is never enabled by these waits; liquid is remembered until a dry result or a reset. One failed status read of a port reported dry no longer mitigates it (three in a row do). The suspend-to-idle busy-wait never removes mitigation.usb: typec: tipd: cd321x: recover a lost plug event on polled controllers: a polled port has been seen with the plug present in STATUS, nothing pending and no partner, so the hub was never enumerated. On every poll without an event the plug bit (masked ascd321x_connect()masks it) is compared with the snapshot and with whether a partner is registered; a difference requests the same fresh read that recovers unreadable events, once per plug state, and not while a revalidation or an update is already under way. Interrupt-driven controllers are not affected.No board or SoC check: the liquid rules key on the controller having liquid detection, the poll comparison on the controller having no interrupt line. Related: #2398 changes the same files (busy controller at probe, shutdown idle, native HPD by DT property); the two merge without conflict.
Evidence
TYPEC_TIPD_KUNIT_TEST+TYPEC_SN201202X_KUNIT_TEST: 179 run, 178 passed, 1 skipped (needs CONFIG_DEBUG_FS), 0 failed; the new lost-plug cases are in cd321x-irq, the liquid cases in sn201202x-pm.tools/asahi/run-host-tests.pywith this PR merged on main: 696/696 (includes the apple-dcpprobe-transaction-rollbackcases above).checkpatch.pl --strict: 0/0/0 per commit.W=1build ofdrivers/usb/typec/tipd/: no warning in changed code.