8a47433b26a96c9615a21e0a737522b298fd14fd
[openwrt.git] / target / linux / mediatek / patches-4.4 / 0087-net-next-mediatek-add-IRQ-locking.patch
1 From 8aa53beda6ad6c8154e4f7b8a7ca9815412fa95a Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 20 Apr 2016 16:18:07 +0200
4 Subject: [PATCH 87/91] net-next: mediatek: add IRQ locking
5
6 The code that enables and disables IRQs is missing proper locking. After
7 adding the IRQ separation patch and routing the putting the RX and TX IRQs
8 on different cores we experienced IRQ stalls. Fix this by adding proper
9 locking. We use a dedicated lock to reduce the latency if the IRQ code.
10 Otherwise it might wait for bottom code to finish before reenabling or
11 disabling IRQs.
12
13 Signed-off-by: John Crispin <blogic@openwrt.org>
14 ---
15  drivers/net/ethernet/mediatek/mtk_eth_soc.c |    7 +++++++
16  drivers/net/ethernet/mediatek/mtk_eth_soc.h |    1 +
17  2 files changed, 8 insertions(+)
18
19 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 index 679cefd..f821820 100644
21 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
22 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
23 @@ -316,22 +316,28 @@ static void mtk_mdio_cleanup(struct mtk_eth *eth)
24  
25  static inline void mtk_irq_disable(struct mtk_eth *eth, u32 mask)
26  {
27 +       unsigned long flags;
28         u32 val;
29  
30 +       spin_lock_irqsave(&eth->irq_lock, flags);
31         val = mtk_r32(eth, MTK_QDMA_INT_MASK);
32         mtk_w32(eth, val & ~mask, MTK_QDMA_INT_MASK);
33         /* flush write */
34         mtk_r32(eth, MTK_QDMA_INT_MASK);
35 +       spin_unlock_irqrestore(&eth->irq_lock, flags);
36  }
37  
38  static inline void mtk_irq_enable(struct mtk_eth *eth, u32 mask)
39  {
40 +       unsigned long flags;
41         u32 val;
42  
43 +       spin_lock_irqsave(&eth->irq_lock, flags);
44         val = mtk_r32(eth, MTK_QDMA_INT_MASK);
45         mtk_w32(eth, val | mask, MTK_QDMA_INT_MASK);
46         /* flush write */
47         mtk_r32(eth, MTK_QDMA_INT_MASK);
48 +       spin_unlock_irqrestore(&eth->irq_lock, flags);
49  }
50  
51  static int mtk_set_mac_address(struct net_device *dev, void *p)
52 @@ -1750,6 +1756,7 @@ static int mtk_probe(struct platform_device *pdev)
53                 return -EADDRNOTAVAIL;
54  
55         spin_lock_init(&eth->page_lock);
56 +       spin_lock_init(&eth->irq_lock);
57  
58         eth->ethsys = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
59                                                       "mediatek,ethsys");
60 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
61 index 57f7e8a..8220275 100644
62 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
63 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
64 @@ -372,6 +372,7 @@ struct mtk_eth {
65         void __iomem                    *base;
66         struct reset_control            *rstc;
67         spinlock_t                      page_lock;
68 +       spinlock_t                      irq_lock;
69         struct net_device               dummy_dev;
70         struct net_device               *netdev[MTK_MAX_DEVS];
71         struct mtk_mac                  *mac[MTK_MAX_DEVS];
72 -- 
73 1.7.10.4
74