Skip to content

usb: typec: report and mitigate SN201202x liquid detection - #1053

Merged
RyanTheTide merged 8 commits into
integration/aurorafrom
work/conn8-liquid
Nov 8, 2026
Merged

RyanTheTide merged 8 commits into
integration/aurorafrom
work/conn8-liquid

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add a capability-gated Type-C contaminant attribute with unknown, none, and liquid states
  • enable and decode SN201202x liquid-detection events without exposing measurement data
  • apply controller-side mitigation before reporting liquid, keep the local port disconnected while liquid or unknown, and retry read or command failures in the safe state
  • restore detection and mitigation state after controller reset and system resume

The first patch contains only the ABI and read-only status path so it can be qualified independently. The second patch adds the mitigation command and fail-safe connection policy.

Verification

  • git diff --check origin/integration/aurora..HEAD
  • buildbox h-48964: arm64 LLVM=1 W=1 Image and modules build (rc=0)
  • buildbox h-49009: warning-clean focused class.o, spmi.o, and core.o
    build (rc=0)
  • buildbox h-48964: arm64 QEMU sn201202x-pm KUnit suite, 29 passed and
    one existing CONFIG_DEBUG_FS-only test skipped

Hardware qualification plan

Use a controlled resistance/connector fixture only; do not introduce free liquid. Instrument VBUS voltage and current independently of software.

Run the matrix on all four J616s HPM ports and both Neo HPM ports, in both cable orientations:

  1. Establish dry baselines for source, sink/charging, USB data, DisplayPort accessory, and USB4/Thunderbolt accessory cases.
  2. Apply each fixture resistance point and verify exactly one KOBJ_CHANGE transition to liquid after controller mitigation completes.
  3. As a source, verify VBUS is removed within the instrumented bound. As a sink, verify charging is refused. Verify data and accessory paths are removed without reconnect loops.
  4. Remove the fixture, wait for a clean controller measurement, and verify mitigation is removed before one transition to none and normal connection reconciliation.
  5. Repeat across runtime idle and 100 suspend/resume cycles per machine; reset the HPM during dry, liquid, and indeterminate states and verify the event mask and safe state are restored.
  6. Inject short/failed status reads and rejected/timed-out mitigation commands. Verify the ABI becomes or remains unknown, the local port stays disconnected, mitigation retries continue, and no source VBUS or sink charging is re-enabled.

Record oscilloscope/current traces, uevents, sysfs state, controller errors, and kernel logs for every physical port. The fixture matrix (real contaminant, instrumented VBUS) needs hands on the machine; the dry no-regression runs below are what landing is gated on.

Hardware results (dry connectors, no regression)

  • J616s, 4 SN201202x ports, dock attached (11-08). Kernel 7.3.0-aurora-gapneo1 = integration/aurora 1eac5fa + this branch at c312d74.
    • contaminant reads none on all 4 ports at boot and after each of 3 suspend-to-idle cycles (rtcwake -d rtc1 -m freeze).
    • Partners are kept, and the dock's 7 USB3 devices stay at 5/10 Gb/s every cycle.
    • No USB3/DP PHY failures, 0 AVC, 0 failed units; kernel warnings are the fleet's usual classes.
    • Baseline: the fleet default (same base, without this branch), same 3 cycles, gives identical USB results.
    • Before 182b62d this test failed in 2 of 2 runs (USB3 PHY bring-up failed (-110), USB2 only on the dock port).
  • Neo, 2 ports (11-07), branch head 825ce7d. contaminant = none on both ports before and after a suspend-to-idle cycle with a charger attached; journal -p err empty. The Neo has no dock, so it could not show the resume problem. It gets a re-run on c312d74 when it is back online.
  • KUnit (arm64 QEMU, tipd + sn201202x): 149 run, 148 passed, 1 skipped (DEBUG_FS-only).
  • a5b2085 (host-test fixture only, no kernel change): the apple-dcp fixtures that compile tipd_init()/tipd_remove() gain the contaminant_ops member. Before it, 20 of the 86 tests failed to build; run.sh now passes 86/86 on the buildbox.

🤖 Generated with Claude Code

Add a capability-gated Type-C contaminant state with unknown, none and liquid values. Notify sysfs and emit a port change uevent only when the state changes.

Enable the SN201202x LDCM event, validate and decode its complete status snapshot in serialized work, and refresh it after controller reset and system resume. Keep this patch read-only so status reporting can be qualified independently from controller-side mitigation.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Acknowledge liquid and indeterminate LDCM states by enabling the controller's mitigation before publishing them. Remove mitigation only after a clean snapshot, then re-read the detector before reporting dry.

Keep the local Type-C role and data path disconnected while the state is liquid or unknown. On status or command failure, publish unknown, retain the safe local state and retry without a bounded failure window. Apply the same ordering to suspend-time events and controller reset recovery.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The SN201202x SPMI driver is a separate module and calls
tps6598x_block_read() and tps6598x_exec_cmd_tmo() for the LDCM status.
With CONFIG_TYPEC_TPS6598X=m modpost fails on both undefined symbols.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J616s test (kernel 7.3.0-aurora-connliq1 = fleet17 2661d71 + this PR, fleet17 config recipe, one-shot):

  • Build fix pushed (f53b0b2): sn201202x.ko failed modpost with CONFIG_TYPEC_TPS6598X=m because tps6598x_block_read() and tps6598x_exec_cmd_tmo() were not exported.
  • After boot, contaminant reads none on all four ports and partners and USB are unchanged. No new boot-log warnings, 0 AVC, 0 failed units.
  • Regression after s2idle. After two rtcwake -d rtc1 -m freeze -s 20 cycles, the dock port's USB3 PHY does not come back. The t6040 USB PHY logs "USB3 PHY bring-up failed (-110), USB2 only", DCP logs "Type-C DP PHY init/power: -67", and the dock drops to 480M. This reproduced in 2 of 2 runs. Fleet17 with the same two cycles keeps the dock at USB3.
  • Likely suspect: the LDCM restore on resume competing with the HPM/PHY resume handshake. Consider deferring it until after the port's own resume work, or skipping it when the cached LDCM state is unchanged.

Not merging until the s2idle A/B is clean. Dock plug and unplug could not be tested remotely.

🤖 Generated with Claude Code

Picks up the tools/aurora-sep source-check fix (c60537c) and the
current release branch, so CI runs against today's base.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

No-regression hardware run on the Neo (J700, two SN201202x ports), 11-08 01:33, silent, one-shot test kernel 7.3.0-aurora-b2t3 = integration/aurora 4114f76 + this PR's head 825ce7d (merged locally) + #1105: both ports expose contaminant = none; port1 keeps its charger partner (macsmc-ac online, tps6598x-source-psy-1-0c online); after an rtcwake s2idle cycle both still read none; USB and Wi-Fi up; journalctl -b -p 3 empty; no kernel warning from tipd/sn201202x; SELinux enforcing, 0 AVC, 0 failed units. Not tested: an actual wet port (no safe way here) and the J616s (macOS until 05:00; planned after). Needs a merge of integration/aurora (82 behind) before the train.

On the J616s the dock port's USB3 PHY failed to come back after
suspend-to-idle with liquid detection enabled (2 of 2 cycles; never
without it). Every system sleep published "unknown" and every LDCM
event did too, so a cable revalidation that ran before the detector
was read again saw no plug and tore the partner down. The suspend
prepare and resume also sent an LDCM command each time, even when
nothing had changed.

Keep the last result until the controller reports a new one:

- read the detector synchronously in the interrupt and in .complete,
  before the cable state is applied, instead of publishing "unknown"
  and reading it later
- treat a measurement in progress as "no new result" when an earlier
  result exists: no mitigation change, no publish, no wake from sleep
- send the LDCM command only for a mitigation change, or when the
  controller state is unknown after a reset or a failed command
- invalidate the state only when the controller was actually reset
  (its power state or event mask had to be restored)
- revalidate the cable from the retry worker only when the published
  state changed

