Skip to content

usb: typec: tipd: keep a CD321x/SN201202x port from going deaf after s2idle (lost event IRQ) - #338

Merged
RyanTheTide merged 5 commits into
aurora-wipfrom
j700/tipd-s2idle-lost-irq
Oct 17, 2026
Merged

RyanTheTide merged 5 commits into
aurora-wipfrom
j700/tipd-s2idle-lost-irq

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

After an s2idle cycle, a USB-C controller on the MacBook Neo can go "deaf": it stops reporting plug, power and partner changes until the driver is rebound. It happened to the rear port on 2026-10-16.

Cause

  • The CD321x/SN201202x raises its event interrupt only on an INT_EVENT1 empty → non-empty edge, and it holds events latched until the host writes INT_CLEAR1.
  • Over SPMI, the controller sleeps during system suspend. An edge that arrives while the interrupt is suspended is replayed at the end of noirq resume, before the controller has had its WAKEUP. So the handler's event read times out.
  • The handler then returned without acknowledging, which left INT_EVENT1 non-empty. No new edge could ever arrive, so the port never interrupted again.

Fix (4 commits + 1 test fix)

  1. cd321x: never leave interrupt events unacknowledged. A failed read or clear schedules a recovery read (a status snapshot plus acknowledge). It is retried with rate-limited backoff, at least once a minute, until it succeeds. A resume always runs one. This is shared with M1/M2 CD321x on I2C, but it only changes error and resume paths: a healthy interrupt is unchanged.
  2. cd321x: recover from a failed partner identity read. This is an error path only.
  3. sn201202x: keep events unhandled while the controller sleeps. The event interrupt is disabled before SPMI SLEEP and enabled after WAKEUP, so a pending edge is handled once the controller can answer. SPMI only (J700/M3+).
  4. sn201202x: wake the controller when suspend fails. SPMI only.
  5. cd321x: don't race the recovery read in the IRQ test. Test-only. The recovery read is queued without delay, so on SMP the test's "still pending" assertion could lose to the worker. With four CPUs it failed 1 run in 5, showing up only after merging with aurora-wip. The test now checks the read's effect. A mutant that drops the resume path's queueing still fails it.

Testing

  • Review: independent re-review APPROVE. The earlier MAJOR (all three recovery reads/clears failing left the latch set) is fixed by commit 1's unbounded, rate-limited retry.
  • KUnit:
    • on the branch: cd321x-pm, cd321x-tbt, cd321x-irq and sn201202x-pm pass 48/48 with the SPMI config, and every commit bisects clean;
    • merged onto aurora-wip 3f12d3d7 with commit 5: both configs pass (43/43 and 48/48), with 10 repeated runs and the mutant check.
  • W=1: drivers/usb/typec/tipd/ is clean with the published config.
  • MacBook Neo, unattended, on 7.1.12-aurora-tipd-irq-v2-g0a7704822, with a device on both ports:
    • 23/23 s2idle cycles (20 × 8 s + 3 × 60 s);
    • 0 of every lost-IRQ signature (failed to read/clear events, failed to acknowledge, cable revalidation failed, failed to read partner identity, failed to suspend, bad_chained_irq), and 0 WARN/BUG;
    • both ports kept their partners, and their controller IRQ paths count up exactly once per cycle;
    • normalised dmesg shows no new messages against the default kernel.
  • Not covered:
    • a real replug after sleep: the Neo's tether must stay on the rear, and no non-physical stimulus raises a PD event;
    • M1/M2 hardware: commits 1–2 are error/resume-path only on I2C, KUnit covers them, and the next ref-Mac sweep includes them.

🤖 Generated with Claude Code

The CD321x and SN201202x controllers latch their events in INT_EVENT1
until the host writes them to INT_CLEAR1, and raise their interrupt
only when an event is latched while none were pending. When
cd321x_interrupt() fails to read the latched events it returns without
acknowledging them, so the controller never interrupts again, and the
port ignores every later plug, power and Alternate Mode change until
the driver is rebound. A failed write to INT_CLEAR1 does the same, and
a failed status read after the acknowledgment drops the change behind
the event.

On the J700 the rear-port SN201202x hits this after s2idle: its event
handler runs while the controller is still in SPMI sleep, the register
select times out, "cd321x_interrupt: failed to read events" is logged,
and the port stays dead for the rest of the boot. The resume
revalidation reads a fresh snapshot but leaves the latched events
alone, so it does not recover the port either.

