Skip to content

phy: apple: atc: admit suspend-to-idle with DWC3 running in device role - #2700

Open
RyanTheTide wants to merge 3 commits into
integration/aurorafrom
airs-wifibt2/t8132-s2idle-device-role
Open

RyanTheTide wants to merge 3 commits into
integration/aurorafrom
airs-wifibt2/t8132-s2idle-device-role

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A T8132 Type-C PHY that owns its common block refuses system sleep unless DWC3 runs on it as a host and the target is suspend-to-idle. A port in device role (the Mac connected to another computer as its USB device) therefore refuses every suspend-to-idle: atcphy_suspend returns -EBUSY and the sleep aborts. On the M4 MacBook Air (J713) with a computer on its USB-C port, s2idle never starts.

Change

The host-only rule rests on the DWC3 glue keeping the controller, and with it the atcN_usb power domain the PHY shares, on across system sleep. dwc3-apple does that for either role: it makes the core a syscore device whenever it is started, host or device, and for suspend-to-idle its prepare work only makes sure the controller is started. The PHY now tracks whether DWC3 is out of the reset it provides (set on deassert, cleared on assert) and admits suspend-to-idle on that. A controller held in reset, or any deeper sleep, is still refused. No new parameters; nothing keyed on a board or SoC beyond the existing T8132 common-block path.

Testing

Still to run

  • The USB4 host-to-host link on the same port drops at s2idle entry and is not found again after resume (as after a deep sleep). Separate from this change, which only lets the sleep start. Afterwards that port's PD controller ends some sleeps early.
  • A row on another T8132 Mac with a device-role port (M4 mini).
  • J713: an NCM gadget passing traffic across s2idle (queued), and the host cable pulled during the sleep (needs a hand at the lab).
Details for reviewers
  • Domains (t8132.dtsi): atcphy0 and dwc3_0 both sit in ps_atc0_usb (parents ps_atc0_common, ps_atc0_usb_aon). ACIO holds the atc0_cio* domains itself for a connected cable (syscore pd devices), so a USB4 link on the same port is unaffected by this check.
  • dwc3-apple: dwc3_apple_init() calls dwc3_apple_syscore(appledwc, true) for HOST and DEVICE. At PM_SUSPEND_PREPARE the notifier clears syscore so prepare runs, and dwc3_apple_pm_prepare() sets it again and returns -EAGAIN (the genpd_prepare returns -11 line). dwc3_apple_sleep_prepare_work() returns right after dwc3_apple_sleep_start() when !sleep_deep.
  • Before (J713, tethered to a host): phy-apple-atc 402a90000.phy: PM: dpm_run_callback(): atcphy_suspend [phy_apple_atc] returns -16, PM: failed to suspend: error -16.
  • The deep-sleep hibernation steps that also toggle DWC3_RESET_N inside one controller session (atcphy_controller_hibernate/_d0) do not change the flag: it follows only the reset controller ops.

Assisted-by: LLM (Claude:Opus 5.5)

A T8132 Type-C PHY that owns its common block refuses system sleep
unless DWC3 runs on it as a host and the target is suspend-to-idle.
The reasoning behind the host condition is that the DWC3 glue keeps
the controller, and with it the power domain the PHY shares
(atcN_usb), on across system sleep. The glue does that for either
role: dwc3-apple makes the core a syscore device whenever it is
started, host or device, and for suspend-to-idle its prepare work
only makes sure the controller is started.

So a port in device role (connected to another computer, the Mac
being the USB device, with or without a gadget bound) refused every
suspend-to-idle with -EBUSY from atcphy_suspend(), although nothing
the PHY holds is lost. On a J713 tethered to a host that blocked
s2idle outright.

Track whether DWC3 is out of the reset this PHY provides, in either
role, and admit suspend-to-idle on that instead of host mode. A
controller held in reset, or any deeper sleep, is still refused.

The host tests follow: every harness that stubs the PHY (the two atc
harnesses and the apple-dcp USB mocks) carries the new field, the
T8132 sleep test admits suspend-to-idle with a running device and
refuses it with the controller in reset, and new negative controls
and mutations reject the host-only rule, a release that doesn't mark
the controller running and an assert that doesn't clear it.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J713 row on a candidate default kernel (this PR merged with #2675, #2670, #2662 and #2694 on the J713 deep-sleep/display/GPU series), stock command line, with a host computer on port0, so DWC3 runs in device role:

  • 3 of 3 suspend-to-idle cycles (rtcwake -m freeze -s 20 on the PMU RTC). suspend_stats went from 0 to 3 successes with 0 failures, and each suspend took about 0.09 s.
  • Wi-Fi reconnected and both displays (eDP and an external DP-2 monitor) were still connected after the cycles.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

No blockers. Since every path that asserts the DWC3 reset also clears host_active, the new dwc3_running condition in
atcphy_suspend() only adds the device-role case, and dwc3-apple keeps the core syscore for either role, so the shared
USB domain stays on through suspend-to-idle as the commit says. Only T8132 PHYs read the flag; other generations are
unchanged. Small suggestion: the hibernate/D0 steps write DWC3_RESET_N directly without updating the flag, which is
fine today, but a note in the @dwc3_running kerneldoc that it follows the reset-controller ops only would keep later
users from treating it as the register state. Rows still worth having: the M4 mini with a device-role port (s2idle
x3), and a J713 row with a gadget function passing traffic across s2idle plus the host cable pulled during the sleep.

The flag tracks the reset controller ops DWC3 uses, not the
DWC3_RESET_N bit: the sleep hibernation and D0 steps toggle that bit
within one controller run without changing it. Say so, so a later user
doesn't read it as the register state.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Thanks. The kerneldoc note is in 916d514: dwc3_running follows the reset controller's assert/deassert only, not the DWC3_RESET_N bit that the hibernation/D0 steps toggle within one controller run.

On the rows: a J713 gadget row (NCM bound and passing traffic across s2idle) is queued on the J713. Pulling the host cable during the sleep needs a hand at the lab, so it waits for that. The M4 mini with a device-role port needs an owner with one; the row is just rtcwake -m freeze -s 20 x3 with a host computer on the port, plus /sys/power/suspend_stats before and after.

Assisted-by: LLM (Claude:Opus 5.5)

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

Reviewed at 916d5142abe7 (host-tests CI green, clean commits/DCO and PR attribution, no new cmdline params or chip/board gates beyond the existing T8132 common-block path).

The dwc3_running invariant against dwc3-apple's syscore ownership (dwc3-apple.c:886-908, 1784-1788, 1907-1979) holds for both host and device roles, atcphy_dwc3_reset_assert() properly keeps dwc3_running = true if atcphy_park_pipehandler() fails, and commit 916d5142 cleanly documents that dwc3_running follows reset-controller ops rather than the DWC3_RESET_N register bit.

Findings before approval

  1. Inconsistent host_active checks in atcphy_resume and atcphy_shutdown (drivers/phy/apple/atc.c:7885, 7915)

    • drivers/phy/apple/atc.c:7885:
      if (atcphy->t8132_common_owned && atcphy->host_active &&
          READ_ONCE(atcphy->pd_was_off))
              dev_warn(dev, "power domain went off under an active USB3 link\n");
      Now that atcphy_suspend() admits s2idle in device role on atcphy->dwc3_running (atc.c:7863-7865), an unexpected power-domain loss during device-role s2idle will silently skip this warning (and then assert DWC3 reset inside atcphy_restore_after_pd_off()). Check atcphy->dwc3_running here so host and device roles get the same invariant check.
    • drivers/phy/apple/atc.c:7915: atcphy_shutdown() similarly checks atcphy->host_active when guarding against incomplete USB3 common ownership; checking atcphy->dwc3_running catches a failed dwc3_apple_shutdown reset assert in device role as well.
  2. Hardware rows still needed

    • Second T8132 Mac with a device-role port: M4 mini (J773g) rtcwake -m freeze -s 20 ×3 with a host on the port and /sys/power/suspend_stats before/after.
    • Queued J713 gadget row (NCM bound and passing traffic across s2idle).
    • Explicit regression check (0 AVC, 0 failed units, 0 new kernel errors) on the J713 row.

