wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips
v3 cover wifi: brcmfmac: pcie: S3 and deep sleep on the T2 Mac chips
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/[email protected]/
[2] v1: https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
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
Signature · 1 line
2.56.0
PATCH v3 1/5 wifi: brcmfmac: pcie: set the state before D0_INFORM on resume
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.
--- drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +2 -1
@@ -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;
Signature · 1 line
2.56.0
PATCH v3 2/5 wifi: brcmfmac: pcie: skip the host ready doorbell at init on the BCM4364
In reply to Andre EikmeyerWith 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.
--- .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +11 -2
@@ -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 ;
Signature · 1 line
2.56.0
PATCH v3 3/5 wifi: brcmfmac: pcie: probe again after a resume through firmware
In reply to Andre EikmeyerAfter 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.
--- .../net/wireless/broadcom/brcm80211/brcmfmac/pcie.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +12 -0
@@ -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" );
Signature · 1 line
2.56.0
PATCH v3 4/5 wifi: brcmfmac: msgbuf: do not wait for tx status on the BCM4377
In reply to Andre EikmeyerThe 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.
--- .../net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +8 -2
@@ -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--; }
Signature · 1 line
2.56.0
PATCH v3 5/5 wifi: brcmfmac: pcie: support inband device wake and deep sleep
In reply to Andre EikmeyerThe 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.
--- .../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(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.c +14 -0
@@ -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); }
drivers/net/wireless/broadcom/brcm80211/brcmfmac/commonring.h +5 -0
@@ -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);
drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +292 -3
403 lines not on this page · raw message
Signature · 1 line
2.56.0