Repository navigation
J700: USB and Bluetooth keyboard wake from s2idle, including clamshell (supersedes #304) - #340
Merged
Merged
Conversation
Neither the AIC nor the AIC2/AIC3 irq_chip implements .irq_set_wake or sets IRQCHIP_SKIP_SET_WAKE, so irq_set_irq_wake() fails with -ENXIO for every hardware interrupt on Apple silicon. Drivers that arm their interrupt for wakeup, directly or through dev_pm_set_wake_irq(), are silently left without a wake interrupt: dev_pm_arm_wake_irq() ignores the error, suspend_device_irqs() then disables the line like any other, and an event on it cannot end suspend-to-idle. Only interrupts requested with IRQF_NO_SUSPEND, such as the Apple mailbox interrupts that carry the SMC lid and power button events, are still delivered, which is why those are the only things that wake these machines today. Suspend-to-idle is the only system sleep state on these SoCs. The AIC stays powered in it and delivers unmasked interrupts to the CPUs idling in WFI as usual, so there is no wake logic to program. Set IRQCHIP_SKIP_SET_WAKE on both chips, like the GICv3 driver does, so that enable_irq_wake() succeeds and the IRQ core keeps wake-armed interrupts enabled and turns their next event into a system wakeup. IRQCHIP_MASK_ON_SUSPEND is deliberately not set. The IRQ core already disables the non-wake interrupts lazily, and masks and records any that fire during suspend so they are replayed on resume. Masking them in hardware up front gains nothing on a controller that has no separate wake path, and would risk losing events from the edge-like MSIs that the PCIe controller delivers through the AIC. The FIQ chip is left alone: it only carries per-CPU timer, PMU and fast IPI interrupts, none of which are system wake sources. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
USB devices cannot wake an Apple silicon machine from suspend-to-idle. The glue device is never made wakeup capable, so dwc3_core_probe() records sys_wakeup = false, dwc3_host_init() leaves the xHCI platform device with wakeup disabled, and xhci_suspend() clears the root port wake bits. Nothing arms the controller interrupt for wakeup either, so suspend_device_irqs() disables it like any other device interrupt. The core itself is already kept running across system sleep whenever it is up (it is a syscore device, see dwc3_apple_init()), so the controller is in a state to report port events. What is missing is the wakeup policy and the wake interrupt: - Initialise the glue device as a wakeup source, enabled by default as usb_hcd_pci_probe() does for PCI host controllers. This happens before the first dwc3_core_probe(), which then passes the setting on to the xHCI device as on other dwc3 platforms, so xhci_suspend() keeps the root port wake-on-connect/disconnect/overcurrent bits and the root hubs stay armed for remote wakeup. Userspace can still turn it off through the power/wakeup attribute of the glue device. - While the controller is in host mode, register the core interrupt, which xHCI shares, as the wake interrupt of the glue device, and drop it again when host mode is torn down. The PM core arms it in the noirq phase when wakeup is enabled. Device mode gets no wake interrupt: a gadget is resumed by its host, and arming bus activity there would only cause spurious wakeups. This needs the AIC to accept enable_irq_wake(), which "irqchip/apple-aic: Allow interrupts to wake the system" provides; before it, the interrupt could not be armed at all. Not yet verified on hardware: whether this DWC3 integration raises its interrupt for a port status change after xhci_suspend() has halted the controller (the xHCI specification leaves wake signalling from the halted state to the platform). If it does not, the wake interrupt is armed but never fires, behaviour is otherwise unchanged, and a follow-up has to find the platform wake path instead. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The driver sets no hdev->wakeup callback, so hci_register_dev() leaves
HCI_CONN_FLAG_REMOTE_WAKEUP out of the supported connection flags.
bluetoothd marks paired HID devices as wake-allowed and is refused
("Bad flag given (0x1) vs supported (0xe)") for each of them on every
boot, and hci_suspend_sync() always takes the disconnect-only path.
Return device_may_wakeup() of the PCI function, as hci_bcm4377 does for
the Bluetooth function of the other Apple PCIe combo chips. The flag is
then supported and the setting is honest: wakeup on the PCI function is
off by default, so by default suspend behaves exactly as before. When
userspace enables it, hci_suspend_sync() additionally leaves page scan
and LE passive scan set up for the devices flagged for remote wakeup
before bt7932_suspend() quiesces the transport.
This does not make Bluetooth wake the system yet. What is still
missing, none of which can be verified today:
- bt7932_suspend() quiesces the firmware with the quiesce/restore
handshake. It is not known whether the firmware keeps scanning in
that state and signals the host when a wake-enabled device connects.
- Nothing arms the MSI vector for wakeup, and it could not be armed:
the pcie-apple MSI chips implement no irq_set_wake, so
enable_irq_wake() fails on the MSI as it did on every AIC interrupt.
- pcie-apple has no WAKE# handling, and whether a PME from the function
reaches a host interrupt in suspend-to-idle has not been tested.
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The VIA Labs VL122 USB 2.0 hub (2109:2122) on the J700 never signals a downstream connect while it is runtime suspended, so it was given USB_QUIRK_IGNORE_REMOTE_WAKEUP. That kept it out of runtime suspend, but it also leaves the hub without a wakeup setting at all, so it is never armed for remote wakeup in system sleep. Every USB 2.0 keyboard and mouse on the machine sits behind this hub, so none of them could wake it. The problem is runtime PM, not remote wakeup: mark the hub with HUB_QUIRK_DISABLE_AUTOSUSPEND, as is done for other hubs with broken runtime suspend, and drop the device quirk so its wakeup setting is available again for system sleep. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
xhci_suspend() halts the controller (clears USBCMD.R/S) and saves its state. A halted xHC writes no events to its event ring, so it raises no interrupt either: wake events from a halted controller are a separate signal, which on PCI is PME# and on other platforms a PHY or glue wake interrupt (dwc3-qcom, dwc3-imx8mp, xhci-mtk, xhci-tegra all have one). A platform without such a signal cannot be woken by USB devices from system sleep at all, even when it keeps the controller powered and its interrupt armed for wakeup. For suspend-to-idle there is a simple way out: do not halt the controller. The root hubs are still bus suspended with their wake bits set, so the ports are in U3 and downstream devices are armed for remote wakeup, but a remote wakeup or port change now raises a Port Status Change Event and with it the interrupt, which wakes the system once the platform arms it with enable_irq_wake(). Add a property, "xhci-run-in-s2idle", for glue drivers to request this. xhci-plat then skips xhci_suspend() and xhci_resume() across a system suspend when the target state is suspend-to-idle and the controller may wake the system with a wakeup source below it, the same way it already leaves the controller alone while a sideband instance is active. In all other cases, including hibernation and when wakeup is disabled through power/wakeup, the controller is halted as before. Event handling needs nothing new: until the interrupt is suspended an event goes through xhci_irq(), whose usb_hcd_resume_root_hub() reports a wakeup event and aborts the suspend; once it is armed for wakeup, the first interrupt ends suspend-to-idle and is handled when device interrupts are resumed. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Add a dwc3 software property for glue drivers whose controller stays powered in suspend-to-idle but has no wake signal besides the core interrupt, and pass it on to the xHCI platform device as "xhci-run-in-s2idle". The property array now holds up to seven entries, so make room for them and for the terminating empty entry. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
With the core interrupt armed for wakeup, USB devices still cannot wake the J700 (T8140) from suspend-to-idle. Tested with a USB keyboard behind the on-board VL122 hub and an external hub, with the whole chain from the root hub to the keyboard set to power/wakeup=enabled: a keypress lights the keyboard up again, so it signals remote wakeup and its hubs pass it on, but the xHCI interrupt never fires during the sleep. The reason is that xhci_suspend() halts the controller. A halted xHC writes no events and raises no interrupt; a remote wakeup is then only visible as a platform wake signal, and this controller has none: the DWC3 node has a single interrupt, and the Type-C PHY has none. The core and its power domain are kept up across system sleep anyway (it is a syscore device while it is up), so ask xHCI to keep running in suspend-to-idle when it may wake the system. The remote wakeup then raises a Port Status Change Event on the running controller, and the core interrupt, already armed as the wake interrupt in host mode, ends suspend-to-idle. Not yet verified on hardware with this change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Move the mapping of boolean device properties to quirks, and the decision whether to keep the controller running in suspend-to-idle, into helpers that do not need a probed controller, and test them: every property maps to its quirk, "xhci-run-in-s2idle" included, and the controller keeps running only for suspend-to-idle with the quirk set, wakeup enabled and a wakeup source below it. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Move the filling of the property array for the xHCI platform device into dwc3_host_xhci_properties() and test it: "xhci-run-in-s2idle" is passed on only when the glue asks for it, and with every optional property set the array still ends in an empty entry. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Test that the VL122 hub (2109:2122) no longer has USB_QUIRK_IGNORE_REMOTE_WAKEUP and gets HUB_QUIRK_DISABLE_AUTOSUSPEND instead, and that neighbouring entries still match as before. Move the HUB_QUIRK_* flags to hub.h and add small accessors for the device quirk list and the hub id table that the test can call. No functional change. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Suspend several times with an RTC alarm (rtc1, the PMU RTC, on the J700) and check after each resume that the sleep lasted until the alarm, that suspend_stats reports no failures, that every USB device is back, that the power/wakeup settings of USB devices, xHCI and DWC3 are unchanged, and that the log has no xHCI resume errors, warnings or oopses. Needs no one at the machine. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
… wakeup The VIA Labs VL122 USB 2.0 hub on the Apple J700 does not pass a remote wakeup from a downstream device upstream while it is suspended itself, the same limitation that makes it miss downstream connects in runtime suspend. With the whole chain armed and the xHC running in suspend-to-idle, a keypress on a keyboard behind it never reaches the root port: PORTSC stays in U3 without a link state change, with the keyboard behind a dock and behind a plain USB 2.0 hub alike. The hub does see the resume while it is awake: an active hub completes a downstream resume on its port and reports it through its status change endpoint. Keep such a hub awake in suspend-to-idle when a device below it may wake the system, as the USB offload support already does for devices that stay in use. Every device between it and the root hub, the root hub included, stays awake too, so that the root port stays in U0 and the running controller keeps polling the hub's interrupt endpoint. The devices below the hub are suspended as before. A remote wakeup then completes a transfer on the hub's status endpoint, and the controller interrupt, armed for wakeup, ends suspend-to-idle. This needs a controller that keeps running in suspend-to-idle; xhci-plat says so through a new runs_in_s2idle flag of struct usb_hcd. Mark the VL122 with a new USB_QUIRK_HUB_NO_SUSPENDED_WAKEUP; it keeps HUB_QUIRK_DISABLE_AUTOSUSPEND for runtime PM. The cost is an active hub and an active root port while a wake source sits below the hub. Tested on the J700 with a USB keyboard behind the VL122 and a dock, lid open and closed: a keypress ends suspend-to-idle through the xHCI interrupt, 3.7 s from entering suspend when pressed right away. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…as dead A controller left running in suspend-to-idle is expected to come back still running. If it stopped all the same, because power was cut or it hit a Host System Error or Host Controller Error, resume skipped xhci_resume() and handed the root hubs a dead controller. It is not brought back here. Reinitialising it, as xhci_resume() does when told power was lost, is only safe on a quiesced controller: one whose devices were suspended and whose URBs were flushed. In suspend-to-idle devices may have been kept awake, with URBs queued and their interrupt and hub retry paths live, and a reset under them frees state those paths still use. Report the controller dead instead, the path for a controller that stops responding: first mask its interrupts and halt it with xhci_halt(), as the other error paths do, unless its registers no longer answer, since the USB core ignores the interrupts of a dead HCD and a pending one would never be acknowledged; then xhci_hc_died() gives back every pending URB and lets the USB core disconnect the devices. USB then needs the controller to be bound again. The new xhci_quiesce_dying() and xhci_hc_died() are exported for this. The check for a stopped controller and the quiescing are tested with KUnit; the quiescing test fails when the interrupts are left enabled. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Before a system suspend, a runtime suspended controller is resumed: it is halted, and both the halting path and the path that keeps it running in suspend-to-idle need it running. The result of pm_runtime_resume() was ignored. When it failed, the keep-running path marked the controller as running and reported success, so the system went to sleep without the wake source it was promised, and the halting path went on to suspend a controller that was not running. Fail the system suspend with the error instead, before anything is marked. The runtime resume is a helper with KUnit tests, built with CONFIG_PM only; the error test fails when the result is ignored. Fixes: 4d9fbe0 ("usb: xhci: plat: Allow the controller to keep running in suspend-to-idle") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The regression script cleared the kernel log before every cycle. That threw away the log from before the test, and every message logged between one cycle's snapshot and the next clear, so a late USB recovery failure could vanish from both the saved log and the error check. Save the log before the first cycle instead, check each cycle's part of it from a mark without clearing anything, and check what was logged after the last cycle as well. The mark moves past exactly what was saved, from the same read, so a message logged between two reads lands in the next collection. A log that wrapped meanwhile is checked whole. A cycle count of 0, a negative one or a non-number ran no cycle and still reported a pass. Accept only positive counts and a sleep of at least 5 s, refuse other arguments with exit status 2, and pass only when every requested cycle ran. It ran as root and wrote its evidence to a predictable path under /var/tmp, creating it with mkdir -p, so a symlink planted there could redirect what it writes. Create a fresh private directory with mktemp -d by default, and accept an explicit -o only as an absolute path that does not exist yet, created with mode 0700. The early-wake check measured the whole rtcwake command, so suspend and resume work could hide a wake long before the alarm. Measure the time actually spent suspended as the growth of CLOCK_BOOTTIME over CLOCK_MONOTONIC, and report the whole command time beside it. Some failed checks passed quietly. A kernel log that cannot be read, a suspend failure count that cannot be read, and an -i expression grep rejects, which made the filter hide every error, now fail the cycle or the run instead. Add -n to check the arguments without suspending, and a hardware-free test of the argument handling, the output directory rules and the kernel log collection. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…tests The controller-lifecycle and dwc3-teardown tests build the actual DWC3 glue teardown into host units. Since the glue arms the core interrupt for wakeup in host mode, it calls dev_pm_set_wake_irq() and dev_pm_clear_wake_irq() and keeps the interrupt number in struct dwc3_apple, none of which the units provided, so neither compiled and none of their cases ran. Model the wake interrupt in both units, and check in the controller-lifecycle test that host teardown drops it again. Fixes: 13e2211 ("usb: dwc3: apple: Arm the core interrupt for system wakeup in host mode") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The change bits in PORTSC are cleared by writing 1, and a port posts a Port Status Change Event only for a change made while none of them is set (xHCI 1.2, section 4.19.2). KUnit tests of the event handling fake the registers in memory, where writing 1 to a change bit leaves it set, so they can show neither. Nor can they let the port change between two accesses of the driver, as the controller may. Let a test stand in for xhci_portsc_writel() and xhci_portsc_readl(), so that it can apply each write the way the controller does, and change the port just before a chosen read. Without CONFIG_KUNIT the redirections compile away, and with it, they only look for a stub while a KUnit test is running. The next change uses them. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A controller that is kept running in suspend-to-idle (XHCI_RUN_IN_S2IDLE) posts a Port Status Change Event for every change on every root port, and with its interrupt armed for wakeup any of them ends suspend-to-idle. On a J700 the SuperSpeed link of the rear port, behind a debug cable, drops to SS.Inactive every few seconds. Once a wake-armed keyboard keeps the controller running, that link change wakes the system within two seconds, although its root hub is suspended with wakeup disabled: usb usb2: bus suspend, wakeup 0 xhci-hcd xhci-hcd.0.auto: wakeup enabled, keep running in suspend-to-idle. PM: Triggering wakeup from IRQ 93 xhci-hcd xhci-hcd.0.auto: Get port status 2-1 read: 0x4002c0, return 0x4002c0 A halted controller signals only some events as a wakeup. The wake bits in PORTSC, which xhci_bus_suspend() sets only when the root hub may wake the system, select connect, disconnect and over-current changes, and a device signals resume only when the USB core enabled its remote wakeup. While the controller runs those bits select nothing, so make the same choice in software instead: when the controller is running in suspend-to-idle, report a hard wakeup event for exactly those port changes, for a transfer completed by a hub that the USB core kept awake to pass on a remote wakeup (the only devices with transfers in flight), for a function wake notification, and for a controller that stopped or reports a Host Controller or Host System Error, so that resume finds it. Such an error wakes the system even if xhci_halt() then times out, as a failing controller may never halt. This is how macsmc-input decides on wakeups from its suspend-to-idle interrupt. Do not resume or poll the root hub for any other port change, so no wakeup event is reported and no hub status URB completes while the system sleeps. Do not leave the change set in PORTSC either: a port posts a Port Status Change Event only for a change made while none of its change bits is set (xHCI 1.2, section 4.19.2), so a later change of that port that should wake the system, such as a connect, would post none. Clear the change bits and hold them in struct xhci_port instead, where GetPortStatus and the root hub status data report them to the hub driver as before, until it clears them. Clearing a change bit is part of the decision, and the event handling clears none before it, not even the link change of a USB 2 port, which it clears at once when the system is awake. The port may change between a read of PORTSC and the write that clears its change bits: - A change latched in between, while other change bits were still set, posts no event, so PORTSC is read again after each write, and judged. - A device that signals resume while PLC is still set, for example from its U3 entry, sets no new PLC, and the write clears the only change bit of that remote wakeup. Only the link state, now Resume, shows it. The event handling then carries on as if PLC were still set, so that it starts the resume timing of a USB 2 port, or moves a SuperSpeed link to U0. When running in suspend-to-idle begins, the root hubs stop being polled until resume, as for a halted controller, and ports whose change bits are still set, for example for a hub driver that froze before it cleared them, are handled as if they had just posted an event. On resume, the root hubs of ports with held changes are resumed, and all root hubs are polled again, as xhci_resume() does. The interface to the platform glue is xhci_run_in_s2idle_begin() and xhci_run_in_s2idle_end(), and the running state moves from the glue into struct xhci_hcd so the event handling can see it. Add KUnit cases for the decision, and for the event path through xhci_irq() on a controller faked in memory, whose PORTSC takes writes and posts events as the controller does. Before this change, the link change resumes and polls the root hub there, neither a remote wakeup nor a controller error reports a wakeup event, and a port whose link change is left set posts no event for a later connect, disconnect, over-current or remote wakeup. Further cases let the device below a USB 2 or SuperSpeed port signal resume while a change is decided on, just before each PORTSC read in turn and just before the write that clears PLC, both on an event and when running in suspend-to-idle begins: the system wakes, and the resume is taken on. This only decides between events: the controller interrupt is still armed for wakeup, so the IRQ core still ends suspend-to-idle before the handler runs. The following changes keep it enabled instead. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…o-idle The event handling of a controller kept running in suspend-to-idle now decides which events wake the system, but its handler never runs then. The glue arms the interrupt for wakeup, and the IRQ core disables an armed interrupt on its first trigger and ends suspend-to-idle without calling the handler. On the J700 that is still IRQ 93 waking the system for a link change on a root port with wakeup disabled. Request the interrupt with IRQF_NO_SUSPEND when the platform asks for XHCI_RUN_IN_S2IDLE, so that suspend_device_irqs() leaves it enabled and xhci_irq() runs while the system sleeps. As the suspend and interrupts documentation describes, the handler of an IRQF_NO_SUSPEND interrupt runs in suspend-to-idle and the system only wakes if it reports a wakeup, which the event handling now does with pm_wakeup_hard_event(). The Apple mailbox interrupts that carry the SMC lid and power button events to macsmc-input work the same way. Interrupts that are no wakeup now cost a pass through the handler, after which suspend-to-idle carries on. A halted controller is unaffected: it writes no events, so it raises no interrupt, and with its hardware marked inaccessible usb_hcd_irq() would not touch it. Only the primary HCD requests the interrupt, and the DWC3 core requests nothing on it in host mode, so it has no other user that would also be kept enabled. IRQF_SHARED is kept as before. Kept enabled, the interrupt is no longer armed by the wake interrupt that the glue sets up for it; the next change removes that. The flags are fixed when the interrupt is requested, so drop XHCI_RUN_IN_S2IDLE again if it only arrives later, from the xhci_hcd quirks module parameter: running without the interrupt could never wake the system. Add a KUnit case for the flags. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
In host mode the core interrupt was set up as the wake interrupt of the glue, so that the Port Status Change Event of a running xHCI would end suspend-to-idle. Armed for wakeup, it ended suspend-to-idle for every event of the controller, which is what made a link change on a root port with wakeup disabled wake the J700. xHCI now keeps its interrupt enabled across suspend-to-idle when it keeps running there and wakes the system itself, for the events a halted controller would signal. A wake interrupt on the same line is never armed then, as the interrupt is no longer suspended, and the PM documentation advises against combining the two on one interrupt. For a halted controller it never served a purpose: a halted xHC writes no events, so the interrupt cannot fire. Drop the wake interrupt and the interrupt number that was kept only for it. The glue stays wakeup capable and enabled by default, which dwc3_host_init() passes on to the xHCI device and which decides whether xHCI keeps running. Drop the wake interrupt from the models of the glue in the DCP lifecycle selftests again as well. Fixes: 13e2211 ("usb: dwc3: apple: Arm the core interrupt for system wakeup in host mode") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A host controller that has to keep running in suspend-to-idle for USB devices to wake the system should do so only when one of them can. The power/wakeup setting of a device does not tell: whether its remote wakeup gets through also depends on the hubs on its way, and the USB core decides on that as it suspends each device. Add usb_wakeup_reaches(), which tells, once the devices below a hub are suspended, whether one of them can wake it. A device signals a remote wakeup only if the USB core enabled that when it suspended it. A hub passes one on from below whatever its own wakeup setting, which only arms it for connect, disconnect and over-current changes (USB 2.0, section 7.1.7.7, and commit 7aba8d0 ("USB: don't enable remote wakeup by default")). The exception is a hub with USB_QUIRK_HUB_NO_SUSPENDED_WAKEUP: while it is suspended, it does not pass one on from below, so the devices below it count only while it is kept awake. The quirk is about passing a wakeup on, so such a hub armed for its own changes still counts. Add KUnit tests for it on device trees built in memory, among them the one behind the front port of a J700. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
While it is suspended, the VIA Labs VL122 hub on the Apple J700 passes no remote wakeup on from below (USB_QUIRK_HUB_NO_SUSPENDED_WAKEUP), and it does not signal one for a connect, disconnect or over-current change on its own ports either. That is what made it miss downstream connects in runtime suspend: with the hub suspended and its root port armed for wakeup, a dock attached to either connector left the root port in U3, without a link state change, until something resumed the hub from the host side, see commit 601d473 ("usb: core: ignore remote wakeup on the VIA VL122 hub"). So in suspend-to-idle, a VL122 with its wakeup enabled and nothing below it that can wake is suspended like any other hub armed for those changes, and none of them wakes the system. Add USB_QUIRK_HUB_NO_SUSPENDED_PORT_WAKEUP for that, and set it for the VL122. Keep a hub with it awake in suspend-to-idle when its wakeup is enabled and the host controller keeps running, as is done for a device below a hub that does not pass wakeups on, so that its status endpoint reports those changes. usb_wakeup_reaches() counts its own wakeup only while it is kept awake. The cost is an active hub and root port while wakeup is enabled for the hub, which it is not by default. Add KUnit tests that the VL122 armed for wakeup, with nothing below it that can wake, is kept awake, and so is the root hub above it, and that a hub with only the other quirk is not, but still counts as able to wake. Fixes: 8d33f64 ("usb: hub: keep the VL122 awake instead of ignoring its remote wakeup") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
XHCI_RUN_IN_S2IDLE keeps the controller running in suspend-to-idle when wakeup is enabled for it and for a device below it, so that the device can wake the system. That costs power, and a device with wakeup enabled does not mean that its remote wakeup gets through. On a J700 at its defaults, wakeup is enabled for the controller and, by usbhid, for the USB keyboards, and disabled for the hubs and root hubs. The VIA Labs VL122 hub between the keyboards and the root hub passes no remote wakeup on while it is suspended, and the USB core keeps it awake only when its own wakeup is enabled. So the controller was kept running, and a key press did not wake the system: usb usb1: bus suspend, wakeup 0 usb usb2: bus suspend, wakeup 0 xhci-hcd xhci-hcd.0.auto: wakeup enabled, keep running in suspend-to-idle. Keep it running only when a USB device can wake the system through one of its root hubs: the root hub is armed for connect, disconnect and over-current changes, or kept awake for a hub below it, or the remote wakeup of a device below reaches it, see usb_wakeup_reaches(). Halt it as before otherwise. Add a KUnit test of the decision, with the J700 defaults among its cases. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…stem The VIA Labs VL122 hub (USB_QUIRK_HUB_NO_SUSPENDED_WAKEUP) passes no remote wakeup from below on while it is suspended, so in suspend-to-idle the USB core keeps it awake, with its status endpoint running, for a device below that may wake the system. It does so only when wakeup is enabled for the hub itself, though. Hubs have it disabled by default, while usbhid enables it for keyboards, so at its defaults a J700 never keeps the VL122 awake, and a USB keyboard behind it cannot wake the system. The hub's own setting is the wrong condition for a wakeup from below. It already keeps the VL122 awake for the changes of its own ports (USB_QUIRK_HUB_NO_SUSPENDED_PORT_WAKEUP). Any other hub passes on a remote wakeup from below whatever its own wakeup setting, which only arms it for connect, disconnect and over-current changes (USB 2.0, section 7.1.7.7, and commit 7aba8d0 ("USB: don't enable remote wakeup by default")). Keep the VL122 awake whenever the remote wakeup of a device below can reach it, see usb_wakeup_reaches(), so that it behaves as such a hub does, and the wakeup setting of the keyboard decides, as it does behind any other hub. This costs power at the defaults: with a USB keyboard below the VL122, the hub and the host controller stay up in every suspend-to-idle. To avoid that, disable wakeup for the keyboard, or for the host controller. As the hub reports any change of its ports on its status endpoint, a connect or disconnect on one of them also wakes the system while it is kept awake. Add KUnit tests that the VL122 is kept awake at the J700 defaults, and not outside suspend-to-idle, on a controller that halts or may not wake the system, or without a device below that can wake it. Fixes: a28673c ("usb: core: Keep a hub awake in suspend-to-idle when it cannot pass on wakeup") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
enable_irq_wake() fails with -ENXIO for every MSI of a function behind
this host bridge. irq_set_irq_wake() only looks at the top-level chip,
which for a PCI function is the per-device PCI/MSI chip built from the
generic template; msi_lib_init_dev_msi_info() gives it neither an
.irq_set_wake callback nor IRQCHIP_SKIP_SET_WAKE, and the MSI bottom chip
of this driver does not forward the request either. A function driver
that arms its interrupt for wakeup, and the PCIe port PME service, are
therefore left without a wake interrupt, suspend_device_irqs() disables
the vector, and the function cannot end suspend-to-idle.
Each vector is an AIC interrupt of its own (see apple_msi_domain_alloc()),
so it can wake the system exactly when that AIC line can. Forward the
wake setting down the hierarchy: give the bottom chip
irq_chip_set_wake_parent(), and set the same callback on the per-device
chip from an init_dev_msi_info() wrapper, as the GICv3 ITS does to adjust
its device domains. With the AIC accepting wake requests ("irqchip/
apple-aic: Allow interrupts to wake the system"), enable_irq_wake() on a
PCI MSI then succeeds, the vector stays enabled across suspend-to-idle
and its next message wakes the system.
Nothing is armed by this change alone: it only lets drivers that ask for
a wake interrupt get one.
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
…to-idle
A paired keyboard or mouse cannot wake the machine. When wakeup is
enabled on the PCI function, hci_suspend_dev() sets up page scan and LE
passive scan for the devices flagged for remote wakeup, but
bt7932_suspend() then quiesces the firmware with the quiesce handshake
and lets the PCI core put the function into D3hot, and nothing arms the
interrupt. No connection request or advertising report from a wake
device can reach the host.
In suspend-to-idle with wakeup enabled and the controller up, leave the
transport running and wake through its MSI instead:
- Track wake reports from the start of the suspend callback, before
waiting for queued HCI work and before hci_suspend_dev(). An event
that the HCI core records as a remote wake reason (a BR/EDR
connection request or completion, an LE advertising report while no
discovery runs) is reported with pm_wakeup_dev_event(), so a report
that arrives before the interrupt is suspended aborts the suspend
rather than being consumed unnoticed. A Hardware Error does the same,
so that HCI recovery runs on an awake system. Command replies and
vendor events never count, so the suspend setup cannot abort itself.
- Arm the MSI with enable_irq_wake(). If it cannot be armed, quiesce as
before.
- Block transmission until resume. HCI recovery, whose work is not
frozen for system sleep and which would need to transmit, waits in
the open callback until resume instead of failing its setup.
- Save the PCI state in suspend_noirq, which keeps the PCI core from
moving the function out of D0, and fail the suspend there if the
transport faulted after it was armed.
- Hold the interrupt off from resume_noirq until resume, after the PCI
core has restored that state.
- Whatever raises a terminal fault while that saved state is
outstanding saves it again after clearing bus mastering, so that the
PCI core never restores bus mastering for a failed transport. A
suspend aborted before suspend_noirq has no saved state to restore.
With wakeup disabled (the default), with the controller down, or for a
user channel, suspend is unchanged. The firmware does not raise
interrupts while idle (none in 60 s on an idle J700), so an armed MSI
only fires for traffic the wake setup asked for. The wake signal is the
function's MSI only; endpoint PME is not enabled on this path.
Why the quiesce exists, and why skipping it here holds: "Bluetooth:
mt7932: support modules and system suspend" quiesces the firmware so that
the PCI power transitions of system sleep never meet a running firmware.
This path makes no PCI power transition: the saved state leaves the
function in D0 with bus mastering and the DMA arena untouched, the
arrangement that "wifi: mt7932: keep the function running across
suspend-to-idle" qualified for the Wi-Fi function after finding that
clearing bus mastering under running firmware hangs the SoC. The PCIe
link and host bridge stay up for that function anyway. The quiesce
still runs whenever wakeup is off. ASPM and clock PM stay disabled on the
link as the transport was admitted, which also keeps the link in L0 for
the MSI. HCI is still suspended only from bt7932_suspend(), after the
queued HCI work ("Bluetooth: mt7932: don't cancel HCI commands at
suspend entry").
KUnit covers which received events end the sleep.
This needs "PCI: apple: Let MSIs wake the system" for enable_irq_wake()
to succeed.
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
When it suspends the system, macOS sends the controller one vendor command, opcode 0xfc6f with seven 0xff parameter bytes, before the PCI function changes power state, and sends nothing when the system wakes (observed in our research of the J700 macOS Bluetooth transport; no code was taken from it). 0xfc6f is the MediaTek vendor channel that btmtk, btmtksdio and btmtkuart also use; those drivers wait for a vendor event in reply, so it is not answered by Command Complete. Send the same command when the transport is left running for wakeup, after hci_suspend_dev() has set up the wake scans and before the interrupt is armed. Place it on the command ring directly, outside the HCI command flow, and wait up to 500 ms until the controller has taken it from the ring. The ring publication is factored out of the TX work for this, so that the command has a result: - Nothing was published (the controller could not be reached without a fault, or the ring was full): wakeup is not armed and the transport is quiesced as without wakeup. - Published but not taken in time: the command may still take effect, so the quiesce cannot be relied on. The suspend fails, HCI is resumed and the controller is reset through HCI recovery. - The transport faulted: the suspend fails. The response contract is not established: any reply is a vendor event, which is never treated as a wake report, but one that arrived after the interrupt is suspended would wake the system. The quiesced path is left alone. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Tests for Bluetooth wake from suspend-to-idle on the J700: - bt-wake-cycle.sh: one RTC-backstopped sleep with wakeup of the Bluetooth PCI function enabled or disabled; checks that the driver armed (or did not arm) its interrupt, that the sleep was ended by the Bluetooth MSI (or by the RTC with wakeup disabled), that the controller is up and a given device is connected again after resume, and the kernel log. - attended-bt-wake.sh: the same with a real keyboard and a person pressing a key, about two minutes. - bt-wake-power.sh: alternating sleeps with wakeup disabled and enabled, recording Bluetooth and total interrupts, s2idle loop re-entries and battery energy. - hog-keyboard.py: an emulated BLE HID-over-GATT keyboard on another BlueZ host that advertises only when told to "press a key", like an idle keyboard, so that the wake test can run unattended. - bt-wake-emulated.sh: driver for the unattended run: pairs the emulator with the system under test, runs wake-enabled and wake-disabled cycles with an emulated key press during each sleep, and removes the pairing. Hosts and Bluetooth addresses come from a local configuration file outside the tree. Not for upstream. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
A paired Bluetooth keyboard or mouse can wake the system only while wakeup is enabled on the PCI function of the controller, see bt7932_wakeup() and bt7932_may_wake(). The PCI core leaves it disabled, so at its defaults a J700 is not woken by a Bluetooth keyboard: the tests that qualified Bluetooth wakeup enabled it from userspace. Enable it once the controller is registered, as btmtksdio does for MediaTek SDIO controllers and hci_bcm for Broadcom UART ones. Which paired device may wake the system stays the user's choice, through the WakeAllowed property that BlueZ keeps per device, and power/wakeup still turns wakeup off for the whole controller. This costs power in suspend-to-idle while Bluetooth is up: the controller keeps running with its interrupt armed, scanning for the devices allowed to wake the system. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
…me tests xhci_plat_resume_from_runtime_ok_test resumes a mock device with no runtime PM reference held. The PM core then queues an idle check, which tries a runtime suspend. The mock has no suspend callback, so the attempt fails and the device returns to active, but for a moment its status is RPM_SUSPENDING. A test that reads pm_runtime_active() then sees false. Under lockdep with two CPUs this failed 1 run in 10. The real caller cannot see this: system suspend calls the suspend callbacks with the reference that device_prepare() takes. Hold one in the tests too, and drop it when they release the device. Fixes: 7dfc99a ("usb: xhci: plat: Fail system suspend when the controller does not resume") Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
This was referenced Oct 17, 2026
RyanTheTide
added a commit
that referenced
this pull request
Oct 17, 2026
Bring the 7.2.10 assembly to the tree of the canonical top-up #5 assembly 1c824ed, stacked on top-up #4 5043778 so that it is a fast-forward of the published branch. The second parent is that canonical assembly; the tree is identical to it. Ported from aurora-wip, each with cherry-pick -x and its original author: - #338 tipd lost IRQ (5): never leave CD321x interrupt events unacknowledged, recover from a failed partner identity read, keep SN201202x events unhandled while it sleeps and wake it when suspend fails, and the KUnit race fix of the IRQ test (170-usb). - #339 Touch ID verify retry (2): say why the sensor status after registration was unusable, and retry a failed sensor bring-up before a verify (100-sep). - #340 USB and Bluetooth wake v4.1 (30): AIC wake (010-soc); xHCI, DWC3 and hub suspend-to-idle wake with their KUnit tests (170-usb); MT7932 Bluetooth wake and MSI wake for Apple PCIe (080-radio); the apple-dcp DWC3 wake model (200-dcp); the tools/aurora-wake regression tools (900-config-tooling). - #341 apple-dcp selftests for the tipd lost-IRQ helpers (200-dcp). - batch1 backlog: rust-clippy (4; 070-audio, 210-gpu), boot-warnings (3; 200-dcp), and the 4 harden-all commits not yet carried (010-soc qspi resume, 070-audio AOP wrapped-entry test, 200-dcp start completion). kunit-parsers, spi-apple-cs and the other 34 harden-all commits were already in the topics, including the AOP ring fix that top-up #4 brought; it is not duplicated. Not ported: 3132675, superseded on 7.2.10 by b69728b ("selftests: apple-dcp: Follow the 7.2.10 driver boundaries"). Adaptations, each with a [ryan: ...] note in its commit: - the new tipd KUnit tests take the CD321x and SN201202x data from the exported tipd_hw_variants[] table of 7.2.10; - the #341 lifecycle.py import also keeps ATC_POST_TUNABLE; - drm/asahi statistics style without the driver.rs part, which 7.2.10 already has; - the Rust doc example refresh only for KVec and Drain: iosys_map.rs, the old IoMem example and declare_flags_type!() are gone in 7.2.10; - "Do not arm the core interrupt for wakeup" split between 170-usb and 200-dcp. New: 11e0ce6 ("usb: typec: tipd: cd321x: Don't race the resume read in the sleep retry test"). Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This lets a USB or Bluetooth keyboard wake the MacBook Neo (J700) from suspend-to-idle, including with the lid closed and with nothing configured by hand.
It supersedes #304. That PR's head is the pre-review line. This is v4.1, after five review rounds and Sashiko, rebased onto aurora-wip.
Why nothing could wake the Neo
Three causes were stacked:
irq_set_wake, so no interrupt could be armed for wakeup. Only theIRQF_NO_SUSPENDmailbox (lid, power button) could wake it.Bluetooth wake on the MT7932 is an ordinary PCIe MSI on 01:00.1. There is no host-wake GPIO. The Apple PCIe MSI domain returned
-ENXIOforirq_set_wake.What this does
USB, 24 commits:
usb_wakeup_reaches()). Otherwise it halts as before.USB_QUIRK_HUB_NO_SUSPENDED_WAKEUP/..._PORT_WAKEUP), or for its own wakeup.Bluetooth, 5 commits, which depend on the AIC commit:
Test fix, 1 commit: the xhci-plat resume-from-runtime KUnit tests now hold a runtime PM reference, as system suspend does (
device_prepare()).Review
Testing
b659856e, which now includes tipd usb: typec: tipd: keep a CD321x/SN201202x port from going deaf after s2idle (lost event IRQ) #338 and the Touch ID retry soc: apple: sep: retry a failed sensor bring-up before a verify (Touch ID after resume) #339:7.1.12-aurora-wakefilter41awip-bt-gf22b055ce), 2026-10-17:slot 1 transfer: s2idle wakeup.=) to the ones that passed last night, KB400 key wake through the mt7932 MSI, lid open and docked clamshell;Known costs / follow-ups
🤖 Generated with Claude Code