1ee9bb52a77695939c5035ee2e02a2265248662a
[openwrt/staging/xback.git] /
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
4
5 Simplify the code converting {tx,rx} ring dma pointer to void
6
7 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
8 Signed-off-by: David S. Miller <davem@davemloft.net>
9 ---
10
11 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
12 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
13 @@ -957,18 +957,15 @@ static int mtk_init_fq_dma(struct mtk_et
14 return 0;
15 }
16
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)
19 {
20 - void *ret = ring->dma;
21 -
22 - return ret + (desc - ring->phys);
23 + return ring->dma + (desc - ring->phys);
24 }
25
26 static struct mtk_tx_buf *mtk_desc_to_tx_buf(struct mtk_tx_ring *ring,
27 - struct mtk_tx_dma *txd,
28 - u32 txd_size)
29 + void *txd, u32 txd_size)
30 {
31 - int idx = ((void *)txd - (void *)ring->dma) / txd_size;
32 + int idx = (txd - ring->dma) / txd_size;
33
34 return &ring->buf[idx];
35 }
36 @@ -976,13 +973,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)
39 {
40 - return ring->dma_pdma - ring->dma + dma;
41 + return ring->dma_pdma - (struct mtk_tx_dma *)ring->dma + dma;
42 }
43
44 -static int txd_to_idx(struct mtk_tx_ring *ring, struct mtk_tx_dma *dma,
45 - u32 txd_size)
46 +static int txd_to_idx(struct mtk_tx_ring *ring, void *dma, u32 txd_size)
47 {
48 - return ((void *)dma - (void *)ring->dma) / txd_size;
49 + return (dma - ring->dma) / txd_size;
50 }
51
52 static void mtk_tx_unmap(struct mtk_eth *eth, struct mtk_tx_buf *tx_buf,
53 @@ -1399,7 +1395,7 @@ static struct mtk_rx_ring *mtk_get_rx_ri
54
55 ring = &eth->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;
61 return ring;
62 @@ -1451,7 +1447,7 @@ static int mtk_poll_rx(struct napi_struc
63 goto rx_done;
64
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];
69
70 if (!mtk_rx_get_desc(eth, &trxd, rxd))
71 @@ -1658,7 +1654,7 @@ static int mtk_poll_tx_pdma(struct mtk_e
72
73 mtk_tx_unmap(eth, tx_buf, true);
74
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);
79
80 @@ -1803,7 +1799,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;
83
84 - txd = (void *)ring->dma + i * sz;
85 + txd = ring->dma + i * sz;
86 txd->txd2 = next_ptr;
87 txd->txd3 = TX_DMA_LS0 | TX_DMA_OWNER_CPU;
88 txd->txd4 = 0;
89 @@ -1833,7 +1829,7 @@ static int mtk_tx_alloc(struct mtk_eth *
90
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 @@ -1948,7 +1944,7 @@ static int mtk_rx_alloc(struct mtk_eth *
99 if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
100 return -ENOMEM;
101
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;
105
106 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
107 @@ -2010,7 +2006,7 @@ static void mtk_rx_clean(struct mtk_eth
108 if (!ring->data[i])
109 continue;
110
111 - rxd = (void *)ring->dma + i * eth->soc->txrx.rxd_size;
112 + rxd = ring->dma + i * eth->soc->txrx.rxd_size;
113 if (!rxd->rxd1)
114 continue;
115
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 {
119 * are present
120 */
121 struct mtk_tx_ring {
122 - struct mtk_tx_dma *dma;
123 + void *dma;
124 struct mtk_tx_buf *buf;
125 dma_addr_t phys;
126 struct mtk_tx_dma *next_free;
127 @@ -719,7 +719,7 @@ enum mtk_rx_flags {
128 * @calc_idx: The current head of ring
129 */
130 struct mtk_rx_ring {
131 - struct mtk_rx_dma *dma;
132 + void *dma;
133 u8 **data;
134 dma_addr_t phys;
135 u16 frag_size;