Skip to content

Suspend on 2016-2017 MacBook Pros: keep USB-C and Thunderbolt working across S3 - #11570

Open
bjhinkle wants to merge 7 commits into
omacom:quattrofrom
bjhinkle:t1-suspend-hooks
Open

bjhinkle wants to merge 7 commits into
omacom:quattrofrom
bjhinkle:t1-suspend-hooks

Conversation

@bjhinkle

@bjhinkle bjhinkle commented Sep 12, 2026 •

Copy link
Copy Markdown

Summary

This adds one systemd-sleep hook. With it, a 2017 13-inch MacBook Pro (MacBookPro14,2, Apple T1) suspends to S3 and comes back with USB-C and Thunderbolt working, which it does not do with the stock setup. The measurements below come from that machine: about twenty suspend cycles on 2026-09-05, normal use through three kernel changes, and a run of the current code from 2026-10-18 to 2026-10-20. The hook installs on the 2016-2017 MacBook Pros (MacBookPro13,x and 14,x). A MacBookPro14,1 and a MacBookPro14,3 have since been tested with it (see the paragraphs below).

Environment for the 2026-09-05 measurements: Omarchy 4.0.2, kernel 7.1.9-arch1-2, Mac firmware 529.140.2.0.0, this repository at 8e479f0 (unmodified), snd_hda_macbookpro at ef27884. The same machine has since run Omarchy 4.0.4 on linux-omarchy 7.2.5-3 (from 2026-09-17) and Omarchy 4.0.5 and 4.0.6 on linux-omarchy 7.2.8-9 (from 2026-10-18). See How this was tested.

Earlier versions of this PR also carried a Wi-Fi hook, brcmfmac-reload. It was removed in 0123087. Only one Wi-Fi fix should land, the reviews pick #7333, and unloading brcmfmac goes through the same driver teardown where a P2P interface race has caused kernel oopses (a driver fix is on its way upstream, per the #7333 thread).

