[PATCH 1/3] wifi: mt76: Separate skb and page_pool_buf pointers in mt76_txwi_cache
Lorenzo Bianconi
lorenzo at kernel.org
Thu Jul 9 01:19:26 PDT 2026
> From: Eason Lai <Eason.Lai at mediatek.com>
>
> Refactor mt76_txwi_cache structure to use separate skb and page_pool_buf
> fields instead of a union with ptr. This improves type safety and makes
> the code more explicit about which pointer type is being used in
> different contexts.
>
> Also add skip_unmap flag to tx_info.buf to handle cases where DMA
> unmapping should be skipped.
>
> Signed-off-by: Eason Lai <Eason.Lai at mediatek.com>
> ---
> drivers/net/wireless/mediatek/mt76/dma.c | 29 ++++++++++++-------
> drivers/net/wireless/mediatek/mt76/mt76.h | 4 +--
> .../net/wireless/mediatek/mt76/mt7996/mac.c | 10 +++----
> drivers/net/wireless/mediatek/mt76/tx.c | 2 +-
> drivers/net/wireless/mediatek/mt76/wed.c | 6 ++--
> 5 files changed, 28 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
> index f8c2fe5f2f58..2716278788bd 100644
> --- a/drivers/net/wireless/mediatek/mt76/dma.c
> +++ b/drivers/net/wireless/mediatek/mt76/dma.c
> @@ -43,7 +43,8 @@ mt76_alloc_rxwi(struct mt76_dev *dev)
> if (!t)
> return NULL;
>
> - t->ptr = NULL;
> + t->skb = NULL;
> + t->page_pool_buf = NULL;
> return t;
> }
>
> @@ -84,8 +85,11 @@ mt76_get_txwi(struct mt76_dev *dev)
> {
> struct mt76_txwi_cache *t = __mt76_get_txwi(dev);
>
> - if (t)
> + if (t) {
> + t->skb = NULL;
> + t->page_pool_buf = NULL;
> return t;
> + }
>
> return mt76_alloc_txwi(dev);
> }
> @@ -147,8 +151,8 @@ mt76_free_pending_rxwi(struct mt76_dev *dev)
>
> local_bh_disable();
> while ((t = __mt76_get_rxwi(dev)) != NULL) {
> - if (t->ptr)
> - mt76_put_page_pool_buf(t->ptr, false);
> + if (t->page_pool_buf)
> + mt76_put_page_pool_buf(t->page_pool_buf, false);
> kfree(t);
> }
> local_bh_enable();
> @@ -475,14 +479,14 @@ mt76_dma_get_rxdmad_c_buf(struct mt76_dev *dev, struct mt76_queue *q,
> if (more)
> *more = !FIELD_GET(RRO_RXDMAD_DATA1_LS_MASK, data1);
>
> - buf = t->ptr;
> + buf = t->page_pool_buf;
> ind_reason = FIELD_GET(RRO_RXDMAD_DATA2_IND_REASON_MASK, data2);
> if (ind_reason == MT_DMA_WED_IND_REASON_REPEAT ||
> ind_reason == MT_DMA_WED_IND_REASON_OLDPKT) {
> mt76_put_page_pool_buf(buf, false);
> buf = ERR_PTR(-EAGAIN);
> }
> - t->ptr = NULL;
> + t->page_pool_buf = NULL;
> t->dma_addr = 0;
>
> mt76_put_rxwi(dev, t);
> @@ -529,9 +533,9 @@ mt76_dma_get_buf(struct mt76_dev *dev, struct mt76_queue *q, int idx,
> SKB_WITH_OVERHEAD(q->buf_size),
> page_pool_get_dma_dir(q->page_pool));
>
> - buf = t->ptr;
> + buf = t->page_pool_buf;
> t->dma_addr = 0;
> - t->ptr = NULL;
> + t->page_pool_buf = NULL;
>
> mt76_put_rxwi(dev, t);
> if (drop)
> @@ -694,6 +698,7 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
> goto unmap;
>
> tx_info.buf[n].addr = addr;
> + tx_info.buf[n].skip_unmap = false;
> tx_info.buf[n++].len = iter->len;
> }
> tx_info.nbuf = n;
> @@ -718,9 +723,11 @@ mt76_dma_tx_queue_skb(struct mt76_phy *phy, struct mt76_queue *q,
> tx_info.info, tx_info.skb, t);
>
> unmap:
> - for (n--; n > 0; n--)
> - dma_unmap_single(dev->dma_dev, tx_info.buf[n].addr,
> - tx_info.buf[n].len, DMA_TO_DEVICE);
> + for (n--; n > 0; n--) {
> + if (!tx_info.buf[n].skip_unmap)
> + dma_unmap_single(dev->dma_dev, tx_info.buf[n].addr,
> + tx_info.buf[n].len, DMA_TO_DEVICE);
> + }
>
> free:
> #ifdef CONFIG_NL80211_TESTMODE
> diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
> index 527bef97e122..927c21536f4e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76.h
> +++ b/drivers/net/wireless/mediatek/mt76/mt76.h
> @@ -445,10 +445,8 @@ struct mt76_txwi_cache {
> struct list_head list;
> dma_addr_t dma_addr;
>
> - union {
> struct sk_buff *skb;
> - void *ptr;
> - };
> + void *page_pool_buf;
if you do not rename the pointer here, the patch would be much less intrusive.
Regards,
Lorenzo
>
> u8 qid;
> u8 phy_idx;
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
> index e2a83da3a09c..924b0dc0ff1e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7996/mac.c
> @@ -1775,12 +1775,12 @@ static void mt7996_rx_token_put(struct mt7996_dev *dev)
> struct mt76_txwi_cache *t;
>
> t = mt76_rx_token_release(&dev->mt76, i);
> - if (!t || !t->ptr)
> + if (!t || !t->page_pool_buf)
> continue;
>
> - mt76_put_page_pool_buf(t->ptr, false);
> + mt76_put_page_pool_buf(t->page_pool_buf, false);
> t->dma_addr = 0;
> - t->ptr = NULL;
> + t->page_pool_buf = NULL;
>
> mt76_put_rxwi(&dev->mt76, t);
> }
> @@ -1928,14 +1928,14 @@ void mt7996_rro_rx_process(struct mt76_dev *mdev, void *data)
> goto next_page;
>
> qid = t->qid;
> - buf = t->ptr;
> + buf = t->page_pool_buf;
> q = &mdev->q_rx[qid];
> dma_sync_single_for_cpu(mdev->dma_dev, t->dma_addr,
> SKB_WITH_OVERHEAD(q->buf_size),
> page_pool_get_dma_dir(q->page_pool));
>
> t->dma_addr = 0;
> - t->ptr = NULL;
> + t->page_pool_buf = NULL;
> mt76_put_rxwi(mdev, t);
> if (!buf)
> goto next_page;
> diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c
> index 22f9690634c9..665156a7ea65 100644
> --- a/drivers/net/wireless/mediatek/mt76/tx.c
> +++ b/drivers/net/wireless/mediatek/mt76/tx.c
> @@ -899,7 +899,7 @@ int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
> token = idr_alloc(&dev->rx_token, t, 0, dev->rx_token_size,
> GFP_ATOMIC);
> if (token >= 0) {
> - t->ptr = ptr;
> + t->page_pool_buf = ptr;
> t->dma_addr = phys;
> }
> spin_unlock_bh(&dev->rx_token_lock);
> diff --git a/drivers/net/wireless/mediatek/mt76/wed.c b/drivers/net/wireless/mediatek/mt76/wed.c
> index ed657d952de2..e1cf81d722b8 100644
> --- a/drivers/net/wireless/mediatek/mt76/wed.c
> +++ b/drivers/net/wireless/mediatek/mt76/wed.c
> @@ -15,11 +15,11 @@ void mt76_wed_release_rx_buf(struct mtk_wed_device *wed)
> struct mt76_txwi_cache *t;
>
> t = mt76_rx_token_release(dev, i);
> - if (!t || !t->ptr)
> + if (!t || !t->page_pool_buf)
> continue;
>
> - mt76_put_page_pool_buf(t->ptr, false);
> - t->ptr = NULL;
> + mt76_put_page_pool_buf(t->page_pool_buf, false);
> + t->page_pool_buf = NULL;
>
> mt76_put_rxwi(dev, t);
> }
> --
> 2.45.2
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-mediatek/attachments/20260709/35010eec/attachment-0001.sig>
More information about the Linux-mediatek
mailing list