Re: [PATCH] net-next: mediatek: add support for IRQ grouping

2016-04-13 Thread David Miller
From: John Crispin 
Date: Thu,  7 Apr 2016 20:24:59 +0200

> The ethernet core has 3 IRQs. Using the IRQ grouping registers we are able
> to separate TX and RX IRQs, which allows us to service them on separate
> cores. This patch splits the IRQ handler into 2 separate functions, one
> for TX and another for RX. The TX housekeeping is split out of the NAPI
> handler. Instead we use a tasklet to handle housekeeping.
> 
> Signed-off-by: John Crispin 

Don't do this with tasklets.

Do your TX reclaim in a NAPI poll just like the RX side.


[PATCH] net-next: mediatek: add support for IRQ grouping

2016-04-07 Thread John Crispin
The ethernet core has 3 IRQs. Using the IRQ grouping registers we are able
to separate TX and RX IRQs, which allows us to service them on separate
cores. This patch splits the IRQ handler into 2 separate functions, one
for TX and another for RX. The TX housekeeping is split out of the NAPI
handler. Instead we use a tasklet to handle housekeeping.

Signed-off-by: John Crispin 
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c |  115 +--
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |   12 ++-
 2 files changed, 86 insertions(+), 41 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c 
b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 8163047..6387516 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -756,7 +756,7 @@ drop:
 }
 
 static int mtk_poll_rx(struct napi_struct *napi, int budget,
-  struct mtk_eth *eth, u32 rx_intr)
+  struct mtk_eth *eth)
 {
struct mtk_rx_ring *ring = >rx_ring;
int idx = ring->calc_idx;
@@ -842,12 +842,12 @@ release_desc:
}
 
if (done < budget)
-   mtk_w32(eth, rx_intr, MTK_QMTK_INT_STATUS);
+   mtk_w32(eth, MTK_RX_DONE_INT, MTK_QMTK_INT_STATUS);
 
return done;
 }
 
-static int mtk_poll_tx(struct mtk_eth *eth, int budget, bool *tx_again)
+static int mtk_poll_tx(struct mtk_eth *eth, int budget)
 {
struct mtk_tx_ring *ring = >tx_ring;
struct mtk_tx_dma *desc;
@@ -910,9 +910,7 @@ static int mtk_poll_tx(struct mtk_eth *eth, int budget, 
bool *tx_again)
}
 
/* read hw index again make sure no new tx packet */
-   if (cpu != dma || cpu != mtk_r32(eth, MTK_QTX_DRX_PTR))
-   *tx_again = true;
-   else
+   if (cpu == dma && cpu == mtk_r32(eth, MTK_QTX_DRX_PTR))
mtk_w32(eth, MTK_TX_DONE_INT, MTK_QMTK_INT_STATUS);
 
if (!total)
@@ -924,27 +922,27 @@ static int mtk_poll_tx(struct mtk_eth *eth, int budget, 
bool *tx_again)
return total;
 }
 
+static void mtk_clean_tx_tasklet(unsigned long arg)
+{
+   struct mtk_eth *eth = (struct mtk_eth *)arg;
+
+   if (mtk_poll_tx(eth, MTK_NAPI_WEIGHT) > 0)
+   tasklet_schedule(>tx_clean_tasklet);
+   else
+   mtk_irq_enable(eth, MTK_TX_DONE_INT);
+}
+
 static int mtk_poll(struct napi_struct *napi, int budget)
 {
struct mtk_eth *eth = container_of(napi, struct mtk_eth, rx_napi);
-   u32 status, status2, mask, tx_intr, rx_intr, status_intr;
-   int tx_done, rx_done;
-   bool tx_again = false;
+   u32 status, status2, mask, status_intr;
+   int rx_done = 0;
 
status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
status2 = mtk_r32(eth, MTK_INT_STATUS2);
-   tx_intr = MTK_TX_DONE_INT;
-   rx_intr = MTK_RX_DONE_INT;
status_intr = (MTK_GDM1_AF | MTK_GDM2_AF);
-   tx_done = 0;
-   rx_done = 0;
-   tx_again = 0;
 
-   if (status & tx_intr)
-   tx_done = mtk_poll_tx(eth, budget, _again);
-
-   if (status & rx_intr)
-   rx_done = mtk_poll_rx(napi, budget, eth, rx_intr);
+   rx_done = mtk_poll_rx(napi, budget, eth);
 
if (unlikely(status2 & status_intr)) {
mtk_stats_update(eth);
@@ -953,20 +951,20 @@ static int mtk_poll(struct napi_struct *napi, int budget)
 
if (unlikely(netif_msg_intr(eth))) {
mask = mtk_r32(eth, MTK_QDMA_INT_MASK);
-   netdev_info(eth->netdev[0],
-   "done tx %d, rx %d, intr 0x%08x/0x%x\n",
-   tx_done, rx_done, status, mask);
+   dev_info(eth->dev,
+"done rx %d, intr 0x%08x/0x%x\n",
+rx_done, status, mask);
}
 
-   if (tx_again || rx_done == budget)
+   if (rx_done == budget)
return budget;
 
status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
-   if (status & (tx_intr | rx_intr))
+   if (status & MTK_RX_DONE_INT)
return budget;
 
napi_complete(napi);
-   mtk_irq_enable(eth, tx_intr | rx_intr);
+   mtk_irq_enable(eth, MTK_RX_DONE_INT);
 
return rx_done;
 }
@@ -1195,22 +1193,43 @@ static void mtk_tx_timeout(struct net_device *dev)
schedule_work(>pending_work);
 }
 
-static irqreturn_t mtk_handle_irq(int irq, void *_eth)
+static irqreturn_t mtk_handle_irq_rx(int irq, void *_eth)
 {
struct mtk_eth *eth = _eth;
u32 status;
 
status = mtk_r32(eth, MTK_QMTK_INT_STATUS);
+   status &= ~MTK_TX_DONE_INT;
+
if (unlikely(!status))
return IRQ_NONE;
 
-   if (likely(status & (MTK_RX_DONE_INT | MTK_TX_DONE_INT))) {
+   if (status & MTK_RX_DONE_INT) {
if (likely(napi_schedule_prep(>rx_napi)))
__napi_schedule(>rx_napi);
-   } else {
-   mtk_w32(eth, status,