Changes after the review

  • 5884ffa: pre stops any retry unit left from the previous resume before it removes anything. The hook acts only when the sleep is S3 (deep), and post acts only if pre did. The mounted-device check also covers active swap. The migration installs the hook unconditionally.
  • 0123087: removes brcmfmac-reload (see above).
  • 7e6ef5c (pushed by omarchybot, from Greptile's review): the mount guard also checks every member of a mounted multi-device btrfs.
  • 936d96b: the hook works out the state systemd-sleep will write to /sys/power/state and acts only when it is mem with mem_sleep at deep, so SuspendState=freeze no longer looks like S3.
  • 3aab5a0, after the 14,2 run below: pre waits only for the root ports of the sides it removed, since the root port of a side kept for a mount may never runtime-suspend and waiting on it cost 5 s. post and the retry unit count the tree as back at the model's xHCI count less one for each kept side.

The problem: Thunderbolt and USB-C are dead after suspend

The platform firmware removes power from the Alpine Ridge controllers in S3 regardless of what the kernel asks. On resume the bridges come back with collapsed windows, the kernel cannot re-allocate them at runtime ("can't assign; no space"), pciehp removes both Thunderbolt-side xHCI controllers, and USB-C is gone until a power cycle. The Touch Bar, keyboard, audio and camera survive because the T1 sits on the chipset's own xHCI.

On the 14,2 this is not limited to short or lid-open sleeps. Without the hook, from a fresh boot with the USB-C ports empty, a 23-minute lid-closed sleep lost both sides, and so did a lid-open sleep that woke after 3 s. In the three runs without the hook, resume also froze for 80 to 104 s while the PM core timed out on the dead bridges, against 12 to 13 ms with the hook. On a 14,3 without this hook, angellindo saw Thunderbolt survive long lid-closed sleeps with the ports empty (3 of 3), so the models may differ.

Things that do not help, all measured: d3cold_allowed=0 on every device in the tree (the ports failed from D3hot, not D3cold), pcie_port_pm=off, pcie_ports=compat, forcing the root ports to D0 and rescanning, and evaluating the firmware's own power-on methods with acpi_call (the GPIO pads read the same on a dead side and a live side, and the rails belong to the platform).

What does help: remove the two Thunderbolt upstream ports (03:00.0 and 79:00.0, the children of root ports 00:1c.4 and 00:1d.0) cleanly before sleep, and rescan after resume. The chipset root ports never lose their windows, so the rescan re-enumerates the whole tree with fresh assignment. thunderbolt-remove-rescan does that, plus:

  • it acts only when the sleep is S3: systemd-sleep must be about to write mem to /sys/power/state (the first SuspendState= entry the kernel supports), and /sys/power/mem_sleep must select deep. post acts only if pre did. The power loss it works around is an S3 behavior, so in s2idle, however it is selected, the hook stands down instead of dropping attached devices on every sleep.
  • before anything else, pre stops any retry unit still running from the previous resume, so a late retry cannot rescan the tree back in after pre removes it.
  • it runs sync first and skips a side if a mounted filesystem, any member of a mounted multi-device btrfs, or active swap is reached through it (a USB-C disk would otherwise be torn before the kernel's suspend sync).
  • it disables S3 wake on the PCIe root ports. They share one wake line, nothing on them needs to wake a laptop, and runtime hot-plug is unaffected.
  • it waits for the root ports of the sides it removed to runtime-suspend (typically a few milliseconds, capped at 5 s). A side kept for a mount is not waited on, because its root port may never suspend with a device in use under it.
  • after resume it rescans once. If the tree is not back within 2 s, it hands retries to a transient unit with systemd-run --collect, because post hooks run while user.slice is still frozen and a plain backgrounded subshell is killed with the hook. "Back" means the model's count of xHCI controllers (2 on the two-port 13,1 and 14,1, 3 on the four-port models), less one for each side kept for a mount.
  • every path exits 0, so it can never block a suspend.

Measured behavior with the hook installed (MacBookPro14,2, kernel 7.1.9, before the 5884ffa changes):

  • Sleeps of about 80 s or more: the full tree is back on the first rescan (32 PCI functions, six USB root hubs, three xHCI controllers, links at 8 GT/s). A tree that was live at sleep entry came back after 47 s.
  • Sleeps of about 7 s or less: the tree is dead afterwards, and comes back on the next sleep of a few minutes (one side after about 80 s, both after about six minutes, with 362 s the shortest measured for both). A reboot is never needed. USB-C still works at USB 2.0 through the chipset controller in the meantime, so a short sleep costs SuperSpeed and Thunderbolt, not the ports.
  • The tree comes back on new bus numbers below the upstream ports (the two xHCI controllers moved from 06:00.0 and 7c:00.0 to 2c:00.0 and a2:00.0, the same numbers on every cycle). Nothing may key on addresses below 03:00.0 or 79:00.0.

On a MacBookPro14,1 (one JHL6540), stefanoverna ran the hooks as they were at 89fe6bf, plus a local fix for the xHCI count. Before them every lid close ended in a black screen that needed a power-button hold. With them, lid-close sleeps of about two minutes resume cleanly with the tree back on the first rescan. A 15 s sleep there also came back complete, so the short-sleep limit above has not been seen on the 14,1. spamnbeans reported the same resume hang on another 14,1 and reached the same Thunderbolt fix independently. The 14,1's full tree has two xHCI controllers rather than three, which is why the count is per model (3c960e4, after stefanoverna's run).

On a MacBookPro14,3, makoni ran this head (936d96b) for 12 S3 cycles on linux-omarchy 7.2.5-3, on battery with nothing in the ports. Every cycle brought the tree back on the first rescan, with 3 xHCI controllers, 37 PCI functions and both links at 8 GT/s. The hook found the 14,3's upstream ports (04:00.0 and 7a:00.0, under the CPU root ports 00:01.1 and 00:01.2) with no address in the code. Three of the 12 cycles ran the hook unchanged, and the other nine varied its wake handling or ran it on a patched kernel. That machine also carried a local amdgpu quirk so that S3 resumes at all, and power/control=on on every PCIe port, which made the settle wait run to its 5 s cap on each cycle. makoni's first report of Wi-Fi loss with the hook was later corrected: on battery the BCM43602 loses power in S3 with or without the hook, and makoni has sent a brcmfmac fix for that to linux-wireless.

Known limits

  • A device left in a USB-C port during S3 loses that side. orospakr found this on a 14,1 (Suspend/resume support for vintage MacBook Pro 13" 2017 (MacBookPro14,1): default deep sleep breaks Thunderbolt on resume — working s2idle enablement, patches forthcoming #10593), where the root port stayed disabled until a cold boot. The four-port models do it too: on a 14,3 without this hook, angellindo lost the side holding an unmounted USB 3 stick after long lid-closed sleeps (2 of 2, once with the device deauthorized in software first), and simbilim's own remove-and-rescan helper lost the controller on a 13,3 with a USB Ethernet adapter attached. On the 14,2 this hook removes that side's upstream port before sleep, and the side is still lost (two different sticks). What the hook changes there: the empty side survives, the device keeps working at USB 2.0 through the chipset controller, resume does not freeze, and the lost side came back with the next long sleep once the port was empty (one run). Without the hook, the same test lost both sides and the stick entirely. Fix Thunderbolt suspend on the MacBookPro14,1 #10758 avoids the 14,1 case by defaulting the 14,1 to s2idle, and this hook does nothing in s2idle, so the two do not collide.
  • A side kept in place for a mounted filesystem or active swap does not survive S3 either. On the 14,2 it was lost in both runs with a mounted USB stick, the mount went with it, and resume froze for about 100 s, as long as with no hook. So the guard keeps the disk attached until the kernel's own suspend sync, at the cost of that freeze. The side came back with the next long sleep once the stick was unplugged (one run).
  • Not covered: hibernate and suspend-then-hibernate, external displays over USB-C across a sleep, and Thunderbolt PCIe devices. Omarchy does not configure suspend-then-hibernate, but upower's default critical-battery action requests it. On the 14,2 at 2 % battery, the first of those sleeps went into S3 with the hook standing down, left both sides dead and froze resume for 102 s. Each of those sleeps also woke within 4 s with the lid open, so the hibernate step never ran and the battery ran flat. Setting CriticalPowerAction=PowerOff in upower makes it shut down instead.
  • On the 15-inch 14,3, the Radeon drives the internal panel, and on the current Omarchy kernel niconistal and linux-omarchy: MacBookPro14,3 backlight, BCM43602 D0, Thunderbolt and fan s2idle fixes omarchy-pkgs#596 each report S3 resume failing in amdgpu (SMU load firmware failed, -22) with the panel left black. That failure is in the graphics driver, not Thunderbolt, so this hook cannot help with it. Sleep in s2idle on the MacBookPro14,3 #14692 (draft) would move the 14,3 to s2idle, and this hook does nothing in s2idle, so the two do not collide. darrellgum's 14,3 in the next item gets past the amdgpu failure on a kernel that also carries two mainline amdgpu commits for that Radeon variant (a5be7ad8f5f0, a22e5e4f2ebb). makoni's 14,3 run above used a local amdgpu quirk for its Radeon Pro 560, since superseded by Maciej Kucharek's series on amd-gfx, which is not in a kernel release yet. The 13,3 has the same Radeon-on-panel design, and simbilim runs S3 on one with the Radeon powered off and their own remove-and-rescan helper. Nobody has posted a run of this hook on a 13,3.
  • darrellgum reports that a kernel carrying Francisco Beltrán Millalén's unmerged PCI/PM and Alpine Ridge patches resumes a 14,3 from S3 with Thunderbolt intact and no hook. The two have not been run together. Once those patches are in the Omarchy kernel, this hook should be re-checked against them and probably retired.
  • On a 13,3, simbilim found that S3 on a USB-C charger ended within about 4 s when a remove-and-rescan helper of their own removed Thunderbolt first (2 of 2 lid-closed sleeps), and held when their module kept the bridges in D0 instead. On the 14,2 this hook's removal on the charger did not do that: the first lid-closed S3 after a fresh boot held in 4 of 4 runs.

Things to expect

Lid-closed sleeps sometimes wake on their own a few seconds in and then re-suspend: at 6 to 8 s on 7.1.9 (4 of 8 hands-off lid closes on 2026-09-05), once at 13 s in the first lid close on 7.2.5, and at 3.2 and 3.6 s in 2 of 12 lid-closed sleeps on 7.2.8. That short sleep leaves the tree dead as above until the next long sleep. On 7.1.9 every wake source the kernel can see was ruled out with controls (GPE counters, wakeup sources, the PM1 status register, the raw GPE0 block), so the cause looks firmware-side.

With the lid open, early wakes are more common: on 7.2.8 a systemctl suspend woke after 2.7 to 4.4 s on three of four boots on the 14,2, with and without the hook, and angellindo saw the same on a 14,3 in 9 of 9 cycles. For a long sleep, close the lid.

A USB device plugged into a USB-C port is not detected while the Alpine Ridge xHCIs (8086:15d4) are runtime-suspended, with or without this hook, including on a fresh boot before any sleep. Setting their power/control to on makes the device appear at once, and angellindo's udev rule keeps it there.

One more scope note: this is for the keyboard-mode Touch Bar stack (apple-ib-tb lineage). The t1bridge display-mode stack replaces those drivers and lists sleep/wake as not working. This hook may still apply there since it touches Thunderbolt, not the T1, but that is untested.

Files

  • default/systemd/system-sleep/thunderbolt-remove-rescan: the hook, beside the packaged keyboard-backlight, force-igpu and unmount-fuse. Root-owned 0755, every path exits 0, and it acts only on a suspend into S3.
  • install/hardware/apple/fix-t1-suspend.sh: installs it when product_name matches MacBookPro13,[123] or MacBookPro14,[123] (all six 2016-2017 models), wired into install/hardware/all.sh after fix-brcmfmac-supplicant.sh.
  • migrations/1789242220.sh: the same for existing installs. It installs unconditionally, so a copy the user carries is also reset to root:root 0755. Nothing to restart, since the hook takes effect at the next suspend.

The hook finds the upstream ports from the NHIs bound to the thunderbolt driver (NHI, downstream port, upstream port), so no PCI addresses are hard-coded. Its only model-specific value is the xHCI count that marks the tree as back. Delete the file to undo.

How this was tested

Hands-off cycles with an RTC alarm as the only wake (echo $(( $(date +%s) + 100 )) > /sys/class/rtc/rtc0/wakealarm; systemctl suspend), with the tree counted before and after by ls /sys/bus/pci/devices | wc -l, ls -d /sys/bus/usb/devices/usb*, and ls /sys/bus/pci/drivers/xhci_hcd, and the journal grepped for can't assign, Unable to change power state and Host halt failed. Then five real lid-close cycles, then daily use. Anyone reproducing this should touch nothing for the first ten seconds of a lid-open sleep, because an early wake strands the tree.

The hook then ran unchanged on the 14,2 through three kernel changes: 7.2.3-arch1-3 from 2026-09-12, linux-omarchy 7.2.5-3 (Omarchy 4.0.4, 2026-09-17) and linux-omarchy 7.2.8-9 (Omarchy 4.0.5, 2026-10-18). On 7.2.5, one lid close held both cases: a 13 s self-wake left the tree dead, and the 46-minute sleep that followed brought the full tree back on the first rescan. On 7.2.8, an 11.5-minute lid-closed sleep with no self-wake brought the full tree back on the first rescan.

The changes after 3c960e4 were first checked off the hardware (syntax, the gating and retry-stop paths against stubbed sysfs and a stubbed systemd config, and omarchybot's VM runs), then on hardware in makoni's 14,3 cycles above and in a 14,2 run at 936d96b and 3aab5a0 from 2026-10-18 to 2026-10-20 (results). That run covered long and short sleeps, s2idle, the retry stop, a device left in a port and a mounted disk with and without the hook, and the lid-closed and lid-open controls without it, mostly one run per case.

🤖 Generated with Claude Code

…cBook Pros

Two system-sleep hooks for the Apple T1 generation (MacBookPro13,x and 14,x),
installed at setup time and by a migration for existing installs:

- brcmfmac-reload unloads the BCM43602 driver before sleep and reloads it after,
  so every resume takes the firmware-reload path instead of the hot-resume path
  that leaves Wi-Fi down with dead firmware about half the time.
- thunderbolt-remove-rescan removes the Thunderbolt upstream ports cleanly before
  sleep and rescans the PCI bus after resume. The platform firmware powers the
  Alpine Ridge controllers off in S3 regardless of the kernel's requests, and
  after a dirty loss the kernel cannot re-allocate the bridge windows, which
  leaves USB-C dead until a power cycle. With a clean removal the chipset root
  ports keep their windows and the rescan re-enumerates the whole tree.

Both measured on a MacBookPro14,2 (Omarchy 4.0.2 and 4.0.3, kernel 7.1.9) over
about thirty suspend cycles. Limits that are the platform's, not the hooks':
a sleep of a few seconds leaves the Thunderbolt tree dead until the next sleep
of a few minutes, and the tree returns on new bus numbers below the upstream
ports. The hooks never block sleep and act on plain suspend only.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@angellindo

Copy link
Copy Markdown

MacBookPro14,3 hardware follow-up — 2026-09-19

Additional observations from the dual-GPU MacBookPro14,3 may help research alongside the MacBookPro14,2 results here. The local trials below used related, guarded experiments, not this PR's exact hooks; they do not establish a regression in this PR or successful S3 support on 14,3. Reliable low-power platform suspend remains unresolved. The related T1 driver and earlier hardware results are documented in my comment on the package PR.

Environment: Omarchy 4.0.4-1, kernel 7.2.5-3-omarchy, firmware 529.140.2.0.0; i7-7820HQ, Intel HD 630 plus Radeon Polaris 1002:67ef / subsystem 106b:0179, BCM43602 14e4:43ba, Alpine Ridge Thunderbolt. Local T1 package 0.1.r2.ga33c7eb-2, based on monomyth/t1-touchbar@a33c7eb, with skip_acpi_power=1. This is one machine. The baseline kernel already has out-of-tree/unsigned modules (taint 12288).

Topology on the tested boot: Radeon 01:00.0, Samsung NVMe 02:00.0, Wi-Fi 03:00.0 behind 00:1c.0; Thunderbolt upstream branches 04:00.0 and 7a:00.0 behind 00:01.1/00:01.2. These are observations, not portable addresses for a script. An older local “NVMe” service incorrectly targeted the Radeon; it was removed, without resolving package idle or S3 recovery.

New findings that may save other researchers time:

  1. Readable Wi-Fi PCI registers do not establish recovered firmware. Preventing D3cold on the BCM43602 and its root port can restore PCI access while brcmf_msgbuf_query_dcmd still times out and NetworkManager cannot initialize the interface. PCI inventory and successful pre/post hooks were insufficient success criteria.

  2. Repeated Wi-Fi module teardown has a separate crash path. The second awake unload with P2P enabled produced an Oops in _cfg80211_unregister_wdev, called through brcmf_p2p_ifp_removed, during module removal; the fault involved 0xdead000000000122. This identifies the observed failure path, not its underlying corruption source. Adding P2P disable to the existing feature mask (0x82000 → 0x82010) and rebooting removed P2P from supported interface modes. Two subsequent awake unload/reload cycles passed, including reconnect and HTTPS 200, with no new Oops/taint. This is a limited mitigation, not proof of reliable recovery from suspended or already-wedged firmware.

  3. A successful PM rehearsal did not predict actual S3 recovery. A local combination of no-P2P Wi-Fi unload/reprobe, temporary Wi-Fi endpoint/root-port D3cold protection, removal/rescan of empty Thunderbolt branches, and a scoped Radeon reset bypass passed pm_test=platform: GPU/device recovery, HTTPS and cleanup succeeded. The otherwise corresponding real S3 test failed. Actual low-level firmware resume occurred after approximately 3.32 seconds of sleep, despite a 45-second RTC target, followed by approximately 19.63 seconds of awake transitions. Radeon reported:

    amdgpu: SMU load firmware failed
    amdgpu 0000:01:00.0: PM: failed to resume async: error -22
    

    Thunderbolt did not re-enumerate; fresh BCM43602 firmware initialization was logged, but connection/HTTPS recovery failed amid the GPU/platform failure. The very short S3 interval is a confounder for Thunderbolt recovery. This was not a verbatim test of Suspend on 2016-2017 MacBook Pros: keep USB-C and Thunderbolt working across S3 #11570.

  4. Skipping the pre-S3 Radeon reset was insufficient. A temporary, model/PCI-ID-restricted kretprobe forced amdgpu_acpi_should_gpu_reset() false only for the S3 target. The failing real S3 run recorded seen=1, overridden=1, missed=0; the SMU failure preceded the later recovery reset. The bypass was removed. This rules out that single bypass as a sufficient fix; it does not establish the complete GPU failure mechanism.

  5. Changing CPU profiles works, but did not unlock deeper package idle. EPP changed from performance to power; measured PC6–PC10 residency remained zero. MSR 0xE2 = 0x40000008 was read as unlimited/unlocked for this CPU, so no speculative MSR writes were made. Forced ASPM/powersave/powersupersave did not establish deeper package residency and were reverted. PMC LTR reads were all 0xffffffff; they are not usable evidence for choosing an LTR blocker or an LTR_IGNORE write.

  6. Sleep selection and consumption need separate verification. This installation's SuspendState=freeze selects s2idle despite [deep] appearing in /sys/power/mem_sleep. An actual five-minute s2idle test accumulated no PC6–PC10 time, lost Wi-Fi/Thunderbolt, and the owner observed fans and keyboard lighting throughout. Its approximately 7.23 W battery estimate covers the whole 394.54-second measurement interval, including 92.60 seconds awake/transitions; it is not a pure-sleep power measurement. A separate awake CPU/GPU comparison showed roughly 8.24→4.80 W CPU package draw under power-saver and 13.09→8.19 W Radeon draw under forced-low policy. Those policies were restored, and neither result demonstrates suspend power. Purported screen-off samples were rejected because recorded DPMS state remained on.

Firmware leads, still hypotheses: locally disassembled ACPI exposes _S3; FADT does not advertise low-power S0 idle. _PTS has different S3 GPIO/EC preparation under !OSDW(). _WAK gates the Thunderbolt PEG1/PEG2.ICMB() calls and Wi-Fi RP01/ARPT wake notifications behind that same non-Darwin branch. These are concrete code paths to investigate, not proof they cause the failures. A global acpi_osi=!Darwin experiment was retired after two reported keyboard failures at login after boot, before session start; captured fallback boots lacked the override, so causality and execution of the intended test path are unconfirmed. It is not a recommended workaround. The desktop lock screen was unaffected; an unrelated lock-focus experiment was reverted.

Useful next work: isolate Radeon SMU/firmware restoration across actual S3; explain the unexpectedly early wake; then validate Wi-Fi reprobe plus PCI protection across real sleep, with empty Thunderbolt branches and repeated successful recovery. Inspect the ACPI branch differences without assuming a global OS override is safe. Intel/GMUX is another unvalidated route: the internal panel currently works through AMD while i915 fails eDP link initialization; do not assume merely detecting the Intel GPU makes it a working alternative.

For comparisons on this model, record actual suspend entry/exit, real firmware resume versus pm_test, elapsed sleep versus transition time, fresh network traffic, complete NHI/xHCI rediscovery and functional USB, and measured battery draw. PM: suspend exit, a visible Wi-Fi interface, cached PCI D3hot, or a working Touch Bar alone does not establish successful platform recovery. The local guarded experiments refused attached external devices and used explicit preparation/cleanup checks; none of these experimental sleep changes has been enabled as a permanent fix. No firmware, unique machine identifiers or raw desktop logs accompany this update.

@spamnbeans

Copy link
Copy Markdown

MacBookPro14,1 (2017 13", no Touch Bar, single JHL6540): confirmed, and here it presents as a resume hang, not just dead USB-C

Independently arrived at the same remove-before-sleep / rescan-after-resume fix on a MacBookPro14,1 before finding this PR. Data in case it helps get it merged — the 14,1 is in your MacBookPro14,[123] gate and needs it.

Symptom on 14,1 (Omarchy 4.0.4, kernel 7.2.5-3-omarchy, deep): close lid → PM: suspend entry (deep) is the last journal line, black screen on lid open, power-button hold to recover. Every single suspend, not after a loop of cycles. s2idle behaves the same.

Why it looks like a hard hang. Bisected with /sys/power/pm_test + pm_print_times=1. At pm_test=processors (no firmware S3 involved at all) the machine does come back, but noirq resume takes 77 s:

[  656.228] PM: suspend entry (deep)
[  656.891] pcieport 0000:05:00.0: Unable to change power state from D0 to D3hot, device inaccessible   <- TB tree already gone at suspend_noirq
[  656.891] pcieport 0000:05:02.0: Unable to change power state from D0 to D3hot, device inaccessible
[  656.894] pcieport 0000:04:00.0: Unable to change power state from D0 to D3hot, device inaccessible
[  668.140] pcieport 0000:04:00.0: PM: pci_pm_resume_noirq returned 0 after 6038889 usecs
[  668.141] pcieport 0000:05:0[124].0: Unable to change power state from D3cold to D0, device inaccessible
[  669.308] thunderbolt 0000:06:00.0: not ready 1023ms after resume; giving up
[  673.255] tb_cfg_read: -108   (WARNING drivers/thunderbolt/ctl.c:1131, tb_switch_reset <- tb_resume_noirq)  x6
[  673.262] thunderbolt 0000:06:00.0: PM: pci_pm_resume_noirq returned 0 after 3953488 usecs
[  738.555] xhci_hcd 0000:07:00.0: not ready 65535ms after resume; giving up
[  738.556] pcieport 0000:05:02.0: PM: pci_pm_resume_noirq returned 0 after 70416423 usecs
[  739.716] PM: noirq resume of devices complete after 77617.658 msecs

A second run stalled 35 s in 04:00.0 pci_pm_resume_noirq. With a real S3 in between, the screen stays black for well over a minute, and everyone (me included) hard-reboots long before suspend exit would have been logged. So on this model the same root cause you describe is a de-facto unusable suspend, which is probably why 14,1 owners report "never resumes" rather than "USB-C dead".

With the hook (my minimal version: echo 1 > 0000:04:00.0/remove + root-port power/wakeup=disabled in pre, echo 1 > 0000:00:1c.4/rescan in post): pm_test=processors round trip 7 s, noirq resume 35 ms; rtcwake -m mem -s 30 and real lid-close suspends resume in ~2 s. The TB tree re-enumerates fine on rescan (xhci comes back on a new bus number, 2d:00.0, as you note). Half a dozen cycles so far, including short sleeps.

Two other data points:

  • The brcmfmac-reload half was not needed on the 14,1 (BCM4350, not BCM43602): with only the Thunderbolt hook installed, Wi-Fi reconnects on its own ~5 s after wake.
  • Careful with hook placement when testing: systemd 261 on Omarchy only executes /usr/lib/systemd/system-sleep/; /etc/systemd/system-sleep/ is silently ignored. Lost an afternoon to that. Your installer already uses /usr/lib, so that's fine.

Will also report the kernel side (thunderbolt/PCI PM spending 70 s on a controller the platform has powered off) to the upstream thunderbolt maintainers.

Attachments (full dmesg of the boot + stall run with pm_print_times, lspci -nnvv of the TB tree, the hook): https://gist.github.com/spamnbeans/819fde7de388f7899d5c11a149685aa6

@spamnbeans

Copy link
Copy Markdown

MacBookPro14,1 follow-up: retracting "brcmfmac-reload not needed" — it is, and the failure mode on the BCM4350 is worse than a driver reload can fix

Correction to my comment above. After a few more hours with only the Thunderbolt hook installed, the 14,1's BCM4350 hit exactly the failure this PR's brcmfmac-reload guards against, and it took a full power-off to recover. Both hooks belong in the MacBookPro14,[123] gate.

What happened. Four deep-sleep cycles resumed cleanly with Wi-Fi reconnecting on its own. The fifth entered S3 and woke back out immediately — Preparing to enter system sleep state S3 to Low-level resume complete is ~3 ms apart in the log, suspend entry to suspend exit under 4 s. brcmfmac took its hot-resume path on a chip whose firmware had been interrupted mid-D3, and it never answered again:

17:28:15.035  PM: suspend entry (deep)
17:28:18.202  ACPI: PM: Preparing to enter system sleep state S3
17:28:18.205  ACPI: PM: Low-level resume complete
17:28:18.925  PM: suspend exit
17:28:21.000  ieee80211 phy4: brcmf_msgbuf_query_dcmd: Timeout on response for query command
17:28:21.000  ieee80211 phy4: brcmf_cfg80211_get_channel: chanspec failed (-5)
   ...every command from here on, forever...
18:12:44.964  ieee80211 phy4: brcmf_run_escan: error (-12)
18:12:44.964  ieee80211 phy4: brcmf_cfg80211_scan: scan error (-12)

Scanning and connecting were dead for the rest of the session. Every subsequent suspend then failed as well, because the driver could not put the dead chip into D3 (brcmf_pcie_pm_enter_D3: Timeout → PM: Some devices failed to suspend → systemd falls back to s2idle → same failure → Failed to put system to sleep). So on the 14,1 a wedged Wi-Fi chip also takes suspend down with it.

Why a driver reload alone would not have recovered it. On the 14,1 the chip went fully off the PCIe bus, not just "registers readable, firmware dead" as you describe for the 43602 on the 14,2. modprobe -r brcmfmac; modprobe brcmfmac and even a warm reboot both failed to probe:

brcmfmac: brcmf_chip_recognition: MMIO read failed: 0xffffffff
brcmfmac: brcmf_pcie_probe: failed 14e4:43a3

Only a shutdown with the charger unplugged brought it back. So brcmfmac-reload is needed here as prevention — unload before sleep so the chip gets a clean firmware shutdown and never sits in the half-D3 state that the early wake catches it in — rather than as recovery.

Suggested addition to the hook: drop the Wi-Fi root port as an S3 wake source. Out of the box the BCM4350's root port is armed:

$ grep RP09 /proc/acpi/wakeup
RP09	  S3	*enabled   pci:0000:00:1d.0

Nothing on Omarchy configures Wake-on-WLAN, so this wake source does no useful work, and a PME glitch from a card mid-power-transition is a plausible source of the instant wake that started all this (I could not prove the wake reason from the log, so treat this as a hypothesis). One line in pre covers it: echo disabled > /sys/bus/pci/devices/<wifi root port>/power/wakeup — the same thing thunderbolt-remove-rescan already does for the Alpine Ridge port. The root port can be found generically from the brcmfmac device's parent (readlink -f /sys/bus/pci/drivers/brcmfmac/0000:*/..).

With the reload + wakeup-disable hook in place (minimal version below, same shape as yours): a 97 s deep sleep, driver deregistered before suspend entry, firmware re-downloaded after suspend exit, NetworkManager reassociated within a couple of seconds. Will report back if the early wake recurs.

RP=/sys/bus/pci/devices/0000:00:1d.0   # RP09, WiFi root port on 14,1
case "$1" in
  pre)  echo disabled > $RP/power/wakeup; modprobe -r brcmfmac_wcc brcmfmac ;;
  post) modprobe brcmfmac ;;
esac

Full filtered journal of the failed boot (the successful cycles, the early-wake cycle, the cascade of failed suspends, the failed probe after warm reboot, the clean probe after the cold boot) added to the gist: https://gist.github.com/spamnbeans/819fde7de388f7899d5c11a149685aa6 — wifi-bcm4350-early-wake-wedge.txt.

@angellindo

Copy link
Copy Markdown

The MacBookPro14,3 driver patches are not in this pull request. The systemd-sleep hooks here (brcmfmac-reload and thunderbolt-remove-rescan) are a different change, reported for S3. They were not tested on this machine, and this comment does not claim they work here.

Untested packaging proposal (not compiled, not runtime-tested): omacom/omarchy-pkgs#596

Ordered status on this MacBookPro14,3 (kernel 7.2.5-3-omarchy, s2idle). Nothing below is a verified fix:

  1. Package C-states: not fixed. The package stays in PC3. PC6–PC10 were not entered. PC6 is not fixed.
  2. Fans: not fixed. No applesmc patch. The floor is SMC firmware (2160 and 2000 rpm). This boot logged kbd=0, so LKSB is absent. Writing 0 is not a valid off command.
  3. Keyboard backlight: not verified. The proposal only calls applespi_set_bl_level(&applespi->backlight_info, 0) from applespi_suspend() before applespi_drain_writes(). Not compiled and not runtime-tested. A userspace write of 0 did not turn the lamp off.
  4. Wi-Fi BCM43602 14e4:43ba subsystem 106b:0173: not verified. The proposal only calls pci_save_state() on the successful return of brcmf_pcie_pm_enter_D3() for that PCI ID. Not compiled and not runtime-tested. The helper module was built and was not loaded.
  5. Thunderbolt RTPC: not a fix and not included. Loading it left the Thunderbolt hosts and xHCI unreachable. Do not reload it.
  6. This PR (Suspend on 2016-2017 MacBook Pros: keep USB-C and Thunderbolt working across S3 #11570): different change (userspace sleep hooks). Not a package C-state fix and not these driver patches. Not tested here.

@bjhinkle

Copy link
Copy Markdown
Author

@spamnbeans thanks for the 14,1 data, and for following up with the correction. The 77 s noirq resume under pm_test probably explains why 14,1 owners report a hang rather than dead USB-C. The BCM4350 wedge also makes a better case for unloading before sleep than the 14,2 does: on the 14,2 a reload after the fact recovers the chip, and on your machine only a full power-off did.

On the wake source: the PR already does this, in the Thunderbolt hook rather than the Wi-Fi one. Before every plain suspend, thunderbolt-remove-rescan sets power/wakeup to disabled on every PCIe root port on bus 0, not only the Alpine Ridge one, so on your 14,1 it covers 00:1d.0 too. The minimal Thunderbolt hook in your gist disables 00:1c.4 only, so if that was the hook in place on September 20, RP09 was still enabled as a wake source during the early wake. With the PR's two hooks installed it would not have been.

For comparison, the 6 to 8 s lid-closed self-wakes described in the PR keep happening on the 14,2 with S3 wake disabled on all four root ports, so there the root ports are not what wakes it. Your wake came about 3 ms after entering S3, which looks like a different event, so I can't say from the 14,2 whether RP09 caused it.

One question, if you have the data: how short were your short sleeps, and did USB-C come back at full speed after them? On the 14,2 a sleep of a few seconds leaves the Thunderbolt tree dead until a later, longer sleep. In your early-wake log 00:1c.4 comes back from D3cold inaccessible right after the early wake, which may be the same limit, but the excerpt is filtered, so I can't tell whether the tree came back.

I'm leaving the PR as it is for now, since both hooks already install on the 14,1 through the MacBookPro14,[123] match.

@angellindo

angellindo commented Sep 22, 2026 •

Copy link
Copy Markdown

MacBookPro14,3 reference (kernel 7.2.5-3-omarchy, s2idle). Not a test of the hooks in this PR. A loaded local module is not a result for the package in omarchy-pkgs#596.

Reported on this thread for other machines. Not retested here:

  • 14,1 tester: Thunderbolt remove-before-sleep / rescan-after-resume. On the cycles they ran, about 77 s of noirq resume became about 2 s. BCM4350: unload brcmfmac before sleep. After that chip wedges, reload and a warm reboot still fail with MMIO 0xffffffff. A shutdown with the charger unplugged recovered it.
  • 14,2 author: reloading brcmfmac after wake recovers that chip. The PR disables S3 wakeup on every bus-0 root port. That did not stop the 14,2 lid self-wake at 6–8 s. A sleep of a few seconds can leave the Thunderbolt tree dead until a longer sleep.

Shown on this 14,3:

  • Keyboard lamp, awake, closed. Writing 0 to spi::kbd_backlight turned the lamp off. Seen on the keys. sysfs read 255, then 0 for about 45 s, then 255. In the v7.2.5 source that store is applespi_set_bl_level. The earlier comment that said this write did not turn the lamp off is superseded.
  • A local out-of-tree applespi is loaded (srcversion 91015AB907CB9AF22D03B53, updates/applespi.ko.zst). Its applespi_suspend calls applespi_set_bl_level(..., 0) before applespi_drain_writes. That callback has not run on a suspend. The stock file is kept as applespi.ko.zst.bak-pre-bl. This is the same source change as patch 0752 in omarchy-pkgs#596. That package has not been built or booted.
  • Earlier awake package RAPL: about 8.24 W down to about 4.80 W on power-saver. That did not open PC6.

Still open on this 14,3:

  • Lamp during sleep. On an earlier s2idle the userspace hook wrote 0 and the lamp stayed on. Stock applespi_suspend does not send the off packet. That does not by itself prove the hook write was lost. The loaded module has not been through a suspend, so the keys staying dark and the keyboard working after wake are still untested.
  • Package residency. Awake, with the Thunderbolt tree present, PC6–PC10 stayed 0 while cores entered CC6/CC7. One s2idle figure of about 99.55% in PC3 came from a run that removed the Thunderbolt trees and blocked Wi-Fi D3cold first. It is not a stock-sleep number. Profiles and pcie_aspm=force (those links reached L0s, not L1) did not open PC6. An RTPC module got success from RTPC(0) and RTPC(1) and left the NHI and xHCI unreachable. Stock Thunderbolt is restored (818021460DA57E63C550EC2). RTPC is not a fix.
  • Wi-Fi BCM43602 14e4:43ba subsystem 106b:0173, two different results. Blocking D3cold once left PCI readable while brcmf_msgbuf_query_dcmd still timed out. A later s2idle, including one with no RTPC, resumed with MMIO 0xffffffff and probe -19. A reboot recovered that one. An awake brcmfmac unload oopsed, so the 14,2 reload-after-wake report is not shown here. Patch 0663 in omarchy-pkgs#596 calls pci_save_state() for this PCI ID only. The separate helper .ko is built and not loaded. Neither has a suspend result.
  • Fans were seen on during s2idle. The journal has no rpm sample for that interval. applesmc has resume and restore only, no .suspend. The SMC floor read back as 2160 and 2000 rpm. No off command was found. This boot logged kbd=0, so LKSB is absent.
  • SuspendState=freeze selects s2idle. An earlier real S3 failed in amdgpu SMU (-22) before a clean platform resume. The remove/rescan and brcmfmac-reload hooks were not installed here.

PC6, the fans, and the lamp are outside what those systemd hooks change. Nothing above says the hooks fix or break this 14,3.

@angellindo

Copy link
Copy Markdown

MacBookPro14,3 update, 2026-09-23 (kernel 7.2.5-3-omarchy, s2idle). This replaces parts of my previous comment. Still not a test of the hooks in this PR.

Thunderbolt: cause confirmed on 14,3, and a kernel-side alternative.

  • The first s2idle after every boot loses both Alpine Ridge domains. At suspend the switch ports are already inaccessible when the PCI core moves them to D3hot. On resume the NHI and xHCI are not ready and tb_cfg fails with -108. This is the mechanism @orospakr described for 14,1 in #9899: tb_lc_set_sleep() sets the LC sleep bit on the host router.
  • Skipping that call in s2idle kept Thunderbolt alive over six sleeps in one boot, with no inaccessible port and no -108. It was tested as a kprobe on the stock module. The same change is patch 0664 in omarchy-pkgs#596. It does not unload thunderbolt or remove the tree.
  • Only the first sleep after a boot is a valid Thunderbolt test. After one failure, every later sleep in that boot enters with -108 already, before any fix gets a chance to run. Three of my earlier "failed" alternatives were run on an already-broken chip. This may also explain the "dead until a later, longer sleep" reports here.
  • Resume is still slow with the skip: about 17.5 s of noirq resume. pci_pm_resume_noirq takes 11.5 s on 04:00.0 and 12.6 s on 7a:00.0, and about 5.5 s on each NHI. @spamnbeans's 6 s and 35 s on 04:00.0 look like the same thing. omarchy-pkgs#544 (ACPICA) is the likely cause. Not tested here yet.

Wi-Fi BCM43602. The brcmfmac module built with patch 0663 has four checked s2idle cycles. None had MMIO read failed or probe -19, and each ended with HTTPS 200. The earlier "no suspend result" is superseded.

Keyboard backlight, correction. The 0752 I described before, applespi_set_bl_level(..., 0) in applespi_suspend(), was wrong. It leaves want_bl_level at 0, so the lamp stays off after wake unless userspace writes the level again. A sleep that skipped the hooks showed this. The corrected patch sends the off packet in its own drain and then restores the level. A trace over s2idle shows the off packet sent and the level restored after resume. The PR was updated in 4b4b0d3.

Two test-method notes.

  • Suspending by writing freeze to /sys/power/state woke here within 0.1 s on an ACPI GPE (IRQ 9). systemctl suspend did not. Record which path a test used.
  • Timestamps in the journal are buffered during s2idle. Use Timekeeping suspended for and /sys/power/pm_print_times for real sleep and resume times.

Still open here: package PC6, fans during sleep, and the resume latency above. Nothing in this comment says the hooks in this PR fix or break this 14,3.

@angellindo

Copy link
Copy Markdown

MacBookPro14,3 update, 2026-09-24 (kernel 7.2.5-3-omarchy, s2idle). This follows my comment from 2026-09-23. It is still not a test of the hooks in this PR.

The 14,3 now suspends and resumes with Wi-Fi, Thunderbolt, the keyboard light, fans and audio working. That needs the fixes below; none of them are systemd-sleep hooks. The patches and test data are in omarchy-pkgs#596.

Problem on the 14,3 Fix State
Wi-Fi BCM43602 gone after sleep (MMIO read failed, -19) 0663 in #596: keep the chip in D0 Works. 31 sleeps on 2026-09-24 without a failure. The stock driver still fails, and reloading the module doesn't recover it.
Both Thunderbolt domains lost on the first sleep (-108) 0664 in #596: skip tb_lc_set_sleep() on the host router in s2idle Works. No -108 in 32 sleeps across 10 boots.
17.8 s of noirq resume once Thunderbolt survives ACPICA 0771 from omarchy-pkgs#544 Tested as a local kretprobe equivalent. 0.53 s, including the first sleep after boot. The firmware was polling 00:00.0 offset 0x530 300,000 times.
Keyboard light stays on in sleep 0752 v2 in #596 Works.
Fans at minimum rpm in sleep 0753 in #596 Works. 0 rpm asleep, back to normal within 10 s of wake.
Woke by itself 12–141 s after sleeping udev rule: power/wakeup=disabled on the T1 (05ac:8600, GPE 0x6D) 4 of 4 five-minute sleeps reached the RTC alarm. Keyboard and trackpad still wake it over SPI.
No sound from speakers or internal mic out-of-tree snd_hda_macbookpro (CS8409) via DKMS Works, including after resume.

Dependencies. 0771 only shows its effect once 0664 keeps Thunderbolt alive. 0753 only matters once sleeps last, which needs the T1 rule. 0663 is independent.

Limits found.

  • PC6 is never reached. PC6–PC10 stay at 0. I ruled out each of these: display off, Radeon off, Thunderbolt removed, the T1 port off, radios off, LTR_IGNORE on every PCH agent, NVMe APST, intel_iommu=igfx_off, acpi_osi=Darwin, and Wi-Fi in D3. What is left is the firmware's CPU power setup. The platform draws roughly 7–13 W in s2idle, so the machine stays warm.
  • S3 is not an option here. The Radeon SMU fails S3 resume with -22.
  • Only the first sleep after a boot tells you anything about Thunderbolt. After one failure, every later sleep in that boot starts broken.
  • Intel GPU mode. With gpu-power-prefs=1 the Intel drives the panel. External monitors then work only if connected after login, and they need the fix for Multi-GPU: Secondary AMD GPU output fails with "destination dmabuf unsupported" (external-only) when primary GPU is different AMD card hyprwm/aquamarine#220. With a monitor connected at boot, the firmware starts on the Radeon and the panel stays dark. Switching back with vga_switcheroo powers off the Radeon, and the next boots came up dark until an NVRAM reset. I went back to factory mode, where the Radeon drives everything.
  • Not tested. I have not slept with a Thunderbolt or USB-C device connected, and have not built a linux-omarchy package. All results are from local modules on the stock kernel.

@stefanoverna

Copy link
Copy Markdown
Contributor

MacBookPro14,1 (A1708, single JHL6540): this PR's exact hooks tested, one fix for the xHCI count, and a third hook for Bluetooth LE devices

Omarchy 4.0.4, kernel 7.2.5-3-omarchy, mem_sleep deep, both hooks installed verbatim from this PR (not a minimal variant). Before them the 14,1 behaved as @spamnbeans describes: every lid close ended at PM: suspend entry (deep), black screen, power-button hold. pm_test walked freezer/devices fine and froze at platform. With the hooks, real lid-close suspends of about two minutes resume cleanly, several cycles today:

thunderbolt-remove-rescan: pre/suspend: removed 0000:04:00.0 (under 0000:00:1c.4)
thunderbolt-remove-rescan: pre/suspend: removed 1 upstream port(s), skipped 0; xhci=1 pci=19 links: 0000:00:1c.4=8.0 GT/s PCIe
thunderbolt-remove-rescan: pre/suspend: settled in 9 ms
brcmfmac-reload: pre/suspend: unloaded brcmfmac_wcc brcmfmac
PM: suspend entry (deep) ... PM: suspend exit                       (1 min 50 s later)
thunderbolt-remove-rescan: post/suspend: tree back after attempt 1 (~0 ms): xhci=2 pci=26 links: 0000:00:1c.4=8.0 GT/s PCIe
brcmfmac-reload: post/suspend: reloaded, wlp2s0 present after 0s

1. The xHCI count is hard-coded for the 14,2. post waits for xhci >= 3. The 14,1 has one Alpine Ridge, so the full tree is 2 xHCI controllers (chipset + JHL6540): the condition never holds, post logs attempt 1 short after 2 s ... retrying, the transient unit rescans six more times (12 s of extra rescans on every resume), and it ends with WARNING tree NOT back after 6 attempts: xhci=2 ... while USB-C is in fact back. Fix: record the count in pre, before the removal, and expect that same count in post. Keeps 3 as the default when the state file is missing:

 STATE=/run/thunderbolt-remove-rescan.roots
+# xHCI controllers expected once the tree is back: the count before removal
+# (3 on two-controller models like the 14,2; 2 on the single-controller 14,1).
+XHCI_STATE=/run/thunderbolt-remove-rescan.xhci
+XHCI_WANT=$(cat "$XHCI_STATE" 2>/dev/null || echo 3)
@@ pre)
     sync
+    xhci >"$XHCI_STATE"
     thunderbolt_ports >"$STATE"
@@ post) / retry)
-    (( $(xhci) >= 3 ))          (three places)
+    (( $(xhci) >= XHCI_WANT ))

