wifi: rt2800usb: don't wait for every TX status
cover wifi: rt2800usb: don't wait for every TX status
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(-)
Signature · 1 line
2.56.1
PATCH 1/3 wifi: rt2x00: add a mode that doesn't wait for every TX status
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).
--- 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(-)
drivers/net/wireless/ralink/rt2x00/rt2x00.h +22 -0
@@ -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);/*
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c +74 -5
107 lines not on this page · raw message
drivers/net/wireless/ralink/rt2x00/rt2x00queue.c +93 -0
111 lines not on this page · raw message
drivers/net/wireless/ralink/rt2x00/rt2x00queue.h +13 -0
@@ -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;
Signature · 1 line
2.56.1
PATCH 2/3 wifi: rt2800: support TX status sampling
In reply to Rosen PenevImplement 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.
--- 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(-)
drivers/net/wireless/ralink/rt2x00/rt2800.h +6 -0
@@ -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 */
drivers/net/wireless/ralink/rt2x00/rt2800lib.c +173 -2
205 lines not on this page · raw message
drivers/net/wireless/ralink/rt2x00/rt2800lib.h +1 -0
@@ -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);
Signature · 1 line
2.56.1
PATCH 3/3 wifi: rt2800usb: don't hold every TX frame until its status is read
In reply to Rosen Penevrt2800usb 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.
--- .../net/wireless/ralink/rt2x00/rt2800usb.c | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/net/wireless/ralink/rt2x00/rt2800usb.c +26 -1
@@ -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. */
Signature · 1 line
2.56.1