Skip to content

phy: apple: atc: Retry only an owed SuperSpeed port power-on, warn on a failed post-sleep mode - #2409

Closed
RyanTheTide wants to merge 2 commits into
mainfrom
hack/phy-usb-retry
Closed

RyanTheTide wants to merge 2 commits into
mainfrom
hack/phy-usb-retry

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

drivers/phy/apple/atc.c retries the power-on of a fixed-hub controller's SuperSpeed root port that a Type-C mux update still owes (atcphy_usb3_port_retry(), added in 5f5dc5f, "phy: apple: atc: Retry a SuperSpeed port power-on that a mux update owes"). It is reached only on a fixed-hub PHY with the T8140 DisplayPort path, which is the J700 rear port today.

atcphy_mux_update_to() hands every USB-side failure to the retry, also a failure to look up the root hub or to take the port down. When no port was held off there is nothing to power on: the retry work still takes the controller, xHCI and root hub locks up to five times over about three seconds, which waits for any enumeration in progress, and if the lookup keeps failing it warns "SuperSpeed port left off" about a port that was never off. The same happens for a port held off once its host or root hub is gone (-ENODEV, -ESHUTDOWN). No retry can bring that port back. The next host powers its root hub ports itself as it starts, and atcphy_usb3_set_mode() drops the debt then.

After a sleep in place, atcphy_common_restore() falls back to USB2 when it cannot set a USB3 mode up again, and warns "USB2 for now". The second attempt that this message promises is atcphy_sleep_ss_up(), which logged its result at debug level only. If that attempt failed as well, the port stayed at USB2 until the next Type-C event, and the log said nothing beyond the first warning.

Change

  1. atcphy_usb3_port_retry() now schedules a retry only for a port that is still held off (usb3_port_off), and not after -ENODEV or -ESHUTDOWN. The case the retry was added for is unchanged: a power-on request to a running root hub that failed for want of memory, after a failed runtime resume, or while a controller or hub driver was not bound yet. Nothing signals when such a request would succeed, so the bounded backoff (100 ms doubling, five tries, about 3 s, then a warning) stays. Each failed power-on is still logged by atcphy_usb3_port_on() as it happens. The comment now says what is retried and why.
  2. atcphy_sleep_ss_up() warns when applying the mode again fails. The fallback's comment and message name the path that applies the mode again, and say that after a power cycle outside a sleep in place only the next Type-C event does. Why the set-up can fail after a sleep is not known yet. That is tracked in phy: apple: atc: USB3 mode not set up again after a sleep falls back to USB2, cause unknown #2314.

Both changes only affect the error paths of the fixed-hub T8140 PHY. On every other ATC PHY atcphy_usb3_pm_get() returns 0 without a root hub, usb3_port_off is never set, and the retry was not reachable before either. The sleep-in-place path exists only on fixed-hub T8140. No register access changes.

The sleep path is Diljit Singh's, from d9b438c ("arm64: apple: support coordinated suspend-to-RAM on T8140").

Testing

  • arm64 LLVM W=1 build of atc.o (with the KUnit tests compiled in) at both commits, release config: 0 warnings. checkpatch --strict is clean.
  • New KUnit case (compiled, not run, see below) atcphy_test_update_port_unowed. With no port held off, a root hub that is not bound yet leaves no retry queued. A held-off port behind such a hub is retried, until the host is gone (-ENODEV). A dead controller that fails the power-on with -ESHUTDOWN queues no retry. The existing retry cases (-ENOMEM power-on retried, given up after five tries, host gone) are unchanged.
KUnit and build

Objects built against an O= dir prepared from base 0abc2f3 with the release config (CONFIG_PHY_APPLE_ATC=m, CONFIG_PHY_APPLE_ATC_KUNIT_TEST=y, so the tests are compiled into atc.o): make ARCH=arm64 LLVM=1 W=1 atc.o, run at each of the two commits. Both builds: rc 0, 0 warnings. checkpatch --strict: 0 errors, 0 warnings, 0 checks on both patches.

