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
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
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>
15 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 54 +++++++++------------
16 1 file changed, 24 insertions(+), 30 deletions(-)
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -1532,7 +1532,6 @@ static void mtk_handle_status_irq(struct
21 static int mtk_napi_tx(struct napi_struct *napi, int budget)
23 struct mtk_eth *eth = container_of(napi, struct mtk_eth, tx_napi);
27 if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
28 @@ -1541,21 +1540,19 @@ static int mtk_napi_tx(struct napi_struc
29 tx_done = mtk_poll_tx(eth, budget);
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);
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));
42 if (tx_done == budget)
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)
50 - if (napi_complete(napi))
51 + if (napi_complete_done(napi, tx_done))
52 mtk_tx_irq_enable(eth, MTK_TX_DONE_INT);
55 @@ -1564,36 +1561,33 @@ static int mtk_napi_tx(struct napi_struc
56 static int mtk_napi_rx(struct napi_struct *napi, int budget)
58 struct mtk_eth *eth = container_of(napi, struct mtk_eth, rx_napi);
61 - int remain_budget = budget;
62 + int rx_done_total = 0;
64 mtk_handle_status_irq(eth);
67 - mtk_w32(eth, MTK_RX_DONE_INT, MTK_PDMA_INT_STATUS);
68 - rx_done = mtk_poll_rx(napi, remain_budget, eth);
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);
76 - "done rx %d, intr 0x%08x/0x%x\n",
77 - rx_done, status, mask);
79 - if (rx_done == remain_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;
85 + if (unlikely(netif_msg_intr(eth))) {
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));
92 - status = mtk_r32(eth, MTK_PDMA_INT_STATUS);
93 - if (status & MTK_RX_DONE_INT) {
94 - remain_budget -= rx_done;
97 + if (rx_done_total == budget)
100 + } while (mtk_r32(eth, MTK_PDMA_INT_STATUS) & MTK_RX_DONE_INT);
102 - if (napi_complete(napi))
103 + if (napi_complete_done(napi, rx_done_total))
104 mtk_rx_irq_enable(eth, MTK_RX_DONE_INT);
106 - return rx_done + budget - remain_budget;
107 + return rx_done_total;
110 static int mtk_tx_alloc(struct mtk_eth *eth)