From 17379d1a45da3bc48a8ceeecede3fe6b0afafdfb Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 1 Dec 2026 23:10:46 +0700 Subject: [PATCH 1/4] wifi: apple: centauri: keep the association through a deep sleep (WoWLAN) A deep sleep refused to start while the station was associated, so cfg80211 left the network first and the machine came back offline until the supplicant joined again. The firmware runs on through the sleep, and its host sleep request has a state that keeps the association: 1, where 3 is the unassociated sleep. Advertise WoWLAN "any". When userspace arms it, the wiphy suspend keeps the association for a deep sleep (on s2idle nothing services the link, so it still leaves first, as without WoWLAN), and the device suspend sends the associated sleep state. It also lets the connection's loss, the disconnect, the scan quota and the keepalive and service wake events through to the host. At resume the events that came during the sleep are drained, so a link lost in the sleep is reported at once, and the log says whether the association was kept. No packet patterns, magic packet or disconnect triggers are advertised: the firmware is not given any. Signed-off-by: Nick --- .../wireless/apple/centauri/centauri_wifi.c | 99 ++++++++++++++++--- 1 file changed, 88 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/centauri_wifi.c b/drivers/net/wireless/apple/centauri/centauri_wifi.c index bb8ff60fa866f..2d69f217334ad 100644 --- a/drivers/net/wireless/apple/centauri/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/centauri_wifi.c @@ -129,6 +129,8 @@ struct centauri_wifi { size_t reply_capacity, reply_size; bool stopping; bool transport_paused, transport_sleep_sent, host_sleep_sent; + /* WoWLAN: armed by cfg80211 for this sleep; the sleep kept the association */ + bool wowlan_armed, wowlan_sleep; bool host_events_fallback_logged; bool connecting, connected, connect_event, disconnect_event; bool connect_privacy; @@ -3599,6 +3601,46 @@ static int wifi_dump_survey(struct wiphy *wiphy, struct net_device *netdev, return ret; } +#ifdef CONFIG_PM +/* + * WoWLAN "any": keep the association through a deep sleep. The firmware runs + * on through it, and is told the host sleeps while associated, so it goes on + * reporting the connection's loss. No packet patterns are programmed. + */ +static const struct wiphy_wowlan_support centauri_wowlan_support = { + .flags = WIPHY_WOWLAN_ANY, +}; + +/* + * Returning 1 has cfg80211 leave the network first, as without WoWLAN. Only a + * deep sleep tells the firmware the host sleeps (centauri_wifi_suspend()); across + * s2idle nothing would service the link, so it is left as before. + */ +static int wifi_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan) +{ + struct centauri_wifi *wifi = *(struct centauri_wifi **)wiphy_priv(wiphy); + + mutex_lock(&wifi->lock); + wifi->wowlan_armed = wowlan && wowlan->any && pm_suspend_via_firmware() && + wifi->connected && !wifi->connecting && + !wifi->scan_request && !wifi->transport_paused && + !READ_ONCE(wifi->stopping) && + readl(wifi->a.bar + 8) == 2; + mutex_unlock(&wifi->lock); + return wowlan && !wifi->wowlan_armed ? 1 : 0; +} + +static int wifi_resume(struct wiphy *wiphy) +{ + struct centauri_wifi *wifi = *(struct centauri_wifi **)wiphy_priv(wiphy); + + mutex_lock(&wifi->lock); + wifi->wowlan_armed = false; + mutex_unlock(&wifi->lock); + return 0; +} +#endif + static const struct cfg80211_ops wifi_ops = { .scan = wifi_scan, .abort_scan = wifi_abort_scan, @@ -3610,6 +3652,10 @@ static const struct cfg80211_ops wifi_ops = { .dump_station = wifi_dump_station, .get_channel = wifi_get_channel, .dump_survey = wifi_dump_survey, +#ifdef CONFIG_PM + .suspend = wifi_suspend, + .resume = wifi_resume, +#endif }; static int net_open(struct net_device *netdev) @@ -4704,6 +4750,9 @@ int centauri_wifi_register(struct centauri *c) wifi->wiphy->n_akm_suites = ARRAY_SIZE(akm_suites); wifi->wiphy->max_num_akm_suites = CFG80211_MAX_NUM_AKM_SUITES; wiphy_ext_feature_set(wifi->wiphy, NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK); +#ifdef CONFIG_PM + wifi->wiphy->wowlan = ¢auri_wowlan_support; +#endif wiphy_ext_feature_set(wifi->wiphy, NL80211_EXT_FEATURE_SAE_OFFLOAD); centauri_wifi_set_address(wifi); ret = radio_start(wifi); @@ -4803,13 +4852,23 @@ static int alpha_transport_state(struct centauri_wifi *wifi, bool asleep) #define CEN_HOST_EVENTS_LEGACY 85 #define CEN_HOST_EVENTS_FULL 91 +/* + * The events the firmware still passes to a sleeping host: unassociated, the + * ones the host acts on at the wake; associated (WoWLAN), also the connection's + * loss, the disconnect, the scan quota and the keepalive and service wakes. + */ +static const u8 host_sleep_events[] = { 24, 26, 27, 15, 51, 8, 9, 10, 84 }; +static const u8 host_sleep_events_wowlan[] = { + 79, 83, 3, 4, 33, 24, 26, 27, 15, 51, 8, 9, 10, 84, +}; + static int alpha_host_power_send(struct centauri_wifi *wifi, bool asleep, u8 event_count) { - static const u8 sleep_events[] = { 24, 26, 27, 15, 51, 8, 9, 10, 84 }; + const u8 *sleep_events = host_sleep_events; u8 payload[3 + 5 + 4 + 1 + CEN_HOST_EVENTS_FULL] = {}; u8 events[1 + CEN_HOST_EVENTS_FULL] = {}; - u8 sleep_option = 1; + u8 sleep_option = 1, state = 3; size_t size = 3; unsigned int i; int ret; @@ -4818,11 +4877,17 @@ static int alpha_host_power_send(struct centauri_wifi *wifi, bool asleep, if (readl(wifi->a.bar + 8) != 2) return -EIO; if (asleep) { - put_unaligned_le16(3, payload); - payload[2] = 3; + /* Sleep state 1 keeps the association, 3 is the unassociated sleep. */ + events[0] = ARRAY_SIZE(host_sleep_events); + if (wifi->connected) { + state = 1; + sleep_events = host_sleep_events_wowlan; + events[0] = ARRAY_SIZE(host_sleep_events_wowlan); + } + put_unaligned_le16(state, payload); + payload[2] = state; append_tlv(payload, &size, 303, &sleep_option, sizeof(sleep_option)); - events[0] = ARRAY_SIZE(sleep_events); - memcpy(events + 1, sleep_events, sizeof(sleep_events)); + memcpy(events + 1, sleep_events, events[0]); } else { events[0] = event_count; for (i = 0; i < event_count; i++) @@ -4831,9 +4896,10 @@ static int alpha_host_power_send(struct centauri_wifi *wifi, bool asleep, append_tlv(payload, &size, 280, events, 1 + event_count); ret = command_control(wifi, 6, payload, size, true); dev_dbg(&wifi->control->pdev->dev, - "Alpha firmware host %s (events=%u tlv280=%u): ret=%d status=%u exec=%u\n", - asleep ? "sleep" : "awake", events[0], 1 + event_count, ret, - wifi->reply_status, readl(wifi->a.bar + 8)); + "Alpha firmware host %s (state=%u events=%u tlv280=%u): ret=%d status=%u exec=%u\n", + asleep ? "sleep" : "awake", asleep ? state : 0, events[0], + 1 + event_count, ret, wifi->reply_status, + readl(wifi->a.bar + 8)); return ret; } @@ -4924,6 +4990,14 @@ int centauri_wifi_resume(struct centauri *c) return 0; mutex_lock(&wifi->lock); ret = alpha_resume_locked(wifi); + if (wifi->wowlan_sleep && !ret) + drain(wifi); + if (wifi->wowlan_sleep) + dev_info(&c->pdev->dev, + "Wi-Fi slept associated (WoWLAN): resume rc=%d, %s\n", ret, + wifi->connected && !wifi->disconnect_event ? + "association kept" : "disconnected"); + wifi->wowlan_sleep = false; mutex_unlock(&wifi->lock); return ret; } @@ -4942,11 +5016,13 @@ int centauri_wifi_suspend(struct centauri *c) if (!wifi || !pm_suspend_via_firmware()) return 0; mutex_lock(&wifi->lock); - if (wifi->transport_paused || wifi->connected || wifi->connecting || wifi->scan_request || - READ_ONCE(wifi->stopping)) { + /* Associated only when cfg80211 armed WoWLAN for this sleep (wifi_suspend()). */ + if (wifi->transport_paused || (wifi->connected && !wifi->wowlan_armed) || + wifi->connecting || wifi->scan_request || READ_ONCE(wifi->stopping)) { mutex_unlock(&wifi->lock); return -EBUSY; } + wifi->wowlan_sleep = wifi->connected; mutex_lock(&wifi->fwlog_lock); WRITE_ONCE(wifi->transport_paused, true); mutex_unlock(&wifi->fwlog_lock); @@ -4964,6 +5040,7 @@ int centauri_wifi_suspend(struct centauri *c) ret = alpha_transport_state(wifi, true); } if (ret) { + wifi->wowlan_sleep = false; restore = alpha_resume_locked(wifi); if (restore) dev_err(&c->pdev->dev, From 4265c100cffa8aef3e22e5b2e176588146b1a69f Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 4 Dec 2026 03:50:54 -0500 Subject: [PATCH 2/4] wifi: apple: centauri: clear WoWLAN arming on sleep abort Return the arming decision captured under the Wi-Fi lock. Clear the arming bit on device resume and on either suspend refusal path. Signed-off-by: DjDeveloperr --- .../net/wireless/apple/centauri/centauri_wifi.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/centauri_wifi.c b/drivers/net/wireless/apple/centauri/centauri_wifi.c index 2d69f217334ad..184beedc5258a 100644 --- a/drivers/net/wireless/apple/centauri/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/centauri_wifi.c @@ -3619,15 +3619,17 @@ static const struct wiphy_wowlan_support centauri_wowlan_support = { static int wifi_suspend(struct wiphy *wiphy, struct cfg80211_wowlan *wowlan) { struct centauri_wifi *wifi = *(struct centauri_wifi **)wiphy_priv(wiphy); + bool armed; mutex_lock(&wifi->lock); - wifi->wowlan_armed = wowlan && wowlan->any && pm_suspend_via_firmware() && - wifi->connected && !wifi->connecting && - !wifi->scan_request && !wifi->transport_paused && - !READ_ONCE(wifi->stopping) && - readl(wifi->a.bar + 8) == 2; + armed = wowlan && wowlan->any && pm_suspend_via_firmware() && + wifi->connected && !wifi->connecting && + !wifi->scan_request && !wifi->transport_paused && + !READ_ONCE(wifi->stopping) && + readl(wifi->a.bar + 8) == 2; + wifi->wowlan_armed = armed; mutex_unlock(&wifi->lock); - return wowlan && !wifi->wowlan_armed ? 1 : 0; + return wowlan && !armed ? 1 : 0; } static int wifi_resume(struct wiphy *wiphy) @@ -4997,6 +4999,7 @@ int centauri_wifi_resume(struct centauri *c) "Wi-Fi slept associated (WoWLAN): resume rc=%d, %s\n", ret, wifi->connected && !wifi->disconnect_event ? "association kept" : "disconnected"); + wifi->wowlan_armed = false; wifi->wowlan_sleep = false; mutex_unlock(&wifi->lock); return ret; @@ -5019,6 +5022,7 @@ int centauri_wifi_suspend(struct centauri *c) /* Associated only when cfg80211 armed WoWLAN for this sleep (wifi_suspend()). */ if (wifi->transport_paused || (wifi->connected && !wifi->wowlan_armed) || wifi->connecting || wifi->scan_request || READ_ONCE(wifi->stopping)) { + wifi->wowlan_armed = false; mutex_unlock(&wifi->lock); return -EBUSY; } @@ -5040,6 +5044,7 @@ int centauri_wifi_suspend(struct centauri *c) ret = alpha_transport_state(wifi, true); } if (ret) { + wifi->wowlan_armed = false; wifi->wowlan_sleep = false; restore = alpha_resume_locked(wifi); if (restore) From a28e5bedd0d616d1af4a1cf3751db8f186a2f14e Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 5 Dec 2026 04:03:51 +0300 Subject: [PATCH 3/4] dt-bindings: net: wireless: apple,centauri: allow wakeup-source A board whose N1 can wake the host from system sleep marks function zero with the standard wakeup-source property. The native driver offers WoWLAN only there. Signed-off-by: Nick --- .../devicetree/bindings/net/wireless/apple,centauri.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml b/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml index 163dea562bdb6..43827ac5e381c 100644 --- a/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml +++ b/Documentation/devicetree/bindings/net/wireless/apple,centauri.yaml @@ -30,6 +30,10 @@ description: | pci/apple,pcie.yaml. With both, the native driver restarts a firmware that stopped; without them it never resets the chip. + wakeup-source marks a board whose N1 can wake the host from system sleep. + Only then does the native driver offer WoWLAN, which keeps the station + associated through a deep sleep. + properties: compatible: oneOf: @@ -59,6 +63,8 @@ properties: const: 27 description: Shared firmware wire protocol profile + wakeup-source: true + allOf: - if: properties: From 6d4e2d31d95d6a47115b74d585549c14613b8cab Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 5 Dec 2026 04:03:52 +0300 Subject: [PATCH 4/4] wifi: apple: centauri: offer WoWLAN only with wakeup-source WoWLAN "any" is a host wake trigger: the device keeps running and wakes the host on activity. The association is kept through a deep sleep, but no N1 board wakes the host from Wi-Fi yet: on the J815 the firmware's test wake during an armed sleep did not wake the machine. Advertise WoWLAN only when the control function's node has wakeup-source, so cfg80211 accepts "wowlan enable any" only where the wake path exists. Without it the wiphy has no WoWLAN support and a deep sleep leaves the network first, as before. Signed-off-by: Nick --- drivers/net/wireless/apple/centauri/centauri_wifi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/apple/centauri/centauri_wifi.c b/drivers/net/wireless/apple/centauri/centauri_wifi.c index 23718c14794bc..7b1aca594cf79 100644 --- a/drivers/net/wireless/apple/centauri/centauri_wifi.c +++ b/drivers/net/wireless/apple/centauri/centauri_wifi.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -3685,7 +3686,8 @@ static int wifi_dump_survey(struct wiphy *wiphy, struct net_device *netdev, /* * WoWLAN "any": keep the association through a deep sleep. The firmware runs * on through it, and is told the host sleeps while associated, so it goes on - * reporting the connection's loss. No packet patterns are programmed. + * reporting the connection's loss. No packet patterns are programmed. Offered + * only with wakeup-source on the control function's node (centauri_wifi_register()). */ static const struct wiphy_wowlan_support centauri_wowlan_support = { .flags = WIPHY_WOWLAN_ANY, @@ -4836,7 +4838,12 @@ int centauri_wifi_register(struct centauri *c) wifi->wiphy->max_num_akm_suites = CFG80211_MAX_NUM_AKM_SUITES; wiphy_ext_feature_set(wifi->wiphy, NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK); #ifdef CONFIG_PM - wifi->wiphy->wowlan = ¢auri_wowlan_support; + /* + * "any" is a host wake trigger, so it is offered only where the board + * describes a working wake path from the N1. + */ + if (device_property_read_bool(&c->pdev->dev, "wakeup-source")) + wifi->wiphy->wowlan = ¢auri_wowlan_support; #endif wiphy_ext_feature_set(wifi->wiphy, NL80211_EXT_FEATURE_SAE_OFFLOAD); centauri_wifi_set_address(wifi);