From: Rosen Penev <rosenp@gmail.com>
To: Stanislaw Gruszka <stf_xl@wp.pl>
Cc: linux-wireless@vger.kernel.org
Subject: [PATCH wireless-next 2/3] wifi: rt2800: support TX status sampling
Date: Sat, 21 Nov 2026 23:03:41 -0800 [thread overview]
Message-ID: <20261122070342.101054-3-rosenp@gmail.com> (raw)
In-Reply-To: <20261122070342.101054-1-rosenp@gmail.com>
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
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 ` [PATCH wireless-next 1/3] wifi: rt2x00: add a mode that doesn't " Rosen Penev
2026-11-22 7:03 ` Rosen Penev [this message]
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-3-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