Skip to content

usb: typec: tipd: survive probe-time read errors and liquid measurements, recover lost plug events - #3280

Merged
DjDeveloperr merged 6 commits into
aurora-silicon:mainfrom
rolotrealanis98:fix/tipd-hotplug
Dec 1, 2026
Merged

DjDeveloperr merged 6 commits into
aurora-silicon:mainfrom
rolotrealanis98:fix/tipd-hotplug

Conversation

@rolotrealanis98

@rolotrealanis98 rolotrealanis98 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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
  1. 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, and tipd_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 real tipd_init() takes the new helper and three cases for this.
  2. 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.
  3. 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 as cd321x_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
  • KUnit (arm64 QEMU, LLVM) 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.py with this PR merged on main: 696/696 (includes the apple-dcp probe-transaction-rollback cases above).
  • checkpatch.pl --strict: 0/0/0 per commit. W=1 build of drivers/usb/typec/tipd/: no warning in changed code.
  • J716s row at 9baf5ec (kernel code identical to the tested build): read-only check and one unbind/bind per USB-C port controller, results as in Tested. The same three changes were written on 2026-11-19 and have been in this machine's everyday kernel since.

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T17:16:05.640960Z 9baf5ec PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +557 to +559
case 1:
ret = ops->rerun(ctx);
return ret ?: -EINPROGRESS;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@github-actions github-actions Bot added area:usb Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 427f46d7: not ready yet

Check Detail
CI at head ok 25 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at 427f46d7
Conflicts ok none
PR text ok Risk: two-way · 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.

Areas: area:usb

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

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:

Port plug changes partner changes longest plug/partner disagreement
Left-front (1-0a) 6 6 ≤ 3 s
Right (2-0c) 6 4 ≤ 3 s
  • On the right port two partner changes fall inside one 1 s sample (an unplug and replug under a second apart); the kernel log has a cable detach and a cable attach for every cycle, and the device enumerated each time (high speed; also SuperSpeed Plus Gen 2x1 on the right port).
  • Commit 3's recovery fired once: sn201202x 1-0a: plug gone without an event, reading the port again, after which the port state agreed with the plug again.
  • Plug bit and partner agree on every port at the end; 0 probe failures, 0 SError, 0 WARNING/BUG/Oops, no deferred probes.
  • Twice a detach logged cable detach: SSPS 0x2: -110 (the SSPS read timed out); the detach completed and the next attach was normal.

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>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

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):

  • All three port controllers bound; on both USB-C ports plug bit = registered partner, contaminant none, liquid detection idle, mitigation off; 0 probe failures, 0 "contaminant state unavailable", 0 bounded-wait overruns.
  • Unbind/bind of each USB-C port controller: bound again within 1 s, contaminant none, LDCM idle, 0 -11 lines in the 12 s after.
  • 0 failed units, 0 SError, 0 WARNING/BUG/Oops, no deferred probes.

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).

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 27, 2026
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>
@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

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.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 27, 2026
…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>
@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

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 ->held() op.

Tests (sn201202x-pm): a new table-driven case, sn201202x_ldcm_hold_mitigation_failure_retried_test, runs sn201202x_ldcm_update_state() with the real wait through the second overrun. It covers 0, 1 and 3 failed mitigation commands, with the retries either on time or each 5 min late. After each failure it checks the error is returned, "unknown" stays published, no hold is running, the next delay is 2 s, and the next update sends the mitigation again with no restart. After the success it checks -EAGAIN, a 10 s delay to the end of the hold, nothing restarted one jiffy before the end, and a restart at the end. The existing hold cases now also check what ->held() is told, and the wait/backoff cases cover a failed hold mitigation (2 s retry, the hold doesn't run out) and a hold timed from the mitigation that succeeded.

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).

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train re-review of 10c960b4..427f46d7: the 11-27 blocker is fixed. sn201202x_ldcm_wait_held() starts the hold clock only from a set_mitigation(true) that succeeded. A failed command clears held, so wait_overdue() keeps returning 2 (resend the mitigation) and never schedules a rerun, and retry_ms() drops to the 2 s slow retry instead of the up-to-5-min hold. A later failure inside a running hold restarts the hold from the next success. Both KUnit op tables gain .held, and the sim test covers the failed-then-succeeded path. No new finding. Before merge: hosted CI at this head (all pending in the runner backlog), the review App's re-review at 427f46d7, and a hardware row at this head (a tipd SPMI Mac: plug/unplug + one short s2idle).

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) labels Nov 28, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 29, 2026
@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

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):

  • Partners present at probe (new in this row): a USB4 dock on the left-front port (CIO mode, USB3 over the USB4 tunnel) and a Thunderbolt host on the right port were plugged through the boot. All three port controllers bound; on both USB-C ports plug bit = registered partner, contaminant none, liquid detection idle, mitigation off; 0 probe failures or rollbacks, 0 port state unreadable at probe, 0 SPMI bus errors.
  • Liquid measurement: 0 contaminant state unavailable, 0 liquid-detection status unavailable, 0 gave no result (first or second wait), 0 hold lines.
  • Rebind: each USB-C port controller unbound and bound once: bound again with the partner, contaminant none within 1 s, LDCM idle, mitigation 0, 0 -11 lines afterwards.
  • 0 failed units, 0 SError, 0 WARNING/BUG/Oops.

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 hardware teardown failed on remove: -16, and the dock's SuperSpeed devices do not come back until a replug or reboot; the J716s default kernel without this PR does the same, so I'll take it up separately.

@rolotrealanis98

Copy link
Copy Markdown
Contributor Author

Ready on everything pr-readiness checks except the approving review: CI at 427f46d passes, the J716s row at 427f46d is above, RyanTheTide's J616s row at the same head passed, no conflicts. Could a Core or Omarchy Mac maintainer take the review?

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@DjDeveloperr
DjDeveloperr merged commit e19c0c2 into aurora-silicon:main Dec 1, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:usb Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants