Skip to content

usb: dwc3: apple: start a host stopped for a sleep 250 ms after the resume - #2524

Merged
DjDeveloperr merged 2 commits into
integration/aurorafrom
fix/dwc3-apple-sleep-start-delay
Nov 20, 2026
Merged

DjDeveloperr merged 2 commits into
integration/aurorafrom
fix/dwc3-apple-sleep-start-delay

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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_work becomes a delayed_work. When the host was stopped for the sleep, it's queued 250 ms after PM_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_phase is 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:

  • The kernel log around the resume is the same for kept and lost wakes (42 wakes compared). The PIPE request is at thaw +27..33 ms in both.
  • The time from the ATC PHY's restore at resume to the PIPE handover doesn't decide it. Wakes with a shorter gap than many lost ones still kept the link once the start came >= 100 ms after the thaw.
  • tipd's mux update after the wake comes about 0.5 s after the thaw. Its order relative to the start doesn't matter: with the 250 ms delay the PIPE is handed over before it and the link still comes back.
  • CFG_STATUS.PIPE_PHY_READY is 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:

Still to run

@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
  • Fix row data: thaw->pipe is "Restarting tasks: Done" to the ATC PHY's PIPE request debug line; thaw->xhci is 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.
  • Recovery split on lost wakes (production 7.3.0-40, test module): glue exit + 500 ms + init 3/3; exit + init with the role kept 1/1; with the role cleared 1/2; rebind 8/8. PIPE re-route 0/2, GUSB2PHYCFG.PHYSOFTRST 0/2, GUSB3PIPECTL.PHYSOFTRST 0/2, re-route + PHYSOFTRST 0/1. The Neo's 40a280000.usb is a fixed-hub controller, so its wake already clears the role and soft-resets the core.
  • User space touching USB devices at the thaw is not the trigger: holding the test's first lsusb for 1 s after each resume still lost 2/8.
  • Delay choice: 100 ms 0/16, 250 ms 0/8 + 0/40 (this row), 1000 ms 0/16.
  • The kept-in-place and tunnel paths queue with a delay of 0, as before.

Assisted-by: LLM (Claude:Opus 5.5)

…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>
@DjDeveloperr

Copy link
Copy Markdown
Contributor

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:

  • Hardware: an M5 Pro with a Dell S2725QC on a Type-C port in DP alt mode (hub 0bda:5409 / 0bda:0409, dwc3 2aa280000.usb).
  • Kernel: the M5 default plus our test copy of this delay. It's a runtime host_start_delay_ms that delays this PR's finish-work start and also the role-switch start of a host waiting for its PHY.
  • Protocol: auto-replug off in both arms; 8 deep sleeps (60 s RTC alarm), alternating arms, each 40 s after a tipd replug of that port; root SuperSpeed port checked 5 s after the start.
arm SS back at +5 s host start after the resume start path
250 ms 4/4 301-450 ms the finish work every time (the PHY was already up)
0 ms 3/4 (1 lost: PORTSC 0x0a0002b0, Rx.Detect, the usual loss) 27-192 ms 3 of 4 from the role switch right after the PHY came up
  • No hangs in 8.
  • One early wake, in the 250 arm. It's unrelated to the delay: the PMU RTC hadn't fired, and the PMU wasn't the source either.

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.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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:

  1. Resume every SuperSpeed root port that has a device attached and a link in U3: write the Resume link state with the link state write strobe (xHCI 5.4.8).
  2. Tell the port controller the USB lines are changing hands: the driver's existing USBw command, hand-back then clear.

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:

boot lost SS side
production 8/40
this PR (250 ms delay) 0/40
no delay + root-port resume + hand-back at the wake 5/40
same, with the lines also armed at sleep entry so the hand-back is accepted 6/40

Why neither step helps:

  • The deep sleep stops the host, so after the wake it starts from scratch. Its SS root port starts in Rx.Detect, never in U3, so there is nothing to resume. The resume write never fired in 80 wakes. In kept wakes the port goes to Polling 83 to 103 ms after the start and reaches U0 about 10 ms later. In every lost wake it stays in Rx.Detect for the whole 500 ms watch: the dock's receiver is never detected.
  • The SN201202x rejects the hand-back (-EPERM) unless the lines were armed at sleep entry. With the arm it takes the hand-back (it still rejects the clear) and sleeps normally, but the loss rate doesn't change.

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
  • Kernel 7.3.0-aurora-atc5 = ae53d2a with the Neo production config. Module shas were checked on disk before every row. RTC-woken deep S2R with a 25 s sleep. A wake counts as kept when the T7 behind the dock's SS hub is back within 15 s. Every lost wake was recovered by one dwc3-apple rebind.
  • Fisher two-sided: production vs delay p = 0.005; root-port resume + hand-back vs delay p = 0.055; with the arm vs delay p = 0.026; both together (11/80) vs delay p = 0.015.
  • The PORTSC watch sampled the SS root port every 200 to 400 us for 500 ms from the start. Kept wakes: 0x2b0 (Rx.Detect), then 0x2f0 (Polling), then 0x2a1603 (U0). Lost wakes: 0x2b0 throughout, and 0x0a0002b0 when read seconds later, the same state the PR describes.
  • Thaw to xHCI registration: 28 to 40 ms without the delay, 279 to 289 ms with it.
  • Sleep wall time was 24 to 25 s in every boot. No early wakes with the lines armed.
  • The arm and hand-back were sent for any attached partner whatever apple,usb-remote-wake says. That property isn't in the Neo's device tree, so production never sends the command there.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

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.

sleep delay start path host start after the resume SS at +5 s
w1 250 ms finish work 448 ms back
w2 0 role switch (finish work got -ENOLINK) 185 ms back
w3 250 ms finish work 446 ms back
w4 0 finish work 27 ms back
w5 250 ms finish work 450 ms back
w6 0 role switch (finish work got -ENOLINK) 192 ms back
w7 250 ms finish work 301 ms back
w8 0 role switch (finish work got -ENOLINK) 183 ms lost
  • Without a delay, the J714s Type-C host usually starts from tipd's role switch, which this PR doesn't delay. It does that when the PHY's mode comes up at about 183-192 ms after the resume.
  • With a delay, the finish work runs after the PHY is up and starts the host itself.
  • This PR's 250 ms from PM_POST_SUSPEND sits about 60 ms past the latest PHY start we saw. So on this board it should start from the finish work too, and the role switch never gets the first start.
  • I don't think the J714s needs more than this PR. If a later wake brings the PHY up after 250 ms, the start would fall back to an undelayed role switch. Our test copy's second hunk covers that: the same delay before a role-switch start of a host that was waiting for its PHY after a sleep. Happy to send it as a follow-up if you want the margin.

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

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.

@DjDeveloperr
DjDeveloperr merged commit 458f759 into integration/aurora Nov 20, 2026
7 checks passed
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

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:

  • 10/10 kept: the T7 was back 2 s after every resume, SS root port in U0 at 5 Gb/s.
  • Thaw to PIPE handover 278-287 ms, thaw to xHCI registration 280-288 ms, so the delay is in effect on the merged code.
  • Every sleep ran its full 25 s with rc 0.

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
  • Modules on disk during the row: dwc3-apple sha256 dfe0717494b31c21..., tps6598x-core df0cf06d0643c5cc...
  • Two full-speed USB2 devices behind the dock's hubs (0bda:1100, 1038:1726) weren't back yet at the 2 s check in wakes 7-10. That's the slow full-speed re-enumeration behind the dock that we already saw before the merge (same device descriptor read/64, error -32 lines, at a lower rate than in the earlier 0/40 row). It isn't the SuperSpeed side.
  • Earlier rows on this PR: production 8/40 and 8/20 lost, delay 0/40 (twice).

@DjDeveloperr

Copy link
Copy Markdown
Contributor

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.

sleep asleep (RTC) wake refusals USB devices Dell 0409 SuperSpeed at +5 s first Dell hub enumeration after PM: suspend exit
w1 57.6 s RTC 0 20/20 back 234 ms
w2 58.0 s RTC 0 20/20 back 224 ms
w3 58.1 s RTC 0 20/20 back 232 ms
w4 58.0 s RTC 0 20/20 back 228 ms
w5 58.1 s RTC 0 20/20 back 277 ms
w6 57.9 s RTC 0 20/20 back 222 ms
  • Hosts start after the delay: every pass is consistent with this PR's 250 ms delayed start from PM_POST_SUSPEND.
  • The other checks were clean on all 6 wakes: GPU after the wake and the GPU's stop at each entry (the tree has the G17S raise), all displays, Wi-Fi/BT, and faults.
  • No dark wake came in these 6 sleeps, so the dark-wake re-suspend wasn't exercised on hardware.
    • Why none: USB-C_plug-only wakes haven't come on this machine since its battery reached Full.
    • By the code: the dark-wake re-entry is the kernel's own loop, while (!error && pm_dark_wake()) error = suspend_devices_and_enter(state);. It runs no PM notifiers, so dwc3-apple's notifier sees neither the PM_SUSPEND_PREPARE sleep_phase check that returns -EBUSY nor the PM_POST_SUSPEND that queues the 250 ms start. Only a new user-space suspend within ~250 ms of a full wake can meet that -EBUSY.
  • Same delay before a tipd replug: the pre-merge alternating A/B is in my comments above. With 250 ms, SS came back 4/4, with the host started from the finish work at 301-450 ms. With 0 ms it came back 3/4, and 3 of the 4 starts came from tipd's role switch at 183-192 ms.

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.

2 participants