* [PATCH wireless-next v3 0/5] wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips
@ 2026-11-27 17:35 Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 1/5] wifi: brcmfmac: pcie: set the state before D0_INFORM on resume Andre Eikmeyer
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Andre Eikmeyer @ 2026-11-27 17:35 UTC (permalink / raw)
To: arend.vanspriel
Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
michael.reeves077, marcan, j, asahi, sebastian.reichel,
Soeren Coremans, Andre Eikmeyer
These are follow-ups to Michael Reeves' BCM4388 series, which is now
in wireless-next.
- Patch 1: D0_INFORM on resume now goes through the control ring,
which refuses to write while the PCIe state is DOWN. Set the state
first.
- Patch 2: The BCM4364 halts on the host ready doorbell at init. Skip
the doorbell there.
- Patch 3: The BCM4364 and BCM4377 come back from S3 without firmware.
Probe them again.
- Patch 4: The BCM4377 returns the tx status only once the flowring
delete is sent. Do not wait for it before.
- Patch 5: Add deep sleep for the BCM4364 and BCM4377, so the package
reaches PC10.
Patch 3 reuses the existing re-probe in brcmf_pcie_pm_leave_D3().
"wifi: brcmfmac: pcie: recover from fatal PCIe errors" [3] adds a
second re-probe after a PCIe error.
Both run under the device lock, but a PCIe error during resume can
still start both. Whichever series lands second should skip the
re-probe in brcmf_pcie_pm_leave_D3() while in_pci_recovery is set.
Patch 5 does not wake a device that is down, so the remove after a
link reset does not stall.
The Bluetooth function of the BCM4377 gets the same resume handling in
"Bluetooth: hci_bcm4377: resume after ACPI S3 and ASPM" on
linux-bluetooth.
Successfully tested with S3 and deep sleep on the BCM4364B2
(MacBookPro15,1), the BCM4364B3 (MacBookPro16,1) and the BCM4377
(MacBookAir9,1).
The T2 Linux community runs v2 of this series.
Changes in v3:
- Rebased on wireless-next, which has Michael's series now
- Patch 1: add the Fixes tag and Arend's Ack
- Patch 2: limit it to the BCM4364, B2 and B3, reword the commit
message and add the Fixes tag
- Patch 3: limit it to the BCM4364 and BCM4377
- Patch 4: keep the wait on all chips but the BCM4377. On the BCM4364B3
a tx status came after the delete response once, so it keeps the
wait as well. Commit ae13aa2ec885 already resets the counter when a
flowring is created
- Patch 5:
- limit it to the BCM4364 and BCM4377 with the mailbox on the
control ring
- check for the interrupt thread instead of in_irq
- handle a deep sleep message that fails to send
- wake the device in remove, disable deep sleep under ds_lock and
cancel the deassert work right after, before brcmf_detach() frees
the rings the work writes to
- give up waking a device that is not up
- clear ds_suspend when entering D3 fails
- DS_INBAND_DW comes on top of DS_NO_OOB_DW, as Broadcom's DHD driver
sets it
[1] v2: https://lore.kernel.org/all/20261111120748.23795-1-dev@deq.rocks/
[2] v1: https://lore.kernel.org/all/20261107154810.89780-1-dev@deq.rocks/
[3] https://lore.kernel.org/all/20261105215954.184290-1-sorencoremans@gmail.com/
Andre Eikmeyer (5):
wifi: brcmfmac: pcie: set the state before D0_INFORM on resume
wifi: brcmfmac: pcie: skip the host ready doorbell at init on the
BCM4364
wifi: brcmfmac: pcie: probe again after a resume through firmware
wifi: brcmfmac: msgbuf: do not wait for tx status on the BCM4377
wifi: brcmfmac: pcie: support inband device wake and deep sleep
.../broadcom/brcm80211/brcmfmac/commonring.c | 14 +
.../broadcom/brcm80211/brcmfmac/commonring.h | 5 +
.../broadcom/brcm80211/brcmfmac/msgbuf.c | 10 +-
.../broadcom/brcm80211/brcmfmac/pcie.c | 323 +++++++++++++++++-
4 files changed, 344 insertions(+), 8 deletions(-)
base-commit: 18d0bedbb5f0538396cb7f763ed9cd1dd69c5b23
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH wireless-next v3 1/5] wifi: brcmfmac: pcie: set the state before D0_INFORM on resume
2026-11-27 17:35 [PATCH wireless-next v3 0/5] wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips Andre Eikmeyer
@ 2026-11-27 17:35 ` Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 2/5] wifi: brcmfmac: pcie: skip the host ready doorbell at init on the BCM4364 Andre Eikmeyer
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andre Eikmeyer @ 2026-11-27 17:35 UTC (permalink / raw)
To: arend.vanspriel
Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
michael.reeves077, marcan, j, asahi, sebastian.reichel,
Soeren Coremans, Andre Eikmeyer, Yossef Osman
With the mailbox on the control ring, D0_INFORM goes through the ring
write path, which refuses to write while devinfo->state is DOWN.
brcmf_pcie_pm_leave_D3() sets the state only after D0_INFORM, so every
hot resume fails and falls back to remove and re-probe:
brcmf_pcie_send_mb_data: Failed to send H2D mailbox data (-5)
Set the state before D0_INFORM and back to DOWN when the hot resume
fails.
Fixes: a83a99d063a0 ("wifi: brcmfmac: Negotiate PCIe mailbox transport with firmware")
Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index 00ecb9c9925..6f329eca2cd 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -3101,10 +3101,10 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev)
/* Check if device is still up and running, if so we are ready */
if (brcmf_pcie_read_pcie32(devinfo, devinfo->reginfo->intmask) != 0) {
brcmf_dbg(PCIE, "Try to wakeup device....\n");
+ devinfo->state = BRCMFMAC_PCIE_STATE_UP;
if (brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM))
goto cleanup;
brcmf_dbg(PCIE, "Hot resume, continue....\n");
- devinfo->state = BRCMFMAC_PCIE_STATE_UP;
brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
brcmf_bus_change_state(bus, BRCMF_BUS_UP);
brcmf_pcie_intr_enable(devinfo);
@@ -3114,6 +3114,7 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev)
}
cleanup:
+ devinfo->state = BRCMFMAC_PCIE_STATE_DOWN;
brcmf_chip_detach(devinfo->ci);
devinfo->ci = NULL;
pdev = devinfo->pdev;
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH wireless-next v3 2/5] wifi: brcmfmac: pcie: skip the host ready doorbell at init on the BCM4364
2026-11-27 17:35 [PATCH wireless-next v3 0/5] wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 1/5] wifi: brcmfmac: pcie: set the state before D0_INFORM on resume Andre Eikmeyer
@ 2026-11-27 17:35 ` Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 3/5] wifi: brcmfmac: pcie: probe again after a resume through firmware Andre Eikmeyer
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andre Eikmeyer @ 2026-11-27 17:35 UTC (permalink / raw)
To: arend.vanspriel
Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
michael.reeves077, marcan, j, asahi, sebastian.reichel,
Soeren Coremans, Andre Eikmeyer, Yossef Osman
With host ready in the host capabilities, the BCM4364 firmware halts on
the doorbell that brcmf_pcie_preinit() rings, before it answers the
first ioctl. The B3 of the MacBookPro16,1 does so on every load, the B2
of the MacBookPro15,1 on some:
brcmf_pcie_handle_mb_data D2H_MB_DATA: FW HALT
brcmf_attach: dongle is not responding: err=-5
The BCM4364 loads without host ready in the host capabilities, or with
it but without the doorbell at init. The BCM4377 does not answer
without host ready in the host capabilities, so the capability has to
stay, and it runs with the doorbell at init. Skip the doorbell at init
on the BCM4364 when host ready is a capability.
Fixes: a83a99d063a0 ("wifi: brcmfmac: Negotiate PCIe mailbox transport with firmware")
Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
.../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index 6f329eca2cd..4aed21061dd 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -330,6 +330,7 @@ struct brcmf_pcie_shared_info {
dma_addr_t ringupd_dmahandle;
u8 version;
bool mb_via_ctl;
+ bool hostrdy;
};
#define BRCMF_OTP_MAX_PARAM_LEN 16
@@ -1648,7 +1649,13 @@ static int brcmf_pcie_preinit(struct device *dev)
brcmf_dbg(PCIE, "Enter\n");
brcmf_pcie_intr_enable(buspub->devinfo);
- brcmf_pcie_hostready(buspub->devinfo);
+ /*
+ * With host ready in the host capabilities, the BCM4364 firmware halts
+ * on this doorbell.
+ */
+ if (!buspub->devinfo->shared.hostrdy ||
+ buspub->devinfo->ci->chip != BRCM_CC_4364_CHIP_ID)
+ brcmf_pcie_hostready(buspub->devinfo);
return 0;
}
@@ -1855,8 +1862,10 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo,
!(shared->flags & BRCMF_PCIE_SHARED_USE_MAILBOX);
host_cap = shared->version;
- if (shared->flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1)
+ if (shared->flags & BRCMF_PCIE_SHARED_HOSTRDY_DB1) {
host_cap |= BRCMF_HOSTCAP_H2D_ENABLE_HOSTRDY;
+ shared->hostrdy = true;
+ }
if (shared->flags & BRCMF_PCIE_SHARED_DAR)
host_cap |= BRCMF_HOSTCAP_H2D_DAR;
host_cap |= BRCMF_HOSTCAP_DS_NO_OOB_DW;
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH wireless-next v3 3/5] wifi: brcmfmac: pcie: probe again after a resume through firmware
2026-11-27 17:35 [PATCH wireless-next v3 0/5] wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 1/5] wifi: brcmfmac: pcie: set the state before D0_INFORM on resume Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 2/5] wifi: brcmfmac: pcie: skip the host ready doorbell at init on the BCM4364 Andre Eikmeyer
@ 2026-11-27 17:35 ` Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 4/5] wifi: brcmfmac: msgbuf: do not wait for tx status on the BCM4377 Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 5/5] wifi: brcmfmac: pcie: support inband device wake and deep sleep Andre Eikmeyer
4 siblings, 0 replies; 6+ messages in thread
From: Andre Eikmeyer @ 2026-11-27 17:35 UTC (permalink / raw)
To: arend.vanspriel
Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
michael.reeves077, marcan, j, asahi, sebastian.reichel,
Soeren Coremans, Andre Eikmeyer, Yossef Osman
After ACPI S3 the BCM4364 and BCM4377 of the T2 Macs come back without
their firmware, but the interrupt mask can read back nonzero, so
brcmf_pcie_pm_leave_D3() takes the hot resume path and every command
times out afterwards.
On these chips, when the platform firmware handled the resume and WoWL
is off, go straight to the existing remove and re-probe path. Other
chips keep the hot resume path.
Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
.../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index 4aed21061dd..ea51ef6189d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -7,6 +7,7 @@
#include <linux/module.h>
#include <linux/firmware.h>
#include <linux/pci.h>
+#include <linux/suspend.h>
#include <linux/vmalloc.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
@@ -3107,6 +3108,17 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev)
devinfo = bus->bus_priv.pcie->devinfo;
brcmf_dbg(PCIE, "Enter, dev=%p, bus=%p\n", dev, bus);
+ /*
+ * Without WoWL the BCM4364 and BCM4377 of the T2 Macs are powered off
+ * when the platform firmware handles the system sleep, as with ACPI
+ * S3, and come back without their firmware. Their registers can still
+ * read back nonzero, so probe them again.
+ */
+ if (pm_resume_via_firmware() && !devinfo->wowl_enabled &&
+ (devinfo->ci->chip == BRCM_CC_4364_CHIP_ID ||
+ devinfo->ci->chip == BRCM_CC_4377_CHIP_ID))
+ goto cleanup;
+
/* Check if device is still up and running, if so we are ready */
if (brcmf_pcie_read_pcie32(devinfo, devinfo->reginfo->intmask) != 0) {
brcmf_dbg(PCIE, "Try to wakeup device....\n");
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH wireless-next v3 4/5] wifi: brcmfmac: msgbuf: do not wait for tx status on the BCM4377
2026-11-27 17:35 [PATCH wireless-next v3 0/5] wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips Andre Eikmeyer
` (2 preceding siblings ...)
2026-11-27 17:35 ` [PATCH wireless-next v3 3/5] wifi: brcmfmac: pcie: probe again after a resume through firmware Andre Eikmeyer
@ 2026-11-27 17:35 ` Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 5/5] wifi: brcmfmac: pcie: support inband device wake and deep sleep Andre Eikmeyer
4 siblings, 0 replies; 6+ messages in thread
From: Andre Eikmeyer @ 2026-11-27 17:35 UTC (permalink / raw)
To: arend.vanspriel
Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
michael.reeves077, marcan, j, asahi, sebastian.reichel,
Soeren Coremans, Andre Eikmeyer, Yossef Osman
The BCM4377 firmware returns the tx status of the queued packets only
when it gets the flowring delete request, before the delete response.
brcmf_msgbuf_delete_flowring() waits up to 100 ms for them before it
sends the request, so every disconnect logs a timeout.
Send the delete right away on the BCM4377. Its tx status still comes
before the delete response, so pend_8021x_cnt drains as before. Other
chips keep the wait.
Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
.../net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
index 79c1891db59..195a1a362ba 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c
@@ -14,6 +14,7 @@
#include <brcmu_utils.h>
#include <brcmu_wifi.h>
+#include <brcm_hw_ids.h>
#include "core.h"
#include "debug.h"
@@ -1505,8 +1506,13 @@ void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u16 flowid)
flow->rings[flowid]->status = RING_CLOSING;
brcmf_commonring_unlock(commonring_del);
- /* wait for commonring txflow finished */
- while (retry && atomic_read(&commonring_del->outstanding_tx)) {
+ /*
+ * Wait for commonring txflow finished. The BCM4377 firmware returns
+ * the tx status of the posted packets only on the delete request,
+ * before the delete response.
+ */
+ while (drvr->bus_if->chip != BRCM_CC_4377_CHIP_ID && retry &&
+ atomic_read(&commonring_del->outstanding_tx)) {
usleep_range(5000, 10000);
retry--;
}
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH wireless-next v3 5/5] wifi: brcmfmac: pcie: support inband device wake and deep sleep
2026-11-27 17:35 [PATCH wireless-next v3 0/5] wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips Andre Eikmeyer
` (3 preceding siblings ...)
2026-11-27 17:35 ` [PATCH wireless-next v3 4/5] wifi: brcmfmac: msgbuf: do not wait for tx status on the BCM4377 Andre Eikmeyer
@ 2026-11-27 17:35 ` Andre Eikmeyer
4 siblings, 0 replies; 6+ messages in thread
From: Andre Eikmeyer @ 2026-11-27 17:35 UTC (permalink / raw)
To: arend.vanspriel
Cc: linux-wireless, brcm80211, brcm80211-dev-list.pdl, linux-kernel,
michael.reeves077, marcan, j, asahi, sebastian.reichel,
Soeren Coremans, Andre Eikmeyer, Yossef Osman
The BCM4364 and BCM4377 firmware report inband deep sleep in the PCIe
shared flags. The driver only advertises that it has no out-of-band
device wake. That leaves deep sleep disabled. The firmware stays awake
and its latency tolerance holds the CPU package out of PC10.
On these chips, advertise inband device wake when the firmware supports
it and the mailbox goes over the control ring. It comes on top of no
out-of-band device wake, as in Broadcom's DHD driver.
The host then follows the handshake of the firmware:
- The device asks for deep sleep while device wake is deasserted.
- The host acknowledges once it has nothing to send.
- Before it uses the rings again, it asserts device wake and waits for
the exit note.
- After 200 ms without ring writes, it deasserts device wake.
Hooks around the ring lock cover every host to device ring writer. A
system suspend asserts device wake before D3_INFORM and keeps the
device out of deep sleep until the resume. Removing the device asserts
device wake first, so brcmf_detach() still reaches it.
Tested on a MacBookPro15,1 (BCM4364 B2), a MacBookPro16,1 (BCM4364 B3)
and a MacBookAir9,1 (BCM4377). At idle with Wi-Fi associated, the
firmware enters and leaves deep sleep, also after S3. Traffic works,
and the driver unloads with deep sleep active. The CPU package reaches
PC10 without ignoring the latency tolerance of the Wi-Fi port.
Tested-by: Yossef Osman <Yossef.Osman@proton.me>
Signed-off-by: Andre Eikmeyer <dev@deq.rocks>
---
.../broadcom/brcm80211/brcmfmac/commonring.c | 14 +
.../broadcom/brcm80211/brcmfmac/commonring.h | 5 +
.../broadcom/brcm80211/brcmfmac/pcie.c | 295 +++++++++++++++++-
3 files changed, 311 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c
index e44236cb210..881505b992c 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c
@@ -28,6 +28,16 @@ void brcmf_commonring_register_cb(struct brcmf_commonring *commonring,
}
+/* Both run outside the ring lock and may sleep */
+void brcmf_commonring_register_pm_cb(struct brcmf_commonring *commonring,
+ void (*cr_wake)(void *ctx),
+ void (*cr_idle)(void *ctx))
+{
+ commonring->cr_wake = cr_wake;
+ commonring->cr_idle = cr_idle;
+}
+
+
void brcmf_commonring_config(struct brcmf_commonring *commonring, u16 depth,
u16 item_len, void *buf_addr)
{
@@ -53,6 +63,8 @@ void brcmf_commonring_lock(struct brcmf_commonring *commonring)
{
unsigned long flags;
+ if (commonring->cr_wake)
+ commonring->cr_wake(commonring->cr_ctx);
spin_lock_irqsave(&commonring->lock, flags);
commonring->flags = flags;
}
@@ -62,6 +74,8 @@ void brcmf_commonring_unlock(struct brcmf_commonring *commonring)
__releases(&commonring->lock)
{
spin_unlock_irqrestore(&commonring->lock, commonring->flags);
+ if (commonring->cr_idle)
+ commonring->cr_idle(commonring->cr_ctx);
}
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.h
index 7fb11f4823e..a27be6d7b17 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.h
@@ -20,6 +20,8 @@ struct brcmf_commonring {
int (*cr_update_wptr)(void *ctx);
int (*cr_write_rptr)(void *ctx);
int (*cr_write_wptr)(void *ctx);
+ void (*cr_wake)(void *ctx);
+ void (*cr_idle)(void *ctx);
void *cr_ctx;
@@ -38,6 +40,9 @@ void brcmf_commonring_register_cb(struct brcmf_commonring *commonring,
int (*cr_update_wptr)(void *ctx),
int (*cr_write_rptr)(void *ctx),
int (*cr_write_wptr)(void *ctx), void *ctx);
+void brcmf_commonring_register_pm_cb(struct brcmf_commonring *commonring,
+ void (*cr_wake)(void *ctx),
+ void (*cr_idle)(void *ctx));
void brcmf_commonring_config(struct brcmf_commonring *commonring, u16 depth,
u16 item_len, void *buf_addr);
void brcmf_commonring_lock(struct brcmf_commonring *commonring);
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
index ea51ef6189d..8aa0fd57c1f 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
@@ -227,10 +227,12 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = {
#define BRCMF_PCIE_SHARED_DMA_2B_IDX 0x100000
#define BRCMF_PCIE_SHARED_USE_MAILBOX 0x2000000
#define BRCMF_PCIE_SHARED_HOSTRDY_DB1 0x10000000
+#define BRCMF_PCIE_SHARED_INBAND_DS 0x40000000
#define BRCMF_PCIE_SHARED_DAR 0x80000000
#define BRCMF_HOSTCAP_H2D_ENABLE_HOSTRDY 0x400
#define BRCMF_HOSTCAP_DS_NO_OOB_DW 0x1000
+#define BRCMF_HOSTCAP_DS_INBAND_DW 0x2000
#define BRCMF_HOSTCAP_H2D_DAR 0x10000
#define BRCMF_PCIE_FLAGS_HTOD_SPLIT 0x4000
@@ -279,6 +281,11 @@ static const struct brcmf_firmware_mapping brcmf_pcie_fwnames[] = {
#define BRCMF_H2D_HOST_DS_ACK 0x00000002
#define BRCMF_H2D_HOST_D0_INFORM_IN_USE 0x00000008
#define BRCMF_H2D_HOST_D0_INFORM 0x00000010
+#define BRCMF_H2D_HOST_DW_DEASSERT 0x00000020
+#define BRCMF_H2D_HOST_DW_ASSERT 0x00000040
+
+#define BRCMF_PCIE_DS_IDLE_MS 200
+#define BRCMF_PCIE_DS_EXIT_TIMEOUT msecs_to_jiffies(500)
#define BRCMF_PCIE_MBDATA_TIMEOUT msecs_to_jiffies(2000)
@@ -343,6 +350,15 @@ struct brcmf_otp_params {
bool valid;
};
+enum brcmf_pcie_ds_state {
+ BRCMF_PCIE_DS_NONE,
+ BRCMF_PCIE_DS_ALLOWED,
+ BRCMF_PCIE_DS_SLEEP_PEND,
+ BRCMF_PCIE_DS_SLEEP,
+ BRCMF_PCIE_DS_EXIT_WAIT,
+ BRCMF_PCIE_DS_AWAKE,
+};
+
struct brcmf_pciedev_info {
enum brcmf_pcie_state state;
bool in_irq;
@@ -379,6 +395,18 @@ struct brcmf_pciedev_info {
char sig_name[BRCMF_FW_NAME_LEN];
u32 fw_size;
bool skip_reset_vector;
+ /* protects ds_state, ds_active and ds_suspend */
+ spinlock_t ds_lock;
+ enum brcmf_pcie_ds_state ds_state;
+ int ds_active;
+ bool ds_suspend;
+ /* serializes the deep sleep mailbox messages */
+ struct mutex ds_mutex;
+ struct task_struct *ds_sender;
+ /* the interrupt thread while it runs */
+ struct task_struct *irq_thread;
+ wait_queue_head_t ds_wait;
+ struct delayed_work ds_deassert_work;
#ifdef DEBUG
u32 console_interval;
bool console_active;
@@ -941,17 +969,219 @@ brcmf_pcie_send_mb_data(struct brcmf_pciedev_info *devinfo, u32 htod_mb_data)
}
+static int brcmf_pcie_ds_send(struct brcmf_pciedev_info *devinfo, u32 data)
+{
+ int err;
+
+ mutex_lock(&devinfo->ds_mutex);
+ WRITE_ONCE(devinfo->ds_sender, current);
+ err = brcmf_pcie_send_mb_data(devinfo, data);
+ WRITE_ONCE(devinfo->ds_sender, NULL);
+ mutex_unlock(&devinfo->ds_mutex);
+
+ return err;
+}
+
+/* The handshake messages themselves go through the hooked rings */
+static bool brcmf_pcie_ds_skip(struct brcmf_pciedev_info *devinfo)
+{
+ return READ_ONCE(devinfo->ds_state) == BRCMF_PCIE_DS_NONE ||
+ READ_ONCE(devinfo->ds_sender) == current;
+}
+
+static bool brcmf_pcie_ds_idle_locked(struct brcmf_pciedev_info *devinfo)
+{
+ lockdep_assert_held(&devinfo->ds_lock);
+
+ if (devinfo->ds_active || devinfo->ds_suspend)
+ return false;
+
+ if (devinfo->ds_state == BRCMF_PCIE_DS_SLEEP_PEND) {
+ devinfo->ds_state = BRCMF_PCIE_DS_SLEEP;
+ return true;
+ }
+ if (devinfo->ds_state == BRCMF_PCIE_DS_AWAKE)
+ mod_delayed_work(system_dfl_wq, &devinfo->ds_deassert_work,
+ msecs_to_jiffies(BRCMF_PCIE_DS_IDLE_MS));
+ return false;
+}
+
+/* Without the ack the device stays awake */
+static void brcmf_pcie_ds_ack(struct brcmf_pciedev_info *devinfo)
+{
+ if (!brcmf_pcie_ds_send(devinfo, BRCMF_H2D_HOST_DS_ACK))
+ return;
+
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state == BRCMF_PCIE_DS_SLEEP)
+ devinfo->ds_state = BRCMF_PCIE_DS_ALLOWED;
+ spin_unlock(&devinfo->ds_lock);
+}
+
+static bool brcmf_pcie_ds_exited(struct brcmf_pciedev_info *devinfo)
+{
+ return READ_ONCE(devinfo->ds_state) != BRCMF_PCIE_DS_EXIT_WAIT ||
+ READ_ONCE(devinfo->state) != BRCMFMAC_PCIE_STATE_UP;
+}
+
+static void brcmf_pcie_ds_wake(struct brcmf_pciedev_info *devinfo)
+{
+ bool up, assert = false, wait;
+
+ if (brcmf_pcie_ds_skip(devinfo))
+ return;
+
+ /* A device that is not up does not answer */
+ up = READ_ONCE(devinfo->state) == BRCMFMAC_PCIE_STATE_UP;
+ spin_lock(&devinfo->ds_lock);
+ devinfo->ds_active++;
+ if (up && devinfo->ds_state == BRCMF_PCIE_DS_SLEEP) {
+ devinfo->ds_state = BRCMF_PCIE_DS_EXIT_WAIT;
+ assert = true;
+ }
+ wait = up && devinfo->ds_state == BRCMF_PCIE_DS_EXIT_WAIT;
+ spin_unlock(&devinfo->ds_lock);
+
+ if (assert) {
+ brcmf_dbg(PCIE, "deep sleep: assert device wake\n");
+ if (brcmf_pcie_ds_send(devinfo, BRCMF_H2D_HOST_DW_ASSERT)) {
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state == BRCMF_PCIE_DS_EXIT_WAIT)
+ devinfo->ds_state = BRCMF_PCIE_DS_SLEEP;
+ spin_unlock(&devinfo->ds_lock);
+ wake_up(&devinfo->ds_wait);
+ return;
+ }
+ }
+ if (!wait)
+ return;
+
+ /* The exit note arrives through the interrupt thread itself */
+ if (READ_ONCE(devinfo->irq_thread) == current) {
+ usleep_range(1000, 1100);
+ return;
+ }
+ if (wait_event_timeout(devinfo->ds_wait, brcmf_pcie_ds_exited(devinfo),
+ BRCMF_PCIE_DS_EXIT_TIMEOUT))
+ return;
+
+ brcmf_err(dev_get_drvdata(&devinfo->pdev->dev),
+ "no deep sleep exit after device wake\n");
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state == BRCMF_PCIE_DS_EXIT_WAIT)
+ devinfo->ds_state = BRCMF_PCIE_DS_AWAKE;
+ spin_unlock(&devinfo->ds_lock);
+}
+
+static void brcmf_pcie_ds_idle(struct brcmf_pciedev_info *devinfo)
+{
+ bool ack;
+
+ if (brcmf_pcie_ds_skip(devinfo))
+ return;
+
+ spin_lock(&devinfo->ds_lock);
+ devinfo->ds_active--;
+ ack = brcmf_pcie_ds_idle_locked(devinfo);
+ spin_unlock(&devinfo->ds_lock);
+
+ if (ack) {
+ brcmf_dbg(PCIE, "deep sleep: ack pending request\n");
+ brcmf_pcie_ds_ack(devinfo);
+ }
+}
+
+static void brcmf_pcie_ds_deassert_worker(struct work_struct *work)
+{
+ struct brcmf_pciedev_info *devinfo =
+ container_of(work, struct brcmf_pciedev_info,
+ ds_deassert_work.work);
+ bool deassert = false;
+
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state == BRCMF_PCIE_DS_AWAKE && !devinfo->ds_active &&
+ !devinfo->ds_suspend) {
+ devinfo->ds_state = BRCMF_PCIE_DS_ALLOWED;
+ deassert = true;
+ }
+ spin_unlock(&devinfo->ds_lock);
+
+ if (!deassert)
+ return;
+
+ brcmf_dbg(PCIE, "deep sleep: deassert device wake\n");
+ if (brcmf_pcie_ds_send(devinfo, BRCMF_H2D_HOST_DW_DEASSERT)) {
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state == BRCMF_PCIE_DS_ALLOWED)
+ devinfo->ds_state = BRCMF_PCIE_DS_AWAKE;
+ spin_unlock(&devinfo->ds_lock);
+ }
+}
+
+static void brcmf_pcie_ds_enter_req(struct brcmf_pciedev_info *devinfo)
+{
+ bool ack = false;
+
+ if (devinfo->ds_state == BRCMF_PCIE_DS_NONE) {
+ brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_DS_ACK);
+ return;
+ }
+
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state == BRCMF_PCIE_DS_ALLOWED) {
+ devinfo->ds_state = BRCMF_PCIE_DS_SLEEP_PEND;
+ ack = brcmf_pcie_ds_idle_locked(devinfo);
+ } else {
+ brcmf_dbg(PCIE, "deep sleep request in state %d\n",
+ devinfo->ds_state);
+ }
+ spin_unlock(&devinfo->ds_lock);
+
+ if (ack)
+ brcmf_pcie_ds_ack(devinfo);
+}
+
+static void brcmf_pcie_ds_exit_note(struct brcmf_pciedev_info *devinfo)
+{
+ if (devinfo->ds_state == BRCMF_PCIE_DS_NONE)
+ return;
+
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state == BRCMF_PCIE_DS_EXIT_WAIT ||
+ devinfo->ds_state == BRCMF_PCIE_DS_SLEEP) {
+ devinfo->ds_state = BRCMF_PCIE_DS_AWAKE;
+ brcmf_pcie_ds_idle_locked(devinfo);
+ }
+ spin_unlock(&devinfo->ds_lock);
+ wake_up(&devinfo->ds_wait);
+}
+
+static void brcmf_pcie_ring_ds_wake(void *ctx)
+{
+ struct brcmf_pcie_ringbuf *ring = ctx;
+
+ brcmf_pcie_ds_wake(ring->devinfo);
+}
+
+static void brcmf_pcie_ring_ds_idle(void *ctx)
+{
+ struct brcmf_pcie_ringbuf *ring = ctx;
+
+ brcmf_pcie_ds_idle(ring->devinfo);
+}
+
static void brcmf_pcie_handle_mb_data(struct brcmf_pciedev_info *devinfo,
u32 dtoh_mb_data)
{
brcmf_dbg(PCIE, "D2H_MB_DATA: 0x%04x\n", dtoh_mb_data);
if (dtoh_mb_data & BRCMF_D2H_DEV_DS_ENTER_REQ) {
brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP REQ\n");
- brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_DS_ACK);
- brcmf_dbg(PCIE, "D2H_MB_DATA: sent DEEP SLEEP ACK\n");
+ brcmf_pcie_ds_enter_req(devinfo);
}
- if (dtoh_mb_data & BRCMF_D2H_DEV_DS_EXIT_NOTE)
+ if (dtoh_mb_data & BRCMF_D2H_DEV_DS_EXIT_NOTE) {
brcmf_dbg(PCIE, "D2H_MB_DATA: DEEP SLEEP EXIT\n");
+ brcmf_pcie_ds_exit_note(devinfo);
+ }
if (dtoh_mb_data & BRCMF_D2H_DEV_D3_ACK) {
brcmf_dbg(PCIE, "D2H_MB_DATA: D3 ACK\n");
devinfo->mbdata_completed = true;
@@ -1121,6 +1351,7 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg)
return IRQ_HANDLED;
devinfo->in_irq = true;
+ WRITE_ONCE(devinfo->irq_thread, current);
status = brcmf_pcie_read_pcie32(devinfo, devinfo->reginfo->mailboxint);
brcmf_dbg(PCIE, "Enter %x\n", status);
if (status) {
@@ -1138,6 +1369,7 @@ static irqreturn_t brcmf_pcie_isr_thread(int irq, void *arg)
brcmf_pcie_write_pcie32(devinfo, devinfo->reginfo->mailboxmask,
devinfo->reginfo->int_d2h_db |
devinfo->reginfo->int_fn0);
+ WRITE_ONCE(devinfo->irq_thread, NULL);
devinfo->in_irq = false;
return IRQ_HANDLED;
}
@@ -1357,6 +1589,10 @@ brcmf_pcie_alloc_dma_and_ring(struct brcmf_pciedev_info *devinfo, u32 ring_id,
brcmf_pcie_ring_mb_update_wptr,
brcmf_pcie_ring_mb_write_rptr,
brcmf_pcie_ring_mb_write_wptr, ring);
+ if (ring_id < BRCMF_NROF_H2D_COMMON_MSGRINGS)
+ brcmf_commonring_register_pm_cb(&ring->commonring,
+ brcmf_pcie_ring_ds_wake,
+ brcmf_pcie_ring_ds_idle);
return (ring);
}
@@ -1550,6 +1786,9 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo)
brcmf_pcie_ring_mb_write_rptr,
brcmf_pcie_ring_mb_write_wptr,
ring);
+ brcmf_commonring_register_pm_cb(&ring->commonring,
+ brcmf_pcie_ring_ds_wake,
+ brcmf_pcie_ring_ds_idle);
ring->w_idx_addr = h2d_w_idx_ptr;
ring->r_idx_addr = h2d_r_idx_ptr;
h2d_w_idx_ptr += idx_offset;
@@ -1870,6 +2109,19 @@ brcmf_pcie_init_share_ram_info(struct brcmf_pciedev_info *devinfo,
if (shared->flags & BRCMF_PCIE_SHARED_DAR)
host_cap |= BRCMF_HOSTCAP_H2D_DAR;
host_cap |= BRCMF_HOSTCAP_DS_NO_OOB_DW;
+ /*
+ * Inband device wake comes on top of no out-of-band device
+ * wake, as Broadcom's DHD driver sets it. The handshake is
+ * tested with the mailbox on the control ring of the BCM4364
+ * and BCM4377.
+ */
+ if ((shared->flags & BRCMF_PCIE_SHARED_INBAND_DS) &&
+ shared->mb_via_ctl &&
+ (devinfo->ci->chip == BRCM_CC_4364_CHIP_ID ||
+ devinfo->ci->chip == BRCM_CC_4377_CHIP_ID)) {
+ host_cap |= BRCMF_HOSTCAP_DS_INBAND_DW;
+ devinfo->ds_state = BRCMF_PCIE_DS_ALLOWED;
+ }
brcmf_pcie_write_tcm32(devinfo, sharedram_addr +
BRCMF_SHARED_HOST_CAP_OFFSET,
@@ -2893,6 +3145,11 @@ brcmf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id)
return ret;
devinfo->pdev = pdev;
+ spin_lock_init(&devinfo->ds_lock);
+ mutex_init(&devinfo->ds_mutex);
+ init_waitqueue_head(&devinfo->ds_wait);
+ INIT_DELAYED_WORK(&devinfo->ds_deassert_work,
+ brcmf_pcie_ds_deassert_worker);
pcie_bus_dev = NULL;
devinfo->ci = brcmf_chip_attach(devinfo, pdev->device,
&brcmf_pcie_buscore_ops);
@@ -3020,6 +3277,15 @@ brcmf_pcie_remove(struct pci_dev *pdev)
return;
devinfo = bus->bus_priv.pcie->devinfo;
+ if (devinfo->ds_state != BRCMF_PCIE_DS_NONE) {
+ /* brcmf_detach() still sends ioctls and flowring deletes */
+ brcmf_pcie_ds_wake(devinfo);
+ spin_lock(&devinfo->ds_lock);
+ devinfo->ds_state = BRCMF_PCIE_DS_NONE;
+ spin_unlock(&devinfo->ds_lock);
+ /* nothing queues it once the state is NONE */
+ cancel_delayed_work_sync(&devinfo->ds_deassert_work);
+ }
brcmf_pcie_bus_console_read(devinfo, false);
brcmf_pcie_fwcon_timer(devinfo, false);
@@ -3061,6 +3327,18 @@ brcmf_pcie_remove(struct pci_dev *pdev)
#ifdef CONFIG_PM
+/* The device is awake, let it sleep again once idle */
+static void brcmf_pcie_ds_end_suspend(struct brcmf_pciedev_info *devinfo)
+{
+ spin_lock(&devinfo->ds_lock);
+ if (devinfo->ds_state != BRCMF_PCIE_DS_NONE) {
+ devinfo->ds_suspend = false;
+ devinfo->ds_state = BRCMF_PCIE_DS_AWAKE;
+ brcmf_pcie_ds_idle_locked(devinfo);
+ }
+ spin_unlock(&devinfo->ds_lock);
+}
+
static int brcmf_pcie_pm_enter_D3(struct device *dev)
{
struct brcmf_pciedev_info *devinfo;
@@ -3074,6 +3352,15 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev)
brcmf_pcie_fwcon_timer(devinfo, false);
brcmf_bus_change_state(bus, BRCMF_BUS_DOWN);
+ if (devinfo->ds_state != BRCMF_PCIE_DS_NONE) {
+ spin_lock(&devinfo->ds_lock);
+ devinfo->ds_suspend = true;
+ spin_unlock(&devinfo->ds_lock);
+ cancel_delayed_work_sync(&devinfo->ds_deassert_work);
+ brcmf_pcie_ds_wake(devinfo);
+ brcmf_pcie_ds_idle(devinfo);
+ }
+
devinfo->mbdata_completed = false;
brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D3_INFORM);
@@ -3082,6 +3369,7 @@ static int brcmf_pcie_pm_enter_D3(struct device *dev)
if (!devinfo->mbdata_completed) {
if (devinfo->wowl_enabled) {
brcmf_err(bus, "Timeout on response for entering D3 substate\n");
+ brcmf_pcie_ds_end_suspend(devinfo);
brcmf_bus_change_state(bus, BRCMF_BUS_UP);
return -EIO;
}
@@ -3126,6 +3414,7 @@ static int brcmf_pcie_pm_leave_D3(struct device *dev)
if (brcmf_pcie_send_mb_data(devinfo, BRCMF_H2D_HOST_D0_INFORM))
goto cleanup;
brcmf_dbg(PCIE, "Hot resume, continue....\n");
+ brcmf_pcie_ds_end_suspend(devinfo);
brcmf_pcie_select_core(devinfo, BCMA_CORE_PCIE2);
brcmf_bus_change_state(bus, BRCMF_BUS_UP);
brcmf_pcie_intr_enable(devinfo);
--
2.56.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-27 17:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 17:35 [PATCH wireless-next v3 0/5] wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 1/5] wifi: brcmfmac: pcie: set the state before D0_INFORM on resume Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 2/5] wifi: brcmfmac: pcie: skip the host ready doorbell at init on the BCM4364 Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 3/5] wifi: brcmfmac: pcie: probe again after a resume through firmware Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 4/5] wifi: brcmfmac: msgbuf: do not wait for tx status on the BCM4377 Andre Eikmeyer
2026-11-27 17:35 ` [PATCH wireless-next v3 5/5] wifi: brcmfmac: pcie: support inband device wake and deep sleep Andre Eikmeyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®