wifi: rtw89: 8852be: add .shutdown callback to quiesce device on reboot
Subsystems (2)
PATCH 1/1 wifi: rtw89: 8852be: add .shutdown callback to quiesce device on reboot
From: "Yuhang.chen" <[email protected]>
Since hardware rfkill polling was introduced, warm reboot on arm64 platforms can panic with an asynchronous SError when the rfkill poll workqueue reads a register while the PCIe link is being torn down:
SError Interrupt on CPU8, code 0x00000000be000011 -- SError
Workqueue: events_power_efficient rfkill_poll [rfkill]
Call trace:
rtw89_pci_ops_read8+0x94/0x160 [rtw89_pci]
rtw89_core_rfkill_poll+0x50/0x1e0 [rtw89_core]
rtw89_ops_rfkill_poll+0x40/0x68 [rtw89_core]
ieee80211_rfkill_poll+0x3c/0x70 [mac80211]
cfg80211_rfkill_poll+0x40/0x2a0 [cfg80211]
rfkill_poll+0x30/0x88 [rfkill]
Kernel panic - not syncing: Asynchronous SError InterruptDuring device_shutdown() the 8852BE PCI driver has no .shutdown callback, so the device is never quiesced and the rfkill polling keeps running. Once the platform brings the PCIe link down, the next MMIO read targets a non-responding device and is reported as an asynchronous SError, which is fatal on arm64.
Add a .shutdown callback that runs the existing remove path to stop the rfkill polling, free interrupts and power down the chip before the link goes away. A NULL drvdata check guards the case where probe did not fully complete.
--- drivers/net/wireless/realtek/rtw89/rtw8852be.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/wireless/realtek/rtw89/rtw8852be.c +9 -0
@@ -92,11 +92,20 @@ static const struct pci_device_id rtw89_8852be_id_table[] = { };MODULE_DEVICE_TABLE (pci, rtw89_8852be_id_table); +static void rtw89_8852be_shutdown (struct pci_dev *pdev) +{ +if (!pci_get_drvdata (pdev)) +return ; + +rtw89_pci_remove (pdev); +} +static struct pci_driver rtw89_8852be_driver = { .name ="rtw89_8852be" , .id_table = rtw89_8852be_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_8852be_shutdown, .driver.pm = &rtw89_pm_ops, .err_handler = &rtw89_pci_err_handler, };
Signature · 1 line
2.34.1
Ping-Ke Shih
maintainerQuoted 5 lines · [email protected] <[email protected]> wrote:
From: "Yuhang.chen" <[email protected]>
Since hardware rfkill polling was introduced, warm reboot on arm64 platforms can panic with an asynchronous SError when the rfkill poll workqueue reads a register while the PCIe link is being torn down:
Does it mean the work is running after .shutdown but before .remove?
Quoted 36 lines
SError Interrupt on CPU8, code
0x00000000be000011-- SErrorWorkqueue: events_power_efficient rfkill_poll [rfkill] Call trace: rtw89_pci_ops_read8+0x94/0x160 [rtw89_pci] rtw89_core_rfkill_poll+0x50/0x1e0 [rtw89_core] rtw89_ops_rfkill_poll+0x40/0x68 [rtw89_core] ieee80211_rfkill_poll+0x3c/0x70 [mac80211] cfg80211_rfkill_poll+0x40/0x2a0 [cfg80211] rfkill_poll+0x30/0x88 [rfkill] Kernel panic - not syncing: Asynchronous SError InterruptDuring
device_shutdown()the 8852BE PCI driver has no .shutdown callback, so the device is never quiesced and the rfkill polling keeps running. Once the platform brings the PCIe link down, the next MMIO read targets a non-responding device and is reported as an asynchronous SError, which is fatal on arm64.Add a .shutdown callback that runs the existing remove path to stop the rfkill polling, free interrupts and power down the chip before the link goes away. A NULL drvdata check guards the case where probe did not fully complete.
Fixes 0b38e6277aed ("wifi: rtw89: add support for hardware rfkill")Signed-off-by Yuhang.chen <[email protected]>--- drivers/net/wireless/realtek/rtw89/rtw8852be.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/net/wireless/realtek/rtw89/rtw8852be.c +0
-0
drivers/net/wireless/realtek/rtw89/rtw8852be.c static const struct pci_device_id rtw89_8852be_id_table[] = { · line 100
Quoted 9 lines
drivers/net/wireless/realtek/rtw89/rtw8852be.c +6
-0@@ -92,11 +92,20 @@ static const struct pci_device_id rtw89_8852be_id_table[] = { };MODULE_DEVICE_TABLE (pci, rtw89_8852be_id_table); +static void rtw89_8852be_shutdown (struct pci_dev *pdev) +{ +if (!pci_get_drvdata (pdev)) +return ; + +rtw89_pci_remove (pdev);
Not prefer calling rtw89_pci_remove() twice.
I think we can add a callback .rtw89_pci_shutdown() to set a flag RTW89_FLAG_SHUTDOWN. In rtw89_ops_rfkill_poll(), just ignore polling, like:
@@ -2010,7 +2010,8 @@ static void rtw89_ops_rfkill_poll(struct ieee80211_hw *hw)
lockdep_assert_wiphy(hw->wiphy);
/* wl_disable GPIO get floating when entering LPS */
- if (test_bit(RTW89_FLAG_RUNNING, rtwdev->flags))
+ if (test_bit(RTW89_FLAG_RUNNING, rtwdev->flags) ||
+ test_bit(RTW89_FLAG_SHUTDOWN, rtwdev->flags))
return;
rtw89_core_rfkill_poll(rtwdev, false);This flag is very similar to USB RTW89_FLAG_UNPLUGGED flag, but I'd add a new flag.
drivers/net/wireless/realtek/rtw89/rtw8852be.c static const struct pci_device_id rtw89_8852be_id_table[] = { · line 108
Quoted 8 lines
drivers/net/wireless/realtek/rtw89/rtw8852be.c +3
-0+} +static struct pci_driver rtw89_8852be_driver = { .name ="rtw89_8852be" , .id_table = rtw89_8852be_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_8852be_shutdown,
I think this fix can apply to all PCI devices for this driver, right?
Quoted 5 lines
drivers/net/wireless/realtek/rtw89/rtw8852be.c +0
-1.driver.pm = &rtw89_pm_ops, .err_handler = &rtw89_pci_err_handler, }; --2.34.1
Hi Ping-Ke,
Thanks for the review.
Quoted 1 line
Does it mean the work is running after .shutdown but before .remove?
On the reboot/poweroff path the kernel only runs device_shutdown(), which invokes each driver's .shutdown callback; .remove is *not* called on this path -- it only runs on driver unbind, module unload or hot-unplug. The rfkill polling workqueue, however, keeps being scheduled by the rfkill core throughout the whole shutdown sequence until the system finally halts. During that window the platform starts tearing the PCIe link down, and the next MMIO read issued by rtw89_ops_rfkill_poll() then targets a non-responding device, which on arm64 is reported as a fatal asynchronous SError. So it is not ".remove after .shutdown"; .remove never runs on reboot -- the poll work simply outlives the link, and that is exactly what the new flag stops.
Quoted 1 line
Not prefer calling
rtw89_pci_remove()twice.
Agreed. In v2 I dropped the rtw89_pci_remove() call from .shutdown and switched to the flag-based approach you suggested:
* add rtw89_pci_shutdown() that sets a new RTW89_FLAG_SHUTDOWN flag
(mirroring the USB RTW89_FLAG_UNPLUGGED pattern);
* make rtw89_ops_rfkill_poll() bail out early when that flag is set, so no MMIO read reaches the chip after shutdown begins.
This keeps the shutdown handler minimal and avoids running the non-idempotent teardown twice.
Quoted 1 line
I think this fix can apply to all PCI devices for this driver, right?
Yes, agreed. v2 wires .shutdown = rtw89_pci_shutdown into all rtw89 PCI device drivers (8851BE/8852AE/8852BE/8852BTE/8852CE/8922AE/8922DE), so the subject prefix is now "wifi: rtw89: pci: ...".
v2 is sent as a reply to this thread.
Thanks,
Yuhang
Ping-Ke Shih
maintainerQuoted 6 lines · [email protected] <[email protected]> wrote:
Hi Ping-Ke,
Thanks for the review.
Quoted 1 line
Does it mean the work is running after .shutdown but before .remove?
Quoted 11 lines
On the reboot/poweroff path the kernel only runs
device_shutdown(), which invokes each driver's .shutdown callback; .remove is *not* called on this path -- it only runs on driver unbind, module unload or hot-unplug. The rfkill polling workqueue, however, keeps being scheduled by the rfkill core throughout the whole shutdown sequence until the system finally halts. During that window the platform starts tearing the PCIe link down, and the next MMIO read issued byrtw89_ops_rfkill_poll()then targets a non-responding device, which on arm64 is reported as a fatal asynchronous SError. So it is not ".remove after .shutdown"; .remove never runs on reboot -- the poll work simply outlives the link, and that is exactly what the new flag stops.
Thanks for the detail.
Ping-Ke
PATCH v2 1/1 wifi: rtw89: pci: add .shutdown callback to stop rfkill polling on reboot
In reply to Ping-Ke ShihFrom: "Yuhang.chen" <[email protected]>
Since the hardware rfkill polling was introduced, arm64 platforms can panic with an asynchronous SError during warm reboot:
SError Interrupt on CPU8, code 0x00000000be000011 -- SError
Workqueue: events_power_efficient rfkill_poll [rfkill]
rtw89_pci_ops_read8+0x94/0x160 [rtw89_pci]
rtw89_core_rfkill_poll+0x50/0x1e0 [rtw89_core]
rtw89_ops_rfkill_poll+0x40/0x68 [rtw89_core]
ieee80211_rfkill_poll+0x3c/0x70 [mac80211]
cfg80211_rfkill_poll+0x40/0x2a0 [cfg80211]
rfkill_poll+0x30/0x88 [rfkill]
Kernel panic - not syncing: Asynchronous SError InterruptOn the reboot path the kernel only runs device_shutdown(), which calls each driver's .shutdown callback; .remove is not invoked. The rtw89 PCI driver had no .shutdown callback, so nothing stopped the rfkill polling work while the platform was tearing the PCIe link down. Once the link is gone, the next MMIO read from the poll handler targets a non-responding device and is reported as a fatal asynchronous SError on arm64.
Add rtw89_pci_shutdown(), wired to all rtw89 PCI device drivers, which sets a new RTW89_FLAG_SHUTDOWN flag (mirroring the USB RTW89_FLAG_UNPLUGGED pattern). When the flag is set, rtw89_ops_rfkill_poll() returns early, so no MMIO read is issued to the chip after shutdown begins and the SError no longer occurs.
This does not call the full .remove path from .shutdown, to keep the shutdown handler minimal and avoid running the non-idempotent teardown twice.
---
v2: per Ping-Ke Shih's review [1], replace the rtw89_pci_remove() call
from .shutdown with a flag-based approach (set RTW89_FLAG_SHUTDOWN and bail out early in rtw89_ops_rfkill_poll), and extend the fix to all rtw89 PCI device drivers instead of 8852BE only.
[1] https://lore.kernel.org/all/[email protected]/
--- drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/mac80211.c | 3 ++- drivers/net/wireless/realtek/rtw89/pci.c | 13 +++++++++++++ drivers/net/wireless/realtek/rtw89/pci.h | 1 + drivers/net/wireless/realtek/rtw89/rtw8851be.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8852ae.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8852be.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8852bte.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8852ce.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8922ae.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8922de.c | 1 + 11 files changed, 24 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/core.h +1 -0
@@ -5373,6 +5373,7 @@ enum rtw89_flags {RTW89_FLAG_CHANGING_INTERFACE ,RTW89_FLAG_HW_RFKILL_STATE ,RTW89_FLAG_UNPLUGGED , +RTW89_FLAG_SHUTDOWN , NUM_OF_RTW89_FLAGS, };
drivers/net/wireless/realtek/rtw89/mac80211.c +2 -1
@@ -1979,7 +1979,8 @@ static void rtw89_ops_rfkill_poll(struct ieee80211_hw *hw)lockdep_assert_wiphy (hw->wiphy);/* wl_disable GPIO get floating when entering LPS */ -if (test_bit (RTW89_FLAG_RUNNING , rtwdev->flags)) +if (test_bit (RTW89_FLAG_RUNNING , rtwdev->flags) || +test_bit (RTW89_FLAG_SHUTDOWN , rtwdev->flags))return ;rtw89_core_rfkill_poll (rtwdev, false);
drivers/net/wireless/realtek/rtw89/pci.c +13 -0
@@ -4874,6 +4874,19 @@ void rtw89_pci_remove(struct pci_dev *pdev) }EXPORT_SYMBOL (rtw89_pci_remove); +void rtw89_pci_shutdown (struct pci_dev *pdev) +{ +struct ieee80211_hw *hw =pci_get_drvdata (pdev); +struct rtw89_dev *rtwdev; + +if (!hw) +return ; + + rtwdev = hw->priv; +set_bit (RTW89_FLAG_SHUTDOWN , rtwdev->flags); +} +EXPORT_SYMBOL (rtw89_pci_shutdown); +MODULE_AUTHOR ("Realtek Corporation" );MODULE_DESCRIPTION ("Realtek PCI 802.11ax wireless driver" );MODULE_LICENSE ("Dual BSD/GPL" );
drivers/net/wireless/realtek/rtw89/pci.h +1 -0
@@ -1751,6 +1751,7 @@ struct pci_device_id;int rtw89_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id);void rtw89_pci_remove (struct pci_dev *pdev); +void rtw89_pci_shutdown (struct pci_dev *pdev);void rtw89_pci_basic_cfg (struct rtw89_dev *rtwdev,bool resume);void rtw89_pci_ops_reset (struct rtw89_dev *rtwdev);int rtw89_pci_ltr_set (struct rtw89_dev *rtwdev,bool en);
drivers/net/wireless/realtek/rtw89/rtw8851be.c +1 -0
@@ -93,6 +93,7 @@ static struct pci_driver rtw89_8851be_driver = { .id_table = rtw89_8851be_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_pci_shutdown, .driver.pm = &rtw89_pm_ops, .err_handler = &rtw89_pci_err_handler, };
drivers/net/wireless/realtek/rtw89/rtw8852ae.c +1 -0
@@ -95,6 +95,7 @@ static struct pci_driver rtw89_8852ae_driver = { .id_table = rtw89_8852ae_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_pci_shutdown, .driver.pm = &rtw89_pm_ops, .err_handler = &rtw89_pci_err_handler, };
drivers/net/wireless/realtek/rtw89/rtw8852be.c +1 -0
@@ -97,6 +97,7 @@ static struct pci_driver rtw89_8852be_driver = { .id_table = rtw89_8852be_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_pci_shutdown, .driver.pm = &rtw89_pm_ops, .err_handler = &rtw89_pci_err_handler, };
drivers/net/wireless/realtek/rtw89/rtw8852bte.c +1 -0
@@ -99,6 +99,7 @@ static struct pci_driver rtw89_8852bte_driver = { .id_table = rtw89_8852bte_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_pci_shutdown, .driver.pm = &rtw89_pm_ops, .err_handler = &rtw89_pci_err_handler, };
drivers/net/wireless/realtek/rtw89/rtw8852ce.c +1 -0
@@ -122,6 +122,7 @@ static struct pci_driver rtw89_8852ce_driver = { .id_table = rtw89_8852ce_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_pci_shutdown, .driver.pm = &rtw89_pm_ops, .err_handler = &rtw89_pci_err_handler, };
drivers/net/wireless/realtek/rtw89/rtw8922ae.c +1 -0
@@ -111,6 +111,7 @@ static struct pci_driver rtw89_8922ae_driver = { .id_table = rtw89_8922ae_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_pci_shutdown, .driver.pm = &rtw89_pm_ops_be, .err_handler = &rtw89_pci_err_handler, };
drivers/net/wireless/realtek/rtw89/rtw8922de.c +1 -0
@@ -111,6 +111,7 @@ static struct pci_driver rtw89_8922de_driver = { .id_table = rtw89_8922de_id_table, .probe = rtw89_pci_probe, .remove = rtw89_pci_remove, + .shutdown = rtw89_pci_shutdown, .driver.pm = &rtw89_pm_ops_be, .err_handler = &rtw89_pci_err_handler, };
Signature · 1 line
2.34.1
RE: [PATCH v2] wifi: rtw89: pci: add .shutdown callback to stop rfkill polling on reboot
Quoted 29 lines · [email protected] <[email protected]> wrote:
From: "Yuhang.chen" <[email protected]>
Since the hardware rfkill polling was introduced, arm64 platforms can panic with an asynchronous SError during warm reboot:
SError Interrupt on CPU8, code
0x00000000be000011-- SErrorWorkqueue: events_power_efficient rfkill_poll [rfkill] rtw89_pci_ops_read8+0x94/0x160 [rtw89_pci] rtw89_core_rfkill_poll+0x50/0x1e0 [rtw89_core] rtw89_ops_rfkill_poll+0x40/0x68 [rtw89_core] ieee80211_rfkill_poll+0x3c/0x70 [mac80211] cfg80211_rfkill_poll+0x40/0x2a0 [cfg80211] rfkill_poll+0x30/0x88 [rfkill] Kernel panic - not syncing: Asynchronous SError InterruptOn the reboot path the kernel only runs
device_shutdown(), which calls each driver's .shutdown callback; .remove is not invoked. The rtw89 PCI driver had no .shutdown callback, so nothing stopped the rfkill polling work while the platform was tearing the PCIe link down. Once the link is gone, the next MMIO read from the poll handler targets a non-responding device and is reported as a fatal asynchronous SError on arm64.Add
rtw89_pci_shutdown(), wired to all rtw89 PCI device drivers, which sets a newRTW89_FLAG_SHUTDOWNflag (mirroring the USBRTW89_FLAG_UNPLUGGEDpattern). When the flag is set,rtw89_ops_rfkill_poll()returns early, so no MMIO read is issued to the chip after shutdown begins and the SError no longer occurs.
Quoted 8 lines
This does not call the full .remove path from .shutdown, to keep the shutdown handler minimal and avoid running the non-idempotent teardown twice.
Fixes 0b38e6277aed ("wifi: rtw89: add support for hardware rfkill")Suggested-by Ping-Ke Shih <[email protected]>Signed-off-by Yuhang.chen <[email protected]>
Ping-Ke Shih
maintainerRe: [PATCH v2] wifi: rtw89: pci: add .shutdown callback to stop rfkill polling on reboot
In reply to [email protected]Quoted 33 lines · [email protected] wrote:
From: "Yuhang.chen" <[email protected]>
Since the hardware rfkill polling was introduced, arm64 platforms can panic with an asynchronous SError during warm reboot:
SError Interrupt on CPU8, code
0x00000000be000011-- SErrorWorkqueue: events_power_efficient rfkill_poll [rfkill] rtw89_pci_ops_read8+0x94/0x160 [rtw89_pci] rtw89_core_rfkill_poll+0x50/0x1e0 [rtw89_core] rtw89_ops_rfkill_poll+0x40/0x68 [rtw89_core] ieee80211_rfkill_poll+0x3c/0x70 [mac80211] cfg80211_rfkill_poll+0x40/0x2a0 [cfg80211] rfkill_poll+0x30/0x88 [rfkill] Kernel panic - not syncing: Asynchronous SError InterruptOn the reboot path the kernel only runs
device_shutdown(), which calls each driver's .shutdown callback; .remove is not invoked. The rtw89 PCI driver had no .shutdown callback, so nothing stopped the rfkill polling work while the platform was tearing the PCIe link down. Once the link is gone, the next MMIO read from the poll handler targets a non-responding device and is reported as a fatal asynchronous SError on arm64.Add
rtw89_pci_shutdown(), wired to all rtw89 PCI device drivers, which sets a newRTW89_FLAG_SHUTDOWNflag (mirroring the USBRTW89_FLAG_UNPLUGGEDpattern). When the flag is set,rtw89_ops_rfkill_poll()returns early, so no MMIO read is issued to the chip after shutdown begins and the SError no longer occurs.This does not call the full .remove path from .shutdown, to keep the shutdown handler minimal and avoid running the non-idempotent teardown twice.
Quoted 5 lines
Fixes 0b38e6277aed ("wifi: rtw89: add support for hardware rfkill")Suggested-by Ping-Ke Shih <[email protected]>Signed-off-by Yuhang.chen <[email protected]>Acked-by Ping-Ke Shih <[email protected]>
1 patch(es) applied to rtw-next branch of rtw.git, thanks.
667c12782aaf wifi: rtw89: pci: add .shutdown callback to stop rfkill polling on reboot