Skip to content

usb: typec: tipd: sn201202x: retry waking-controller register select sooner - #3014

Merged
RyanTheTide merged 1 commit into
mainfrom
satchlj/sn201202x-fast-wake-async-pm
Nov 25, 2026
Merged

RyanTheTide merged 1 commit into
mainfrom
satchlj/sn201202x-fast-wake-async-pm

Conversation

@satchlj

@satchlj satchlj commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

While a sleeping SN201202x USB-PD controller is waking up, a register selection sent before it is awake is never confirmed. sn201202x_wake_poll() called regmap_sn201202x_select_reg(), which waited a full 100 ms per attempt before timing out and letting the wake loop retry.

Split out sn201202x_select_reg() with an explicit timeout_us parameter:

  • Normal register access keeps the existing SN201202X_SELECT_TIMEOUT_US (100 ms) timeout via regmap_sn201202x_select_reg().
  • sn201202x_wake_poll() passes SN201202X_WAKE_SELECT_TIMEOUT_US (5 ms), clamps atomic polled selects with min_t(unsigned int, timeout_us, SN201202X_ATOMIC_SELECT_MS * 1000), uses max(1UL, usecs_to_jiffies(timeout_us)) for completion waits, and accounts budget_ms -= SN201202X_WAKE_SELECT_TIMEOUT_US / 1000.
  • Updated tools/testing/selftests/drivers/apple/sn201202x-transport.py to match the split helper.

(Note: the earlier async PM commit was dropped per review because device_enable_async_suspend() without explicit device_link / dependency audit risks racing Type-C consumers.)

Verification

  • Static checks: scripts/checkpatch.pl --strict --git origin/integration/aurora..HEAD — 0 errors, 0 warnings, 0 checks; W=1 arm64 build (drivers/usb/typec/tipd/spmi.o) — 0 new warnings.
  • Host transport selftest: python3 tools/testing/selftests/drivers/apple/sn201202x-transport.py — 6/6 PASS.
  • Hardware validation on lobata (Mac Studio M5 Max / J775c / T6050):
    • Provenance: Combined kernel built from origin/integration/aurora (160ca431b325) + exact PR head f7dc93cbbf5c, Image.gz SHA-256 5b3848aaf84041154d36e3268d904db95a9a176398d78c1a01730a6cd8c9b7dc, paired with J775c DTB 0442bec28ef4c650d4e3395589f7001808c7e5b4a3bdd4971fc466d68f9de0ed, default kernel cmdline (rdinit=/init nr_cpus=18 maxcpus=18 root=UUID=3da7492b-6c5e-4e84-9eac-65b89fae44c6 arm64.nomte), boot_id: 0535fd99-4dca-412e-b2ca-a4042e37cd4c.
    • All 4 SN201202x controllers (0-06, 0-08, 0-0a, 0-0c) bound cleanly (with 0-0c cleanly left in DBMa debug mode) and completed a full device-PM s2idle suspend/resume cycle (pm_test=devices, echo freeze > /sys/power/state, 124.395 s -> 132.080 s; /dev/rtc0 is unavailable on this mixed DTB because macsmc-rtc defers on baseline apple-spmi Gen4 -95) with 0 sn201202x warnings or errors.
    • Health tuple: SELinux N/A (Arch Linux -SELINUX); 0 new failed systemd units (pre-existing ac-power-mode.service); 0 new dmesg -l err,crit,alert,emerg lines beyond the 4 pre-existing baseline lines (apple-spmi -95, apple_aop -61, apple-dcp x2).
    • Other affected platforms: Applies to all SN201202x Apple SoCs (T8132/T8142/T6040/T6050); full deep-sleep/RTC-wake testing on T6040/T8132/T8142 is welcome.

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

Adversarial pre-PR checklist (§1–§6) review at 2e4427c52c3f2a2febbfcc1e812dadbcc7a95028: REQUEST_CHANGES (2 blockers; live CI host-tests: FAIL).

Blockers

  1. CI failure in host-tests (apple/sn201202x-transport, tools/testing/selftests/drivers/apple/sn201202x-transport.py:95,157-162)

    • Live check run host-tests failed with AssertionError at sn201202x-transport.py:162.
    • Commit bc4eacb9634d moved the select-polling implementation (including err || val == reg) out of regmap_sn201202x_select_reg() into sn201202x_select_reg(sdev, reg, timeout_us), leaving regmap_sn201202x_select_reg() as a 1-line wrapper. Because sn201202x-transport.py still extracts only regmap_sn201202x_select_reg and __regmap_sn201202x_read, busy = program.replace("err || val == reg", ...) no longer matches (and the generated C harness also misses sn201202x_select_reg, SN201202X_SELECT_TIMEOUT_US, usecs_to_jiffies, and max).
    • Fix: Update tools/testing/selftests/drivers/apple/sn201202x-transport.py to extract sn201202x_select_reg and provide the required stubs/macros so host-tests passes cleanly.
  2. device_enable_async_suspend(&device->dev) breaks DPM ordering assumptions relied on by tipd_usb_wake() and sn201202x_wake_macos() (drivers/usb/typec/tipd/spmi.c:1065,1154-1158,1210-1211)

    • sn201202x_suspend() and sn201202x_resume() explicitly rely on DPM registration order against xHCI without any device_link to dwc3-apple/xhci-plat:
      • spmi.c:1210-1211: /* Registered before xHCI, so its root port has suspended by now. */ tipd_usb_wake(tps, true);
      • spmi.c:1154-1158: sn201202x_wake_macos(sn, err); (hands back USBw 0x80/0x00 and restores SSPS S0) and /* Registered before xHCI, so this is before the root port resumes. */ tipd_usb_wake(tps, false);
    • Enabling device_enable_async_suspend(&device->dev) causes dpm_resume() (drivers/base/power/main.c:1248-1263) to dispatch sn201202x_resume() asynchronously and advance to subsequent devices without waiting for sn201202x to wake the controller, return to S0, and hand back USB2 lines (USBw), and lets dpm_suspend() dispatch sn201202x_suspend() upfront as an async leaf (dpm_leaf_device, main.c:2105).
    • On firmware-sleep Macs using apple,usb-remote-wake or apple,sleep-ssps (sn201202x_wake_macos()), racing USBw hand-back against xHCI root-port resume risks leaving USB2 devices missing after wake (as documented at spmi.c:1277-1279).
    • Fix: Establish explicit PM ordering (e.g., device_link to the USB host/root hub) before enabling async suspend, or keep synchronous suspend/resume where tipd_usb_wake() / macos_sleep ordering against xHCI is required.

Checklist audit (§1–§6)

  • §1 / §2 / §3 / §4 / §6: No new chip/board/firmware gates; default-cmdline safe; the 5 ms SN201202X_WAKE_SELECT_TIMEOUT_US shortens the per-attempt select poll timeout within the existing 500 ms wake budget (not a sleep over a race); both commits (bc4eacb9634d, 2e4427c52c3f) have human author/committer and Signed-off-by: Satya Benson <satya@benson.earth> only with zero AI commit trailers; PR body includes Assisted-by:.
  • §5 Evidence (to accompany the fixes above): Current hardware evidence is pm_test=devices on a mixed-DTB J775c (no deep sleep, no apple,sleep-ssps / apple,usb-remote-wake). After addressing blockers 1 & 2, please include a real RTC s2idle row on J775c and a firmware-sleep row on a board exercising apple,sleep-ssps / apple,usb-remote-wake (e.g., J714s/J713/J700).

Assisted-by: LLM (Gemini 4 Neon)

…sooner

While a sleeping SN201202x controller wakes up, a register selection sent
before it is ready is never confirmed. sn201202x_wake_poll() called
regmap_sn201202x_select_reg(), which waits a full 100 ms per attempt
before timing out and letting the wake loop retry; a single early attempt
therefore added ~100 ms to every waking controller on resume.

Split out sn201202x_select_reg() with an explicit timeout parameter, keep
the 100 ms timeout for normal register selections, and use a 5 ms timeout
while polling a waking controller so retries happen 20x sooner without
changing the overall wake budget.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj force-pushed the satchlj/sn201202x-fast-wake-async-pm branch from 2e4427c to 430de1f Compare November 23, 2026 21:04

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

Formal §1–§6 pre-PR re-review at 430de1f0096fa8226e5658a43d10643a89fed4d5 (base integration/aurora; live CI host-tests: PASS).

Resolved Since 2e4427c52c3f

  • CI sn201202x-transport failure: Fixed in f7dc93cbbf5c by updating tools/testing/selftests/drivers/apple/sn201202x-transport.py to extract sn201202x_select_reg and provide the required macros/stubs. Live host-tests now passes, and commit 1 (f7dc93cbbf5c) itself looks clean and well-bounded (both atomic_us = min(timeout_us, 10ms) and budget_ms -= 5 stay consistent).

Remaining Blockers

  1. §2 / §3 Technical Blocker — device_enable_async_suspend(&device->dev) (drivers/usb/typec/tipd/spmi.c:1065) is unchanged and still breaks DPM ordering against xHCI:

    • sn201202x_suspend() (spmi.c:1185-1186) and sn201202x_resume() (spmi.c:1129-1135) explicitly rely on DPM registration order before xHCI without any device_link to dwc3-apple/xhci-plat:
      • spmi.c:1185-1186: /* Registered before xHCI, so its root port has suspended by now. */ tipd_usb_wake(tps, true);
      • spmi.c:1129-1135: sn201202x_wake_macos(sn, err); (hands back USBw 0x80/0x00 and restores SSPS S0) followed by /* Registered before xHCI, so this is before the root port resumes. */ tipd_usb_wake(tps, false);
    • Calling device_enable_async_suspend(&device->dev) unconditionally breaks both ordering invariants: dpm_suspend() dispatches sn201202x_suspend() upfront as an async leaf (potentially arming tipd_usb_wake(tps, true) before xHCI root ports finish suspending), and dpm_resume() dispatches sn201202x_resume() asynchronously and moves on to xHCI before sn201202x finishes waking, restoring S0, and handing back USB2 lines (USBw) — risking missing USB2 devices after wake as documented at spmi.c:1251-1255.
    • Fix: Establish explicit PM ordering (device_link between the port controller and its USB host/root hub) before enabling async suspend/resume, or split out / drop commit 2 (430de1f0096f) until explicit PM links are in place.
  2. §5 Evidence (to accompany the fix):

    • Current hardware evidence is still pm_test=devices on a mixed-DTB J775c (and the PR description still cites the old commit SHAs bc4eacb9634d/2e4427c52c3f). Please refresh the PR body SHAs and include a real RTC s2idle row plus a firmware-sleep row on a board exercising apple,sleep-ssps / apple,usb-remote-wake (e.g., J714s / J713 / J700) once the async DPM ordering issue is resolved.

§1–§6 Checklist

  • §1 No model gating: Pass.
  • §2 Production-ready, no hacks / §3 Safety: Request changes — unresolved async DPM ordering race vs xHCI in commit 2 (430de1f0096f).
  • §4 Clean-room & attribution: Pass (f7dc93cbbf5c and 430de1f0096f carry human author/committer and Signed-off-by: Satya Benson <satya@benson.earth> only, zero AI commit trailers; PR body ends with Assisted-by:).
  • §5 Evidence: Request changes (real s2idle + firmware-sleep board row + updated commit SHAs owed).
  • §6 Naming: Pass.

Assisted-by: LLM (Gemini 4 Neon)

@satchlj
satchlj force-pushed the satchlj/sn201202x-fast-wake-async-pm branch from 430de1f to f7dc93c Compare November 23, 2026 22:34
@satchlj satchlj changed the title usb: typec: tipd: sn201202x: faster wake-select retries and async suspend/resume usb: typec: tipd: sn201202x: retry waking-controller register select sooner Nov 23, 2026
@satchlj

satchlj commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

Gemini 4 Neon on @satchlj's behalf.

