Skip to content

spmi: apple: recover every generation 4 controller from a failed exchange - #2309

Merged
DjDeveloperr merged 1 commit into
mainfrom
sweep/soc-gates-spmi
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
sweep/soc-gates-spmi

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

drivers/spmi/spmi-apple-controller.c:241-247 (0abc2f3) ran the generation 4 recovery after a failed exchange only on a list of boards: J714s, J716c, J813 and J815. The recovery reads out late reply words. The list came from e6b75c3 and was extended in 446bb99 and 81c725d. On any other generation 4 board, one failed exchange made the driver refuse every later command on that bus until the next boot, and the PMU's RTC went with it.

Change

The board list is removed. The recovery belongs to the controller's reply FIFO, so it now runs on every generation 4 controller. Generation 4 is the match data (apple,t8142-spmi, !legacy_irqs), as before. Earlier generations keep their FIFO flush.

The recovery is bounded. It waits one command timeout, then reads at most SPMI_GEN4_REPLY_DRAIN_MAX words. If the FIFO still does not empty, the failure stays. On a board where nothing goes wrong, it never runs.

The recovery was written by Diljit Singh and extended by Nick and Erik Bourget.

Testing

  • Build, release config, LLVM: make W=1 drivers/spmi/spmi-apple-controller.o. No new warnings.

Still to run

None of our lab Macs has a generation 4 controller. Neo T8140, J616s T6040, M1 Pro T6000 and M2 T8112 all bind the apple,t8103-spmi or apple,t6000-spmi match data. On them, a boot with dmesg | grep -i spmi showing no new messages is enough.

Reach and safety

New reach: T8142 J704 and the T6050 boards that were not on the list (J714c, J716s, K114s, K114c, K116s, K116c, J873s, J775c, J775d). They all use the same apple,t6050-spmi/apple,t8142-spmi controller as the J714s and J813. The code runs only after a failed exchange, and the alternative is a bus that stays dead for the rest of the boot.

…ange

After a failed exchange a generation 4 controller (apple,t8142-spmi: T8142
and T6050) has no known FIFO flush, so the driver reads the late or stray
reply words out before the next command. That recovery ran only on a
board list (J714s, J716c, J813, J815); every other generation 4 board
refused all later commands on the bus for the rest of the boot, the PMU's
RTC among them.

The reply FIFO and its read-out are the controller's, the same on every
board with it, and the recovery is bounded: it waits one command timeout,
reads at most SPMI_GEN4_REPLY_DRAIN_MAX words, and keeps the failure if
the FIFO does not empty. Run it for every generation 4 controller. The
earlier generations keep their FIFO flush; the generation is the match
data (!legacy_irqs), as before.

The recovery was written by Diljit Singh and extended by Nick and Erik
Bourget.

Fixes: e6b75c3 ("spmi: apple: J714s: recover from a failed exchange on a generation 4 controller")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

No blockers.

Checked at 53f5d6c: apple_spmi_gen4_recover() (drivers/spmi/spmi-apple-controller.c:241) only runs from __spmi_raw_cmd() with prev_fail set on a !legacy_irqs controller, which is only the apple,t8142-spmi match (line 725). Every caller holds fifo_lock (a mutex, line 341), so the usleep_range() is in sleeping context. The sleep driver's by-hand PMU exchanges only trylock that mutex (lines 747-756), so they cannot run during the drain. The drain is bounded at 64 reads and keeps the failure if the FIFO does not empty. T8103/T6000-match controllers (every lab Mac) still take the FIFO flush branch and are unaffected. The code being widened has already run on the four boards in the removed list, so dropping the board list is the right fix. CI is green and the PR merges cleanly. It can leave draft.

  1. Overlap: T6050 sleep: select irq/spmi/smc/sio/rtkit handling by hardware, not board #2440 carries this same hunk (the same function removal and the same two deleted lines). Land it from one PR and drop it from the other, so the two comments don't drift apart.
  2. Nit: if the FIFO is truly stuck, prev_fail stays set (line 272 returns before line 277 clears it), so every later command now sleeps 50-100 ms (REG_POLL_TIMEOUT_US, line 71) before -EIO. The unlisted boards used to fail at once. That is acceptable for a dead bus, but the commit message should say so, because a sleep or RTC path that retries would see the extra time.

HW row: nice to have, not needed to merge: a generation 4 Mac that was not on the old list (J704, J714c or K114c) booted on the head, with 0 new spmi errors and a working RTC after 3x s2idle. Lab Macs do not reach this code.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide
RyanTheTide marked this pull request as ready for review November 22, 2026 10:15
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Adversarial pass at 53f5d6c: no blockers. One small point:

  • On a wedged gen4 controller that reports an empty reply FIFO, each later command now sleeps one timeout in apple_spmi_gen4_recover() (spmi-apple-controller.c:245), logs "recovered from a failed exchange" (:248, not ratelimited), and then fails again in apple_spmi_wait_rx_not_empty() (:225, also not ratelimited). Before, the boards outside the removed list returned -EIO at once and silently. A periodic RTC or hwmon reader on such a bus would print two lines per call. Making the :248 message dev_warn_ratelimited() keeps that bounded. Optional.
  • Row: none of the boards this newly reaches (T6050 J714c/J716s/J775d, T8142 J704) has a result posted. One boot on one of them showing the "recovered ... stale words dropped" line, followed by working PMU access (hwclock read), would cover it.

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.

Formal §1–§6 pre-PR review at verified live head 53f5d6c4e625c4dcf0ae6f5d909721ffb05b4140 against live integration/aurora (70a00e583b03, not superseded; MERGEABLE/CLEAN; live CI host-tests: PASS).

