From: Ho Jie Feng <hjf3108@gmail.com>
To: Stanislaw Gruszka <stf_xl@wp.pl>
Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
Ho Jie Feng <hjf3108@gmail.com>
Subject: [PATCH wireless-next v3 7/7] wifi: rt2x00usb: use a threaded NAPI with GRO for RX
Date: Fri, 13 Nov 2026 00:45:41 +0800 [thread overview]
Message-ID: <20261112164544.3176458-8-hjf3108@gmail.com> (raw)
In-Reply-To: <20261112164544.3176458-1-hjf3108@gmail.com>
GRO makes sense now that RX aggregation is enabled, since multiple
frames arrive at once.
This code is referenced from commit 5323d3e50c20
("wifi: mt76: mt76u: use a threaded NAPI for the RX path")
The RX locking is referenced from commit 3298b1f866fb ("mt76: use
ieee80211_rx_list to pass frames to the network stack as a batch") and
commit 5b8ccdfb943f ("wifi: mt76: add missing locking to protect
against concurrent rx/status calls")
Test results:
before after
TX 30.5 30.5
RX 80.9 161.7
Signed-off-by: Ho Jie Feng <hjf3108@gmail.com>
---
drivers/net/wireless/ralink/rt2x00/rt2x00.h | 16 ++++-
.../net/wireless/ralink/rt2x00/rt2x00dev.c | 28 ++++++++-
.../net/wireless/ralink/rt2x00/rt2x00usb.c | 59 +++++++++++++++----
3 files changed, 89 insertions(+), 14 deletions(-)
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
index 7b1a32d3e1..7d10bbe3ba 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
@@ -960,11 +960,22 @@ struct rt2x00_dev {
struct work_struct intf_work;
/**
- * Scheduled work for TX/RX done handling (USB devices)
+ * Scheduled work for TX done handling (USB devices)
*/
- struct work_struct rxdone_work;
struct work_struct txdone_work;
+ /*
+ * NAPI context for RX done handling (USB devices).
+ */
+ struct net_device *napi_dev;
+ struct napi_struct napi;
+ struct sk_buff_head rx_skb;
+
+ /*
+ * Serialize the RX in NAPI with the TX status reports to mac80211.
+ */
+ spinlock_t rx_lock;
+
/*
* Powersaving work
*/
@@ -1462,6 +1473,7 @@ void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
struct txdone_entry_desc *txdesc);
void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status);
void rt2x00lib_rxdone(struct queue_entry *entry, unsigned int len, gfp_t gfp);
+void rt2x00lib_rx_complete(struct rt2x00_dev *rt2x00dev);
/*
* mac80211 handlers.
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
index dc6a7d12b2..aae96d082a 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
@@ -461,7 +461,9 @@ void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
rt2x00lib_fill_tx_status(rt2x00dev, &txinfo, skbdesc, txdesc,
success);
+ spin_lock_bh(&rt2x00dev->rx_lock);
ieee80211_tx_status_noskb(rt2x00dev->hw, skbdesc->sta, &txinfo);
+ spin_unlock_bh(&rt2x00dev->rx_lock);
}
dev_kfree_skb_any(entry->skb);
@@ -545,10 +547,12 @@ void rt2x00lib_txdone(struct queue_entry *entry,
* send the status report back.
*/
if (!(skbdesc_flags & SKBDESC_NOT_MAC80211)) {
+ spin_lock_bh(&rt2x00dev->rx_lock);
if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_TASKLET_CONTEXT))
ieee80211_tx_status_skb(rt2x00dev->hw, entry->skb);
else
ieee80211_tx_status_ni(rt2x00dev->hw, entry->skb);
+ spin_unlock_bh(&rt2x00dev->rx_lock);
} else {
dev_kfree_skb_any(entry->skb);
}
@@ -871,7 +875,10 @@ static void rt2x00lib_rxdone_skb(struct queue_entry *entry)
rx_status->bw = rxdesc.bw;
rx_status->antenna = rt2x00dev->link.ant.active.rx;
- ieee80211_rx_ni(rt2x00dev->hw, entry->skb);
+ if (rt2x00dev->napi_dev)
+ __skb_queue_tail(&rt2x00dev->rx_skb, entry->skb);
+ else
+ ieee80211_rx_ni(rt2x00dev->hw, entry->skb);
}
void rt2x00lib_rxdone(struct queue_entry *entry, unsigned int len, gfp_t gfp)
@@ -945,6 +952,23 @@ void rt2x00lib_rxdone(struct queue_entry *entry, unsigned int len, gfp_t gfp)
}
EXPORT_SYMBOL_GPL(rt2x00lib_rxdone);
+void rt2x00lib_rx_complete(struct rt2x00_dev *rt2x00dev)
+{
+ struct sk_buff *skb, *tmp;
+ LIST_HEAD(list);
+
+ spin_lock(&rt2x00dev->rx_lock);
+ while ((skb = __skb_dequeue(&rt2x00dev->rx_skb)) != NULL)
+ ieee80211_rx_list(rt2x00dev->hw, NULL, skb, &list);
+ spin_unlock(&rt2x00dev->rx_lock);
+
+ list_for_each_entry_safe(skb, tmp, &list, list) {
+ skb_list_del_init(skb);
+ napi_gro_receive(&rt2x00dev->napi, skb);
+ }
+}
+EXPORT_SYMBOL_GPL(rt2x00lib_rx_complete);
+
/*
* Driver initialization handlers.
*/
@@ -1469,6 +1493,8 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
mutex_init(&rt2x00dev->conf_mutex);
INIT_LIST_HEAD(&rt2x00dev->bar_list);
spin_lock_init(&rt2x00dev->bar_list_lock);
+ spin_lock_init(&rt2x00dev->rx_lock);
+ skb_queue_head_init(&rt2x00dev->rx_skb);
hrtimer_setup(&rt2x00dev->txstatus_timer, hrtimer_dummy_timeout, CLOCK_MONOTONIC,
HRTIMER_MODE_REL);
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
index 4519a20a7f..4fe0d6f836 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
@@ -341,15 +341,16 @@ static bool rt2x00usb_kick_tx_entry(struct queue_entry *entry, void *data)
/*
* RX data handlers.
*/
-static void rt2x00usb_work_rxdone(struct work_struct *work)
+static int rt2x00usb_poll_rxdone(struct napi_struct *napi, int budget)
{
struct rt2x00_dev *rt2x00dev =
- container_of(work, struct rt2x00_dev, rxdone_work);
+ container_of(napi, struct rt2x00_dev, napi);
struct queue_entry_priv_usb *entry_priv;
struct queue_entry *entry;
struct skb_frame_desc *skbdesc;
u8 rxd[32];
+ rcu_read_lock();
while (!rt2x00queue_empty(rt2x00dev->rx)) {
entry = rt2x00queue_get_entry(rt2x00dev->rx, Q_INDEX_DONE);
@@ -368,8 +369,14 @@ static void rt2x00usb_work_rxdone(struct work_struct *work)
*/
entry_priv = entry->priv_data;
rt2x00lib_rxdone(entry, entry_priv->urb->actual_length,
- GFP_KERNEL);
+ GFP_ATOMIC);
}
+ rt2x00lib_rx_complete(rt2x00dev);
+ rcu_read_unlock();
+
+ napi_complete(napi);
+
+ return 0;
}
static void rt2x00usb_interrupt_rxdone(struct urb *urb)
@@ -396,7 +403,7 @@ static void rt2x00usb_interrupt_rxdone(struct urb *urb)
/*
* Schedule the delayed work for processing RX data
*/
- queue_work(rt2x00dev->workqueue, &rt2x00dev->rxdone_work);
+ napi_schedule(&rt2x00dev->napi);
}
static bool rt2x00usb_kick_rx_entry(struct queue_entry *entry, void *data)
@@ -478,7 +485,7 @@ static bool rt2x00usb_flush_entry(struct queue_entry *entry, void *data)
void rt2x00usb_flush_queue(struct data_queue *queue, bool drop)
{
- struct work_struct *completion;
+ bool is_tx;
unsigned int i;
if (drop)
@@ -486,17 +493,17 @@ void rt2x00usb_flush_queue(struct data_queue *queue, bool drop)
rt2x00usb_flush_entry);
/*
- * Obtain the queue completion handler
+ * Obtain the queue type
*/
switch (queue->qid) {
case QID_AC_VO:
case QID_AC_VI:
case QID_AC_BE:
case QID_AC_BK:
- completion = &queue->rt2x00dev->txdone_work;
+ is_tx = true;
break;
case QID_RX:
- completion = &queue->rt2x00dev->rxdone_work;
+ is_tx = false;
break;
default:
return;
@@ -515,7 +522,14 @@ void rt2x00usb_flush_queue(struct data_queue *queue, bool drop)
* Schedule the completion handler manually, when this
* worker function runs, it should cleanup the queue.
*/
- queue_work(queue->rt2x00dev->workqueue, completion);
+ if (is_tx) {
+ queue_work(queue->rt2x00dev->workqueue,
+ &queue->rt2x00dev->txdone_work);
+ } else {
+ local_bh_disable();
+ napi_schedule(&queue->rt2x00dev->napi);
+ local_bh_enable();
+ }
/*
* Wait for a little while to give the driver
@@ -750,7 +764,7 @@ void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev)
usb_kill_anchored_urbs(rt2x00dev->anchor);
hrtimer_cancel(&rt2x00dev->txstatus_timer);
- cancel_work_sync(&rt2x00dev->rxdone_work);
+ napi_synchronize(&rt2x00dev->napi);
cancel_work_sync(&rt2x00dev->txdone_work);
queue_for_each(rt2x00dev, queue)
@@ -758,6 +772,14 @@ void rt2x00usb_uninitialize(struct rt2x00_dev *rt2x00dev)
}
EXPORT_SYMBOL_GPL(rt2x00usb_uninitialize);
+static void rt2x00usb_free_napi(struct rt2x00_dev *rt2x00dev)
+{
+ napi_disable(&rt2x00dev->napi);
+ netif_napi_del(&rt2x00dev->napi);
+ free_netdev(rt2x00dev->napi_dev);
+ rt2x00dev->napi_dev = NULL;
+}
+
int rt2x00usb_probe(struct usb_interface *usb_intf,
const struct rt2x00_ops *ops)
{
@@ -801,9 +823,21 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
rt2x00_set_chip_intf(rt2x00dev, RT2X00_CHIP_INTF_USB);
- INIT_WORK(&rt2x00dev->rxdone_work, rt2x00usb_work_rxdone);
INIT_WORK(&rt2x00dev->txdone_work, rt2x00usb_work_txdone);
+ rt2x00dev->napi_dev = alloc_netdev_dummy(0);
+ if (!rt2x00dev->napi_dev) {
+ retval = -ENOMEM;
+ goto exit_free_hw;
+ }
+
+ strscpy(rt2x00dev->napi_dev->name, wiphy_name(hw->wiphy),
+ sizeof(rt2x00dev->napi_dev->name));
+ netif_napi_add(rt2x00dev->napi_dev, &rt2x00dev->napi,
+ rt2x00usb_poll_rxdone);
+ netif_threaded_enable(rt2x00dev->napi_dev);
+ napi_enable(&rt2x00dev->napi);
+
init_usb_anchor(rt2x00dev->anchor);
retval = rt2x00lib_probe_dev(rt2x00dev);
@@ -814,6 +848,8 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
exit_free_anchor:
usb_kill_anchored_urbs(rt2x00dev->anchor);
+ rt2x00usb_free_napi(rt2x00dev);
+exit_free_hw:
ieee80211_free_hw(hw);
usb_set_intfdata(usb_intf, NULL);
@@ -830,6 +866,7 @@ void rt2x00usb_disconnect(struct usb_interface *usb_intf)
* Free all allocated data.
*/
rt2x00lib_remove_dev(rt2x00dev);
+ rt2x00usb_free_napi(rt2x00dev);
ieee80211_free_hw(hw);
usb_set_intfdata(usb_intf, NULL);
--
2.53.0
prev parent reply other threads:[~2026-11-12 16:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 16:45 [PATCH wireless-next v3 0/7] wifi: rt2x00: improve the throughput of rt2800usb Ho Jie Feng
2026-11-12 16:45 ` [PATCH wireless-next v3 1/7] wifi: rt2x00: start the link tuner when an interface is added Ho Jie Feng
2026-11-12 16:45 ` [PATCH wireless-next v3 2/7] wifi: rt2800: calibrate the crystal of RT3593 with the beacons Ho Jie Feng
2026-11-12 16:45 ` [PATCH wireless-next v3 3/7] wifi: rt2800: make MCS 16 fall back to MCS 8 on devices with 3 TX chains Ho Jie Feng
2026-11-12 16:45 ` [PATCH wireless-next v3 4/7] wifi: rt2800: don't report an A-MPDU length to minstrel_ht Ho Jie Feng
2026-11-12 16:45 ` [PATCH wireless-next v3 5/7] wifi: rt2800usb: enable RX bulk aggregation Ho Jie Feng
2026-11-12 16:45 ` [PATCH wireless-next v3 6/7] wifi: rt2800: support A-MSDU in A-MPDU Ho Jie Feng
2026-11-12 16:45 ` Ho Jie Feng [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261112164544.3176458-8-hjf3108@gmail.com \
--to=hjf3108@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=stf_xl@wp.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®