Skip to content

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

Open
RyanTheTide wants to merge 1 commit into
integration/aurorafrom
sweep/soc-gates-spmi
Open

RyanTheTide wants to merge 1 commit into
integration/aurorafrom
sweep/soc-gates-spmi

Conversation

@RyanTheTide

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.

Assisted-by: LLM (Claude:Opus 5.5)

…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)

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