With this the 14,1 logs tree back after attempt 1 (~0 ms) on every resume (log above). Full patch and file: https://gist.github.com/stefanoverna/6efd79f09f351555efdc45e4a988cb2f.

2. Bluetooth LE devices do not come back on their own (BCM4350 Bluetooth half, hci_uart / btbcm, the same chip brcmfmac-reload deals with). After every resume a paired LE mouse (MX Master 3S) stays disconnected: the controller drops the mouse's reconnect advertisements (Bluetooth: hci0: unknown advertising packet type: 0x11 / 0x13, 24 of them today), and bluetoothd's own background reconnect gets stuck in InProgress. A host-side bluetoothctl connect <mac>, retried, works within 3-20 s. A third hook in the same shape as yours does that: pre saves the trusted device list, post starts a transient unit that waits for the controller to be powered again and retries the connect for each device, logging every attempt:

bluetooth-reconnect: pre/suspend: will reconnect: DA:ED:39:68:3F:F1
bluetooth-reconnect: controller powered after 0s
bluetooth-reconnect: DA:ED:39:68:3F:F1 attempt 1: Failed to connect: org.bluez.Error.InProgress In Progress
bluetooth-reconnect: DA:ED:39:68:3F:F1 connected (attempt 2)

It is in the same gist. Whether it belongs in this PR or in a follow-up is your call; it fits the MacBookPro14,[123] gate, and the 14,2 has the same Bluetooth chip.

3. A note on the short-sleep question. Not measured here yet: every real cycle so far was 1.5 to 2.5 minutes, and all came back on the first rescan. Happy to run a series of 5-10 s sleeps if useful.

@stefanoverna

Copy link
Copy Markdown
Contributor

Follow-up on the short-sleep question, MacBookPro14,1 with this PR's hooks (plus the xHCI-count fix above): a 15 s deep sleep (PM: suspend entry (deep) 13:08:59, PM: suspend exit 13:09:14, lid closed and reopened) came back complete on the first rescan:

thunderbolt-remove-rescan: pre/suspend: removed 1 upstream port(s), skipped 0; xhci=1 pci=19 links: 0000:00:1c.4=8.0 GT/s PCIe
thunderbolt-remove-rescan: pre/suspend: settled in 8 ms
thunderbolt-remove-rescan: post/suspend: tree back after attempt 1 (~0 ms): xhci=2 pci=26 links: 0000:00:1c.4=8.0 GT/s PCIe
brcmfmac-reload: post/suspend: reloaded, wlp2s0 present after 0s

So on the single-controller 14,1 a sleep of seconds does not leave the Thunderbolt tree dead, unlike the 14,2 behaviour you describe. USB-C and Wi-Fi were usable right after resume.

@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Sep 27, 2026
thunderbolt-remove-rescan counted the Thunderbolt tree as back once three
xHCI controllers were bound. That is the four-port models' number: the
chipset's controller plus one per Alpine Ridge. The two-port 13,1 and 14,1
have one Alpine Ridge, so a full tree there has two, the check never
passed, and every resume ran the retry unit for about 12 s and ended with
a false "tree NOT back" warning while USB-C worked. Reported and measured
on a MacBookPro14,1 by stefanoverna on the pull request.

The expected count now comes from the model: 2 on the 13,1 and 14,1, 3 on
the others. It is not the count at sleep entry, because a short sleep can
leave the tree dead going into the next one: 34 of the 65 sleeps in a
MacBookPro14,2's hook log started with both sides dead, and a count taken
then would report a dead tree as back and skip the retries. The comparison
stays >=, so an extra controller from a dock does not matter. Behaviour on
the four-port models is unchanged.

The installer comment no longer calls every covered model a Touch Bar
machine with a BCM43602, and the migration banner drops "Touch Bar", since
the gate also covers the 13,1 and 14,1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bjhinkle

Copy link
Copy Markdown
Author

@stefanoverna thanks for testing the hooks exactly as they are in the PR, on a second model, and for tracking down the xHCI count. You're right: >= 3 is the 14,2's number, and the gate also matches the two-port 13,1 and 14,1, which have one Alpine Ridge controller and so two xHCI controllers in a full tree. On those models every resume goes through the retry unit and ends with a false warning.

Recording the count in pre has one problem on the four-port models, though. On the 14,2 a sleep of a few seconds can leave one or both Thunderbolt sides dead, and the lid-closed self-wakes described in the PR are that short. The next pre then records 1 or 2, so post logs the tree as back straight away and skips the retries while USB-C is still at USB 2.0. It isn't a rare case: 34 of the 65 sleeps in this machine's hook log started with both sides already dead (removed 0 upstream port(s), xhci=1). Instead, the check now uses a fixed count by model: 2 on the 13,1 and 14,1, and 3 on the other four. The comparison stays >=, so an extra controller from a dock doesn't matter. That's pushed as 3c960e4. A resume on your 14,1 should now log tree back after attempt 1 with xhci=2 and start no retry unit.

Thanks for the 15 s run as well. On the 14,2 a 13 s sleep left the whole tree dead, so the 14,1 doesn't seem to share that limit. The second Alpine Ridge controller is one difference that might explain it, but that's a guess. If you do run the 5 to 10 s series, it would show whether the 14,1 has any lower limit at all, but it isn't needed for this PR.

On the Bluetooth hook, I'd keep it out of this PR and suggest a separate one from you. One correction on the chip: the 14,2's Wi-Fi chip, the BCM43602, has no Bluetooth, and the Bluetooth there is a separate BCM20703A2 on the UART. So the 14,2 can't check a fix for the BCM4350's Bluetooth half, and LE reconnect across sleep hasn't been tried on it. A separate PR with your 14,1 logs would be easier to review, and it keeps this one to Wi-Fi and USB-C.

@angellindo, on your note that only the first sleep after a boot is a valid Thunderbolt test: on the 14,2 in deep sleep with this hook, a later sleep does bring a dead tree back within the same boot. In one lid close, a 13 s self-wake left the tree dead, and the 46 minute sleep that followed brought it back on the first rescan. So the short-sleep limit in the PR doesn't look like the first-sleep effect you describe, though that may well be what you're seeing in s2idle on the 14,3.

@bjhinkle bjhinkle changed the title Suspend on MacBookPro14,2: keep Wi-Fi and USB-C working across S3 (two systemd-sleep hooks) Suspend on 2016-2017 MacBook Pros: keep Wi-Fi and USB-C working across S3 (two systemd-sleep hooks) Sep 29, 2026
@rand0mdud3

Copy link
Copy Markdown

Suspend-hook review from the 11,5 Wi-Fi trenches (BCM43602, same chip): brcmfmac-reload is missing the two hardening lessons from #10332, and I believe both will bite here:

  1. Interface-down before unload. Plain modprobe -r loses a race with NetworkManager mid-teardown and fails silently; the hook then records failed and the resume path this PR exists to fix never happens. Fix: ip link set $iface down (+ small retry) before modprobe -r. (Not nmcli disconnect — that blocks autoconnect.)
  2. Firmware-health gate. If the firmware is already timing out pre-sleep, unloading walks into a GPF in cfg80211 unregister (brcmf_pcie_remove → use-after-free on a dead address), segfaulting modprobe and wedging wpa_supplicant into unkillable D-state — worse than leaving the driver loaded. Suggest checking for recent brcmf_msgbuf_query_dcmd: Timeout in the journal in pre and standing down when the firmware is already flaking.

The state tracking + post-fallback + never-blocks-sleep design is good. My hardened v2 with both changes runs live across lid cycles on 11,5 — happy to help converge the two hooks.

@orospakr

orospakr commented Sep 30, 2026 •

Copy link
Copy Markdown