Assisted-by: LLM (Google:Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Gadget row on the J713 (lab kernel = J713 batch 7 + this PR, stock command line, NCM gadget on port0, the other computer enumerating it as cdc_ncm):

  • 6 of 6 suspend-to-idle cycles (20 s, PMU RTC) completed with the gadget bound; the UDC stayed configured through each.
  • IPv6 ping over the NCM link passed after the 3rd and 4th sleep. After the 5th and 6th, host-to-device traffic stopped: the host's OUT transfers never complete (cdc_ncm ... NETDEV WATCHDOG: transmit queue 0 timed out on the host), while device-to-host still works.

So the PHY side holds, but a device that stays connected through s2idle can lose its OUT path. dwc3-apple has only a .prepare PM op, so in device role nothing takes the gadget off the bus for the sleep the way dwc3's own system suspend does (dwc3_gadget_suspend() soft-disconnects). Before this PR the same configuration could not enter s2idle at all, and an image with no gadget function bound is unaffected. A follow-up for dwc3-apple (disconnect a device-role gadget for s2idle, connect it again after) is in progress, with its own row.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

The gadget stall is fixed in #2728 (dwc3-apple takes a device role off the bus for suspend-to-idle and connects it again after). With it on top of this PR, the J713 gadget row passes: 6/6 suspend-to-idle with ping 10/10 and iperf3 host-to-device 280 Mbit/s after each, a clean disconnect and re-enumeration on the host every time, and no watchdog timeouts.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Still needed: check dwc3_running instead of host_active in the resume power-domain warning (atc.c:7885) and in atcphy_shutdown() (:7915), an M4 mini (J773g) row with a device-role port (3 suspend-to-idle cycles), and the 0 AVC / 0 failed units / 0 new kernel errors counts on the J713 row. It should land together with #2728, which keeps the device-role OUT path working across suspend-to-idle, and #2705 after it.

atcphy_suspend() now admits suspend-to-idle for a T8132 common epoch
whenever DWC3 runs on the PHY, as a host or as a device. Two checks of
the same invariant still looked at host mode only:

- atcphy_resume() warns when the power domain went off under an active
  USB3 link. A device role that lost the domain across suspend-to-idle
  went unreported, although it was admitted on the same promise that
  the domain stays on.
- atcphy_shutdown() refuses to take down a common epoch that is still
  in use. A device role whose reset assert failed in
  dwc3_apple_shutdown() left DWC3 running with host_active clear, so
  the PHY went on to power the common block off under it.

Check dwc3_running in both. Every path that asserts the DWC3 reset also
clears host_active, and host mode is only set on a running controller,
so host roles are covered as before.

The T8132 host test now counts the resume warning and expects it for a
device role that lost the domain, the shutdown test blocks on a DWC3
left running in device role and its reset stub clears the flag, and two
negative controls reject the host-only checks.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Both findings from the 11-21 review are fixed in da78109.

  • Resume warning (atcphy_resume(), drivers/phy/apple/atc.c:7886): it now checks dwc3_running instead of host_active, the same condition atcphy_suspend() admits suspend-to-idle on. If a device role loses the power domain across suspend-to-idle, it now gets the warning before the restore asserts the DWC3 reset.
  • atcphy_shutdown() (atc.c:7917): the guard checks dwc3_running instead of host_active. Before this, if dwc3_apple_shutdown() failed to assert the reset with the port in device role, the PHY still powered the common block off under the running controller; now it keeps the epoch and logs the error. Host roles behave as before: every reset-assert path also clears host_active, and host mode is only set while the controller runs.

Tests: tools/testing/selftests/drivers/apple/atc-t8132-usb3.py now counts resume warnings and expects one when a device role lost the domain. The shutdown case covers DWC3 left running in device role, and its reset stub clears the flag the way the real assert does. Two new negative controls swap each check back to host_active, and both fail as they should. The same test run against the old atc.c fails on the new resume assertion. Host tests --only atc passed 6/6 (including atc-usb3-tests --mutations and apple/atc-t8132-usb3 at 13/13), --only dwc3 passed 1/1 and apple-dcp passed 1/1. drivers/phy/apple/atc.o builds with W=1 (clang, fleet81 config) with no compiler warnings, and checkpatch --strict is clean.

Hardware rows still to run:

  • J713, device role on port0, with this head and usb: dwc3: apple: take a device role off the bus for suspend-to-idle #2728 on top, stock command line: rtcwake -m freeze -s 20 x3, then 0 AVC (ausearch --input-logs -m avc), 0 failed units, and no new kernel errors against the boot.
  • M4 mini (J773g) with a device-role port: 3 suspend-to-idle cycles plus /sys/power/suspend_stats before and after. We have no M4 mini in the lab, so this one needs an owner who has one, or a waiver.

This should land together with #2728.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at da78109: no blockers.

Both findings from the 11-21 review are fixed. atcphy_resume() (drivers/phy/apple/atc.c:7886) now warns on a lost power domain when dwc3_running is set, the same condition atcphy_suspend() (:7864) admits suspend-to-idle on, so a device role that loses the domain is reported before atcphy_restore_after_pd_off() asserts the reset. atcphy_shutdown() (:7917) now keeps the common epoch when DWC3 is still out of reset in either role. Host roles behave as before. Every reader of dwc3_running is behind a T8132 check (hw->gen/t8132_ss/t8132_common_owned), so other Macs are unchanged.

Still open, as listed earlier: the J773g device-role suspend-to-idle row (x3, suspend_stats before and after), and the 0 AVC / 0 failed units / 0 new kernel errors counts on the J713 row. This should land together with #2728.

Full review
  • Commits in integration/aurora..da781091 (8b8e6af, 916d514, da78109): each has only a human Signed-off-by, with no Co-Authored-By, Assisted-by or session trailers. The PR body ends with the Assisted-by: line. git merge-tree onto the current integration/aurora (95a13cf) is clean.
  • Writers of dwc3_running: _atcphy_dwc3_reset_assert() clears it under atcphy->lock, and atcphy_dwc3_reset_deassert() sets it after the RESET_N write, also under the lock. Every reset-assert path goes through the helper: the reset op, atcphy_restore_after_pd_off(), probe finalize and atcphy_sleep_recover(). All three readers (suspend, resume, shutdown) hold the same lock, so the flag cannot change between the check and the decision.
  • If atcphy_park_pipehandler() fails in the assert op, host_active is cleared but dwc3_running stays true. That is correct: the controller has not been reset, and suspend-to-idle with a running controller keeps the shared domain on.
  • The direct RESET_N writes in the sleep-in-place hibernate and come-back steps (atc.c:7071, :7123) leave the flag alone. That matches the kerneldoc ("follows the reset controller's assert/deassert only"). atcphy_sleep_recover() clears the flag, and the glue's dwc3_apple_recover() restarts the controller through sleep_stop/sleep_start and the reset ops, which set it again. That path also only exists on fixed-hub (sleep_power) ports, which none of the T8132 checks reach.
  • Resume warning: system resume runs suppliers before consumers, so the PHY checks pd_was_off before dwc3 can touch the controller. A domain lost at runtime can't produce a false warning, because a started controller holds a runtime PM reference (rpm_held) for as long as reset_pending is set.
  • Shutdown: dwc3_apple_shutdown() (T8132 compatible only) goes through dwc3_apple_exit(), which asserts the reset whenever reset_pending is set. reset_pending is set on every deassert, in either role, so after a normal shutdown dwc3_running is false and the common block is powered off as before. Only a failed assert now keeps the epoch, with the existing dev_err. Without dwc3-apple bound, the reset was never deasserted, so the flag stays false and shutdown is unchanged.
  • No new module or cmdline parameters, no added delays, and no chip or board checks beyond the existing T8132 generation and of-data selection. The struct field is written on every generation but read only on T8132.
  • Tests, run locally at da78109: run-host-tests.py --only atc passed 6/6 (including atc-usb3-tests --mutations with the two new reset-flag mutations, and apple/atc-t8132-usb3 with its new host-only negative controls for suspend, resume warning and shutdown guard). --only dwc3 passed 1/1 and --only apple-dcp passed 1/1. drivers/phy/apple/atc.o builds with W=1 (clang, fleet81 release config) with no compiler warnings. The only W=1 output is the kernel-doc notes for existing t8132_*/cio_sleep members; the new @dwc3_running is documented.

Assisted-by: LLM (Claude:Opus 5.5)

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