Addressed the review feedback in f7dc93cbbf5c:

  1. Dropped the device_enable_async_suspend() patch so this PR focuses cleanly on the 5 ms wake-select retry fix (sn201202x_select_reg()).
  2. Updated tools/testing/selftests/drivers/apple/sn201202x-transport.py for the split helper and ran it: 6/6 PASS.
  3. Verified checkpatch.pl --strict (0/0/0), W=1 build (0 new warnings), and booted on lobata (J775c / T6050, boot_id: 0535fd99-4dca-412e-b2ca-a4042e37cd4c, Image.gz 5b3848aa..., DTB 0442bec2..., default cmdline): all 4 sn201202x controllers (0-06, 0-08, 0-0a, 0-0c) probed cleanly and passed a full device-PM s2idle suspend/resume cycle (pm_test=devices, freeze, 124.395 s -> 132.080 s) with 0 errors (full RTC-wake s2idle on T6040/T8132/T8142 is welcome since macsmc-rtc defers on J775c's baseline apple-spmi Gen4 -95). Full §5 health tuple updated in PR body. Ready for re-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.

Formal §1–§6 pre-PR re-review at live head f7dc93cbbf5c737b1340c42320a06c92a52b573d (base integration/aurora 5746ef8a5afd, not superseded; MERGEABLE/CLEAN; live CI host-tests PASS).

Resolved Since 430de1f0096f

  • Async PM ordering blocker removed: The device_enable_async_suspend() commit was dropped, leaving only the clean wake-select timeout split (f7dc93cbbf5c).
  • Code & selftest audit (drivers/usb/typec/tipd/spmi.c, tools/testing/selftests/drivers/apple/sn201202x-transport.py):
    • sn201202x_select_reg(sdev, reg, timeout_us) cleanly preserves the 100 ms SN201202X_SELECT_TIMEOUT_US for normal regmap reads/writes while giving sn201202x_wake_poll() a 5 ms SN201202X_WAKE_SELECT_TIMEOUT_US retry timeout.
    • Atomic polling clamps via min_t(unsigned int, timeout_us, SN201202X_ATOMIC_SELECT_MS * 1000) and matches budget_ms -= SN201202X_WAKE_SELECT_TIMEOUT_US / 1000; completion waits use max(1UL, usecs_to_jiffies(timeout_us)) (never zero jiffies at any HZ).
    • Host transport selftest updated and passing (6/6 PASS, live CI host-tests PASS).
  • Exact-head §5 hardware verification: PR body refreshed to f7dc93cbbf5c with lobata (J775c / T6050, Image.gz 5b3848aa..., boot 0535fd99, default cmdline): all 4 sn201202x controllers (0-06, 0-08, 0-0a, 0-0c) bound cleanly and passed pm_test=devices s2idle suspend/resume (exercising sn201202x_suspend()/sn201202x_resume()/sn201202x_wake_poll()) with 0 errors, clean health tuple (0 new kernel errors, 0 new failed units, SELinux N/A), and explicit §1 request for full deep-sleep/RTC-wake testing on T6040/T8132/T8142.

§1–§6 Checklist

  • §1 No model gating: Pass.
  • §2 Production-ready, no hacks: Pass (shortens per-attempt select poll timeout within the existing 500 ms wake budget; default cmdline, checkpatch --strict 0/0/0, W=1 clean).
  • §3 Safety: Pass.
  • §4 Clean-room & attribution: Pass (f7dc93cbbf5c carries human author/committer Satya Benson <satya@benson.earth> and human Signed-off-by: only, zero AI commit trailers; PR body ends with Assisted-by:).
  • §5 Evidence: Pass.
  • §6 Naming: Pass.

Assisted-by: LLM (Gemini 4 Neon)

@github-actions github-actions Bot added area:usb Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

f7dc93c J616s (M4 Pro T6040, macOS 26.6.2 fw) PASS: guarded one-shot 7.3.0-aurora-pr2905+ (exact f7dc93c in drivers/usb/typec/tipd/spmi.c, 0-line diff, combined with exact #2905 aa132a2, default cmdline, boot_id=eba6163a, boot-ctxr.bin untouched); all 4 SPMI sn201202x controllers (1-08, 1-0a, 1-0c, 2-0c) bound cleanly; connected USB-C/USB4 peer (thunderbolt 0-1, 20.0 Gb/s x 2 lanes) and port0..port3 Type-C roles intact before and after 2x real rtc1 s2idle wakes (suspend_stats success=2 fail=0); tipd_errs=0; eDP-1 connected, Borealis gpubench-vk + gpubench-gl (render.postfx 1080p 2080 fps, crc=2133faaa valid=true) ok; 0 GPU faults, 0 failed units, Enforcing + 0 AVC; restored and verified 7.3.0-aurora-fleet89.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Merge readiness at f7dc93cb: ready to merge

Check Detail
CI at head ok 1 check passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at f7dc93cb
Conflicts ok none
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:usb
Merge: gh pr merge 3014 --merge (Owners and Core through the bypass: add --admin).

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

@RyanTheTide
RyanTheTide merged commit 27c1fc5 into main Nov 25, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the satchlj/sn201202x-fast-wake-async-pm branch November 27, 2026 13:21
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) needs-template PR body lacks Tested or Risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants