Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH rtw-next v2] wifi: rtw89: usb: keep the endpoints until the driver lets go on unbind
@ 2026-12-02  8:21 rcfa
  0 siblings, 0 replies; only message in thread
From: rcfa @ 2026-12-02  8:21 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless, Bitterblue Smith, kernel

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).

Signed-off-by: rcfa <kernel@cubiculum.net>
---

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/20261107230547.3673679-1-kernel@cubiculum.net/
    
    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(-)

diff --git a/drivers/net/wireless/realtek/rtw89/rtw8851bu.c b/drivers/net/wireless/realtek/rtw89/rtw8851bu.c
index 6672ebe68f17..e89d5dd05fc8 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8851bu.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8851bu.c
@@ -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);
 
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852au.c b/drivers/net/wireless/realtek/rtw89/rtw8852au.c
index ea465d7f8329..2862fab49c06 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852au.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852au.c
@@ -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);
 
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852bu.c b/drivers/net/wireless/realtek/rtw89/rtw8852bu.c
index 550fc4ac7a21..9c53bc686bca 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852bu.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852bu.c
@@ -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);
 
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c
index 2e46b05b05ee..dbc2274dfc49 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8852cu.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8852cu.c
@@ -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);
 
diff --git a/drivers/net/wireless/realtek/rtw89/rtw8922au.c b/drivers/net/wireless/realtek/rtw89/rtw8922au.c
index 4a2bc1b2037f..5715decdc42b 100644
--- a/drivers/net/wireless/realtek/rtw89/rtw8922au.c
+++ b/drivers/net/wireless/realtek/rtw89/rtw8922au.c
@@ -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);
 
diff --git a/drivers/net/wireless/realtek/rtw89/usb.c b/drivers/net/wireless/realtek/rtw89/usb.c
index 8dc2c93e502e..c854f43c439b 100644
--- a/drivers/net/wireless/realtek/rtw89/usb.c
+++ b/drivers/net/wireless/realtek/rtw89/usb.c
@@ -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
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-02  8:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  8:21 [PATCH rtw-next v2] wifi: rtw89: usb: keep the endpoints until the driver lets go on unbind rcfa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox