Skip to content

phy: apple: t6040: Count the coprocessor hard recoveries in debugfs - #2410

Merged
RyanTheTide merged 4 commits into
mainfrom
hack/phy-usb-retry-b
Nov 28, 2026
Merged

RyanTheTide merged 4 commits into
mainfrom
hack/phy-usb-retry-b

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What: Count the T6040/T6041 USB2 PHY coprocessor hard recoveries (started, bring-ups retried, bring-ups failed with no retry left) and show them read-only in debugfs. The recovery itself is unchanged.
Tested: J616s (M4 Pro, T6040) at 15782d9 in the combined one-shot kernel 7.3.0-aurora-dsw2 (main 2a173ca + 15 drafts; this PR's files byte-identical to head 62cf9b5 = 15782d9 + a clean merge of main): hard_recoveries = 0 on all three T6040 PHYs (t6040-atcphy-382a90000/38aa90000/392a90000.phy), USB root hubs up, 0 error-level lines, 0 WARN/BUG, s2idle rc 0 (only the baseline dwc3 genpd_prepare -11 lines the fleet kernel's own s2idle shows too), 0 failed units. M1 Pro, J473 and J713 (no T6040 PHY) boot the same kernel unchanged.
Risk: two-way · T6040, T6041 (debugfs counters only)
Not yet: a boot where a recovery actually runs (non-zero counter); none happened in this row

Evidence
  • Install: non-default boot entry copied from the saved one (same options, default command line), one-shot grub2-reboot, no Stage 2, DTB or boot.bin change (boot.bin 3fe02289 before and after). The J616s went back to the saved fleet89, the test kernel was removed, and production state was verified: next_entry empty, Enforcing, 0 failed units.
Original description

Problem