Three notes from the MacBookPro14,1 side (I wrote the competing omarchy#10758 / omarchy-pkgs#349).

1. A 14,1 S3 hazard this PR's gate walks into. From omarchy#10593: on the 14,1, if anything is physically present in a Thunderbolt port when the machine enters S3, Apple's EFI S3 resume script function-disables root port RP05 (00:1c.4) about 4–6 ms after wake, before the kernel runs, and only a cold boot brings the port back. Reproduced 8/8; 11 OS-side countermeasures were eliminated one at a time (wake-source disarming, D-state pinning, driver unbinding, link forcing, PD-controller mailbox commands, ...).

The MacBookPro14,[123] gate installs the S3 hooks on the 14,1, and the PR body lists USB-C displays and Thunderbolt PCIe devices across a sleep as not covered. @stefanoverna, @spamnbeans: has either of you closed the lid on deep with something plugged in? If your units behave the same, deep on the 14,1 is only safe with empty ports, which is why omarchy#10758 defaults the 14,1 to s2idle. The two PRs need reconciling for the 14,1 rather than both landing. I'm open to either outcome, e.g. these hooks for 14,2/14,3 and s2idle plus the shim for 14,1, or a lid-close policy that picks deep only when the ports are empty (hypothesis, untested).

2. Interaction with tb_ar_shim if both merge. The shim (omarchy-pkgs#349) grafts a dev_pm_domain onto the 04:00.0 upstream bridge's pci_dev once at module init and holds a reference to it. thunderbolt-remove-rescan removes 04:00.0 before every plain suspend, so from the first hook-driven suspend onward the re-enumerated bridge has no pm_domain and the shim is inert. Harmless, and redundant with the hooks anyway.

3. BCM4350 fails in s2idle too. Kernel 7.2.5-3-omarchy, stock brcmfmac, firmware brcmfmac4350c2-pcie 7.35.180.133, no sleep hooks. A full-length RTC-timed 180 s s2idle (PM: suspend entry 21:57:24.9 → PM: suspend exit 22:00:24.3, not an early wake) came back with Wi-Fi dead: brcmf_msgbuf_process_ring_status: Firmware reported ring 0 error: 3 22 ms after suspend exit, then every brcmf_msgbuf_query_dcmd timed out and NetworkManager never got a supplicant interface back. PCI was intact (no MMIO read failed: 0xffffffff, no D-state errors), so this is the "registers readable, firmware dead" variant from Problem 1, not @spamnbeans' off-the-bus one; a warm reboot recovered it.

It was the first failure in 8 s2idle cycles that boot; the other 7 (lid or keyboard wakes, 1 min to 22 h) reconnected on their own. The only known difference is the wake source (RTC vs lid), which is a hypothesis, not a finding. So the 14,1 needs brcmfmac-reload in s2idle as well as S3: if 14,1 policy ends up as s2idle, that hook should still install. @rand0mdud3's two hardening points (interface down before unload; stand down if the firmware is already timing out) look relevant to this failure mode.

@angellindo, I've answered your ACPICA question on omarchy-pkgs#349 rather than here.

🤖 Generated with Claude Code

@rand0mdud3

Copy link
Copy Markdown

Confirming from the 11,5 side that the hardening covers your note-3 failure mode. "Registers readable, firmware dead" (ring error, then every query_dcmd timing out) is exactly the case the firmware-health gate exists for: unloading brcmfmac while the firmware is already timing out walks into the GPF-in-unregister → unkillable D-state wedge from #10332, which is worse than leaving the driver loaded. And the iface-down ordering covers the NM-teardown race on the reload path regardless of sleep mode. So yes — if 14,1 policy lands on s2idle, brcmfmac-reload should still install, hardened.

Our datapoint for the matrix: 11,5 (BCM43602, different chip from your 4350) suspends to deep (mem_sleep default here) with the hardened v2 hook (iface-down, health gate, retry, logging) installed since Sep 11, and Wi-Fi survives deep cycles. So hook+hardening-on-deep is confirmed working on a second chip; your s2idle-also-needs-reload finding is new data I can't confirm or deny — we don't run s2idle here.

On notes 1–2: nothing to add from 11,5. Ours are Thunderbolt 2 ports with no peripherals to test against, a different generation from the RP05 hazard, and the 14,1 reconciliation (hooks vs shim vs s2idle-default) is for the PR authors. One interaction worth keeping explicit as that decision lands: your own note 3 means s2idle-default does not remove the need for the reload hook on the 14,1.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 3c960e4 by Claude Opus 5.5, with Codex Medium as a second opinion. Both read the diff against quattro. Codex also read the three oldest competing pull requests. Its findings below were checked against the source before being included, and where it agrees with my reading, that agreement may not be independent.

What ran. On a disposable Omarchy VM (not a Mac): ./test/cli, plus unowned-system-paths-test.sh, system-sleep-ownership-migration-test.sh and brcmfmac-supplicant-test.sh. All passed. All four new scripts parse. On a machine outside the gate, the install script and the migration install nothing, and thunderbolt-remove-rescan pre hibernate exits 0 without acting. A VM has no Alpine Ridge and no Broadcom Wi-Fi, so the fix itself is unproven here. It rests on the hardware reports in this thread, and none of them is from a maintainer at this head. stefanoverna's 14,1 run was 89fe6bf with their own count patch, not 3c960e4.

Findings, most significant first:

  • thunderbolt-remove-rescan:149: the retry unit keeps rescanning /sys/bus/pci for about 12 s after resume, and pre neither stops it nor waits for it. If the lid closes again inside that window, which is the self-wake case the description mentions, a retry rescan can re-enumerate a tree that the new pre has just removed. That tree then goes into S3 live, which is the original failure. Stopping any thunderbolt-remove-rescan-retry-* unit at the top of pre would close the race.
  • brcmfmac-reload:28 and :46: when pre records absent, post still runs modprobe brcmfmac and then waits up to 20 s for an interface. On the VM, pre suspend followed by post suspend loaded a driver that had not been loaded before and logged WARNING reloaded but no brcmfmac interface after 20s. On a gated Mac running broadcom-wl instead of brcmfmac (Quattro upgrade leaves legacy broadcom-wl-dkms installed on BCM4350 Macs, disabling brcmfmac #8810), or one where the user has removed brcmfmac, every resume does the same. post should only reload what pre unloaded.
  • thunderbolt-remove-rescan:98: the hook checks the sleep operation, not the sleep state. Under s2idle it still removes and rescans the Thunderbolt tree, so attached USB-C devices and displays drop and re-enumerate on every sleep. The S3 power loss this works around does not happen there. That matters for the 14,1 if Fix Thunderbolt suspend on the MacBookPro14,1 #10758's s2idle default lands. In the other direction, suspend-then-hibernate passes that name as $2, so its suspend phase gets no protection. Omarchy does not configure that mode by default.
  • thunderbolt-remove-rescan:122: S3 wake is disabled on every PCIe root port on bus 0, not just the Thunderbolt parents, and is not restored until reboot. The header explains why, so this is a scope note for the maintainer rather than a defect.
  • thunderbolt-remove-rescan, mounted_under: the guard reads /proc/mounts, which does not list swap. A swap partition on a USB-C disk would be removed with its controller. This is an edge case.
  • migrations/1789242220.sh:14: an existing hook is kept if its contents match, whatever its owner or mode. 1788662350.sh exists because hooks in this directory have been user-owned before. Installing unconditionally costs nothing and removes the check.

The concerns rand0mdud3 raised (bring the interface down before modprobe -r, and stand down when the firmware is already timing out) are reasonable hardening for the reload path, but neither was reproduced here. #11377 is the report behind the second one.

Competing pull requests. Several other open pull requests change the same behaviour on the same machines:

Systemd runs every hook in system-sleep at the same time, so two Wi-Fi reload hooks on one machine would race. Only one of them should land. Among the Thunderbolt pull requests, both reviewers prefer this one's remove-and-rescan approach: it finds the ports from the bound NHIs instead of fixed addresses and needs no out-of-tree module. For Wi-Fi, Codex preferred #10332's narrower PCI-ID gate. This pull request's coverage of the BCM4350 on the 13,1 and 14,1 is backed by spamnbeans' and orospakr's reports. Which of these should land is the maintainer's decision.

What happens next. This waits on the author for the first two findings, and on the maintainer to choose among the competing fixes. Because the bug only shows on hardware a VM cannot provide, it cannot be marked verified until it has been confirmed on a gated Mac at the final head.

@dreinecke

Copy link
Copy Markdown

Data from another MacBookPro14,2 (firmware 529.140.2.0.0, linux-omarchy 7.2.15-1, this hook at 3aab5a0, T1Bridge 0.1.12). On battery, lid-closed S3 holds (2 of 2, three minutes each), with the full tree back on the first rescan. On the charger it never holds, including the first lid close after a fresh boot: 21 sleeps in four lid closes on 2 and 3 November ended by themselves after 6 to 18 s, and logind re-suspended each time, with the battery charging or full. pm_wakeup_irq is empty, no wakeup source counts up, and GPE 0x32/0x33 rise by one per sleep, as on nonderbe's 14,2 (olofd/omarchy-macbookpro-a1706#1). Your first lid-closed S3 on the charger held 4 of 4. Which charger and port were you on, and was anything else different, such as the T1 drivers or the T1's USB wake (ours is disabled during sleep)?

@bjhinkle

bjhinkle commented Nov 3, 2026

Copy link
Copy Markdown
Author

Charger: a 250 W Anker USB-C charger, always in the left rear port (nearest the hinge). The T1 runs the keyboard-mode stack (apple_ibridge, apple_ib_tb and apple_ib_als DKMS from nohzafk/omarchy-macbookpro-t1, USB configuration 1), with no T1Bridge. The T1's USB wake stays enabled: power/wakeup on 1-3 (05ac:8600) reads enabled, XHC1 is armed for S3 in /proc/acpi/wakeup, and nothing changes either during sleep. Firmware is 529.140.2.0.0 here too.

Later in a boot, a close here can still wake once or twice after 3 to 5 s before a sleep holds. Today on the charger, one close woke after 5 s and then held 4 min 37 s on the next sleep. Closes here have always settled into a held sleep within about two minutes, so T1Bridge and the T1's USB wake are the two differences I can see.

@makoni

makoni commented Nov 3, 2026

Copy link
Copy Markdown

@dreinecke, on the T1Bridge difference @bjhinkle points to: one concrete thing that changes with it is whether the T1 is told the host is going to sleep.

On my 14,3, GPE 0x33 belongs to the T1: in the SSDT, the T1's ACPI device ASOC has two children with wake GPEs, PNIC on 0x33 and WDOG on 0x31 (going by the names, panic and watchdog; _L33 and _L31 are empty). I haven't seen a 14,2's tables. If yours match, a 0x33 count that rises by one per sleep means the T1 raises that line once per cycle. That fits the T1 waking the Mac, but the counter can't tell whether it fired before the wake or in reaction to it. My tables have no handler for 0x32 (gpe32 reads invalid here), so I can't say what it is.

From reading the macOS kext, macOS evaluates ASOC.SOCW(0) before sleep ("host sleep" to the T1 through the EC mailbox) and SOCW(1) after wake. The legacy apple_ibridge driver that @bjhinkle runs does the same in its suspend and resume callbacks. T1Bridge 0.1.12 doesn't, so the T1 goes into sleep without being told. I've opened standardagents/t1bridge#58, which adds that pair to appletbdrm. Until something like that lands, a sleep hook can send the same pair:

#!/bin/sh
# /usr/lib/systemd/system-sleep/t1-socw-sleep
case "$1/${SYSTEMD_SLEEP_ACTION:-$2}" in
	pre/suspend) v=0x0 ;;
	post/suspend) v=0x1 ;;
	*) exit 0 ;;
esac
modprobe acpi_call 2>/dev/null || exit 0
printf '%s %s' '\_SB.PCI0.XHC1.RHUB.ASOC.SOCW' "$v" > /proc/acpi/call
logger -t t1-socw-sleep "$1: SOCW($v): $(tr -d '\0' < /proc/acpi/call)"

It needs acpi_call-dkms, the file has to be executable, and systemd only runs these from /usr/lib/systemd/system-sleep/. On a 14,2, cat /sys/bus/acpi/devices/APP7777:00/path should print \_SB_.PCI0.XHC1.RHUB.ASOC; if it doesn't, adjust the path. 0x0 in the log means the T1 acknowledged.

Don't send SOCW(0) and SOCW(1) by hand on an awake machine: doing that with no sleep in between left my Touch Bar dark until a full power-off. A suspend that aborts before the machine actually sleeps would send the same pair; that hasn't happened here. From a sleep hook it has been fine, but only before s2idle so far. I haven't sent SOCW(0) before an S3 sleep yet, and #58 is also tested only with s2idle.

If the T1 is the cause, then with the hook in place a lid-closed sleep on the charger should hold, and /sys/firmware/acpi/interrupts/gpe33 should stop rising. macOS also turns the T1's USB remote wake off for sleep, so your setting matches macOS there.

This is only a guess. It doesn't explain why your sleeps hold on battery. And on my 14,3, with T1Bridge and without SOCW(0), every S3 sleep I ran on the charger in October held: lid closes of about 10 minutes, 47 s and 32 s, each until I opened the lid, and RTC-timed sleeps of 60 and 90 s. I didn't watch the GPE counters then. Here PNIC and WDOG are disabled in /proc/acpi/wakeup and gpe33 reads 0 disabled, so on this machine the T1 couldn't wake the host through 0x33, and the counter couldn't move even if it raised the line. If PNIC shows enabled on yours, that alone could explain the difference, and echo PNIC | sudo tee /proc/acpi/wakeup (it toggles) is a quicker test than the hook.

@bjhinkle

bjhinkle commented Nov 3, 2026

Copy link
Copy Markdown
Author

@makoni, the 14,2's tables differ from your 14,3 there. ASOC.PNIC is on GPE 0x53 (_PRW 0x53, S4) and WDOG on 0x51 (S3), both disabled in /proc/acpi/wakeup, and gpe51 and gpe53 read 0 disabled. GPE 0x32 and 0x33 are the Thunderbolt hot-plug handlers in the TbtOnPCH SSDT (_L32 for RP05, _L33 for RP09), and both read 17 here after 17 S3 sleeps this boot. So on a 14,2 the one-per-sleep rise @dreinecke sees on 0x32 and 0x33 points to the Thunderbolt side, not the T1.

apple_ibridge, which is bound to the T1's ACPI device (APP7777:00) here, calls SOCW(0) in its suspend callback and SOCW(1) on resume, with no failure logged this boot. With the T1's USB wake disabled (power/wakeup on 1-3 set to disabled, and still disabled after each wake), a lid close on the charger still woke twice, after 6 s and 5 s, and then held for 3 min until I opened the lid. Both wakes had pm_wakeup_irq empty and PM1a_STS at 0. So the T1's USB wake isn't what separates our two machines, which leaves T1Bridge, and with it SOCW(0) before sleep, as the one difference I know of.

@makoni

makoni commented Nov 4, 2026

Copy link
Copy Markdown

@bjhinkle, thanks, that corrects my 14,3 reading for the 14,2. With 0x32 and 0x33 being the Thunderbolt hot-plug handlers on your 14,2, as you found, a one-per-sleep rise on both points to the Thunderbolt side, though the counters alone can't say whether it comes before the wake or after it.

That takes back two things from my previous comment. The PNIC toggle rested on my 14,3 tables, where 0x33 is PNIC; on your 14,2 PNIC is on 0x53 and disabled, and toggling a disabled one would enable it. @dreinecke, unless PNIC shows enabled in /proc/acpi/wakeup on yours, please skip that test. And gpe33 isn't the counter to watch with the hook on a 14,2; what matters is whether a lid-closed sleep on the charger holds.

Your run with the T1's USB wake disabled shows that isn't what separates your machine from @dreinecke's, so the sleep hook is still the test I'd try next. It's still a guess: your machine sends SOCW(0) too and can still wake once or twice before a sleep holds.

@angellindo

Copy link
Copy Markdown

MacBookPro14,3 update, 2026-11-04: S3 with an occupied USB-C port now has a working local kernel configuration in four cycles across two cold boots. This is a kernel-path test report, not validation of the exact sleep hook in this PR, and not a claim that all 13,x/14,x models are fixed.

Artifact and dependencies. My experimental 7.2.8-9.1-omarchy-t106v3 package is based on Omarchy 7.2.8-9. It carries a backport of the Apple/Alpine Ridge SXFP v3, PCI config-accessibility/save-state/link-check prerequisites, and a local adjustment that places NHI preparation in nhi.c, retaining tb->lock through preparation and domain stop. The local ACPICA 0771 equivalent associated with omacom/omarchy-pkgs#544 stayed enabled. Existing T1/SOCW handling was kept. This is therefore not an unmodified upstream v3 or the exact artifact of omacom/omarchy-pkgs#596.

Why the old local workaround matters. With my tb_skip_lc_sleep2/0664 kprobe loaded, two S3 attempts still lost the occupied right-hand branch: PEG2 link width x0, UPSB 7a:00.0 and NHI 7c:00.0 inaccessible, and xHCI 7d:00.0 gone. The slow UPSB callback took about 26.7 s, with six D3hot -> D0 errors and seven kernel WARNING splats. In the instrumented attempt, both NHIs reached the ACPI: calling SXFP callsite before S3; no SXFP failed was reported. That callsite is after a successful return from the bit-26 helper, so the result was not simply an omitted SXFP call. It does not establish hardware readback or the electrical outcome of SXFP.

Blocking only that local module for the trial boot (module_blacklist=tb_skip_lc_sleep2), with the same UKI and the other local modules unchanged, gave:

Cycle/configuration Actual S3, seconds UPSB 04 resume_noirq, seconds UPSB 7a resume_noirq, seconds
First sleep, receiver right 3407.112 0.453384 0.449108
Second sleep, same boot 309.319 0.447785 0.450844
Third sleep, Kingston USB3 left + receiver right 1095.768 0.451198 0.448381
First sleep after another cold boot, Kingston USB3 right + receiver right 315.985 0.450868 0.446772

All four returned with both upstream links at 8 GT/s x4, both NHIs and xHCI controllers present, no device inaccessible or kernel WARNING splats in those captures, and working receiver input confirmed after each resume. All used battery power, lid closure/opening and deep/S3. The durations above are measured Timekeeping suspended for values, not the nominal requested duration. The last run used a new cold boot; the Kingston was initially on the left and moved to the right before its first S3, so I am not claiming it was on the right from power-on.

For the USB3-attached cycles, a Kingston DataTraveler 70 remained connected on the tested side at SuperSpeed 5000 Mbit/s, under 07:00.0 on the left or 7d:00.0 on the right. Two direct 64 MiB reads of the same range before and two after each S3 had identical SHA-256. Device identity and controller ancestry were rechecked. No filesystems were mounted, LUKS unlocked or storage written. The USB2 receiver alone would not prove this: it enumerates through the PCH xHCI.

Remaining observation: 07:00.0 logged xHC error in resume, USBSTS 0x401, Reinit in three of the four successful cycles, but not with the Kingston attached on the left. This is a save/restore-error reinitialization path, not a kernel WARNING splat or the earlier upstream-link loss. The controller remained accessible, and post-resume USB3 reads on it were verified. I do not consider that message fully explained or universally harmless.

The local 0664 module skips tb_lc_set_sleep() during system sleep, changing the sequence after SXFP. These results support investigating that interaction; they do not prove an electrical root cause or an A/B/A causal result. They also do not invalidate #596's current s2idle-only 0609 patch, which does not run in S3. No real Thunderbolt device, hibernation, s2idle or aborted suspend-after-SXFP was tested in this series. Four cycles are limited evidence, not a reliability guarantee. Debug flags were restored after the captures, and stock/default boot configuration was retained.

@bjhinkle

bjhinkle commented Nov 5, 2026

Copy link
Copy Markdown
Author

Data from a MacBookPro14,2 after updating to Omarchy 4.5.0-3 (from 4.0.6), linux-omarchy 7.2.15-1, with this PR's hook at 3aab5a0 and the keyboard-mode T1 drivers (no T1Bridge), charger in.

One lid close on 2026-11-05: the first three deep sleeps ended by themselves after about 6 s each, and each left the Thunderbolt tree down until a longer sleep, which is the known short-sleep behavior on this model. The fourth sleep held for 25 minutes until the lid was opened, and the hook's rescan brought both sides back on its first attempt (3 xHCI controllers, 32 PCI devices). Wi-Fi, audio and the Touch Bar came back as well.

That's the same model, Omarchy release and kernel as hanscnelson's test of the #12211 approach (#12211 (comment)), where the lid-closed cycle cost the Thunderbolt xHCI controllers until a reboot.

Separately, hibernation on this model needs HibernateMode=shutdown. With the default ACPI S4 mode, the Mac woke straight back up with the lid open. With a plain power-off, it stayed off and restored cleanly in three tries. The hook only acts on suspend and the power-off resets the tree, so hibernation doesn't need anything from this PR.

@acmccubbin

Copy link
Copy Markdown

@makoni, follow-up to my RAM note: that turned out to be overheating, since fixed. Here are v3 results on a 13,3 (Omarchy 7.2.15, subsystem 106b:015a), all S3:

  • Driver unloaded/reloaded by the hook, hook only reading chipcontrol: battery, 3 sleeps: 0x00000000 each time and v3 set the bit; 2 clean 5 GHz rejoins, 1 inconclusive on a weak pub AP (-80 dBm). Charger, 1 sleep (~1 h): bit kept (0x01000010), v3 wrote nothing, clean rejoin.
  • Driver left loaded across S3, battery, 3/3: every resume re-probes, v3 logs "setting discrete FEM control mode", 5 GHz back in 4 s, no status 16. A loaded brcmfmac did not block deep sleep.

So with v3 the unload/reload half of the hook isn't needed on this model, at least in these tests. I can't easily send a properly threaded reply to the list from here, so in case it's useful for a v4:

Tested-by: Alex McCubbin [email protected] # MacBookPro13,3

@makoni

makoni commented Nov 10, 2026

Copy link
Copy Markdown

@acmccubbin, thanks, and good to hear the RAM problem was overheating and is fixed. I've forwarded your Tested-by to the v3 thread on linux-wireless with a link to your comment, and Cc'd you there in case you want to confirm it. If a v4 is needed, it will carry the tag.

@bjhinkle

Copy link
Copy Markdown
Author

A note on test hardware: the MacBookPro14,2 I've been testing this on goes back to its owner on 2026-11-12, so I can't retest on it after that. It ran this hook at 3aab5a0 from 2026-10-20 to now, and its results are in this thread.

@omarchybot

Copy link
Copy Markdown
Collaborator

Read the ten comments since the last review against the hook at 3aab5a0, by Claude Opus 5.5 with Codex Medium and muse-wonder (pi, thinking high) as second opinions. The head has not moved, so nothing was rerun.

@dreinecke's 14,2 narrows one claim in the description. It is the first run of this head on a second 14,2. On battery, lid-closed S3 held 2 of 2 with the tree back on the first rescan, which matches @bjhinkle's results. On the charger, none of 21 sleeps held. So the last Known limits bullet, that this hook's removal did not stop a charger S3 from holding on the 14,2 (4 of 4 on @bjhinkle's machine), is true of that machine and not of every 14,2. It does not show that the hook causes the wakes: the two machines run different Touch Bar stacks, and a sleep that ends in 6 to 18 s strands the tree whatever woke it, as the description already says of short sleeps.

The stack difference is stock against a replacement. Omarchy installs macbook12-spi-driver-dkms on these models (install/hardware/apple/fix-spi-keyboard.sh), and Omarchy's build of it includes apple-ibridge, which evaluates SOCW(0) on suspend and SOCW(1) on resume (apple-ibridge.c:855-879 at marc-git/macbook12-spi-driver@807b65b). So @bjhinkle's charger results are on the stack a stock install runs. @dreinecke's T1Bridge 0.1.12, which @makoni says sends no SOCW(0), replaces it, and the description already lists it as untested. Whether the missing SOCW(0) is why that machine wakes is still a guess.

One test would settle whether the hook is involved there. @dreinecke, if you have the time: on the charger, same port, from a fresh boot with nothing else changed, move /usr/lib/systemd/system-sleep/thunderbolt-remove-rescan out of that directory and close the lid, a few times. If lid-closed sleeps then hold for minutes, the hook contributes to the wakes on T1Bridge. If they still end within 6 to 18 s, the hook is not what causes them. One sleep that holds is worth repeating before it counts. Without the hook, USB-C and Thunderbolt can stay down until a power-off, per the description, so put the file back afterwards.

Nothing else here changes the diff. @bjhinkle's run on Omarchy 4.5.0-3 and linux-omarchy 7.2.15-1 brought the full tree back on the first rescan after a 25-minute sleep, so the hook still works on the current kernel. The hibernation note, the brcmfmac v3 results and the Alpine Ridge SXFP v3 kernel report don't touch this diff. That kernel work is the path to retiring this hook that the description already names.

Both second opinions read the comments the same way and named the same test without being given it. Their independence from this session is not guaranteed.

Not marked verified. @bjhinkle's 14,2 went back to its owner on 2026-11-12, so any further run of this head on a 14,2 has to come from someone else. @dreinecke's battery run is at this head, but on a stack Omarchy does not install and with the charger case open, so it does not verify this head on its own. Nothing is required from @bjhinkle, though the charger bullet could mention @dreinecke's result. The maintainer chooses whether to keep the machine-wide xHCI count or take the per-side one, and which sleep mode these Macs default to, between this, #10758, #12211, #14409, #14692 and the opt-in #14894.

@makoni

makoni commented Nov 17, 2026

Copy link
Copy Markdown

One correction to the stack comparison above. The premise is right as far as the source goes: install/hardware/apple/fix-spi-keyboard.sh adds macbook12-spi-driver-dkms, and the package's apple-ibridge.c does send SOCW(0)/SOCW(1). But the package in the omarchy repository (0+git.315-2, marc-git/macbook12-spi-driver@807b65b) no longer builds against 7.2. I built that commit with the package's DKMS make line against the linux-omarchy 7.2.15-1 headers, and none of its four modules compiles:

  • applespi.c: asm/unaligned.h: No such file or directory
  • apple-ibridge.c: the report_fixup callback type no longer matches, and struct acpi_driver has no owner field
  • apple-ib-tb.c and apple-ib-als.c: the platform remove() callback must return void

On my 14,3 the package's DKMS build failed on every kernel after I installed it on 15 September, and I removed it on 2 November; the keyboard there runs on the in-tree applespi. The 7.2.15 tree has no SOCW call, and in the ACPI tables I dumped from my 14,3 SOCW is only defined, never called (I haven't checked a 14,2). So with the shipped kernel and the in-tree applespi, no driver evaluates SOCW(0)/SOCW(1) around sleep. @bjhinkle's apple_ibridge came from the nohzafk/omarchy-macbookpro-t1 DKMS, not from this package. On the SOCW point only, a stock 14,2 looks closer to @dreinecke's T1Bridge setup than to @bjhinkle's.

@omarchybot

Copy link
Copy Markdown
Collaborator

@makoni is right, and the previous comment's paragraph "The stack difference is stock against a replacement" was wrong. Checked by Claude Opus 5.5, with Codex Medium and muse-wonder (pi, thinking high) as second opinions. The head (3aab5a0) has not moved, so nothing was rerun.

What was checked. The omarchy-pkgs recipe for macbook12-spi-driver-dkms pins marc-git/macbook12-spi-driver@807b65b and applies no patches. I read each of its four modules against the linux-omarchy 7.2.14 headers, and each fails on at least one of the errors @makoni named. applespi.c:64 includes asm/unaligned.h, which the 7.2 headers don't have. apple-ibridge.c:425 returns a non-const __u8 * where report_fixup now returns const __u8 *, and apple-ibridge.c:901 sets .owner, which struct acpi_driver no longer has. apple-ib-tb.c:1262 and apple-ib-als.c:648 return int from platform remove(), which now returns void. I did not build it. Both second opinions found the same four errors.

