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
6 This is a preliminary patch to add mt7986 ethernet support.
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>
13 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
14 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
15 @@ -1624,8 +1624,10 @@ static int mtk_napi_rx(struct napi_struc
17 static int mtk_tx_alloc(struct mtk_eth *eth)
19 + const struct mtk_soc_data *soc = eth->soc;
20 struct mtk_tx_ring *ring = ð->tx_ring;
21 - int i, sz = sizeof(*ring->dma);
22 + int i, sz = soc->txrx.txd_size;
23 + struct mtk_tx_dma *txd;
25 ring->buf = kcalloc(MTK_DMA_SIZE, sizeof(*ring->buf),
27 @@ -1641,8 +1643,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;
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;
39 /* On MT7688 (PDMA only) this driver uses the ring->dma structs
40 @@ -1664,7 +1668,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;
49 @@ -1697,6 +1701,7 @@ no_tx_mem:
51 static void mtk_tx_clean(struct mtk_eth *eth)
53 + const struct mtk_soc_data *soc = eth->soc;
54 struct mtk_tx_ring *ring = ð->tx_ring;
57 @@ -1709,17 +1714,15 @@ static void mtk_tx_clean(struct mtk_eth
60 dma_free_coherent(eth->dma_dev,
61 - MTK_DMA_SIZE * sizeof(*ring->dma),
64 + MTK_DMA_SIZE * soc->txrx.txd_size,
65 + ring->dma, ring->phys);
70 dma_free_coherent(eth->dma_dev,
71 - MTK_DMA_SIZE * sizeof(*ring->dma_pdma),
74 + MTK_DMA_SIZE * soc->txrx.txd_size,
75 + ring->dma_pdma, ring->phys_pdma);
76 ring->dma_pdma = NULL;