1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Fri, 20 May 2022 20:11:37 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: convert ring dma pointer to void
5 Simplify the code converting {tx,rx} ring dma pointer to void
7 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
8 Signed-off-by: David S. Miller <davem@davemloft.net>
11 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
12 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
13 @@ -947,18 +947,15 @@ static int mtk_init_fq_dma(struct mtk_et
17 -static inline void *mtk_qdma_phys_to_virt(struct mtk_tx_ring *ring, u32 desc)
18 +static void *mtk_qdma_phys_to_virt(struct mtk_tx_ring *ring, u32 desc)
20 - void *ret = ring->dma;
22 - return ret + (desc - ring->phys);
23 + return ring->dma + (desc - ring->phys);
26 static struct mtk_tx_buf *mtk_desc_to_tx_buf(struct mtk_tx_ring *ring,
27 - struct mtk_tx_dma *txd,
29 + void *txd, u32 txd_size)
31 - int idx = ((void *)txd - (void *)ring->dma) / txd_size;
32 + int idx = (txd - ring->dma) / txd_size;
34 return &ring->buf[idx];
36 @@ -966,13 +963,12 @@ static struct mtk_tx_buf *mtk_desc_to_tx
37 static struct mtk_tx_dma *qdma_to_pdma(struct mtk_tx_ring *ring,
38 struct mtk_tx_dma *dma)
40 - return ring->dma_pdma - ring->dma + dma;
41 + return ring->dma_pdma - (struct mtk_tx_dma *)ring->dma + dma;
44 -static int txd_to_idx(struct mtk_tx_ring *ring, struct mtk_tx_dma *dma,
46 +static int txd_to_idx(struct mtk_tx_ring *ring, void *dma, u32 txd_size)
48 - return ((void *)dma - (void *)ring->dma) / txd_size;
49 + return (dma - ring->dma) / txd_size;
52 static void mtk_tx_unmap(struct mtk_eth *eth, struct mtk_tx_buf *tx_buf,
53 @@ -1389,7 +1385,7 @@ static struct mtk_rx_ring *mtk_get_rx_ri
55 ring = ð->rx_ring[i];
56 idx = NEXT_DESP_IDX(ring->calc_idx, ring->dma_size);
57 - rxd = (void *)ring->dma + idx * eth->soc->txrx.rxd_size;
58 + rxd = ring->dma + idx * eth->soc->txrx.rxd_size;
59 if (rxd->rxd2 & RX_DMA_DONE) {
60 ring->calc_idx_update = true;
62 @@ -1441,7 +1437,7 @@ static int mtk_poll_rx(struct napi_struc
65 idx = NEXT_DESP_IDX(ring->calc_idx, ring->dma_size);
66 - rxd = (void *)ring->dma + idx * eth->soc->txrx.rxd_size;
67 + rxd = ring->dma + idx * eth->soc->txrx.rxd_size;
68 data = ring->data[idx];
70 if (!mtk_rx_get_desc(eth, &trxd, rxd))
71 @@ -1648,7 +1644,7 @@ static int mtk_poll_tx_pdma(struct mtk_e
73 mtk_tx_unmap(eth, tx_buf, true);
75 - desc = (void *)ring->dma + cpu * eth->soc->txrx.txd_size;
76 + desc = ring->dma + cpu * eth->soc->txrx.txd_size;
77 ring->last_free = desc;
78 atomic_inc(&ring->free_count);
80 @@ -1793,7 +1789,7 @@ static int mtk_tx_alloc(struct mtk_eth *
81 int next = (i + 1) % MTK_DMA_SIZE;
82 u32 next_ptr = ring->phys + next * sz;
84 - txd = (void *)ring->dma + i * sz;
85 + txd = ring->dma + i * sz;
87 txd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
89 @@ -1823,7 +1819,7 @@ static int mtk_tx_alloc(struct mtk_eth *
91 ring->dma_size = MTK_DMA_SIZE;
92 atomic_set(&ring->free_count, MTK_DMA_SIZE - 2);
93 - ring->next_free = &ring->dma[0];
94 + ring->next_free = ring->dma;
95 ring->last_free = (void *)txd;
96 ring->last_free_ptr = (u32)(ring->phys + ((MTK_DMA_SIZE - 1) * sz));
97 ring->thresh = MAX_SKB_FRAGS;
98 @@ -1938,7 +1934,7 @@ static int mtk_rx_alloc(struct mtk_eth *
99 if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
102 - rxd = (void *)ring->dma + i * eth->soc->txrx.rxd_size;
103 + rxd = ring->dma + i * eth->soc->txrx.rxd_size;
104 rxd->rxd1 = (unsigned int)dma_addr;
106 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
107 @@ -2000,7 +1996,7 @@ static void mtk_rx_clean(struct mtk_eth
111 - rxd = (void *)ring->dma + i * eth->soc->txrx.rxd_size;
112 + rxd = ring->dma + i * eth->soc->txrx.rxd_size;
116 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
117 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
118 @@ -689,7 +689,7 @@ struct mtk_tx_buf {
122 - struct mtk_tx_dma *dma;
124 struct mtk_tx_buf *buf;
126 struct mtk_tx_dma *next_free;
127 @@ -719,7 +719,7 @@ enum mtk_rx_flags {
128 * @calc_idx: The current head of ring
131 - struct mtk_rx_dma *dma;