All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH rtw-next] wifi: rtw88: sdio: limit the high queue to DTIM delivery
@ 2026-10-20 19:15 Luka Gejak
  0 siblings, 0 replies; only message in thread
From: Luka Gejak @ 2026-10-20 19:15 UTC (permalink / raw)
  To: Ping-Ke Shih; +Cc: linux-wireless, Luka Gejak

In AP mode every broadcast and multicast (bmc) frame is sent through the
high queue, which the hardware only drains after a DTIM beacon. Only a
few frames leave per DTIM, so steady multicast traffic builds a backlog
that holds the TX pages the other queues need. Unicast traffic then
stalls for seconds and clients can no longer renew their DHCP lease.

USB had the same problem and was fixed by commit c710c7c2e038 ("wifi:
rtw88: usb: route bmc frames via the high queue only for DTIM delivery")
and the two commits that followed it. Use the same rule for SDIO. A bmc
frame goes to the high queue only when mac80211 asks for DTIM delivery
because a station is dozing, the frame is ARP, EAPOL or DHCP, and the
budget allows it. All other bmc frames go out on their access category
queue.

Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
---
  Tested on rtl8723bs with atk19 client. No regression in station mode.
  Note: this adds support for AP mode for rtl8723bs, as I states AP
  mode was left for future work.
- Broadcast ping round trip was 3.6 ms, it was ~104 ms before the
    patch.
  - During a 50 frames/s broadcast flood, the TX page pool didn't
    move and unicast was unaffected.
  - A DHCP renewal under that load got a lease on the first DISCOVER.
  - A dozing client received 18 of 20 broadcast ARP requests.

 drivers/net/wireless/realtek/rtw88/sdio.c | 69 +++++++++++++++++++++++
 drivers/net/wireless/realtek/rtw88/sdio.h |  5 ++
 2 files changed, 74 insertions(+)

diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index dc2fd0f8f9ff..3cdffac5b5b0 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -6,9 +6,11 @@
  *   Copyright(c) 2018-2019  Realtek Corporation
  */
 
+#include <linux/ip.h>
 #include <linux/module.h>
 #include <linux/mmc/host.h>
 #include <linux/mmc/sdio_func.h>
+#include <linux/udp.h>
 #include "main.h"
 #include "mac.h"
 #include "debug.h"
@@ -26,6 +28,8 @@
 #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_HIQ_REFILL_INTERVAL			(HZ / 10)
+#define RTW_SDIO_HIQ_BUDGET_MAX				16
 
 static bool rtw_sdio_is_bus_addr(u32 addr)
 {
@@ -1299,6 +1303,64 @@ static void rtw_sdio_8723bs_wake_tx_queue(struct rtw_dev *rtwdev,
 	ieee80211_wake_queue(rtwdev->hw, q_map);
 }
 
+static bool rtw_sdio_bmc_needs_dtim(struct sk_buff *skb)
+{
+	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+	struct udphdr *udphdr;
+
+	if (info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO)
+		return true;
+
+	if (skb->protocol == htons(ETH_P_ARP))
+		return true;
+
+	if (skb->protocol == htons(ETH_P_IP) &&
+	    ip_hdr(skb)->protocol == IPPROTO_UDP) {
+		udphdr = udp_hdr(skb);
+
+		return udphdr->dest == htons(67) || udphdr->dest == htons(68);
+	}
+
+	return false;
+}
+
+static bool rtw_sdio_hiq_take_budget(struct rtw_sdio *rtwsdio)
+{
+	unsigned long flags, elapsed, add;
+	bool ok;
+
+	spin_lock_irqsave(&rtwsdio->hiq_lock, flags);
+
+	elapsed = jiffies - rtwsdio->hiq_refill;
+	add = elapsed / RTW_SDIO_HIQ_REFILL_INTERVAL;
+	if (add) {
+		rtwsdio->hiq_budget = min_t(unsigned long,
+					    rtwsdio->hiq_budget + add,
+					    RTW_SDIO_HIQ_BUDGET_MAX);
+
+		/* keep the unfinished part of the interval for the next unit */
+		rtwsdio->hiq_refill = jiffies -
+				      elapsed % RTW_SDIO_HIQ_REFILL_INTERVAL;
+	}
+
+	ok = rtwsdio->hiq_budget > 0;
+	if (ok)
+		rtwsdio->hiq_budget--;
+
+	spin_unlock_irqrestore(&rtwsdio->hiq_lock, flags);
+
+	return ok;
+}
+
+static bool rtw_sdio_bmc_use_hiq(struct rtw_sdio *rtwsdio, struct sk_buff *skb)
+{
+	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+
+	return (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) &&
+	       rtw_sdio_bmc_needs_dtim(skb) &&
+	       rtw_sdio_hiq_take_budget(rtwsdio);
+}
+
 static int rtw_sdio_tx_write(struct rtw_dev *rtwdev,
 			     struct rtw_tx_pkt_info *pkt_info,
 			     struct sk_buff *skb)
@@ -1308,6 +1370,9 @@ static int rtw_sdio_tx_write(struct rtw_dev *rtwdev,
 	u16 q_map = skb_get_queue_mapping(skb);
 	struct rtw_sdio_tx_data *tx_data;
 
+	if (queue == RTW_TX_QUEUE_HI0 && !rtw_sdio_bmc_use_hiq(rtwsdio, skb))
+		queue = rtw_tx_ac_to_hwq(q_map);
+
 	rtw_sdio_tx_skb_prepare(rtwdev, pkt_info, skb, queue);
 
 	tx_data = rtw_sdio_get_tx_data(skb);
@@ -1730,6 +1795,10 @@ static int rtw_sdio_init_tx(struct rtw_dev *rtwdev)
 	struct rtw_sdio *rtwsdio = (struct rtw_sdio *)rtwdev->priv;
 	int i;
 
+	spin_lock_init(&rtwsdio->hiq_lock);
+	rtwsdio->hiq_budget = RTW_SDIO_HIQ_BUDGET_MAX;
+	rtwsdio->hiq_refill = jiffies;
+
 	rtwsdio->txwq = create_singlethread_workqueue("rtw88_sdio: tx wq");
 	if (!rtwsdio->txwq) {
 		rtw_err(rtwdev, "failed to create TX work queue\n");
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.h b/drivers/net/wireless/realtek/rtw88/sdio.h
index 6e7e6009744b..2083e6fb3fa9 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.h
+++ b/drivers/net/wireless/realtek/rtw88/sdio.h
@@ -174,6 +174,11 @@ struct rtw_sdio {
 	struct sk_buff_head tx_queue[RTK_MAX_TX_QUEUE_NUM];
 	bool tx_queue_stopped[RTK_MAX_TX_QUEUE_NUM];
 
+	/* protects hiq_budget and hiq_refill */
+	spinlock_t hiq_lock;
+	u32 hiq_budget;
+	unsigned long hiq_refill;
+
 	atomic_t free_pg_high;
 	atomic_t free_pg_normal;
 	atomic_t free_pg_low;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-20 19:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 19:15 [PATCH rtw-next] wifi: rtw88: sdio: limit the high queue to DTIM delivery Luka Gejak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.