0547d7874f3d10eac25ed61b93ac716651e45c3e
[openwrt/staging/xback.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 @@ -1635,8 +1635,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 @@ -1652,8 +1654,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 @@ -1675,7 +1679,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 @@ -1708,6 +1712,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 @@ -1720,17 +1725,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 }