From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Eason Lai <eason.lai@mediatek.com>
Cc: nbd@nbd.name, linux-wireless@vger.kernel.org,
linux-mediatek@lists.infradead.org, Yf.Luo@mediatek.com,
kun.wu@mediatek.com, deren.wu@mediatek.com,
sean.wang@mediatek.com, quan.zhou@mediatek.com,
ryder.lee@mediatek.com, leon.yen@mediatek.com,
litien.chang@mediatek.com, jb.tsai@mediatek.com
Subject: Re: [PATCH 1/3] wifi: mt76: Separate skb and page_pool_buf pointers in mt76_txwi_cache
Date: Thu, 9 Jul 2026 10:19:26 +0200 [thread overview]
Message-ID: <ak9Zjm-czxVIjrhX@lore-desk> (raw)
In-Reply-To: <20260709075558.1654164-2-eason.lai@mediatek.com>
[-- Attachment #1: Type: text/plain, Size: 6697 bytes --]
> From: Eason Lai <Eason.Lai@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@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
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-07-09 8:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 7:55 [PATCH 0/3] Fix TX performance degradation when IOMMU is enabled Eason Lai
2026-07-09 7:55 ` [PATCH 1/3] wifi: mt76: Separate skb and page_pool_buf pointers in mt76_txwi_cache Eason Lai
2026-07-09 8:19 ` Lorenzo Bianconi [this message]
2026-07-09 7:55 ` [PATCH 2/3] wifi: mt76: mt792x: Add TX page pool support for IOMMU-enabled systems Eason Lai
2026-07-09 8:27 ` Lorenzo Bianconi
2026-07-09 7:55 ` [PATCH 3/3] wifi: mt76: mt792x: Restrict TX page pool to MT8196 platform Eason Lai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ak9Zjm-czxVIjrhX@lore-desk \
--to=lorenzo@kernel.org \
--cc=Yf.Luo@mediatek.com \
--cc=deren.wu@mediatek.com \
--cc=eason.lai@mediatek.com \
--cc=jb.tsai@mediatek.com \
--cc=kun.wu@mediatek.com \
--cc=leon.yen@mediatek.com \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-wireless@vger.kernel.org \
--cc=litien.chang@mediatek.com \
--cc=nbd@nbd.name \
--cc=quan.zhou@mediatek.com \
--cc=ryder.lee@mediatek.com \
--cc=sean.wang@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox