1 From 3bc8e0aff23be0526af0dbc7973a8866a08d73f1 Mon Sep 17 00:00:00 2001
2 From: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
3 Date: Thu, 22 Apr 2021 22:21:08 -0700
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: use iopoll.h macro for DMA init
6 Replace a tight busy-wait loop without a pause with a standard
7 readx_poll_timeout_atomic routine with a 5 us poll period.
9 Tested by booting a MT7621 device to ensure the driver initializes
12 Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
13 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
14 Signed-off-by: David S. Miller <davem@davemloft.net>
16 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 29 +++++++++------------
17 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +-
18 2 files changed, 14 insertions(+), 17 deletions(-)
20 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
21 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
22 @@ -2033,25 +2033,22 @@ static int mtk_set_features(struct net_d
23 /* wait for DMA to finish whatever it is doing before we start using it again */
24 static int mtk_dma_busy_wait(struct mtk_eth *eth)
26 - unsigned long t_start = jiffies;
32 - if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA)) {
33 - if (!(mtk_r32(eth, MTK_QDMA_GLO_CFG) &
34 - (MTK_RX_DMA_BUSY | MTK_TX_DMA_BUSY)))
37 - if (!(mtk_r32(eth, MTK_PDMA_GLO_CFG) &
38 - (MTK_RX_DMA_BUSY | MTK_TX_DMA_BUSY)))
41 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
42 + reg = MTK_QDMA_GLO_CFG;
44 + reg = MTK_PDMA_GLO_CFG;
46 - if (time_after(jiffies, t_start + MTK_DMA_BUSY_TIMEOUT))
49 + ret = readx_poll_timeout_atomic(__raw_readl, eth->base + reg, val,
50 + !(val & (MTK_RX_DMA_BUSY | MTK_TX_DMA_BUSY)),
51 + 5, MTK_DMA_BUSY_TIMEOUT_US);
53 + dev_err(eth->dev, "DMA init timeout\n");
55 - dev_err(eth->dev, "DMA init timeout\n");
60 static int mtk_dma_init(struct mtk_eth *eth)
61 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
62 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
64 #define MTK_TX_DMA_BUSY BIT(1)
65 #define MTK_RX_DMA_EN BIT(2)
66 #define MTK_TX_DMA_EN BIT(0)
67 -#define MTK_DMA_BUSY_TIMEOUT HZ
68 +#define MTK_DMA_BUSY_TIMEOUT_US 1000000
70 /* QDMA Reset Index Register */
71 #define MTK_QDMA_RST_IDX 0x1A08