Skip to content

usb: dwc3: apple: keep USB teardown out of the PM notifier chain - #1947

Merged
DjDeveloperr merged 2 commits into
integration/aurorafrom
dwc3-pm-notifier-host-stop
Nov 15, 2026
Merged

DjDeveloperr merged 2 commits into
integration/aurorafrom
dwc3-pm-notifier-host-stop

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

One commit, three files: drivers/usb/dwc3/dwc3-apple.c, drivers/phy/apple/atc.c, include/linux/phy/apple-atc.h. Based on integration/aurora 580e911; it applies unchanged on the current tip (nothing since touches these files).

The glue's PM notifier no longer tears USB down or waits for anything, on every board:

  • PM_SUSPEND_PREPARE opens a sleep epoch with a trylock and queues the preparation work. A busy glue lock, an epoch still open, or the PHY's finish from the last wake not over yet refuse the sleep with -EBUSY instead of waiting inside the chain.
  • The preparation work keeps a fixed-hub host in place (T8140), or stops the controller, as the notifier did before.
  • The controller's prepare callback (after the freezer, before any device suspends) waits for that work with the existing 5 s bound; a failed or unfinished preparation refuses the sleep. A host that keeps running gets its syscore mark back through -EAGAIN, so that genpd unwinds its prepare count before the PM core retries.
  • PM_POST_SUSPEND queues the finish work: it waits for the preparation, then checks, recovers or restarts the host (the restart of a host that lost its state in the sleep now runs here, not in the notifier), applies a role change that came during the epoch, restores the syscore mark as the remaining power ownership requires, and queues the PHY's finish under the glue lock.
  • The fixed hub's check runs only while no epoch is open and the host is healthy; shutdown and remove quiesce this work on every board (only T8132 still takes the controller down at shutdown).
  • The PHY's finish work gets a completion and a non-blocking query, apple_atcphy_sleep_finish_done(); its work items are set up after the resources they use.

Second commit, tests only: the host-test harnesses (neo-stability; apple-dcp dwc3-teardown and controller-lifecycle) learn dwc3_apple_syscore() and the PM quiesce, plus a new usb-epoch-syscore mutation for the epoch rule; no kernel code changes.

Why

Stopping a running host disconnects its devices, and so does restarting a host that lost its state in the sleep. A driver that unregisters a PM notifier of its own as its device goes away then waits for the chain it is being called from: r8152 does so when its interface is closed (rtl8152_close() → unregister_pm_notifier()). With such an adapter attached the suspend never gets past PM_SUSPEND_PREPARE (seen on J714s / T6050). On boards with a fixed hub the same applies to the in-place host's restart at PM_POST_SUSPEND.

Tested

On a J700 (T8140) with an r8152 adapter (RTL8153, interface open) on the front port behind the on-board hub; two one-shot boots of a full arm64 build (Image, modules, dtbs) of this exact tree with the distribution kernel's config, then a third boot of it as the default kernel:

  • 9 sleeps (DRAM-kept, the board's normal path) on 2 boots, each on the same boot: the host was kept in place every time (no USB disconnect, no re-enumeration, the adapter kept its device number), and the adapter's link, timed on 7 of them, was back within 0.35 s of the resume in 6 (once after 11.8 s; that segment also drops link without any sleep), and up when checked after the other 2.
  • 2 sleeps aborted late with pm_test=platform: no real sleep, USB and the adapter fine afterwards, the next sleep normal.
  • A sleep requested 4 ms after a wake was accepted on the first try.
  • SEP, Wi-Fi, Bluetooth, GPU, audio, input and camera nodes fine after the sleeps; no new USB/PHY warnings in the kernel log other than the line below.
  • Not exercised on J700: the controller STOP path (both Type-C ports sit behind the fixed hub) and the deep (not DRAM-kept) path, which the board doesn't take on its own.

Not covered yet

  • The host STOP path with an r8152 attached and open, on a board without a fixed hub (J714s, where the hang was seen; J713). On J700 both Type-C ports sit behind the on-board hub, so a sleep keeps the host in place and never stops it.
  • Each sleep logs one err-level PM: device_prepare(): genpd_prepare returns -11 for the controller: the PM core reports the deliberate -EAGAIN syscore handoff with dev_err. Harmless; a follow-up should avoid the noise.

🤖 Generated with Claude Code

m0d16l14n1 added a commit to m0d16l14n1/linux that referenced this pull request Nov 15, 2026
DjDeveloperr: usb: dwc3: apple: stop a host for deep sleep outside the PM notifier chain

# Conflicts:
#	drivers/usb/dwc3/dwc3-apple.c
m0d16l14n1 added a commit to m0d16l14n1/linux that referenced this pull request Nov 15, 2026
…n#1947 merge

aurora-silicon#1947 added the prepare callback in its own dwc3_apple_pm_ops; this tree
already had one with the out-of-band wake suspend. Both callbacks now sit in
the one table.

Assisted-by: Claude Opus 5.5
Signed-off-by: Nick <[email protected]>
When "mem" means deep sleep, the glue prepares its controller at
PM_SUSPEND_PREPARE. A host behind a fixed hub sleeps in place; any other
controller, or one whose PHY can't keep it, is stopped the way a cable
disconnect does. Stopping a running host disconnects its devices, and so
does restarting a host that lost its state in the sleep, at
PM_POST_SUSPEND. Outside the J714s both ran inside the PM notifier chain.
A driver that unregisters a PM notifier of its own as its device goes away
then waits for the chain it is being called from: r8152 does so when its
interface is closed (rtl8152_close() -> unregister_pm_notifier()). With
such an adapter attached the suspend never gets past PM_SUSPEND_PREPARE.
The hang was seen on one machine (J714s, T6050) with an r8152 adapter.

Let the notifier only open a sleep epoch or queue its finish, on every
board:

- PM_SUSPEND_PREPARE takes the glue lock with a trylock, checks that the
  PHY's finish after the last wake is over, opens the epoch, lifts the
  syscore mark so that the controller's prepare callback runs, and queues
  the preparation work. It never waits. A busy lock, an unfinished PHY
  finish or an epoch still open refuse the sleep with -EBUSY.
- The preparation work does what the notifier did: it keeps the host in
  place, or stops the controller.
- The controller's prepare callback, after the freezer and before any
  device suspends, waits for that work with the existing 5 s bound. A
  preparation that failed or hasn't ended refuses the sleep. A host that
  keeps running gets its syscore mark back through -EAGAIN, so that genpd
  unwinds its prepare count before the PM core retries and skips it.
- PM_POST_SUSPEND queues the finish work. It waits for the preparation,
  then checks, recovers or restarts the host, applies a role change that
  came during the epoch, restores the syscore mark as the remaining
  power ownership requires, and queues the PHY's finish under the glue
  lock. A failed exit keeps its restart and cleanup obligations.
- The fixed hub's check runs only while no epoch is open and the host is
  healthy; the finish drains an older check before it closes the epoch.
- Shutdown and remove quiesce this work on every board. Only T8132 still
  takes the controller down at shutdown.

The PHY's finish work gets a completion and a non-blocking query,
apple_atcphy_sleep_finish_done(), for the admission check. Its work items
are set up after the resources they use, so that devres drains them first.

Waiting for a Type-C PHY that has not started after a sleep stays
specific to the J714s.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr force-pushed the dwc3-pm-notifier-host-stop branch from 67e2596 to a667121 Compare November 15, 2026 22:42
@DjDeveloperr DjDeveloperr changed the title usb: dwc3: apple: stop a host for deep sleep outside the PM notifier chain usb: dwc3: apple: keep USB teardown out of the PM notifier chain Nov 15, 2026
The host tests that extract dwc3-apple code no longer compiled: the
glue now sets its syscore mark through dwc3_apple_syscore(), its role
switch reads the sleep epoch, and its remove quiesces the PM work
through dwc3_apple_pm_quiesce().

neo-stability: extract the syscore helper too, with the driver's sleep
epoch enum and the fields it uses in the model struct; the old-USB
control keeps the current core stop and helper. The helper's only new
rule is that an open epoch records the wanted mark without setting it,
so that device prepare still runs: check it, and add the matching
mutation.

apple-dcp dwc3-teardown: extract the syscore helper as well, take the
epoch enum from the driver, add the epoch fields to the model struct,
and model the epoch spinlock (taken only when free, released only when
held).

apple-dcp controller-lifecycle: model the PM quiesce. It must run once,
before the host is removed, for a controller removal, and it stops new
starts as the driver's does.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr merged commit 07ade53 into integration/aurora Nov 15, 2026
7 checks passed
@RyanTheTide
RyanTheTide deleted the dwc3-pm-notifier-host-stop branch November 16, 2026 05:06
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