The KUnit suite was compiled but not run. Running it needs a full arm64 kernel and modules for QEMU, which was not built for this change. Run with: ./tools/testing/kunit/kunit.py run --arch=arm64 --kconfig_add CONFIG_PHY_APPLE_ATC=y --kconfig_add CONFIG_PHY_APPLE_ATC_KUNIT_TEST=y 'phy-apple-atc*' (or load phy-apple-atc.ko on any arm64 kernel with KUnit and read /sys/kernel/debug/kunit/*/results).

Still to run

  • KUnit phy-apple-atc on arm64 (command below).

On J700 (T8140), with a USB3 device on the rear port:

  • Boot, then lsusb -t: the device is at 5000M, and dmesg | grep -c 'SuperSpeed port left off' is 0. It was also expected to be 0 before this change, so the row checks for regressions.
  • DisplayPort and USB3 through a dock, with a pin assignment change (replug the DP sink): USB3 comes back at 5000M, and there is no "SuperSpeed port left off" line.
  • s2idle and the deep sleep, where the lab allows it (rtcwake -m freeze -s 15, then the deep sleep path): after resume lsusb -t shows 5000M again, and the log has neither "not set up again after the sleep" nor "not applied again after the sleep". If either line shows up, it goes to phy: apple: atc: USB3 mode not set up again after a sleep falls back to USB2, cause unknown #2314 with the error code.
Hardware rows (combined test kernel, 2026-11-20)

This change was booted in a combined test kernel: integration/aurora 0abc2f3 plus the open gate-sweep drafts plus this and the related drafts (7.3.0-aurora-hk2/pwr1/hk3). It ran once on each lab Mac (M1 Pro J316s, M2 J413, J616s, Neo J700) and was compared against the production kernel on the same Mac, using the same silent row script:

  • kernel errors, failed units and SELinux denials;
  • microphone capture byte counts;
  • camera frame counts;
  • USB speeds;
  • panel brightness steps;
  • every retry/refusal message these drafts touch;
  • 2 s2idle cycles on M1 Pro, M2 and J616s.

M1 Pro, M2 and J616s matched production on every row, apart from the new counters and lines the drafts add. The Neo row found the old-DTB display regression that #2358's follow-up commit fixes.

This PR: "SuperSpeed port left off" and "not set up again after the sleep": 0 on all four Macs, including after 2 s2idle cycles on J616s, M1 Pro and M2.

…owed

atcphy_mux_update_to() hands every USB-side failure to
atcphy_usb3_port_retry(), also a failure to look up the root hub or to
take the port down. When no port was held off, nothing is owed: the
retry work only takes the controller, xHCI and root hub locks five
times over about three seconds, which waits for any enumeration in
progress, and if the lookup keeps failing it ends in "SuperSpeed port
left off" for a port that was never off. The same happens for a port
held off once its host or root hub is gone (-ENODEV, -ESHUTDOWN): no
retry can bring that port back, and the next host powers the ports of
its root hubs itself as it starts, where atcphy_usb3_set_mode() drops
the debt.

Schedule a retry only for a port that is still held off, and not for
a host that is gone. What is left is the case the retry was added for:
a power-on request to a running root hub that failed for want of
memory, a failed runtime resume, or a controller or hub driver not
bound yet. Nothing signals when such a request would succeed, so the
bounded backoff stays, and each failed power-on is still logged as it
happens. Document what is retried and why.

Fixes: 5f5dc5f ("phy: apple: atc: Retry a SuperSpeed port power-on that a mux update owes")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
When atcphy_common_restore() cannot set a USB3 mode up again after a
sleep in place, it falls back to USB2 and warns "USB2 for now", saying
that the mux update after the wake tries the mode again. That second
attempt is atcphy_sleep_ss_up(), which logs its result at debug level
only: if it fails too, the port stays at USB2 until the next Type-C
event, and the log has nothing beyond the first warning to say so.

Warn when atcphy_sleep_ss_up() fails, and say in the fallback's comment
and message which path applies the mode again, and that after a power
cycle outside a sleep in place only the next Type-C event does. Why the
set-up can fail after the sleep is not known yet; that is tracked in
#2314.

The sleep path is Diljit Singh's, from commit d9b438c ("arm64:
apple: support coordinated suspend-to-RAM on T8140").

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

Copy link
Copy Markdown
Contributor Author

Looks good; approve once the KUnit suite has run and the J700 rear-port row is done.

I checked the following and found no blocker.

  • drivers/phy/apple/atc.c:5664-5670: the early returns sit under atcphy->lock, before usb3_port_retries is reset. A retry chain already queued is not disturbed. usb3_port_off is cleared again by atcphy_usb3_set_mode() (:4737) and atcphy_dwc3_reset_assert() (:5264), so a port left to the next host does not leave a stale debt behind.
  • -ENODEV from atcphy_usb3_pm_get() covers only permanent or teardown cases: no graph endpoint, wrong driver, NOTATTACHED/dead HCD, multiport root. "Not bound yet" is still -EAGAIN, so the case the retry exists for keeps working.
  • :7504-7508: the new warning fires only when atcphy_mux_update_to() returns an error. An in-mode USB-side failure still returns 0 and queues the retry, so a recoverable case does not produce a false warning.
  • Reachability: atcphy_usb3_pm_get() returns 0 unless the PHY is fixed_usb2 && has_t8140_dp, so other Macs cannot reach the changed branches.

There are no gates, no new parameters and no register changes. The commits carry a human Signed-off-by with no agent trailers. The body ends with the Assisted-by line. CI host-tests pass. The PR merges cleanly with the current base and with #2403.

The combined-kernel row (0 "SuperSpeed port left off" on four Macs) is a regression check only. No Mac in it had a device on the J700 rear port, so the changed paths were not exercised. The new atcphy_test_update_port_unowed case has only been compiled.

HW row: on this head, run KUnit phy-apple-atc* on arm64 and get all cases passing. Then on J700, with a USB3 device on the rear port: boot shows 5000M; replug the DP sink through a dock 3 times and USB3 returns at 5000M with no "SuperSpeed port left off"; after 2 s2idle cycles (rtcwake on rtc0) USB3 is at 5000M and there is no "not applied again after the sleep" line. Pass criteria: 0 AVC, 0 failed units, no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

RyanTheTide added a commit that referenced this pull request Nov 25, 2026
…d port power-on, warn on a failed post-sleep mode

Folds #2409 into this PR unchanged.

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

Copy link
Copy Markdown
Contributor Author

Folded into #2457, which now carries this PR's commits unchanged (merge commit); review continues there.

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