1f4fa1dfb50e3b29f7b06f098650212ab532f77b
[openwrt/staging/pepe2k.git] /
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Fri, 20 May 2022 20:11:34 +0200
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: rely on rxd_size field in
4 mtk_rx_alloc/mtk_rx_clean
5
6 Remove mtk_rx_dma structure layout dependency in mtk_rx_alloc/mtk_rx_clean.
7 Initialize to 0 rxd3 and rxd4 in mtk_rx_alloc.
8 This is a preliminary patch to add mt7986 ethernet support.
9
10 Tested-by: Sam Shih <sam.shih@mediatek.com>
11 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14
15 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
16 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 @@ -1784,18 +1784,25 @@ static int mtk_rx_alloc(struct mtk_eth *
18 return -ENOMEM;
19
20 for (i = 0; i < rx_dma_size; i++) {
21 + struct mtk_rx_dma *rxd;
22 +
23 dma_addr_t dma_addr = dma_map_single(eth->dma_dev,
24 ring->data[i] + NET_SKB_PAD + eth->ip_align,
25 ring->buf_size,
26 DMA_FROM_DEVICE);
27 if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
28 return -ENOMEM;
29 - ring->dma[i].rxd1 = (unsigned int)dma_addr;
30 +
31 + rxd = (void *)ring->dma + i * eth->soc->txrx.rxd_size;
32 + rxd->rxd1 = (unsigned int)dma_addr;
33
34 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
35 - ring->dma[i].rxd2 = RX_DMA_LSO;
36 + rxd->rxd2 = RX_DMA_LSO;
37 else
38 - ring->dma[i].rxd2 = RX_DMA_PLEN0(ring->buf_size);
39 + rxd->rxd2 = RX_DMA_PLEN0(ring->buf_size);
40 +
41 + rxd->rxd3 = 0;
42 + rxd->rxd4 = 0;
43 }
44 ring->dma_size = rx_dma_size;
45 ring->calc_idx_update = false;
46 @@ -1820,14 +1827,17 @@ static void mtk_rx_clean(struct mtk_eth
47
48 if (ring->data && ring->dma) {
49 for (i = 0; i < ring->dma_size; i++) {
50 + struct mtk_rx_dma *rxd;
51 +
52 if (!ring->data[i])
53 continue;
54 - if (!ring->dma[i].rxd1)
55 +
56 + rxd = (void *)ring->dma + i * eth->soc->txrx.rxd_size;
57 + if (!rxd->rxd1)
58 continue;
59 - dma_unmap_single(eth->dma_dev,
60 - ring->dma[i].rxd1,
61 - ring->buf_size,
62 - DMA_FROM_DEVICE);
63 +
64 + dma_unmap_single(eth->dma_dev, rxd->rxd1,
65 + ring->buf_size, DMA_FROM_DEVICE);
66 skb_free_frag(ring->data[i]);
67 }
68 kfree(ring->data);