Linux-Rockchip Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH rtw-next v2 0/2] wifi: rtw88: reduce RTL8822CS SDIO request overhead
@ 2026-11-16 10:08 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 ` [PATCH rtw-next v2 2/2] wifi: rtw88: sdio: combine free TX page register reads Leonard Lausen
  0 siblings, 2 replies; 4+ messages in thread
From: Leonard Lausen @ 2026-11-16 10:08 UTC (permalink / raw)
  To: Ping-Ke Shih
  Cc: leonard, Luka Gejak, Shawn Lin, Heiko Stuebner, linux-wireless,
	linux-rockchip, linux-kernel

Reduce RTL8822CS SDIO request overhead by filtering hardware-handled
control frames and combining adjacent TX-capacity reads.

This complete v2 series is based on rtw-next at 61a5eb87b2d9. Changes in v2:
- Rebase both patches onto rtw-next.
- Fix continuation and argument alignment, declaration order, comment
  formatting and long lines throughout the added code.
- Remove the deprecated Assisted-by tag.
- Refresh throughput measurements using the rebased driver.

TCP medians on RTL8822CS/NanoPi M5 with the v2 driver, in Mbit/s:

                              Upload   Download
  rtw-next baseline             165.7      206.7
  Both patches                  296.9      271.2

Together the patches improved median upload by 79.2% and download by 31.2%.
Each configuration used three 20-second TCP samples per direction on a
shared Wi-Fi network, so throughput can vary.

Both driver stacks were built against the running v7.4-rc2 kernel and
hot-loaded. The same test-only adaptation restored the older key-iteration
API and RCU locking in firmware recovery. Both configurations used the
same MMC host stack, 198 MHz SDR104 and performance governors, with SDIO
IRQ on CPU4, iperf client on CPU6 and server on CPU7. Traffic crossed
Wi-Fi/AP/Ethernet between two endpoints on the board.

Independent v1 tests measured a 52% upload and 9% download gain from
filtering alone, and 9% upload and 8% download from combined reads alone.
Adding combined reads after filtering gave another 11% upload and 4%
download. Those tests used v7.4-rc2 with the RX-bounds and MMC voltage-switch
fixes and stock MMC host limits: four 20-second upload samples and four
30-second download samples per configuration on the shared network.

All 20 configured rtw88 module objects compiled and linked as relocatable
objects on ARM64 with W=1 after each patch, without warnings. Runtime
builds passed modpost; loaded module IDs, traffic paths and register
settings were checked. MMC traces confirmed three 4-byte capacity reads
became one 12-byte read, with zero SDIO command errors.
No full rtw-next kernel was booted or installed module files replaced.
AP/monitor, suspend/resume and other-chip hardware remain untested.

AI assistance: Codex helped develop the code, inspect vendor sources,
automate the earlier benchmarks, rebase the series, apply style fixes
and draft the messages.

v1: https://lore.kernel.org/linux-wireless/20261115142330.359247-2-leonard@lausen.nl/

Leonard Lausen (2):
  wifi: rtw88: 8822c: filter hardware-handled control frames on SDIO
  wifi: rtw88: sdio: combine free TX page register reads

 drivers/net/wireless/realtek/rtw88/reg.h      |  4 ++
 drivers/net/wireless/realtek/rtw88/rtw8822c.c | 10 +++
 drivers/net/wireless/realtek/rtw88/sdio.c     | 63 +++++++++++++++++--
 drivers/net/wireless/realtek/rtw88/sdio.h     |  1 +
 4 files changed, 74 insertions(+), 4 deletions(-)


base-commit: 61a5eb87b2d9b4d5e353780b781cf691f39ba9e1

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH rtw-next v2 1/2] wifi: rtw88: 8822c: filter hardware-handled control frames on SDIO
  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 ` Leonard Lausen
  2026-11-16 16:30   ` Luka Gejak
  2026-11-16 10:08 ` [PATCH rtw-next v2 2/2] wifi: rtw88: sdio: combine free TX page register reads Leonard Lausen
  1 sibling, 1 reply; 4+ messages in thread
From: Leonard Lausen @ 2026-11-16 10:08 UTC (permalink / raw)
  To: Ping-Ke Shih
  Cc: leonard, Luka Gejak, Shawn Lin, Heiko Stuebner, linux-wireless,
	linux-rockchip, linux-kernel

RTL8822C forwards every control-frame subtype to the host by default.
ACK, Block Ack, RTS and CTS frames are handled by hardware, but forwarding
them also adds small SDIO transfers to the data path.

Clear these four subtypes from the SDIO default RX filter. Retain BAR,
PS-Poll and the remaining subtypes, and store the default in rxfltmap1
so FIF_CONTROL can still request all control frames.

Limit the new default to SDIO, where profiling identified this overhead.
PCIe and USB receive paths have not been tested with this filter setting.

FriendlyElec's RTL8822CS driver also filters control frames at startup;
this change retains additional subtypes for mac80211.

Link: https://github.com/friendlyarm/rtl8822cs/blob/c8b944a34bba2116fcdb060362bde40242bb87e5/hal/rtl8822c/rtl8822c_halinit.c
Signed-off-by: Leonard Lausen <leonard@lausen.nl>
---
 drivers/net/wireless/realtek/rtw88/reg.h      |  4 ++++
 drivers/net/wireless/realtek/rtw88/rtw8822c.c | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw88/reg.h b/drivers/net/wireless/realtek/rtw88/reg.h
