wifi: rtw89: usb: keep the endpoints until the driver lets go on unbind
PATCH v2 1/1 wifi: rtw89: usb: keep the endpoints until the driver lets go on unbind
When the driver is unbound from a device that is still attached (rmmod, or an unbind through sysfs), usbcore kills the URBs of the interface's endpoints before it calls the disconnect method, unless the driver sets soft_unbind; and rtw89_usb_disconnect() cancels the RX and TX URBs itself before it calls rtw89_core_unregister(). Whatever rtw89_core_unregister() still asks of the chip then fails. On an RTL8922AU, an unload while associated logs:
c2h reg timeout
timed out to flush queues (3 times)
read HWSI is busy (18 times)
and an unload with no association, while a scan runs:
rtw89_hw_scan_offload failed ret -110
read HWSI is busy (18 times)
failed to wait RF TSSI (2 times)
Set soft_unbind for the USB drivers, and unregister before cancelling the URBs.
Tested on an RTL8922AU (a USB 2 adapter).
---
Notes:
v2:
- One calling order in rtw89_usb_disconnect(): unregister, then cancel the URBs, after an unplug too (v1 kept the old order for a device in USB_STATE_NOTATTACHED).
- Commit message reduced to the problem, the log and the test line, without the Fixes tag, as asked; the rest follows here.
- Rebased on rtw-next ae6b9e98b904.
On the name: rcfa is the name I sign with everywhere, and it is my GitHub identity (https://github.com/rcfa), where the out-of-tree side of this rtw89 work is public, e.g. morrownr/rtw89 pull requests #139 and #141. submitting-patches.rst asks for "a known identity" (since d4563201f33a, 2023), not a legal name. I hope that is acceptable.
v1: https://lore.kernel.org/linux-wireless/[email protected]/
You asked whether this comes from sending the deauth frames. Not only:
unloading the unchanged driver with no association, so with no deauthentication, still logs the HWSI and RF TSSI errors and a scan abort that times out. The deauthentication adds the three flush timeouts, because its frame cannot be sent. Whatever rtw89_core_unregister() asks of the chip fails, because the URBs are gone by then.
You also asked whether soft_unbind alone is enough, and whether one calling order would do. soft_unbind alone is not enough: with the old order an unload logs the same as without it, associated or not, because rtw89_usb_disconnect() then cancels the URBs itself before rtw89_core_unregister(). The reorder without soft_unbind did not help either (tested for v1). One calling order does work; see below.
Test details: the out-of-tree copy of this driver (morrownr/rtw89, which carries rtw-next as of 2026-11-05; hence the module name in the log), kernel 7.2.15, IPS off before each unload. Time of the rmmod and the kernel lines after "deregistering interface driver":
associated not associated
unchanged 2.2, 2.4 s: errors 1.6, 1.6 s: errors
soft_unbind only 2.6, 2.2 s: errors 1.5 s: errors
this patch 1.9, 1.1 s: deauth (*) 1.0 s: nothing
(*) The first of these also logged one "rtw89_hw_scan_offload failed ret -110" and nothing else: a scan was running at the unload, and its abort timed out. v1, which runs the same code on an rmmod, did not log it in three unloads.
Unplugging the adapter while associated, with this patch: the disconnect took 1.3 s and logged one "c2h reg timeout", three "timed out to flush queues" and 18 "read HWSI is busy", with no warnings and no task stuck. v1's unplug (2026-11-07), which kept the old order, logged the same lines in the same time: the device is gone by then, so these lines come with either order. Plugged back in, the adapter was probed and connected again.
The problem was found with Claude Code (Claude Opus 5.5) while testing the driver; this change and its changelog were written in the same session.
drivers/net/wireless/realtek/rtw89/rtw8851bu.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8852au.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8852bu.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8852cu.c | 1 + drivers/net/wireless/realtek/rtw89/rtw8922au.c | 1 + drivers/net/wireless/realtek/rtw89/usb.c | 6 ++++-- 6 files changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/realtek/rtw89/rtw8851bu.c +1 -0
@@ -70,6 +70,7 @@ static struct usb_driver rtw_8851bu_driver = { .id_table = rtw_8851bu_id_table, .probe = rtw8851bu_probe, .disconnect = rtw89_usb_disconnect, + .soft_unbind = 1, };module_usb_driver (rtw_8851bu_driver);
drivers/net/wireless/realtek/rtw89/rtw8852au.c +1 -0
@@ -86,6 +86,7 @@ static struct usb_driver rtw_8852au_driver = { .id_table = rtw_8852au_id_table, .probe = rtw8852au_probe, .disconnect = rtw89_usb_disconnect, + .soft_unbind = 1, };module_usb_driver (rtw_8852au_driver);
drivers/net/wireless/realtek/rtw89/rtw8852bu.c +1 -0
@@ -84,6 +84,7 @@ static struct usb_driver rtw_8852bu_driver = { .id_table = rtw_8852bu_id_table, .probe = rtw8852bu_probe, .disconnect = rtw89_usb_disconnect, + .soft_unbind = 1, };module_usb_driver (rtw_8852bu_driver);
drivers/net/wireless/realtek/rtw89/rtw8852cu.c +1 -0
@@ -145,6 +145,7 @@ static struct usb_driver rtw_8852cu_driver = { .id_table = rtw_8852cu_id_table, .probe = rtw8852cu_probe, .disconnect = rtw89_usb_disconnect, + .soft_unbind = 1, };module_usb_driver (rtw_8852cu_driver);
drivers/net/wireless/realtek/rtw89/rtw8922au.c +1 -0
@@ -93,6 +93,7 @@ static struct usb_driver rtw_8922au_driver = { .id_table = rtw_8922au_id_table, .probe = rtw8922au_probe, .disconnect = rtw89_usb_disconnect, + .soft_unbind = 1, };module_usb_driver (rtw_8922au_driver);
drivers/net/wireless/realtek/rtw89/usb.c +4 -2
@@ -1314,10 +1314,12 @@ void rtw89_usb_disconnect(struct usb_interface *intf) rtwdev = hw->priv; rtwusb =rtw89_usb_priv (rtwdev); +/* rtw89_core_unregister() still talks to the chip, so cancel the URBs +* only after it. +*/ +rtw89_core_unregister (rtwdev);rtw89_usb_cancel_rx_bufs (rtwusb);rtw89_usb_cancel_tx_bufs (rtwusb); - -rtw89_core_unregister (rtwdev);rtw89_core_deinit (rtwdev);rtw89_usb_deinit_rx (rtwdev);rtw89_usb_free_rx_bufs (rtwusb);
base-commit: ae6b9e98b9045e47f609ec2a8197a3f3109627cb
Signature · 1 line
2.53.0