[RFC v3 17/18] mt76: use netmem descriptor and APIs for page pool

Byungchul Park
2025-05-29T03:11:11Z

To simplify struct page, the effort to separate its own descriptor from
struct page is required and the work for page pool is on going.

Use netmem descriptor and APIs for page pool in mt76 code.

Signed-off-by: Byungchul Park <byungchul@sk.com>
Reviewed-by: Mina Almasry <almasrymina@google.com>
---
drivers/net/wireless/mediatek/mt76/dma.c | 6 ++---
drivers/net/wireless/mediatek/mt76/mt76.h | 12 +++++-----
.../net/wireless/mediatek/mt76/sdio_txrx.c | 24 +++++++++----------
drivers/net/wireless/mediatek/mt76/usb.c | 10 ++++----
4 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
index 35b4ec91979e..41b529b95877 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/dma.c
@@ -820,10 +820,10 @@ mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data,
int nr_frags = shinfo->nr_frags;

if (nr_frags < ARRAY_SIZE(shinfo->frags)) {
- struct page *page = virt_to_head_page(data);
- int offset = data - page_address(page) + q->buf_offset;
+ netmem_ref netmem = virt_to_head_netmem(data);
+ int offset = data - netmem_address(netmem) + q->buf_offset;

- skb_add_rx_frag(skb, nr_frags, page, offset, len, q->buf_size);
+ skb_add_rx_frag_netmem(skb, nr_frags, netmem, offset, len, q->buf_size);
} else {
mt76_put_page_pool_buf(data, allow_direct);
}
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 5f8d81cda6cd..16d09b6d8270 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -1795,21 +1795,21 @@ int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
int mt76_create_page_pool(struct mt76_dev *dev, struct mt76_queue *q);
static inline void mt76_put_page_pool_buf(void *buf, bool allow_direct)
{
- struct page *page = virt_to_head_page(buf);
+ netmem_ref netmem = virt_to_head_netmem(buf);

- page_pool_put_full_page(page->pp, page, allow_direct);
+ page_pool_put_full_netmem(netmem_get_pp(netmem), netmem, allow_direct);
}

static inline void *
mt76_get_page_pool_buf(struct mt76_queue *q, u32 *offset, u32 size)
{
- struct page *page;
+ netmem_ref netmem;

- page = page_pool_dev_alloc_frag(q->page_pool, offset, size);
- if (!page)
+ netmem = page_pool_dev_alloc_netmem(q->page_pool, offset, &size);
+ if (!netmem)
return NULL;

- return page_address(page) + *offset;
+ return netmem_address(netmem) + *offset;
}

static inline void mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)
diff --git a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
index 0a927a7313a6..b1d89b6f663d 100644
--- a/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
+++ b/drivers/net/wireless/mediatek/mt76/sdio_txrx.c
@@ -68,14 +68,14 @@ mt76s_build_rx_skb(void *data, int data_len, int buf_len)

skb_put_data(skb, data, len);
if (data_len > len) {
- struct page *page;
+ netmem_ref netmem;

data += len;
- page = virt_to_head_page(data);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- page, data - page_address(page),
- data_len - len, buf_len);
- get_page(page);
+ netmem = virt_to_head_netmem(data);
+ skb_add_rx_frag_netmem(skb, skb_shinfo(skb)->nr_frags,
+ netmem, data - netmem_address(netmem),
+ data_len - len, buf_len);
+ get_netmem(netmem);
}

return skb;
@@ -88,7 +88,7 @@ mt76s_rx_run_queue(struct mt76_dev *dev, enum mt76_rxq_id qid,
struct mt76_queue *q = &dev->q_rx[qid];
struct mt76_sdio *sdio = &dev->sdio;
int len = 0, err, i;
- struct page *page;
+ netmem_ref netmem;
u8 *buf, *end;

for (i = 0; i < intr->rx.num[qid]; i++)
@@ -100,11 +100,11 @@ mt76s_rx_run_queue(struct mt76_dev *dev, enum mt76_rxq_id qid,
if (len > sdio->func->cur_blksize)
len = roundup(len, sdio->func->cur_blksize);

- page = __dev_alloc_pages(GFP_KERNEL, get_order(len));
- if (!page)
+ netmem = page_to_netmem(__dev_alloc_pages(GFP_KERNEL, get_order(len)));
+ if (!netmem)
return -ENOMEM;

- buf = page_address(page);
+ buf = netmem_address(netmem);

sdio_claim_host(sdio->func);
err = sdio_readsb(sdio->func, buf, MCR_WRDR(qid), len);
@@ -112,7 +112,7 @@ mt76s_rx_run_queue(struct mt76_dev *dev, enum mt76_rxq_id qid,

if (err < 0) {
dev_err(dev->dev, "sdio read data failed:%d\n", err);
- put_page(page);
+ put_netmem(netmem);
return err;
}

@@ -140,7 +140,7 @@ mt76s_rx_run_queue(struct mt76_dev *dev, enum mt76_rxq_id qid,
}
buf += round_up(len + 4, 4);
}
- put_page(page);
+ put_netmem(netmem);

spin_lock_bh(&q->lock);
q->head = (q->head + i) % q->ndesc;
diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
index f9e67b8c3b3c..1ea80c87a839 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -478,7 +478,7 @@ mt76u_build_rx_skb(struct mt76_dev *dev, void *data,

head_room = drv_flags & MT_DRV_RX_DMA_HDR ? 0 : MT_DMA_HDR_LEN;
if (SKB_WITH_OVERHEAD(buf_size) < head_room + len) {
- struct page *page;
+ netmem_ref netmem;

/* slow path, not enough space for data and
* skb_shared_info
@@ -489,10 +489,10 @@ mt76u_build_rx_skb(struct mt76_dev *dev, void *data,

skb_put_data(skb, data + head_room, MT_SKB_HEAD_LEN);
data += head_room + MT_SKB_HEAD_LEN;
- page = virt_to_head_page(data);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- page, data - page_address(page),
- len - MT_SKB_HEAD_LEN, buf_size);
+ netmem = virt_to_head_netmem(data);
+ skb_add_rx_frag_netmem(skb, skb_shinfo(skb)->nr_frags,
+ netmem, data - netmem_address(netmem),
+ len - MT_SKB_HEAD_LEN, buf_size);

return skb;
}
--
2.17.1