]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
wifi: rtw89: usb: fix TX flow control by tracking in-flight URBs
authorLucid Duck <lucid_duck@justthetip.ca>
Thu, 2 Apr 2026 05:22:16 +0000 (22:22 -0700)
committerPing-Ke Shih <pkshih@realtek.com>
Thu, 2 Apr 2026 06:06:53 +0000 (14:06 +0800)
commit80119a77e5b03747b8886505df1b3cb26f49168d
tree7747250a8947e70842aacbeb513e3beddaa78eaf
parent4e4fc2149b0a983670fd99bbd549012839bda79e
wifi: rtw89: usb: fix TX flow control by tracking in-flight URBs

rtw89_usb_ops_check_and_reclaim_tx_resource() returns a hardcoded
placeholder value (42) instead of actual TX resource availability.
This violates mac80211's flow control contract, preventing backpressure
and causing uncontrolled URB accumulation under sustained TX load.

Fix by adding per-channel atomic counters (tx_inflight[]) that track
in-flight URBs. Increment before usb_submit_urb() with rollback on
failure, decrement in the completion callback, and return the
remaining capacity to mac80211. The firmware command channel (CH12)
always returns 1 since it has its own flow control.

The pre-increment pattern prevents a race where USB core completes the
URB on another CPU before the submitting code increments the counter.

128 URBs per channel provides headroom for RTL8832CU at 160 MHz
bandwidth. Tested on RTL8852AU (USB3 80 MHz) where 64 and 128 showed
equivalent throughput, and on RTL8832AU where 128 sustained full
throughput under 8-stream parallel load.

Tested on D-Link DWA-X1850 (RTL8832AU), kernel 6.19.8, Fedora 43:

                     Unpatched -> Patched (128 URBs)
  USB3 5GHz UL:      844 -> 837 Mbps (no regression)
  USB3 5GHz retx:    3 -> 0
  USB3 2.4GHz UL:    162 -> 164 Mbps (no regression)
  4-stream UL:       858 -> 826 Mbps (within variance)
  8-stream UL:       872 -> 826 Mbps (within variance)
  UDP flood:         0% loss (690K datagrams)
  60-second soak:    855 Mbps, 0 retransmits

Reported-by: morrownr <morrownr@gmail.com>
Signed-off-by: Lucid Duck <lucid_duck@justthetip.ca>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/20260402052216.207858-1-lucid_duck@justthetip.ca
drivers/net/wireless/realtek/rtw89/usb.c
drivers/net/wireless/realtek/rtw89/usb.h