* [PATCH v5 1/6] wifi: rtw88: add the RTL8723B chip type and SDIO helper
2026-08-14 10:53 [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS luka.gejak
@ 2026-08-14 10:53 ` luka.gejak
2026-08-14 10:53 ` [PATCH v5 2/6] wifi: rtw88: rx: mark zero length packets on RTL8723BS luka.gejak
` (5 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: luka.gejak @ 2026-08-14 10:53 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Michael Straube, Bitterblue Smith, Peter Robinson,
Hans de Goede, Luka Gejak
From: Luka Gejak <luka.gejak@linux.dev>
The RTL8723B is a 802.11n combo chip whose SDIO variant, RTL8723BS, runs
a Realtek vendor firmware that differs from the firmware used by the
other rtw88 8723 family devices. Supporting it needs a number of small
adjustments spread across the shared core, all of which have to be
restricted to this one chip and bus combination.
Add the chip type and a helper that tests for it, so the changes that
follow can be gated without repeating the chip and bus comparison.
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
---
drivers/net/wireless/realtek/rtw88/main.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h
index c6e981ba7986..8f86f7c12de5 100644
--- a/drivers/net/wireless/realtek/rtw88/main.h
+++ b/drivers/net/wireless/realtek/rtw88/main.h
@@ -194,6 +194,7 @@ enum rtw_chip_type {
RTW_CHIP_TYPE_8723D,
RTW_CHIP_TYPE_8821C,
RTW_CHIP_TYPE_8703B,
+ RTW_CHIP_TYPE_8723B,
RTW_CHIP_TYPE_8821A,
RTW_CHIP_TYPE_8812A,
RTW_CHIP_TYPE_8814A,
@@ -2194,6 +2195,12 @@ static inline bool rtw_chip_has_tx_stbc(struct rtw_dev *rtwdev)
return rtwdev->chip->tx_stbc;
}
+static inline bool rtw_is_8723bs(struct rtw_dev *rtwdev)
+{
+ return rtwdev->chip->id == RTW_CHIP_TYPE_8723B &&
+ rtwdev->hci.type == RTW_HCI_TYPE_SDIO;
+}
+
static inline u8 rtw_acquire_macid(struct rtw_dev *rtwdev)
{
unsigned long mac_id;
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v5 2/6] wifi: rtw88: rx: mark zero length packets on RTL8723BS
2026-08-14 10:53 [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS luka.gejak
2026-08-14 10:53 ` [PATCH v5 1/6] wifi: rtw88: add the RTL8723B chip type and SDIO helper luka.gejak
@ 2026-08-14 10:53 ` luka.gejak
2026-08-19 0:41 ` Ping-Ke Shih
2026-08-14 10:53 ` [PATCH v5 3/6] wifi: rtw88: tx: extend the TX report purge timeout to RTL8723BS luka.gejak
` (4 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: luka.gejak @ 2026-08-14 10:53 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Michael Straube, Bitterblue Smith, Peter Robinson,
Hans de Goede, Luka Gejak
From: Luka Gejak <luka.gejak@linux.dev>
Like the RTL8703B, the RTL8723BS reports receive descriptors with a zero
packet length, which the vendor driver drops outright. rtw88 already
flags these as having no PSDU for the RTL8703B, so extend the same
handling rather than passing an empty frame up.
This is gated on the SDIO interface rather than the chip id, because it
has only been observed there; the USB variant is not known to do it.
Co-developed-by: Michael Straube <straube.linux@gmail.com>
Signed-off-by: Michael Straube <straube.linux@gmail.com>
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
drivers/net/wireless/realtek/rtw88/rx.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/rx.c b/drivers/net/wireless/realtek/rtw88/rx.c
index 01fd299abb7f..fde21c840ac0 100644
--- a/drivers/net/wireless/realtek/rtw88/rx.c
+++ b/drivers/net/wireless/realtek/rtw88/rx.c
@@ -253,10 +253,12 @@ static void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
rtw_rx_addr_match(rtwdev, pkt_stat, hdr);
- /* Rtl8723cs driver checks for size < 14 or size > 8192 and
- * simply drops the packet.
+ /*
+ * Rtl8723cs and rtl8723bs drivers check for size < 14 or size > 8192
+ * and simply drop the packet.
*/
- if (rtwdev->chip->id == RTW_CHIP_TYPE_8703B && pkt_stat->pkt_len == 0) {
+ if (pkt_stat->pkt_len == 0 &&
+ (rtwdev->chip->id == RTW_CHIP_TYPE_8703B || rtw_is_8723bs(rtwdev))) {
rx_status->flag |= RX_FLAG_NO_PSDU;
rtw_dbg(rtwdev, RTW_DBG_RX, "zero length packet");
}
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* RE: [PATCH v5 2/6] wifi: rtw88: rx: mark zero length packets on RTL8723BS
2026-08-14 10:53 ` [PATCH v5 2/6] wifi: rtw88: rx: mark zero length packets on RTL8723BS luka.gejak
@ 2026-08-19 0:41 ` Ping-Ke Shih
0 siblings, 0 replies; 12+ messages in thread
From: Ping-Ke Shih @ 2026-08-19 0:41 UTC (permalink / raw)
To: luka.gejak@linux.dev, linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Michael Straube, Bitterblue Smith,
Peter Robinson, Hans de Goede
luka.gejak@linux.dev <luka.gejak@linux.dev> wrote:
> From: Luka Gejak <luka.gejak@linux.dev>
>
> Like the RTL8703B, the RTL8723BS reports receive descriptors with a zero
> packet length, which the vendor driver drops outright. rtw88 already
> flags these as having no PSDU for the RTL8703B, so extend the same
> handling rather than passing an empty frame up.
>
> This is gated on the SDIO interface rather than the chip id, because it
> has only been observed there; the USB variant is not known to do it.
>
> Co-developed-by: Michael Straube <straube.linux@gmail.com>
> Signed-off-by: Michael Straube <straube.linux@gmail.com>
> Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
By the way, though you have added change log in cover letter. It'd be
better to make a copy here (after --- delimiter).
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v5 3/6] wifi: rtw88: tx: extend the TX report purge timeout to RTL8723BS
2026-08-14 10:53 [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS luka.gejak
2026-08-14 10:53 ` [PATCH v5 1/6] wifi: rtw88: add the RTL8723B chip type and SDIO helper luka.gejak
2026-08-14 10:53 ` [PATCH v5 2/6] wifi: rtw88: rx: mark zero length packets on RTL8723BS luka.gejak
@ 2026-08-14 10:53 ` luka.gejak
2026-08-14 10:53 ` [PATCH v5 4/6] wifi: rtw88: sdio: track free TX pages and OQT credits for RTL8723BS luka.gejak
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: luka.gejak @ 2026-08-14 10:53 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Michael Straube, Bitterblue Smith, Peter Robinson,
Hans de Goede, Luka Gejak
From: Luka Gejak <luka.gejak@linux.dev>
Commit c80788f7c5ae ("wifi: rtw88: increase TX report timeout to fix
race condition") raised the purge timeout to 2500 ms for the RTL8723DU,
because the firmware can stay off channel during background scans for
longer than the 500 ms default, which delays the TX reports and lets the
purge timer drop the tracking skbs. The host stack then reads the missing
status as loss and collapses TCP throughput.
The RTL8723BS runs the same vendor firmware over a slower SDIO host and
hits the same race. Testers on ARM SDIO boards see "failed to get tx
report from firmware" under load, with the same throughput collapse.
Extend the 2500 ms timeout to the RTL8723BS.
Reported-by: Peter Robinson <pbrobinson@gmail.com>
Closes: https://lore.kernel.org/all/CALeDE9PgQmpMfDt1DgfLD4tBFGH0MZ7GncV6RUEOHhHbKF+TdQ@mail.gmail.com/
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
---
drivers/net/wireless/realtek/rtw88/tx.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/tx.c b/drivers/net/wireless/realtek/rtw88/tx.c
index 9d747a060b98..797c1e0402f2 100644
--- a/drivers/net/wireless/realtek/rtw88/tx.c
+++ b/drivers/net/wireless/realtek/rtw88/tx.c
@@ -208,8 +208,9 @@ void rtw_tx_report_enqueue(struct rtw_dev *rtwdev, struct sk_buff *skb, u8 sn)
__skb_queue_tail(&tx_report->queue, skb);
spin_unlock_irqrestore(&tx_report->q_lock, flags);
- if (rtwdev->chip->id == RTW_CHIP_TYPE_8723D &&
- rtwdev->hci.type == RTW_HCI_TYPE_USB)
+ if ((rtwdev->chip->id == RTW_CHIP_TYPE_8723D &&
+ rtwdev->hci.type == RTW_HCI_TYPE_USB) ||
+ rtw_is_8723bs(rtwdev))
timeout = msecs_to_jiffies(2500);
mod_timer(&tx_report->purge_timer, jiffies + timeout);
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* [PATCH v5 4/6] wifi: rtw88: sdio: track free TX pages and OQT credits for RTL8723BS
2026-08-14 10:53 [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS luka.gejak
` (2 preceding siblings ...)
2026-08-14 10:53 ` [PATCH v5 3/6] wifi: rtw88: tx: extend the TX report purge timeout to RTL8723BS luka.gejak
@ 2026-08-14 10:53 ` luka.gejak
2026-08-19 0:52 ` Ping-Ke Shih
2026-08-14 10:53 ` [PATCH v5 5/6] wifi: rtw88: sdio: set up RX aggregation and interrupts " luka.gejak
` (2 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: luka.gejak @ 2026-08-14 10:53 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Michael Straube, Bitterblue Smith, Peter Robinson,
Hans de Goede, Luka Gejak
From: Luka Gejak <luka.gejak@linux.dev>
The RTL8723BS reports free TX page counts that the generic 8051 path
reads back from the chip on every transfer, which is both slow over SDIO
and unreliable on this part: the register frequently reads back zero
while pages are in fact available. It also gates transmission on a free
count in the SDIO output queue, REG_SDIO_OQT_FREE_PG, which rtw88 does
not track at all. The vendor driver calls this the OQT free space and
never expands the acronym; the register holds the number of further
transfers the SDIO output queue can accept, and the chip discards
writes that arrive when it has run out.
Mirror the vendor driver and keep the per-queue and public page counts
in software, seeded at start and resynchronised from the chip only when
the cached counts say there is not enough room. Wait for a free output
queue entry before writing, and account for the pages consumed after a
successful transfer.
Transfers also have to be padded up to the SDIO block size for this
chip rather than using the generic alignment, so size the write
separately from the frame and trim the skb back afterwards.
Measured on RTL8723BS hardware against an iperf3 server one hop behind
the AP, with the wlan0 byte counters as ground truth. On the generic
path the association completes but no data passes at all: TCP and UDP
both measure 0 bit/s in either direction. With this patch TCP is
25.3 Mbit/s up and 37.3 Mbit/s down, and UDP is 25.0 Mbit/s up at 0%
loss.
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 293 +++++++++++++++++++++-
drivers/net/wireless/realtek/rtw88/sdio.h | 10 +
2 files changed, 291 insertions(+), 12 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index 5b40d74b16ee..a8209b9acefd 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -20,6 +20,7 @@
#include "tx.h"
#define RTW_SDIO_INDIRECT_RW_RETRIES 50
+#define RTW_SDIO_OQT_TIMEOUT_MS 1000
static bool rtw_sdio_is_bus_addr(u32 addr)
{
@@ -548,12 +549,157 @@ static int rtw_sdio_read_port(struct rtw_dev *rtwdev, u8 *buf, size_t count)
return ret;
}
+/*
+ * The cached free page counters are a fast path hint only. They are written
+ * from the single threaded TX work and, for H2C and reserved page writes,
+ * from process context, so they are atomic_t; whenever they claim there is
+ * not enough room they are resynchronised from the chip before the caller
+ * gives up, which also absorbs a lost update.
+ */
+static void rtw_sdio_8723bs_store_free_txpg(struct rtw_dev *rtwdev,
+ u32 free_txpg)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+
+ atomic_set(&rtwsdio->free_pg_high,
+ u32_get_bits(free_txpg, BIT_FREE_TXPG_HIGH));
+ atomic_set(&rtwsdio->free_pg_normal,
+ u32_get_bits(free_txpg, BIT_FREE_TXPG_NORMAL));
+ atomic_set(&rtwsdio->free_pg_low,
+ u32_get_bits(free_txpg, BIT_FREE_TXPG_LOW));
+ atomic_set(&rtwsdio->free_pg_pub,
+ u32_get_bits(free_txpg, BIT_FREE_TXPG_PUB));
+}
+
+/*
+ * Refresh the cached counters from the chip. Returns false when the chip
+ * reports no free pages at all, which means the counts cannot be trusted
+ * and the caller has to decide what to do instead.
+ */
+static bool rtw_sdio_8723bs_sync_free_txpg(struct rtw_dev *rtwdev)
+{
+ u32 free_txpg = rtw_read32(rtwdev, REG_SDIO_FREE_TXPG);
+
+ if (!free_txpg)
+ return false;
+
+ rtw_sdio_8723bs_store_free_txpg(rtwdev, free_txpg);
+
+ return true;
+}
+
+/*
+ * Size of the public page pool: whatever the transmit page allocation has
+ * left once the per queue pools are taken out. Fails if the allocation
+ * cannot cover the reserved queues, since the remainder would underflow and
+ * there would be no sensible pool to hand out.
+ */
+static int rtw_sdio_8723bs_pubq_num(struct rtw_dev *rtwdev, u16 *pubq_num)
+{
+ const struct rtw_page_table *pg_tbl = &rtwdev->chip->page_table[0];
+ u16 acq_pg_num = rtwdev->fifo.acq_pg_num;
+ u16 reserved_num;
+
+ reserved_num = pg_tbl->hq_num + pg_tbl->lq_num + pg_tbl->nq_num +
+ pg_tbl->exq_num + pg_tbl->gapq_num;
+ if (acq_pg_num <= reserved_num) {
+ rtw_err(rtwdev,
+ "no transmit pages left for the public queue: %u of %u reserved\n",
+ reserved_num, acq_pg_num);
+ return -EINVAL;
+ }
+
+ *pubq_num = acq_pg_num - reserved_num;
+
+ return 0;
+}
+
+static int rtw_sdio_8723bs_init_free_txpg(struct rtw_dev *rtwdev)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ const struct rtw_page_table *pg_tbl;
+ u16 pubq_num;
+ int ret;
+
+ /* Seed from the page table when the chip has nothing to report yet. */
+ if (!rtw_sdio_8723bs_sync_free_txpg(rtwdev)) {
+ ret = rtw_sdio_8723bs_pubq_num(rtwdev, &pubq_num);
+ if (ret)
+ return ret;
+
+ pg_tbl = &rtwdev->chip->page_table[0];
+ atomic_set(&rtwsdio->free_pg_high, pg_tbl->hq_num);
+ atomic_set(&rtwsdio->free_pg_normal, pg_tbl->nq_num);
+ atomic_set(&rtwsdio->free_pg_low, pg_tbl->lq_num);
+ atomic_set(&rtwsdio->free_pg_pub, pubq_num);
+ }
+
+ atomic_set(&rtwsdio->tx_oqt_free,
+ rtw_read8(rtwdev, REG_SDIO_OQT_FREE_PG));
+
+ return 0;
+}
+
+/*
+ * Sum of the queue's dedicated counter and the public pool, clamped at zero:
+ * a lost update between the check below and rtw_sdio_8723bs_consume_txpg()
+ * can briefly drive a counter negative, and letting that wrap would hide the
+ * shortage instead of triggering a resync from the chip.
+ */
+static unsigned int rtw_sdio_8723bs_pages_free(struct rtw_dev *rtwdev,
+ atomic_t *dedicated)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ int free;
+
+ free = atomic_read(dedicated) + atomic_read(&rtwsdio->free_pg_pub);
+
+ return free > 0 ? free : 0;
+}
+
+static atomic_t *rtw_sdio_8723bs_free_txpg(struct rtw_dev *rtwdev, u8 queue)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+
+ switch (queue) {
+ case RTW_TX_QUEUE_VI:
+ return &rtwsdio->free_pg_normal;
+ case RTW_TX_QUEUE_BE:
+ case RTW_TX_QUEUE_BK:
+ return &rtwsdio->free_pg_low;
+ case RTW_TX_QUEUE_BCN:
+ case RTW_TX_QUEUE_H2C:
+ case RTW_TX_QUEUE_HI0:
+ case RTW_TX_QUEUE_MGMT:
+ case RTW_TX_QUEUE_VO:
+ return &rtwsdio->free_pg_high;
+ default:
+ return NULL;
+ }
+}
+
static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue,
size_t count)
{
unsigned int pages_free, pages_needed;
- if (rtw_chip_wcpu_8051(rtwdev)) {
+ if (rtw_is_8723bs(rtwdev)) {
+ atomic_t *dedicated;
+
+ dedicated = rtw_sdio_8723bs_free_txpg(rtwdev, queue);
+ if (!dedicated) {
+ rtw_warn(rtwdev, "Unknown mapping for queue %u\n", queue);
+ return -EINVAL;
+ }
+
+ pages_free = rtw_sdio_8723bs_pages_free(rtwdev, dedicated);
+ pages_needed = DIV_ROUND_UP(count, rtwdev->chip->page_size);
+ if (pages_needed <= pages_free)
+ return 0;
+
+ rtw_sdio_8723bs_sync_free_txpg(rtwdev);
+ pages_free = rtw_sdio_8723bs_pages_free(rtwdev, dedicated);
+ } else if (rtw_chip_wcpu_8051(rtwdev)) {
u32 free_txpg;
free_txpg = rtw_sdio_read32(rtwdev, REG_SDIO_FREE_TXPG);
@@ -632,44 +778,124 @@ static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue,
return 0;
}
+static int rtw_sdio_8723bs_wait_tx_oqt(struct rtw_dev *rtwdev)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ unsigned long deadline;
+ u8 free;
+
+ if (atomic_add_unless(&rtwsdio->tx_oqt_free, -1, 0))
+ return 0;
+
+ deadline = jiffies + msecs_to_jiffies(RTW_SDIO_OQT_TIMEOUT_MS);
+ do {
+ free = rtw_read8(rtwdev, REG_SDIO_OQT_FREE_PG);
+ if (free) {
+ atomic_set(&rtwsdio->tx_oqt_free, free - 1);
+ return 0;
+ }
+ usleep_range(1000, 2000);
+ } while (time_before(jiffies, deadline));
+
+ return -EBUSY;
+}
+
+static void rtw_sdio_8723bs_consume_txpg(struct rtw_dev *rtwdev, u8 queue,
+ unsigned int pages)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ atomic_t *dedicated;
+ unsigned int taken;
+ int free;
+
+ dedicated = rtw_sdio_8723bs_free_txpg(rtwdev, queue);
+ if (!dedicated)
+ return;
+
+ free = atomic_read(dedicated);
+ taken = min_t(unsigned int, pages, free > 0 ? free : 0);
+ atomic_sub(taken, dedicated);
+
+ pages -= taken;
+ if (pages && atomic_sub_return(pages, &rtwsdio->free_pg_pub) < 0)
+ atomic_set(&rtwsdio->free_pg_pub, 0);
+}
+
static int rtw_sdio_write_port(struct rtw_dev *rtwdev, struct sk_buff *skb,
enum rtw_tx_queue_type queue)
{
struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ bool rtl8723bs = rtw_is_8723bs(rtwdev);
+ unsigned int orig_len = skb->len;
+ unsigned int pages;
+ size_t write_size;
bool bus_claim;
size_t txsize;
u32 txaddr;
int ret;
- txaddr = rtw_sdio_get_tx_addr(rtwdev, skb->len, queue);
- if (!txaddr)
- return -EINVAL;
+ if (rtl8723bs) {
+ txsize = round_up(orig_len, 4);
+ write_size = txsize > RTW_SDIO_BLOCK_SIZE ?
+ round_up(txsize, RTW_SDIO_BLOCK_SIZE) : txsize;
+ } else {
+ txsize = sdio_align_size(rtwsdio->sdio_func, orig_len);
+ write_size = txsize;
+ }
- txsize = sdio_align_size(rtwsdio->sdio_func, skb->len);
+ if (write_size > orig_len) {
+ unsigned int padding = write_size - orig_len;
+
+ if (skb_tailroom(skb) < padding) {
+ ret = pskb_expand_head(skb, 0,
+ padding - skb_tailroom(skb),
+ GFP_KERNEL);
+ if (ret)
+ return ret;
+ }
+ skb_put_zero(skb, padding);
+ }
+
+ txaddr = rtw_sdio_get_tx_addr(rtwdev, txsize, queue);
+ if (!txaddr) {
+ ret = -EINVAL;
+ goto out_trim;
+ }
ret = rtw_sdio_check_free_txpg(rtwdev, queue, txsize);
if (ret)
- return ret;
+ goto out_trim;
+
+ if (rtl8723bs) {
+ ret = rtw_sdio_8723bs_wait_tx_oqt(rtwdev);
+ if (ret)
+ goto out_trim;
+ }
if (!IS_ALIGNED((unsigned long)skb->data, RTW_SDIO_DATA_PTR_ALIGN))
rtw_warn(rtwdev, "Got unaligned SKB in %s() for queue %u\n",
__func__, queue);
bus_claim = rtw_sdio_bus_claim_needed(rtwsdio);
-
if (bus_claim)
sdio_claim_host(rtwsdio->sdio_func);
-
- ret = sdio_memcpy_toio(rtwsdio->sdio_func, txaddr, skb->data, txsize);
-
+ ret = sdio_memcpy_toio(rtwsdio->sdio_func, txaddr, skb->data,
+ write_size);
if (bus_claim)
sdio_release_host(rtwsdio->sdio_func);
- if (ret)
+ if (ret) {
rtw_warn(rtwdev,
"Failed to write %zu byte(s) to SDIO port 0x%08x",
- txsize, txaddr);
+ write_size, txaddr);
+ } else if (rtl8723bs) {
+ pages = DIV_ROUND_UP(txsize, rtwdev->chip->page_size);
+ rtw_sdio_8723bs_consume_txpg(rtwdev, queue, pages);
+ }
+out_trim:
+ if (write_size > orig_len)
+ skb_trim(skb, orig_len);
return ret;
}
@@ -749,8 +975,51 @@ static int rtw_sdio_setup(struct rtw_dev *rtwdev)
return 0;
}
+/*
+ * Reprogram the queue page allocation if the chip came up with none. This is
+ * a repair path, not part of the normal start sequence: a non-zero free page
+ * count means the allocation latched during power on and must be left alone,
+ * and without a transmit page pool there is nothing to divide up either.
+ */
+static int rtw_sdio_8723bs_check_rqpn(struct rtw_dev *rtwdev)
+{
+ const struct rtw_chip_info *chip = rtwdev->chip;
+ struct rtw_fifo_conf *fifo = &rtwdev->fifo;
+ const struct rtw_page_table *pg_tbl;
+ u32 free_txpg;
+ u16 pubq_num;
+ int ret;
+
+ free_txpg = rtw_read32(rtwdev, REG_SDIO_FREE_TXPG);
+ if (free_txpg || !fifo->acq_pg_num)
+ return 0;
+
+ ret = rtw_sdio_8723bs_pubq_num(rtwdev, &pubq_num);
+ if (ret)
+ return ret;
+
+ pg_tbl = &chip->page_table[0];
+ rtw_write32(rtwdev, REG_RQPN_NPQ,
+ BIT_RQPN_NE(pg_tbl->nq_num, pg_tbl->exq_num));
+ rtw_write32(rtwdev, REG_RQPN,
+ BIT_RQPN_HLP(pg_tbl->hq_num, pg_tbl->lq_num, pubq_num));
+
+ return 0;
+}
+
static int rtw_sdio_start(struct rtw_dev *rtwdev)
{
+ if (rtw_is_8723bs(rtwdev)) {
+ int ret = rtw_sdio_8723bs_check_rqpn(rtwdev);
+
+ if (ret)
+ return ret;
+
+ ret = rtw_sdio_8723bs_init_free_txpg(rtwdev);
+ if (ret)
+ return ret;
+ }
+
rtw_sdio_enable_rx_aggregation(rtwdev);
rtw_sdio_enable_interrupt(rtwdev);
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index 457e8b02380e..5b000cb8fac2 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -86,6 +86,10 @@
#define REG_SDIO_OQT_FREE_PG (SDIO_LOCAL_OFFSET + 0x001E)
/* Free Tx Buffer Page */
#define REG_SDIO_FREE_TXPG (SDIO_LOCAL_OFFSET + 0x0020)
+#define BIT_FREE_TXPG_HIGH GENMASK(7, 0)
+#define BIT_FREE_TXPG_NORMAL GENMASK(15, 8)
+#define BIT_FREE_TXPG_LOW GENMASK(23, 16)
+#define BIT_FREE_TXPG_PUB GENMASK(31, 24)
/* HCI Current Power Mode 1 */
#define REG_SDIO_HCPWM1 (SDIO_LOCAL_OFFSET + 0x0024)
/* HCI Current Power Mode 2 */
@@ -159,6 +163,12 @@ struct rtw_sdio {
struct workqueue_struct *txwq;
struct rtw_sdio_work_data *tx_handler_data;
struct sk_buff_head tx_queue[RTK_MAX_TX_QUEUE_NUM];
+
+ atomic_t free_pg_high;
+ atomic_t free_pg_normal;
+ atomic_t free_pg_low;
+ atomic_t free_pg_pub;
+ atomic_t tx_oqt_free;
};
extern const struct dev_pm_ops rtw_sdio_pm_ops;
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* RE: [PATCH v5 4/6] wifi: rtw88: sdio: track free TX pages and OQT credits for RTL8723BS
2026-08-14 10:53 ` [PATCH v5 4/6] wifi: rtw88: sdio: track free TX pages and OQT credits for RTL8723BS luka.gejak
@ 2026-08-19 0:52 ` Ping-Ke Shih
0 siblings, 0 replies; 12+ messages in thread
From: Ping-Ke Shih @ 2026-08-19 0:52 UTC (permalink / raw)
To: luka.gejak@linux.dev, linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Michael Straube, Bitterblue Smith,
Peter Robinson, Hans de Goede
luka.gejak@linux.dev <luka.gejak@linux.dev> wrote:
> From: Luka Gejak <luka.gejak@linux.dev>
>
> The RTL8723BS reports free TX page counts that the generic 8051 path
> reads back from the chip on every transfer, which is both slow over SDIO
> and unreliable on this part: the register frequently reads back zero
> while pages are in fact available. It also gates transmission on a free
> count in the SDIO output queue, REG_SDIO_OQT_FREE_PG, which rtw88 does
> not track at all. The vendor driver calls this the OQT free space and
> never expands the acronym; the register holds the number of further
> transfers the SDIO output queue can accept, and the chip discards
> writes that arrive when it has run out.
>
> Mirror the vendor driver and keep the per-queue and public page counts
> in software, seeded at start and resynchronised from the chip only when
> the cached counts say there is not enough room. Wait for a free output
> queue entry before writing, and account for the pages consumed after a
> successful transfer.
>
> Transfers also have to be padded up to the SDIO block size for this
> chip rather than using the generic alignment, so size the write
> separately from the frame and trim the skb back afterwards.
>
> Measured on RTL8723BS hardware against an iperf3 server one hop behind
> the AP, with the wlan0 byte counters as ground truth. On the generic
> path the association completes but no data passes at all: TCP and UDP
> both measure 0 bit/s in either direction. With this patch TCP is
> 25.3 Mbit/s up and 37.3 Mbit/s down, and UDP is 25.0 Mbit/s up at 0%
> loss.
>
> Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v5 5/6] wifi: rtw88: sdio: set up RX aggregation and interrupts for RTL8723BS
2026-08-14 10:53 [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS luka.gejak
` (3 preceding siblings ...)
2026-08-14 10:53 ` [PATCH v5 4/6] wifi: rtw88: sdio: track free TX pages and OQT credits for RTL8723BS luka.gejak
@ 2026-08-14 10:53 ` luka.gejak
2026-08-19 0:56 ` Ping-Ke Shih
2026-08-14 10:53 ` [PATCH v5 6/6] wifi: rtw88: sdio: add TX back-pressure and retry on page starvation luka.gejak
2026-08-19 0:44 ` [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS Ping-Ke Shih
6 siblings, 1 reply; 12+ messages in thread
From: luka.gejak @ 2026-08-14 10:53 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Michael Straube, Bitterblue Smith, Peter Robinson,
Hans de Goede, Luka Gejak
From: Luka Gejak <luka.gejak@linux.dev>
Enable the existing RX aggregation setup for this chip and select the
larger DMA burst count it needs. The RTL8723BS does not raise CPWM1, so
leave that source out of its interrupt mask, and set the SDIO TX control
bit the vendor driver uses to have transfers always recognised.
The chip was also seen to keep raising the interrupt after resume when
undefined status bits were written back on acknowledgment, so
acknowledge only the bits this driver defines. That observation dates
from bring up and I cannot re-measure it: the test machine only offers
s2idle and does not reliably return from it, so the resume path is not
exercised here. The change is scoped to this chip; the other SDIO parts
keep writing the status word back unchanged.
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 28 ++++++++++++++++++++++-
drivers/net/wireless/realtek/rtw88/sdio.h | 9 ++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index a8209b9acefd..eaec776dd943 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -903,7 +903,11 @@ static void rtw_sdio_init(struct rtw_dev *rtwdev)
{
struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
- rtwsdio->irq_mask = REG_SDIO_HIMR_RX_REQUEST | REG_SDIO_HIMR_CPWM1;
+ if (rtw_is_8723bs(rtwdev))
+ rtwsdio->irq_mask = REG_SDIO_HIMR_RX_REQUEST;
+ else
+ rtwsdio->irq_mask = REG_SDIO_HIMR_RX_REQUEST |
+ REG_SDIO_HIMR_CPWM1;
}
static void rtw_sdio_enable_rx_aggregation(struct rtw_dev *rtwdev)
@@ -911,6 +915,7 @@ static void rtw_sdio_enable_rx_aggregation(struct rtw_dev *rtwdev)
u8 size, timeout;
switch (rtwdev->chip->id) {
+ case RTW_CHIP_TYPE_8723B:
case RTW_CHIP_TYPE_8703B:
case RTW_CHIP_TYPE_8821A:
case RTW_CHIP_TYPE_8812A:
@@ -938,6 +943,8 @@ static void rtw_sdio_enable_rx_aggregation(struct rtw_dev *rtwdev)
FIELD_PREP(BIT_DMA_AGG_TO_V1, timeout));
rtw_write8_set(rtwdev, REG_RXDMA_MODE, BIT_DMA_MODE);
+ if (rtw_is_8723bs(rtwdev))
+ rtw_write8_mask(rtwdev, REG_RXDMA_MODE, BIT_DMA_BURST_CNT, 0x3);
}
static void rtw_sdio_enable_interrupt(struct rtw_dev *rtwdev)
@@ -1009,6 +1016,8 @@ static int rtw_sdio_8723bs_check_rqpn(struct rtw_dev *rtwdev)
static int rtw_sdio_start(struct rtw_dev *rtwdev)
{
+ u32 clear;
+
if (rtw_is_8723bs(rtwdev)) {
int ret = rtw_sdio_8723bs_check_rqpn(rtwdev);
@@ -1021,6 +1030,13 @@ static int rtw_sdio_start(struct rtw_dev *rtwdev)
}
rtw_sdio_enable_rx_aggregation(rtwdev);
+
+ if (rtw_is_8723bs(rtwdev)) {
+ clear = rtw_read32(rtwdev, REG_SDIO_HISR) & RTW_SDIO_HISR_CLEAR_MASK;
+ if (clear)
+ rtw_write32(rtwdev, REG_SDIO_HISR, clear);
+ }
+
rtw_sdio_enable_interrupt(rtwdev);
return 0;
@@ -1100,6 +1116,8 @@ static void rtw_sdio_interface_cfg(struct rtw_dev *rtwdev)
val = rtw_read32(rtwdev, REG_SDIO_TX_CTRL);
val &= 0xfff8;
+ if (rtw_is_8723bs(rtwdev))
+ val |= BIT_SDIO_TX_CTRL_ALWAYS_RECOGNIZE;
rtw_write32(rtwdev, REG_SDIO_TX_CTRL, val);
}
@@ -1364,6 +1382,14 @@ static void rtw_sdio_handle_interrupt(struct sdio_func *sdio_func)
rtw_sdio_rx_isr(rtwdev);
}
+ /*
+ * RTL8723BS keeps raising the interrupt after resume if undefined
+ * status bits are written back, so acknowledge only the bits this
+ * driver defines. Other chips keep the existing behaviour.
+ */
+ if (rtw_is_8723bs(rtwdev))
+ hisr &= RTW_SDIO_HISR_CLEAR_MASK;
+
rtw_write32(rtwdev, REG_SDIO_HISR, hisr);
rtwsdio->irq_thread = NULL;
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index 5b000cb8fac2..7474a7511811 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -22,6 +22,7 @@
/* SDIO Tx Control */
#define REG_SDIO_TX_CTRL (SDIO_LOCAL_OFFSET + 0x0000)
+#define BIT_SDIO_TX_CTRL_ALWAYS_RECOGNIZE BIT(4)
/*SDIO status timeout*/
#define REG_SDIO_TIMEOUT (SDIO_LOCAL_OFFSET + 0x0002)
@@ -77,6 +78,14 @@
/* the following two are RTL8188 SDIO Specific */
#define REG_SDIO_HISR_MCU_ERR BIT(28)
#define REG_SDIO_HISR_TSF_BIT32_TOGGLE BIT(29)
+#define RTW_SDIO_HISR_CLEAR_MASK \
+ (REG_SDIO_HISR_TXERR | REG_SDIO_HISR_RXERR | \
+ REG_SDIO_HISR_TXFOVW | REG_SDIO_HISR_RXFOVW | \
+ REG_SDIO_HISR_TXBCNOK | REG_SDIO_HISR_TXBCNERR | \
+ REG_SDIO_HISR_C2HCMD | REG_SDIO_HISR_CPWM1 | \
+ REG_SDIO_HISR_CPWM2 | REG_SDIO_HISR_HSISR_IND | \
+ REG_SDIO_HISR_GTINT3_IND | REG_SDIO_HISR_GTINT4_IND | \
+ REG_SDIO_HISR_PSTIMEOUT | REG_SDIO_HISR_OCPINT)
/* HCI Current Power Mode */
#define REG_SDIO_HCPWM (SDIO_LOCAL_OFFSET + 0x0019)
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* RE: [PATCH v5 5/6] wifi: rtw88: sdio: set up RX aggregation and interrupts for RTL8723BS
2026-08-14 10:53 ` [PATCH v5 5/6] wifi: rtw88: sdio: set up RX aggregation and interrupts " luka.gejak
@ 2026-08-19 0:56 ` Ping-Ke Shih
0 siblings, 0 replies; 12+ messages in thread
From: Ping-Ke Shih @ 2026-08-19 0:56 UTC (permalink / raw)
To: luka.gejak@linux.dev, linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Michael Straube, Bitterblue Smith,
Peter Robinson, Hans de Goede
luka.gejak@linux.dev <luka.gejak@linux.dev> wrote:
> From: Luka Gejak <luka.gejak@linux.dev>
>
> Enable the existing RX aggregation setup for this chip and select the
> larger DMA burst count it needs. The RTL8723BS does not raise CPWM1, so
> leave that source out of its interrupt mask, and set the SDIO TX control
> bit the vendor driver uses to have transfers always recognised.
>
> The chip was also seen to keep raising the interrupt after resume when
> undefined status bits were written back on acknowledgment, so
> acknowledge only the bits this driver defines. That observation dates
> from bring up and I cannot re-measure it: the test machine only offers
> s2idle and does not reliably return from it, so the resume path is not
> exercised here. The change is scoped to this chip; the other SDIO parts
> keep writing the status word back unchanged.
>
> Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v5 6/6] wifi: rtw88: sdio: add TX back-pressure and retry on page starvation
2026-08-14 10:53 [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS luka.gejak
` (4 preceding siblings ...)
2026-08-14 10:53 ` [PATCH v5 5/6] wifi: rtw88: sdio: set up RX aggregation and interrupts " luka.gejak
@ 2026-08-14 10:53 ` luka.gejak
2026-08-19 1:14 ` Ping-Ke Shih
2026-08-19 0:44 ` [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS Ping-Ke Shih
6 siblings, 1 reply; 12+ messages in thread
From: luka.gejak @ 2026-08-14 10:53 UTC (permalink / raw)
To: Ping-Ke Shih, linux-wireless
Cc: linux-kernel, Michael Straube, Bitterblue Smith, Peter Robinson,
Hans de Goede, Luka Gejak
From: Luka Gejak <luka.gejak@linux.dev>
Two problems show up on RTL8723BS uplink. The per-AC software FIFO is
unbounded, so mac80211 keeps handing frames down until latency collapses
under load. And when a transfer cannot be completed the queue is simply
abandoned for that pass, which stalls the AC until something else kicks
the worker.
Stop the mac80211 queue once a data AC fills past a high watermark and
wake it from the drain path when it falls back to a low one. Convert the
TX work item to a delayed work and re-arm it when a transfer fails for a
reason that can clear on its own, so it is retried rather than the AC
abandoned, and cancel the work on teardown.
Retrying matters once the queue can be stopped. A stopped queue is
handed no further frames, so nothing else would kick the worker, and the
AC would stay stopped for good with the link still up and receive
unaffected. The two retried cases, a transmit page or output queue
shortage and a failed skb expansion, are also the two that fail
silently; the rest are logged where they happen, so they are visible
rather than an unexplained hang, and they keep the existing behaviour
rather than being retried indefinitely.
Measured on RTL8723BS hardware, uplink goes from 11.9 Mbit/s with 204
TCP retransmits to 20.1 Mbit/s with 2.
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 139 ++++++++++++++++++++--
drivers/net/wireless/realtek/rtw88/sdio.h | 3 +-
2 files changed, 131 insertions(+), 11 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index eaec776dd943..1de104870572 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -22,6 +22,16 @@
#define RTW_SDIO_INDIRECT_RW_RETRIES 50
#define RTW_SDIO_OQT_TIMEOUT_MS 1000
+/*
+ * 8723BS SDIO TX FIFO back-pressure watermarks: stop the mac80211 queue once
+ * the per-AC software FIFO fills past the high watermark, and wake it from the
+ * TX drain path once it falls back to the low one. Bounds the queueing latency
+ * that otherwise causes uplink bufferbloat / congestion collapse.
+ */
+#define RTW_SDIO_TX_FIFO_HIWATER 16
+#define RTW_SDIO_TX_FIFO_LOWATER 8
+#define RTW_SDIO_TX_RETRY_DELAY msecs_to_jiffies(1)
+
static bool rtw_sdio_is_bus_addr(u32 addr)
{
return !!(addr & RTW_SDIO_BUS_MSK);
@@ -1100,7 +1110,11 @@ static void rtw_sdio_tx_kick_off(struct rtw_dev *rtwdev)
{
struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
- queue_work(rtwsdio->txwq, &rtwsdio->tx_handler_data->work);
+ /*
+ * A retry may already be pending with a delay; re-arm it so a newly
+ * queued frame is not held back by it.
+ */
+ mod_delayed_work(rtwsdio->txwq, &rtwsdio->tx_handler_data->work, 0);
}
static void rtw_sdio_link_ps(struct rtw_dev *rtwdev, bool enter)
@@ -1209,6 +1223,50 @@ 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);
}
+/*
+ * Back-pressure on the data ACs (BK/BE/VI/VO): once the software FIFO fills
+ * past the high watermark, stop the corresponding mac80211 queue so it stops
+ * handing frames down, which bounds the queueing latency. The queue is woken
+ * again from the TX drain path once the FIFO falls back to the low watermark.
+ */
+static void rtw_sdio_8723bs_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)
+ return;
+
+ if (rtwsdio->tx_queue_stopped[queue])
+ return;
+
+ if (skb_queue_len(&rtwsdio->tx_queue[queue]) < RTW_SDIO_TX_FIFO_HIWATER)
+ 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)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+
+ if (!rtw_is_8723bs(rtwdev) || queue >= RTW_TX_QUEUE_BCN)
+ return;
+
+ if (!rtwsdio->tx_queue_stopped[queue])
+ return;
+
+ if (skb_queue_len(&rtwsdio->tx_queue[queue]) > RTW_SDIO_TX_FIFO_LOWATER)
+ return;
+
+ rtwsdio->tx_queue_stopped[queue] = false;
+ ieee80211_wake_queue(rtwdev->hw, q_map);
+}
+
static int rtw_sdio_tx_write(struct rtw_dev *rtwdev,
struct rtw_tx_pkt_info *pkt_info,
struct sk_buff *skb)
@@ -1224,6 +1282,8 @@ static int rtw_sdio_tx_write(struct rtw_dev *rtwdev,
skb_queue_tail(&rtwsdio->tx_queue[queue], skb);
+ rtw_sdio_8723bs_stop_tx_queue(rtwdev, queue, skb_get_queue_mapping(skb));
+
return 0;
}
@@ -1526,43 +1586,99 @@ static void rtw_sdio_indicate_tx_status(struct rtw_dev *rtwdev,
ieee80211_tx_status_irqsafe(hw, skb);
}
-static void rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev,
- enum rtw_tx_queue_type queue)
+/*
+ * 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
+ * the frame is put back at the head of the queue.
+ */
+static int rtw_sdio_process_tx_queue(struct rtw_dev *rtwdev,
+ enum rtw_tx_queue_type queue)
{
struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
struct sk_buff *skb;
+ u16 q_map;
int ret;
skb = skb_dequeue(&rtwsdio->tx_queue[queue]);
if (!skb)
- return;
+ return 1;
+ q_map = skb_get_queue_mapping(skb);
ret = rtw_sdio_write_port(rtwdev, skb, queue);
if (ret) {
skb_queue_head(&rtwsdio->tx_queue[queue], skb);
- return;
+ return ret;
}
rtw_sdio_indicate_tx_status(rtwdev, skb);
+
+ rtw_sdio_8723bs_wake_tx_queue(rtwdev, queue, q_map);
+
+ return 0;
+}
+
+static void rtw_sdio_reschedule_tx_work(struct rtw_dev *rtwdev,
+ struct rtw_sdio_work_data *work_data,
+ unsigned long delay)
+{
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+
+ queue_delayed_work(rtwsdio->txwq, &work_data->work, delay);
}
static void rtw_sdio_tx_handler(struct work_struct *work)
{
struct rtw_sdio_work_data *work_data =
- container_of(work, struct rtw_sdio_work_data, work);
+ container_of(to_delayed_work(work), struct rtw_sdio_work_data,
+ work);
struct rtw_sdio *rtwsdio;
struct rtw_dev *rtwdev;
- int limit, queue;
+ int limit, queue, ret;
+ bool rtl8723bs;
rtwdev = work_data->rtwdev;
rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ rtl8723bs = rtw_is_8723bs(rtwdev);
if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_TX_WAKE))
rtw_sdio_deep_ps_leave(rtwdev);
for (queue = RTK_MAX_TX_QUEUE_NUM - 1; queue >= 0; queue--) {
for (limit = 0; limit < 1000; limit++) {
- rtw_sdio_process_tx_queue(rtwdev, queue);
+ ret = rtw_sdio_process_tx_queue(rtwdev, queue);
+ if (ret > 0)
+ break;
+
+ if (ret < 0) {
+ /*
+ * A page or output queue shortage and a failed
+ * skb expansion are both transient, and the
+ * frame is still queued, so come back for it.
+ * That matters once the queue can be stopped:
+ * a stopped queue is handed no further frames,
+ * so nothing else would kick this work item and
+ * the queue would stay stopped for good. The
+ * remaining errors cannot succeed on a retry
+ * and each log where they happen.
+ */
+ if (rtl8723bs &&
+ (ret == -EBUSY || ret == -ENOMEM)) {
+ rtw_sdio_reschedule_tx_work(rtwdev, work_data,
+ RTW_SDIO_TX_RETRY_DELAY);
+ return;
+ }
+ break;
+ }
+
+ /*
+ * Restart from the highest priority queue after every
+ * management frame so the join sequence is not held up
+ * behind a data backlog.
+ */
+ if (rtl8723bs && queue == RTW_TX_QUEUE_MGMT) {
+ rtw_sdio_reschedule_tx_work(rtwdev, work_data, 0);
+ return;
+ }
if (skb_queue_empty(&rtwsdio->tx_queue[queue]))
break;
@@ -1589,14 +1705,16 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)
return -ENOMEM;
}
- for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++)
+ for (i = 0; i < RTK_MAX_TX_QUEUE_NUM; i++) {
skb_queue_head_init(&rtwsdio->tx_queue[i]);
+ rtwsdio->tx_queue_stopped[i] = false;
+ }
rtwsdio->tx_handler_data = kmalloc_obj(*rtwsdio->tx_handler_data);
if (!rtwsdio->tx_handler_data)
goto err_destroy_wq;
rtwsdio->tx_handler_data->rtwdev = rtwdev;
- INIT_WORK(&rtwsdio->tx_handler_data->work, rtw_sdio_tx_handler);
+ INIT_DELAYED_WORK(&rtwsdio->tx_handler_data->work, rtw_sdio_tx_handler);
return 0;
@@ -1610,6 +1728,7 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev)
struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
int i;
+ cancel_delayed_work_sync(&rtwsdio->tx_handler_data->work);
destroy_workqueue(rtwsdio->txwq);
kfree(rtwsdio->tx_handler_data);
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index 7474a7511811..cec3dd1c4b2e 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -156,7 +156,7 @@ struct rtw_sdio_tx_data {
};
struct rtw_sdio_work_data {
- struct work_struct work;
+ struct delayed_work work;
struct rtw_dev *rtwdev;
};
@@ -172,6 +172,7 @@ struct rtw_sdio {
struct workqueue_struct *txwq;
struct rtw_sdio_work_data *tx_handler_data;
struct sk_buff_head tx_queue[RTK_MAX_TX_QUEUE_NUM];
+ bool tx_queue_stopped[RTK_MAX_TX_QUEUE_NUM];
atomic_t free_pg_high;
atomic_t free_pg_normal;
--
2.53.0
^ permalink raw reply related [flat|nested] 12+ messages in thread* RE: [PATCH v5 6/6] wifi: rtw88: sdio: add TX back-pressure and retry on page starvation
2026-08-14 10:53 ` [PATCH v5 6/6] wifi: rtw88: sdio: add TX back-pressure and retry on page starvation luka.gejak
@ 2026-08-19 1:14 ` Ping-Ke Shih
0 siblings, 0 replies; 12+ messages in thread
From: Ping-Ke Shih @ 2026-08-19 1:14 UTC (permalink / raw)
To: luka.gejak@linux.dev, linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Michael Straube, Bitterblue Smith,
Peter Robinson, Hans de Goede
luka.gejak@linux.dev <luka.gejak@linux.dev> wrote:
> +
> +static void rtw_sdio_reschedule_tx_work(struct rtw_dev *rtwdev,
> + struct rtw_sdio_work_data *work_data,
> + unsigned long delay)
> +{
> + struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
> +
> + queue_delayed_work(rtwsdio->txwq, &work_data->work, delay);
> }
Actually, I didn't request this wrapper by v4. (Also I don't prefer a
simple wrapper like this that hides kernel API).
(See below)
>
> static void rtw_sdio_tx_handler(struct work_struct *work)
> {
> struct rtw_sdio_work_data *work_data =
> - container_of(work, struct rtw_sdio_work_data, work);
> + container_of(to_delayed_work(work), struct rtw_sdio_work_data,
> + work);
> struct rtw_sdio *rtwsdio;
> struct rtw_dev *rtwdev;
> - int limit, queue;
> + int limit, queue, ret;
> + bool rtl8723bs;
>
> rtwdev = work_data->rtwdev;
> rtwsdio = (struct rtw_sdio *)rtwdev->priv;
> + rtl8723bs = rtw_is_8723bs(rtwdev);
>
> if (!rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_TX_WAKE))
> rtw_sdio_deep_ps_leave(rtwdev);
>
> for (queue = RTK_MAX_TX_QUEUE_NUM - 1; queue >= 0; queue--) {
> for (limit = 0; limit < 1000; limit++) {
> - rtw_sdio_process_tx_queue(rtwdev, queue);
> + ret = rtw_sdio_process_tx_queue(rtwdev, queue);
> + if (ret > 0)
> + break;
> +
> + if (ret < 0) {
> + /*
> + * A page or output queue shortage and a failed
> + * skb expansion are both transient, and the
> + * frame is still queued, so come back for it.
> + * That matters once the queue can be stopped:
> + * a stopped queue is handed no further frames,
> + * so nothing else would kick this work item and
> + * the queue would stay stopped for good. The
> + * remaining errors cannot succeed on a retry
> + * and each log where they happen.
> + */
> + if (rtl8723bs &&
> + (ret == -EBUSY || ret == -ENOMEM)) {
> + rtw_sdio_reschedule_tx_work(rtwdev, work_data,
> + RTW_SDIO_TX_RETRY_DELAY);
> + return;
> + }
> + break;
> + }
> +
> + /*
> + * Restart from the highest priority queue after every
> + * management frame so the join sequence is not held up
> + * behind a data backlog.
> + */
> + if (rtl8723bs && queue == RTW_TX_QUEUE_MGMT) {
> + rtw_sdio_reschedule_tx_work(rtwdev, work_data, 0);
> + return;
> + }
I'd move this chunk you are adding to a function. I think it is just to
reschedule TX work for RTL8723BS for certain conditions, but explaining
a lot of things (conditions) in common flow makes people hard to read
the flow.
>
> if (skb_queue_empty(&rtwsdio->tx_queue[queue]))
> break;
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS
2026-08-14 10:53 [PATCH v5 0/6] wifi: rtw88: preparations for RTL8723B/RTL8723BS luka.gejak
` (5 preceding siblings ...)
2026-08-14 10:53 ` [PATCH v5 6/6] wifi: rtw88: sdio: add TX back-pressure and retry on page starvation luka.gejak
@ 2026-08-19 0:44 ` Ping-Ke Shih
6 siblings, 0 replies; 12+ messages in thread
From: Ping-Ke Shih @ 2026-08-19 0:44 UTC (permalink / raw)
To: luka.gejak@linux.dev, linux-wireless@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Michael Straube, Bitterblue Smith,
Peter Robinson, Hans de Goede
luka.gejak@linux.dev <luka.gejak@linux.dev> wrote:
> Changes in v5:
> - Dropped "fw: handle the RTL8723BS management TX reports", which v4
> had restored. It cannot do what its commit message claimed. This
> firmware does not advertise FW_FEATURE_LPS_C2H, so
> rtw_fw_leave_lps_check() takes the REG_TCR polling path and nothing
> ever waits on the C2H completion the patch rerouted; and with the
> driver instrumented, 93 TX reports over three scans all arrive as
> C2H id 0x03, with no event ever arriving as a top level 0x12 or
> 0x32. Bitterblue Smith made exactly this point on v1 and was right.
> A tester on a Rockchip RK3288 board confirmed the timeout patch in
> this series is enough on its own. This is the fourth correction of
> something I had claimed on the list; restoring it in v4 was based on
> a tester reporting that a branch containing it cleared the warnings,
> which showed the branch helped, not that this patch in it did.
> With it gone the series no longer touches fw.c.
> - Power save is now enabled on the test machine, so LPS is exercised
> there. The v2 entry below dropped a patch that gated LPS entry on
> smoothed throughput, partly on the grounds that LPS never engaged on
> this setup at all, which was never a sound reason to drop it. It is
> measured now, paired against this series in one session with power
> save on: 60 idle pings average 5.1 ms without the gating and 6.0 ms
> with it, and TCP is 30.0 down and 19.1 up against 32.3 and 18.9. It
> makes no difference, because the gate tests the smoothed throughput
> and interactive traffic rounds to zero there, so it never fires in
> the case it was meant to help. It stays dropped, now on a
> measurement rather than for want of one.
> - sdio: fixed a transmit stall in the back-pressure patch, found while
> auditing a tester report of transmit stopping under bidirectional
> load with receive unaffected and nothing in the log. The TX work
> item was only re-armed when a transfer failed with a page shortage.
> Once the mac80211 queue can be stopped, that is not enough: a
> stopped queue is handed no further frames, so on any other failure
> nothing would kick the worker again and the affected access category
> would stay stopped for good, with the link still up. It now also
> re-arms on a failed skb expansion, which together with the page
> shortage covers both of the failures that produce no log message.
> The remaining errors are each logged where they happen, so unlike
> those two they are visible rather than an unexplained hang, and they
> keep the existing behaviour rather than being retried forever.
> - rx: the zero length test now evaluates pkt_stat->pkt_len first, so
> the unlikely case short circuits before the chip test.
> - sdio: the commit message now says what OQT is, as far as the vendor
> driver reveals it: the vendor calls the register the OQT free space
> and never expands the acronym, and it holds the number of further
> transfers the SDIO output queue will accept.
> - sdio: rtw_sdio_8723bs_sync_free_txpg() now returns whether the chip
> reported anything and is the only caller of
> rtw_sdio_8723bs_store_free_txpg(), and
> rtw_sdio_8723bs_init_free_txpg() returns an error rather than
> nothing. Working through that suggestion found a real bug: the
> public pool size was computed as acq_pg_num minus the reserved
> queues with no check, so a chip that came up with no transmit page
> allocation at all would underflow a u16 and leave the driver
> believing it had about 65000 free pages. That calculation is now
> rtw_sdio_8723bs_pubq_num(), shared with the queue page allocation
> repair path, and it fails cleanly instead.
> - sdio: the output queue wait is now bounded by a jiffies deadline
> rather than a loop count, so RTW_SDIO_OQT_TIMEOUT_MS really is a
> timeout in milliseconds. It was 1000 iterations of a 1 to 2 ms
> sleep before, so the name was only approximately true.
> - sdio: rtw_sdio_8723bs_check_rqpn() returns an error instead of
> silently doing nothing when the transmit page pool cannot cover the
> reserved queues, and rtw_sdio_start() propagates it. Both early
> returns are now explained: a non-zero free page count means the
> allocation latched during power on and must be left alone.
> - sdio: fixed the interrupt acknowledgment. It masked the status word
> with both irq_mask and RTW_SDIO_HISR_CLEAR_MASK, but for this chip
> irq_mask is REG_SDIO_HIMR_RX_REQUEST alone and that bit is not in
> the clear mask, so the two had no bits in common and the driver
> acknowledged nothing at all. It now masks with the defined bits
> only, which is what the comment described. Thanks to Ping-Ke for
> catching this. Retested on hardware.
> - sdio: the back-pressure and wake conditions moved into
> rtw_sdio_8723bs_stop_tx_queue() and _wake_tx_queue(), and the two
> requeue sites into rtw_sdio_reschedule_tx_work(), instead of long
> conditions inline.
> - sdio: rtw_sdio_process_tx_queue() now returns 0 on success and 1 for
> the empty queue case, rather than the other way round.
> - sdio: queue_stopped[] renamed to tx_queue_stopped[].
> - RTW_SDIO_TX_RETRY_DELAY is left as msecs_to_jiffies(1). Ping-Ke
> asked whether it becomes 0 when HZ is below 1000; it does not, since
> msecs_to_jiffies() rounds up for HZ < 1000 and returns one jiffy.
If you can add these notes along my comments, it will be easier to me.
Not only your reply, but also I can reference source code again to
reconsider my comments if needed.
^ permalink raw reply [flat|nested] 12+ messages in thread