Repository navigation
PCI: apple: link PWREN to the GPIO chip's device - #4213
Conversation
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>
|
Merge readiness at
Areas: none matched in CODEOWNERS Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J516s row, exact head What this PR is about, all PASS:
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 Not run here: T6041 (J614c/J616c), which runs the same function. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
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), soperst_gpiostays NULL. The firstapple_pcie_link_pwren()call then comes from the noirq resume, throughapple_pcie_hib_port_up()(pcie-apple.c:10170, 10191). There,device_link_add()reorders the host and its children to the tail ofdpm_listin 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.
|
J414s ( 1. Merge tree on current
|
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:Why: PWREN on J516s is an SMC GPIO (
&smc_gpio 19).gpio_device_find()hands out agpio_deviceas soon asdevice_add()has added its kobject (device_is_registered()), butdevice_add()only puts it on the PM list a few steps later (device_pm_add()), anddevice_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'sFirst 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 thegpio_deviceyet, and on the fixed J516s boot the host reaches neithermacsmc-gpionor itsgpiochipover child or consumer links, sodevice_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 agpio_deviceresumes 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 tomacsmc-gpio(port00'spwren-gpios). It adds the stateless flag and a reference, and once the host binds, a plain stateless link is left, whichdpm_wait_for_suppliers()waits on. On J516ssupplier:platform:macsmc-gpiois 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 maind6e13deca924with this commit's blob (pcie-apple.chas 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 tomacsmc-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_noirqis off there).Not yet
require_last_push_approval).