* [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path
@ 2026-11-23 13:41 Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 01/10] wifi: ath11k: use page_pool for the RX refill ring Julius Bairaktaris
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The ath11k RX path spends a part of its time per received frame on work
that the hardware or a cheaper structure already provides: an allocation,
a DMA map and unmap and an IDR walk per buffer, a peer lookup done twice,
a cache invalidation per ring entry and per full buffer, bottom-half
toggles inside a region that already has them off, PPDU stats TLVs nobody
parses, and a flow hash computed again in software. This series removes
these one at a time:
1-2 give the refill ring a page_pool and replace the buffer IDR with a
table of ids;
3 asks the firmware only for the PPDU stats TLVs the driver parses;
4 sets the skb hash from the receive engine's Toeplitz hash;
5-6 sync the new entries of a cached ring once per head read and
prefetch the buffers of the entries ahead (cached rings only, that is
IPQ8074, IPQ6018, QCN9074 and IPQ5018);
7 looks the peer of an MSDU up once;
8 drops a nested bottom-half disable in the reap and refill loops;
9 invalidates only the part of a page pool buffer the device wrote;
10 takes the buffer table lock once per chunk of refill buffers.
None of them changes interrupt placement or adds work on another CPU;
each takes work away from the CPU that already handles the frame.
The profile shares in the commit messages come from perf on an IPQ8074
access point (Xiaomi AX3600, 4x Cortex-A53, 5 GHz HE160, one station at
850-900 Mbit/s TCP), one run each, with OpenWrt's version of these
patches.
On a Xiaomi AX3600 (IPQ8074 hw2.0, firmware
WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1) running OpenWrt's wireless
backports with the RX fixes, with one HE160 station at 830-940 Mbit/s
TCP and 3 runs per cell, the series lowered the share of the four
cores the traffic takes in the cells where the station sends: bridged
IPv4 33.0 -> 27.6 %, bridged IPv6 32.8 -> 27.7 %, routed IPv4
33.7 -> 27.6 %, and routed IPv6 31.2 -> 27.9 %, which is within the
spread between runs. Where the station receives, the change was
between -1.4 and +0.8 points, also within that spread. The share is the time idle-priority spinners lose
on each core. Switching pktlog (lite and full) and the extended TX
stats on and off, adding and removing a monitor interface on both
radios, and unloading and reloading the modules left traffic and dmesg
clean.
The series applies on top of the RX correctness fixes https://lore.kernel.org/all/20261122210525.2076058-1-julius@bairaktaris.de/: its
4/10 uses the msdu_start_info2 accessor that series adds.
I used Claude (Anthropic) to help write these patches.
Julius Bairaktaris (10):
wifi: ath11k: use page_pool for the RX refill ring
wifi: ath11k: replace the RX buffer IDR with a table
wifi: ath11k: request only the PPDU stats TLVs it reads
wifi: ath11k: set the skb hash of a received frame from the hardware
wifi: ath11k: sync a cached ring's new entries once per head read
wifi: ath11k: prefetch the buffers of the REO entries ahead of their
reap
wifi: ath11k: look the peer of a received MSDU up once
wifi: ath11k: take the refill buffer lock without a second BH disable
wifi: ath11k: hand the CPU only the part of a REO buffer the device
wrote
wifi: ath11k: give the refill buffers their ids a chunk at a time
drivers/net/wireless/ath/ath11k/Kconfig | 1 +
drivers/net/wireless/ath/ath11k/core.h | 5 +
drivers/net/wireless/ath/ath11k/debugfs.c | 15 +-
drivers/net/wireless/ath/ath11k/debugfs.h | 10 +
drivers/net/wireless/ath/ath11k/dp.c | 9 +-
drivers/net/wireless/ath/ath11k/dp.h | 27 +-
drivers/net/wireless/ath/ath11k/dp_rx.c | 712 +++++++++++++++++-----
drivers/net/wireless/ath/ath11k/dp_tx.c | 34 ++
drivers/net/wireless/ath/ath11k/dp_tx.h | 1 +
drivers/net/wireless/ath/ath11k/hal.c | 107 +++-
drivers/net/wireless/ath/ath11k/hal.h | 1 +
drivers/net/wireless/ath/ath11k/hw.c | 22 +
drivers/net/wireless/ath/ath11k/hw.h | 1 +
drivers/net/wireless/ath/ath11k/mac.c | 13 +-
14 files changed, 765 insertions(+), 193 deletions(-)
base-commit: 1983b40acfcb3c3464b291c85977290a785bcfdc
prerequisite-patch-id: ed566369a9bbda0ac9a48357261e8cfe1cc0f1d1
prerequisite-patch-id: 726d7737c833da0842192eccececad4a0dedb1a6
prerequisite-patch-id: cf0b8ff1ac6cef681433247e4b937a3e23af78a3
prerequisite-patch-id: 03c89df01745ac9a80653431261f9a003dbca7db
prerequisite-patch-id: cb48c0eddbe0c2fe176e8edc94c6bc40be3c48a9
prerequisite-patch-id: 1956ec85ad80b68868538070fc0e89c29603467a
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 01/10] wifi: ath11k: use page_pool for the RX refill ring
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 02/10] wifi: ath11k: replace the RX buffer IDR with a table Julius Bairaktaris
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The RX refill ring takes every buffer from dev_alloc_skb(), maps it with
dma_map_single() and unmaps it again when the frame is reaped, so each
received frame costs one allocation from the per-CPU page-frag cache and
one map and unmap. Buffers of the ring also share that cache with
unrelated allocations, so one long-lived skb pins a whole high-order
page.
Give the refill ring of each radio its own page_pool. The pool keeps the
DMA mapping of its pages, the reap paths sync the buffer for the CPU
instead of unmapping it, and a freed skb returns its page to the pool.
Each order-1 page carries three 128-byte aligned buffers, about the
memory the page-frag allocation took for the same three. The pool holds
as many pages as the ring has entries. The monitor rings keep
dev_alloc_skb().
A defragmented frame that is reinjected into the refill ring is synced
for the device when it comes from the pool, and mapped as before
otherwise.
Mark Ruvald Pedersen's RFC proposed private page-frag caches for these
rings.
Link: https://lore.kernel.org/linux-wireless/20260719215817.2468580-1-wabsie@gmail.com/
Link: https://lore.kernel.org/linux-wireless/20261008-ath12k-pp-v1-0-68f888cd7eec@oss.qualcomm.com/
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/Kconfig | 1 +
drivers/net/wireless/ath/ath11k/dp.h | 4 +
drivers/net/wireless/ath/ath11k/dp_rx.c | 191 +++++++++++++++++-------
3 files changed, 138 insertions(+), 58 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/Kconfig b/drivers/net/wireless/ath/ath11k/Kconfig
index 99f625b82fe1..5c949e856649 100644
--- a/drivers/net/wireless/ath/ath11k/Kconfig
+++ b/drivers/net/wireless/ath/ath11k/Kconfig
@@ -3,6 +3,7 @@ config ATH11K
tristate "Qualcomm 802.11ax chipset support"
depends on MAC80211 && HAS_DMA
select QCOM_QMI_HELPERS
+ select PAGE_POOL
help
This module adds support for Qualcomm Technologies 802.11ax family of
chipsets.
diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h
index 84f66839f0c6..357185e45ae6 100644
--- a/drivers/net/wireless/ath/ath11k/dp.h
+++ b/drivers/net/wireless/ath/ath11k/dp.h
@@ -72,6 +72,7 @@ struct dp_srng {
struct dp_rxdma_ring {
struct dp_srng refill_buf_ring;
+ struct page_pool *page_pool;
struct idr bufs_idr;
/* Protects bufs_idr */
spinlock_t idr_lock;
@@ -229,6 +230,9 @@ struct ath11k_pdev_dp {
#define DP_RX_BUFFER_SIZE 2048
#define DP_RX_BUFFER_SIZE_LITE 1024
#define DP_RX_BUFFER_ALIGN_SIZE 128
+#define DP_RX_PP_ORDER 1
+#define DP_RX_PP_FRAG_SIZE ALIGN(SKB_HEAD_ALIGN(DP_RX_BUFFER_SIZE), \
+ DP_RX_BUFFER_ALIGN_SIZE)
#define DP_RXDMA_BUF_COOKIE_BUF_ID GENMASK(17, 0)
#define DP_RXDMA_BUF_COOKIE_PDEV_ID GENMASK(20, 18)
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index 6fdcd2aed7dc..bad5c58dfafa 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -8,6 +8,7 @@
#include <linux/ieee80211.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
+#include <net/page_pool/helpers.h>
#include "core.h"
#include "debug.h"
#include "debugfs_htt_stats.h"
@@ -340,6 +341,56 @@ static int ath11k_dp_purge_mon_ring(struct ath11k_base *ab)
return -ETIMEDOUT;
}
+static bool ath11k_dp_rx_buf_is_pp(struct sk_buff *skb)
+{
+ return skb->pp_recycle && skb->head_frag;
+}
+
+static void ath11k_dp_rx_unmap_buf(struct ath11k_base *ab, struct sk_buff *skb,
+ enum dma_data_direction dir)
+{
+ struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(skb);
+ unsigned int len = skb->len + skb_tailroom(skb);
+
+ if (ath11k_dp_rx_buf_is_pp(skb))
+ dma_sync_single_for_cpu(ab->dev, rxcb->paddr, len,
+ DMA_BIDIRECTIONAL);
+ else
+ dma_unmap_single(ab->dev, rxcb->paddr, len, dir);
+}
+
+static dma_addr_t ath11k_dp_rx_pp_dma_addr(struct sk_buff *skb)
+{
+ struct page *page = virt_to_head_page(skb->data);
+
+ return page_pool_get_dma_addr(page) +
+ (skb->data - (u8 *)page_address(page));
+}
+
+static struct sk_buff *ath11k_dp_rx_pp_alloc_skb(struct dp_rxdma_ring *rx_ring)
+{
+ struct sk_buff *skb;
+ unsigned int offset;
+ struct page *page;
+ void *va;
+
+ page = page_pool_dev_alloc_frag(rx_ring->page_pool, &offset,
+ DP_RX_PP_FRAG_SIZE);
+ if (!page)
+ return NULL;
+
+ va = page_address(page) + offset;
+ skb = build_skb(va, DP_RX_PP_FRAG_SIZE);
+ if (!skb) {
+ page_pool_put_full_page(rx_ring->page_pool, page, false);
+ return NULL;
+ }
+
+ skb_mark_for_recycle(skb);
+
+ return skb;
+}
+
/* Returns number of Rx buffers replenished */
int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
struct dp_rxdma_ring *rx_ring,
@@ -371,23 +422,32 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
num_remain = req_entries;
while (num_remain > 0) {
- skb = dev_alloc_skb(DP_RX_BUFFER_SIZE +
- DP_RX_BUFFER_ALIGN_SIZE);
- if (!skb)
- break;
+ if (rx_ring->page_pool) {
+ skb = ath11k_dp_rx_pp_alloc_skb(rx_ring);
+ if (!skb)
+ break;
- if (!IS_ALIGNED((unsigned long)skb->data,
- DP_RX_BUFFER_ALIGN_SIZE)) {
- skb_pull(skb,
- PTR_ALIGN(skb->data, DP_RX_BUFFER_ALIGN_SIZE) -
- skb->data);
- }
+ paddr = ath11k_dp_rx_pp_dma_addr(skb);
+ } else {
+ skb = dev_alloc_skb(DP_RX_BUFFER_SIZE +
+ DP_RX_BUFFER_ALIGN_SIZE);
+ if (!skb)
+ break;
- paddr = dma_map_single(ab->dev, skb->data,
- skb->len + skb_tailroom(skb),
- DMA_FROM_DEVICE);
- if (dma_mapping_error(ab->dev, paddr))
- goto fail_free_skb;
+ if (!IS_ALIGNED((unsigned long)skb->data,
+ DP_RX_BUFFER_ALIGN_SIZE)) {
+ skb_pull(skb,
+ PTR_ALIGN(skb->data,
+ DP_RX_BUFFER_ALIGN_SIZE) -
+ skb->data);
+ }
+
+ paddr = dma_map_single(ab->dev, skb->data,
+ skb->len + skb_tailroom(skb),
+ DMA_FROM_DEVICE);
+ if (dma_mapping_error(ab->dev, paddr))
+ goto fail_free_skb;
+ }
spin_lock_bh(&rx_ring->idr_lock);
buf_id = idr_alloc(&rx_ring->bufs_idr, skb, 1,
@@ -421,8 +481,9 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
idr_remove(&rx_ring->bufs_idr, buf_id);
spin_unlock_bh(&rx_ring->idr_lock);
fail_dma_unmap:
- dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
- DMA_FROM_DEVICE);
+ if (!rx_ring->page_pool)
+ dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
+ DMA_FROM_DEVICE);
fail_free_skb:
dev_kfree_skb_any(skb);
@@ -445,14 +506,18 @@ static int ath11k_dp_rxdma_buf_ring_free(struct ath11k *ar,
/* TODO: Understand where internal driver does this dma_unmap
* of rxdma_buffer.
*/
- dma_unmap_single(ar->ab->dev, ATH11K_SKB_RXCB(skb)->paddr,
- skb->len + skb_tailroom(skb), DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ar->ab, skb, DMA_FROM_DEVICE);
dev_kfree_skb_any(skb);
}
idr_destroy(&rx_ring->bufs_idr);
spin_unlock_bh(&rx_ring->idr_lock);
+ if (rx_ring->page_pool) {
+ page_pool_destroy(rx_ring->page_pool);
+ rx_ring->page_pool = NULL;
+ }
+
return 0;
}
@@ -486,6 +551,25 @@ static int ath11k_dp_rxdma_ring_buf_setup(struct ath11k *ar,
num_entries = rx_ring->refill_buf_ring.size /
ath11k_hal_srng_get_entrysize(ar->ab, ringtype);
+ if (ringtype == HAL_RXDMA_BUF) {
+ struct page_pool_params pp_params = {
+ .order = DP_RX_PP_ORDER,
+ .flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV,
+ .pool_size = num_entries,
+ .nid = NUMA_NO_NODE,
+ .dev = ar->ab->dev,
+ .dma_dir = DMA_BIDIRECTIONAL,
+ .max_len = PAGE_SIZE << DP_RX_PP_ORDER,
+ };
+ struct page_pool *pp;
+
+ pp = page_pool_create(&pp_params);
+ if (IS_ERR(pp))
+ return PTR_ERR(pp);
+
+ rx_ring->page_pool = pp;
+ }
+
rx_ring->bufs_max = num_entries;
ath11k_dp_rxbufs_replenish(ar->ab, dp->mac_id, rx_ring, num_entries,
ar->ab->hw_params.hal_params->rx_buf_rbm);
@@ -497,9 +581,11 @@ static int ath11k_dp_rxdma_pdev_buf_setup(struct ath11k *ar)
struct ath11k_pdev_dp *dp = &ar->dp;
struct ath11k_base *ab = ar->ab;
struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring;
- int i;
+ int i, ret;
- ath11k_dp_rxdma_ring_buf_setup(ar, rx_ring, HAL_RXDMA_BUF);
+ ret = ath11k_dp_rxdma_ring_buf_setup(ar, rx_ring, HAL_RXDMA_BUF);
+ if (ret)
+ return ret;
if (ar->ab->hw_params.rxdma1_enable) {
rx_ring = &dp->rxdma_mon_buf_ring;
@@ -2775,9 +2861,7 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
spin_unlock_bh(&rx_ring->idr_lock);
rxcb = ATH11K_SKB_RXCB(msdu);
- dma_unmap_single(ab->dev, rxcb->paddr,
- msdu->len + skb_tailroom(msdu),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
num_buffs_reaped[mac_id]++;
@@ -3209,9 +3293,7 @@ static int ath11k_dp_rx_reap_mon_status_ring(struct ath11k_base *ab, int mac_id,
idr_remove(&rx_ring->bufs_idr, buf_id);
spin_unlock_bh(&rx_ring->idr_lock);
- dma_unmap_single(ab->dev, rxcb->paddr,
- skb->len + skb_tailroom(skb),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ab, skb, DMA_FROM_DEVICE);
dev_kfree_skb_any(skb);
pmon->buf_state = DP_MON_STATUS_REPLINISH;
@@ -3227,9 +3309,7 @@ static int ath11k_dp_rx_reap_mon_status_ring(struct ath11k_base *ab, int mac_id,
pmon->buf_state = DP_MON_STATUS_MATCH;
}
- dma_unmap_single(ab->dev, rxcb->paddr,
- skb->len + skb_tailroom(skb),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ab, skb, DMA_FROM_DEVICE);
__skb_queue_tail(skb_list, skb);
} else {
@@ -3516,11 +3596,20 @@ static int ath11k_dp_rx_h_defrag_reo_reinject(struct ath11k *ar, struct dp_rx_ti
/* change msdu len in hal rx desc */
ath11k_dp_rxdesc_set_msdu_len(ab, rx_desc, defrag_skb->len - hal_rx_desc_sz);
- paddr = dma_map_single(ab->dev, defrag_skb->data,
- defrag_skb->len + skb_tailroom(defrag_skb),
- DMA_TO_DEVICE);
- if (dma_mapping_error(ab->dev, paddr))
- return -ENOMEM;
+ if (ath11k_dp_rx_buf_is_pp(defrag_skb)) {
+ paddr = ath11k_dp_rx_pp_dma_addr(defrag_skb);
+ dma_sync_single_for_device(ab->dev, paddr,
+ defrag_skb->len +
+ skb_tailroom(defrag_skb),
+ DMA_BIDIRECTIONAL);
+ } else {
+ paddr = dma_map_single(ab->dev, defrag_skb->data,
+ defrag_skb->len +
+ skb_tailroom(defrag_skb),
+ DMA_TO_DEVICE);
+ if (dma_mapping_error(ab->dev, paddr))
+ return -ENOMEM;
+ }
spin_lock_bh(&rx_refill_ring->idr_lock);
buf_id = idr_alloc(&rx_refill_ring->bufs_idr, defrag_skb, 0,
@@ -3583,8 +3672,10 @@ static int ath11k_dp_rx_h_defrag_reo_reinject(struct ath11k *ar, struct dp_rx_ti
idr_remove(&rx_refill_ring->bufs_idr, buf_id);
spin_unlock_bh(&rx_refill_ring->idr_lock);
err_unmap_dma:
- dma_unmap_single(ab->dev, paddr, defrag_skb->len + skb_tailroom(defrag_skb),
- DMA_TO_DEVICE);
+ if (!ath11k_dp_rx_buf_is_pp(defrag_skb))
+ dma_unmap_single(ab->dev, paddr,
+ defrag_skb->len + skb_tailroom(defrag_skb),
+ DMA_TO_DEVICE);
return ret;
}
@@ -3805,7 +3896,6 @@ ath11k_dp_process_rx_err_buf(struct ath11k *ar, u32 *ring_desc, int buf_id, bool
struct ath11k_pdev_dp *dp = &ar->dp;
struct dp_rxdma_ring *rx_ring = &dp->rx_refill_buf_ring;
struct sk_buff *msdu;
- struct ath11k_skb_rxcb *rxcb;
struct hal_rx_desc *rx_desc;
u8 *hdr_status;
u16 msdu_len;
@@ -3823,10 +3913,7 @@ ath11k_dp_process_rx_err_buf(struct ath11k *ar, u32 *ring_desc, int buf_id, bool
idr_remove(&rx_ring->bufs_idr, buf_id);
spin_unlock_bh(&rx_ring->idr_lock);
- rxcb = ATH11K_SKB_RXCB(msdu);
- dma_unmap_single(ar->ab->dev, rxcb->paddr,
- msdu->len + skb_tailroom(msdu),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ar->ab, msdu, DMA_FROM_DEVICE);
if (drop) {
dev_kfree_skb_any(msdu);
@@ -4258,9 +4345,7 @@ int ath11k_dp_rx_process_wbm_err(struct ath11k_base *ab,
spin_unlock_bh(&rx_ring->idr_lock);
rxcb = ATH11K_SKB_RXCB(msdu);
- dma_unmap_single(ab->dev, rxcb->paddr,
- msdu->len + skb_tailroom(msdu),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
num_buffs_reaped[mac_id]++;
total_num_buffs_reaped++;
@@ -4328,7 +4413,6 @@ int ath11k_dp_process_rxdma_err(struct ath11k_base *ab, int mac_id, int budget)
u32 msdu_cookies[HAL_NUM_RX_MSDUS_PER_LINK_DESC];
enum hal_rx_buf_return_buf_manager rbm;
enum hal_reo_entr_rxdma_ecode rxdma_err_code;
- struct ath11k_skb_rxcb *rxcb;
struct sk_buff *skb;
struct hal_reo_entrance_ring *entr_ring;
void *desc;
@@ -4383,10 +4467,7 @@ int ath11k_dp_process_rxdma_err(struct ath11k_base *ab, int mac_id, int budget)
idr_remove(&rx_ring->bufs_idr, buf_id);
spin_unlock_bh(&rx_ring->idr_lock);
- rxcb = ATH11K_SKB_RXCB(skb);
- dma_unmap_single(ab->dev, rxcb->paddr,
- skb->len + skb_tailroom(skb),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ab, skb, DMA_FROM_DEVICE);
dev_kfree_skb_any(skb);
num_buf_freed++;
@@ -4857,10 +4938,7 @@ u32 ath11k_dp_rx_mon_mpdu_pop(struct ath11k *ar, int mac_id,
}
rxcb = ATH11K_SKB_RXCB(msdu);
if (!rxcb->unmapped) {
- dma_unmap_single(ar->ab->dev, rxcb->paddr,
- msdu->len +
- skb_tailroom(msdu),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ar->ab, msdu, DMA_FROM_DEVICE);
rxcb->unmapped = 1;
}
if (drop_mpdu) {
@@ -5489,10 +5567,7 @@ ath11k_dp_rx_full_mon_mpdu_pop(struct ath11k *ar,
rxcb = ATH11K_SKB_RXCB(msdu);
if (!rxcb->unmapped) {
- dma_unmap_single(ar->ab->dev, rxcb->paddr,
- msdu->len +
- skb_tailroom(msdu),
- DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf(ar->ab, msdu, DMA_FROM_DEVICE);
rxcb->unmapped = 1;
}
if (drop_mpdu) {
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 02/10] wifi: ath11k: replace the RX buffer IDR with a table
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 01/10] wifi: ath11k: use page_pool for the RX refill ring Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 03/10] wifi: ath11k: request only the PPDU stats TLVs it reads Julius Bairaktaris
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
Every RX buffer gets an id from its ring's IDR when it is posted and
gives it back when it is reaped, so each received frame costs an
idr_alloc() and an idr_remove(), each a radix tree walk with node
allocation and freeing under the ring lock.
The ids a ring hands out are bounded by its size, so keep them in a table
indexed by id, with a stack of the free ones. Posting a buffer pops an id
and reaping it pushes the id back, both in constant time under the same
lock, and a lookup is an array index.
The table holds twice the ring size: a ring never has more buffers posted
than entries, plus the defragmented frames reinjected into the refill
ring. Id 0 stays unused, because the refill path treats it as invalid.
An id outside the table, or one the table does not hold, finds no buffer,
as an id unknown to the IDR did.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/dp.c | 9 +-
drivers/net/wireless/ath/ath11k/dp.h | 10 +-
drivers/net/wireless/ath/ath11k/dp_rx.c | 214 ++++++++++++++++--------
3 files changed, 155 insertions(+), 78 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/dp.c b/drivers/net/wireless/ath/ath11k/dp.c
index be65d73b904b..e29a49df2a42 100644
--- a/drivers/net/wireless/ath/ath11k/dp.c
+++ b/drivers/net/wireless/ath/ath11k/dp.c
@@ -897,16 +897,13 @@ void ath11k_dp_pdev_pre_alloc(struct ath11k_base *ab)
ar = ab->pdevs[i].ar;
dp = &ar->dp;
dp->mac_id = i;
- idr_init(&dp->rx_refill_buf_ring.bufs_idr);
- spin_lock_init(&dp->rx_refill_buf_ring.idr_lock);
+ spin_lock_init(&dp->rx_refill_buf_ring.bufs_lock);
atomic_set(&dp->num_tx_pending, 0);
init_waitqueue_head(&dp->tx_empty_waitq);
for (j = 0; j < ab->hw_params.num_rxdma_per_pdev; j++) {
- idr_init(&dp->rx_mon_status_refill_ring[j].bufs_idr);
- spin_lock_init(&dp->rx_mon_status_refill_ring[j].idr_lock);
+ spin_lock_init(&dp->rx_mon_status_refill_ring[j].bufs_lock);
}
- idr_init(&dp->rxdma_mon_buf_ring.bufs_idr);
- spin_lock_init(&dp->rxdma_mon_buf_ring.idr_lock);
+ spin_lock_init(&dp->rxdma_mon_buf_ring.bufs_lock);
}
}
diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h
index 357185e45ae6..e6e05eb25692 100644
--- a/drivers/net/wireless/ath/ath11k/dp.h
+++ b/drivers/net/wireless/ath/ath11k/dp.h
@@ -73,9 +73,13 @@ struct dp_srng {
struct dp_rxdma_ring {
struct dp_srng refill_buf_ring;
struct page_pool *page_pool;
- struct idr bufs_idr;
- /* Protects bufs_idr */
- spinlock_t idr_lock;
+ /* Buffers by the id their descriptor carries, and the ids not in use */
+ struct sk_buff **bufs;
+ u32 *free_ids;
+ u32 num_free;
+ u32 num_ids;
+ /* Protects bufs and free_ids */
+ spinlock_t bufs_lock;
int bufs_max;
};
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index bad5c58dfafa..b3b8afb82a78 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -341,6 +341,68 @@ static int ath11k_dp_purge_mon_ring(struct ath11k_base *ab)
return -ETIMEDOUT;
}
+/*
+ * The ids a ring hands out, as a table indexed by id with a stack of the
+ * free ones: the descriptor cookie names the buffer directly. Id 0 is never
+ * handed out, because the refill path treats it as invalid. Callers of the
+ * id helpers hold bufs_lock.
+ */
+static int ath11k_dp_rx_bufs_init(struct dp_rxdma_ring *rx_ring)
+{
+ u32 num = rx_ring->bufs_max * 2 + 1;
+ u32 id;
+
+ rx_ring->bufs = kvcalloc(num, sizeof(*rx_ring->bufs), GFP_KERNEL);
+ rx_ring->free_ids = kvcalloc(num, sizeof(*rx_ring->free_ids),
+ GFP_KERNEL);
+ if (!rx_ring->bufs || !rx_ring->free_ids) {
+ kvfree(rx_ring->bufs);
+ kvfree(rx_ring->free_ids);
+ rx_ring->bufs = NULL;
+ rx_ring->free_ids = NULL;
+ return -ENOMEM;
+ }
+
+ rx_ring->num_ids = num;
+ rx_ring->num_free = 0;
+ for (id = num; id-- > 1;)
+ rx_ring->free_ids[rx_ring->num_free++] = id;
+
+ return 0;
+}
+
+static int ath11k_dp_rx_buf_get_id(struct dp_rxdma_ring *rx_ring,
+ struct sk_buff *skb)
+{
+ u32 id;
+
+ if (unlikely(!rx_ring->num_free))
+ return -ENOSPC;
+
+ id = rx_ring->free_ids[--rx_ring->num_free];
+ rx_ring->bufs[id] = skb;
+
+ return id;
+}
+
+static struct sk_buff *ath11k_dp_rx_buf_lookup(struct dp_rxdma_ring *rx_ring,
+ u32 id)
+{
+ if (unlikely(id >= rx_ring->num_ids))
+ return NULL;
+
+ return rx_ring->bufs[id];
+}
+
+static void ath11k_dp_rx_buf_put_id(struct dp_rxdma_ring *rx_ring, u32 id)
+{
+ if (unlikely(id >= rx_ring->num_ids || !rx_ring->bufs[id]))
+ return;
+
+ rx_ring->bufs[id] = NULL;
+ rx_ring->free_ids[rx_ring->num_free++] = id;
+}
+
static bool ath11k_dp_rx_buf_is_pp(struct sk_buff *skb)
{
return skb->pp_recycle && skb->head_frag;
@@ -449,10 +511,9 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
goto fail_free_skb;
}
- spin_lock_bh(&rx_ring->idr_lock);
- buf_id = idr_alloc(&rx_ring->bufs_idr, skb, 1,
- (rx_ring->bufs_max * 3) + 1, GFP_ATOMIC);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ buf_id = ath11k_dp_rx_buf_get_id(rx_ring, skb);
+ spin_unlock_bh(&rx_ring->bufs_lock);
if (buf_id <= 0)
goto fail_dma_unmap;
@@ -477,9 +538,9 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
return req_entries - num_remain;
fail_idr_remove:
- spin_lock_bh(&rx_ring->idr_lock);
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
fail_dma_unmap:
if (!rx_ring->page_pool)
dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
@@ -500,9 +561,13 @@ static int ath11k_dp_rxdma_buf_ring_free(struct ath11k *ar,
struct sk_buff *skb;
int buf_id;
- spin_lock_bh(&rx_ring->idr_lock);
- idr_for_each_entry(&rx_ring->bufs_idr, skb, buf_id) {
- idr_remove(&rx_ring->bufs_idr, buf_id);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ for (buf_id = 0; buf_id < rx_ring->num_ids; buf_id++) {
+ skb = rx_ring->bufs[buf_id];
+ if (!skb)
+ continue;
+
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
/* TODO: Understand where internal driver does this dma_unmap
* of rxdma_buffer.
*/
@@ -510,8 +575,13 @@ static int ath11k_dp_rxdma_buf_ring_free(struct ath11k *ar,
dev_kfree_skb_any(skb);
}
- idr_destroy(&rx_ring->bufs_idr);
- spin_unlock_bh(&rx_ring->idr_lock);
+ kvfree(rx_ring->bufs);
+ kvfree(rx_ring->free_ids);
+ rx_ring->bufs = NULL;
+ rx_ring->free_ids = NULL;
+ rx_ring->num_ids = 0;
+ rx_ring->num_free = 0;
+ spin_unlock_bh(&rx_ring->bufs_lock);
if (rx_ring->page_pool) {
page_pool_destroy(rx_ring->page_pool);
@@ -571,6 +641,14 @@ static int ath11k_dp_rxdma_ring_buf_setup(struct ath11k *ar,
}
rx_ring->bufs_max = num_entries;
+ if (ath11k_dp_rx_bufs_init(rx_ring)) {
+ if (rx_ring->page_pool) {
+ page_pool_destroy(rx_ring->page_pool);
+ rx_ring->page_pool = NULL;
+ }
+ return -ENOMEM;
+ }
+
ath11k_dp_rxbufs_replenish(ar->ab, dp->mac_id, rx_ring, num_entries,
ar->ab->hw_params.hal_params->rx_buf_rbm);
return 0;
@@ -2848,17 +2926,17 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
ar = ab->pdevs[mac_id].ar;
rx_ring = &ar->dp.rx_refill_buf_ring;
- spin_lock_bh(&rx_ring->idr_lock);
- msdu = idr_find(&rx_ring->bufs_idr, buf_id);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ msdu = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
if (unlikely(!msdu)) {
ath11k_warn(ab, "frame rx with invalid buf_id %d\n",
buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_unlock_bh(&rx_ring->bufs_lock);
continue;
}
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
rxcb = ATH11K_SKB_RXCB(msdu);
ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
@@ -3039,10 +3117,9 @@ static struct sk_buff *ath11k_dp_rx_alloc_mon_status_buf(struct ath11k_base *ab,
if (unlikely(dma_mapping_error(ab->dev, paddr)))
goto fail_free_skb;
- spin_lock_bh(&rx_ring->idr_lock);
- *buf_id = idr_alloc(&rx_ring->bufs_idr, skb, 0,
- rx_ring->bufs_max, GFP_ATOMIC);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ *buf_id = ath11k_dp_rx_buf_get_id(rx_ring, skb);
+ spin_unlock_bh(&rx_ring->bufs_lock);
if (*buf_id < 0)
goto fail_dma_unmap;
@@ -3111,9 +3188,9 @@ int ath11k_dp_rx_mon_status_bufs_replenish(struct ath11k_base *ab, int mac_id,
return req_entries - num_remain;
fail_desc_get:
- spin_lock_bh(&rx_ring->idr_lock);
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
DMA_FROM_DEVICE);
dev_kfree_skb_any(skb);
@@ -3181,9 +3258,9 @@ ath11k_dp_rx_mon_buf_done(struct ath11k_base *ab, struct hal_srng *srng,
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, cookie);
- spin_lock_bh(&rx_ring->idr_lock);
- skb = idr_find(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ skb = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
if (!skb)
return DP_MON_STATUS_NO_DMA;
@@ -3245,9 +3322,9 @@ static int ath11k_dp_rx_reap_mon_status_ring(struct ath11k_base *ab, int mac_id,
if (paddr) {
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, cookie);
- spin_lock_bh(&rx_ring->idr_lock);
- skb = idr_find(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ skb = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
if (!skb) {
ath11k_warn(ab, "rx monitor status with invalid buf_id %d\n",
@@ -3289,9 +3366,9 @@ static int ath11k_dp_rx_reap_mon_status_ring(struct ath11k_base *ab, int mac_id,
if (reap_status == DP_MON_STATUS_NO_DMA)
continue;
- spin_lock_bh(&rx_ring->idr_lock);
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
ath11k_dp_rx_unmap_buf(ab, skb, DMA_FROM_DEVICE);
@@ -3300,9 +3377,9 @@ static int ath11k_dp_rx_reap_mon_status_ring(struct ath11k_base *ab, int mac_id,
goto move_next;
}
- spin_lock_bh(&rx_ring->idr_lock);
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
if (ab->hw_params.full_monitor_mode) {
ath11k_dp_rx_mon_update_status_buf_state(pmon, tlv);
if (paddr == pmon->mon_status_paddr)
@@ -3611,10 +3688,9 @@ static int ath11k_dp_rx_h_defrag_reo_reinject(struct ath11k *ar, struct dp_rx_ti
return -ENOMEM;
}
- spin_lock_bh(&rx_refill_ring->idr_lock);
- buf_id = idr_alloc(&rx_refill_ring->bufs_idr, defrag_skb, 0,
- rx_refill_ring->bufs_max * 3, GFP_ATOMIC);
- spin_unlock_bh(&rx_refill_ring->idr_lock);
+ spin_lock_bh(&rx_refill_ring->bufs_lock);
+ buf_id = ath11k_dp_rx_buf_get_id(rx_refill_ring, defrag_skb);
+ spin_unlock_bh(&rx_refill_ring->bufs_lock);
if (buf_id < 0) {
ret = -ENOMEM;
goto err_unmap_dma;
@@ -3668,9 +3744,9 @@ static int ath11k_dp_rx_h_defrag_reo_reinject(struct ath11k *ar, struct dp_rx_ti
return 0;
err_free_idr:
- spin_lock_bh(&rx_refill_ring->idr_lock);
- idr_remove(&rx_refill_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_refill_ring->idr_lock);
+ spin_lock_bh(&rx_refill_ring->bufs_lock);
+ ath11k_dp_rx_buf_put_id(rx_refill_ring, buf_id);
+ spin_unlock_bh(&rx_refill_ring->bufs_lock);
err_unmap_dma:
if (!ath11k_dp_rx_buf_is_pp(defrag_skb))
dma_unmap_single(ab->dev, paddr,
@@ -3901,17 +3977,17 @@ ath11k_dp_process_rx_err_buf(struct ath11k *ar, u32 *ring_desc, int buf_id, bool
u16 msdu_len;
u32 hal_rx_desc_sz = ar->ab->hw_params.hal_desc_sz;
- spin_lock_bh(&rx_ring->idr_lock);
- msdu = idr_find(&rx_ring->bufs_idr, buf_id);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ msdu = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
if (!msdu) {
ath11k_warn(ar->ab, "rx err buf with invalid buf_id %d\n",
buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_unlock_bh(&rx_ring->bufs_lock);
return -EINVAL;
}
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
ath11k_dp_rx_unmap_buf(ar->ab, msdu, DMA_FROM_DEVICE);
@@ -4332,17 +4408,17 @@ int ath11k_dp_rx_process_wbm_err(struct ath11k_base *ab,
ar = ab->pdevs[mac_id].ar;
rx_ring = &ar->dp.rx_refill_buf_ring;
- spin_lock_bh(&rx_ring->idr_lock);
- msdu = idr_find(&rx_ring->bufs_idr, buf_id);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ msdu = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
if (!msdu) {
ath11k_warn(ab, "frame rx with invalid buf_id %d pdev %d\n",
buf_id, mac_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_unlock_bh(&rx_ring->bufs_lock);
continue;
}
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
rxcb = ATH11K_SKB_RXCB(msdu);
ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
@@ -4455,17 +4531,17 @@ int ath11k_dp_process_rxdma_err(struct ath11k_base *ab, int mac_id, int budget)
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID,
msdu_cookies[i]);
- spin_lock_bh(&rx_ring->idr_lock);
- skb = idr_find(&rx_ring->bufs_idr, buf_id);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ skb = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
if (!skb) {
ath11k_warn(ab, "rxdma error with invalid buf_id %d\n",
buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_unlock_bh(&rx_ring->bufs_lock);
continue;
}
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
ath11k_dp_rx_unmap_buf(ab, skb, DMA_FROM_DEVICE);
dev_kfree_skb_any(skb);
@@ -4928,9 +5004,9 @@ u32 ath11k_dp_rx_mon_mpdu_pop(struct ath11k *ar, int mac_id,
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID,
msdu_list.sw_cookie[i]);
- spin_lock_bh(&rx_ring->idr_lock);
- msdu = idr_find(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ msdu = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
if (!msdu) {
ath11k_dbg(ar->ab, ATH11K_DBG_DATA,
"msdu_pop: invalid buf_id %d\n", buf_id);
@@ -4997,9 +5073,9 @@ u32 ath11k_dp_rx_mon_mpdu_pop(struct ath11k *ar, int mac_id,
next_msdu:
pmon->mon_last_buf_cookie = msdu_list.sw_cookie[i];
rx_bufs_used++;
- spin_lock_bh(&rx_ring->idr_lock);
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
}
ath11k_hal_rx_buf_addr_info_set(rx_link_buf_info, paddr, sw_cookie, rbm);
@@ -5553,17 +5629,17 @@ ath11k_dp_rx_full_mon_mpdu_pop(struct ath11k *ar,
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID,
msdu_list.sw_cookie[i]);
- spin_lock_bh(&rx_ring->idr_lock);
- msdu = idr_find(&rx_ring->bufs_idr, buf_id);
+ spin_lock_bh(&rx_ring->bufs_lock);
+ msdu = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
if (!msdu) {
ath11k_dbg(ar->ab, ATH11K_DBG_DATA,
"full mon msdu_pop: invalid buf_id %d\n",
buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ spin_unlock_bh(&rx_ring->bufs_lock);
goto next_msdu;
}
- idr_remove(&rx_ring->bufs_idr, buf_id);
- spin_unlock_bh(&rx_ring->idr_lock);
+ ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
+ spin_unlock_bh(&rx_ring->bufs_lock);
rxcb = ATH11K_SKB_RXCB(msdu);
if (!rxcb->unmapped) {
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 03/10] wifi: ath11k: request only the PPDU stats TLVs it reads
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 01/10] wifi: ath11k: use page_pool for the RX refill ring Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 02/10] wifi: ath11k: replace the RX buffer IDR with a table Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 04/10] wifi: ath11k: set the skb hash of a received frame from the hardware Julius Bairaktaris
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The driver asks the firmware for eight PPDU stats TLVs on every PPDU, but
ath11k_htt_tlv_ppdu_stats_parse() keeps four of them: the common TLV (PPDU
airtime), the user rate TLV (rate, NSS and bandwidth of each user, which
the station rate and the airtime accounting use), the user completion
common TLV (MPDUs tried and succeeded) and the ack/BA status TLV (acked
bytes and MSDUs, TID). The user common, scheduler command status, flush
and user array TLVs are parsed by nothing, yet the firmware builds them
and the host walks them for every PPDU of every station.
Request the four the driver reads. The full pktlog, the extended TX
statistics and the monitor interface keep the default set and the lite
pktlog its own set, as before, so the mask is recomputed when any of them
is switched on or off.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/debugfs.c | 15 ++++++++--
drivers/net/wireless/ath/ath11k/debugfs.h | 10 +++++++
drivers/net/wireless/ath/ath11k/dp.h | 9 ++++++
drivers/net/wireless/ath/ath11k/dp_tx.c | 34 +++++++++++++++++++++++
drivers/net/wireless/ath/ath11k/dp_tx.h | 1 +
drivers/net/wireless/ath/ath11k/mac.c | 13 +++++++--
6 files changed, 77 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/debugfs.c b/drivers/net/wireless/ath/ath11k/debugfs.c
index 70922612d3fb..b936101d6fa5 100644
--- a/drivers/net/wireless/ath/ath11k/debugfs.c
+++ b/drivers/net/wireless/ath/ath11k/debugfs.c
@@ -460,7 +460,9 @@ static ssize_t ath11k_write_enable_extd_tx_stats(struct file *file,
}
ar->debug.extd_tx_stats = filter;
- ret = count;
+ ret = ath11k_dp_tx_htt_ppdu_stats_update(ar);
+ if (!ret)
+ ret = count;
out:
mutex_unlock(&ar->conf_mutex);
@@ -1010,6 +1012,13 @@ static ssize_t ath11k_write_pktlog_filter(struct file *file,
HTT_RX_FILTER_TLV_FLAGS_MPDU_START)
if (mode == ATH11K_PKTLOG_MODE_FULL) {
+ ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
+ HTT_PPDU_STATS_TAG_DEFAULT);
+ if (ret) {
+ ath11k_err(ar->ab, "failed to enable pktlog full: %d\n", ret);
+ goto out;
+ }
+
rx_filter = HTT_RX_FILTER_TLV_LITE_MODE |
HTT_RX_FILTER_TLV_FLAGS_MSDU_START |
HTT_RX_FILTER_TLV_FLAGS_MSDU_END |
@@ -1032,8 +1041,8 @@ static ssize_t ath11k_write_pktlog_filter(struct file *file,
tlv_filter = ath11k_mac_mon_status_filter_default;
rx_filter = tlv_filter.rx_filter;
- ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
- HTT_PPDU_STATS_TAG_DEFAULT);
+ ar->debug.pktlog_mode = mode;
+ ret = ath11k_dp_tx_htt_ppdu_stats_update(ar);
if (ret) {
ath11k_err(ar->ab, "failed to send htt ppdu stats req: %d\n",
ret);
diff --git a/drivers/net/wireless/ath/ath11k/debugfs.h b/drivers/net/wireless/ath/ath11k/debugfs.h
index 859071938a65..4bec01a85eae 100644
--- a/drivers/net/wireless/ath/ath11k/debugfs.h
+++ b/drivers/net/wireless/ath/ath11k/debugfs.h
@@ -279,6 +279,11 @@ static inline bool ath11k_debugfs_is_pktlog_lite_mode_enabled(struct ath11k *ar)
return (ar->debug.pktlog_mode == ATH11K_PKTLOG_MODE_LITE);
}
+static inline bool ath11k_debugfs_is_pktlog_enabled(struct ath11k *ar)
+{
+ return ar->debug.pktlog_mode;
+}
+
static inline bool ath11k_debugfs_is_pktlog_rx_stats_enabled(struct ath11k *ar)
{
return (!ar->debug.pktlog_peer_valid && ar->debug.pktlog_mode);
@@ -364,6 +369,11 @@ static inline bool ath11k_debugfs_is_pktlog_lite_mode_enabled(struct ath11k *ar)
return false;
}
+static inline bool ath11k_debugfs_is_pktlog_enabled(struct ath11k *ar)
+{
+ return false;
+}
+
static inline bool ath11k_debugfs_is_pktlog_rx_stats_enabled(struct ath11k *ar)
{
return false;
diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h
index e6e05eb25692..5e973c337cb2 100644
--- a/drivers/net/wireless/ath/ath11k/dp.h
+++ b/drivers/net/wireless/ath/ath11k/dp.h
@@ -595,6 +595,15 @@ enum htt_ppdu_stats_tag_type {
| BIT(HTT_PPDU_STATS_TAG_USR_COMPLTN_FLUSH) \
| BIT(HTT_PPDU_STATS_TAG_USR_COMMON_ARRAY))
+/*
+ * The TLVs ath11k_htt_tlv_ppdu_stats_parse() keeps: the PPDU airtime, the
+ * rate of each user, the retry counts and the acked bytes.
+ */
+#define HTT_PPDU_STATS_TAG_USED (BIT(HTT_PPDU_STATS_TAG_COMMON) \
+ | BIT(HTT_PPDU_STATS_TAG_USR_RATE) \
+ | BIT(HTT_PPDU_STATS_TAG_USR_COMPLTN_COMMON) \
+ | BIT(HTT_PPDU_STATS_TAG_USR_COMPLTN_ACK_BA_STATUS))
+
#define HTT_PPDU_STATS_TAG_PKTLOG (BIT(HTT_PPDU_STATS_TAG_USR_MPDU_ENQ_BITMAP_64) | \
BIT(HTT_PPDU_STATS_TAG_USR_MPDU_ENQ_BITMAP_256) | \
BIT(HTT_PPDU_STATS_TAG_USR_COMPLTN_BA_BITMAP_64) | \
diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c
index cac970c92806..9e21c7c3dba2 100644
--- a/drivers/net/wireless/ath/ath11k/dp_tx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_tx.c
@@ -1033,6 +1033,40 @@ int ath11k_dp_tx_htt_h2t_ver_req_msg(struct ath11k_base *ab)
return 0;
}
+/*
+ * The TLVs the driver does not parse (user common, scheduler command status,
+ * flush, user array) go only to pktlog and the trace point. The pktlog lite
+ * mode asks for its own set, and the full pktlog, the monitor and the
+ * extended statistics debugfs file keep the whole default set.
+ */
+static u32 ath11k_dp_tx_htt_ppdu_stats_mask(struct ath11k *ar)
+{
+ if (ath11k_debugfs_is_pktlog_lite_mode_enabled(ar))
+ return HTT_PPDU_STATS_TAG_PKTLOG;
+
+ if (ath11k_debugfs_is_extd_tx_stats_enabled(ar) ||
+ ath11k_debugfs_is_pktlog_enabled(ar) ||
+ test_bit(ATH11K_FLAG_MONITOR_STARTED, &ar->monitor_flags))
+ return HTT_PPDU_STATS_TAG_DEFAULT;
+
+ return HTT_PPDU_STATS_TAG_USED;
+}
+
+/**
+ * ath11k_dp_tx_htt_ppdu_stats_update() - request the PPDU stats TLVs in use
+ * @ar: the radio, whose conf_mutex the caller holds
+ *
+ * Asks the firmware for the PPDU stats TLVs that the driver and the enabled
+ * debug features read, and only those.
+ *
+ * Return: 0 on success, or the error of the HTT request.
+ */
+int ath11k_dp_tx_htt_ppdu_stats_update(struct ath11k *ar)
+{
+ return ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
+ ath11k_dp_tx_htt_ppdu_stats_mask(ar));
+}
+
int ath11k_dp_tx_htt_h2t_ppdu_stats_req(struct ath11k *ar, u32 mask)
{
struct ath11k_base *ab = ar->ab;
diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.h b/drivers/net/wireless/ath/ath11k/dp_tx.h
index 9303b5ba6e01..934c9ab6acf5 100644
--- a/drivers/net/wireless/ath/ath11k/dp_tx.h
+++ b/drivers/net/wireless/ath/ath11k/dp_tx.h
@@ -29,6 +29,7 @@ int ath11k_dp_tx_send_reo_cmd(struct ath11k_base *ab, struct dp_rx_tid *rx_tid,
enum hal_reo_cmd_status));
int ath11k_dp_tx_htt_h2t_ppdu_stats_req(struct ath11k *ar, u32 mask);
+int ath11k_dp_tx_htt_ppdu_stats_update(struct ath11k *ar);
int
ath11k_dp_tx_htt_h2t_ext_stats_req(struct ath11k *ar, u8 type,
struct htt_ext_stats_cfg_params *cfg_params,
diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
index 1a237adaa37d..79d5cf88f3b7 100644
--- a/drivers/net/wireless/ath/ath11k/mac.c
+++ b/drivers/net/wireless/ath/ath11k/mac.c
@@ -1195,6 +1195,11 @@ static int ath11k_mac_monitor_start(struct ath11k *ar)
return ret;
}
+ ret = ath11k_dp_tx_htt_ppdu_stats_update(ar);
+ if (ret)
+ ath11k_warn(ar->ab, "failed to req ppdu stats for monitor: %d\n",
+ ret);
+
ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "monitor started\n");
return 0;
@@ -1225,6 +1230,11 @@ static int ath11k_mac_monitor_stop(struct ath11k *ar)
return ret;
}
+ ret = ath11k_dp_tx_htt_ppdu_stats_update(ar);
+ if (ret)
+ ath11k_warn(ar->ab, "failed to req ppdu stats for monitor: %d\n",
+ ret);
+
ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "monitor stopped ret %d\n", ret);
return 0;
@@ -6694,8 +6704,7 @@ static int ath11k_mac_op_start(struct ieee80211_hw *hw)
goto err;
}
- ret = ath11k_dp_tx_htt_h2t_ppdu_stats_req(ar,
- HTT_PPDU_STATS_TAG_DEFAULT);
+ ret = ath11k_dp_tx_htt_ppdu_stats_update(ar);
if (ret) {
ath11k_err(ab, "failed to req ppdu stats: %d\n", ret);
goto err;
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 04/10] wifi: ath11k: set the skb hash of a received frame from the hardware
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
` (2 preceding siblings ...)
2026-11-23 13:41 ` [PATCH ath-next v1 03/10] wifi: ath11k: request only the PPDU stats TLVs it reads Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 05/10] wifi: ath11k: sync a cached ring's new entries once per head read Julius Bairaktaris
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
mac80211 picks the TXQ flow of a frame by skb_get_hash() in
fq_flow_idx(), and RPS and the queueing disciplines on the output device
do the same. ath11k never sets the hash, so every received frame that is
forwarded or steered is dissected again, though the receive engine has
already hashed its 5-tuple (flow_id_toeplitz in the MSDU start TLV, with
the seed ath11k_wmi_pdev_lro_cfg() sets at random).
Use that hash as an L4 hash for a frame whose descriptor says it is TCP
or UDP, not an IP fragment, and with the fixed IP header and the TCP/UDP
header parsed. A zero hash is not used. A boot random value is mixed into
it, so that it is not a function of the packet alone and a station
cannot choose the flow queue that a flow of another station shares.
The field is at the same place in the MSDU start TLV of every chip
family; read it, and the word with the flags, through two new hw_ops.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/dp_rx.c | 36 +++++++++++++++++++++++++
drivers/net/wireless/ath/ath11k/hw.c | 22 +++++++++++++++
drivers/net/wireless/ath/ath11k/hw.h | 1 +
3 files changed, 59 insertions(+)
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index b3b8afb82a78..b027b76ea3f3 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -6,7 +6,9 @@
#include <linux/fips.h>
#include <linux/ieee80211.h>
+#include <linux/jhash.h>
#include <linux/kernel.h>
+#include <linux/net.h>
#include <linux/skbuff.h>
#include <net/page_pool/helpers.h>
#include "core.h"
@@ -2057,6 +2059,39 @@ static void ath11k_dp_rx_h_csum_offload(struct ath11k *ar, struct sk_buff *msdu)
msdu->ip_summed = CHECKSUM_UNNECESSARY;
}
+static u32 ath11k_rx_hash_seed __read_mostly;
+
+/*
+ * The receive engine hashes the 5-tuple of a TCP or UDP frame whose IP and L4
+ * headers it parsed. mac80211's queue selection and the queueing disciplines
+ * would otherwise dissect the frame again for the same hash.
+ */
+static void ath11k_dp_rx_h_hash(struct ath11k *ar, struct sk_buff *msdu)
+{
+ const struct ath11k_hw_ops *ops = ar->ab->hw_params.hw_ops;
+ struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu);
+ u32 info2, hash;
+
+ info2 = ops->rx_desc_get_msdu_start_info2(rxcb->rx_desc);
+ if (!(info2 & (RX_MSDU_START_INFO2_TCP | RX_MSDU_START_INFO2_UDP)) ||
+ (info2 & RX_MSDU_START_INFO2_IP_FRAG) ||
+ !(info2 & RX_MSDU_START_INFO2_IP_FIXED_HDR_VALID) ||
+ !(info2 & RX_MSDU_START_INFO2_IP_TCP_UDP_HDR_VALID))
+ return;
+
+ hash = ops->rx_desc_get_flow_id_toeplitz(rxcb->rx_desc);
+ if (!hash)
+ return;
+
+ /*
+ * Make the hash differ per boot, so that a station cannot aim
+ * collisions at the queues of the others.
+ */
+ net_get_random_once(&ath11k_rx_hash_seed, sizeof(ath11k_rx_hash_seed));
+ skb_set_hash(msdu, jhash_1word(hash, ath11k_rx_hash_seed),
+ PKT_HASH_TYPE_L4);
+}
+
int ath11k_dp_rx_crypto_mic_len(struct ath11k *ar, enum hal_encrypt_type enctype)
{
switch (enctype) {
@@ -2524,6 +2559,7 @@ static int ath11k_dp_rx_h_mpdu(struct ath11k *ar,
}
ath11k_dp_rx_h_csum_offload(ar, msdu);
+ ath11k_dp_rx_h_hash(ar, msdu);
ath11k_dp_rx_h_undecap(ar, msdu, rx_desc,
enctype, rx_status, is_decrypted);
diff --git a/drivers/net/wireless/ath/ath11k/hw.c b/drivers/net/wireless/ath/ath11k/hw.c
index 096366b85849..40a9fae52e84 100644
--- a/drivers/net/wireless/ath/ath11k/hw.c
+++ b/drivers/net/wireless/ath/ath11k/hw.c
@@ -283,6 +283,11 @@ static u8 ath11k_hw_ipq8074_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc)
__le32_to_cpu(desc->u.ipq8074.msdu_start.info2));
}
+static u32 ath11k_hw_ipq8074_rx_desc_get_flow_id_toeplitz(struct hal_rx_desc *desc)
+{
+ return __le32_to_cpu(desc->u.ipq8074.msdu_start.flow_id_toeplitz);
+}
+
static bool ath11k_hw_ipq8074_rx_desc_get_ldpc_support(struct hal_rx_desc *desc)
{
return FIELD_GET(RX_MSDU_START_INFO2_LDPC,
@@ -465,6 +470,11 @@ static u8 ath11k_hw_qcn9074_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc)
__le32_to_cpu(desc->u.qcn9074.msdu_start.info2));
}
+static u32 ath11k_hw_qcn9074_rx_desc_get_flow_id_toeplitz(struct hal_rx_desc *desc)
+{
+ return __le32_to_cpu(desc->u.qcn9074.msdu_start.flow_id_toeplitz);
+}
+
static bool ath11k_hw_qcn9074_rx_desc_get_ldpc_support(struct hal_rx_desc *desc)
{
return FIELD_GET(RX_MSDU_START_INFO2_LDPC,
@@ -647,6 +657,11 @@ static u8 ath11k_hw_wcn6855_rx_desc_get_mesh_ctl(struct hal_rx_desc *desc)
__le32_to_cpu(desc->u.wcn6855.msdu_start.info2));
}
+static u32 ath11k_hw_wcn6855_rx_desc_get_flow_id_toeplitz(struct hal_rx_desc *desc)
+{
+ return __le32_to_cpu(desc->u.wcn6855.msdu_start.flow_id_toeplitz);
+}
+
static bool ath11k_hw_wcn6855_rx_desc_get_mpdu_seq_ctl_vld(struct hal_rx_desc *desc)
{
return !!FIELD_GET(RX_MPDU_START_INFO1_MPDU_SEQ_CTRL_VALID,
@@ -930,6 +945,7 @@ const struct ath11k_hw_ops ipq8074_ops = {
.rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type,
.rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl,
.rx_desc_get_msdu_start_info2 = ath11k_hw_ipq8074_rx_desc_get_msdu_start_info2,
+ .rx_desc_get_flow_id_toeplitz = ath11k_hw_ipq8074_rx_desc_get_flow_id_toeplitz,
.rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support,
.rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld,
.rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid,
@@ -971,6 +987,7 @@ const struct ath11k_hw_ops ipq6018_ops = {
.rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type,
.rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl,
.rx_desc_get_msdu_start_info2 = ath11k_hw_ipq8074_rx_desc_get_msdu_start_info2,
+ .rx_desc_get_flow_id_toeplitz = ath11k_hw_ipq8074_rx_desc_get_flow_id_toeplitz,
.rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support,
.rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld,
.rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid,
@@ -1012,6 +1029,7 @@ const struct ath11k_hw_ops qca6390_ops = {
.rx_desc_get_decap_type = ath11k_hw_ipq8074_rx_desc_get_decap_type,
.rx_desc_get_mesh_ctl = ath11k_hw_ipq8074_rx_desc_get_mesh_ctl,
.rx_desc_get_msdu_start_info2 = ath11k_hw_ipq8074_rx_desc_get_msdu_start_info2,
+ .rx_desc_get_flow_id_toeplitz = ath11k_hw_ipq8074_rx_desc_get_flow_id_toeplitz,
.rx_desc_get_ldpc_support = ath11k_hw_ipq8074_rx_desc_get_ldpc_support,
.rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_ipq8074_rx_desc_get_mpdu_seq_ctl_vld,
.rx_desc_get_mpdu_fc_valid = ath11k_hw_ipq8074_rx_desc_get_mpdu_fc_valid,
@@ -1053,6 +1071,7 @@ const struct ath11k_hw_ops qcn9074_ops = {
.rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type,
.rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl,
.rx_desc_get_msdu_start_info2 = ath11k_hw_qcn9074_rx_desc_get_msdu_start_info2,
+ .rx_desc_get_flow_id_toeplitz = ath11k_hw_qcn9074_rx_desc_get_flow_id_toeplitz,
.rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support,
.rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld,
.rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid,
@@ -1094,6 +1113,7 @@ const struct ath11k_hw_ops wcn6855_ops = {
.rx_desc_get_decap_type = ath11k_hw_wcn6855_rx_desc_get_decap_type,
.rx_desc_get_mesh_ctl = ath11k_hw_wcn6855_rx_desc_get_mesh_ctl,
.rx_desc_get_msdu_start_info2 = ath11k_hw_wcn6855_rx_desc_get_msdu_start_info2,
+ .rx_desc_get_flow_id_toeplitz = ath11k_hw_wcn6855_rx_desc_get_flow_id_toeplitz,
.rx_desc_get_ldpc_support = ath11k_hw_wcn6855_rx_desc_get_ldpc_support,
.rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_wcn6855_rx_desc_get_mpdu_seq_ctl_vld,
.rx_desc_get_mpdu_fc_valid = ath11k_hw_wcn6855_rx_desc_get_mpdu_fc_valid,
@@ -1135,6 +1155,7 @@ const struct ath11k_hw_ops wcn6750_ops = {
.rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type,
.rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl,
.rx_desc_get_msdu_start_info2 = ath11k_hw_qcn9074_rx_desc_get_msdu_start_info2,
+ .rx_desc_get_flow_id_toeplitz = ath11k_hw_qcn9074_rx_desc_get_flow_id_toeplitz,
.rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support,
.rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld,
.rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid,
@@ -1177,6 +1198,7 @@ const struct ath11k_hw_ops ipq5018_ops = {
.rx_desc_get_decap_type = ath11k_hw_qcn9074_rx_desc_get_decap_type,
.rx_desc_get_mesh_ctl = ath11k_hw_qcn9074_rx_desc_get_mesh_ctl,
.rx_desc_get_msdu_start_info2 = ath11k_hw_qcn9074_rx_desc_get_msdu_start_info2,
+ .rx_desc_get_flow_id_toeplitz = ath11k_hw_qcn9074_rx_desc_get_flow_id_toeplitz,
.rx_desc_get_ldpc_support = ath11k_hw_qcn9074_rx_desc_get_ldpc_support,
.rx_desc_get_mpdu_seq_ctl_vld = ath11k_hw_qcn9074_rx_desc_get_mpdu_seq_ctl_vld,
.rx_desc_get_mpdu_fc_valid = ath11k_hw_qcn9074_rx_desc_get_mpdu_fc_valid,
diff --git a/drivers/net/wireless/ath/ath11k/hw.h b/drivers/net/wireless/ath/ath11k/hw.h
index 8725e119707b..925785c9f688 100644
--- a/drivers/net/wireless/ath/ath11k/hw.h
+++ b/drivers/net/wireless/ath/ath11k/hw.h
@@ -250,6 +250,7 @@ struct ath11k_hw_ops {
u8 (*rx_desc_get_decap_type)(struct hal_rx_desc *desc);
u8 (*rx_desc_get_mesh_ctl)(struct hal_rx_desc *desc);
u32 (*rx_desc_get_msdu_start_info2)(struct hal_rx_desc *desc);
+ u32 (*rx_desc_get_flow_id_toeplitz)(struct hal_rx_desc *desc);
bool (*rx_desc_get_ldpc_support)(struct hal_rx_desc *desc);
bool (*rx_desc_get_mpdu_seq_ctl_vld)(struct hal_rx_desc *desc);
bool (*rx_desc_get_mpdu_fc_valid)(struct hal_rx_desc *desc);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 05/10] wifi: ath11k: sync a cached ring's new entries once per head read
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
` (3 preceding siblings ...)
2026-11-23 13:41 ` [PATCH ath-next v1 04/10] wifi: ath11k: set the skb hash of a received frame from the hardware Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 06/10] wifi: ath11k: prefetch the buffers of the REO entries ahead of their reap Julius Bairaktaris
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The REO destination and TX completion rings are cacheable on the chips
with alloc_cacheable_memory (IPQ8074, IPQ6018, QCN9074, IPQ5018). The CPU
takes each entry from the device with a dma_sync_single_for_cpu() of its
32 bytes when the entry before it is handed out, and prefetches it then.
That is a call into the DMA layer and a cache invalidation with its
barrier for every frame received and every frame completed, and a
prefetch issued a few dozen instructions before the load: in a profile
of bridged downlink at 900 Mbit/s (IPQ8074, one run) the instruction
after the first load of a completion entry in
ath11k_dp_tx_completion_handler() takes 0.70 % of all samples.
Invalidate the entries where they become the CPU's, when a read of the
head pointer moves cached_hp: the whole range from the old head to the
new one, in one call or two where it wraps, in access_begin and in
ath11k_hal_srng_dst_num_free(), the two places that move it. An entry is
read only below cached_hp, so each is invalidated once after the device
wrote it, and a line the CPU loaded earlier, by a prefetch or
speculatively, is discarded before its entries are read: the guarantee
the per-entry sync gave. The range is clamped to the ring. Prefetch the
entries two cache lines ahead, which may run past the head: such a line
is discarded again when the head exposes it.
ath11k_hal_srng_dst_num_free() now reads the head with READ_ONCE() and
orders the entry reads after it with dma_rmb(), as access_begin does.
Rings in coherent memory are not touched.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/hal.c | 86 ++++++++++++++++++---------
1 file changed, 57 insertions(+), 29 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/hal.c b/drivers/net/wireless/ath/ath11k/hal.c
index 98bd9e3f0aae..e5c35647a136 100644
--- a/drivers/net/wireless/ath/ath11k/hal.c
+++ b/drivers/net/wireless/ath/ath11k/hal.c
@@ -627,34 +627,54 @@ u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng)
return NULL;
}
-static u32 *ath11k_hal_srng_dst_peek_with_dma(struct ath11k_base *ab,
- struct hal_srng *srng, dma_addr_t *paddr)
+/*
+ * Hands the CPU the entries of a cached destination ring from word @from up
+ * to word @to, which the head pointer the caller just read shows the device
+ * has written. Every entry the ring hands out passes through here once, after
+ * the head pointer that exposed it was read, so a line of the ring that the
+ * CPU loaded before, by a prefetch or speculatively, is discarded before it is
+ * read. The range is clamped to the ring, whatever the head pointer holds.
+ */
+static void ath11k_hal_srng_dst_sync(struct ath11k_base *ab,
+ struct hal_srng *srng, u32 from, u32 to)
{
- lockdep_assert_held(&srng->lock);
+ u32 size = srng->ring_size;
- if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) {
- *paddr = srng->ring_base_paddr +
- sizeof(*srng->ring_base_vaddr) * srng->u.dst_ring.tp;
- return srng->ring_base_vaddr + srng->u.dst_ring.tp;
- }
+ if (!(srng->flags & HAL_SRNG_FLAGS_CACHED) || from >= size)
+ return;
- return NULL;
+ to = min(to, size);
+ if (to < from) {
+ dma_sync_single_for_cpu(ab->dev, srng->ring_base_paddr +
+ from * sizeof(u32),
+ (size - from) * sizeof(u32),
+ DMA_FROM_DEVICE);
+ from = 0;
+ }
+ if (to > from)
+ dma_sync_single_for_cpu(ab->dev, srng->ring_base_paddr +
+ from * sizeof(u32),
+ (to - from) * sizeof(u32),
+ DMA_FROM_DEVICE);
}
-static void ath11k_hal_srng_prefetch_desc(struct ath11k_base *ab,
- struct hal_srng *srng)
+/*
+ * Starts the load of the entries @lines cache lines past word @tp of a cached
+ * ring. A line past the head pointer is discarded again by
+ * ath11k_hal_srng_dst_sync() before its entries are read.
+ */
+static void ath11k_hal_srng_dst_prefetch(struct hal_srng *srng, u32 tp,
+ u32 lines)
{
- dma_addr_t desc_paddr;
- u32 *desc;
+ u32 ahead = tp + lines * L1_CACHE_BYTES / sizeof(u32);
- /* prefetch only if desc is available */
- desc = ath11k_hal_srng_dst_peek_with_dma(ab, srng, &desc_paddr);
- if (likely(desc)) {
- dma_sync_single_for_cpu(ab->dev, desc_paddr,
- (srng->entry_size * sizeof(u32)),
- DMA_FROM_DEVICE);
- prefetch(desc);
- }
+ if (!(srng->flags & HAL_SRNG_FLAGS_CACHED))
+ return;
+
+ if (ahead >= srng->ring_size)
+ ahead -= srng->ring_size;
+ if (ahead < srng->ring_size)
+ prefetch(srng->ring_base_vaddr + ahead);
}
u32 *ath11k_hal_srng_dst_get_next_entry(struct ath11k_base *ab,
@@ -675,9 +695,7 @@ u32 *ath11k_hal_srng_dst_get_next_entry(struct ath11k_base *ab,
if (srng->u.dst_ring.tp == srng->ring_size)
srng->u.dst_ring.tp = 0;
- /* Try to prefetch the next descriptor in the ring */
- if (srng->flags & HAL_SRNG_FLAGS_CACHED)
- ath11k_hal_srng_prefetch_desc(ab, srng);
+ ath11k_hal_srng_dst_prefetch(srng, srng->u.dst_ring.tp, 2);
return desc;
}
@@ -692,8 +710,15 @@ int ath11k_hal_srng_dst_num_free(struct ath11k_base *ab, struct hal_srng *srng,
tp = srng->u.dst_ring.tp;
if (sync_hw_ptr) {
- hp = *srng->u.dst_ring.hp_addr;
- srng->u.dst_ring.cached_hp = hp;
+ hp = READ_ONCE(*srng->u.dst_ring.hp_addr);
+ if (hp != srng->u.dst_ring.cached_hp) {
+ u32 old = srng->u.dst_ring.cached_hp;
+
+ srng->u.dst_ring.cached_hp = hp;
+ /* the entries are read after the head pointer */
+ dma_rmb();
+ ath11k_hal_srng_dst_sync(ab, srng, old, hp);
+ }
} else {
hp = srng->u.dst_ring.cached_hp;
}
@@ -835,16 +860,19 @@ void ath11k_hal_srng_access_begin(struct ath11k_base *ab, struct hal_srng *srng)
hp = READ_ONCE(*srng->u.dst_ring.hp_addr);
if (hp != srng->u.dst_ring.cached_hp) {
+ u32 old = srng->u.dst_ring.cached_hp;
+
srng->u.dst_ring.cached_hp = hp;
/* Make sure descriptor is read after the head
* pointer.
*/
dma_rmb();
+ ath11k_hal_srng_dst_sync(ab, srng, old, hp);
}
- /* Try to prefetch the next descriptor in the ring */
- if (srng->flags & HAL_SRNG_FLAGS_CACHED)
- ath11k_hal_srng_prefetch_desc(ab, srng);
+ ath11k_hal_srng_dst_prefetch(srng, srng->u.dst_ring.tp, 0);
+ ath11k_hal_srng_dst_prefetch(srng, srng->u.dst_ring.tp, 1);
+ ath11k_hal_srng_dst_prefetch(srng, srng->u.dst_ring.tp, 2);
}
}
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 06/10] wifi: ath11k: prefetch the buffers of the REO entries ahead of their reap
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
` (4 preceding siblings ...)
2026-11-23 13:41 ` [PATCH ath-next v1 05/10] wifi: ath11k: sync a cached ring's new entries once per head read Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 07/10] wifi: ath11k: look the peer of a received MSDU up once Julius Bairaktaris
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The REO reap loads, for each frame, the buffer table entry its cookie
names, then the sk_buff the entry holds, and after the reap the
processing of the frame loads the descriptor TLVs and headers the device
wrote. Each is a cache miss, taken one after the other: the table entry
and the sk_buff were written when the buffer was posted and are cold when
the frame comes back, and the frame's lines were just invalidated. In a
profile of bridged uplink at 900 Mbit/s (IPQ8074, one run) the
instruction after the table load in ath11k_dp_process_rx() takes 0.72 %
of all samples, the ones after the first sk_buff loads in
ath11k_dp_rx_unmap_buf() 2.26 %, after the attention load in
ath11k_dp_rx_h_attn_mpdu_err() 1.10 %, after the source address load in
ath11k_dp_rx_h_mpdu() 1.01 % and after the load of the data pointer in
ath11k_dp_rx_process_msdu() 1.05 %.
On a cached REO ring the entries ahead and their cookies are already in
the cache, so start these loads early: as each entry is reaped, prefetch
the table entry of the one after the next and the four lines of the next
one's sk_buff, whose table entry the entry before prefetched; once a
frame is handed to the CPU, prefetch the first three lines of its
descriptor and the first two lines of the frame behind it.
ath11k_hal_srng_dst_peek_ahead() returns an entry below the head pointer
read last. The table is read for an address only, without its lock: a
buffer the table no longer holds costs a prefetch to nothing. Rings in
coherent memory, where each entry read is a read from uncached memory,
are left as they are.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/dp_rx.c | 93 +++++++++++++++++++++++++
drivers/net/wireless/ath/ath11k/hal.c | 27 +++++++
drivers/net/wireless/ath/ath11k/hal.h | 1 +
3 files changed, 121 insertions(+)
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index b027b76ea3f3..e8226b2b832c 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -2919,6 +2919,92 @@ static void ath11k_dp_rx_process_received_packets(struct ath11k_base *ab,
}
}
+/*
+ * The refill buffer table entry a REO entry names, or NULL for a cookie that
+ * names none.
+ */
+static struct sk_buff **
+ath11k_dp_rx_reo_buf_slot(struct ath11k_base *ab,
+ const struct hal_reo_dest_ring *desc)
+{
+ u32 cookie = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE,
+ desc->buf_addr_info.info1);
+ u32 buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID, cookie);
+ u32 mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, cookie);
+ struct dp_rxdma_ring *rx_ring;
+ struct ath11k *ar;
+
+ if (!buf_id || mac_id >= ab->num_radios)
+ return NULL;
+
+ ar = ab->pdevs[mac_id].ar;
+ if (!ar)
+ return NULL;
+
+ rx_ring = &ar->dp.rx_refill_buf_ring;
+ if (buf_id >= rx_ring->num_ids)
+ return NULL;
+
+ return &rx_ring->bufs[buf_id];
+}
+
+/*
+ * Starts the loads of the reap of the next REO entries, which are cold by
+ * the time the frames come back: the buffer table entry of the entry after
+ * the next one, and the sk_buff of the next one, whose table entry the reap
+ * before prefetched. Only an address is read from the table, without its
+ * lock: a buffer it no longer holds costs a prefetch to nothing.
+ */
+static void ath11k_dp_rx_reo_prefetch(struct ath11k_base *ab,
+ struct hal_srng *srng)
+{
+ struct sk_buff **slot;
+ struct sk_buff *skb;
+ void *desc;
+
+ desc = ath11k_hal_srng_dst_peek_ahead(srng, 1);
+ if (desc) {
+ slot = ath11k_dp_rx_reo_buf_slot(ab, desc);
+ if (slot)
+ prefetch(slot);
+ }
+
+ desc = ath11k_hal_srng_dst_peek_ahead(srng, 0);
+ if (!desc)
+ return;
+
+ slot = ath11k_dp_rx_reo_buf_slot(ab, desc);
+ if (!slot)
+ return;
+
+ skb = READ_ONCE(*slot);
+ if (skb) {
+ prefetchw(skb);
+ prefetchw((u8 *)skb + L1_CACHE_BYTES);
+ prefetchw((u8 *)skb + 2 * L1_CACHE_BYTES);
+ prefetchw((u8 *)skb + 3 * L1_CACHE_BYTES);
+ }
+}
+
+/*
+ * Starts the loads of the descriptor TLVs and the headers of a frame the
+ * device has handed back, which its processing reads once the reap is done:
+ * the first three lines of the descriptor, where its end, attention and start
+ * TLVs begin, and the first two lines past it. A line past what the device
+ * wrote is not read.
+ */
+static void ath11k_dp_rx_prefetch_frame(struct ath11k_base *ab,
+ struct sk_buff *msdu)
+{
+ u8 *data = msdu->data, *hdr = data + ab->hw_params.hal_desc_sz;
+
+ prefetch(data);
+ prefetch(data + L1_CACHE_BYTES);
+ prefetch(data + 2 * L1_CACHE_BYTES);
+ prefetch(hdr);
+ prefetch(hdr + L1_CACHE_BYTES);
+}
+
int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
struct napi_struct *napi, int budget)
{
@@ -2936,12 +3022,14 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
struct hal_reo_dest_ring *desc;
enum hal_reo_dest_ring_push_reason push_reason;
u32 cookie;
+ bool cached;
int i;
for (i = 0; i < MAX_RADIOS; i++)
__skb_queue_head_init(&msdu_list[i]);
srng = &ab->hal.srng_list[dp->reo_dst_ring[ring_id].ring_id];
+ cached = srng->flags & HAL_SRNG_FLAGS_CACHED;
spin_lock_bh(&srng->lock);
@@ -2951,6 +3039,9 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
while (likely(desc =
(struct hal_reo_dest_ring *)ath11k_hal_srng_dst_get_next_entry(ab,
srng))) {
+ if (cached)
+ ath11k_dp_rx_reo_prefetch(ab, srng);
+
cookie = FIELD_GET(BUFFER_ADDR_INFO1_SW_COOKIE,
desc->buf_addr_info.info1);
buf_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_BUF_ID,
@@ -2976,6 +3067,8 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
rxcb = ATH11K_SKB_RXCB(msdu);
ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
+ if (cached)
+ ath11k_dp_rx_prefetch_frame(ab, msdu);
num_buffs_reaped[mac_id]++;
diff --git a/drivers/net/wireless/ath/ath11k/hal.c b/drivers/net/wireless/ath/ath11k/hal.c
index e5c35647a136..fffecc077eac 100644
--- a/drivers/net/wireless/ath/ath11k/hal.c
+++ b/drivers/net/wireless/ath/ath11k/hal.c
@@ -627,6 +627,33 @@ u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng)
return NULL;
}
+/**
+ * ath11k_hal_srng_dst_peek_ahead() - an entry of a destination ring past the next
+ * @srng: the ring, whose lock the caller holds
+ * @n: how many entries past the one ath11k_hal_srng_dst_get_next_entry()
+ * returns next
+ *
+ * Return: the entry, or NULL when the head pointer read last does not
+ * reach it.
+ */
+u32 *ath11k_hal_srng_dst_peek_ahead(struct hal_srng *srng, u32 n)
+{
+ u32 tp = srng->u.dst_ring.tp, hp = srng->u.dst_ring.cached_hp;
+ u32 avail, off = n * srng->entry_size;
+
+ lockdep_assert_held(&srng->lock);
+
+ avail = hp >= tp ? hp - tp : srng->ring_size - tp + hp;
+ if (off >= avail)
+ return NULL;
+
+ tp += off;
+ if (tp >= srng->ring_size)
+ tp -= srng->ring_size;
+
+ return srng->ring_base_vaddr + tp;
+}
+
/*
* Hands the CPU the entries of a cached destination ring from word @from up
* to word @to, which the head pointer the caller just read shows the device
diff --git a/drivers/net/wireless/ath/ath11k/hal.h b/drivers/net/wireless/ath/ath11k/hal.h
index 82603a389bb9..45ac2391abd8 100644
--- a/drivers/net/wireless/ath/ath11k/hal.h
+++ b/drivers/net/wireless/ath/ath11k/hal.h
@@ -944,6 +944,7 @@ void ath11k_hal_srng_get_params(struct ath11k_base *ab, struct hal_srng *srng,
u32 *ath11k_hal_srng_dst_get_next_entry(struct ath11k_base *ab,
struct hal_srng *srng);
u32 *ath11k_hal_srng_dst_peek(struct ath11k_base *ab, struct hal_srng *srng);
+u32 *ath11k_hal_srng_dst_peek_ahead(struct hal_srng *srng, u32 n);
int ath11k_hal_srng_dst_num_free(struct ath11k_base *ab, struct hal_srng *srng,
bool sync_hw_ptr);
u32 *ath11k_hal_srng_src_peek(struct ath11k_base *ab, struct hal_srng *srng);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 07/10] wifi: ath11k: look the peer of a received MSDU up once
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
` (5 preceding siblings ...)
2026-11-23 13:41 ` [PATCH ath-next v1 06/10] wifi: ath11k: prefetch the buffers of the REO entries ahead of their reap Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 08/10] wifi: ath11k: take the refill buffer lock without a second BH disable Julius Bairaktaris
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
ath11k_dp_rx_h_mpdu() looks up the peer of each MSDU by its peer id in the
rhashtable, under base_lock, for the cipher, and
ath11k_dp_rx_deliver_msdu() looks it up again for the station it hands to
mac80211, under a second hold of the lock. In a profile of bridged uplink
at 900 Mbit/s (IPQ8074, one run) the lookup and its hash take 1.7 % of
all samples (ath11k_peer_find_by_id() 1.12 %, rhashtable_jhash2()
0.62 %).
Keep the station ath11k_dp_rx_h_mpdu() found in the frame's control
block, and have ath11k_dp_rx_deliver_msdu() take it from there. mac80211
then gets the station of the peer whose cipher the frame was handled
with, where two lookups could find different peers if the peer table
changed between them. The station is used after the lock and in the same
NAPI poll, as ath11k_dp_rx_deliver_msdu() used the station of its own
lookup after the lock. A frame that does not pass ath11k_dp_rx_h_mpdu(),
from the monitor and error paths, still looks its peer up; the mark is
cleared where those frames are reaped and when it is read. The debug
message prints the station's address.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/core.h | 3 +++
drivers/net/wireless/ath/ath11k/dp_rx.c | 33 ++++++++++++++++++++-----
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
index a0d725923ef2..4eb40e674c14 100644
--- a/drivers/net/wireless/ath/ath11k/core.h
+++ b/drivers/net/wireless/ath/ath11k/core.h
@@ -131,6 +131,8 @@ struct ath11k_skb_rxcb {
bool is_continuation;
bool is_mcbc;
bool is_eapol;
+ /* sta holds the station of the peer ath11k_dp_rx_h_mpdu() found */
+ bool sta_valid;
struct hal_rx_desc *rx_desc;
u8 err_rel_src;
u8 err_code;
@@ -140,6 +142,7 @@ struct ath11k_skb_rxcb {
u8 tid;
u16 peer_id;
u16 seq_no;
+ struct ieee80211_sta *sta;
};
enum ath11k_hw_rev {
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index e8226b2b832c..ff09463d829f 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -2512,6 +2512,14 @@ static int ath11k_dp_rx_h_mpdu(struct ath11k *ar,
spin_lock_bh(&ar->ab->base_lock);
peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu);
+ /*
+ * For ath11k_dp_rx_deliver_msdu(): the station of the peer whose
+ * cipher the frame is handled with, from the same hold of the lock.
+ */
+ BUILD_BUG_ON(sizeof(struct ath11k_skb_rxcb) >
+ sizeof_field(struct sk_buff, cb));
+ rxcb->sta = peer ? peer->sta : NULL;
+ rxcb->sta_valid = true;
if (peer) {
if (rxcb->is_mcbc)
enctype = peer->sec_type_grp;
@@ -2721,17 +2729,27 @@ static void ath11k_dp_rx_deliver_msdu(struct ath11k *ar, struct napi_struct *nap
if (!(status->flag & RX_FLAG_ONLY_MONITOR))
decap = ath11k_dp_rx_h_msdu_start_decap_type(ar->ab, rxcb->rx_desc);
- spin_lock_bh(&ar->ab->base_lock);
- peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu);
- if (peer && peer->sta)
- pubsta = peer->sta;
- spin_unlock_bh(&ar->ab->base_lock);
+ /*
+ * The station ath11k_dp_rx_h_mpdu() found for the frame, if it ran,
+ * so that mac80211 gets the station whose cipher the frame was
+ * handled with.
+ */
+ if (rxcb->sta_valid) {
+ rxcb->sta_valid = false;
+ pubsta = rxcb->sta;
+ } else {
+ spin_lock_bh(&ar->ab->base_lock);
+ peer = ath11k_dp_rx_h_find_peer(ar->ab, msdu);
+ if (peer && peer->sta)
+ pubsta = peer->sta;
+ spin_unlock_bh(&ar->ab->base_lock);
+ }
ath11k_dbg(ar->ab, ATH11K_DBG_DATA,
"rx skb %p len %u peer %pM %d %s sn %u %s%s%s%s%s%s%s %srate_idx %u vht_nss %u freq %u band %u flag 0x%x fcs-err %i mic-err %i amsdu-more %i\n",
msdu,
msdu->len,
- peer ? peer->addr : NULL,
+ pubsta ? pubsta->addr : NULL,
rxcb->tid,
is_mcbc ? "mcast" : "ucast",
rxcb->seq_no,
@@ -3081,6 +3099,7 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
continue;
}
+ rxcb->sta_valid = false;
rxcb->is_first_msdu = !!(desc->rx_msdu_info.info0 &
RX_MSDU_DESC_INFO0_FIRST_MSDU_IN_MPDU);
rxcb->is_last_msdu = !!(desc->rx_msdu_info.info0 &
@@ -4562,6 +4581,7 @@ int ath11k_dp_rx_process_wbm_err(struct ath11k_base *ab,
continue;
}
+ rxcb->sta_valid = false;
rxcb->err_rel_src = err_info.err_rel_src;
rxcb->err_code = err_info.err_code;
rxcb->rx_desc = (struct hal_rx_desc *)msdu->data;
@@ -5471,6 +5491,7 @@ static int ath11k_dp_rx_mon_deliver(struct ath11k *ar, u32 mac_id,
rxs->flag |= RX_FLAG_ONLY_MONITOR;
ath11k_update_radiotap(ar, ppduinfo, mon_skb, rxs);
+ ATH11K_SKB_RXCB(mon_skb)->sta_valid = false;
ath11k_dp_rx_deliver_msdu(ar, napi, mon_skb, rxs);
mon_skb = skb_next;
} while (mon_skb);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 08/10] wifi: ath11k: take the refill buffer lock without a second BH disable
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
` (6 preceding siblings ...)
2026-11-23 13:41 ` [PATCH ath-next v1 07/10] wifi: ath11k: look the peer of a received MSDU up once Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 09/10] wifi: ath11k: hand the CPU only the part of a REO buffer the device wrote Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 10/10] wifi: ath11k: give the refill buffers their ids a chunk at a time Julius Bairaktaris
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The REO reap and the refill take the buffer table lock of the refill
ring once per frame with spin_lock_bh(), inside their hold of the ring
lock, which they take with spin_lock_bh() and which keeps bottom halves
off for the whole loop. Each unlock then goes through
__local_bh_enable_ip() for nothing: in a profile of bridged uplink at
900 Mbit/s (IPQ8074, one run) the instruction after that call in
ath11k_dp_rxbufs_replenish() takes 0.43 % of all samples and the one in
ath11k_dp_process_rx() 0.13 %, and __local_bh_enable_ip() itself 1.23 %
from all its callers.
Take the table lock with spin_lock() in these two loops and in the
refill's error path, which all run under the ring lock. The other holders
of the table lock still disable bottom halves themselves, and none takes
it from hard interrupt context.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/dp_rx.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index ff09463d829f..dd5bc35581f7 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -513,9 +513,10 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
goto fail_free_skb;
}
- spin_lock_bh(&rx_ring->bufs_lock);
+ /* bottom halves are off with the ring lock */
+ spin_lock(&rx_ring->bufs_lock);
buf_id = ath11k_dp_rx_buf_get_id(rx_ring, skb);
- spin_unlock_bh(&rx_ring->bufs_lock);
+ spin_unlock(&rx_ring->bufs_lock);
if (buf_id <= 0)
goto fail_dma_unmap;
@@ -540,9 +541,9 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
return req_entries - num_remain;
fail_idr_remove:
- spin_lock_bh(&rx_ring->bufs_lock);
+ spin_lock(&rx_ring->bufs_lock);
ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
- spin_unlock_bh(&rx_ring->bufs_lock);
+ spin_unlock(&rx_ring->bufs_lock);
fail_dma_unmap:
if (!rx_ring->page_pool)
dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
@@ -3071,17 +3072,18 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
ar = ab->pdevs[mac_id].ar;
rx_ring = &ar->dp.rx_refill_buf_ring;
- spin_lock_bh(&rx_ring->bufs_lock);
+ /* bottom halves are off with the ring lock */
+ spin_lock(&rx_ring->bufs_lock);
msdu = ath11k_dp_rx_buf_lookup(rx_ring, buf_id);
if (unlikely(!msdu)) {
ath11k_warn(ab, "frame rx with invalid buf_id %d\n",
buf_id);
- spin_unlock_bh(&rx_ring->bufs_lock);
+ spin_unlock(&rx_ring->bufs_lock);
continue;
}
ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
- spin_unlock_bh(&rx_ring->bufs_lock);
+ spin_unlock(&rx_ring->bufs_lock);
rxcb = ATH11K_SKB_RXCB(msdu);
ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 09/10] wifi: ath11k: hand the CPU only the part of a REO buffer the device wrote
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
` (7 preceding siblings ...)
2026-11-23 13:41 ` [PATCH ath-next v1 08/10] wifi: ath11k: take the refill buffer lock without a second BH disable Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 10/10] wifi: ath11k: give the refill buffers their ids a chunk at a time Julius Bairaktaris
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The REO reap takes each page pool buffer back from the device with a
dma_sync_single_for_cpu() over the whole buffer, 2048 bytes, while the
device wrote the descriptor, the L3 padding and the MSDU, whose length
the REO entry carries. A TCP acknowledgment, which is what a station
sends back on downlink, takes 453 bytes of it on IPQ8074 (384 of
descriptor, at most 3 of padding, 66 of frame): on a non-coherent system
the invalidation walks 32 cache lines where 8 hold what the device wrote.
Take back the descriptor, the largest padding of the two padding fields
and the MSDU length of the entry. The buffers of an MSDU that spans
several, the one with the continuation bit and the ones after it on the
ring, are taken whole as before; whether the last entry reaped had the
bit is kept per ring, so a chain split between two polls is still seen.
The length taken is recorded in the frame's control block, and
ath11k_dp_rx_process_msdu() takes back the rest, up to the length the
descriptor gives, before it reads the frame, should that be longer than
the entry's: the CPU never reads a byte of the buffer it has not
invalidated after the device wrote it. A line past what was taken back
is not read and may hold a stale copy; the page pool syncs the whole
page for the device before the device gets it again, and the reap of its
next frame invalidates what that frame covers.
A buffer of its own, without a page pool, is unmapped whole as before.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/core.h | 2 +
drivers/net/wireless/ath/ath11k/dp.h | 4 ++
drivers/net/wireless/ath/ath11k/dp_rx.c | 71 +++++++++++++++++++++++--
3 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
index 4eb40e674c14..6b05b2e4d926 100644
--- a/drivers/net/wireless/ath/ath11k/core.h
+++ b/drivers/net/wireless/ath/ath11k/core.h
@@ -142,6 +142,8 @@ struct ath11k_skb_rxcb {
u8 tid;
u16 peer_id;
u16 seq_no;
+ /* the bytes of the buffer from its start that the CPU took back */
+ u16 sync_len;
struct ieee80211_sta *sta;
};
diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h
index 5e973c337cb2..861cf65c5218 100644
--- a/drivers/net/wireless/ath/ath11k/dp.h
+++ b/drivers/net/wireless/ath/ath11k/dp.h
@@ -234,6 +234,8 @@ struct ath11k_pdev_dp {
#define DP_RX_BUFFER_SIZE 2048
#define DP_RX_BUFFER_SIZE_LITE 1024
#define DP_RX_BUFFER_ALIGN_SIZE 128
+/* The most L3 header padding the msdu_end TLV of any chip gives */
+#define DP_RX_L3_PAD_MAX 3
#define DP_RX_PP_ORDER 1
#define DP_RX_PP_FRAG_SIZE ALIGN(SKB_HEAD_ALIGN(DP_RX_BUFFER_SIZE), \
DP_RX_BUFFER_ALIGN_SIZE)
@@ -279,6 +281,8 @@ struct ath11k_dp {
struct dp_srng reo_cmd_ring;
struct dp_srng reo_status_ring;
struct dp_srng reo_dst_ring[DP_REO_DST_RING_MAX];
+ /* the last entry reaped from the ring had the continuation bit */
+ bool reo_dst_cont[DP_REO_DST_RING_MAX];
struct dp_tx_ring tx_ring[DP_TCL_NUM_RING_MAX];
struct hal_wbm_idle_scatter_list scatter_list[DP_IDLE_SCATTER_BUFS_MAX];
struct list_head reo_cmd_list;
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index dd5bc35581f7..313a39f15781 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -410,17 +410,59 @@ static bool ath11k_dp_rx_buf_is_pp(struct sk_buff *skb)
return skb->pp_recycle && skb->head_frag;
}
-static void ath11k_dp_rx_unmap_buf(struct ath11k_base *ab, struct sk_buff *skb,
- enum dma_data_direction dir)
+/*
+ * Hands a receive buffer back to the CPU: of a page pool buffer the first
+ * @want bytes, or all of it for a @want of 0 or past its end, and records
+ * how much in sync_len. A buffer of its own is unmapped whole.
+ */
+static void ath11k_dp_rx_unmap_buf_len(struct ath11k_base *ab,
+ struct sk_buff *skb,
+ enum dma_data_direction dir,
+ unsigned int want)
{
struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(skb);
unsigned int len = skb->len + skb_tailroom(skb);
- if (ath11k_dp_rx_buf_is_pp(skb))
+ BUILD_BUG_ON(FIELD_MAX(RX_MSDU_END_INFO2_L3_HDR_PADDING) >
+ DP_RX_L3_PAD_MAX);
+ BUILD_BUG_ON(FIELD_MAX(RX_MSDU_END_INFO4_L3_HDR_PADDING) >
+ DP_RX_L3_PAD_MAX);
+
+ if (ath11k_dp_rx_buf_is_pp(skb)) {
+ if (want && want < len)
+ len = want;
dma_sync_single_for_cpu(ab->dev, rxcb->paddr, len,
DMA_BIDIRECTIONAL);
- else
+ } else {
dma_unmap_single(ab->dev, rxcb->paddr, len, dir);
+ }
+ rxcb->sync_len = len;
+}
+
+static void ath11k_dp_rx_unmap_buf(struct ath11k_base *ab, struct sk_buff *skb,
+ enum dma_data_direction dir)
+{
+ ath11k_dp_rx_unmap_buf_len(ab, skb, dir, 0);
+}
+
+/*
+ * Takes back from the device the bytes of @msdu past those it took at the
+ * reap, up to @need, for a frame whose descriptor says it is longer than
+ * its REO entry did.
+ */
+static void ath11k_dp_rx_sync_more(struct ath11k_base *ab, struct sk_buff *msdu,
+ unsigned int need)
+{
+ struct ath11k_skb_rxcb *rxcb = ATH11K_SKB_RXCB(msdu);
+ unsigned int len = msdu->len + skb_tailroom(msdu);
+
+ need = min(need, len);
+ if (likely(need <= rxcb->sync_len))
+ return;
+
+ dma_sync_single_for_cpu(ab->dev, rxcb->paddr + rxcb->sync_len,
+ need - rxcb->sync_len, DMA_BIDIRECTIONAL);
+ rxcb->sync_len = need;
}
static dma_addr_t ath11k_dp_rx_pp_dma_addr(struct sk_buff *skb)
@@ -2870,6 +2912,8 @@ static int ath11k_dp_rx_process_msdu(struct ath11k *ar,
sizeof(struct hal_rx_desc));
goto free_out;
}
+ ath11k_dp_rx_sync_more(ab, msdu, hal_rx_desc_sz + l3_pad_bytes +
+ msdu_len);
skb_put(msdu, hal_rx_desc_sz + l3_pad_bytes + msdu_len);
skb_pull(msdu, hal_rx_desc_sz + l3_pad_bytes);
} else {
@@ -3027,6 +3071,8 @@ static void ath11k_dp_rx_prefetch_frame(struct ath11k_base *ab,
int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
struct napi_struct *napi, int budget)
{
+ unsigned int want;
+ u32 info0;
struct ath11k_dp *dp = &ab->dp;
struct dp_rxdma_ring *rx_ring;
int num_buffs_reaped[MAX_RADIOS] = {};
@@ -3067,6 +3113,21 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
cookie);
mac_id = FIELD_GET(DP_RXDMA_BUF_COOKIE_PDEV_ID, cookie);
+ /*
+ * The device wrote the descriptor, the padding and the MSDU
+ * of the length the entry gives. A buffer of an MSDU that
+ * spans several, which follows one with the continuation bit
+ * or has it, is taken whole.
+ */
+ info0 = desc->rx_msdu_info.info0;
+ want = ab->hw_params.hal_desc_sz + DP_RX_L3_PAD_MAX +
+ FIELD_GET(RX_MSDU_DESC_INFO0_MSDU_LENGTH, info0);
+ if (dp->reo_dst_cont[ring_id] ||
+ (info0 & RX_MSDU_DESC_INFO0_MSDU_CONTINUATION))
+ want = 0;
+ dp->reo_dst_cont[ring_id] =
+ !!(info0 & RX_MSDU_DESC_INFO0_MSDU_CONTINUATION);
+
if (unlikely(buf_id == 0))
continue;
@@ -3086,7 +3147,7 @@ int ath11k_dp_process_rx(struct ath11k_base *ab, int ring_id,
spin_unlock(&rx_ring->bufs_lock);
rxcb = ATH11K_SKB_RXCB(msdu);
- ath11k_dp_rx_unmap_buf(ab, msdu, DMA_FROM_DEVICE);
+ ath11k_dp_rx_unmap_buf_len(ab, msdu, DMA_FROM_DEVICE, want);
if (cached)
ath11k_dp_rx_prefetch_frame(ab, msdu);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH ath-next v1 10/10] wifi: ath11k: give the refill buffers their ids a chunk at a time
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
` (8 preceding siblings ...)
2026-11-23 13:41 ` [PATCH ath-next v1 09/10] wifi: ath11k: hand the CPU only the part of a REO buffer the device wrote Julius Bairaktaris
@ 2026-11-23 13:41 ` Julius Bairaktaris
9 siblings, 0 replies; 11+ messages in thread
From: Julius Bairaktaris @ 2026-11-23 13:41 UTC (permalink / raw)
To: Jeff Johnson
Cc: ath11k, linux-wireless, linux-kernel, Baochen Qiang,
Vasanthakumar Thiagarajan, Rameshkumar Sundaram, Praneesh P,
Lorenzo Bianconi, Mark Ruvald Pedersen, Rosen Penev
The refill takes the buffer table lock of the refill ring once per
buffer, and the cache line of the lock moves between the CPUs of the REO
rings, whose reaps take it for every frame: in a profile of bridged
uplink at 850 Mbit/s (IPQ8074, one run) the compare-and-swap of that
spin_lock() in ath11k_dp_rxbufs_replenish() takes 0.84 % of all samples.
Allocate the buffers of a chunk of up to 16 first, outside the lock, and
give them their ids under one hold of it. A buffer that gets no id or no
ring entry goes back and ends the refill with what is on the ring, as an
allocation failure does. The reaps still hold the lock for one table
entry at a time, so they wait at most for 16 id operations.
Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.9.0.1-02146-QCAHKSWPL_SILICONZ-1
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/wireless/ath/ath11k/dp_rx.c | 142 +++++++++++++++---------
1 file changed, 92 insertions(+), 50 deletions(-)
diff --git a/drivers/net/wireless/ath/ath11k/dp_rx.c b/drivers/net/wireless/ath/ath11k/dp_rx.c
index 313a39f15781..a85edaf19bfb 100644
--- a/drivers/net/wireless/ath/ath11k/dp_rx.c
+++ b/drivers/net/wireless/ath/ath11k/dp_rx.c
@@ -497,12 +497,65 @@ static struct sk_buff *ath11k_dp_rx_pp_alloc_skb(struct dp_rxdma_ring *rx_ring)
return skb;
}
+/*
+ * The refill takes buffer ids for this many buffers under one hold of the
+ * buffer table lock, which the reaps of every REO ring take too.
+ */
+#define ATH11K_DP_RX_REFILL_CHUNK 16
+
+/* A buffer for the refill of @rx_ring and the address the device writes it at */
+static struct sk_buff *ath11k_dp_rx_refill_alloc(struct ath11k_base *ab,
+ struct dp_rxdma_ring *rx_ring,
+ dma_addr_t *paddr)
+{
+ struct sk_buff *skb;
+
+ if (rx_ring->page_pool) {
+ skb = ath11k_dp_rx_pp_alloc_skb(rx_ring);
+ if (skb)
+ *paddr = ath11k_dp_rx_pp_dma_addr(skb);
+ return skb;
+ }
+
+ skb = dev_alloc_skb(DP_RX_BUFFER_SIZE + DP_RX_BUFFER_ALIGN_SIZE);
+ if (!skb)
+ return NULL;
+
+ if (!IS_ALIGNED((unsigned long)skb->data, DP_RX_BUFFER_ALIGN_SIZE))
+ skb_pull(skb, PTR_ALIGN(skb->data, DP_RX_BUFFER_ALIGN_SIZE) -
+ skb->data);
+
+ *paddr = dma_map_single(ab->dev, skb->data,
+ skb->len + skb_tailroom(skb), DMA_FROM_DEVICE);
+ if (dma_mapping_error(ab->dev, *paddr)) {
+ dev_kfree_skb_any(skb);
+ return NULL;
+ }
+
+ return skb;
+}
+
+/* Frees a buffer ath11k_dp_rx_refill_alloc() gave that is not on the ring */
+static void ath11k_dp_rx_refill_free(struct ath11k_base *ab,
+ struct dp_rxdma_ring *rx_ring,
+ struct sk_buff *skb, dma_addr_t paddr)
+{
+ if (!rx_ring->page_pool)
+ dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
+ DMA_FROM_DEVICE);
+ dev_kfree_skb_any(skb);
+}
+
/* Returns number of Rx buffers replenished */
int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
struct dp_rxdma_ring *rx_ring,
int req_entries,
enum hal_rx_buf_return_buf_manager mgr)
{
+ struct sk_buff *skbs[ATH11K_DP_RX_REFILL_CHUNK];
+ dma_addr_t paddrs[ATH11K_DP_RX_REFILL_CHUNK];
+ int ids[ATH11K_DP_RX_REFILL_CHUNK];
+ int n, got, ided, i, j;
struct hal_srng *srng;
u32 *desc;
struct sk_buff *skb;
@@ -528,70 +581,59 @@ int ath11k_dp_rxbufs_replenish(struct ath11k_base *ab, int mac_id,
num_remain = req_entries;
while (num_remain > 0) {
- if (rx_ring->page_pool) {
- skb = ath11k_dp_rx_pp_alloc_skb(rx_ring);
- if (!skb)
- break;
-
- paddr = ath11k_dp_rx_pp_dma_addr(skb);
- } else {
- skb = dev_alloc_skb(DP_RX_BUFFER_SIZE +
- DP_RX_BUFFER_ALIGN_SIZE);
+ n = min(num_remain, ATH11K_DP_RX_REFILL_CHUNK);
+ for (got = 0; got < n; got++) {
+ skb = ath11k_dp_rx_refill_alloc(ab, rx_ring, &paddr);
if (!skb)
break;
-
- if (!IS_ALIGNED((unsigned long)skb->data,
- DP_RX_BUFFER_ALIGN_SIZE)) {
- skb_pull(skb,
- PTR_ALIGN(skb->data,
- DP_RX_BUFFER_ALIGN_SIZE) -
- skb->data);
- }
-
- paddr = dma_map_single(ab->dev, skb->data,
- skb->len + skb_tailroom(skb),
- DMA_FROM_DEVICE);
- if (dma_mapping_error(ab->dev, paddr))
- goto fail_free_skb;
+ skbs[got] = skb;
+ paddrs[got] = paddr;
}
/* bottom halves are off with the ring lock */
spin_lock(&rx_ring->bufs_lock);
- buf_id = ath11k_dp_rx_buf_get_id(rx_ring, skb);
+ for (ided = 0; ided < got; ided++) {
+ buf_id = ath11k_dp_rx_buf_get_id(rx_ring, skbs[ided]);
+ if (buf_id <= 0)
+ break;
+ ids[ided] = buf_id;
+ }
spin_unlock(&rx_ring->bufs_lock);
- if (buf_id <= 0)
- goto fail_dma_unmap;
-
- desc = ath11k_hal_srng_src_get_next_entry(ab, srng);
- if (!desc)
- goto fail_idr_remove;
-
- ATH11K_SKB_RXCB(skb)->paddr = paddr;
- cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, mac_id) |
- FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, buf_id);
+ for (i = 0; i < ided; i++) {
+ desc = ath11k_hal_srng_src_get_next_entry(ab, srng);
+ if (!desc)
+ break;
- num_remain--;
+ ATH11K_SKB_RXCB(skbs[i])->paddr = paddrs[i];
- ath11k_hal_rx_buf_addr_info_set(desc, paddr, cookie, mgr);
- }
+ cookie = FIELD_PREP(DP_RXDMA_BUF_COOKIE_PDEV_ID, mac_id) |
+ FIELD_PREP(DP_RXDMA_BUF_COOKIE_BUF_ID, ids[i]);
- ath11k_hal_srng_access_end(ab, srng);
+ num_remain--;
- spin_unlock_bh(&srng->lock);
+ ath11k_hal_rx_buf_addr_info_set(desc, paddrs[i], cookie,
+ mgr);
+ }
- return req_entries - num_remain;
+ /*
+ * A buffer that got no id or no ring entry goes back, and the
+ * refill ends with what is on the ring.
+ */
+ if (i < got) {
+ spin_lock(&rx_ring->bufs_lock);
+ for (j = i; j < ided; j++)
+ ath11k_dp_rx_buf_put_id(rx_ring, ids[j]);
+ spin_unlock(&rx_ring->bufs_lock);
+ for (j = i; j < got; j++)
+ ath11k_dp_rx_refill_free(ab, rx_ring, skbs[j],
+ paddrs[j]);
+ break;
+ }
-fail_idr_remove:
- spin_lock(&rx_ring->bufs_lock);
- ath11k_dp_rx_buf_put_id(rx_ring, buf_id);
- spin_unlock(&rx_ring->bufs_lock);
-fail_dma_unmap:
- if (!rx_ring->page_pool)
- dma_unmap_single(ab->dev, paddr, skb->len + skb_tailroom(skb),
- DMA_FROM_DEVICE);
-fail_free_skb:
- dev_kfree_skb_any(skb);
+ if (got < n)
+ break;
+ }
ath11k_hal_srng_access_end(ab, srng);
--
2.53.0
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-11-23 13:41 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 13:41 [PATCH ath-next v1 00/10] wifi: ath11k: cut the per-packet cost of the RX path Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 01/10] wifi: ath11k: use page_pool for the RX refill ring Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 02/10] wifi: ath11k: replace the RX buffer IDR with a table Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 03/10] wifi: ath11k: request only the PPDU stats TLVs it reads Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 04/10] wifi: ath11k: set the skb hash of a received frame from the hardware Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 05/10] wifi: ath11k: sync a cached ring's new entries once per head read Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 06/10] wifi: ath11k: prefetch the buffers of the REO entries ahead of their reap Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 07/10] wifi: ath11k: look the peer of a received MSDU up once Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 08/10] wifi: ath11k: take the refill buffer lock without a second BH disable Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 09/10] wifi: ath11k: hand the CPU only the part of a REO buffer the device wrote Julius Bairaktaris
2026-11-23 13:41 ` [PATCH ath-next v1 10/10] wifi: ath11k: give the refill buffers their ids a chunk at a time Julius Bairaktaris
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®