Skip to content

PCI: apple: link PWREN to the GPIO chip's device - #4213

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/pcie-apple-pwren-provider
Dec 3, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/pcie-apple-pwren-provider

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What

Since #3809, T6030 (J514s/J516s) goes through apple_pcie_link_pwren(). On a J516s boot of main (536a613c0abe + #4200, 17:25Z) that failed the whole PCIe host, so Wi-Fi, Bluetooth and the SD reader were gone and the Mac fell off the LAN:

pcie-apple 580000000.pcie: error -EINVAL: no device link to gpiochip1
pcie-apple 580000000.pcie: probe with driver pcie-apple failed with error -22

Why: PWREN on J516s is an SMC GPIO (&smc_gpio 19). gpio_device_find() hands out a gpio_device as soon as device_add() has added its kobject (device_is_registered()), but device_add() only puts it on the PM list a few steps later (device_pm_add()), and device_link_add() returns NULL for a supplier that is not on that list yet. In the failing boot the host probed while macsmc-gpio was still adding its chip: the error is at 1.4118 s, between macsmc-gpio's First GPIO key (1.4034 s) and macsmc-low-gpio's (1.4160 s). Nothing else on that path can return NULL here: the flags are valid, there was no link to the gpio_device yet, and on the fixed J516s boot the host reaches neither macsmc-gpio nor its gpiochip over child or consumer links, so device_is_dependent() can't be the reason.

The fix links the host to the device that registered the chip (the gpio_device's parent, here the macsmc-gpio platform device). That device is on the PM list long before its driver adds the chip, and resume order stays the same, because a gpio_device resumes after its parent. If a link still can't be made, the host now warns and keeps going. The link only orders deep-sleep resume, and failing the probe takes every port down.

With the parent as supplier, device_link_add() usually reuses the SYNC_STATE_ONLY link that fw_devlink already made from the host to macsmc-gpio (port00's pwren-gpios). It adds the stateless flag and a reference, and once the host binds, a plain stateless link is left, which dpm_wait_for_suppliers() waits on. On J516s supplier:platform:macsmc-gpio is still there after a deep sleep.

One file, drivers/pci/controller/pcie-apple.c. The same function runs on T6041 (t6041_hw.s2r_noirq), where PWREN is also an SMC GPIO.

Tested

  • checkpatch --strict: 0 errors. The one warning is the quoted log line in the commit message.

  • W=1 build of pcie-apple.o: rc 0, 0 warnings, both on this head and on current main d6e13deca924 with this commit's blob (pcie-apple.c has not changed on main since the base). Plus a warm J516s kernel built from this head (7.3.0-pwren, f3822 config, gcc 16.2, on pc).

  • J516s (fw 27.2) row on this exact head, boot 2c7898d0, 18:09Z: the host probed and has a PWREN link to macsmc-gpio, 0 probe errors, Wi-Fi up. One committed deep sleep came back with Wi-Fi in 7 s, the same 5 PCIe functions, 0 AER/DART faults and 0 new error lines. The receipt comment has the details, including the audio FAIL that this PR does not cause.

  • J414s (firmware 27.2), exact head on main dc68a27f33d8: 2/2 committed deep sleeps, identical PCIe devices and bindings, Wi-Fi and NVMe working before and after both wakes, zero new errors.

Risk

Risk: two-way · J514s/J516s (T6030), J614c/J616c (T6041). Low. Only the device the link points at changes, and the link-failure path no longer fails the probe. On T6020/T8132 nothing changes (s2r_noirq is off there).

Not yet

  • T6041 (J614c/J616c) row on this head.
  • An approval from a maintainer other than DjDeveloperr, who pushed this head (require_last_push_approval).

Since T6030 takes the noirq resume path (#3809), a J516s boot can lose
the whole host, and with it Wi-Fi, Bluetooth and the SD reader:

  pcie-apple 580000000.pcie: error -EINVAL: no device link to gpiochip1
  pcie-apple 580000000.pcie: probe with driver pcie-apple failed with error -22

PWREN on J514s/J516s is an SMC GPIO. gpio_device_find() returns a
gpio_device as soon as device_add() has registered its kobject, but
device_add() puts it on the PM list only later, and device_link_add()
returns NULL for a supplier that is not on that list yet. The failing
boot probed the host while macsmc-gpio was still adding its chip: the
error falls between macsmc-gpio's "First GPIO key" line and
macsmc-low-gpio's.

Link the host to the device that registered the chip (the gpio_device's
parent) instead. That device is on the PM list before its driver adds
the chip, and resume order is unchanged, because a gpio_device resumes
after its parent. If no link can be made, warn and keep the host: the
link only orders deep-sleep resume, and failing the probe takes every
port down.

Fixes: 60d53dc ("PCI: apple: Set T604x ports up in the noirq resume after a sleep")
Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 18:03
@github-actions github-actions Bot added blast:m2 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (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 Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at a313071a: not ready yet

Check Detail
CI at head no failing: 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 comment at a313071a
Conflicts ok none
PR text ok Risk: two-way · J514s/J516s (T6030), J614c/J616c (T6041). Low. Only the device the link points at changes, and the link-failure path no longer fails the probe. On T6020/T8132 nothing changes (s2rnoirq is off there).

Areas: none matched in CODEOWNERS

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s row, exact head a313071a0aad (tree 9e7344e9ab0a), kernel 7.3.0-pwren (J516s config f3822), this kernel's own t6030-j516s.dtb in the stock Stage 2 1.0.0b17-g683a128b, fw 27.2. Boot 2c7898d0-572e-482d-84f7-3c5fcff02ed7, 18:07–18:10Z. Watchdog (60 s) and dead-man armed, reset route verified (M5 USB-C Right). J516s went back to stock 7.3.0-f3822 afterwards (boot bf5b9bdf).

What this PR is about, all PASS:

  • pcie-apple bound, 0 probe errors, 0 "PWREN may not be ready" warnings. The host's suppliers include platform:macsmc-gpio (the new link).
  • Wi-Fi up, lspci shows 5 functions (2 root ports, Wi-Fi, BT, SD).
  • One committed deep sleep (rtcwake -m mem -s 20): back from sleep, boot object resumes 0 -> 1, same boot, suspend_stats +1. Afterwards Wi-Fi answered in 7 s, the same 5 PCIe functions came back with none reading ffff and drivers bound, and there were 0 AER, 0 DART and 0 GPU faults.
  • 0 WARN/BUG/Oops before or after, and 0 new error lines against the f66d67e baseline boots.
  • On this boot the host reaches neither gpiochip1 (= macsmc-gpio here) nor macsmc-gpio over child/consumer links (what device_is_dependent() walks). A dependency cycle is therefore not why the old device_link_add() returned NULL.

Verdict FAIL, on timed audio only: 2 s of zeros to the headphone PCM played in 0.32 s/0.29 s before the sleep and 0.30 s/0.27 s after (stock f3822 takes 2.06 s), and cs42l84 1-004b: PLL lock error repeated (3 before the sleep, 5 at the end). This diff does not cause it. It only changes which device the PCIe host links to. The 17:25Z boot of main 536a613c + #4200 without this PR logged the same PLL error, and the f66d67e baseline boots log one each. It looks like an MCA/NCO clock fault on main, to be tracked on its own.

Not run here: T6041 (J614c/J616c), which runs the same function.

@github-actions github-actions Bot added blast:m3 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) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 3, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review at a313071a0aad: no correctness problem found. This is a comment, not an approval.

I read the diff, the surrounding code in pcie-apple.c, the SMC GPIO driver, gpiolib and the device-link code at this head, without relying on the PR text.

Root cause. It holds up against the code. gpio_device_find() hands out a chip once device_is_registered() is true (gpiolib.c:1491), and that is set by kobject_add() in device_add() (core.c:3727). device_pm_add() runs later (core.c:3752). Until then device_link_add() returns NULL, because device_pm_initialized(supplier) is false (core.c:843). So the gap the commit describes is real.

The new supplier. macsmc-gpio sets gc.parent = &pdev->dev (gpio-macsmc.c:563, and :455 for the pcIO bank), and gpiolib copies that into gdev->dev.parent (gpiolib.c:1220). The link therefore points at the macsmc-gpio platform device. That device is on the PM list before its probe can add the chip, so the race is gone.

Resume order. When fw_devlink's sync-state-only link from the host to macsmc-gpio already exists, device_link_add() takes a reference, adds STATELESS and reorders the host to the tail (core.c:887-890). After the host binds, device_link_drop_managed() drops only the managed reference. The flags left behind (STATELESS plus SYNC_STATE_ONLY) no longer count as sync-state-only, so dpm_wait_for_suppliers() still waits on macsmc-gpio in noirq resume (power/main.c:292-295). macsmc-gpio waits for its parent, the SMC, so PWREN is reached in the same order as before.

References and error paths. Each port with PWREN takes one link reference and adds one devm action. They are released when the host unbinds or its probe fails, and devm_add_action_or_reset() drops the reference itself if it fails. The warning path adds nothing, so nothing leaks there. gpiod_to_gpio_device() takes no reference, and the descriptor is devm-held.

Other SoCs. Hosts with no PWREN or without s2r_noirq (T6020, T8132) never reach this code (pcie-apple.c:3172). A chip with no parent falls back to the gpio_device, which is the old behaviour except that it now warns.

Hard failure turned into a warning. I agree with this change. With the parent as supplier, this race can't trigger it any more. The remaining NULL case is a dependency cycle, which isn't expected here. The warning is loud enough for a row to count, and the J516s row counted 0.

Fixes tag. 60d53dcf22c3 (from #2215) is on main and added apple_pcie_link_pwren(), so the tag is correct.

Merge with current main 24970e12484c. git merge-tree is clean. Nothing that landed on main since the base touches pcie-apple.c, gpiolib or the driver core.

Two notes, neither blocking:

  • If the warning ever does fire, the noirq resume still drives PWREN through the SMC with nothing ordering it. A later change could note the missing link and leave that port to the normal resume. This fix doesn't need it.
  • A problem that predates this PR, outside the diff: if a bootloader ever leaves a T6030/T6041 port trained, probe skips apple_pcie_setup_link() (pcie-apple.c:3496-3497), so perst_gpio stays NULL. The first apple_pcie_link_pwren() call then comes from the noirq resume, through apple_pcie_hib_port_up() (pcie-apple.c:10170, 10191). There, device_link_add() reorders the host and its children to the tail of dpm_list in the middle of resume (core.c:457-471). That takes them off the lists the rest of that resume walks. The J516s row didn't hit this, because the link was made at probe. It's worth its own issue.

Still owed before merge: the exact-head J414s (T6020) row, since pcie-apple is shared code.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J414s (Mac14,9, T6020, OS firmware 27.2) exact-head PCIe and deep-sleep regression row at a313071a0aad3b9cf0cf31345f040c629ef620f3: 2/2 PASS on current main (dc68a27f33d80c50ca0adaeea355254276e38b34, which includes #4200 ebfc4f60bdd1).

1. Merge tree on current main (dc68a27f33d8 + #4213 a313071a0aad): 2/2 PASS

  • Target: J414s (Mac14,9, T6020, m1n1/boot.bin sha256 196da4c690882ac64a70932e2dbb5affa0828e533117c975633e1b6705a9bd38, sleep-controller@28e080000 verified identical to t6020-j414s.dtb).
  • Kernel: 7.3.0-j414s-4213-dc68 (merge 24d7425530b969eb1edf88539c728907e4d43b63, tree db4d5ca64d91d8968af5151ef2c98b5677f2c60e, build ID 72aee41901302096e51b0055b2706ecb58f71550, Image sha256 d211fe8ede35025298e4ef9f9d055aa0f222a476c838674cff596aa9ef2808f3, .config sha256 ea70d3ce5481eed72fd4b79b2ead31d6324e2e573625ca398dd2ea527f6dc281 — zero config diff vs the sealed kit).
  • Boot ID: 85d4cbde-a0fe-4064-b3de-572ec15ed25d
  • Runner: row.sh --run (rtcwake -d /dev/rtc0 -m mem -s 20, wld0 -> 10.0.0.1, /dev/nvme0n1 4 MiB O_DIRECT read, Apple SoC Watchdog active + systemd dead-man timer active), run twice consecutively in the same boot:
    • Cycle 1 (out1): PASS J414s regression: committed deep sleep, identical PCIe devices and bindings, Wi-Fi and NVMe before/after (boot object resumes 0 -> 1, pcie-apple 580000000.pcie: S2R: /soc/pcie@580000000/pci@0,0 and pci@1,0 link back, PWREN and PERST# cycled as at probe, boot-pcie-errors and kernel-errors empty).
    • Cycle 2 (out2): PASS J414s regression: committed deep sleep, identical PCIe devices and bindings, Wi-Fi and NVMe before/after (boot object resumes 1 -> 2, suspend_stats: success=2 fail=0, identical PCIe devices 00:00.0, 00:01.0, 01:00.0 brcmfmac, 01:00.1 hci_bcm4377, 02:00.0 sdhci-pci and driver bindings before/after both wakes, boot-pcie-errors and kernel-errors empty).
  • Stock return verified: 7.3.0-47.fc45.aurora.aarch64 (boot 28bcbcb0-0ff0-429c-b75c-b42d7ba7f6d6).
  • Archive: work/j414s-pr4213-dc68-20261203/ (SHA256SUMS).

2. Earlier run on pre-#4200 main (d6e13deca924 + #4213 a313071a0aad): base issue confirmed

  • The earlier sealed kit (work/edge-j414s-4213-20261203, 7.3.0-edge-j414s-4213-a313071a, build ID 6b0e480c1a4d7efd361748fe4a381ca0f709681a) was based on main d6e13deca924 prior to #4200 (ebfc4f60bdd1, clk: apple-nco). On both attempts (bfda3a7c, bf40813f) boot PCIe enumeration and pre-sleep Wi-Fi/NVMe checks passed, while rtcwake -s 20 deep sleep reset identically (PMU logged 1 boot error(s) and 0 panic(s) at +91–92 s from suspend entry) due to the stopped-NCO deep-sleep stall fixed by #4200. Rebuilding with identical .config, DTB, boot.bin, and row.sh -s 20 onto main dc68a27f33d8 (with #4200) resolved it cleanly (2/2 PASS above).
  • Scope note: T6020 has s2r_noirq = false, so this J414s row covers cross-generation PCIe enumeration, Wi-Fi/NVMe I/O, and deep-sleep non-regression; the changed apple_pcie_link_pwren() branch is covered by the J516s exact-head row.

@DjDeveloperr
DjDeveloperr merged commit d140c54 into main Dec 3, 2026
16 of 17 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/pcie-apple-pwren-provider branch December 3, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (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