What that changes. On the shipped kernel, a stock install never gets the apple-ibridge that would send SOCW(0)/SOCW(1) around sleep. @bjhinkle's apple_ibridge came from the nohzafk/omarchy-macbookpro-t1 DKMS, as their comment of 3 November says. So the 4 of 4 charger sleeps that held were on a separately installed stack that does send SOCW, not on what a stock 14,2 runs. On the SOCW point alone, a stock 14,2 is closer to @dreinecke's T1Bridge setup. That is not the same stack, and whether a stock 14,2 calls SOCW from anywhere else is unchecked: @makoni's ACPI reading is from a 14,3. Whether the missing SOCW(0) causes the charger wakes is still a guess. @bjhinkle's own GPE readings point at the Thunderbolt handlers, and their machine still woke early with the T1's USB wake disabled.

The diff doesn't change. The hook touches only Thunderbolt removal and the PCI rescan, never the Touch Bar drivers or SOCW. Two things in the description could be updated, by @bjhinkle or whoever carries it forward. The charger bullet in Known limits could say the 4 of 4 were on the nohzafk stack, and add @dreinecke's result: 2 of 2 on battery, 0 of 21 on the charger. And the T1Bridge scope note could mention that @dreinecke has now run it, on battery, at this head.

The test asked of @dreinecke still stands, and it matters more now that their setup is the closer match for stock on SOCW. One correction to how I read the result before: if sleeps on the charger still end within 6 to 18 s with the hook moved out, the hook is not needed for those wakes, which is narrower than "not what causes them". If they hold for minutes, the hook contributes on that setup. Either way, the result is about T1Bridge, not a stock install.

The package that no longer builds is a problem of its own, already reported in #9831 and #10825, with #9880 proposing to stop installing it. It is outside this diff.

Still not marked verified. No one has run this head on a stock 14,2. @bjhinkle's machine is gone, and @dreinecke's run is on T1Bridge with the charger case open. Besides that hardware run, it waits on the maintainer: whether to keep the machine-wide xHCI count or take the per-side one, and which sleep mode these Macs default to, between this, #10758, #12211, #14409, #14692 and the opt-in #14894. Both second opinions came to the same reading. They were asked what @makoni's comment meant without being told my conclusion, but their independence from this session is not guaranteed.

@angellindo

Copy link
Copy Markdown

Physical test of thunderbolt-remove-rescan (3aab5a0) on a MacBookPro14,3 (Omarchy 4.5.0-3, stock 7.2.15-1-omarchy):

I ran the exact unmodified hook from 3aab5a0 (sha256: 3e361ee2…) on the first lid-closed deep S3 after a cold boot on battery with empty USB-C ports. Note on host setup: Intel drives the internal panel (boot_vga=1), /run/systemd/sleep.conf.d/ selects SuspendState=mem / MemorySleepMode=deep, local mbp143-s3-unbind unbinds the Radeon before S3, mbp143-t1-socw sends SOCW(0)/SOCW(1), and local DKMS modules (brcmfmac 0667, acpica_hwpci_bus 0771, tb_skip_lc_sleep2 0664, apple-ib-drv) were loaded.

  • Pre-suspend: the hook removed both Alpine Ridge upstream ports (0000:04:00.0 under 0000:00:01.1, 0000:7a:00.0 under 0000:00:01.2), logged removed 2 upstream port(s), skipped 0; xhci=1 pci=23, disabled power/wakeup on all five 0x0604* root ports (00:01.0, 00:01.1, 00:01.2, 00:1b.0, 00:1c.0), and logged settled in 11 ms.
  • Sleep & resume: lid-closed deep S3 lasted 298.15 s (suspend_stats: 0/0 -> 1/0, battery throughout). On resume, post logged tree back after attempt 1 (~0 ms): xhci=3 pci=37 links: 0000:00:01.1=8.0 GT/s PCIe 0000:00:01.2=8.0 GT/s PCIe.
  • Post-resume state: both upstream bridges (04:00.0, 7a:00.0) and NHIs (06:00.0, 7c:00.0) returned in D0 at 8.0 GT/s x4 with config space accessible; both Alpine Ridge xHCI controllers re-enumerated cleanly onto new buses (07:00.0 -> 2d:00.0 under 00:01.1, 7d:00.0 -> a3:00.0 under 00:01.2, USB buses 3–6 registered, config accessible). No USBSTS 0x401, Reinit, device inaccessible, can't assign, or kernel WARNING splats appeared. Keyboard, trackpad, Touch Bar, Wi-Fi, and speakers all worked after resume.

Context on 7.2.15 without the hook (kernel-path baseline on the same unit, earlier 7.2.8 report):

  • Without this hook, stock 7.2.15-1-omarchy (same local DKMS stack, with a USB2 receiver on the PCH port) lost the right Alpine Ridge branch on first S3 (7a:00.0 and 7c:00.0 inaccessible in D3cold, 7d:00.0 absent, 7 kernel WARNINGs) while the left branch stayed accessible.
  • On the local 7.2.15-1.1-omarchy-mbp143ab kernel (without 0664), toggling only thunderbolt.apple_sxfp in a 1 -> 0 -> 1 cold-boot first-S3 sequence retained all six monitored PCI functions in both =1 runs and lost the right branch (7a/7c D3cold inaccessible, 7d absent) with =0. In a separate =1 cycle (131 s S3), an unmounted Kingston USB3 drive on the left controller returned at 5 Gb/s with all four 16 MiB read-only SHA-256 samples matching before and after; other =1 runs still logged xHCI USBSTS 0x401, Reinit even when both branches returned.

Note on the previously reported XHCI_WANT - skipped check (earlier review / author reply):
In synthetic sysfs fixtures at 3aab5a0 (mounted device-mapper volume on the left, removed right branch absent at post), post logged tree back after attempt 1 with xhci=2 (PCH + kept left xHCI) and scheduled no retries for the missing right xHCI. While our stock no-hook run above had no mounted USB-C disk on the left, it did show that on a 14,3 an unremoved left branch can survive S3 while the right branch is lost, so if the maintainer opts for the per-root-port check, that synthetic fixture provides a clean regression case.

@omarchybot

Copy link
Copy Markdown
Collaborator

Checked the new report against 3aab5a0 by GPT-6 in Codex (high effort), with Opus 5.5 High and muse-wonder via pi (thinking high) as second opinions. No code changed and no tests were rerun in this review; a VM cannot reproduce Alpine Ridge suspend behavior.

@angellindo's report adds one successful cycle of the current hook on a 14,3: after 298 seconds of lid-closed S3 on battery, both NHIs and xHCI controllers returned on the first rescan. The hook's reported hash prefix matches this head. This is evidence for that configured machine. The kernel package was stock, but the sleep configuration, Radeon/SOCW hooks and DKMS modules were local, including a Thunderbolt sleep module. The hooked cycle used empty ports, so it established re-enumeration without testing a USB-C device after resume. It does not settle the stock-system or charger cases.

The reported fixture matches the existing count finding at thunderbolt-remove-rescan:211-219: with one side kept, PCH plus that side's surviving xHCI meets the target of two, suppressing retries for the missing removed side. The separate no-hook run shows an unremoved branch can survive S3 on a 14,3; it does not reproduce the mounted kept-side case end to end. Whether retries would recover the missing side remains unshown. The per-side check remains the maintainer decision @bjhinkle offered to implement if wanted.

Both second opinions agreed with these limits; their independence from this session is not guaranteed. No new code defect was found. Hardware confirmation, the outstanding 14,2 charger comparison, and the maintainer's controller-check and sleep-mode decisions remain open, so this stays waiting on the maintainer without verification.

@mihneadevries

Copy link
Copy Markdown

Data point from a MacBookPro14,3 (Radeon Pro 560, SM961, BCM43602), Omarchy, linux-omarchy 7.2.15-1: on this model the Thunderbolt stall also happens in s2idle, so the hook's S3-only gate leaves 14,3 owners on s2idle (#14692) with a hang.

  • s2idle with the NVMe D3cold fix and brcmfmac unloaded: every suspend looked like a hard hang (journal ends at PM: suspend entry (s2idle), power-button hold needed).
  • pm_test=devices passed; pm_test=platform hung.
  • Removing both upstream ports before sleep (04:00.0, 7a:00.0, the grandparents of the two NHIs) and rescanning 00:01.1 / 00:01.2 after it: pm_test=platform round trip 7 s, then real s2idle (RTC-timed and lid close/open) resumes every time, with all 3 xHCI controllers and 37 PCI functions back.

So for the 14,3 at least, the remove/rescan seems needed whatever the sleep state is. My hook, plus the other fixes this model needed, is at https://github.com/mihneadevries/mbp14-3-linux-sleep-fix.

@omarchybot

Copy link
Copy Markdown
Collaborator

Checked the new s2idle report against 3aab5a0 by GPT-6 in Codex (high effort), with Opus 5.5 High and muse-wonder via pi (thinking high) as second opinions. No code changed or tests were rerun; a worker VM cannot reproduce Alpine Ridge suspend behavior.

@mihneadevries, this adds a possible s2idle limit on the 14,3. At thunderbolt-remove-rescan:144-150, this hook deliberately skips s2idle, so it would not address the stall you reported. #14692 selecting s2idle would not gain Thunderbolt recovery from this hook; that draft already waits on kernel fixes. Your helper also changes Wi-Fi and sends the Touch Bar SOCW pair, and rescans individual root ports rather than using this hook's global rescan. Its success does not verify this head or establish that firmware cuts controller power in s2idle.

To isolate the Thunderbolt change, please give the helper's full commit SHA and an A/B/A comparison with the other settings held fixed: removal off, on, then off again. Include the effective sleep mode, cycle counts and durations, charger/battery and USB-C device state, and the available suspend/resume journal. Your notes say some earlier hangs were stopped after 30–60 seconds, so please distinguish those from a stall that eventually resumes; allow at least three minutes before classifying a run as hung. For real sleep cycles, confirm pm_test was reset to none, as in the kernel debugging guide.

Both second opinions found no new defect established in the promised S3 behavior and agreed that this report does not verify the unchanged head; their independence from this session is not guaranteed. Extending the gate to s2idle remains a maintainer decision alongside #14692. This stays waiting on the maintainer, with hardware verification and the earlier controller-count decision still outstanding.

@mihneadevries

Copy link
Copy Markdown

A/B/A as requested, on the MacBookPro14,3 (linux-omarchy 7.2.15-1). Hook at 8aa3b29b97a8555d95e3a74811981cfb92067224; the test script is tools/tb-abtest.sh.

Each run enters s2idle directly (echo freeze > /sys/power/state) with pm_test=platform, so no systemd-sleep hooks run. The Wi-Fi unload, SOCW pair, pm_async=0, s2idle, charger connected and empty USB-C ports were the same in every run; only the Thunderbolt upstream-port removal changed. pm_test was reset to none after each run.

Run TB removal Result
1 off Never resumed. Journal ends at the brcmfmac unload just before the state write; next boot 3 min 44 s later, machine reset itself
2 on rc=0, 7.1 s round trip (5 s is the pm_test delay), 37 PCI functions and 3 xHCI back
3 off Never resumed; next boot 4 min 47 s later

Both "off" runs went well past 3 minutes, so these are hangs rather than a stall that eventually resumes. Earlier real s2idle cycles with removal on (RTC-timed and lid close/open, pm_test=none) resumed every time.

Limits: this is pm_test=platform, not a firmware sleep, so it shows the hang is in the late/noirq phases with the Alpine Ridge trees present. It doesn't prove the firmware cuts their power in s2idle.

@omarchybot

Copy link
Copy Markdown
Collaborator

Checked the new response and its pinned test script against 3aab5a0 by GPT-6 in Codex (high effort), with Opus 5.5 High and muse-wonder via pi (thinking high) as second opinions. This was a source review; no code changed or tests were rerun on a worker, which lacks Alpine Ridge hardware.

@mihneadevries, the off/on/off result answers the timing question: the two failed runs went beyond three minutes, with a 7.1-second return between them. It strengthens the evidence for the Thunderbolt preparation path on your 14,3. One control remains in the pinned script: the on arm also sets the Thunderbolt root ports' power/wakeup to disabled. Were those values already disabled in all three runs? If they differed, an off run with the same wake settings would separate that change from upstream-port removal.

Your limit on pm_test=platform is right: the kernel returns before s2idle_loop, so this comparison does not establish what happens during actual s2idle or whether firmware cuts controller power. Without the failed run's phase logs it also cannot identify the exact failing callback. The earlier successful real-sleep runs remain separate evidence. This script bypasses systemd-sleep and does not execute this PR's S3-only hook, so it does not verify this head.

Both second opinions found no new defect established in the promised S3 behavior and agreed with these evidence limits; their independence from this session is not guaranteed. Extending this hook to s2idle remains a maintainer decision alongside #14692. The installer also now conflicts with current quattro in install/hardware/all.sh; this stays waiting on the maintainer without verification.

@makoni

makoni commented Nov 22, 2026

Copy link
Copy Markdown

Results from real s2idle cycles on my MacBookPro14,3: whether the remove/rescan matters outside S3, and a problem with USB-C devices plugged in after the wake.

Setup: Omarchy 4.5.0-3, stock linux-omarchy 7.2.15-1, firmware 529.140.2.0.0, Radeon driving the panel, mem_sleep s2idle, pm_async=1, charger connected, NVMe d3cold_allowed=0. Out-of-tree modules, among others: mbp_ec_wake (marks the EC GPE for wake, so the lid wakes it, as in omacom/omarchy-pkgs#2472), appletbdrm with the SOCW pair from standardagents/t1bridge#58, brcmfmac with the FEM patch, t1bridge's modules and acpi_call. As the hook I used only the Thunderbolt part of @mihneadevries' files/90-mbp-sleep: disable wake on 00:01.1/00:01.2 and remove both Alpine Ridge upstream ports in pre, rescan those two root ports in post (no sync, settle wait, retries or mount check, unlike 3aab5a0). Cycles 4–5 ran a version that also saves and restores power/control (restore turned off in cycle 5), see below. No Wi-Fi unload, no SOCW and no pm_async change from the hook. The test disk was a USB 3 SSD (JMicron 152d:0576), not mounted.

cycle removal USB-C pre→post after the wake
1 on nothing 2 min 16 s rescan took 68 ms: 37 PCI functions, 3 xHCI, both NHIs, both root ports at 8.0 GT/s x4
2 on SSD 3 min 35 s rescan took 62 ms, the SSD re-enumerated by itself at 5 Gb/s (uas)
3 off SSD 3 min 50 s about a minute of black screen after the lid opened: both Alpine Ridge xHCIs logged not ready 1023ms ... 65535ms after resume; giving up, plus the same 12 tb_cfg_read/tb_cfg_write: -108 warnings as the first wake of every unhooked boot; both xHCIs removed, SSD gone
4 on, with restore SSD plugged ~25 s after the wake 6 min 24 s rescan took 57 ms; SSD enumerated, but its first reads hung (see below)
5 on, no restore SSD plugged ~25 s after the wake 2 min 27 s rescan took 57 ms; SSD not seen at all

Cycles 1–3 were in one boot, 4 and 5 in the next one, after a full power-off. Root-port wake was the same in cycles 2 and 3: cycle 1's pre set it to disabled and nothing restored it, so the wake setting doesn't explain the difference between them.

Without the removal, the tree is lost in s2idle here too: in all 14 of my boots since early October that had an s2idle (7.2.5–7.2.15, one of them a local test build, no hook), both Alpine Ridge xHCIs were removed on the first wake, with the same 12 tb_cfg warnings and no 65 s wait. I don't know why cycle 3 added the wait. It isn't just the attached SSD: the left xHCI (07:00.0), with nothing on it, waited 65 s too. One difference is that cycle 3 ran on a tree already rebuilt by cycle 2's rescan (bridges at power/control = auto, see below), while those 14 boots slept with the boot-time tree. Unlike @mihneadevries' "off" runs, cycle 3 did come back; his used pm_test=platform, pm_async=0 and a Wi-Fi unload. After cycle 3, removing and rescanning by hand didn't bring the tree back (root ports at 2.5 GT/s, no NHI or xHCI); a full power-off did.

So on this 14,3 the header note in 3aab5a0 ("In s2idle the firmware does not cut the controllers' power, so removing the tree there would only drop attached devices") doesn't match the outcome: attached devices are lost in s2idle anyway. I can't tell from this whether the firmware cuts power. 0609 in omacom/omarchy-pkgs#596 attributes the s2idle failure to the kernel setting LC sleep on the TB3 host router, and skips that in s2idle. I haven't tested that patch.

A device plugged in after the wake. After a fresh boot, all ten Alpine Ridge bridges (04:00.0, 05:0x.0, 7a:00.0, 7b:0x.0) have power/control = on, while the two xHCIs are auto and runtime-suspend. Plugging the SSD in then woke the xHCI and it enumerated, with no reads left pending when I unplugged it. After remove + rescan, the kernel recreates those bridges with auto, the downstream bridges in front of the idle xHCIs runtime-suspend to D3hot, and a device plugged in afterwards produced no USB event at all: the SSD about 25 s after the wake in cycle 5, and a few minutes after the wake in cycle 1. That time, writing on by hand to the two downstream bridges and the two xHCIs made it enumerate straight away. In cycle 4 the hook saved power/control for everything under the two upstream ports before the removal and wrote it back after the rescan (ten bridges back to on). The SSD plugged in after that wake enumerated at 5 Gb/s, but the two reads issued right after it (sectors 2368 and 2816) were still pending 28 s later when I unplugged it (uas_zap_pending, cmd_age=28s). That didn't happen with the fresh-boot plug or in cycle 2. So restoring power/control gets the device enumerated, but I haven't shown the disk is usable after it. I also haven't found why the boot path leaves the bridges at on.

3aab5a0's post does a global rescan and doesn't touch power/control, so I'd expect a device plugged in after an S3 wake to go unseen there too, but I can't check: S3 isn't usable here while the Radeon drives the panel. @angellindo, since you tested the hook in S3 on a 14,3: after a hooked S3, do the Alpine Ridge bridges show auto (grep . /sys/bus/pci/devices/*/power/control lists them all), and does a USB 3 device plugged in about 30 s after the wake show up in lsusb -t? Your earlier cycle covered re-enumeration with the ports empty, not a device plugged in afterwards.

The sample is small: one run without the removal (cycle 3) against four with it, one each way with the SSD attached through sleep, and one run with the power/control restore against two without. This is one machine's data rather than a verification of 3aab5a0.

@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6 in Codex (high effort) reviewed @makoni's new report and pinned helper against 3aab5a0, with second opinions from Opus 5.5 High and muse-wonder via pi (thinking high). Both found no newly established defect in this head; their independence from this session is not guaranteed. This was a source review; the head is unchanged, no code changed or tests were rerun, and a worker lacks Alpine Ridge hardware.

Cycles 2 and 3 kept root-port wake disabled in both runs, so that setting does not explain their difference. These are real s2idle sleeps, adding evidence beyond the earlier platform tests. Cycle 3 entered sleep on an already-rescanned tree, so tree history remains a difference. The result shows Thunderbolt loss in s2idle on this setup; it does not establish whether firmware cuts power or verify this S3-only hook.

The new hot-plug observation is relevant to the S3 check: this head rescans and counts xHCIs but does not preserve power/control. A full count therefore does not establish that a device plugged in later works. Restoring the bridge policy got the SSD enumerated in cycle 4, but the hung reads leave storage usability unresolved, so there is no demonstrated policy fix to copy here.

@angellindo, on an S3-capable machine, the useful next check is with ports empty during sleep: after waking, record the Alpine Ridge bridges' power/control, wait about 30 seconds, plug in a USB 3 disk, check lsusb -t, and verify a read succeeds. Compare with the same plug/read after a fresh boot. For this head, install the pinned hook at /usr/lib/systemd/system-sleep/thunderbolt-remove-rescan, owned by root with mode 0755, and include journalctl -t thunderbolt-remove-rescan with the result. The s2idle scope decision and existing hardware verification remain with the maintainer; the installer conflict with current quattro also remains.

@makoni

makoni commented Nov 24, 2026

Copy link
Copy Markdown

Follow-up to my s2idle report above: the hung reads in cycle 4 don't reproduce on linux-omarchy 7.2.15-4, so they were most likely an xHCI bug in linux-omarchy 7.2.15-1 (not proven, see below) rather than a gap in the hook's power/control restore.

Same MacBookPro14,3, firmware, out-of-tree modules and SSD (JMicron 152d:0576, uas, not mounted) as before, charger connected, s2idle, lid closed for 1 min 48 s to 2 min 55 s each time. The kernel went from 7.2.15-1 to 7.2.15-4. Same hook as before, with the power/control write-back. In two of the cycles it also re-ran my local boot-time script, which sets d3cold_allowed=0 on every PCI device (the rescan leaves the new devices at 1) and power/control=on on every PCIe bridge, so there the write-back had nothing left to do. In the other two it didn't, which is the same restore as cycle 4. Each time the SSD was not attached during sleep. I plugged it in 32–50 s after the wake (about 25 s last time) and read it with dd if=/dev/sdX of=/dev/null bs=1M count=512 iflag=direct.

cycle d3cold_allowed re-applied SSD port (xHCI) read
1 yes right (7d:00.0) 512 MiB in under 2 s, no errors
2 yes left (07:00.0) same
3 no left (07:00.0) same
4 no right (7d:00.0), same port and restore as the old cycle 4 same

In all four, both trees came back (rescan 57–130 ms, links at 8.0 GT/s x4) and the SSD enumerated at 5 Gb/s with uas.

This also answers an open question in my earlier report: the Alpine Ridge bridges are on after boot because of my local boot-time script, not the kernel. On a stock install they are probably auto from boot, so a device plugged into an idle port may go unseen even without sleep (not tested here).

Why I think the old hang was in xHCI: in cycle 4 the two stuck commands were readahead reads of the partition (sectors 2368 and 2816). They were still inflight: CMD 28 s later, just under the 30 s SCSI timeout, with no xHCI or uas error before the unplug zapped them. linux-omarchy 7.2.15-1 already carries 042aad8d0db6 ("xhci: prevent endpoint recovery after roothub disconnect") and 7e0ef4332ed9 ("xhci: avoid xHC endpoint changes after disconnect or link error") from the 7.3 cycle, in its 0603-usb-updates.patch. Upstream 6895dbdc19d9 ("xhci: give back TDs and clean up ep0 after disconnect", Cc stable) describes a regression from those two: TDs on a halted endpoint behind a port flagged as disconnected or link-inactive are never given back, so URBs stay pending. 7.2.15-4 adds that fix as 0611-usb-xhci-give-back-tds-and-clean-up-ep0-after-disconnect.patch, and it is the only xHCI change between the two packages. Cycle 4's log shows no disconnect around the plug-in, and I didn't have xHCI debug logging on, so I can't show the port was flagged that way. The explanation fits the symptom, but it isn't proven. The follow-up bb261776d1a2 ("xhci: keep port link_inactive and connected flags in sync when polled", Cc stable), which fixes 0611, is not in 7.2.15-4. Without it, a stale link_inactive/connected flag after a port reset plus a STALL can still block an endpoint until the device is reset.

So on 7.2.15-4, removing the tree before sleep, rescanning after and getting the bridges back to power/control=on gave a usable disk plugged in after the wake in 4 of 4 runs, with or without d3cold_allowed re-applied. Without the write-back, the device wasn't seen at all (cycle 5 of the earlier report, on 7.2.15-1; I didn't re-run that on -4). This is still s2idle on one machine, so the S3 check @angellindo was asked about still applies.

@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6 in Codex (high effort) reviewed the follow-up against 3aab5a0. Opus 5.5 High and muse-wonder via pi (thinking high) also reviewed it. Both found no newly established defect in this head; their independence from this session is not guaranteed. This was a source review; no code changed or tests were rerun, and a worker lacks Alpine Ridge hardware.

@makoni, the four successful 512 MiB reads on 7.2.15-4 update the earlier storage finding: your helper with bridge-policy restoration now has successful late-plug I/O on this s2idle setup. The restore-off test was on 7.2.15-1, so these new runs do not establish whether restoration is still needed on -4. The kernel explanation remains plausible rather than proven.

Identifying your local boot script as the source of the bridges' power/control=on also changes the baseline: the earlier on-to-auto comparison does not establish a regression from stock boot policy. Stock behavior remains untested in this report.

These runs still use a different helper in s2idle. They do not verify this S3-only head. The existing request for a post-S3 plug/read comparison with fresh boot remains open, alongside hardware confirmation and the maintainer's controller-check and sleep-mode decisions. The installer conflict with current quattro also remains; this stays waiting on the maintainer.

@makoni

makoni commented Nov 25, 2026

Copy link
Copy Markdown

Follow-up on the stock-behaviour point: I have since tested it, and the hot-plug part has a kernel cause with an upstream fix.

Stock 7.2.15-4, no sleep.

  • On a running boot, I put both Alpine Ridge trees back to the kernel defaults by hand: bridges at power/control = auto, d3cold_allowed = 1. The root ports stayed at on.
  • Both xHCIs and the ports in front of them runtime-suspended to D3hot.
  • A USB 3 SSD plugged into an idle USB-C port produced no kernel message for about 30 s. It enumerated as soon as my boot script set the bridges back to on; the script also sets d3cold_allowed to 0.

So in the kernel's default runtime-PM state this does not depend on sleep. A real default boot does reach that state: the patched kernel below booted without my rule or script, with root ports at auto, and the xHCIs and their ports were in D3hot about 35 s after boot. The rescan after resume only brings the bridges back at auto, and from there it is the same case.

Cause and fix.

Patched kernel on this MacBookPro14,3.

  • No sleep. No udev rule and no boot script, so the kernel defaults applied, including root ports at auto. The SSD enumerated within a quarter of a second of the root port's PME interrupt, on both controllers.
  • After one s2idle cycle. This used my local remove-and-rescan helper, with my boot script and udev rule back on for that cycle. I then set the re-created bridges back to auto, and the SSD again enumerated within a quarter of a second of the PME interrupt.

What this means for this PR's head.

  • Without the kernel fix, a device plugged into an idle port isn't seen once the bridges are at auto, with or without an s2idle cycle. S3 is untested. After the head's S3 rescan, a late plug-in should go unseen in the same way. That is a kernel problem, not a problem in the hook.
  • With the fix, the missing power/control restore shouldn't matter for hot-plug. I've checked that only once, after s2idle, with my helper rather than this PR's head, and not in S3. So the post-S3 plug-and-read check asked of angellindo is still the open item.

Details are in omacom/omarchy-pkgs#3475.

@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6 in Codex (high effort) reviewed the new report, the upstream PME change and draft omacom/omarchy-pkgs#3475 against 3aab5a0. Opus 5.5 High and muse-wonder via pi (thinking high) also reviewed them; both found no newly established defect in this head. Their independence from this session is not guaranteed. This was source review; no code changed or tests were rerun, and a worker lacks Alpine Ridge hardware.

The new observations support the kernel explanation for idle hot-plug. The Apple path omits native PME handling, and polling skips devices behind a runtime-suspended bridge. Upstream 2d89ca89b01f enables native PME; the patch carried in draft #3475 matches it. The reported patched-kernel results cover fresh-boot hot-plug and one s2idle cycle with a different helper. They do not verify this head in S3 or show that its remove/rescan is obsolete.

For the outstanding S3 plug/read comparison, record the kernel version, whether the boot log lists PME, any keep-awake rule or script, and bridge power/control and xHCI runtime_status before plugging in. Match those conditions on the fresh-boot leg: missing native PME can hide the disk in either case. Hardware verification, the maintainer's sleep-mode/controller-check decisions and the installer conflict remain open; this stays waiting on the maintainer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.