9bc948015d245c1a613c06cf2c6cca48f397a0ec
[openwrt/staging/jow.git] /
1 From db2c7b353db3b3f71b55f9ff4627d8a786446fbe Mon Sep 17 00:00:00 2001
2 From: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
3 Date: Thu, 22 Apr 2021 22:21:06 -0700
4 Subject: [PATCH] net: ethernet: mtk_eth_soc: rework NAPI callbacks
5
6 Use napi_complete_done to communicate total TX and RX work done to NAPI.
7 Count total RX work up instead of remaining work down for clarity.
8 Remove unneeded local variables for clarity. Use do {} while instead of
9 goto for clarity.
10
11 Suggested-by: Jakub Kicinski <kuba@kernel.org>
12 Signed-off-by: Ilya Lipnitskiy <ilya.lipnitskiy@gmail.com>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 54 +++++++++------------
16 1 file changed, 24 insertions(+), 30 deletions(-)
17
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -1496,7 +1496,6 @@ static void mtk_handle_status_irq(struct
21 static int mtk_napi_tx(struct napi_struct *napi, int budget)
22 {
23 struct mtk_eth *eth = container_of(napi, struct mtk_eth, tx_napi);
24 - u32 status, mask;
25 int tx_done = 0;
26
27 if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
28 @@ -1505,21 +1504,19 @@ static int mtk_napi_tx(struct napi_struc
29 tx_done = mtk_poll_tx(eth, budget);
30
31 if (unlikely(netif_msg_intr(eth))) {
32 - status = mtk_r32(eth, eth->tx_int_status_reg);
33 - mask = mtk_r32(eth, eth->tx_int_mask_reg);
34 dev_info(eth->dev,
35 - "done tx %d, intr 0x%08x/0x%x\n",
36 - tx_done, status, mask);
37 + "done tx %d, intr 0x%08x/0x%x\n", tx_done,
38 + mtk_r32(eth, eth->tx_int_status_reg),
39 + mtk_r32(eth, eth->tx_int_mask_reg));
40 }
41
42 if (tx_done == budget)
43 return budget;
44
45 - status = mtk_r32(eth, eth->tx_int_status_reg);
46 - if (status & MTK_TX_DONE_INT)
47 + if (mtk_r32(eth, eth->tx_int_status_reg) & MTK_TX_DONE_INT)
48 return budget;
49
50 - if (napi_complete(napi))
51 + if (napi_complete_done(napi, tx_done))
52 mtk_tx_irq_enable(eth, MTK_TX_DONE_INT);
53
54 return tx_done;
55 @@ -1528,36 +1525,33 @@ static int mtk_napi_tx(struct napi_struc
56 static int mtk_napi_rx(struct napi_struct *napi, int budget)
57 {
58 struct mtk_eth *eth = container_of(napi, struct mtk_eth, rx_napi);
59 - u32 status, mask;
60 - int rx_done = 0;
61 - int remain_budget = budget;
62 + int rx_done_total = 0;
63
64 mtk_handle_status_irq(eth);
65
66 -poll_again:
67 - mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
68 - rx_done = mtk_poll_rx(napi, remain_budget, eth);
69 + do {
70 + int rx_done;
71
72 - if (unlikely(netif_msg_intr(eth))) {
73 - status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
74 - mask = mtk_r32(eth, MTK_PDMA_INT_MASK);
75 - dev_info(eth->dev,
76 - "done rx %d, intr 0x%08x/0x%x\n",
77 - rx_done, status, mask);
78 - }
79 - if (rx_done == remain_budget)
80 - return budget;
81 + mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
82 + rx_done = mtk_poll_rx(napi, budget - rx_done_total, eth);
83 + rx_done_total += rx_done;
84 +
85 + if (unlikely(netif_msg_intr(eth))) {
86 + dev_info(eth->dev,
87 + "done rx %d, intr 0x%08x/0x%x\n", rx_done,
88 + mtk_r32(eth, MTK_PDMA_INT_STATUS),
89 + mtk_r32(eth, MTK_PDMA_INT_MASK));
90 + }
91
92 - status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
93 - if (status & MTK_RX_DONE_INT) {
94 - remain_budget -= rx_done;
95 - goto poll_again;
96 - }
97 + if (rx_done_total == budget)
98 + return budget;
99 +
100 + } while (mtk_r32(eth, MTK_PDMA_INT_STATUS) & MTK_RX_DONE_INT);
101
102 - if (napi_complete(napi))
103 + if (napi_complete_done(napi, rx_done_total))
104 mtk_rx_irq_enable(eth, MTK_RX_DONE_INT);
105
106 - return rx_done + budget - remain_budget;
107 + return rx_done_total;
108 }
109
110 static int mtk_tx_alloc(struct mtk_eth *eth)