Skip to content

soc: apple: sleep: T6030: GP PCIe wake from the loader's ADT tables - #4234

Open
RyanTheTide wants to merge 2 commits into
mainfrom
fix/t6030-gp-pcie-adt-tunables
Open

RyanTheTide wants to merge 2 commits into
mainfrom
fix/t6030-gp-pcie-adt-tunables

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem: #4067 brought T6030 (M3 Pro, J516s) deep sleep with a GP PCIe wake that replays about 450 register writes captured from a macOS wake: sleep-t6030-pcie-wake.h and the constants in t6030_gp_clocks_wake(). They are the AXI bridge, CIO3 PLL, clock generator, PHY, PHY PLL and lane tables that the ADT holds in /arm-io/apcie and aura applies at boot. Ryan's rule: nothing hard-coded; values come from the ADT, as M1/M2 and M4/M5 already do (the loader copies the ADT tables into apple,tunable-* properties and the driver applies them).

Change:

  • arm64: dts: apple: t6030: add the ADT reg[2] window (0x59e004000, 0xc000) to pcie0 as phy-block, the window apple,tunable-phy is relative to. The binding now allows 19 entries for T6030. pcie-apple maps by index and doesn't use the new window.
  • soc: apple: sleep: T6030: read apple,tunable-axi2af/-cio3pll/-clkgen/-phy/-phy-ip-pll/-phy-ip-auspma from the PCIe host and apply them during the existing wake steps. Like macOS, a register is only written when its value differs. The steps around the tables are the same as T6040's apple_sleep_raise_apcie(): clock generator start, PHY clock requests, reset release, run enables, ready, phy-common enable, PHY up, root complex ready. Only the PHY reset and up bits differ (7 and 9). sleep-t6030-pcie-wake.h is deleted. The power-word steps, PERST# handling and timings measured on our own Macs are unchanged.
  • Without all six tables, apple_sleep_undescribed() keeps s2idle the default and t6030_sleep_begin() refuses deep sleep: the same refusal model as ANS without its tunables.

Needs aurora-silicon/aura#665, which publishes the tables. Merge order: aura#665, then the J516s runs it, then this PR. On an older aura the J516s loses deep sleep (refused; s2idle stays).

Tested: J615 (T8122) at 9835b8d, no regression: deep sleep stays the default, 2/2 deep cycles, Wi-Fi back (comment below). No J516s yet. W=1 build of drivers/soc/apple/ is clean (no new warnings). CHECK_DTBS with apple,pcie.yaml is clean on t6030-j514s and t6030-j516s; the same check without the binding change flags the 19-entry reg. dt_binding_check passes. The J516s ADT values are not posted anywhere.
Risk: Two-way (plain revert). J516s (T6030) deep sleep only. J514s gets the DT window only; its sleep node stays disabled.

Still to run:

  • J516s (Dj) on aura#665 + this head: probe line deep sleep is the default, no no GP PCIe tunables warning. gp_equiv.py below must print EQUIVALENT (counts only). Then 2-3 committed deep sleeps with Wi-Fi, SD and Bluetooth back and no WARNING/SError.
  • J514s: boot, s2idle once.
Prior art and offset match
  • M1/M2: aura pcie_init_controller() applies apcie-axi2af/-common/-phy/-phy-ip-pll/-phy-ip-auspma-tunables from the ADT at boot and re-runs it after a sleep. T6040/T8140: aura dt_set_t6040_sleep_apcie() publishes the same six tables plus windows, and apple_sleep_map_apcie()/apple_sleep_raise_apcie() apply them. T8142: dt_set_t8142_sleep_apcie(). Post-M4 ANS: pcie_apcie_tables_fdt().
  • Our J615's 27.2 live ADT (T8122, the same M3 PCIe generation) carries these six tables on /arm-io/apcie. The offsets the J516s capture touched match them: all 13 axi2af offsets and all 7 cio3pll offsets exactly. The clkgen write is its single record's masked bits, followed by START go and OFF2 clear (the T6040 sequence). The phy table's 0x800c/0x8010 are the capture's phy-shared +0xc/+0x10 reads. The PHY-IP writes run the PLL table first, then the per-lane AUSPMA tables, in table order. The capture's 7 remaining phy writes are the sequence steps above.
  • T8122's reg[2] (0x59e000000, 0x1c000) differs from T6030's (0x59e004000, 0xc000), so the window comes from the DT instead of a fixed offset.
gp_equiv.py: check the published tables against the old capture (J516s, counts only)
git show 7303d70ea68d:drivers/soc/apple/sleep-t6030-pcie-wake.h > old-wake.h
git show 7303d70ea68d:drivers/soc/apple/sleep-t6030.h > old-t6030.h
python3 -I gp_equiv.py old-wake.h old-t6030.h /proc/device-tree/soc/pcie@580000000
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only OR MIT
"""Check the loader-published T6030 GP PCIe tables against the old captured wake sequence.

Run on a J516s booted with the new aura (the tables are in the live DT):
    python3 -I gp_equiv.py <old sleep-t6030-pcie-wake.h> <old sleep-t6030.h> [dt-host-dir]

The old headers are main 7303d70ea68d's drivers/soc/apple/sleep-t6030-pcie-wake.h and
sleep-t6030.h (git show 7303d70ea68d:<path>). dt-host-dir defaults to
/proc/device-tree/soc/pcie@580000000. Prints counts only, never register values.

For each register the old sequence wrote in a table-backed block, the table must predict the
written value from the value read just before it: (before & ~mask) | (value & mask). Each
table record whose application would change the value read must have been written. Clock
blocks have no "before" in the capture, so there only the masked bits are compared.
"""
import re
import struct
import sys
from pathlib import Path

WAKE, T6030 = Path(sys.argv[1]).read_text(), Path(sys.argv[2]).read_text()
HOST = Path(sys.argv[3] if len(sys.argv) > 3 else "/proc/device-tree/soc/pcie@580000000")

def table(name):
    p = HOST / f"apple,tunable-{name}"
    if not p.exists():
        sys.exit(f"MISSING apple,tunable-{name}: the loader did not publish it")
    raw = p.read_bytes()
    words = struct.unpack(f">{len(raw) // 4}I", raw)
    return [(words[i], words[i + 1], words[i + 2]) for i in range(0, len(words), 3)]

tables = {n: table(n) for n in ("axi2af", "cio3pll", "clkgen", "phy", "phy-ip-pll",
                                "phy-ip-auspma")}
print("published:", ", ".join(f"{n} {len(t)}" for n, t in tables.items()))

# phy-block holds phy-common at +0x4000 and phy-shared at +0x8000 (DT windows).
BLOCK = {"PHY_COMMON": ("phy", 0x4000), "PHY_SHARED": ("phy", 0x8000),
         "PHY_IP": ("phy-ip", 0)}
steps = re.findall(r"\{ T6030_GPW_(\w+), T6030_GPW_(\w+), (0x[0-9a-f]+), (0x[0-9a-f]+) \}", WAKE)

def records(block):
    if block == "phy-ip":
        return tables["phy-ip-pll"] + tables["phy-ip-auspma"]
    return tables[block]

def apply(block, off, before, k):
    """The value after the table's records at off, up to its k-th (0-based); hit: k exists."""
    recs = [(m, val) for o, m, val in records(block) if o == off]
    v = before
    for m, val in recs[:k + 1]:
        v = (v & ~m) | (val & m)
    return v, k < len(recs)

seen, last_read, nth, ok, bad, seq_only = {}, {}, {}, 0, 0, 0
for blk, op, off, val in steps:
    if blk not in BLOCK:
        continue
    block, base = BLOCK[blk]
    off, val = int(off, 16) + base, int(val, 16)
    if op == "READ":
        last_read.setdefault((block, off), val)
        continue
    if op != "WRITE":
        continue
    before = last_read.get((block, off))
    k = nth.get((block, off), 0)
    nth[(block, off)] = k + 1
    first = last_read.get(("first", block, off), before)
    last_read.setdefault(("first", block, off), before)
    want, hit = apply(block, off, first if first is not None else 0, k)
    if not hit:
        seq_only += 1          # a sequence step (clock request, run enable...), not a table
    elif before is not None and want == val:
        ok += 1
    else:
        bad += 1
    seen[(block, off)] = True
    last_read[(block, off)] = val

missed = 0
for block in ("phy", "phy-ip"):
    for o, m, val in records(block):
        before = last_read.get((block, o))
        if before is not None and (before & ~m) | (val & m) != before and (block, o) not in seen:
            missed += 1
print(f"phy/phy-ip writes: {ok} predicted by the tables, {bad} NOT, {seq_only} sequence steps")
print(f"table records that change a captured value but were never written: {missed}")

clk = {"a": "axi2af", "c": "cio3pll", "k": "clkgen"}
cok = cbad = cseq = 0
cnth = {}
for var, off, val in re.findall(r"t6030_gp_rw\((\w), (0x[0-9a-f]+), (0x[0-9a-f]+)\)", T6030):
    block, off, val = clk[var], int(off, 16), int(val, 16)
    k = cnth.get((block, off), 0)
    cnth[(block, off)] = k + 1
    recs = [(m, v) for o, m, v in tables[block] if o == off][k:k + 1]
    if not recs:
        cseq += 1
    elif all((val & m) == (v & m) for m, v in recs):
        cok += 1
    else:
        cbad += 1