index afcdb66fdb9a1..8e220580be4f8 100644
--- a/drivers/net/wireless/realtek/rtw88/reg.h
+++ b/drivers/net/wireless/realtek/rtw88/reg.h
@@ -587,6 +587,10 @@
 
 #define REG_RXFLTMAP0		0x06A0
 #define REG_RXFLTMAP1		0x06A2
+#define BIT_RXFLTMAP1_BACK	BIT(9)
+#define BIT_RXFLTMAP1_RTS	BIT(11)
+#define BIT_RXFLTMAP1_CTS	BIT(12)
+#define BIT_RXFLTMAP1_ACK	BIT(13)
 #define REG_RXFLTMAP2		0x06A4
 #define REG_RXFLTMAP4		0x068A
 #define REG_BT_COEX_TABLE0	0x06C0
diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
index 09315d23e2c40..03e714c3c2e7a 100644
--- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c
+++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c
@@ -2096,6 +2096,16 @@ static int rtw8822c_mac_init(struct rtw_dev *rtwdev)
 	rtw_write8(rtwdev, REG_WMAC_TRXPTCL_CTL_H  + 2, WLAN_BAR_ACK_TYPE);
 	rtw_write16(rtwdev, REG_RXFLTMAP0, WLAN_RX_FILTER0);
 	rtwdev->hal.rxfltmap1 = WLAN_RX_FILTER1;
+	if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_SDIO) {
+		/*
+		 * Hardware handles these frames; retain BAR and PS-Poll for
+		 * mac80211. FIF_CONTROL restores all subtypes for monitors.
+		 */
+		rtwdev->hal.rxfltmap1 &= ~(BIT_RXFLTMAP1_BACK |
+					   BIT_RXFLTMAP1_RTS |
+					   BIT_RXFLTMAP1_CTS |
+					   BIT_RXFLTMAP1_ACK);
+	}
 	rtw_write16(rtwdev, REG_RXFLTMAP1, rtwdev->hal.rxfltmap1);
 	rtw_write16(rtwdev, REG_RXFLTMAP2, WLAN_RX_FILTER2);
 	rtw_write32(rtwdev, REG_RCR, WLAN_RCR_CFG);

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH rtw-next v2 2/2] wifi: rtw88: sdio: combine free TX page register reads
  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
  1 sibling, 0 replies; 4+ messages in thread
From: Leonard Lausen @ 2026-11-16 10:08 UTC (permalink / raw)
  To: Ping-Ke Shih
  Cc: leonard, Luka Gejak, Shawn Lin, Heiko Stuebner, linux-wireless,
	linux-rockchip, linux-kernel

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;

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH rtw-next v2 1/2] wifi: rtw88: 8822c: filter hardware-handled control frames on SDIO
  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 16:30   ` Luka Gejak
  0 siblings, 0 replies; 4+ messages in thread
From: Luka Gejak @ 2026-11-16 16:30 UTC (permalink / raw)
  To: Leonard Lausen, Ping-Ke Shih
  Cc: leonard, Shawn Lin, Heiko Stuebner, linux-wireless,
	linux-rockchip, linux-kernel

Hi Leonard,

Thanks for the update. One comment below.

On November 16, 2026 11:08:03 AM GMT+01:00, Leonard Lausen
<leonard@lausen.nl> wrote:

> @@ -2096,6 +2096,16 @@ static int rtw8822c_mac_init(struct rtw_dev *rtwdev)

[ ... ]

>       rtwdev->hal.rxfltmap1 = WLAN_RX_FILTER1;
> +     if (rtw_hci_type(rtwdev) == RTW_HCI_TYPE_SDIO) {
> +             /*
> +              * Hardware handles these frames; retain BAR and PS-Poll for
> +              * mac80211. FIF_CONTROL restores all subtypes for monitors.
> +              */
> +             rtwdev->hal.rxfltmap1 &= ~(BIT_RXFLTMAP1_BACK |
> +                                        BIT_RXFLTMAP1_RTS |
> +                                        BIT_RXFLTMAP1_CTS |
> +                                        BIT_RXFLTMAP1_ACK);
> +     }
>       rtw_write16(rtwdev, REG_RXFLTMAP1, rtwdev->hal.rxfltmap1);

[ ... ]

As far as I can see, later writes of this default can disable these frames
while a monitor still requests them.

For example, with an unassociated interface in IPS, bringing up a monitor
first calls ieee80211_configure_filter(). The following
ieee80211_recalc_idle() leaves IPS and runs rtw8822c_mac_init(), which
writes the reduced map again. A hardware restart or resume with an
existing monitor seems to have the same problem.

mac80211 keeps local->filter_flags, so FIF_CONTROL can still be set in
*new_flags but clear in changed_flags. Then rtw_ops_configure_filter()
skips restoring 0xffff.

There also seems to be a way to lose it while the radio stays on.
Associating a managed interface with an MU beamformer calls:

        rtw_bf_enable_bfee_mu()
                rtw_bf_cfg_sounding()

Both functions write hal.rxfltmap1 back to REG_RXFLTMAP1, replacing the
monitor's 0xffff with the reduced map. Before this patch those writes
left the four subtypes enabled.

Could we preserve the active FIF_CONTROL setting in the common filter
code and use it for MAC initialization and the writes in bf.c too?

Best regards,
Luka Gejak

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-16 16:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 16:30   ` Luka Gejak
2026-11-16 10:08 ` [PATCH rtw-next v2 2/2] wifi: rtw88: sdio: combine free TX page register reads Leonard Lausen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox