09b8b3afb972a0522f4525a6176b619cac60ac07
[openwrt/staging/blogic.git] /
1 From 816ac3e6e67bdd78d86226c6eb53619780750e92 Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Thu, 22 Apr 2021 22:21:04 -0700
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: only read the full RX descriptor
5 if DMA is done
6
7 Uncached memory access is expensive, and there is no need to access all
8 descriptor words if we can't process them anyway
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 12 ++++++++----
15 1 file changed, 8 insertions(+), 4 deletions(-)
16
17 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 @@ -798,13 +798,18 @@ static inline int mtk_max_buf_size(int f
20 return buf_size;
21 }
22
23 -static inline void mtk_rx_get_desc(struct mtk_rx_dma *rxd,
24 +static inline bool mtk_rx_get_desc(struct mtk_rx_dma *rxd,
25 struct mtk_rx_dma *dma_rxd)
26 {
27 - rxd->rxd1 = READ_ONCE(dma_rxd->rxd1);
28 rxd->rxd2 = READ_ONCE(dma_rxd->rxd2);
29 + if (!(rxd->rxd2 & RX_DMA_DONE))
30 + return false;
31 +
32 + rxd->rxd1 = READ_ONCE(dma_rxd->rxd1);
33 rxd->rxd3 = READ_ONCE(dma_rxd->rxd3);
34 rxd->rxd4 = READ_ONCE(dma_rxd->rxd4);
35 +
36 + return true;
37 }
38
39 /* the qdma core needs scratch memory to be setup */
40 @@ -1276,8 +1281,7 @@ static int mtk_poll_rx(struct napi_struc
41 rxd = &ring->dma[idx];
42 data = ring->data[idx];
43
44 - mtk_rx_get_desc(&trxd, rxd);
45 - if (!(trxd.rxd2 & RX_DMA_DONE))
46 + if (!mtk_rx_get_desc(&trxd, rxd))
47 break;
48
49 /* find out which mac the packet come from. values start at 1 */