ebe1ee3d59a45ca0fc10ac9845150a1223122792
[openwrt/staging/blogic.git] /
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Fri, 20 May 2022 20:11:29 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: rely on txd_size in
4 mtk_tx_alloc/mtk_tx_clean
5
6 This is a preliminary patch to add mt7986 ethernet support.
7
8 Tested-by: Sam Shih <sam.shih@mediatek.com>
9 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Signed-off-by: David S. Miller <davem@davemloft.net>
11 ---
12
13 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
14 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
15 @@ -1625,8 +1625,10 @@ static int mtk_napi_rx(struct napi_struc
16
17 static int mtk_tx_alloc(struct mtk_eth *eth)
18 {
19 + const struct mtk_soc_data *soc = eth->soc;
20 struct mtk_tx_ring *ring = &eth->tx_ring;
21 - int i, sz = sizeof(*ring->dma);
22 + int i, sz = soc->txrx.txd_size;
23 + struct mtk_tx_dma *txd;
24
25 ring->buf = kcalloc(MTK_DMA_SIZE, sizeof(*ring->buf),
26 GFP_KERNEL);
27 @@ -1642,8 +1644,10 @@ static int mtk_tx_alloc(struct mtk_eth *
28 int next = (i + 1) % MTK_DMA_SIZE;
29 u32 next_ptr = ring->phys + next * sz;
30
31 - ring->dma[i].txd2 = next_ptr;
32 - ring->dma[i].txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
33 + txd = (void *)ring->dma + i * sz;
34 + txd->txd2 = next_ptr;
35 + txd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
36 + txd->txd4 = 0;
37 }
38
39 /* On MT7688 (PDMA only) this driver uses the ring->dma structs
40 @@ -1665,7 +1669,7 @@ static int mtk_tx_alloc(struct mtk_eth *
41 ring->dma_size = MTK_DMA_SIZE;
42 atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
43 ring->next_free = &ring->dma[0];
44 - ring->last_free = &ring->dma[MTK_DMA_SIZE - 1];
45 + ring->last_free = (void *)txd;
46 ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
47 ring->thresh = MAX_SKB_FRAGS;
48
49 @@ -1698,6 +1702,7 @@ no_tx_mem:
50
51 static void mtk_tx_clean(struct mtk_eth *eth)
52 {
53 + const struct mtk_soc_data *soc = eth->soc;
54 struct mtk_tx_ring *ring = &eth->tx_ring;
55 int i;
56
57 @@ -1710,17 +1715,15 @@ static void mtk_tx_clean(struct mtk_eth
58
59 if (ring->dma) {
60 dma_free_coherent(eth->dma_dev,
61 - MTK_DMA_SIZE * sizeof(*ring->dma),
62 - ring->dma,
63 - ring->phys);
64 + MTK_DMA_SIZE * soc->txrx.txd_size,
65 + ring->dma, ring->phys);
66 ring->dma = NULL;
67 }
68
69 if (ring->dma_pdma) {
70 dma_free_coherent(eth->dma_dev,
71 - MTK_DMA_SIZE * sizeof(*ring->dma_pdma),
72 - ring->dma_pdma,
73 - ring->phys_pdma);
74 + MTK_DMA_SIZE * soc->txrx.txd_size,
75 + ring->dma_pdma, ring->phys_pdma);
76 ring->dma_pdma = NULL;
77 }
78 }