Acknowledge latched events at the start of every snapshot read, which
covers them, and have an interrupt that could not read, acknowledge or
apply its events schedule such a read with a full retry budget. A port
whose earlier recovery gave up is included, since no further interrupt
can arrive to reopen it. Failures during suspend or probe need nothing
extra, because both end with a snapshot read. A failed read says
nothing about the cable, so it does not force a reconnect.

Keep the acknowledgment apart from the bounded budget for reading and
applying the cable state. While the events stay latched, no interrupt
can restart a recovery that gave up, so a snapshot read that fails to
acknowledge them is not charged to that budget and never gives up: it
is retried after a delay that doubles from 500 ms to at most 30 s. Sleep
cancels the retry and the resume read takes it over, and removal ends
it. Only the first failure of a series is logged.

Add KUnit tests that model the controller's event latch behind a
regmap and drive the interrupt handler and the snapshot worker. They
check that the next event still raises an interrupt after a failed
event read, clear or status read, after a failed read on a port that had
given up, and after events latched across a sleep cycle; also when the
event reads or clears keep failing long after the cable-state budget
has run out, including across a sleep cycle, before the bus recovers.
They also check that removal stops the retries. Without this change,
all of them fail except the one where the interrupt succeeds. State
machine tests check the retry delay and that the acknowledgment leaves
the cable-state budget alone.

Fixes: 45188f2 ("usb: typec: tipd: Add support for Apple CD321X")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
When cd321x_interrupt() fails to read the identity of a PD partner after
a power status change, it logs the error, clears the identity and goes
on to queue the cable update. The event has been acknowledged by then,
and nothing reads the identity again. The update then registers a new
partner with an all-zero identity, or, for a partner that is already
registered, takes the changed identity for a different partner and
tears down a working connection to register it again.

Handle the failure like the other failed reads in the interrupt: leave
the queued state alone and schedule a fresh snapshot read, which reads
the identity together with the rest of the cable state, retrying within
the usual budget.

Add a KUnit test whose identity read fails once: the identity in use
must be kept until the fresh read has succeeded, and then be replaced.
Without this change it fails.

Fixes: 36c791c ("usb: typec: tipd: Update partner identity when power status was updated")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
…er sleeps

sn201202x_suspend() puts the controller into SPMI sleep, and
sn201202x_resume() wakes it again, but its event interrupt stays
enabled for the whole time. An event latched around suspend is handled
while the controller sleeps: during suspend until the interrupt is
suspended, and during resume as soon as the interrupt is replayed after
the noirq phase, before the wakeup command has been sent. The register
select then times out and the event read fails.

On the J700 this shows up after s2idle as "sn201202x 1-0c:
cd321x_interrupt: failed to read events", logged during device resume,
with no further rear-port event for the rest of the boot.

Disable the event interrupt before the controller is put to sleep, and
enable it again once the controller is awake, or when suspend fails.
An interrupt arriving meanwhile is replayed when it is enabled, and the
resume revalidation acknowledges anything latched during sleep. A
resume whose wakeup fails still enables the interrupt, so that a later
event can be handled once the controller answers. Polled controllers
have no event interrupt and are unaffected.

Fixes: 419cafb ("usb: typec: tipd: Add sn201202x support")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
sn201202x_suspend() fails the suspend when the controller does not
confirm the SLEEP command within 100 ms, and rolls back with
tipd_resume(). The controller accepted the command, though, so it may
well be asleep with only the confirmation missing. The PM core does not
resume a device whose suspend failed, so nothing wakes the controller:
the rollback reads its registers, its event interrupt is enabled again,
and every event read then fails until the next system sleep.

Send WAKEUP before rolling back once SLEEP was accepted. A failed wakeup
is logged, and the suspend still fails with its own error. A SLEEP
command that was rejected leaves the controller awake and needs no
wakeup, as before. Failing the suspend, where the Asahi driver only logs
the missing confirmation, is kept, so that the system does not sleep
with the controller in an unknown state.

Make the system sleep callbacks visible to KUnit and test them on a
simulated SPMI bus: a sleep cycle keeps the event interrupt off while
the controller sleeps, a failed wakeup at resume still enables it, a
rejected SLEEP is not followed by a wakeup, and a SLEEP that is never
confirmed is followed by a wakeup before the event interrupt is enabled
again, also when that wakeup fails. Without this change the last two
fail.

Fixes: 38c14f6 ("drm: apple: support ProMotion variable refresh rate")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
cd321x_test_recover() asserted that the recovery read was still pending
before flushing it. The driver queues that read with no delay, so on an
SMP test machine a worker can run it before the assertion, and the test
fails although the driver behaved correctly. With four CPUs,
cd321x_resume_acknowledges_events_test failed 1 time in 5.

Check the read's effect instead. After the flush the port must accept
updates again, which it only does once the recovery read has run.
Removing the resume path's mod_delayed_work() still makes the test fail.

Fixes: 7e97f2f ("usb: typec: tipd: cd321x: Never leave interrupt events unacknowledged")
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide merged commit 3aecdf8 into aurora-wip Oct 17, 2026
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 #5
assembly 1c824ed, stacked on top-up #4 5043778 so that it is
a fast-forward of the published branch. The second parent is that
canonical assembly; the tree is identical to it.

Ported from aurora-wip, each with cherry-pick -x and its original
author:
- #338 tipd lost IRQ (5): never leave CD321x interrupt events
  unacknowledged, recover from a failed partner identity read, keep
  SN201202x events unhandled while it sleeps and wake it when suspend
  fails, and the KUnit race fix of the IRQ test (170-usb).
- #339 Touch ID verify retry (2): say why the sensor status after
  registration was unusable, and retry a failed sensor bring-up before
  a verify (100-sep).
- #340 USB and Bluetooth wake v4.1 (30): AIC wake (010-soc); xHCI,
  DWC3 and hub suspend-to-idle wake with their KUnit tests (170-usb);
  MT7932 Bluetooth wake and MSI wake for Apple PCIe (080-radio); the
  apple-dcp DWC3 wake model (200-dcp); the tools/aurora-wake regression
  tools (900-config-tooling).
- #341 apple-dcp selftests for the tipd lost-IRQ helpers (200-dcp).
- batch1 backlog: rust-clippy (4; 070-audio, 210-gpu), boot-warnings
  (3; 200-dcp), and the 4 harden-all commits not yet carried (010-soc
  qspi resume, 070-audio AOP wrapped-entry test, 200-dcp start
  completion). kunit-parsers, spi-apple-cs and the other 34 harden-all
  commits were already in the topics, including the AOP ring fix that
  top-up #4 brought; it is not duplicated.

Not ported: 3132675, superseded on 7.2.10 by b69728b
("selftests: apple-dcp: Follow the 7.2.10 driver boundaries").

Adaptations, each with a [ryan: ...] note in its commit:
- the new tipd KUnit tests take the CD321x and SN201202x data from
  the exported tipd_hw_variants[] table of 7.2.10;
- the #341 lifecycle.py import also keeps ATC_POST_TUNABLE;
- drm/asahi statistics style without the driver.rs part, which 7.2.10
  already has;
- the Rust doc example refresh only for KVec and Drain: iosys_map.rs,
  the old IoMem example and declare_flags_type!() are gone in 7.2.10;
- "Do not arm the core interrupt for wakeup" split between 170-usb and
  200-dcp.

New: 11e0ce6 ("usb: typec: tipd: cd321x: Don't race the resume
read in the sleep retry test").

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide deleted the j700/tipd-s2idle-lost-irq branch October 17, 2026 09:38
RyanTheTide added a commit that referenced this pull request Oct 17, 2026
cd321x_update_work() decides inline whether a cable update first reports
the external display as disconnected, and whether it reports the display
as connected once the mux is set.  The conditions mix Type-C session
state with the DisplayPort HPD and pin assignment bits of DATA_STATUS,
and so far they could only be exercised with real cables.

Move them into cd321x-dp.h as pure functions of the update's DATA_STATUS,
the bits that changed since the previous update and whether a display
route was up, and add KUnit tests that pin down the current behaviour.

No functional change.

[ryan: rebased onto aurora-wip 0daed2d + ATC PIPE park v3. Kconfig and
 Makefile: the tests' help text and objects follow those of the
 interrupt (#338) and held-mux (PIPE park v3) tests. core.c:
 cd321x_dp_notify() follows v3's cd321x_retry_held_mux() and
 cd321x_update_done(), and the connected event is sent before v3's
 cd321x_update_done(). No other change.]
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>

(cherry picked from commit 44e5333 ("usb: typec: tipd: Factor out the CD321x DisplayPort hotplug decisions"))
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
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