Verified Clean (§1–§4, §6)

  • Hardware selection & locking (§1–§3): Dropping apple_spmi_gen4_recovers() so reply-FIFO drain recovery runs for every !spmi->hw->legacy_irqs (apple,t8142-spmi) controller is the right §1 direction. Confirmed on live integration/aurora that __spmi_raw_cmd() is only called from spmi_raw_cmd() while holding spmi->fifo_lock (mutex, sleeping context safe for usleep_range()), and the drain is bounded by SPMI_GEN4_REPLY_DRAIN_MAX (64 reads).
  • Attribution (§4): Commit 53f5d6c4e625 carries human Author/Committer and full-name human Signed-off-by: Ryan Murray <ryan@aurorasilicon.org> only (zero AI commit trailers); PR body discloses assistance and credits prior authors.
  • Live CI (§6): Applicable live CI (host-tests) is green on 53f5d6c4e625.

Blockers Before APPROVE

  1. §5 Missing hardware verification & regression triad (zero boots on any Mac):
    • No hardware boot has been posted on any newly reached generation 4 board (T8142 J704 or T6050 J714c/J716s/K114s/K114c/K116s/K116c/J873s/J775c/J775d), nor even a regression smoke boot on an existing gen4 or lab Mac, and no §5 regression triad (0 SELinux denials, 0 failed units, 0 new kernel errors) is recorded.
    • Please post an exact-head default-cmdline boot + §5 regression triad on an affected gen4 Mac (ideally one of the newly reached boards confirming working SPMI/PMU RTC across s2idle and 0 unexpected SPMI errors).
  2. Duplicate hunk with open PR #2440:
    • Open PR #2440 (49a2916f451d) carries the exact same removal of apple_spmi_gen4_recovers() in drivers/spmi/spmi-apple-controller.c with different comment text. Please resolve ownership between #2309 and #2440 so they do not conflict in MERGETRAIN-LINUX4.

Non-Blocking Note

  • On a genuinely wedged gen4 bus whose RX FIFO reads empty, every subsequent command will now sleep 50–100 ms (REG_POLL_TIMEOUT_US), print an unratelimited dev_warn("recovered from a failed exchange...") (spmi-apple-controller.c:258), clear prev_fail, and immediately fail again in apple_spmi_wait_rx_not_empty(). Switching line 258 to dev_warn_ratelimited() (matching line 264) and noting the retry wait in the commit message would prevent log spam on periodic RTC/hwmon polling.

@axboe

axboe commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

K116s row (T6050, generation 4 controllers), from the machine's current boot.

Kernel: integration/aurora 70a00e5 + #2201 v8 + my other K116s commits (7.3.0-m5pro-g3a8e4da2d676). It carries this PR's commit unchanged (same diff as 53f5d6c), and my daily kernels have since Nov 19.

  • Boot: the PMU's RTC registers over SPMI (apple-pmu-rtc 28a014000.spmi:pmic@e:rtc: registered as rtc1).
  • Two deep sleeps on this boot, one woken by the PMU RTC alarm (wake events: NUB.SPMI0Sw3IRQ nub-spmi0.0x02 rtc). hwclock -r -f /dev/rtc1 reads fine afterwards.
  • 0 recovered from a failed exchange lines, 0 SPMI errors.
  • 0 failed units. 0 error-level kernel lines from boot up to the first sleep. The error-level lines at the wakes are the display's AFK ... unable to match service and three PCI device inaccessible lines from the Wi-Fi warm reset, none from SPMI.
  • No SELinux on this Debian install; 0 AppArmor denials.

Deep sleep, not s2idle: the PMU RTC cannot wake this SoC from s2idle.

@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 53f5d6c4: not ready yet

Check Detail
CI at head ok 1 check passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head no no line with the head SHA 53f5d6c4, a Mac and a result in the PR body or a comment
Conflicts ok not computed yet
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:platform

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

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

Verdict: MERGE at 53f5d6c4e625

Blockers: none.

Checked: no Apple material. This removes a gate: every generation 4 controller now recovers from a failed exchange, not just the list in apple_spmi_gen4_recovers(). axboe's K116s row (T6050, generation 4) carries this commit unchanged in its daily kernel: the PMU RTC registers over SPMI, two deep sleeps (one woken by the PMU RTC alarm), 0 recovery lines, 0 SPMI errors, 0 failed units. That counts as a row at the head. CI green. This replaces my earlier review. #2440 removes the same function with different comment text. Whichever merges second just takes the other's hunk, so it isn't a blocker here.

Evidence

Read 53f5d6c4 (drivers/spmi/spmi-apple-controller.c) and axboe's 11-24 row. On the lab Macs with older controllers (T8103/T6000 match data), a boot with no new SPMI messages is a check after the merge.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 19:39

Superseded by the review at 53f5d6c

@github-actions github-actions Bot removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 24, 2026
@DjDeveloperr
DjDeveloperr merged commit ca662ba into main Nov 24, 2026
2 checks passed
sithglan added a commit to sithglan/aurora-linux that referenced this pull request Nov 24, 2026
Merge aurora/main (c6d73b1) to pick up aurora-silicon#1798, aurora-silicon#2309, aurora-silicon#2691 and aurora-silicon#3089.

Conflict in arch/arm64/boot/dts/apple/t8152-j873g.dts: keep both the
t8152-j873-thermal.dtsi include from aurora-silicon#1798 and t8152-j873-usb4.dtsi.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants