8000a8759e5b5041672e31b40fb1bf323f4970ef
[openwrt/staging/linusw.git] /
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Mon, 18 Sep 2023 12:29:08 +0200
3 Subject: [PATCH] net: ethernet: mtk_wed: introduce mtk_wed_buf structure
4
5 Introduce mtk_wed_buf structure to store both virtual and physical
6 addresses allocated in mtk_wed_tx_buffer_alloc() routine. This is a
7 preliminary patch to add WED support for MT7988 SoC since it relies on a
8 different dma descriptor layout not storing page dma addresses.
9
10 Co-developed-by: Sujuan Chen <sujuan.chen@mediatek.com>
11 Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
12 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
13 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
14 ---
15
16 --- a/drivers/net/ethernet/mediatek/mtk_wed.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
18 @@ -299,9 +299,9 @@ out:
19 static int
20 mtk_wed_tx_buffer_alloc(struct mtk_wed_device *dev)
21 {
22 + struct mtk_wed_buf *page_list;
23 struct mtk_wdma_desc *desc;
24 dma_addr_t desc_phys;
25 - void **page_list;
26 int token = dev->wlan.token_start;
27 int ring_size;
28 int n_pages;
29 @@ -342,7 +342,8 @@ mtk_wed_tx_buffer_alloc(struct mtk_wed_d
30 return -ENOMEM;
31 }
32
33 - page_list[page_idx++] = page;
34 + page_list[page_idx].p = page;
35 + page_list[page_idx++].phy_addr = page_phys;
36 dma_sync_single_for_cpu(dev->hw->dev, page_phys, PAGE_SIZE,
37 DMA_BIDIRECTIONAL);
38
39 @@ -386,8 +387,8 @@ mtk_wed_tx_buffer_alloc(struct mtk_wed_d
40 static void
41 mtk_wed_free_tx_buffer(struct mtk_wed_device *dev)
42 {
43 + struct mtk_wed_buf *page_list = dev->tx_buf_ring.pages;
44 struct mtk_wdma_desc *desc = dev->tx_buf_ring.desc;
45 - void **page_list = dev->tx_buf_ring.pages;
46 int page_idx;
47 int i;
48
49 @@ -399,13 +400,12 @@ mtk_wed_free_tx_buffer(struct mtk_wed_de
50
51 for (i = 0, page_idx = 0; i < dev->tx_buf_ring.size;
52 i += MTK_WED_BUF_PER_PAGE) {
53 - void *page = page_list[page_idx++];
54 - dma_addr_t buf_addr;
55 + dma_addr_t buf_addr = page_list[page_idx].phy_addr;
56 + void *page = page_list[page_idx++].p;
57
58 if (!page)
59 break;
60
61 - buf_addr = le32_to_cpu(desc[i].buf0);
62 dma_unmap_page(dev->hw->dev, buf_addr, PAGE_SIZE,
63 DMA_BIDIRECTIONAL);
64 __free_page(page);
65 --- a/include/linux/soc/mediatek/mtk_wed.h
66 +++ b/include/linux/soc/mediatek/mtk_wed.h
67 @@ -76,6 +76,11 @@ struct mtk_wed_wo_rx_stats {
68 __le32 rx_drop_cnt;
69 };
70
71 +struct mtk_wed_buf {
72 + void *p;
73 + dma_addr_t phy_addr;
74 +};
75 +
76 struct mtk_wed_device {
77 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
78 const struct mtk_wed_ops *ops;
79 @@ -97,7 +102,7 @@ struct mtk_wed_device {
80
81 struct {
82 int size;
83 - void **pages;
84 + struct mtk_wed_buf *pages;
85 struct mtk_wdma_desc *desc;
86 dma_addr_t desc_phys;
87 } tx_buf_ring;