Repository navigation
usb: dwc3: apple: start a host stopped for a sleep 250 ms after the resume - #2524
Conversation
…esume A host that was stopped for a deep sleep is started again from the PM notifier's work right after the resume, about 30 ms after the tasks are thawed. On the J700 (MacBook Neo) with a dock in DP alt mode on its USB3 port, that start lost the dock's SuperSpeed side in about a third of the deep sleeps: the root port stays in Rx.Detect with a warm reset that never finishes (PORTSC 0x0a0002b0), and only resetting the controller brings it back. Started 100, 250 or 1000 ms after the resume, the same host never lost it. On one integration build whose two boots differed only in this file, 8 of 20 deep sleeps lost it without the delay and 0 of 40 with it. Nothing the kernel can see marks the point after which the start is safe. The kernel log around the resume is the same for kept and lost wakes, the time from the PHY's restore to the PIPE handover doesn't decide it, the port controller's mux update after the wake comes later and its order doesn't matter, and the PHY reports its PIPE ready either way. So this waits a fixed time: 100 ms was enough in 16 sleeps, and 250 ms leaves a margin. SuperSpeed devices come back about a quarter of a second later after a wake. Queue the start after such a sleep as delayed work, 250 ms after the resume. A host kept in place through the sleep still resumes at once. Link: #2380 Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
The 250 ms delay keeps the Dell's SuperSpeed side on the J714s (M5 Pro) too, though so far on only 4 sleeps per arm. Setup:
The sample is small, but it points the same way as your Neo 8/20 vs 0/40. On the J714s the Type-C PHY starts about 185-192 ms after the resume, so this PR's 250 ms from PM_POST_SUSPEND also starts the host from the finish work with the PHY up. So the extra role-switch hunk in our copy isn't needed on this board. We're putting this PR, not our copy, into the M5 ship candidate. |
|
Tried an event-based alternative to the fixed delay. It doesn't help, so the delay stays as it is. The two steps tried, with no delay, after the host start that follows a deep sleep:
Neo + dock, one test kernel (#2524 head on integration 449c6a1). The four boots differ only in dwc3-apple.ko and tps6598x-core.ko. 40 deep sleeps per boot:
Why neither step helps:
So the dock's side becomes detectable about 120 to 130 ms after the thaw, and nothing visible to the kernel marks that point. That matches 100 ms being enough before and 250 ms leaving a margin. Details
|
|
J714s (M5 Pro), the start path for each sleep, following up my comment above. This is the same 8-sleep run with auto-replug off, the arms alternating, each sleep 40 s after a tipd replug of the Dell S2725QC port.
|
DjDeveloperr
left a comment
There was a problem hiding this comment.
Approving at b92ed54 (base merged in; 7/7 CI). The delay applies only to a host the sleep stopped; a kept host still starts at once. sleep_start_work is converted everywhere (queue, cancel, devm autocancel). A suspend requested inside the 250 ms window is refused by PM_SUSPEND_PREPARE (sleep_phase not idle), which is acceptable; please note it in a follow-up commit message or the docs. The Neo A/B (8/40 vs 0/40, 100 ms already 0/16) and the step-5 negative result (Rx.Detect after a fresh host start) justify the fixed delay for now. Keeping the host in place across deep sleep, as macOS does, is the follow-up. A Neo row at this head (10 docked deep sleeps) is post-merge verification, since this is the first run with #2231's dark-wake path.
|
Neo row at b92ed54 (this branch with integration merged in, so the 250 ms start delay now sits next to #2231, #2274 and #2445 in the same sleep path): 0 of 10 deep sleeps lost the SuperSpeed side. MacBook Neo, Plugable UD-ULTC4K dock in DP alt mode, Samsung T7 behind the dock's SS hub, RTC-woken deep s2r (25 s each). Test kernel built from b92ed54 with the Neo production config, one boot:
Not covered: no dark wake happened in these 10 (an RTC alarm is always a full wake), so #2231's dark-wake keep didn't run in this row. A dock in DP alt mode doesn't take the tunnel path that code is on anyway. Per-wake detail
|
|
J714s (M5 Pro) post-merge row, built natively from integration/aurora at 458f759 (this PR merged): no SS loss, no refusals, no hang in 6 docked deep sleeps. Setup: Dell S2725QC in DP alt mode on a Type-C port, plus a TB5 dock and the panel. 6 real deep sleeps through logind, each on a 60 s RTC alarm.
|
Fixes the lost SuperSpeed side after a deep sleep in #2380.
Problem
On the MacBook Neo (J700) with a USB-C dock in DP alt mode, about a third of deep sleeps come back without the dock's SuperSpeed side: the SS hub and everything behind it are gone, the USB2 side stays, and the SS root port sits in Rx.Detect with a warm reset that never finishes (
PORTSC 0x0a0002b0). Only a controller reset (rebind, or stop + 500 ms + start) brings it back.A host stopped for the sleep is started again from the PM notifier's work about 30 ms after the tasks are thawed. When that start comes 100 ms or more after the resume, the link always comes back.
Change
sleep_start_workbecomes adelayed_work. When the host was stopped for the sleep, it's queued 250 ms afterPM_POST_SUSPEND. A host kept in place through the sleep (in-place or tunnel) is still started at once. A suspend requested inside the 250 ms window is refused with -EBUSY:sleep_phaseis not idle until the delayed start has run.This is a fixed delay, not a wait on a ready event. I looked for one first and found none the kernel can see:
CFG_STATUS.PIPE_PHY_READYis set before the handover in kept and lost wakes alike.So the delay is measured: 100 ms was already enough (0/16), and 250 ms leaves a 2.5x margin. The cost is that SuperSpeed devices come back about 250 ms later after a deep sleep, and only on hosts that were stopped for it.
Testing
MacBook Neo, Plugable UD-ULTC4K dock in DP alt mode, Samsung T7 behind the dock's SS hub, RTC-woken deep s2r:
dwc3-apple.ko(on disk and in the initramfs). Without the patch, 8 of 20 deep sleeps lost the SS side (thaw to PIPE handover 26-35 ms). With it, 0 of 40 (277-286 ms). One-sided Fisher p = 5e-5.tools/testing/selftests/drivers/gpu/apple-dcp/run.py89/89 ok (incl.dwc3-teardown).dwc3-initial-role.pyandatc-t8132-usb3.pydon't compile on integration today (fixed by selftests: apple: repair the rotted host harnesses and run them in CI #2512). With selftests: apple: repair the rotted host harnesses and run them in CI #2512's versions they pass 7/7 and 13/13, the same as without this patch.Still to run
rmmodalso lost the SS side 3 times in 12 on the Neo. That isn't a sleep path and this patch doesn't touch it.@DjDeveloperr, could you check whether the J714s Dell (Realtek SS hub, #2274/#2078) also loses SuperSpeed only when the host starts right after the wake? If a 250 ms start delay keeps it there, the replug in #2274 might not be needed.
Reviewer detail: per-wake data and the recovery split
thaw->pipeis "Restarting tasks: Done" to the ATC PHY'sPIPE requestdebug line;thaw->xhciis to the xHCI registration. Lost wakes in the unpatched boot were c09 c10 c12 c13 c14 c17 c18 c20 (none in the first 8); each was recovered by one dwc3 rebind.GUSB2PHYCFG.PHYSOFTRST0/2,GUSB3PIPECTL.PHYSOFTRST0/2, re-route +PHYSOFTRST0/1. The Neo's40a280000.usbis a fixed-hub controller, so its wake already clears the role and soft-resets the core.lsusbfor 1 s after each resume still lost 2/8.Assisted-by: LLM (Claude:Opus 5.5)