Skip to contentSkip to conversation

wifi: rtw88: reduce RTL8822CS SDIO request overhead

PATCH Superseded Leonard Lausen 2 participants 4 messages Nov 16

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover wifi: rtw88: reduce RTL8822CS SDIO request overhead

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/[email protected]/

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

#1 lore raw

PATCH v2 1/2 wifi: rtw88: 8822c: filter hardware-handled control frames on SDIO

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.

---
 drivers/net/wireless/realtek/rtw88/reg.h      |  4 ++++
 drivers/net/wireless/realtek/rtw88/rtw8822c.c | 10 ++++++++++
 2 files changed, 14 insertions(+)
drivers/net/wireless/realtek/rtw88/reg.h +4 -0
index afcdb66fdb9a1..8e220580be4f8 100644
@@ -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
drivers/net/wireless/realtek/rtw88/rtw8822c.c +10 -0
index 09315d23e2c40..03e714c3c2e7a 100644
@@ -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);
#2 lore raw

Re: [PATCH rtw-next v2 1/2] wifi: rtw88: 8822c: filter hardware-handled control frames on SDIO

Hi Leonard,

Thanks for the update. One comment below.

Quoted 1 line · Leonard Lausen
(quoted diff) +0 -0
@@ -2096,6 +2096,16 @@ static int rtw8822c_mac_init(struct rtw_dev *rtwdev)

[ ... ]

drivers/net/wireless/realtek/rtw88/rtw8822c.c static int rtw8822c_mac_init(struct rtw_dev *rtwdev) · line 2109

Quoted 12 lines
      rtwdev->hal.rxfltmap1 = WLAN_RX_FILTER1;
drivers/net/wireless/realtek/rtw88/rtw8822c.c +10 -0
+     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

#3 lore raw

PATCH v2 2/2 wifi: rtw88: sdio: combine free TX page register reads

In reply to Leonard Lausen

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.

---
 drivers/net/wireless/realtek/rtw88/sdio.c | 64 +++++++++++++++++++++++++++++--
 drivers/net/wireless/realtek/rtw88/sdio.h |  1 +
 2 files changed, 61 insertions(+), 4 deletions(-)
drivers/net/wireless/realtek/rtw88/sdio.c +60 -4
index ecd4d751c05a5..09337acb76749 100644
@@ -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);
drivers/net/wireless/realtek/rtw88/sdio.h +1 -0
index 6e7e6009744b0..5c2337ccffb2a 100644
@@ -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;