mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Härdeman" <david@hardeman.nu>
To: Ping-Ke Shih <pkshih@realtek.com>, linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
	"Leonard Lausen" <leonard@lausen.nl>,
	"Alastair D'Silva" <alastair@d-silva.org>,
	"Luka Gejak" <luka.gejak@linux.dev>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Bitterblue Smith" <rtl8821cerfe2@gmail.com>,
	"David Härdeman" <david@hardeman.nu>
Subject: [PATCH rtw-next 3/5] wifi: rtw88: sdio: limit the TX queue length of the 88xx chips
Date: Mon, 16 Nov 2026 20:01:43 +0100	[thread overview]
Message-ID: <20261116190145.2736364-4-david@hardeman.nu> (raw)
In-Reply-To: <20261116190145.2736364-1-david@hardeman.nu>

The TX path pulls every frame mac80211 has queued into its own per-queue
FIFO, and only the RTL8723BS stops the mac80211 queues when that FIFO
grows. On the 88xx chips the FIFO is unbounded: the backlog builds up
there instead of in mac80211, where fq_codel would keep it short and
schedule it fairly between flows. On a NanoPi R76S (RTL8822CS) acting as
an AP, the round trip time to a client goes up to more than a second
during a single TCP download.

Stop the mac80211 queue of an access category above 64 frames in its
FIFO and wake it again below 32, as is done for the RTL8723BS with lower
watermarks. The 88xx chips send up to 32 frames per transfer and need
the deeper FIFO to keep doing that. Also wake the queue after an
aggregate is sent, which the single frame path already does.

A stopped queue is handed no further frames, so nothing would kick the
TX work again if the chip stayed full for its whole retry loop. Requeue
the work after a jiffy in that case, as the RTL8723BS path does.

With this, the round trip time during a download stays at about 12-30
ms on average (100-570 ms at most, mostly from the client), and the
download throughput is unchanged at about 190-215 Mbit/s.

Signed-off-by: David Härdeman <david@hardeman.nu>
---
 drivers/net/wireless/realtek/rtw88/sdio.c | 77 +++++++++++++++++++----
 1 file changed, 64 insertions(+), 13 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index 17a4c3037d7..cced6fdfa6d 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -22,9 +22,16 @@
 #define RTW_SDIO_INDIRECT_RW_RETRIES			50
 #define RTW_SDIO_OQT_TIMEOUT_MS				1000
 
-/* Bounds the queueing latency of the unbounded per-AC software FIFO. */
+/*
+ * Bound the queueing latency of the per-AC software FIFO, so that the
+ * backlog stays in mac80211, where it is scheduled fairly between flows and
+ * stations. The 88xx chips send up to RTW_SDIO_TX_AGG_MAX_NUM frames per
+ * transfer and need a deeper FIFO to keep doing that.
+ */
 #define RTW_SDIO_TX_FIFO_HIWATER			16
 #define RTW_SDIO_TX_FIFO_LOWATER			8
+#define RTW_SDIO_88XX_TX_FIFO_HIWATER			64
+#define RTW_SDIO_88XX_TX_FIFO_LOWATER			32
 #define RTW_SDIO_TX_RETRY_DELAY			msecs_to_jiffies(1)
 
 static bool rtw_sdio_is_bus_addr(u32 addr)
@@ -1391,19 +1398,43 @@ static int rtw_sdio_write_data_h2c(struct rtw_dev *rtwdev, u8 *buf, u32 size)
 	return rtw_sdio_write_data(rtwdev, &pkt_info, skb, RTW_TX_QUEUE_H2C);
 }
 
+static bool rtw_sdio_tx_queue_limited(struct rtw_dev *rtwdev,
+				      enum rtw_tx_queue_type queue)
+{
+	if (queue >= RTW_TX_QUEUE_BCN)
+		return false;
+
+	return rtw_is_8723bs(rtwdev) || !rtw_chip_wcpu_8051(rtwdev);
+}
+
+static u32 rtw_sdio_tx_fifo_hiwater(struct rtw_dev *rtwdev)
+{
+	if (rtw_chip_wcpu_8051(rtwdev))
+		return RTW_SDIO_TX_FIFO_HIWATER;
+
+	return RTW_SDIO_88XX_TX_FIFO_HIWATER;
+}
+
+static u32 rtw_sdio_tx_fifo_lowater(struct rtw_dev *rtwdev)
+{
+	if (rtw_chip_wcpu_8051(rtwdev))
+		return RTW_SDIO_TX_FIFO_LOWATER;
+
+	return RTW_SDIO_88XX_TX_FIFO_LOWATER;
+}
+
 /*
  * Both this and the wake below hold the TX queue lock across the length check
  * and the flag update, so a queue is only ever stopped while it really is
  * above the watermark, and the drain path always sees the flag the producer
  * set.
  */
-static void rtw_sdio_8723bs_stop_tx_queue(struct rtw_dev *rtwdev,
-					  enum rtw_tx_queue_type queue,
-					  u16 q_map)
+static void rtw_sdio_stop_tx_queue(struct rtw_dev *rtwdev,
+				   enum rtw_tx_queue_type queue, u16 q_map)
 {
 	struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
 
-	if (!rtw_is_8723bs(rtwdev) || queue >= RTW_TX_QUEUE_BCN)
+	if (!rtw_sdio_tx_queue_limited(rtwdev, queue))
 		return;
 
 	guard(spinlock_irqsave)(&rtwsdio->tx_queue[queue].lock);
@@ -1411,20 +1442,20 @@ static void rtw_sdio_8723bs_stop_tx_queue(struct rtw_dev *rtwdev,
 	if (rtwsdio->tx_queue_stopped[queue])
 		return;
 
-	if (skb_queue_len(&rtwsdio->tx_queue[queue]) < RTW_SDIO_TX_FIFO_HIWATER)
+	if (skb_queue_len(&rtwsdio->tx_queue[queue]) <
+	    rtw_sdio_tx_fifo_hiwater(rtwdev))
 		return;
 
 	rtwsdio->tx_queue_stopped[queue] = true;
 	ieee80211_stop_queue(rtwdev->hw, q_map);
 }
 
-static void rtw_sdio_8723bs_wake_tx_queue(struct rtw_dev *rtwdev,
-					  enum rtw_tx_queue_type queue,
-					  u16 q_map)
+static void rtw_sdio_wake_tx_queue(struct rtw_dev *rtwdev,
+				   enum rtw_tx_queue_type queue, u16 q_map)
 {
 	struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
 
-	if (!rtw_is_8723bs(rtwdev) || queue >= RTW_TX_QUEUE_BCN)
+	if (!rtw_sdio_tx_queue_limited(rtwdev, queue))
 		return;
 
 	guard(spinlock_irqsave)(&rtwsdio->tx_queue[queue].lock);
@@ -1432,7 +1463,8 @@ static void rtw_sdio_8723bs_wake_tx_queue(struct rtw_dev *rtwdev,
 	if (!rtwsdio->tx_queue_stopped[queue])
 		return;
 
-	if (skb_queue_len(&rtwsdio->tx_queue[queue]) > RTW_SDIO_TX_FIFO_LOWATER)
+	if (skb_queue_len(&rtwsdio->tx_queue[queue]) >
+	    rtw_sdio_tx_fifo_lowater(rtwdev))
 		return;
 
 	rtwsdio->tx_queue_stopped[queue] = false;
@@ -1456,7 +1488,7 @@ static int rtw_sdio_tx_write(struct rtw_dev *rtwdev,
 	/* The TX worker may already have freed the skb, so do not touch it. */
 	skb_queue_tail(&rtwsdio->tx_queue[queue], skb);
 
-	rtw_sdio_8723bs_stop_tx_queue(rtwdev, queue, q_map);
+	rtw_sdio_stop_tx_queue(rtwdev, queue, q_map);
 
 	return 0;
 }
@@ -1820,6 +1852,7 @@ static int rtw_sdio_process_tx_agg(struct rtw_dev *rtwdev,
 	struct sk_buff *skb;
 	u8 ac = U8_MAX;
 	u32 txaddr;
+	u16 q_map;
 	int ret;
 
 	__skb_queue_head_init(&agg);
@@ -1895,9 +1928,14 @@ static int rtw_sdio_process_tx_agg(struct rtw_dev *rtwdev,
 
 	mutex_unlock(&rtwsdio->tx_credit_lock);
 
+	/* all frames are of the same AC, and the skbs are consumed below */
+	q_map = skb_get_queue_mapping(skb_peek(&agg));
+
 	while ((skb = __skb_dequeue(&agg)))
 		rtw_sdio_indicate_tx_status(rtwdev, skb);
 
+	rtw_sdio_wake_tx_queue(rtwdev, queue, q_map);
+
 	return 0;
 
 err_requeue:
@@ -1944,7 +1982,7 @@ static int rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev,
 
 	rtw_sdio_indicate_tx_status(rtwdev, skb);
 
-	rtw_sdio_8723bs_wake_tx_queue(rtwdev, queue, q_map);
+	rtw_sdio_wake_tx_queue(rtwdev, queue, q_map);
 
 	return 0;
 }
@@ -1990,6 +2028,7 @@ static void rtw_sdio_tx_handler(struct work_struct *work)
 	struct rtw_sdio *rtwsdio;
 	struct rtw_dev *rtwdev;
 	int limit, queue, ret;
+	bool resched = false;
 
 	rtwdev = work_data->rtwdev;
 	rtwsdio = (struct rtw_sdio *)rtwdev->priv;
@@ -2010,7 +2049,19 @@ static void rtw_sdio_tx_handler(struct work_struct *work)
 			if (skb_queue_empty(&rtwsdio->tx_queue[queue]))
 				break;
 		}
+
+		/*
+		 * A stopped queue is handed no further frames, so nothing
+		 * else would kick this work item if the chip stayed full for
+		 * the whole loop.
+		 */
+		if (ret == -EBUSY && !rtw_chip_wcpu_8051(rtwdev))
+			resched = true;
 	}
+
+	if (resched)
+		queue_delayed_work(rtwsdio->txwq, &work_data->work,
+				   RTW_SDIO_TX_RETRY_DELAY);
 }
 
 static void rtw_sdio_free_irq(struct rtw_dev *rtwdev,
-- 
2.47.3


  parent reply	other threads:[~2026-11-16 19:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for " David Härdeman
2026-11-16 19:01 ` [PATCH rtw-next 1/5] wifi: rtw88: sdio: cache the free TX page counts of " David Härdeman
2026-11-16 19:01 ` [PATCH rtw-next 2/5] wifi: rtw88: sdio: aggregate TX frames " David Härdeman
2026-11-16 19:01 ` David Härdeman [this message]
2026-11-16 19:01 ` [PATCH rtw-next 4/5] wifi: rtw88: sdio: let TX in while receiving on " David Härdeman
2026-11-16 19:01 ` [PATCH rtw-next 5/5] wifi: rtw88: sdio: read neighbouring registers of the 88xx chips at once David Härdeman
2026-11-16 21:59 ` [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips Luka Gejak

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=20261116190145.2736364-4-david@hardeman.nu \
    --to=david@hardeman.nu \
    --cc=alastair@d-silva.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=leonard@lausen.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luka.gejak@linux.dev \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=pkshih@realtek.com \
    --cc=rtl8821cerfe2@gmail.com \
    /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®