From: Rosen Penev <rosenp@gmail.com>
To: Stanislaw Gruszka <stf_xl@wp.pl>
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH wireless-next 1/3] wifi: rt2x00: add a mode that doesn't wait for every TX status
Date: Sat, 21 Nov 2026 23:03:40 -0800 [thread overview]
Message-ID: <20261122070342.101054-2-rosenp@gmail.com> (raw)
In-Reply-To: <20261122070342.101054-1-rosenp@gmail.com>
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
next prev parent reply other threads:[~2026-11-22 7:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20261122070342.101054-2-rosenp@gmail.com \
--to=rosenp@gmail.com \
--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