print(f"axi2af/cio3pll/clkgen writes: {cok} match the tables' masked bits, {cbad} NOT, "
      f"{cseq} sequence steps")
print("EQUIVALENT" if not bad and not missed and not cbad else "DIFFERENT")

Self-check: tables built from the capture's own writes give EQUIVALENT; flipping one bit in one lane record gives DIFFERENT.

The ADT's /arm-io/apcie reg[2] (0x59e004000, 0xc000) is the window the
loader's apple,tunable-phy records are relative to. The DT so far only
named the phy-common and phy-shared parts of it. Add it to pcie0 as
"phy-block", as other Apple PCIe hosts already do, so the T6030 sleep
driver can apply that table after a deep sleep. pcie-apple maps its
windows by index and doesn't use the new one.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The T6030 wake replayed about 450 register writes of the GP PCIe AXI
bridge, CIO3 PLL, clock generator, PHY, PHY PLL and lanes that were
captured from a macOS wake. Those are the values the ADT holds in
/arm-io/apcie's apcie-*-tunables, the same tables aura applies when it
brings the block up at boot. On every other Apple PCIe block Linux gets
them from the loader as apple,tunable-* properties.

Do the same on T6030: read apple,tunable-axi2af, -cio3pll, -clkgen,
-phy, -phy-ip-pll and -phy-ip-auspma from the PCIe host and apply them
during the existing wake steps, writing only registers whose value
differs, like macOS does. The sequence around them (clock generator
start, PHY clock requests, reset, run enables, ready, root complex) is
the same as T6040's in apple_sleep_raise_apcie(). Only the PHY reset
and up bits differ (7 and 9).

When the loader didn't publish all six tables, apple_sleep_undescribed()
keeps s2idle the default and T6030 refuses deep sleep, as it does for
ANS without its tunables.

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

Copy link
Copy Markdown
Contributor Author

J615 no-regression row (T8122, 27.2) at 9835b8d, booted with its own J615 DTB through aura-try (production aura b18, Stage 2 unchanged). The only shared change here is a T6030-only flag in sleep.c.

  • Deep sleep stays the default (deep sleep is the default: boot object resumes 0); no GP PCIe tunables line on T8122.
  • 2/2 committed deep sleeps via the apple-pmu RTC (resumes 0 -> 1 -> 2, suspend_stats 3/0); Wi-Fi answered after each; 0 Oops/WARN; 0 failed units.
  • Err-level lines: brcmfmac/bcm4377 D3hot to D0 x2 and one Bluetooth 0x0c01 timeout with rebind after cycle 2. Both also show up on main-based J615 rows (2d24189, dbfe45a), so they're not from this PR.
  • J615 restored: 7.3.0-aurora-edge default, next_entry empty, Enforcing.

Still owed: the J516s row (aura#665 + this head, gp_equiv.py EQUIVALENT, deep cycles), asked of Dj in the M3 thread.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J516s row kit for this head is sealed; the M3 lead runs it.

  • Stage 2: aura main 06c581d1 + aura#667 (e684ee89, the wake-replay fix) + aura#665 (4c0f64da), merged without conflict. aura#665 alone doesn't stop aura#529's wake replay on J516s: its GP branch returns 0, so kboot still calls pcie_set_os_restores_apcie(false). main cold-boots there on the first deep wake, so this row needs aura#667 as well.
  • Kernel: 9835b8d with its own t6030-j516s.dtb (J516s f3822 config).
  • Pass: aura's GP tables published line, the six tables in the live DT, gp_equiv.py EQUIVALENT, then 3 committed deep sleeps. After each one, Wi-Fi, SD and Bluetooth must be back (Bluetooth checked with an HCI round trip), and there must be no T6030 wake: GP PCIe warnings. A stock control arm runs first to check the Wi-Fi/SD/BT tests on this Mac.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Hardware verification on MacBook Pro 16-inch (M3 Pro, J516s, T6030, OS firmware 27.2) covering paired aura#665 (4c0f64da115db64796ccb16093e3e0fa3f47b431) + linux#4234 (9835b8d09b2f52e4e461aff2b6eae064a3817a9d).

Stack

  • Arm A (stock control, 0 reboots): 7.3.0-f3822 + Stage 2 1.0.0b17-g683a128b (boot_id 7ae9a46c-a3c2-4811-8257-6fbc655f1b43, 2026-12-03T22:50:40Z .. 22:51:15Z) — PASS (21 PASS, 0 FAIL, 0 INCOMPLETE), confirming stock DT has none of the six apple,tunable-* tables and baseline Wi-Fi / Bluetooth (60:3e:5f:4a:e8:c8) / SD (sdhci-pci 17a0 mmc0) / PCIe (5/5) / NVMe pass twice.
  • Arm B (trial): Stage 1 1.0.0b17-gf52d8324 (aura-try one-shot) -> Stage 2 1.0.0b19-ge684ee89-pr665 (aura main 06c581d1 + aura#667 e684ee89 + aura#665 4c0f64da, merged tree 08237bf6c3d6, aura.bin 2ee5d015...) -> Kernel 7.3.0-r4234 (linux#4234 9835b8d09b2f, tree 80d6a4f60f2c, with #4234's t6030-j516s.dtb, captured sleep-t6030-pcie-wake.h absent). boot_id 3b1bcd22-646b-45be-8fca-825d52d7b634 (2026-12-03T22:52:14Z .. 22:55:01Z).

Result: PASS (all hardware & equivalence criteria met; 78/79 automated checks PASS, 1 parser wrap miss on Stage 2 ring log explained below)

  • Stage 2 publication (aura#665): FDT: /arm-io/apcie GP tables published, 240 records (refusal empty). Live DT host pcie@580000000 exposes phy-block and all six apple,tunable-* tables totaling 240 records: axi2af:13, cio3pll:7, clkgen:1, phy:2, phy-ip-pll:31, phy-ip-auspma:186.
  • gp_equiv.py equivalence: EQUIVALENT (rc=0):
    • phy/phy-ip writes: 208 predicted by the tables, 0 NOT, 7 sequence steps
    • table records that change a captured value but were never written: 0
    • axi2af/cio3pll/clkgen writes: 12 match the tables' masked bits, 0 NOT, 2 sequence steps
  • 3/3 committed deep sleeps in one boot (21 s each, rtcwake rc=0):
    • apple-sleep 3642d4000.sleep-controller: deep sleep is the default: boot object resumes 0 (0 missing-tunables warnings), boot object resumes 0 -> 1 -> 2 -> 3, suspend_stats/success 0 -> 1 -> 2 -> 3, wake source NUB.SPMI0.SW3, 0 refusals, 0 T6030 wake: GP PCIe timeout/busy lines.
    • Every wake (1, 2, 3): CPUs 0-11; GPU 0 recoveries / 0 faults; 0 DART/IOMMU faults; 0 AER; PCIe 5/5 functions bound at 5GT/s x1 (brcmfmac, hci_bcm4377, sdhci-pci); Wi-Fi gateway reachable in 8 s / 7 s / 7 s with 0 firmware traps; Bluetooth UP,RUNNING 60:3e:5f:4a:e8:c8 with Read_BD_ADDR round trip 1 ms and 0 errors; SD sdhci-pci vendor=17a0 host=mmc0 with 0 errors; NVMe read/write verified; 0 WARN/BUG/SError; 0 new error lines at boot and 0 new error lines from sleep 1 through wake 3.
  • Note on the 1 automated judge line (aura#667 gate log grep): the line IS present in aura_stage2.log (mtd1, 16 KiB circular buffer), split across the 16 KiB wrap boundary — tail ends with [ 13.496929] pc and byte 0 of mtd1 continues ie: the OS brings /arm-io/apcie's host back from a sleep itself followed by [ 13.497150] dapf: .... The gate clearly fired (all 3 deep wakes stayed in boot 3b1bcd22).

@RyanTheTide
RyanTheTide marked this pull request as ready for review December 3, 2026 23:00
@RyanTheTide
RyanTheTide requested review from a team as code owners December 3, 2026 23:00
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Merge readiness at 9835b8d0: not ready yet

Check Detail
CI at head running running: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok in the PR body at 9835b8d0
Conflicts ok none
PR text ok Risk: two-way · (plain revert). J516s (T6030) deep sleep only. J514s gets the DT window only; its sleep node stays disabled. Still to run: - J516s (Dj) on aura#665 + this head: probe line deep sleep is the default, no no GP PCIe tunables warning. gp_equiv.py below must print EQUIVALENT (counts only). Then 2-3 committed deep sleeps with Wi-Fi, SD and Bluetooth back and no WARNING/SError. - J514s: boot, s2idle once.

Areas: area:platform

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

This branch has not been deployed

No deployments
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) blast:m3 Macs affected, from Merge risk (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.

2 participants