* [PATCH wireless-next 0/3] wifi: rt2800usb: don't wait for every TX status
@ 2026-11-22 7:03 Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 1/3] wifi: rt2x00: add a mode that doesn't " Rosen Penev
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-22 7:03 UTC (permalink / raw)
To: Stanislaw Gruszka; +Cc: linux-wireless
rt2800usb keeps each frame in its TX queue until it has read the frame's
TX status from TX_STA_FIFO, one USB control transfer per report. On
hosts where a control transfer takes several milliseconds (AMD X470
chipset USB 2.0 ports take 3 ms or more), TX is capped at a few hundred
frames per second.
Patch 1 adds a mode to rt2x00lib, REQUIRE_TXSTATUS_SAMPLING, in which
only frames that need their status (mac80211 asked for one, or BARs)
wait for it. All other frames are completed when their DMA is done, and
a few of them still ask for a report that only feeds rate control.
Patch 2 implements it in rt2800lib using the TXWI packet id: 0 for no
report, the queue for waiting frames, and a sample bit plus the low
bits of the requested MCS for rate control samples. Patch 3 enables it
for rt2800usb. rt2800pci/soc behaviour is unchanged.
RT3070 station, MT7612U AP, channel 6 HT20, WPA2-CCMP, same host,
median of three 15 s iperf3 runs:
before after
TCP TX 3.4 Mbit/s, ~340 retr 37.8 Mbit/s, 1-8 retr
UDP TX (60M sent) 8.9 Mbit/s, 60% loss 43.8 Mbit/s, 0% loss
TCP RX 10.2 Mbit/s 29.8 Mbit/s
A GTK rekey every 10 s during 60 s of saturating TX with an A-MPDU
session completed every time, with no TX status timeouts or unmatched
reports. Each patch builds with W=1 and passes checkpatch --strict.
An AI coding assistant (Claude Code, Claude Opus 5.5) was used to review
the series, write the fixes from that review, run the hardware tests
and draft this cover letter.
Rosen Penev (3):
wifi: rt2x00: add a mode that doesn't wait for every TX status
wifi: rt2800: support TX status sampling
wifi: rt2800usb: don't hold every TX frame until its status is read
drivers/net/wireless/ralink/rt2x00/rt2800.h | 6 +
.../net/wireless/ralink/rt2x00/rt2800lib.c | 175 +++++++++++++++++-
.../net/wireless/ralink/rt2x00/rt2800lib.h | 1 +
.../net/wireless/ralink/rt2x00/rt2800usb.c | 27 ++-
drivers/net/wireless/ralink/rt2x00/rt2x00.h | 22 +++
.../net/wireless/ralink/rt2x00/rt2x00dev.c | 79 +++++++-
.../net/wireless/ralink/rt2x00/rt2x00queue.c | 93 ++++++++++
.../net/wireless/ralink/rt2x00/rt2x00queue.h | 13 ++
8 files changed, 408 insertions(+), 8 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH wireless-next 1/3] wifi: rt2x00: add a mode that doesn't wait for every TX status
2026-11-22 7:03 [PATCH wireless-next 0/3] wifi: rt2800usb: don't wait for every TX status Rosen Penev
@ 2026-11-22 7:03 ` Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 2/3] wifi: rt2800: support TX status sampling Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 3/3] wifi: rt2800usb: don't hold every TX frame until its status is read Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-22 7:03 UTC (permalink / raw)
To: Stanislaw Gruszka; +Cc: linux-wireless
Drivers with REQUIRE_TXSTATUS_FIFO keep each TX queue entry until the
hardware has reported the TX status of its frame. On USB, reading that
report is a control transfer, so the TX rate is bounded by the rate of
control transfers.
Add REQUIRE_TXSTATUS_SAMPLING for drivers that can tell the hardware
which frames to report. With it, only frames that need their status
wait for it: those mac80211 asked a status for and BARs, which are
tracked on the BAR list. These are counted per queue. All other frames
are marked ENTRY_DATA_NO_TXSTATUS and completed as soon as the DMA is
done, through rt2x00lib_txdone_unreported(), which hands the frame back
to mac80211 without a station so that rate control and the ACK
tracking are not fed made up results.
Some of the other frames, unicast frames to a station that expect an
ACK, still ask the hardware for a report (ENTRY_DATA_TXSTATUS_SAMPLE),
which only feeds rate control through rt2x00lib_txdone_sample(). At
most eight samples are sent until the driver next finds the status
FIFO empty, a sample in an A-MPDU (whose frames may all be reported)
takes all eight, and no samples are sent while a tracked frame is
pending, so the hardware status FIFO is unlikely to overflow and lose
a report that a frame waits for.
As unreported frames come back without a station, a frame that failed
because its station went to power save is no longer filtered and
requeued by mac80211, and such frames would not give back their
airtime if AQL were enabled (rt2x00 doesn't enable it).
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/wireless/ralink/rt2x00/rt2x00.h | 22 +++++
.../net/wireless/ralink/rt2x00/rt2x00dev.c | 79 +++++++++++++++-
.../net/wireless/ralink/rt2x00/rt2x00queue.c | 93 +++++++++++++++++++
.../net/wireless/ralink/rt2x00/rt2x00queue.h | 13 +++
4 files changed, 202 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00.h b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
index babc04210a65..9b2aa86a048b 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00.h
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00.h
@@ -687,6 +687,7 @@ enum rt2x00_capability_flags {
REQUIRE_COPY_IV,
REQUIRE_L2PAD,
REQUIRE_TXSTATUS_FIFO,
+ REQUIRE_TXSTATUS_SAMPLING,
REQUIRE_TASKLET_CONTEXT,
REQUIRE_SW_SEQNO,
REQUIRE_HT_TX_DESC,
@@ -976,6 +977,13 @@ struct rt2x00_dev {
*/
DECLARE_KFIFO_PTR(txstatus_fifo, u32);
+ /*
+ * Rate control sample slots taken since the TX status FIFO was
+ * last seen empty (REQUIRE_TXSTATUS_SAMPLING). A sample sent in an
+ * A-MPDU takes all of them.
+ */
+ atomic_t txstatus_samples;
+
/*
* Timer to ensure tx status reports are read (rt2800usb).
*/
@@ -1403,6 +1411,15 @@ void rt2x00queue_stop_queues(struct rt2x00_dev *rt2x00dev);
*/
void rt2x00queue_flush_queues(struct rt2x00_dev *rt2x00dev, bool drop);
+/**
+ * rt2x00queue_txstatus_tracked - Check for frames waiting for a TX status
+ * @rt2x00dev: Pointer to &struct rt2x00_dev.
+ *
+ * With %REQUIRE_TXSTATUS_SAMPLING, return true if any TX queue holds a
+ * frame that waits for its TX status report.
+ */
+bool rt2x00queue_txstatus_tracked(struct rt2x00_dev *rt2x00dev);
+
/*
* Debugfs handlers.
*/
@@ -1442,6 +1459,11 @@ void rt2x00lib_txdone(struct queue_entry *entry,
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_txdone_unreported(struct queue_entry *entry);
+void rt2x00lib_txdone_sample(struct rt2x00_dev *rt2x00dev,
+ struct ieee80211_sta *sta,
+ struct skb_frame_desc *skbdesc,
+ struct txdone_entry_desc *txdesc);
void rt2x00lib_rxdone(struct queue_entry *entry, gfp_t gfp);
/*
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
index ec1bb61a54b6..14598e67df6a 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
@@ -387,6 +387,9 @@ static void rt2x00lib_clear_entry(struct rt2x00_dev *rt2x00dev,
/*
* Make this entry available for reuse.
*/
+ if (test_bit(ENTRY_DATA_TXSTATUS_ACCT, &entry->flags))
+ atomic_dec(&entry->queue->txstatus_inflight);
+
entry->skb = NULL;
entry->flags = 0;
@@ -457,15 +460,11 @@ void rt2x00lib_txdone_nomatch(struct queue_entry *entry,
}
EXPORT_SYMBOL_GPL(rt2x00lib_txdone_nomatch);
-void rt2x00lib_txdone(struct queue_entry *entry,
- struct txdone_entry_desc *txdesc)
+static void rt2x00lib_txdone_restore_skb(struct queue_entry *entry)
{
struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
- struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
- u8 skbdesc_flags = skbdesc->flags;
unsigned int header_length;
- bool success;
/*
* Unmap the skb.
@@ -507,6 +506,18 @@ void rt2x00lib_txdone(struct queue_entry *entry,
* we are going to overwrite the skb->cb array.
*/
rt2x00debug_dump_frame(rt2x00dev, DUMP_FRAME_TXDONE, entry);
+}
+
+void rt2x00lib_txdone(struct queue_entry *entry,
+ struct txdone_entry_desc *txdesc)
+{
+ struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
+ struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
+ struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
+ u8 skbdesc_flags = skbdesc->flags;
+ bool success;
+
+ rt2x00lib_txdone_restore_skb(entry);
/*
* Determine if the frame has been successfully transmitted and
@@ -545,6 +556,64 @@ void rt2x00lib_txdone(struct queue_entry *entry,
}
EXPORT_SYMBOL_GPL(rt2x00lib_txdone);
+/*
+ * Complete a frame for which the hardware was asked not to report a TX
+ * status (see %REQUIRE_TXSTATUS_SAMPLING). Nothing is known about the
+ * transmission, so the frame is given back without a station: mac80211
+ * then frees it without feeding rate control or the ACK tracking.
+ */
+void rt2x00lib_txdone_unreported(struct queue_entry *entry)
+{
+ struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
+ struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(entry->skb);
+ struct skb_frame_desc *skbdesc = get_skb_frame_desc(entry->skb);
+ struct ieee80211_tx_status status = {
+ .skb = entry->skb,
+ .info = tx_info,
+ };
+ u8 skbdesc_flags = skbdesc->flags;
+
+ rt2x00lib_txdone_restore_skb(entry);
+
+ if (!(skbdesc_flags & SKBDESC_NOT_MAC80211)) {
+ memset(&tx_info->status, 0, sizeof(tx_info->status));
+ tx_info->status.rates[0].idx = -1;
+
+ if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_TASKLET_CONTEXT)) {
+ ieee80211_tx_status_ext(rt2x00dev->hw, &status);
+ } else {
+ local_bh_disable();
+ ieee80211_tx_status_ext(rt2x00dev->hw, &status);
+ local_bh_enable();
+ }
+ } else {
+ dev_kfree_skb_any(entry->skb);
+ }
+
+ rt2x00lib_clear_entry(rt2x00dev, entry);
+}
+EXPORT_SYMBOL_GPL(rt2x00lib_txdone_unreported);
+
+/*
+ * Report a TX status that belongs to no queue entry (any more), only to
+ * update rate control and the station statistics.
+ */
+void rt2x00lib_txdone_sample(struct rt2x00_dev *rt2x00dev,
+ struct ieee80211_sta *sta,
+ struct skb_frame_desc *skbdesc,
+ struct txdone_entry_desc *txdesc)
+{
+ struct ieee80211_tx_info txinfo = {};
+ bool success = test_bit(TXDONE_SUCCESS, &txdesc->flags);
+
+ rt2x00dev->link.qual.tx_success += success;
+ rt2x00dev->link.qual.tx_failed += !success;
+
+ rt2x00lib_fill_tx_status(rt2x00dev, &txinfo, skbdesc, txdesc, success);
+ ieee80211_tx_status_noskb(rt2x00dev->hw, sta, &txinfo);
+}
+EXPORT_SYMBOL_GPL(rt2x00lib_txdone_sample);
+
void rt2x00lib_txdone_noinfo(struct queue_entry *entry, u32 status)
{
struct txdone_entry_desc txdesc;
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
index 4b842497653c..de3387243b86 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.c
@@ -596,6 +596,96 @@ static void rt2x00queue_bar_check(struct queue_entry *entry)
spin_unlock_bh(&rt2x00dev->bar_list_lock);
}
+/*
+ * Upper bound of rate control samples sent between two times the
+ * hardware TX status FIFO, which holds 16 reports, is seen empty.
+ */
+#define RT2X00_TXSTATUS_MAX_SAMPLES 8
+
+bool rt2x00queue_txstatus_tracked(struct rt2x00_dev *rt2x00dev)
+{
+ struct data_queue *queue;
+
+ tx_queue_for_each(rt2x00dev, queue) {
+ if (atomic_read(&queue->txstatus_inflight))
+ return true;
+ }
+ return false;
+}
+EXPORT_SYMBOL_GPL(rt2x00queue_txstatus_tracked);
+
+/*
+ * Take a rate control sample slot. The hardware reports every MPDU of an
+ * A-MPDU with the packet id of the first one, so a sample sent as part of
+ * an A-MPDU can produce as many reports as the aggregate has frames: it
+ * takes all remaining slots.
+ */
+static bool rt2x00queue_txstatus_take_sample(struct rt2x00_dev *rt2x00dev,
+ bool ampdu)
+{
+ int samples = atomic_read(&rt2x00dev->txstatus_samples);
+
+ do {
+ if (samples >= RT2X00_TXSTATUS_MAX_SAMPLES)
+ return false;
+ } while (!atomic_try_cmpxchg(&rt2x00dev->txstatus_samples, &samples,
+ ampdu ? RT2X00_TXSTATUS_MAX_SAMPLES :
+ samples + 1));
+
+ return true;
+}
+
+/*
+ * With REQUIRE_TXSTATUS_SAMPLING only frames that need a TX status
+ * (mac80211 asked for one, or BARs which are tracked on the BAR list)
+ * wait for their report. All other frames are completed as soon as they
+ * are handed to the hardware, so they don't wait for a status report that
+ * is slow to fetch over USB. Some of those still ask the hardware for a
+ * report, which only feeds rate control; they are not sent while a
+ * tracked frame is pending, and only a few are sent until the status
+ * FIFO is seen empty, so the FIFO is unlikely to overflow and lose the
+ * report of a tracked frame.
+ */
+static void rt2x00queue_txstatus_select(struct queue_entry *entry,
+ struct ieee80211_tx_info *tx_info,
+ struct ieee80211_sta *sta)
+{
+ struct data_queue *queue = entry->queue;
+ struct rt2x00_dev *rt2x00dev = queue->rt2x00dev;
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)entry->skb->data;
+ bool ampdu;
+
+ if (!rt2x00_has_cap_flag(rt2x00dev, REQUIRE_TXSTATUS_SAMPLING))
+ return;
+
+ if ((tx_info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) ||
+ ieee80211_is_back_req(hdr->frame_control)) {
+ atomic_inc(&queue->txstatus_inflight);
+ set_bit(ENTRY_DATA_TXSTATUS_ACCT, &entry->flags);
+ return;
+ }
+
+ set_bit(ENTRY_DATA_NO_TXSTATUS, &entry->flags);
+
+ /* Rate control can only use reports of acked unicast frames. */
+ if (!sta || (tx_info->flags & IEEE80211_TX_CTL_NO_ACK) ||
+ is_multicast_ether_addr(hdr->addr1))
+ return;
+
+ ampdu = tx_info->flags & IEEE80211_TX_CTL_AMPDU;
+ if (!rt2x00queue_txstatus_tracked(rt2x00dev) &&
+ rt2x00queue_txstatus_take_sample(rt2x00dev, ampdu))
+ set_bit(ENTRY_DATA_TXSTATUS_SAMPLE, &entry->flags);
+}
+
+static void rt2x00queue_txstatus_unselect(struct queue_entry *entry)
+{
+ clear_bit(ENTRY_DATA_NO_TXSTATUS, &entry->flags);
+ clear_bit(ENTRY_DATA_TXSTATUS_SAMPLE, &entry->flags);
+ if (test_and_clear_bit(ENTRY_DATA_TXSTATUS_ACCT, &entry->flags))
+ atomic_dec(&entry->queue->txstatus_inflight);
+}
+
int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
struct ieee80211_sta *sta, bool local)
{
@@ -681,12 +771,15 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb,
entry->skb = skb;
+ rt2x00queue_txstatus_select(entry, tx_info, sta);
+
/*
* It could be possible that the queue was corrupted and this
* call failed. Since we always return NETDEV_TX_OK to mac80211,
* this frame will simply be dropped.
*/
if (unlikely(rt2x00queue_write_tx_data(entry, &txdesc))) {
+ rt2x00queue_txstatus_unselect(entry);
clear_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags);
entry->skb = NULL;
ret = -EIO;
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
index 23739dd0bc9b..99478ae7f57d 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
+++ b/drivers/net/wireless/ralink/rt2x00/rt2x00queue.h
@@ -342,6 +342,12 @@ struct txentry_desc {
* @ENTRY_DATA_STATUS_PENDING: The entry has been send to the device and
* returned. It is now waiting for the status reporting before the
* entry can be reused again.
+ * @ENTRY_DATA_NO_TXSTATUS: The entry does not wait for a TX status report;
+ * it is completed as soon as the DMA is done.
+ * @ENTRY_DATA_TXSTATUS_SAMPLE: The hardware reports a TX status for this
+ * %ENTRY_DATA_NO_TXSTATUS entry, used only to feed rate control.
+ * @ENTRY_DATA_TXSTATUS_ACCT: The entry waits for its TX status report and
+ * is counted in &data_queue.txstatus_inflight.
*/
enum queue_entry_flags {
ENTRY_BCN_ASSIGNED,
@@ -350,6 +356,9 @@ enum queue_entry_flags {
ENTRY_DATA_PENDING,
ENTRY_DATA_IO_FAILED,
ENTRY_DATA_STATUS_PENDING,
+ ENTRY_DATA_NO_TXSTATUS,
+ ENTRY_DATA_TXSTATUS_SAMPLE,
+ ENTRY_DATA_TXSTATUS_ACCT,
};
/**
@@ -438,6 +447,8 @@ enum data_queue_flags {
* @wd_count: watchdog counter number of times entry does change
* in the queue
* @wd_idx: index of queue entry saved by watchdog
+ * @txstatus_inflight: number of entries for which a TX status report is
+ * expected (only with %REQUIRE_TXSTATUS_SAMPLING).
* @txop: maximum burst time.
* @aifs: The aifs value for outgoing frames (field ignored in RX queue).
* @cw_min: The cw min value for outgoing frames (field ignored in RX queue).
@@ -468,6 +479,8 @@ struct data_queue {
unsigned short wd_count;
unsigned int wd_idx;
+ atomic_t txstatus_inflight;
+
unsigned short txop;
unsigned short aifs;
unsigned short cw_min;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH wireless-next 2/3] wifi: rt2800: support TX status sampling
2026-11-22 7:03 [PATCH wireless-next 0/3] wifi: rt2800usb: don't wait for every TX status Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 1/3] wifi: rt2x00: add a mode that doesn't " Rosen Penev
@ 2026-11-22 7:03 ` Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 3/3] wifi: rt2800usb: don't hold every TX frame until its status is read Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-22 7:03 UTC (permalink / raw)
To: Stanislaw Gruszka; +Cc: linux-wireless
Implement REQUIRE_TXSTATUS_SAMPLING in rt2800lib.
A TXWI packet id of 0 tells the hardware not to report a TX status for
the frame. Frames that wait for their report keep the queue in the
packet id, with entry 1. Rate control samples carry RT2800_PID_SAMPLE
and the low three bits of the requested MCS: every MPDU of an A-MPDU is
reported with the packet id of the first frame, so a sample can't be
matched to a queue entry, but the requested MCS lets the number of
retries be worked out from the report alone, as rt2800_txdone_entry()
does from the TXWI. The MCS group (stream count, short preamble) comes
from the MCS in the report.
A report with a packet id that doesn't match the first waiting entry of
its queue, which can happen for an A-MPDU led by a waiting frame, is
ignored instead of being given to the wrong entry. Before a report is
matched, the entries at the head of the queue that don't wait for one
are completed.
Waiting frames of a queue all carry the same packet id, as the sample
bit leaves no room for the entry index, so a lost report can't be told
apart from the report of the next waiting frame. A waiting frame that
the hardware aggregates behind a frame with packet id 0 gets no report
and is completed by the TX status timeout. That is unlikely for EAPOL,
which goes out on VO, where mac80211 doesn't start BA sessions itself.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/net/wireless/ralink/rt2x00/rt2800.h | 6 +
.../net/wireless/ralink/rt2x00/rt2800lib.c | 175 +++++++++++++++++-
.../net/wireless/ralink/rt2x00/rt2800lib.h | 1 +
3 files changed, 180 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800.h b/drivers/net/wireless/ralink/rt2x00/rt2800.h
index 8930589b4967..9348fb87c64d 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800.h
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800.h
@@ -3116,6 +3116,12 @@ enum rt2800_eeprom_word {
#define TXWI_W1_PACKETID_QUEUE FIELD32(0x30000000)
#define TXWI_W1_PACKETID_ENTRY FIELD32(0xc0000000)
+/*
+ * PACKETID bit of rate control samples (REQUIRE_TXSTATUS_SAMPLING), see
+ * rt2800_tx_packet_id().
+ */
+#define RT2800_PID_SAMPLE 0x8
+
/*
* Word2
*/
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
index f15533c5be9b..c65243f3d062 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
@@ -793,6 +793,36 @@ int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
}
EXPORT_SYMBOL_GPL(rt2800_load_firmware);
+/*
+ * PACKETID 0 tells the hardware not to report a TX status for a frame.
+ * In sampling mode, frames that wait for their report carry the queue and
+ * entry 1, and rate control samples carry RT2800_PID_SAMPLE and the low
+ * bits of the requested MCS, so the number of retries can be worked out
+ * from the report alone. Note that every frame in an A-MPDU is reported
+ * with the packet id of the first frame.
+ *
+ * With RT2800_PID_SAMPLE taking the top bit, all waiting frames of a
+ * queue share one packet id, so a lost report can't be told apart from
+ * the report of the next waiting frame of the queue. A waiting frame
+ * that the hardware puts in an A-MPDU behind a frame with packet id 0
+ * gets no report and is completed by the TX status timeout.
+ */
+static u8 rt2800_tx_packet_id(struct queue_entry *entry,
+ struct txentry_desc *txdesc)
+{
+ if (!rt2x00_has_cap_flag(entry->queue->rt2x00dev,
+ REQUIRE_TXSTATUS_SAMPLING))
+ return ((entry->entry_idx % 3) + 1) << 2 | entry->queue->qid;
+
+ if (test_bit(ENTRY_DATA_TXSTATUS_SAMPLE, &entry->flags))
+ return RT2800_PID_SAMPLE | (txdesc->u.ht.mcs & 0x7);
+
+ if (test_bit(ENTRY_DATA_NO_TXSTATUS, &entry->flags))
+ return 0;
+
+ return 1 << 2 | entry->queue->qid;
+}
+
void rt2800_write_tx_data(struct queue_entry *entry,
struct txentry_desc *txdesc)
{
@@ -836,8 +866,8 @@ void rt2800_write_tx_data(struct queue_entry *entry,
txdesc->key_idx : txdesc->u.ht.wcid);
rt2x00_set_field32(&word, TXWI_W1_MPDU_TOTAL_BYTE_COUNT,
txdesc->length);
- rt2x00_set_field32(&word, TXWI_W1_PACKETID_QUEUE, entry->queue->qid);
- rt2x00_set_field32(&word, TXWI_W1_PACKETID_ENTRY, (entry->entry_idx % 3) + 1);
+ rt2x00_set_field32(&word, TXWI_W1_PACKETID,
+ rt2800_tx_packet_id(entry, txdesc));
rt2x00_desc_write(txwi, 1, word);
/*
@@ -1119,6 +1149,137 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
}
EXPORT_SYMBOL_GPL(rt2800_txdone_entry);
+/*
+ * Complete the entries at the head of the queue that are done with DMA
+ * and for which the hardware will not report a TX status.
+ */
+static void rt2800_txdone_unreported_queue(struct data_queue *queue)
+{
+ struct queue_entry *entry;
+
+ while (!rt2x00queue_empty(queue)) {
+ entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
+
+ if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
+ !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags) ||
+ !test_bit(ENTRY_DATA_NO_TXSTATUS, &entry->flags))
+ break;
+
+ if (test_bit(ENTRY_DATA_IO_FAILED, &entry->flags))
+ rt2x00lib_txdone_noinfo(entry, TXDONE_FAILURE);
+ else
+ rt2x00lib_txdone_unreported(entry);
+ }
+}
+
+void rt2800_txdone_unreported(struct rt2x00_dev *rt2x00dev)
+{
+ struct data_queue *queue;
+
+ tx_queue_for_each(rt2x00dev, queue)
+ rt2800_txdone_unreported_queue(queue);
+}
+EXPORT_SYMBOL_GPL(rt2800_txdone_unreported);
+
+/*
+ * Feed a TX status report of a rate control sample (or of a frame that
+ * went out in an A-MPDU behind one) to rate control. The requested MCS
+ * comes from the packet id, see rt2800_tx_packet_id().
+ */
+static void rt2800_txdone_sample(struct rt2x00_dev *rt2x00dev, u32 status)
+{
+ struct rt2800_drv_data *drv_data = rt2x00dev->drv_data;
+ struct skb_frame_desc skbdesc = {};
+ struct txdone_entry_desc txdesc = {};
+ struct ieee80211_sta *sta;
+ u8 real_mcs, mcs;
+ int wcid;
+
+ wcid = rt2x00_get_field32(status, TX_STA_FIFO_WCID);
+ if (wcid < WCID_START || wcid > WCID_END)
+ return;
+
+ real_mcs = rt2x00_get_field32(status, TX_STA_FIFO_MCS);
+ mcs = (real_mcs & ~0x7) |
+ (rt2x00_get_field32(status, TX_STA_FIFO_PID_TYPE) & 0x7);
+
+ rt2800_rate_from_status(&skbdesc, status, rt2x00dev->curr_band);
+
+ if (rt2x00_get_field32(status, TX_STA_FIFO_TX_AGGRE))
+ __set_bit(TXDONE_AMPDU, &txdesc.flags);
+
+ if (!rt2x00_get_field32(status, TX_STA_FIFO_TX_ACK_REQUIRED))
+ __set_bit(TXDONE_NO_ACK_REQ, &txdesc.flags);
+
+ /* See rt2800_txdone_entry() for how the retries are counted. */
+ if (rt2x00_get_field32(status, TX_STA_FIFO_TX_SUCCESS)) {
+ __set_bit(TXDONE_SUCCESS, &txdesc.flags);
+ txdesc.retry = mcs > real_mcs ? mcs - real_mcs : 0;
+ } else {
+ __set_bit(TXDONE_FAILURE, &txdesc.flags);
+ txdesc.retry = rt2x00dev->long_retry;
+ }
+
+ if (txdesc.retry)
+ __set_bit(TXDONE_FALLBACK, &txdesc.flags);
+
+ /* rt2x00lib_fill_tx_status() wants the first rate that was tried. */
+ if (mcs > real_mcs)
+ skbdesc.tx_rate_idx += mcs - real_mcs;
+
+ rcu_read_lock();
+ sta = drv_data->wcid_to_sta[wcid - WCID_START];
+ if (sta)
+ rt2x00lib_txdone_sample(rt2x00dev, sta, &skbdesc, &txdesc);
+ rcu_read_unlock();
+}
+
+static void rt2800_txdone_sampling(struct rt2x00_dev *rt2x00dev, u32 reg)
+{
+ struct data_queue *queue;
+ struct queue_entry *entry;
+ __le32 *txwi;
+ u8 pid;
+
+ pid = rt2x00_get_field32(reg, TX_STA_FIFO_PID_TYPE);
+ if (pid & RT2800_PID_SAMPLE) {
+ rt2800_txdone_sample(rt2x00dev, reg);
+ return;
+ }
+
+ queue = rt2x00queue_get_tx_queue(rt2x00dev,
+ rt2x00_get_field32(reg, TX_STA_FIFO_PID_QUEUE));
+
+ /* The report is for the first entry that waits for one. */
+ rt2800_txdone_unreported_queue(queue);
+
+ if (rt2x00queue_empty(queue))
+ goto unexpected;
+
+ entry = rt2x00queue_get_entry(queue, Q_INDEX_DONE);
+ if (test_bit(ENTRY_OWNER_DEVICE_DATA, &entry->flags) ||
+ !test_bit(ENTRY_DATA_STATUS_PENDING, &entry->flags) ||
+ test_bit(ENTRY_DATA_NO_TXSTATUS, &entry->flags))
+ goto unexpected;
+
+ /*
+ * Unlike rt2800_txdone_entry_check(), also check the packet id of
+ * an A-MPDU report: it can belong to another frame of the aggregate.
+ */
+ txwi = rt2800_drv_get_txwi(entry);
+ if (pid != rt2x00_get_field32(rt2x00_desc_read(txwi, 1),
+ TXWI_W1_PACKETID) ||
+ !rt2800_txdone_entry_check(entry, reg))
+ goto unexpected;
+
+ rt2800_txdone_entry(entry, reg, txwi, true);
+ return;
+
+unexpected:
+ rt2x00_dbg(rt2x00dev, "Unexpected TX status %08x for queue %u\n",
+ reg, queue->qid);
+}
+
void rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota)
{
struct data_queue *queue;
@@ -1128,6 +1289,11 @@ void rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota)
bool match;
while (quota-- > 0 && kfifo_get(&rt2x00dev->txstatus_fifo, ®)) {
+ if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_TXSTATUS_SAMPLING)) {
+ rt2800_txdone_sampling(rt2x00dev, reg);
+ continue;
+ }
+
/*
* TX_STA_FIFO_PID_QUEUE is a 2-bit field, thus qid is
* guaranteed to be one of the TX QIDs .
@@ -1201,6 +1367,11 @@ bool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev)
{
struct data_queue *queue;
+ if (rt2x00_has_cap_flag(rt2x00dev, REQUIRE_TXSTATUS_SAMPLING)) {
+ return atomic_read(&rt2x00dev->txstatus_samples) ||
+ rt2x00queue_txstatus_tracked(rt2x00dev);
+ }
+
tx_queue_for_each(rt2x00dev, queue) {
if (rt2x00queue_get_entry(queue, Q_INDEX_DMA_DONE) !=
rt2x00queue_get_entry(queue, Q_INDEX_DONE))
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
index c9d0417dc292..9774fcbff467 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.h
@@ -204,6 +204,7 @@ void rt2800_txdone_entry(struct queue_entry *entry, u32 status, __le32 *txwi,
bool match);
void rt2800_txdone(struct rt2x00_dev *rt2x00dev, unsigned int quota);
void rt2800_txdone_nostatus(struct rt2x00_dev *rt2x00dev);
+void rt2800_txdone_unreported(struct rt2x00_dev *rt2x00dev);
bool rt2800_txstatus_timeout(struct rt2x00_dev *rt2x00dev);
bool rt2800_txstatus_pending(struct rt2x00_dev *rt2x00dev);
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH wireless-next 3/3] wifi: rt2800usb: don't hold every TX frame until its status is read
2026-11-22 7:03 [PATCH wireless-next 0/3] wifi: rt2800usb: don't wait for every TX status Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 1/3] wifi: rt2x00: add a mode that doesn't " Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 2/3] wifi: rt2800: support TX status sampling Rosen Penev
@ 2026-11-22 7:03 ` Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-22 7:03 UTC (permalink / raw)
To: Stanislaw Gruszka; +Cc: linux-wireless
rt2800usb reads TX_STA_FIFO with one control transfer per report, and
keeps each frame in its 16 entry TX queue until its report has been
read, so the TX rate is bound to the latency of control transfers.
On the AMD X470 chipset USB 2.0 ports, each control transfer to an
RT3070 takes 3 ms or more (the host retries an endpoint that NAKs only
every few ms; the CPU's own xHCI does that within 0.25 ms). Pipelining
reads doesn't help, the host still serves one transfer per 3 ms. TX
there is limited to about 300 frames per second.
Enable REQUIRE_TXSTATUS_SAMPLING: complete frames that don't need their
status when the URB is done, read the FIFO while samples or waiting
frames are outstanding, and give the sample slots back only when the
FIFO is found empty.
RT3070 as station on an X470 chipset port, MT7612U AP, channel 6 HT20,
WPA2-CCMP, median of three 15 s iperf3 runs:
before after
TCP TX 3.4 Mbit/s, ~340 retr 37.8 Mbit/s, 1-8 retr
UDP TX (60M sent) 8.9 Mbit/s, 60% loss 43.8 Mbit/s, 0% loss
TCP RX 10.2 Mbit/s 29.8 Mbit/s
minstrel_ht keeps getting samples with retries at all rates and picks
MCS7. A GTK rekey every 10 s during 60 s of saturating TX with an
A-MPDU session completes every time, without TX status timeouts. WPA2
(CCMP, TKIP, mixed) and SAE connect in both station and AP mode.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
.../net/wireless/ralink/rt2x00/rt2800usb.c | 27 ++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
index 15de3db12429..5dd849e3dde5 100644
--- a/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/ralink/rt2x00/rt2800usb.c
@@ -104,6 +104,14 @@ static bool rt2800usb_tx_sta_fifo_read_completed(struct rt2x00_dev *rt2x00dev,
}
valid = rt2x00_get_field32(tx_status, TX_STA_FIFO_VALID);
+
+ /*
+ * Rate control samples may produce more than one report each (A-MPDU),
+ * so the sample slots are only given back once the FIFO is empty.
+ */
+ if (!valid)
+ atomic_set(&rt2x00dev->txstatus_samples, 0);
+
if (valid) {
if (!kfifo_put(&rt2x00dev->txstatus_fifo, tx_status))
rt2x00_warn(rt2x00dev, "TX status FIFO overrun\n");
@@ -156,7 +164,12 @@ static void rt2800usb_tx_dma_done(struct queue_entry *entry)
{
struct rt2x00_dev *rt2x00dev = entry->queue->rt2x00dev;
- rt2800usb_async_read_tx_status(rt2x00dev);
+ if (test_bit(ENTRY_DATA_NO_TXSTATUS, &entry->flags))
+ queue_work(rt2x00dev->workqueue, &rt2x00dev->txdone_work);
+
+ if (!test_bit(ENTRY_DATA_NO_TXSTATUS, &entry->flags) ||
+ test_bit(ENTRY_DATA_TXSTATUS_SAMPLE, &entry->flags))
+ rt2800usb_async_read_tx_status(rt2x00dev);
}
static enum hrtimer_restart rt2800usb_tx_sta_fifo_timeout(struct hrtimer *timer)
@@ -458,11 +471,15 @@ static void rt2800usb_work_txdone(struct work_struct *work)
struct rt2x00_dev *rt2x00dev =
container_of(work, struct rt2x00_dev, txdone_work);
+ rt2800_txdone_unreported(rt2x00dev);
+
while (!kfifo_is_empty(&rt2x00dev->txstatus_fifo) ||
rt2800_txstatus_timeout(rt2x00dev)) {
rt2800_txdone(rt2x00dev, UINT_MAX);
+ rt2800_txdone_unreported(rt2x00dev);
+
rt2800_txdone_nostatus(rt2x00dev);
/*
@@ -615,6 +632,14 @@ static int rt2800usb_probe_hw(struct rt2x00_dev *rt2x00dev)
if (retval)
return retval;
+ /*
+ * Each TX status read is a USB control transfer, which can take
+ * several milliseconds. Holding every frame until its status has
+ * been read caps TX at one frame per transfer, so only frames that
+ * need a status wait for it.
+ */
+ __set_bit(REQUIRE_TXSTATUS_SAMPLING, &rt2x00dev->cap_flags);
+
/*
* Set txstatus timer function.
*/
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-22 7:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 7:03 [PATCH wireless-next 0/3] wifi: rt2800usb: don't wait for every TX status Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 1/3] wifi: rt2x00: add a mode that doesn't " Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 2/3] wifi: rt2800: support TX status sampling Rosen Penev
2026-11-22 7:03 ` [PATCH wireless-next 3/3] wifi: rt2800usb: don't hold every TX frame until its status is read Rosen Penev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox