wifi: rtw89: usb: keep the endpoints until the driver lets go on unbind
PATCH 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 disables the interface's endpoints and kills their URBs before it calls the disconnect method, unless the driver sets soft_unbind. rtw89_core_unregister() then still deauthenticates, flushes the queues and stops the chip, but the bulk endpoints that carry H2C and C2H are already gone. On an RTL8922AU with an association, every unload logged:
c2h reg timeout
timed out to flush queues (3 times)
read HWSI is busy (18 times)
Set soft_unbind for the USB drivers, and in rtw89_usb_disconnect() unregister before cancelling the RX and TX URBs while the device is still attached. After an unplug the device is gone, so the order stays as it was; usbcore disables the endpoints first in that case (state NOTATTACHED) whether soft_unbind is set or not.
Tested on an RTL8922AU (a USB 2 adapter) with the out-of-tree copy of this driver (morrownr/rtw89, which carries rtw-next as of 2026-11-05), kernels 7.1.5 and 7.2.15. Every unload while associated now logs only the deauthentication and "deregistering interface driver", with no warnings. A physical unplug while associated logs what it logged before (the messages above), with no warnings and nothing stuck. Reordering rtw89_usb_disconnect() without soft_unbind changed nothing. The other USB chips share rtw89_usb_disconnect() but were not tested.
The problem was found with Claude Code (Claude Opus 5.5) while testing the driver, and this change and 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 | 17 ++++++++++++++--- 6 files changed, 19 insertions(+), 3 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
@@ -84,6 +84,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
@@ -91,6 +91,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 +14 -3
@@ -1314,10 +1314,21 @@ void rtw89_usb_disconnect(struct usb_interface *intf) rtwdev = hw->priv; rtwusb =rtw89_usb_priv (rtwdev); -rtw89_usb_cancel_rx_bufs (rtwusb); -rtw89_usb_cancel_tx_bufs (rtwusb); +/* After an unplug the device is gone, so stop the transfers first. When +* the driver is unbound from a device that is still attached (rmmod), +* rtw89_core_unregister() still talks to the firmware and needs the RX +* transfers for the replies. +*/ +if (rtwusb->udev->state ==USB_STATE_NOTATTACHED ) { +rtw89_usb_cancel_rx_bufs (rtwusb); +rtw89_usb_cancel_tx_bufs (rtwusb); +rtw89_core_unregister (rtwdev); + }else { +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: dc16902cad9c6b08df9395a510c7be44fbab545d
Signature · 1 line
2.53.0
Ping-Ke Shih
maintainerQuoted 11 lines · rcfa
When the driver is unbound from a device that is still attached (rmmod, or an unbind through sysfs), usbcore disables the interface's endpoints and kills their URBs before it calls the disconnect method, unless the driver sets
soft_unbind.rtw89_core_unregister()then still deauthenticates, flushes the queues and stops the chip, but the bulk endpoints that carry H2C and C2H are already gone. On an RTL8922AU with an association, every unload logged:c2h reg timeout
timed out to flush queues (3 times)
read HWSI is busy (18 times)
Is this because sending deauth frames?
Quoted 6 lines
Set
soft_unbindfor the USB drivers, and inrtw89_usb_disconnect()unregister before cancelling the RX and TX URBs while the device is still attached. After an unplug the device is gone, so the order stays as it was; usbcore disables the endpoints first in that case (state NOTATTACHED) whethersoft_unbindis set or not.
With soft_unbind=1, is it enough? Can we just one calling odrer?
Quoted 9 lines
Tested on an RTL8922AU (a USB 2 adapter) with the out-of-tree copy of this driver (morrownr/rtw89, which carries rtw-next as of 2026-11-05), kernels 7.1.5 and 7.2.15. Every unload while associated now logs only the deauthentication and "deregistering interface driver", with no warnings. A physical unplug while associated logs what it logged before (the messages above), with no warnings and nothing stuck. Reordering
rtw89_usb_disconnect()withoutsoft_unbindchanged nothing. The other USB chips sharertw89_usb_disconnect()but were not tested.
Only need " Tested on an RTL8922AU (a USB 2 adapter)". Putting others after your s-o-b with "---" delimiter.
Quoted 4 lines
The problem was found with Claude Code (Claude Opus 5.5) while testing the driver, and this change and changelog were written in the same session.
To disclose LLM use, put this in additional note area.
Quoted 2 lines
Fixes 2135c28be6a8 ("wifi: rtw89: Add usb.{c,h}")
I don't think it touch chips, and it isn't not a severe problem.
Quoted 1 line
Signed-off-by rcfa <[email protected]>
Please use your real name.
---
(Put additional note/comment here)
Quoted 9 lines
--- 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 | 17 ++++++++++++++--- 6 files changed, 19 insertions(+), 3 deletions(-)