* [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips
@ 2026-11-16 19:01 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
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: David Härdeman @ 2026-11-16 19:01 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Leonard Lausen, Alastair D'Silva, Luka Gejak,
Martin Blumenstingl, Jernej Skrabec, Bitterblue Smith,
David Härdeman
The RTL8822CS on a NanoPi R76S (RK3576, SDR104 at 198 MHz) sends at less
than half the rate it receives at, and with traffic in both directions
it hardly sends at all. These patches are about the 88xx chips
(RTL8822BS, RTL8822CS, RTL8821CS); the 8051 chips keep their current
paths.
1. keep the free page and AC output queue counts, as the RTL8723BS path
does, and read the registers only when a transfer doesn't fit;
2. send up to 32 frames / 20 KiB of one access category per transfer;
3. stop the mac80211 queues when the driver's FIFO is deep, so the
backlog stays in mac80211 (fq_codel) instead of an unbounded FIFO;
4. let the TX work have the host between RX reads while frames are
waiting; the RX path otherwise takes most of the bus;
5. read HISR with RX0_REQ_LEN, and the three free page registers, with
one transfer each.
R76S as AP, VHT80 1x1 (client 2x2, AX210), 2 m line of sight, iperf3
TCP between the client and a wired host on the AP's switch, Mbit/s
(AP->client 30 s / client->AP 30 s / both directions at once 120 s),
mean of 3 interleaved rounds:
down up bidir
rtw-next 64 132 28 + 76
+ 1-4 184 210 77 + 89
+ 1-5 198 212 84 + 86
Realtek driver ~183 ~265 ~40 + 180 (FriendlyWrt, same board)
In the bidir runs, the share of 5 s intervals with the download below
40 Mbit/s went from 11-24 of 24 with rtw-next to 1-5 of 24 with the
series.
The individual steps were measured in another set of runs, with the
sender behind a path that reorders some TCP segments (which costs a
little download throughput but doesn't change the ranking); RTT is
ping AP->client during the download, median / 90th percentile:
down up bidir RTT under load
rtw-next 89 164 23 + 119 34 / 91 ms
+ 1-2 189 220 37 + 167 22 / 51 ms
+ 1-3 181 214 30 + 176 10 / 29 ms
+ 1-4 194 198 79 + 91 11 / 25 ms
+ 1-5 190 202 73 + 100 13 / 47 ms
Patch 2 is the big step for one-way traffic, patch 3 halves the
latency under load, and patch 4 is what makes both directions work at
the same time (it costs some upload when that runs alone). Patch 5 is
mainly about bus transfers; in a longer A/B (10 interleaved rounds,
channel 149) it gave about 10 % more download than 1-4 (190 vs 171
Mbit/s), with up and bidir unchanged.
A soak with the full series, 30 120 s bidir transfers in a row,
averaged 95 + 88 Mbit/s, the slowest download being 80 Mbit/s (10 of
the 720 5 s intervals had the download below 40 Mbit/s). There were no
kernel messages and the bus stayed at SDR104.
Known issue, not addressed here: when the client goes off-channel (for
example for a background scan), the chip sometimes gives up on an MPDU
of an A-MPDU session without sending a BAR, and keeps sending up to 64
frames past it. rtw88 reports every SDIO data frame as acked, so
mac80211 doesn't know either and can't send a BAR. The client's
reorder window then stalls until it is pushed past the hole, which
costs a short throughput dip. With iwlwifi clients it turned into
bursts of up to 63 lost frames per hole because of a reorder buffer
bug there, for which I have sent fixes:
https://lore.kernel.org/linux-wireless/20261116155609.535595-1-david@hardeman.nu/
I tried the hardware BAR settings (REG_BAR_MODE_CTRL thresholds, the
BAR retry bits in the TX descriptor), a longer retry limit, MACID sleep
for dozing clients, per-frame TX reports and a BAR sent by the driver
after the client wakes up; none of them helped, and per-frame reports
only came back for about one frame per A-MPDU. Ping-Ke, is there a way
for the firmware to report which MPDU it dropped, or to send the BAR
itself?
Tested on the RTL8822CS only. The RTL8822BS and RTL8821CS share the
register layout and code paths; testing on them would be welcome.
Two series on the list touch the same code, and I'd like to make sure
this one doesn't clash with them:
- Alastair D'Silva's "wifi: rtw88: sdio: Fix unhandled RX request
interrupt storm" (v10) changes the RX interrupt handling that patches
4 and 5 touch. This series is based on rtw-next without it; I have a
version rebased on top of it and will send that once it's applied.
https://lore.kernel.org/linux-wireless/20261113082242.2773369-1-alastair@d-silva.org/
- Leonard Lausen's "wifi: rtw88: reduce RTL8822CS SDIO request
overhead" (v2): his patch 1 (control frame filter) is independent of
this series and applies on top of it. His patch 2 combines the free
page register reads that patch 1 here replaces with cached counts,
so only one of the two makes sense; Leonard, I'm happy to go with
whatever you and Ping-Ke prefer.
https://lore.kernel.org/linux-wireless/20261116100804.425592-2-leonard@lausen.nl/
The bus speed itself needs 67a97316a31a ("mmc: core: sdio: skip CMD11 if
signalling is already 1.8V") from mmc/next on this board; without it the
card runs at 50 MHz and the gains are smaller.
The patches were generated with the help of an LLM; I have reviewed
them (to the best of my ability), and tested them on actual hardware as
described above.
David Härdeman (5):
wifi: rtw88: sdio: cache the free TX page counts of the 88xx chips
wifi: rtw88: sdio: aggregate TX frames of the 88xx chips
wifi: rtw88: sdio: limit the TX queue length of the 88xx chips
wifi: rtw88: sdio: let TX in while receiving on the 88xx chips
wifi: rtw88: sdio: read neighbouring registers of the 88xx chips at
once
drivers/net/wireless/realtek/rtw88/sdio.c | 574 +++++++++++++++++++---
drivers/net/wireless/realtek/rtw88/sdio.h | 13 +
2 files changed, 526 insertions(+), 61 deletions(-)
base-commit: 61a5eb87b2d9b4d5e353780b781cf691f39ba9e1
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH rtw-next 1/5] wifi: rtw88: sdio: cache the free TX page counts of the 88xx chips
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips David Härdeman
@ 2026-11-16 19:01 ` David Härdeman
2026-11-16 19:01 ` [PATCH rtw-next 2/5] wifi: rtw88: sdio: aggregate TX frames " David Härdeman
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Härdeman @ 2026-11-16 19:01 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Leonard Lausen, Alastair D'Silva, Luka Gejak,
Martin Blumenstingl, Jernej Skrabec, Bitterblue Smith,
David Härdeman
Before every transfer, rtw_sdio_check_free_txpg() reads the three
REG_SDIO_FREE_TXPG registers of the RTL8822BS, RTL8822CS and RTL8821CS
to see whether the frame fits. That is three register reads per frame,
more bus time than the transfer of a small frame takes, and the main
reason why the RTL8822CS sends at only about a third of the rate it
receives at.
The chip only ever frees pages, so counts read earlier and reduced by
every transfer since then never exceed what is free. Keep the counts,
reserve each transfer's pages from them, and read the registers again
only when they say the frame does not fit, as the RTL8723BS path does
and as Realtek's driver does for these chips. Pages are taken from the
queue's dedicated pages first and then from the public ones, and the
management queue, which goes to the extra FIFO on these chips, has its
own count.
The same registers report the free entries of the AC output queue;
track them too, one per frame of an AC queue, so that a later change can
send several frames per transfer without overrunning it.
tx_credit_lock is held from the reservation until the transfer is done,
so the counts are never read back while a transfer they were reduced for
has not reached the chip yet. They are read again after start and stop,
and after a failed transfer.
On a NanoPi R76S (RTL8822CS, SDR104) acting as an AP, TCP throughput to
a client goes from about 87 to about 100 Mbit/s, and from the client from
about 160 to about 185 Mbit/s.
Signed-off-by: David Härdeman <david@hardeman.nu>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 201 ++++++++++++++++++----
drivers/net/wireless/realtek/rtw88/sdio.h | 3 +
2 files changed, 170 insertions(+), 34 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index ecd4d751c05..49d733a5104 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -675,6 +675,135 @@ static atomic_t *rtw_sdio_8723bs_free_txpg(struct rtw_dev *rtwdev, u8 queue)
}
}
+/*
+ * The other chips with a non-8051 MCU (RTL8822BS, RTL8822CS, RTL8821CS) report
+ * their free pages in three registers, one 12 bit count per FIFO, and the
+ * free entries of the AC output queue in the third. Reading them for every
+ * transfer costs three register reads, more bus time than the transfer of a
+ * small frame. The chip only frees pages and entries, so counts read earlier
+ * and reduced by every transfer since then never exceed what is really free:
+ * keep them and read the registers again only when they say a transfer does
+ * not fit.
+ */
+static void rtw_sdio_88xx_sync_free_txpg(struct rtw_dev *rtwdev)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ u32 free_txpg[3];
+
+ lockdep_assert_held(&rtwsdio->tx_credit_lock);
+
+ free_txpg[0] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG);
+ free_txpg[1] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 4);
+ free_txpg[2] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 8);
+
+ atomic_set(&rtwsdio->free_pg_high, free_txpg[0] & 0xfff);
+ atomic_set(&rtwsdio->free_pg_normal, (free_txpg[0] >> 16) & 0xfff);
+ atomic_set(&rtwsdio->free_pg_low, free_txpg[1] & 0xfff);
+ atomic_set(&rtwsdio->free_pg_pub, (free_txpg[1] >> 16) & 0xfff);
+ atomic_set(&rtwsdio->free_pg_extra, free_txpg[2] & 0xfff);
+ atomic_set(&rtwsdio->tx_oqt_free, (free_txpg[2] >> 16) & 0xff);
+
+ rtwsdio->free_txpg_valid = true;
+}
+
+static void rtw_sdio_88xx_invalidate_free_txpg(struct rtw_dev *rtwdev)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+
+ guard(mutex)(&rtwsdio->tx_credit_lock);
+
+ rtwsdio->free_txpg_valid = false;
+}
+
+static atomic_t *rtw_sdio_88xx_free_txpg(struct rtw_dev *rtwdev, u8 queue)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+
+ switch (queue) {
+ case RTW_TX_QUEUE_BCN:
+ case RTW_TX_QUEUE_H2C:
+ case RTW_TX_QUEUE_HI0:
+ return &rtwsdio->free_pg_high;
+ case RTW_TX_QUEUE_VI:
+ case RTW_TX_QUEUE_VO:
+ return &rtwsdio->free_pg_normal;
+ case RTW_TX_QUEUE_BE:
+ case RTW_TX_QUEUE_BK:
+ return &rtwsdio->free_pg_low;
+ case RTW_TX_QUEUE_MGMT:
+ return &rtwsdio->free_pg_extra;
+ default:
+ return NULL;
+ }
+}
+
+static bool rtw_sdio_queue_is_ac(u8 queue)
+{
+ return queue <= RTW_TX_QUEUE_VO;
+}
+
+static bool rtw_sdio_88xx_txpg_fits(struct rtw_dev *rtwdev, atomic_t *dedicated,
+ u8 queue, unsigned int pages,
+ unsigned int frames)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+
+ if (atomic_read(dedicated) + atomic_read(&rtwsdio->free_pg_pub) < pages)
+ return false;
+
+ /* every frame of an AC queue takes an entry of the output queue */
+ if (rtw_sdio_queue_is_ac(queue) &&
+ atomic_read(&rtwsdio->tx_oqt_free) < frames)
+ return false;
+
+ return true;
+}
+
+/*
+ * Reserve the pages and output queue entries for a transfer of @frames frames
+ * needing @pages pages, from the queue's dedicated pages first and then from
+ * the public ones, as the chip charges them. The caller holds tx_credit_lock
+ * until the transfer is done, so that the counts are never read back from the
+ * chip while a transfer they were already reduced for has not reached it.
+ */
+static int rtw_sdio_88xx_reserve_txpg(struct rtw_dev *rtwdev, u8 queue,
+ unsigned int pages, unsigned int frames)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ atomic_t *dedicated;
+ unsigned int taken;
+
+ lockdep_assert_held(&rtwsdio->tx_credit_lock);
+
+ dedicated = rtw_sdio_88xx_free_txpg(rtwdev, queue);
+ if (!dedicated) {
+ rtw_warn(rtwdev, "Unknown mapping for queue %u\n", queue);
+ return -EINVAL;
+ }
+
+ if (!rtwsdio->free_txpg_valid ||
+ !rtw_sdio_88xx_txpg_fits(rtwdev, dedicated, queue, pages, frames))
+ rtw_sdio_88xx_sync_free_txpg(rtwdev);
+
+ if (!rtw_sdio_88xx_txpg_fits(rtwdev, dedicated, queue, pages, frames)) {
+ rtw_dbg(rtwdev, RTW_DBG_SDIO,
+ "Not enough free pages (%u needed, %u free) or output queue entries (%u needed, %u free) in queue %u\n",
+ pages, atomic_read(dedicated) +
+ atomic_read(&rtwsdio->free_pg_pub), frames,
+ atomic_read(&rtwsdio->tx_oqt_free), queue);
+ return -EBUSY;
+ }
+
+ taken = min_t(unsigned int, pages, atomic_read(dedicated));
+ atomic_sub(taken, dedicated);
+ atomic_sub(pages - taken, &rtwsdio->free_pg_pub);
+
+ if (rtw_sdio_queue_is_ac(queue))
+ atomic_sub(frames, &rtwsdio->tx_oqt_free);
+
+ return 0;
+}
+
static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue,
size_t count)
{
@@ -727,40 +856,8 @@ static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue,
/* add the pages from the public queue */
pages_free += (free_txpg >> 24) & 0xff;
} else {
- u32 free_txpg[3];
-
- free_txpg[0] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG);
- free_txpg[1] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 4);
- free_txpg[2] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 8);
-
- switch (queue) {
- case RTW_TX_QUEUE_BCN:
- case RTW_TX_QUEUE_H2C:
- case RTW_TX_QUEUE_HI0:
- /* high */
- pages_free = free_txpg[0] & 0xfff;
- break;
- case RTW_TX_QUEUE_VI:
- case RTW_TX_QUEUE_VO:
- /* normal */
- pages_free = (free_txpg[0] >> 16) & 0xfff;
- break;
- case RTW_TX_QUEUE_BE:
- case RTW_TX_QUEUE_BK:
- /* low */
- pages_free = free_txpg[1] & 0xfff;
- break;
- case RTW_TX_QUEUE_MGMT:
- /* extra */
- pages_free = free_txpg[2] & 0xfff;
- break;
- default:
- rtw_warn(rtwdev, "Unknown mapping for queue %u\n", queue);
- return -EINVAL;
- }
-
- /* add the pages from the public queue */
- pages_free += (free_txpg[1] >> 16) & 0xfff;
+ /* the other chips use rtw_sdio_88xx_reserve_txpg() */
+ return -EINVAL;
}
pages_needed = DIV_ROUND_UP(count, rtwdev->chip->page_size);
@@ -889,6 +986,32 @@ static int rtw_sdio_write_port_8723bs(struct rtw_dev *rtwdev,
return 0;
}
+static int rtw_sdio_write_port_88xx(struct rtw_dev *rtwdev,
+ struct sk_buff *skb,
+ enum rtw_tx_queue_type queue, u32 txaddr,
+ size_t write_size)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ unsigned int pages;
+ int ret;
+
+ /* the chip charges pages by frame length, not by the padded transfer */
+ pages = DIV_ROUND_UP(skb->len, rtwdev->chip->page_size);
+
+ guard(mutex)(&rtwsdio->tx_credit_lock);
+
+ ret = rtw_sdio_88xx_reserve_txpg(rtwdev, queue, pages, 1);
+ if (ret)
+ return ret;
+
+ ret = rtw_sdio_write_to_port(rtwdev, skb, queue, txaddr, write_size);
+ if (ret)
+ /* the pages may or may not have been used, read them again */
+ rtwsdio->free_txpg_valid = false;
+
+ return ret;
+}
+
static int rtw_sdio_write_port_generic(struct rtw_dev *rtwdev,
struct sk_buff *skb,
enum rtw_tx_queue_type queue, u32 txaddr,
@@ -933,6 +1056,10 @@ static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb,
return rtw_sdio_write_port_8723bs(rtwdev, skb, queue, txaddr,
write_size);
+ if (!rtw_chip_wcpu_8051(rtwdev))
+ return rtw_sdio_write_port_88xx(rtwdev, skb, queue, txaddr,
+ write_size);
+
return rtw_sdio_write_port_generic(rtwdev, skb, queue, txaddr,
write_size);
}
@@ -1067,6 +1194,9 @@ static int rtw_sdio_start(struct rtw_dev *rtwdev)
return ret;
}
+ if (!rtw_chip_wcpu_8051(rtwdev))
+ rtw_sdio_88xx_invalidate_free_txpg(rtwdev);
+
rtw_sdio_enable_rx_aggregation(rtwdev);
if (rtw_is_8723bs(rtwdev)) {
@@ -1083,6 +1213,9 @@ static int rtw_sdio_start(struct rtw_dev *rtwdev)
static void rtw_sdio_stop(struct rtw_dev *rtwdev)
{
rtw_sdio_disable_interrupt(rtwdev);
+
+ if (!rtw_chip_wcpu_8051(rtwdev))
+ rtw_sdio_88xx_invalidate_free_txpg(rtwdev);
}
static void rtw_sdio_deep_ps_enter(struct rtw_dev *rtwdev)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index 6e7e6009744..57890533eec 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -178,7 +178,10 @@ struct rtw_sdio {
atomic_t free_pg_normal;
atomic_t free_pg_low;
atomic_t free_pg_pub;
+ atomic_t free_pg_extra;
atomic_t tx_oqt_free;
+ /* the non-8051 chips' counters hold what the chip last reported */
+ bool free_txpg_valid;
/* one writer at a time between the credit check and the accounting */
struct mutex tx_credit_lock;
};
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH rtw-next 2/5] wifi: rtw88: sdio: aggregate TX frames of the 88xx chips
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips 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 ` David Härdeman
2026-11-16 19:01 ` [PATCH rtw-next 3/5] wifi: rtw88: sdio: limit the TX queue length " David Härdeman
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Härdeman @ 2026-11-16 19:01 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Leonard Lausen, Alastair D'Silva, Luka Gejak,
Martin Blumenstingl, Jernej Skrabec, Bitterblue Smith,
David Härdeman
The 88xx chips accept several frames in one transfer: the first TX
descriptor carries the number of frames in DMA_TXAGG_NUM and every frame
starts 8 byte aligned, as for USB TX aggregation. Realtek's driver sends
up to about 32 KiB per transfer this way. rtw88 sends one frame per
transfer, so a full sized frame costs a CMD53 and its interrupts, and
the RTL8822CS cannot get near its PHY rate.
When an AC queue holds more than one frame, copy up to 32 frames or
20 KiB of the same access category into a buffer and send them with one
transfer. The chip rejects aggregates that mix access categories; an AC
queue only holds one, but the queue select of each frame is checked to
be sure. Every frame is charged its own pages and output queue entry,
so the aggregate is shrunk until it fits what is free. A frame too big
for the buffer is sent on its own, as before.
The RTL8723BS and the other chips with an 8051 MCU keep sending one
frame per transfer.
On a NanoPi R76S (RTL8822CS, SDR104) acting as an AP, TCP throughput to
a client goes from about 100 to about 220 Mbit/s, and from the client
from about 185 to about 245 Mbit/s. Realtek's driver reaches about 183
and 265 Mbit/s on the same setup.
Signed-off-by: David Härdeman <david@hardeman.nu>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 181 +++++++++++++++++++++-
drivers/net/wireless/realtek/rtw88/sdio.h | 6 +
2 files changed, 180 insertions(+), 7 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index 49d733a5104..17a4c3037d7 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -919,16 +919,16 @@ static void rtw_sdio_8723bs_consume_txpg(struct rtw_dev *rtwdev, u8 queue,
atomic_set(&rtwsdio->free_pg_pub, 0);
}
-static int rtw_sdio_write_to_port(struct rtw_dev *rtwdev, struct sk_buff *skb,
- enum rtw_tx_queue_type queue, u32 txaddr,
- size_t write_size)
+static int rtw_sdio_write_buf_to_port(struct rtw_dev *rtwdev, void *buf,
+ enum rtw_tx_queue_type queue, u32 txaddr,
+ size_t write_size)
{
struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
bool bus_claim;
int ret;
- if (!IS_ALIGNED((unsigned long)skb->data, RTW_SDIO_DATA_PTR_ALIGN))
- rtw_warn(rtwdev, "Got unaligned SKB in %s() for queue %u\n",
+ if (!IS_ALIGNED((unsigned long)buf, RTW_SDIO_DATA_PTR_ALIGN))
+ rtw_warn(rtwdev, "Got unaligned buffer in %s() for queue %u\n",
__func__, queue);
bus_claim = rtw_sdio_bus_claim_needed(rtwsdio);
@@ -936,8 +936,7 @@ static int rtw_sdio_write_to_port(struct rtw_dev *rtwdev, struct sk_buff *skb,
if (bus_claim)
sdio_claim_host(rtwsdio->sdio_func);
- ret = sdio_memcpy_toio(rtwsdio->sdio_func, txaddr, skb->data,
- write_size);
+ ret = sdio_memcpy_toio(rtwsdio->sdio_func, txaddr, buf, write_size);
if (bus_claim)
sdio_release_host(rtwsdio->sdio_func);
@@ -950,6 +949,14 @@ static int rtw_sdio_write_to_port(struct rtw_dev *rtwdev, struct sk_buff *skb,
return ret;
}
+static int rtw_sdio_write_to_port(struct rtw_dev *rtwdev, struct sk_buff *skb,
+ enum rtw_tx_queue_type queue, u32 txaddr,
+ size_t write_size)
+{
+ return rtw_sdio_write_buf_to_port(rtwdev, skb->data, queue, txaddr,
+ write_size);
+}
+
static int rtw_sdio_write_port_8723bs(struct rtw_dev *rtwdev,
struct sk_buff *skb,
enum rtw_tx_queue_type queue, u32 txaddr,
@@ -1760,6 +1767,148 @@ static void rtw_sdio_indicate_tx_status(struct rtw_dev *rtwdev,
ieee80211_tx_status_irqsafe(hw, skb);
}
+/* the access category of a data frame's TX descriptor queue select (TID) */
+static u8 rtw_sdio_skb_qsel_ac(struct sk_buff *skb)
+{
+ static const u8 tid_to_ac[] = {
+ IEEE80211_AC_BE, IEEE80211_AC_BK, IEEE80211_AC_BK,
+ IEEE80211_AC_BE, IEEE80211_AC_VI, IEEE80211_AC_VI,
+ IEEE80211_AC_VO, IEEE80211_AC_VO,
+ };
+ struct rtw_tx_desc *tx_desc = (struct rtw_tx_desc *)skb->data;
+ u8 qsel = le32_get_bits(tx_desc->w1, RTW_TX_DESC_W1_QSEL);
+
+ return qsel < ARRAY_SIZE(tid_to_ac) ? tid_to_ac[qsel] : U8_MAX;
+}
+
+static unsigned int rtw_sdio_agg_pages(struct rtw_dev *rtwdev,
+ struct sk_buff_head *agg)
+{
+ unsigned int pages = 0;
+ struct sk_buff *skb;
+
+ /* the chip charges every frame of an aggregate its own pages */
+ skb_queue_walk(agg, skb)
+ pages += DIV_ROUND_UP(skb->len, rtwdev->chip->page_size);
+
+ return pages;
+}
+
+/*
+ * Send several frames of an AC queue with one transfer, for the 88xx chips:
+ * each frame, TX descriptor and payload, starts 8 byte aligned and the first
+ * descriptor carries the number of frames, as for USB TX aggregation. This
+ * saves a transfer, and its interrupts, per frame. The chip takes the frames
+ * of one access category only, which an AC queue holds anyway, but check the
+ * queue select of every frame to be sure.
+ *
+ * Returns 0 when frames were written, 1 when the queue was empty, -E2BIG when
+ * the first frame does not fit the buffer and another negative errno when
+ * the write failed. In both error cases the frames are back in the queue.
+ */
+static int rtw_sdio_process_tx_agg(struct rtw_dev *rtwdev,
+ enum rtw_tx_queue_type queue)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ struct sk_buff_head *list = &rtwsdio->tx_queue[queue];
+ struct rtw_tx_pkt_info pkt_info = {};
+ u8 *buf = rtwsdio->tx_agg_buf;
+ struct rtw_tx_desc *tx_desc;
+ size_t len = 0, write_size;
+ struct sk_buff_head agg;
+ unsigned int num = 0;
+ struct sk_buff *skb;
+ u8 ac = U8_MAX;
+ u32 txaddr;
+ int ret;
+
+ __skb_queue_head_init(&agg);
+
+ while (num < RTW_SDIO_TX_AGG_MAX_NUM) {
+ skb = skb_dequeue(list);
+ if (!skb)
+ break;
+
+ if (!num) {
+ if (skb->len > RTW_SDIO_TX_AGG_MAX_SIZE) {
+ skb_queue_head(list, skb);
+ return -E2BIG;
+ }
+ ac = rtw_sdio_skb_qsel_ac(skb);
+ } else if (ALIGN(len, 8) + skb->len > RTW_SDIO_TX_AGG_MAX_SIZE ||
+ rtw_sdio_skb_qsel_ac(skb) != ac) {
+ skb_queue_head(list, skb);
+ break;
+ }
+
+ len = (num ? ALIGN(len, 8) : 0) + skb->len;
+ __skb_queue_tail(&agg, skb);
+ num++;
+ }
+
+ if (!num)
+ return 1;
+
+ mutex_lock(&rtwsdio->tx_credit_lock);
+
+ /* shrink the aggregate until it fits the free pages and entries */
+ for (;;) {
+ ret = rtw_sdio_88xx_reserve_txpg(rtwdev, queue,
+ rtw_sdio_agg_pages(rtwdev, &agg),
+ num);
+ if (!ret)
+ break;
+ if (ret != -EBUSY || num == 1)
+ goto err_requeue;
+
+ skb_queue_head(list, __skb_dequeue_tail(&agg));
+ num--;
+ }
+
+ len = 0;
+ skb_queue_walk(&agg, skb) {
+ len = ALIGN(len, 8);
+ memcpy(buf + len, skb->data, skb->len);
+ len += skb->len;
+ }
+
+ if (num > 1) {
+ tx_desc = (struct rtw_tx_desc *)buf;
+ le32p_replace_bits(&tx_desc->w7, num,
+ RTW_TX_DESC_W7_DMA_TXAGG_NUM);
+ pkt_info.pkt_offset = le32_get_bits(tx_desc->w1,
+ RTW_TX_DESC_W1_PKT_OFFSET);
+ rtw_tx_fill_txdesc_checksum(rtwdev, &pkt_info, buf);
+ }
+
+ txaddr = rtw_sdio_get_tx_addr(rtwdev, len, queue);
+ write_size = sdio_align_size(rtwsdio->sdio_func, len);
+ memset(buf + len, 0, write_size - len);
+
+ ret = rtw_sdio_write_buf_to_port(rtwdev, buf, queue, txaddr,
+ write_size);
+ if (ret) {
+ /* the pages may or may not have been used, read them again */
+ rtwsdio->free_txpg_valid = false;
+ goto err_requeue;
+ }
+
+ mutex_unlock(&rtwsdio->tx_credit_lock);
+
+ while ((skb = __skb_dequeue(&agg)))
+ rtw_sdio_indicate_tx_status(rtwdev, skb);
+
+ return 0;
+
+err_requeue:
+ mutex_unlock(&rtwsdio->tx_credit_lock);
+
+ while ((skb = __skb_dequeue_tail(&agg)))
+ skb_queue_head(list, skb);
+
+ return ret;
+}
+
/*
* Send one frame from @queue. Returns 0 when a frame was written, 1 when the
* queue was empty and a negative errno when the write failed, in which case
@@ -1773,6 +1922,13 @@ static int rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev,
u16 q_map;
int ret;
+ if (rtwsdio->tx_agg_buf && rtw_sdio_queue_is_ac(queue) &&
+ skb_queue_len(&rtwsdio->tx_queue[queue]) > 1) {
+ ret = rtw_sdio_process_tx_agg(rtwdev, queue);
+ if (ret != -E2BIG)
+ return ret;
+ }
+
skb = skb_dequeue(&rtwsdio->tx_queue[queue]);
if (!skb)
return 1;
@@ -1878,6 +2034,15 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)
mutex_init(&rtwsdio->tx_credit_lock);
+ /*
+ * TX aggregation relies on the free page and output queue counts
+ * that only the non-8051 chips keep; without the buffer, frames are
+ * sent one by one.
+ */
+ if (!rtw_chip_wcpu_8051(rtwdev))
+ rtwsdio->tx_agg_buf = kmalloc(RTW_SDIO_TX_AGG_MAX_SIZE +
+ RTW_SDIO_BLOCK_SIZE, GFP_KERNEL);
+
for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++) {
skb_queue_head_init(&rtwsdio->tx_queue[i]);
rtwsdio->tx_queue_stopped[i] = false;
@@ -1892,6 +2057,7 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)
return 0;
err_destroy_wq:
+ kfree(rtwsdio->tx_agg_buf);
mutex_destroy(&rtwsdio->tx_credit_lock);
destroy_workqueue(rtwsdio->txwq);
return -ENOMEM;
@@ -1909,6 +2075,7 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev)
for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++)
ieee80211_purge_tx_queue(rtwdev->hw, &rtwsdio->tx_queue[i]);
+ kfree(rtwsdio->tx_agg_buf);
mutex_destroy(&rtwsdio->tx_credit_lock);
}
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index 57890533eec..ab366f82d92 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -148,6 +148,10 @@
#define RTW_SDIO_DATA_PTR_ALIGN 8
+/* TX aggregation of the 88xx chips: at most this much per transfer */
+#define RTW_SDIO_TX_AGG_MAX_SIZE (20 * 1024)
+#define RTW_SDIO_TX_AGG_MAX_NUM 32
+
struct sdio_func;
struct sdio_device_id;
@@ -182,6 +186,8 @@ struct rtw_sdio {
atomic_t tx_oqt_free;
/* the non-8051 chips' counters hold what the chip last reported */
bool free_txpg_valid;
+ /* TX aggregation buffer of the non-8051 chips, under tx_credit_lock */
+ u8 *tx_agg_buf;
/* one writer at a time between the credit check and the accounting */
struct mutex tx_credit_lock;
};
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH rtw-next 3/5] wifi: rtw88: sdio: limit the TX queue length of the 88xx chips
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips 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
2026-11-16 19:01 ` [PATCH rtw-next 4/5] wifi: rtw88: sdio: let TX in while receiving on " David Härdeman
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: David Härdeman @ 2026-11-16 19:01 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Leonard Lausen, Alastair D'Silva, Luka Gejak,
Martin Blumenstingl, Jernej Skrabec, Bitterblue Smith,
David Härdeman
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH rtw-next 4/5] wifi: rtw88: sdio: let TX in while receiving on the 88xx chips
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips David Härdeman
` (2 preceding siblings ...)
2026-11-16 19:01 ` [PATCH rtw-next 3/5] wifi: rtw88: sdio: limit the TX queue length " David Härdeman
@ 2026-11-16 19:01 ` 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
5 siblings, 0 replies; 7+ messages in thread
From: David Härdeman @ 2026-11-16 19:01 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Leonard Lausen, Alastair D'Silva, Luka Gejak,
Martin Blumenstingl, Jernej Skrabec, Bitterblue Smith,
David Härdeman
The interrupt handler reads RX data for up to 64 KiB per interrupt while
it holds the host, and the TX work waits for the host meanwhile. At
SDR104 speeds an RTL8822CS spends most of the bus time on the per
transfer overhead, so when a client sends at full rate, the RX path
takes about 80% of the bus and leaves too little for TX. On a NanoPi
R76S acting as an AP, with TCP traffic in both directions, the AP sends
at only 20-35 Mbit/s while it receives at 165-220 Mbit/s.
When frames are waiting to be sent, stop reading after 8 KiB, about one
RX aggregate, so the TX work gets the host between reads; the handler
runs again for the rest. Without TX frames waiting, it still reads up
to 64 KiB. The 8051 chips keep their behaviour.
With traffic in both directions, the R76S now sends at 70-85 Mbit/s
while receiving at 100-120 Mbit/s, steadily over each run. The sum is
somewhat lower, as sending costs more bus time than receiving, and
one-way throughput doesn't change. Realtek's driver shows the same
imbalance as before (about 40 + 180 Mbit/s on the same setup).
Signed-off-by: David Härdeman <david@hardeman.nu>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 39 ++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index cced6fdfa6d..a7664486613 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -34,6 +34,14 @@
#define RTW_SDIO_88XX_TX_FIFO_LOWATER 32
#define RTW_SDIO_TX_RETRY_DELAY msecs_to_jiffies(1)
+/*
+ * The interrupt handler holds the host while it reads RX data. Bound how much
+ * it reads per interrupt, and with frames waiting to be sent, let the TX path
+ * have the host after a smaller amount.
+ */
+#define RTW_SDIO_RX_BUDGET SZ_64K
+#define RTW_SDIO_RX_BUDGET_TX_PENDING SZ_8K
+
static bool rtw_sdio_is_bus_addr(u32 addr)
{
return !!(addr & RTW_SDIO_BUS_MSK);
@@ -1597,6 +1605,34 @@ static void rtw_sdio_rxfifo_recv(struct rtw_dev *rtwdev, u32 rx_len)
}
}
+static bool rtw_sdio_tx_pending(struct rtw_dev *rtwdev)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ int queue;
+
+ for (queue = 0; queue <= RTW_TX_QUEUE_VO; queue++)
+ if (!skb_queue_empty(&rtwsdio->tx_queue[queue]))
+ return true;
+
+ return false;
+}
+
+static bool rtw_sdio_rx_budget_left(struct rtw_dev *rtwdev, u32 rx_bytes)
+{
+ if (rx_bytes >= RTW_SDIO_RX_BUDGET)
+ return false;
+
+ /*
+ * The 8051 chips send one frame per transfer and are not limited by
+ * the bus in the same way, keep their behaviour.
+ */
+ if (rtw_chip_wcpu_8051(rtwdev))
+ return true;
+
+ return rx_bytes < RTW_SDIO_RX_BUDGET_TX_PENDING ||
+ !rtw_sdio_tx_pending(rtwdev);
+}
+
static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev)
{
u32 rx_len, hisr, total_rx_bytes = 0;
@@ -1631,7 +1667,8 @@ static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev)
*/
hisr = REG_SDIO_HISR_RX_REQUEST;
}
- } while (total_rx_bytes < SZ_64K && hisr & REG_SDIO_HISR_RX_REQUEST);
+ } while (rtw_sdio_rx_budget_left(rtwdev, total_rx_bytes) &&
+ hisr & REG_SDIO_HISR_RX_REQUEST);
}
static void rtw_sdio_handle_interrupt(struct sdio_func *sdio_func)
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH rtw-next 5/5] wifi: rtw88: sdio: read neighbouring registers of the 88xx chips at once
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips David Härdeman
` (3 preceding siblings ...)
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 ` 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
5 siblings, 0 replies; 7+ messages in thread
From: David Härdeman @ 2026-11-16 19:01 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Leonard Lausen, Alastair D'Silva, Luka Gejak,
Martin Blumenstingl, Jernej Skrabec, Bitterblue Smith,
David Härdeman
Every register access costs a full SDIO command, about 40 us on a NanoPi
R76S (RTL8822CS, SDR104), no matter how many bytes it moves. The
interrupt handler reads HISR and then RX0_REQ_LEN, which follows it, and
a free page sync reads the three REG_SDIO_FREE_TXPG words one by one.
Read HISR together with RX0_REQ_LEN, and the three free page words, with
one transfer each, as Realtek's driver does. As in rtw_sdio_readl(),
this is only done while the chip is powered on; before that, and if the
small DMA-safe buffers this needs could not be allocated, the registers
are read one by one as before.
On the R76S acting as an AP, TCP throughput to a client goes from about
170 to about 190 Mbit/s, the other directions are unchanged.
Signed-off-by: David Härdeman <david@hardeman.nu>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 84 ++++++++++++++++++++---
drivers/net/wireless/realtek/rtw88/sdio.h | 4 ++
2 files changed, 78 insertions(+), 10 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index a7664486613..76309405b4e 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -700,16 +700,59 @@ static atomic_t *rtw_sdio_8723bs_free_txpg(struct rtw_dev *rtwdev, u8 queue)
* keep them and read the registers again only when they say a transfer does
* not fit.
*/
+/*
+ * Read consecutive SDIO local registers with one transfer instead of one per
+ * register. buf must be DMA-safe. Like rtw_sdio_readl(), this only uses CMD53
+ * while the chip is powered on; otherwise it fails with -EAGAIN and the caller
+ * reads the registers one by one.
+ */
+static int rtw_sdio_read_local_regs(struct rtw_dev *rtwdev, u32 addr,
+ __le32 *buf, unsigned int num)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ bool bus_claim;
+ int ret;
+
+ if (!rtw_sdio_use_memcpy_io(rtwdev, addr, 4))
+ return -EAGAIN;
+
+ bus_claim = rtw_sdio_bus_claim_needed(rtwsdio);
+
+ if (bus_claim)
+ sdio_claim_host(rtwsdio->sdio_func);
+
+ ret = sdio_memcpy_fromio(rtwsdio->sdio_func, buf,
+ rtw_sdio_to_io_address(rtwdev, addr, true),
+ num * sizeof(*buf));
+
+ if (bus_claim)
+ sdio_release_host(rtwsdio->sdio_func);
+
+ if (ret)
+ rtw_warn(rtwdev, "sdio read of %u registers at 0x%x failed: %d",
+ num, addr, ret);
+
+ return ret;
+}
+
static void rtw_sdio_88xx_sync_free_txpg(struct rtw_dev *rtwdev)
{
struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ __le32 *regs = rtwsdio->txpg_regs;
u32 free_txpg[3];
lockdep_assert_held(&rtwsdio->tx_credit_lock);
- free_txpg[0] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG);
- free_txpg[1] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 4);
- free_txpg[2] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 8);
+ if (regs && !rtw_sdio_read_local_regs(rtwdev, REG_SDIO_FREE_TXPG,
+ regs, 3)) {
+ free_txpg[0] = le32_to_cpu(regs[0]);
+ free_txpg[1] = le32_to_cpu(regs[1]);
+ free_txpg[2] = le32_to_cpu(regs[2]);
+ } else {
+ free_txpg[0] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG);
+ free_txpg[1] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 4);
+ free_txpg[2] = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG + 8);
+ }
atomic_set(&rtwsdio->free_pg_high, free_txpg[0] & 0xfff);
atomic_set(&rtwsdio->free_pg_normal, (free_txpg[0] >> 16) & 0xfff);
@@ -1633,12 +1676,15 @@ static bool rtw_sdio_rx_budget_left(struct rtw_dev *rtwdev, u32 rx_bytes)
!rtw_sdio_tx_pending(rtwdev);
}
-static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev)
+/* rx_len: the RX request length if it was read together with HISR, or 0 */
+static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev, u32 rx_len)
{
- u32 rx_len, hisr, total_rx_bytes = 0;
+ u32 hisr, total_rx_bytes = 0;
do {
- if (rtw_chip_wcpu_8051(rtwdev))
+ if (rx_len)
+ ;
+ else if (rtw_chip_wcpu_8051(rtwdev))
rx_len = rtw_read16(rtwdev, REG_SDIO_RX0_REQ_LEN);
else
rx_len = rtw_read32(rtwdev, REG_SDIO_RX0_REQ_LEN);
@@ -1649,6 +1695,7 @@ static void rtw_sdio_rx_isr(struct rtw_dev *rtwdev)
rtw_sdio_rxfifo_recv(rtwdev, rx_len);
total_rx_bytes += rx_len;
+ rx_len = 0;
if (rtw_chip_wcpu_8051(rtwdev)) {
/* Stop if no more RX requests are pending, even if
@@ -1676,20 +1723,28 @@ static void rtw_sdio_handle_interrupt(struct sdio_func *sdio_func)
struct ieee80211_hw *hw = sdio_get_drvdata(sdio_func);
struct rtw_sdio *rtwsdio;
struct rtw_dev *rtwdev;
- u32 hisr;
+ u32 hisr, rx_len = 0;
rtwdev = hw->priv;
rtwsdio = (struct rtw_sdio *)rtwdev->priv;
rtwsdio->irq_thread = current;
- hisr = rtw_read32(rtwdev, REG_SDIO_HISR);
+ /* RX0_REQ_LEN follows HISR, read both at once where possible */
+ if (rtwsdio->rx_regs &&
+ !rtw_sdio_read_local_regs(rtwdev, REG_SDIO_HISR,
+ rtwsdio->rx_regs, 2)) {
+ hisr = le32_to_cpu(rtwsdio->rx_regs[0]);
+ rx_len = le32_to_cpu(rtwsdio->rx_regs[1]);
+ } else {
+ hisr = rtw_read32(rtwdev, REG_SDIO_HISR);
+ }
if (hisr & REG_SDIO_HISR_TXERR)
rtw_sdio_tx_err_isr(rtwdev);
if (hisr & REG_SDIO_HISR_RX_REQUEST) {
hisr &= ~REG_SDIO_HISR_RX_REQUEST;
- rtw_sdio_rx_isr(rtwdev);
+ rtw_sdio_rx_isr(rtwdev, rx_len);
}
/*
@@ -2127,9 +2182,14 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)
* that only the non-8051 chips keep; without the buffer, frames are
* sent one by one.
*/
- if (!rtw_chip_wcpu_8051(rtwdev))
+ if (!rtw_chip_wcpu_8051(rtwdev)) {
rtwsdio->tx_agg_buf = kmalloc(RTW_SDIO_TX_AGG_MAX_SIZE +
RTW_SDIO_BLOCK_SIZE, GFP_KERNEL);
+ /* without these, the registers are read one by one */
+ rtwsdio->rx_regs = kmalloc_array(2, sizeof(__le32), GFP_KERNEL);
+ rtwsdio->txpg_regs = kmalloc_array(3, sizeof(__le32),
+ GFP_KERNEL);
+ }
for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++) {
skb_queue_head_init(&rtwsdio->tx_queue[i]);
@@ -2146,6 +2206,8 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)
err_destroy_wq:
kfree(rtwsdio->tx_agg_buf);
+ kfree(rtwsdio->rx_regs);
+ kfree(rtwsdio->txpg_regs);
mutex_destroy(&rtwsdio->tx_credit_lock);
destroy_workqueue(rtwsdio->txwq);
return -ENOMEM;
@@ -2164,6 +2226,8 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev)
ieee80211_purge_tx_queue(rtwdev->hw, &rtwsdio->tx_queue[i]);
kfree(rtwsdio->tx_agg_buf);
+ kfree(rtwsdio->rx_regs);
+ kfree(rtwsdio->txpg_regs);
mutex_destroy(&rtwsdio->tx_credit_lock);
}
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index ab366f82d92..6aa59ed3db2 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -188,6 +188,10 @@ struct rtw_sdio {
bool free_txpg_valid;
/* TX aggregation buffer of the non-8051 chips, under tx_credit_lock */
u8 *tx_agg_buf;
+ /* non-8051 chips: HISR + RX0_REQ_LEN, read by the interrupt handler */
+ __le32 *rx_regs;
+ /* non-8051 chips: the REG_SDIO_FREE_TXPG words, under tx_credit_lock */
+ __le32 *txpg_regs;
/* one writer at a time between the credit check and the accounting */
struct mutex tx_credit_lock;
};
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips David Härdeman
` (4 preceding siblings ...)
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 ` Luka Gejak
5 siblings, 0 replies; 7+ messages in thread
From: Luka Gejak @ 2026-11-16 21:59 UTC (permalink / raw)
To: David Härdeman, Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Leonard Lausen, Alastair D'Silva,
Martin Blumenstingl, Jernej Skrabec, Bitterblue Smith
Hi David,
On November 16, 2026 8:01:40 PM GMT+01:00, "David Härdeman"
<david@hardeman.nu> wrote:
[ ... ]
>
>Two series on the list touch the same code, and I'd like to make sure
>this one doesn't clash with them:
>
>- Alastair D'Silva's "wifi: rtw88: sdio: Fix unhandled RX request
> interrupt storm" (v10) changes the RX interrupt handling that patches
> 4 and 5 touch. This series is based on rtw-next without it; I have a
> version rebased on top of it and will send that once it's applied.
> https://lore.kernel.org/linux-wireless/20261113082242.2773369-1-alastair@d-silva.org/
>
>- Leonard Lausen's "wifi: rtw88: reduce RTL8822CS SDIO request
> overhead" (v2): his patch 1 (control frame filter) is independent of
> this series and applies on top of it. His patch 2 combines the free
> page register reads that patch 1 here replaces with cached counts,
> so only one of the two makes sense; Leonard, I'm happy to go with
> whatever you and Ping-Ke prefer.
> https://lore.kernel.org/linux-wireless/20261116100804.425592-2-leonard@lausen.nl/
>
These two will probably land before your series, as both had gone through
couple(or more) versions and both carry my Reviewed-by tag.
Either way I will review it in the morning, so we will see then.
Best regards,
Luka Gejak
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-16 21:59 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 19:01 [PATCH rtw-next 0/5] wifi: rtw88: sdio: faster and fairer TX for the 88xx chips 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 ` [PATCH rtw-next 3/5] wifi: rtw88: sdio: limit the TX queue length " David Härdeman
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
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®