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
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.
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>
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 *
20 for (i = 0; i < rx_dma_size; i++) {
21 + struct mtk_rx_dma *rxd;
23 dma_addr_t dma_addr = dma_map_single(eth->dma_dev,
24 ring->data[i] + NET_SKB_PAD + eth->ip_align,
27 if (unlikely(dma_mapping_error(eth->dma_dev, dma_addr)))
29 - ring->dma[i].rxd1 = (unsigned int)dma_addr;
31 + rxd = (void *)ring->dma + i * eth->soc->txrx.rxd_size;
32 + rxd->rxd1 = (unsigned int)dma_addr;
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;
38 - ring->dma[i].rxd2 = RX_DMA_PLEN0(ring->buf_size);
39 + rxd->rxd2 = RX_DMA_PLEN0(ring->buf_size);
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
48 if (ring->data && ring->dma) {
49 for (i = 0; i < ring->dma_size; i++) {
50 + struct mtk_rx_dma *rxd;
54 - if (!ring->dma[i].rxd1)
56 + rxd = (void *)ring->dma + i * eth->soc->txrx.rxd_size;
59 - dma_unmap_single(eth->dma_dev,
64 + dma_unmap_single(eth->dma_dev, rxd->rxd1,
65 + ring->buf_size, DMA_FROM_DEVICE);
66 skb_free_frag(ring->data[i]);