Linux wireless drivers development
 help / color / mirror / Atom feed
* [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX
@ 2026-12-03  5:00 Ho Jie Feng
  2026-12-03 15:33 ` Luka Gejak
  2026-12-03 15:57 ` Jie Feng
  0 siblings, 2 replies; 5+ messages in thread
From: Ho Jie Feng @ 2026-12-03  5:00 UTC (permalink / raw)
  To: pkshih; +Cc: Ho Jie Feng, linux-wireless

Process the RX URBs in a threaded NAPI poll, so that the receive
path can take advantage of GRO.

Signed-off-by: Ho Jie Feng <hjf3108@gmail.com>
---
RFT because the RTL8812AU I have does not enumerate over USB3, so the
full impact of this patch could not be tested.

 drivers/net/wireless/realtek/rtw88/usb.c | 37 +++++++++++++++++++-----
 drivers/net/wireless/realtek/rtw88/usb.h |  4 ++-
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c
index ef2a0686b7..a552ccb7fc 100644
--- a/drivers/net/wireless/realtek/rtw88/usb.c
+++ b/drivers/net/wireless/realtek/rtw88/usb.c
@@ -673,9 +673,9 @@ static void rtw_usb_tx_kick_off(struct rtw_dev *rtwdev)
 	queue_work(rtwusb->txwq, &rtwusb->tx_work);
 }
 
-static void rtw_usb_rx_handler(struct work_struct *work)
+static int rtw_usb_napi_poll(struct napi_struct *napi, int budget)
 {
-	struct rtw_usb *rtwusb = container_of(work, struct rtw_usb, rx_work);
+	struct rtw_usb *rtwusb = container_of(napi, struct rtw_usb, napi);
 	struct rtw_dev *rtwdev = rtwusb->rtwdev;
 	struct ieee80211_rx_status rx_status;
 	struct rtw_rx_pkt_stat pkt_stat;
@@ -685,14 +685,16 @@ static void rtw_usb_rx_handler(struct work_struct *work)
 	u32 max_skb_len = pkt_desc_sz + PHY_STATUS_SIZE * 8 +
 			  IEEE80211_MAX_MPDU_LEN_VHT_11454;
 	u32 pkt_offset, next_pkt, skb_len;
-	int limit, ret;
+	int done = 0, ret;
 	u8 *rx_desc;
 
-	for (limit = 0; limit < 200; limit++) {
+	while (done < budget) {
 		rx_skb = skb_dequeue(&rtwusb->rx_queue);
 		if (!rx_skb)
 			break;
 
+		done++;
+
 		if (skb_queue_len(&rtwusb->rx_queue) >= RTW_USB_MAX_RXQ_LEN) {
 			dev_dbg_ratelimited(rtwdev->dev, "failed to get rx_queue, overflow\n");
 			dev_kfree_skb_any(rx_skb);
@@ -749,7 +751,7 @@ static void rtw_usb_rx_handler(struct work_struct *work)
 							       &pkt_stat);
 				rtw_rx_stats(rtwdev, pkt_stat.vif, skb);
 				memcpy(skb->cb, &rx_status, sizeof(rx_status));
-				ieee80211_rx_irqsafe(rtwdev->hw, skb);
+				ieee80211_rx_napi(rtwdev->hw, NULL, skb, napi);
 			}
 
 skip_packet:
@@ -762,6 +764,11 @@ static void rtw_usb_rx_handler(struct work_struct *work)
 		else
 			skb_queue_tail(&rtwusb->rx_free_queue, rx_skb);
 	}
+
+	if (done < budget)
+		napi_complete_done(napi, done);
+
+	return done;
 }
 
 static void rtw_usb_read_port_complete(struct urb *urb);
@@ -840,7 +847,7 @@ static void rtw_usb_read_port_complete(struct urb *urb)
 		} else {
 			skb_put(skb, urb->actual_length);
 			skb_queue_tail(&rtwusb->rx_queue, skb);
-			queue_work(rtwusb->rxwq, &rtwusb->rx_work);
+			napi_schedule(&rtwusb->napi);
 		}
 		rtw_usb_rx_resubmit(rtwusb, rxcb, GFP_ATOMIC);
 	} else {
@@ -1062,10 +1069,20 @@ static int rtw_usb_init_rx(struct rtw_dev *rtwdev)
 		return -ENOMEM;
 	}
 
+	rtwusb->netdev = alloc_netdev_dummy(0);
+	if (!rtwusb->netdev) {
+		destroy_workqueue(rtwusb->rxwq);
+		return -ENOMEM;
+	}
+
+	strscpy(rtwusb->netdev->name, "rtw88-usb-rx");
+	rtwusb->netdev->threaded = 1;
+	netif_napi_add(rtwusb->netdev, &rtwusb->napi, rtw_usb_napi_poll);
+	napi_enable(&rtwusb->napi);
+
 	skb_queue_head_init(&rtwusb->rx_queue);
 	skb_queue_head_init(&rtwusb->rx_free_queue);
 
