From: Leonard Lausen <leonard@lausen.nl>
To: Ping-Ke Shih <pkshih@realtek.com>
Cc: leonard@lausen.nl, Luka Gejak <luka.gejak@linux.dev>,
Shawn Lin <shawn.lin@rock-chips.com>,
Heiko Stuebner <heiko@sntech.de>,
linux-wireless@vger.kernel.org,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH rtw-next v2 2/2] wifi: rtw88: sdio: combine free TX page register reads
Date: Mon, 16 Nov 2026 10:08:05 +0000 [thread overview]
Message-ID: <20261116100804.425592-6-leonard@lausen.nl> (raw)
In-Reply-To: <20261116100804.425592-2-leonard@lausen.nl>
TX capacity checks on non-8051 chips read three adjacent 32-bit registers
in separate SDIO requests. Combine them into one 12-byte CMD53 read when
the existing power/alignment check permits it, with the per-register
fallback otherwise. Propagate read errors before checking queue capacity.
Allocate a DMA-safe buffer at probe and copy its little-endian values
into the caller's array before releasing the host. Holding the host
through the read and copy serializes access to the shared buffer.
Signed-off-by: Leonard Lausen <leonard@lausen.nl>
---
drivers/net/wireless/realtek/rtw88/sdio.c | 64 +++++++++++++++++++++++++++++--
drivers/net/wireless/realtek/rtw88/sdio.h | 1 +
2 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index ecd4d751c05a5..09337acb76749 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -26,6 +26,7 @@
#define RTW_SDIO_TX_FIFO_HIWATER 16
#define RTW_SDIO_TX_FIFO_LOWATER 8
#define RTW_SDIO_TX_RETRY_DELAY msecs_to_jiffies(1)
+#define RTW_SDIO_FREE_TXPG_COUNT 3
static bool rtw_sdio_is_bus_addr(u32 addr)
{
@@ -675,6 +676,43 @@ static atomic_t *rtw_sdio_8723bs_free_txpg(struct rtw_dev *rtwdev, u8 queue)
}
}
+static int rtw_sdio_read_free_txpg(struct rtw_dev *rtwdev, u32 *free_txpg)
+{
+ u32 addr = rtw_sdio_to_bus_offset(rtwdev, REG_SDIO_FREE_TXPG);
+ struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ bool bus_claim = rtw_sdio_bus_claim_needed(rtwsdio);
+ int i, ret;
+
+ if (bus_claim)
+ sdio_claim_host(rtwsdio->sdio_func);
+
+ if (!rtw_sdio_use_memcpy_io(rtwdev, addr, sizeof(u32))) {
+ for (i = 0; i < RTW_SDIO_FREE_TXPG_COUNT; i++) {
+ free_txpg[i] = rtw_sdio_readl(rtwdev,
+ addr + i * sizeof(u32),
+ &ret);
+ if (ret)
+ break;
+ }
+ goto out;
+ }
+
+ ret = sdio_memcpy_fromio(rtwsdio->sdio_func,
+ rtwsdio->free_txpg_buf, addr,
+ RTW_SDIO_FREE_TXPG_COUNT * sizeof(__le32));
+ if (!ret) {
+ /* Copy the shared DMA buffer before releasing the host. */
+ for (i = 0; i < RTW_SDIO_FREE_TXPG_COUNT; i++)
+ free_txpg[i] = le32_to_cpu(rtwsdio->free_txpg_buf[i]);
+ }
+
+out:
+ if (bus_claim)
+ sdio_release_host(rtwsdio->sdio_func);
+
+ return ret;
+}
+
static int rtw_sdio_check_free_txpg(struct rtw_dev *rtwdev, u8 queue,
size_t count)
{
@@ -727,11 +765,15 @@ 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];
+ u32 free_txpg[RTW_SDIO_FREE_TXPG_COUNT];
+ int ret;
- 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);
+ ret = rtw_sdio_read_free_txpg(rtwdev, free_txpg);
+ if (ret) {
+ rtw_warn(rtwdev, "Failed to read free TX pages: %d\n",
+ ret);
+ return ret;
+ }
switch (queue) {
case RTW_TX_QUEUE_BCN:
@@ -1782,6 +1824,7 @@ static void rtw_sdio_deinit_tx(struct rtw_dev *rtwdev)
int rtw_sdio_probe(struct sdio_func *sdio_func,
const struct sdio_device_id *id)
{
+ struct rtw_sdio *rtwsdio;
struct ieee80211_hw *hw;
struct rtw_dev *rtwdev;
int drv_data_size;
@@ -1805,6 +1848,19 @@ int rtw_sdio_probe(struct sdio_func *sdio_func,
if (ret)
goto err_release_hw;
+ rtwsdio = (struct rtw_sdio *)rtwdev->priv;
+ if (!rtw_chip_wcpu_8051(rtwdev)) {
+ rtwsdio->free_txpg_buf =
+ devm_kmalloc_array(rtwdev->dev,
+ RTW_SDIO_FREE_TXPG_COUNT,
+ sizeof(*rtwsdio->free_txpg_buf),
+ GFP_KERNEL);
+ if (!rtwsdio->free_txpg_buf) {
+ ret = -ENOMEM;
+ goto err_deinit_core;
+ }
+ }
+
rtw_dbg(rtwdev, RTW_DBG_SDIO,
"rtw88 SDIO probe: vendor=0x%04x device=%04x class=%02x",
id->vendor, id->device, id->class);
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index 6e7e6009744b0..5c2337ccffb2a 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -181,6 +181,7 @@ struct rtw_sdio {
atomic_t tx_oqt_free;
/* one writer at a time between the credit check and the accounting */
struct mutex tx_credit_lock;
+ __le32 *free_txpg_buf;
};
extern const struct dev_pm_ops rtw_sdio_pm_ops;
prev parent reply other threads:[~2026-11-16 10:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 10:08 [PATCH rtw-next v2 0/2] wifi: rtw88: reduce RTL8822CS SDIO request overhead Leonard Lausen
2026-11-16 10:08 ` [PATCH rtw-next v2 1/2] wifi: rtw88: 8822c: filter hardware-handled control frames on SDIO Leonard Lausen
2026-11-16 10:08 ` Leonard Lausen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116100804.425592-6-leonard@lausen.nl \
--to=leonard@lausen.nl \
--cc=heiko@sntech.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=luka.gejak@linux.dev \
--cc=pkshih@realtek.com \
--cc=shawn.lin@rock-chips.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®