drivers/phy/apple/t6040-usb2.c (T6040/T6041) recovers a PHY coprocessor that did not acknowledge Power Down on detach, did not stop cleanly, or did not tune the PHY on attach. It power-cycles the common_dp and phymxwrap domains and tries the USB3 or CIO bring-up once more (T6040_RECOVERY_RETRIES, from 249746e, "phy: apple: t6040: hard-recover a wedged coprocessor"). Each step is logged. But the retry turns a wedged coprocessor into a working port, so the only way to tell how often this happens is to read back through the kernel log. Why the coprocessor wedges is not known (#2315).

Change

The recovery and its single retry stay as they are, and are now counted. struct t6040_recovery_state counts hard recoveries started, bring-ups tried again, and bring-ups that failed with no retry left. These appear read-only as hard_recoveries, bringup_retries and bringup_retries_exhausted in the PHY's existing debugfs directory (/sys/kernel/debug/t6040-atcphy-<dev>/), next to drop_next_power_down_ack. A comment at T6040_RECOVERY_RETRIES says why the retry is there and links #2315.

The counters are updated under the PHY lock on paths that already run, so there is no behaviour change on any port. The driver binds only on T6040/T6041.

The PHY driver is the work of Jonathan Goyvaerts, František Balázsy, CJ Damsleth, Jos Dehaes and AxxzyWasTaken, and the recovery is from 249746e.

Testing

  • arm64 LLVM W=1 build of t6040-usb2.o (with the KUnit tests compiled in), release config: 0 warnings. checkpatch --strict is clean.
  • KUnit phy-apple-t6040-recovery extended (compiled, not run, see below): the retry and exhaustion counts, and that they outlive the bring-up they were taken in.
KUnit and build

Objects built against an O= dir prepared from base 0abc2f3 with the release config (CONFIG_PHY_APPLE_T6040_USB2=m, CONFIG_PHY_APPLE_T6040_KUNIT_TEST=y, so the tests are compiled into t6040-usb2.o): make ARCH=arm64 LLVM=1 W=1 t6040-usb2.o: rc 0, 0 warnings. checkpatch --strict: 0 errors, 0 warnings, 0 checks.

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_T6040_USB2=y --kconfig_add CONFIG_PHY_APPLE_T6040_KUNIT_TEST=y phy-apple-t6040-recovery (or load phy-apple-t6040-usb2.ko on any arm64 kernel with KUnit and read /sys/kernel/debug/kunit/*/results).

Still to run

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

On J616s (T6040):

  • After boot, cat /sys/kernel/debug/t6040-atcphy-*/{hard_recoveries,bringup_retries,bringup_retries_exhausted} reads 0 0 0 with no missed acknowledgement in the log.
  • echo 1 > /sys/kernel/debug/t6040-atcphy-<dev>/drop_next_power_down_ack, then unplug and replug a USB3 device (or, without a person at the machine, unbind and bind the port's dwc3-apple controller, which powers the USB3 PHY off and on): hard_recoveries reads 1, the device comes back at 5000M (lsusb -t), and the log shows "completed hard recovery".
  • Plug cycles and DP/USB3 changes: record the counters. Any natural non-zero value goes to phy: apple: t6040: PHY coprocessor wedge is hidden by a hard recovery and one retry #2315 with the log lines around it.
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: J616s: hard_recoveries / bringup_retries / bringup_retries_exhausted read 0/0/0 on all three PHYs after boot and after 2 s2idle cycles.

A PHY coprocessor that does not acknowledge Power Down on detach, does
not stop cleanly or does not tune the PHY on attach has its common_dp
and phymxwrap domains power-cycled, and the USB3 or CIO bring-up is
tried once more. Each step is logged, but the retry turns a wedged
coprocessor into a working port, so how often it happens can only be
told by reading back through the kernel log, and why the coprocessor
wedges is not known yet.

Keep the recovery and the single retry, and count them: hard
recoveries started, bring-ups tried again and bring-ups that failed
with no retry left, read-only in the PHY's existing debugfs directory
next to drop_next_power_down_ack. Document why the retry is there and
link the issue that tracks the cause:
#2315.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Blockers: 1.

  1. drivers/phy/apple/t6040-usb2.c:1117-1119 and :1754-1756: when t6040_usb3_hard_recover() itself fails (phymxwrap does not power off, RTKit transport restart fails, common_dp resume fails), the bring-up jumps straight to failed/put. That bumps hard_recoveries, but nothing else counts it. t6040_recovery_retry() is never reached, so bringup_retries_exhausted stays 0. The same goes for a wake failure (goto sleep, :1124 and :1761). These are the cases that leave the port at USB2 until reboot, which is the outcome the counters are meant to show. From debugfs, "a recovery that started and failed" looks the same as "a recovery that started and worked". Count failed bring-ups on every path that ends in "USB3 PHY bring-up failed" / "CIO PHY bring-up failed", for example a bringup_failures counter bumped at the failed: and put: labels, or count exhausted there instead of in t6040_recovery_retry(). Then extend the KUnit case to cover a failed hard recovery.

Otherwise sound. I checked that every counter write happens under tphy->lock (the lockdep_assert_held at :1090 and :1729), that a racing u32 debugfs read cannot tear, and that the counts survive t6040_recovery_start()/complete() as the tests claim. The driver binds only on T6040/T6041, so other Macs are unaffected. Commit has a human Signed-off-by and no agent trailers. The body ends with the Assisted-by line. CI host-tests pass.

Not this PR: recovery_dwell_ms (:186-190) is a module parameter on the recovery path. It would be worth replacing with a fixed, documented dwell when #2315 is understood.

HW row: J616s on this head. Run the KUnit suite phy-apple-t6040-recovery (it has not been run yet). Then echo 1 > drop_next_power_down_ack and replug a USB3 device: hard_recoveries reads 1, the device is back at 5000M, and the counters read 0/0/0 on all three PHYs after a clean boot and after 2 s2idle cycles. Pass criteria: 0 AVC, 0 failed units, no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

The recovery counters only saw a failed bring-up when the firmware tune
failed with no retry left. A hard recovery that itself fails (phymxwrap
does not power off, the RTKit transport does not restart, common_dp does
not resume) and a wake that fails both leave the bring-up before
t6040_recovery_retry() is reached, so hard_recoveries went up and
nothing else did. Those are the cases that leave the port without USB3
or CIO, and in debugfs they looked the same as a recovery that worked.

Count every bring-up that ends in "USB3 PHY bring-up failed" or "CIO PHY
bring-up failed" at the two labels all those paths reach, and show it
as bringup_failures next to the other counters. bringup_retries_exhausted
keeps its meaning and is the part of the failures that had used the
retry. Cover a failed power cycle in the KUnit suite: it counts as a
failure, not as a retry or an exhausted one, and the next bring-up
still power-cycles.

Link: #2315
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review blocker fixed in 15782d9: every bring-up that ends in "USB3 PHY bring-up failed" or "CIO PHY bring-up failed" (failed hard recovery, failed wake via goto sleep, retry exhaustion) is now counted at the failed:/put: labels and shown as debugfs bringup_failures; bringup_retries_exhausted keeps its meaning. KUnit gains t6040_recovery_failed_cycle_test and the existing cases assert the new count.

Testing: t6040-usb2.c compiles warning-free with the KUnit test enabled; the recovery state machine + KUnit cases run on the host via a shim: 4/4 ok, and a mutant without the count fails 2/4; --only t6040 host tests 1/1.
Still to run: arm64 kunit.py run of the suite; J616s row on this head.

@RyanTheTide
RyanTheTide marked this pull request as ready for review November 28, 2026 17:14
@RyanTheTide
RyanTheTide requested review from a team as code owners November 28, 2026 17:14

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 62cf9b5

  1. The four debugfs_create_u32() readers in t6040_debugfs_init() use the generic plain load without tphy->lock, while recovery writers update the same fields under that mutex. A read during recovery races with the write. Use synchronized access on both sides, such as read-only getters that take the PHY mutex or atomic counters.
  2. bringup_failures is documented in struct t6040_recovery_state as counting all failed bring-ups. In t6040_cio_up_locked(), pm_runtime_resume_and_get() can fail after orientation and mode checks, yet it returns before the counter. Count that failure without dropping an unacquired PM reference, or document and test the narrower lifetime of the count.

I traced the USB3 and CIO retry, exhaustion, and early return paths. The DTS and bindings are unchanged. The J616s zero-count row covers idle exposure. Please run the recovery suite and confirm a nonzero readback in the next validation.

@github-actions github-actions Bot added area:usb Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
…d resume

The four recovery counts were plain u32s exposed with debugfs_create_u32(),
whose reader loads them without tphy->lock while a recovery updates them under
it. Make them atomic_t and expose them with debugfs_create_atomic_t().

bringup_failures is documented as every failed bring-up, but
t6040_cio_up_locked() returned before counting when
pm_runtime_resume_and_get() failed. Count that failure too. No runtime
reference was taken, so nothing is put.

The recovery KUnit cases now read the counts with atomic_read().

Reported by the aurora-silicon review of #2410.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Fixed in 571f175, per the review at 62cf9b5:

  1. Synchronized reads: the four counts are now atomic_t, updated with atomic_inc() and exposed with debugfs_create_atomic_t() (still 0400). So the lock-free debugfs read and the locked recovery write can't race.
  2. bringup_failures lifetime: t6040_cio_up_locked() now counts a failed pm_runtime_resume_and_get() as a failed bring-up before it returns. No reference was taken, so nothing is put. The struct comment names that case and says why the counts are atomic.
  • KUnit (PHY_APPLE_T6040_KUNIT_TEST, arm64 QEMU, LLVM): phy-apple-t6040-recovery 4/4 and phy-apple-t6040-usb2-mode pass (9 run, 8 passed, 1 skipped). The cases read the counts with atomic_read(). t6040-usb2.o, arm64 LLVM W=1: 0 warnings.
  • A nonzero readback on hardware is next: arm drop_next_power_down_ack on a J616s port, then one detach/attach so the next bring-up runs a hard recovery, and read hard_recoveries. That needs a cable action, so it's queued for the J616s.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 571f175 after hosted checks and nonzero hardware readback.

Checked: all four debugfs files now read atomics, and every update uses atomic_inc(). Failed CIO runtime resume increments the failure counter and returns before the reference-release path. Reviewed the retry and exhaustion assertions, the posted recovery KUnit results, and the prior J616s zero-count boot. DT sources and bindings are unchanged.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at 571f175a. App approved, rows J616s, T6040-PHY-only. Merges 1 h from now under the 6-point rule once hosted CI is green, unless you object.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merging under the 6-point rule (Ryan 09:29, permanent), at 571f175a. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J616s;T6040-PHY-only. (5) There's no blocking review. (6) Dj was pinged here 100 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit ed00bd1 into main Nov 28, 2026
2 of 5 checks passed
@RyanTheTide
RyanTheTide deleted the hack/phy-usb-retry-b branch November 28, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:usb Area from CODEOWNERS (bot) blast:m4 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant