Skip to contentSkip to conversation

wifi: rtw88: pci: Power off MAC and disable interrupts on shutdown

PATCH In review Swapnil Shinde 2 participants 9 messages Nov 27 – Dec 2 Realtek wireless driver (rtw88)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: rtw88: pci: Power off MAC and disable interrupts on shutdown

Currently rtw_pci_shutdown() invokes chip->ops->shutdown() and immediately transitions the device to PCI_D3hot without powering off the MAC or disabling PCI interrupts when RTW_FLAG_POWERON is active.

On RTL8723DE combo cards, leaving the MAC powered across a warm reset causes REG_APS_FSMCO polling (offset 0x5, mask 0x1) to time out with -EBUSY (-16) on the next boot. Power off the MAC under rtwdev->mutex and disable PCI interrupts before entering PCI_D3hot.

---
 drivers/net/wireless/realtek/rtw88/pci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/net/wireless/realtek/rtw88/pci.c +15 -0
index 66d2e5f51..b0bbb9397 100644
@@ -1949,14 +1949,29 @@ void rtw_pci_shutdown(struct pci_dev *pdev)
 {
 	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
 	struct rtw_dev *rtwdev;
+	struct rtw_pci *rtwpci;
 	const struct rtw_chip_info *chip;
 
 	if (!hw)
 		return;
 
 	rtwdev = hw->priv;
+	rtwpci = (struct rtw_pci *)rtwdev->priv;
 	chip = rtwdev->chip;
 
+	mutex_lock(&rtwdev->mutex);
+	if (test_bit(RTW_FLAG_POWERON, rtwdev->flags)) {
+		clear_bit(RTW_FLAG_RUNNING, rtwdev->flags);
+		clear_bit(RTW_FLAG_FW_RUNNING, rtwdev->flags);
+		rtw_power_off(rtwdev);
+		clear_bit(RTW_FLAG_POWERON, rtwdev->flags);
+	} else {
+		rtw_hci_link_ps(rtwdev, false);
+	}
+	mutex_unlock(&rtwdev->mutex);
+
+	rtw_pci_disable_interrupt(rtwdev, rtwpci);
+
 	if (chip->ops->shutdown)
 		chip->ops->shutdown(rtwdev);
 
Signature · 1 line
2.56.0
maintainer
#1 lore raw
Quoted 8 lines · Swapnil Shinde

Currently rtw_pci_shutdown() invokes chip->ops->shutdown() and immediately transitions the device to PCI_D3hot without powering off the MAC or disabling PCI interrupts when RTW_FLAG_POWERON is active.

On RTL8723DE combo cards, leaving the MAC powered across a warm reset causes REG_APS_FSMCO polling (offset 0x5, mask 0x1) to time out with -EBUSY (-16) on the next boot. Power off the MAC under rtwdev->mutex and disable PCI interrupts before entering PCI_D3hot.

IIRC the commit 05202746ed70 ("rtw88: 8723d: Add shutdown callback to disable BT USB suspend") is to fix the problem your encountered.

The later another commit 44492e70adc8 ("rtw88: pci: Power cycle device during shutdown") is to let PCI enters PCI_D3hot.

Can you revert both or either one to see if anything different?

Quoted 14 lines
---
 drivers/net/wireless/realtek/rtw88/pci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/net/wireless/realtek/rtw88/pci.c +0 -0
index 66d2e5f51..b0bbb9397 100644
@@ -1949,14 +1949,29 @@ void rtw_pci_shutdown(struct pci_dev *pdev)
 {
        struct ieee80211_hw *hw = pci_get_drvdata(pdev);
        struct rtw_dev *rtwdev;

drivers/net/wireless/realtek/rtw88/pci.c void rtw_pci_shutdown(struct pci_dev *pdev) · line 1961

Quoted 10 lines
drivers/net/wireless/realtek/rtw88/pci.c +2 -0
+       struct rtw_pci *rtwpci;
        const struct rtw_chip_info *chip;
 
        if (!hw)
                return;
 
        rtwdev = hw->priv;
+       rtwpci = (struct rtw_pci *)rtwdev->priv;
        chip = rtwdev->chip;
 

Can it just call rtw_enter_ips()?

Quoted 18 lines
drivers/net/wireless/realtek/rtw88/pci.c +13 -1
+       mutex_lock(&rtwdev->mutex);
+       if (test_bit(RTW_FLAG_POWERON, rtwdev->flags)) {
+               clear_bit(RTW_FLAG_RUNNING, rtwdev->flags);
+               clear_bit(RTW_FLAG_FW_RUNNING, rtwdev->flags);
+               rtw_power_off(rtwdev);
+               clear_bit(RTW_FLAG_POWERON, rtwdev->flags);
+       } else {
+               rtw_hci_link_ps(rtwdev, false);
+       }
+       mutex_unlock(&rtwdev->mutex);
+
+       rtw_pci_disable_interrupt(rtwdev, rtwpci);
+
        if (chip->ops->shutdown)
                chip->ops->shutdown(rtwdev);
 
--

2.56.0

#2 lore raw

Hi Ping-Ke,

Thank you for the review and suggestion.

I tested calling rtw_enter_ips(rtwdev) under rtwdev->mutex in rtw_pci_shutdown() (with EXPORT_SYMBOL(rtw_enter_ips) added in ps.c, running alongside the companion btusb shutdown/autosuspend fix) on my RTL8723DE laptop:

- Cold boot: Wi-Fi and Bluetooth both work.
- Warm reboot #1 (Wi-Fi ON, Bluetooth ON): Both Wi-Fi and Bluetooth work.
- Warm reboot #2 (Bluetooth toggled OFF mid-session, Wi-Fi ON): Both Wi-Fi and Bluetooth work cleanly (no -16 MAC power-on timeout or -71 USB enumeration error).

Using rtw_enter_ips() is indeed much cleaner than manually clearing the internal flags and calling rtw_power_off(), and it also notifies BT coex via COEX_IPS_ENTER before entering PCI_D3hot.

Regarding commits 05202746ed70 and 44492e70adc8:
- 05202746ed70 sets BIT_USB_SUS_DIS in REG_HCI_OPT_CTRL, which does not power off the Wi-Fi MAC before 44492e70adc8 transitions the device to PCI_D3hot—leaving REG_APS_FSMCO active across warm reset (-EBUSY).
- Calling rtw_enter_ips() right before pci_set_power_state(pdev, PCI_D3hot) cleanly resolves that while keeping both commits intact.

Would you like me to send a [PATCH v2] that exports rtw_enter_ips() in ps.c and calls it from rtw_pci_shutdown() in pci.c?

Best regards,
Swapnil

Quoted 66 lines · Ping-Ke Shih
Quoted 8 lines · Swapnil Shinde

Currently rtw_pci_shutdown() invokes chip->ops->shutdown() and immediately transitions the device to PCI_D3hot without powering off the MAC or disabling PCI interrupts when RTW_FLAG_POWERON is active.

On RTL8723DE combo cards, leaving the MAC powered across a warm reset causes REG_APS_FSMCO polling (offset 0x5, mask 0x1) to time out with -EBUSY (-16) on the next boot. Power off the MAC under rtwdev->mutex and disable PCI interrupts before entering PCI_D3hot.

IIRC the commit 05202746ed70 ("rtw88: 8723d: Add shutdown callback to disable BT USB suspend") is to fix the problem your encountered.

The later another commit 44492e70adc8 ("rtw88: pci: Power cycle device during shutdown") is to let PCI enters PCI_D3hot.

Can you revert both or either one to see if anything different?

Quoted 14 lines
---
 drivers/net/wireless/realtek/rtw88/pci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/net/wireless/realtek/rtw88/pci.c +0 -0
index 66d2e5f51..b0bbb9397 100644
@@ -1949,14 +1949,29 @@ void rtw_pci_shutdown(struct pci_dev *pdev)
 {
        struct ieee80211_hw *hw = pci_get_drvdata(pdev);
        struct rtw_dev *rtwdev;

drivers/net/wireless/realtek/rtw88/pci.c void rtw_pci_shutdown(struct pci_dev *pdev) · line 1961

Quoted 10 lines
drivers/net/wireless/realtek/rtw88/pci.c +2 -0
+       struct rtw_pci *rtwpci;
        const struct rtw_chip_info *chip;
 
        if (!hw)
                return;
 
        rtwdev = hw->priv;
+       rtwpci = (struct rtw_pci *)rtwdev->priv;
        chip = rtwdev->chip;
 

Can it just call rtw_enter_ips()?

Quoted 18 lines
drivers/net/wireless/realtek/rtw88/pci.c +13 -1
+       mutex_lock(&rtwdev->mutex);
+       if (test_bit(RTW_FLAG_POWERON, rtwdev->flags)) {
+               clear_bit(RTW_FLAG_RUNNING, rtwdev->flags);
+               clear_bit(RTW_FLAG_FW_RUNNING, rtwdev->flags);
+               rtw_power_off(rtwdev);
+               clear_bit(RTW_FLAG_POWERON, rtwdev->flags);
+       } else {
+               rtw_hci_link_ps(rtwdev, false);
+       }
+       mutex_unlock(&rtwdev->mutex);
+
+       rtw_pci_disable_interrupt(rtwdev, rtwpci);
+
        if (chip->ops->shutdown)
                chip->ops->shutdown(rtwdev);
 
--

2.56.0

maintainer
#3 lore raw
Quoted 9 lines · ꧁Swapnil Shinde꧂

Hi Ping-Ke,

Thank you for the review and suggestion.

I tested calling rtw_enter_ips(rtwdev) under rtwdev->mutex in rtw_pci_shutdown() (with EXPORT_SYMBOL(rtw_enter_ips) added in ps.c, running alongside the companion btusb shutdown/autosuspend fix) on my RTL8723DE laptop:

Quoted 5 lines

- Cold boot: Wi-Fi and Bluetooth both work.
- Warm reboot #1 (Wi-Fi ON, Bluetooth ON): Both Wi-Fi and Bluetooth work.
- Warm reboot #2 (Bluetooth toggled OFF mid-session, Wi-Fi ON): Both Wi-Fi and Bluetooth work cleanly (no -16 MAC power-on timeout or -71 USB enumeration error).

Good to hear that.

Quoted 9 lines

Using rtw_enter_ips() is indeed much cleaner than manually clearing the internal flags and calling rtw_power_off(), and it also notifies BT coex via COEX_IPS_ENTER before entering PCI_D3hot.

Regarding commits 05202746ed70 and 44492e70adc8:
- 05202746ed70 sets BIT_USB_SUS_DIS in REG_HCI_OPT_CTRL, which does not power off the Wi-Fi MAC before 44492e70adc8 transitions the device to PCI_D3hot—leaving REG_APS_FSMCO active across warm reset (-EBUSY).

So both or either one commit don't help?

Quoted 5 lines

- Calling rtw_enter_ips() right before pci_set_power_state(pdev, PCI_D3hot) cleanly resolves that while keeping both commits intact.

Would you like me to send a [PATCH v2] that exports rtw_enter_ips() in ps.c and calls it from rtw_pci_shutdown() in pci.c?

If this is the only way to fix, please.

---

pw-bot: cr

#4 lore raw

PATCH v2 1/1 wifi: rtw88: pci: Enter IPS before PCI_D3hot on shutdown

In reply to Swapnil Shinde

Currently rtw_pci_shutdown() invokes chip->ops->shutdown() and immediately transitions the device to PCI_D3hot without stopping the firmware/MAC or notifying Bluetooth coexistence when RTW_FLAG_POWERON is active.

On RTL8723DE combo cards, leaving the MAC active across a warm reset causes REG_APS_FSMCO polling (offset 0x5, mask 0x1) to time out with -EBUSY (-16) on the next boot. Export rtw_enter_ips() and invoke it under rtwdev->mutex before entering PCI_D3hot so the driver notifies COEX_IPS_ENTER, stops the core/MAC, and enters PCIe link power save.

---
Changes in v2:
- Call rtw_enter_ips() under rtwdev->mutex instead of manually clearing internal flags and calling rtw_power_off() (suggested by Ping-Ke Shih).
- Export rtw_enter_ips() in ps.c so rtw88_pci can invoke it.
- Note on commits 05202746ed70 and 44492e70adc8: neither alone resolves the warm-reboot failure on RTL8723DE because 05202746ed70 only sets BIT_USB_SUS_DIS in REG_HCI_OPT_CTRL without powering down the Wi-Fi MAC, and 44492e70adc8 puts PCI into PCI_D3hot while the MAC is still powered on. Calling rtw_enter_ips() before PCI_D3hot fixes the MAC shutdown cleanly while keeping both commits intact.

---
 drivers/net/wireless/realtek/rtw88/pci.c | 4 ++++
 drivers/net/wireless/realtek/rtw88/ps.c  | 1 +
 2 files changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/pci.c +4 -0
index 66d2e5f..ecf954d 100644
@@ -1960,6 +1960,10 @@ void rtw_pci_shutdown(struct pci_dev *pdev)
 	if (chip->ops->shutdown)
 		chip->ops->shutdown(rtwdev);
 
+	mutex_lock(&rtwdev->mutex);
+	rtw_enter_ips(rtwdev);
+	mutex_unlock(&rtwdev->mutex);
+
 	pci_set_power_state(pdev, PCI_D3hot);
 }
 EXPORT_SYMBOL(rtw_pci_shutdown);
drivers/net/wireless/realtek/rtw88/ps.c +1 -0
index add5a20..41a13d9 100644
@@ -36,6 +36,7 @@ int rtw_enter_ips(struct rtw_dev *rtwdev)
 
 	return 0;
 }
+EXPORT_SYMBOL(rtw_enter_ips);
 
 static void rtw_restore_port_cfg_iter(void *data, struct ieee80211_vif *vif)
 {
Signature · 1 line
2.56.0
maintainer
#5 lore raw

Re: [PATCH v2] wifi: rtw88: pci: Enter IPS before PCI_D3hot on shutdown

Quoted 10 lines · Swapnil Shinde

Currently rtw_pci_shutdown() invokes chip->ops->shutdown() and immediately transitions the device to PCI_D3hot without stopping the firmware/MAC or notifying Bluetooth coexistence when RTW_FLAG_POWERON is active.

On RTL8723DE combo cards, leaving the MAC active across a warm reset causes REG_APS_FSMCO polling (offset 0x5, mask 0x1) to time out with -EBUSY (-16) on the next boot. Export rtw_enter_ips() and invoke it under rtwdev->mutex before entering PCI_D3hot so the driver notifies COEX_IPS_ENTER, stops the core/MAC, and enters PCIe link power save.

1 patch(es) applied to rtw-next branch of rtw.git, thanks.

28f426f4ef94 wifi: rtw88: pci: Enter IPS before PCI_D3hot on shutdown

---
https://github.com/pkshih/rtw.git

#6 lore raw

Re: [PATCH v2] wifi: rtw88: pci: Enter IPS before PCI_D3hot on shutdown

Hi Ping-Ke,

Thank you very much for reviewing and applying this patch to rtw-next.

Update: Extended testing showed that no rtw88 changes are needed, fixing drivers/bluetooth/btusb.c alone resolves all issues cleanly (rtw88 changes are not needed in v3).

After sending v2, I ran extended stress tests across cold boots, warm reboots, and runtime radio toggles on my RTL8723DE (10ec:d723 / 0bda:b009) combo card. Since rtw-next has not been pulled upstream yet, I wanted to transparently share the full picture so you can decide whether to keep or drop 28f426f4ef94:

1. Root cause isolated strictly to drivers/bluetooth/btusb.c (no rtw88 changes needed):
With stock rtw88 (leaving rtw_pci_shutdown() and ps.c completely untouched), modifying only drivers/bluetooth/btusb.c (.shutdown handler
+ usb_disable_autosuspend() + HCI_QUIRK_NON_PERSISTENT_SETUP) fixes all warm-reboot hangs and runtime toggle issues 100% of tested scenarios passed without touching any rtw88 files.

2. Edge cases observed during extended testing with v2:
1- Dual-radio OFF drop (when rtw_enter_ips() is in rtw_pci_shutdown()):
When 28f426f4ef94 is active alongside the btusb changes, normal boots, consecutive warm reboots, and single-radio toggles all work fine. However, if a user performs:
Cold boot -> Warm reboot -> Turn BOTH Wi-Fi and BT OFF
both interfaces drop out immediately upon turning both OFF (Bluetooth disconnects from USB and Wi-Fi ON/OFF switch becomes unresponsive until the next reboot):
rtw88_8723de 0000:02:00.0: failed to poll offset=0x5 mask=0x3 value=0x0 rtw88_8723de 0000:02:00.0: mac power on failed
usb 1-6: device not accepting address 7, error -71

With stock rtw88 (no rtw88 modifications), turning both Wi-Fi and Bluetooth OFF after a warm reboot passes repeatedly without dropping either interface.

2- Bluetooth UI toggle freeze (BT OFF -> wait >2s -> BT ON):
Without HCI_QUIRK_NON_PERSISTENT_SETUP on the btusb side, toggling Bluetooth OFF mid-session and back ON left the Bluetooth adapter frozen (Opcode 0x202f failed: -38) until reloading btusb. Adding HCI_QUIRK_NON_PERSISTENT_SETUP in btusb_probe() resolved that cleanly.

3. Full logs, test matrix, and current btusb-only patch details:
I documented the full investigation, dmesg logs, and test matrix here:
https://github.com/sudo-WearTherinG/linux-rtl8723de-driver-patch

I leave it completely up to your judgment whether 28f426f4ef94 is still worth keeping in rtw-next for general rtw88 PCI shutdown cleanliness or better dropped so rtw88 stays untouched on RTL8723DE.

V3 doesn't require any rtw88 changes and works completely fine with only btusb.c modified.

Thanks again for your time and guidance!

Best regards,
Swapnil

maintainer
#7 lore raw

RE: [PATCH v2] wifi: rtw88: pci: Enter IPS before PCI_D3hot on shutdown

Quoted 3 lines · ꧁Swapnil Shinde꧂

I leave it completely up to your judgment whether 28f426f4ef94 is still worth keeping in rtw-next for general rtw88 PCI shutdown cleanliness or better dropped so rtw88 stays untouched on RTL8723DE.

Thanks for the note.

Dropped.

Force update rtw-next, and add tag rtw-next-2026-12-02-drop-shutdown-ips as a backup.

Ping-Ke

#8 lore raw

Re: [PATCH v2] wifi: rtw88: pci: Enter IPS before PCI_D3hot on shutdown

Hi Ping-Ke,

Thank you for dropping the patch from rtw-next and for all your help and guidance throughout this investigation. I really appreciate the time you took to review it and share your suggestions.

Just a quick update: I've now submitted the standalone btusb.c v2 patch to linux-bluetooth, so the Bluetooth fix can be handled in its own subsystem without changes to rtw88.

No need to reply. I just wanted to thank you again for your help.

Best regards,
Swapnil

Quoted 16 lines · Ping-Ke Shih
Quoted 3 lines · ꧁Swapnil Shinde꧂

I leave it completely up to your judgment whether 28f426f4ef94 is still worth keeping in rtw-next for general rtw88 PCI shutdown cleanliness or better dropped so rtw88 stays untouched on RTL8723DE.

Thanks for the note.

Dropped.

Force update rtw-next, and add tag rtw-next-2026-12-02-drop-shutdown-ips as a backup.

Ping-Ke