-	INIT_WORK(&rtwusb->rx_work, rtw_usb_rx_handler);
 	INIT_WORK(&rtwusb->rx_urb_work, rtw_usb_rx_resubmit_work);
 
 	for (i = 0; i < RTW_USB_RX_SKB_NUM; i++) {
@@ -1093,6 +1110,10 @@ static void rtw_usb_deinit_rx(struct rtw_dev *rtwdev)
 {
 	struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev);
 
+	napi_disable(&rtwusb->napi);
+	netif_napi_del(&rtwusb->napi);
+	free_netdev(rtwusb->netdev);
+
 	skb_queue_purge(&rtwusb->rx_queue);
 
 	destroy_workqueue(rtwusb->rxwq);
@@ -1456,7 +1477,7 @@ void rtw_usb_disconnect(struct usb_interface *intf)
 	rtwusb = rtw_get_usb_priv(rtwdev);
 
 	rtw_usb_cancel_rx_bufs(rtwusb);
-	cancel_work_sync(&rtwusb->rx_work);
+	napi_synchronize(&rtwusb->napi);
 
 	rtw_unregister_hw(rtwdev, hw);
 	rtw_usb_deinit_tx(rtwdev);
diff --git a/drivers/net/wireless/realtek/rtw88/usb.h b/drivers/net/wireless/realtek/rtw88/usb.h
index 04f835ea28..9a6e205e19 100644
--- a/drivers/net/wireless/realtek/rtw88/usb.h
+++ b/drivers/net/wireless/realtek/rtw88/usb.h
@@ -84,8 +84,10 @@ struct rtw_usb {
 	struct rx_usb_ctrl_block rx_cb[RTW_USB_RXCB_NUM];
 	struct sk_buff_head rx_queue;
 	struct sk_buff_head rx_free_queue;
-	struct work_struct rx_work;
 	struct work_struct rx_urb_work;
+
+	struct net_device *netdev;
+	struct napi_struct napi;
 };
 
 static inline struct rtw_usb_tx_data *rtw_usb_get_tx_data(struct sk_buff *skb)

base-commit: f496c65cc2870f2342ff37736dd31d0748588c72
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX
  2026-12-03  5:00 [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX Ho Jie Feng
@ 2026-12-03 15:33 ` Luka Gejak
  2026-12-03 15:56   ` Jie Feng
  2026-12-03 15:57 ` Jie Feng
  1 sibling, 1 reply; 5+ messages in thread
From: Luka Gejak @ 2026-12-03 15:33 UTC (permalink / raw)
  To: Ho Jie Feng; +Cc: pkshih, linux-wireless

Hi Jie Feng,

Thanks for posting this. Two comments below.

On December 3, 2026 1:00:56 PM GMT+08:00, Ho Jie Feng
<hjf3108@gmail.com> wrote:

[ ... ]

> +	while (done < budget) {
>  		rx_skb = skb_dequeue(&rtwusb->rx_queue);
>  		if (!rx_skb)
>  			break;
>
> +		done++;

As far as I can see, done counts completed URBs. With USB RX aggregation
enabled, the inner loop can pass several packets to mac80211 for each
increment, so one poll can process more packets than its budget allows.

Could the poll count packets here and resume a partially processed URB
on the next call?

[ ... ]

>  				rtw_rx_stats(rtwdev, pkt_stat.vif, skb);
>  				memcpy(skb->cb, &rx_status, sizeof(rx_status));
> -				ieee80211_rx_irqsafe(rtwdev->hw, skb);
> +				ieee80211_rx_napi(rtwdev->hw, NULL, skb, napi);

I think this can change the order of RX and TX status in AP mode.
rtw_tx_report_tx_status() still queues the status for a power save poll
response through ieee80211_tx_status_irqsafe(). Before this change, a
later RX frame went behind that status in the same mac80211 queue.

The next power save poll can now reach ieee80211_sta_pspoll() with that
status still pending. If WLAN_STA_SP is still set, mac80211 ignores the
poll. Could we preserve that ordering when moving RX to NAPI?

Best regards,
Luka Gejak

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX
  2026-12-03 15:33 ` Luka Gejak
@ 2026-12-03 15:56   ` Jie Feng
  2026-12-03 16:48     ` Luka Gejak
  0 siblings, 1 reply; 5+ messages in thread
From: Jie Feng @ 2026-12-03 15:56 UTC (permalink / raw)
  To: Luka Gejak; +Cc: pkshih, linux-wireless

Hi Luka,

On Thu, 3 Dec 2026 at 23:33, Luka Gejak <luka.gejak@linux.dev> wrote:
>
> Hi Jie Feng,
>
> Thanks for posting this. Two comments below.
>
> On December 3, 2026 1:00:56 PM GMT+08:00, Ho Jie Feng
> <hjf3108@gmail.com> wrote:
>
> [ ... ]
>
> > +     while (done < budget) {
> >               rx_skb = skb_dequeue(&rtwusb->rx_queue);
> >               if (!rx_skb)
> >                       break;
> >
> > +             done++;
>
> As far as I can see, done counts completed URBs. With USB RX aggregation
> enabled, the inner loop can pass several packets to mac80211 for each
> increment, so one poll can process more packets than its budget allows.
>
> Could the poll count packets here and resume a partially processed URB
> on the next call?
Yeah this is a known bug. However, making it count packets here will
make the patch more complicated, so I used this instead.
This patch is mainly to let people test the RX speed with and without GRO.

> [ ... ]
>
> >                               rtw_rx_stats(rtwdev, pkt_stat.vif, skb);
> >                               memcpy(skb->cb, &rx_status, sizeof(rx_status));
> > -                             ieee80211_rx_irqsafe(rtwdev->hw, skb);
> > +                             ieee80211_rx_napi(rtwdev->hw, NULL, skb, napi);
>
> I think this can change the order of RX and TX status in AP mode.
> rtw_tx_report_tx_status() still queues the status for a power save poll
> response through ieee80211_tx_status_irqsafe(). Before this change, a
> later RX frame went behind that status in the same mac80211 queue.
>
> The next power save poll can now reach ieee80211_sta_pspoll() with that
> status still pending. If WLAN_STA_SP is still set, mac80211 ignores the
> poll. Could we preserve that ordering when moving RX to NAPI?
That would be a bigger change, possibly to move both TX and RX status
handling into the napi thread and put both in a queue.

Another problem with GRO is that it can reduce speed for forwarding,
such as the common case in AP mode. Possibly fraglist GRO can help
here.
https://lore.kernel.org/all/20240423094117.93206-1-nbd@nbd.name/

> Best regards,
> Luka Gejak

Best regards,
Jie Feng

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX
  2026-12-03  5:00 [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX Ho Jie Feng
  2026-12-03 15:33 ` Luka Gejak
@ 2026-12-03 15:57 ` Jie Feng
  1 sibling, 0 replies; 5+ messages in thread
From: Jie Feng @ 2026-12-03 15:57 UTC (permalink / raw)
  To: pkshih; +Cc: linux-wireless

On Thu, 3 Dec 2026 at 13:01, Ho Jie Feng <hjf3108@gmail.com> wrote:
>
> Process the RX URBs in a threaded NAPI poll, so that the receive
> path can take advantage of GRO.
>
> Signed-off-by: Ho Jie Feng <hjf3108@gmail.com>
> ---
> RFT because the RTL8812AU I have does not enumerate over USB3, so the
> full impact of this patch could not be tested.
Noticed this is a bit sparse on what to test.

For testers: test the receive speed of these network adapters when
connected to USB3, because the top speed is higher than what USB2 can
provide.
Also check if CPU usage decreased due to GRO when receiving.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX
  2026-12-03 15:56   ` Jie Feng
@ 2026-12-03 16:48     ` Luka Gejak
  0 siblings, 0 replies; 5+ messages in thread
From: Luka Gejak @ 2026-12-03 16:48 UTC (permalink / raw)
  To: Jie Feng; +Cc: pkshih, linux-wireless

Hi Jie Feng,

Thanks for explaining. One thought on the shared queue below.

On December 3, 2026 11:56:11 PM GMT+08:00, Jie Feng
<hjf3108@gmail.com> wrote:

[ ... ]

> That would be a bigger change, possibly to move both TX and RX status
> handling into the napi thread and put both in a queue.

The power save poll response gets its status through
rtw_tx_report_tx_status() when the firmware report comes in. Could we
feed the shared queue from there as well as from USB TX completion?
The C2H handler takes rtwdev->mutex, so I'd keep it on the workqueue
and pass just the finished TX status to NAPI.

Best regards,
Luka Gejak

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-03 16:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  5:00 [PATCH RFT] wifi: rtw88: usb: use a threaded NAPI and GRO for RX Ho Jie Feng
2026-12-03 15:33 ` Luka Gejak
2026-12-03 15:56   ` Jie Feng
2026-12-03 16:48     ` Luka Gejak
2026-12-03 15:57 ` Jie Feng

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