Failed reads still publish "unknown" with mitigation enabled, and a
liquid result is still reported only after the mitigation ACK.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
Picks up the current release branch so the test kernel and CI run
against today's base.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Note on my 01:33 Neo run: it used this PR's old head (825ce7d). GAPNEO since found that every suspend/LDCM IRQ published 'unknown' and cd321x_connect() hid the plug until 'none' (J616s dock USB3 lost after s2idle) and has the fix (gapneo/liquid 182b62d). The Neo has no dock on these ports, so that run could not show it; treat it as old-code evidence only. GAPNEO owns this PR now.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Pushed c312d74: 182b62d "usb: typec: tipd: keep SN201202x ports up across liquid checks", plus a merge of integration/aurora 1eac5fa.

Why. In the first hardware run on the J616s (2 suspend-to-idle cycles), the dock port's USB3 PHY did not come back: USB3 PHY bring-up failed (-110), USB2 only and Type-C DP PHY init/power: -67 in 2 of 2 runs. Without this series, 0 of 2 runs failed. The PHY logs show repeated power-down and bring-up attempts across resume, which means the partner was dropped and reconnected.

Code cause:

  • Every system sleep and every LDCM interrupt published unknown.
  • cd321x_connect() hides the plug while the state is not none.
  • Cable revalidation and the LDCM worker race on system_freezable_wq, so revalidation could apply "no plug" before the detector was read again.
  • prepare/complete also sent an LDCM 4CC on every cycle.
  • check_setup() invalidated the detector on any unexpected event, even when the controller had not been reset.

Change.

  • The detector is read synchronously in the interrupt and in .complete, before the cable state is applied.
  • A measurement in progress keeps the previous result when one exists: no mitigation change, no publish, no wake from sleep.
  • The LDCM command is sent only for a change, or when the controller's mitigation state is unknown (after a reset or a failed command).
  • The detector is invalidated only when the controller had to be restored (it was really reset).
  • The retry worker revalidates the cable only when the published state changed.
  • Failed reads still publish unknown with mitigation on, and liquid is still published only after the mitigation ACK.

Checks (buildbox).

  • KUnit, arm64 QEMU (tipd + sn201202x suites): 149 run, 148 passed, 1 skipped (the existing DEBUG_FS-only case). This includes 3 new LDCM cases: a running measurement keeps a none or liquid result, a measurement with no earlier result stays unknown and mitigated, and a read failure is never taken for a running measurement.
  • checkpatch --strict: 0/0/0.
  • W=1 on drivers/usb/typec/tipd/ and class.o: no new warnings. The only warning is the existing i2c.c enum cast, which this series does not touch.
  • Fleet-recipe test kernel 7.3.0-aurora-gapneo1 built from c312d74.

Next. No-regression run on the J616s (all 4 ports, the dock port, repeated s2idle), then the Neo once it is back. This stays a draft until those pass.

@RyanTheTide
RyanTheTide marked this pull request as ready for review November 7, 2026 19:14
The quiesce and transaction fixtures compile tipd_remove() and
tipd_init() from core.c against a reduced struct tps6598x. Both now
call through tps->contaminant_ops, so the fixtures stopped compiling
and 20 apple-dcp host tests failed to build. Add the member and the
two callbacks those paths use; the fixtures leave it NULL, as on
controllers without liquid detection.

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J616s no-regression run, 2026-11-08 06:07-06:14 AEDT (lane GAPNEO; posted by the J616s queue keeper). Stage 2 DTB: integration J616s e4292d96.

  • Baseline, fleet27 default (integration 95e30d5), 3x rtcwake s2idle: dock USB3 devices 7/7 after every cycle, 3 partners, 0 PHY failures.
  • One-shot 7.3.0-aurora-gapneo1 (integration 1eac5fa + this PR at c312d74, including the resume fix), same 3x s2idle gate:
    • contaminant=none on all 4 ports at boot and after each resume.
    • Dock USB3 devices 7/7 every cycle; the 11-07 regression was a USB3 PHY bring-up -110 in 2 of 2 cycles.
    • 0 PHY/DP failures, partners kept, SELinux enforcing with 0 AVC, 0 failed units, kernel warnings limited to the existing fleet classes.
  • Test kernel removed afterwards; the J616s is back on the fleet27 default.

Not exercised: a real liquid or contaminant event. Merge is held for Ryan's hands-on unplug/replug pass, because the mitigation can cut VBUS/charging.

@RyanTheTide
RyanTheTide merged commit 36d9198 into integration/aurora Nov 8, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the work/conn8-liquid branch November 8, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant