ff21c09ac3171a04e2b61c9c2f6f72566cdc2601
[openwrt/staging/hauke.git] / target / linux / mediatek / patches-4.4 / 0095-net-next-mediatek-add-IRQ-locking.patch
1 From dd08d1ac4cfc86fbea5ee207b9615922ede88ec6 Mon Sep 17 00:00:00 2001
2 From: John Crispin <john@phrozen.org>
3 Date: Tue, 17 May 2016 06:01:45 +0200
4 Subject: [PATCH 095/102] 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: Sean Wang <keyhaede@gmail.com>
14 Signed-off-by: John Crispin <john@phrozen.org>
15 ---
16 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 7 +++++++
17 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 +
18 2 files changed, 8 insertions(+)
19
20 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
21 index 13ee15f..c869064 100644
22 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
23 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
24 @@ -331,18 +331,24 @@ static void mtk_mdio_cleanup(struct mtk_eth *eth)
25
26 static inline void mtk_irq_disable(struct mtk_eth *eth, u32 mask)
27 {
28 + unsigned long flags;
29 u32 val;
30
31 + spin_lock_irqsave(&eth->irq_lock, flags);
32 val = mtk_r32(eth, MTK_QDMA_INT_MASK);
33 mtk_w32(eth, val & ~mask, MTK_QDMA_INT_MASK);
34 + spin_unlock_irqrestore(&eth->irq_lock, flags);
35 }
36
37 static inline void mtk_irq_enable(struct mtk_eth *eth, u32 mask)
38 {
39 + unsigned long flags;
40 u32 val;
41
42 + spin_lock_irqsave(&eth->irq_lock, flags);
43 val = mtk_r32(eth, MTK_QDMA_INT_MASK);
44 mtk_w32(eth, val | mask, MTK_QDMA_INT_MASK);
45 + spin_unlock_irqrestore(&eth->irq_lock, flags);
46 }
47
48 static int mtk_set_mac_address(struct net_device *dev, void *p)
49 @@ -1771,6 +1777,7 @@ static int mtk_probe(struct platform_device *pdev)
50 return -EADDRNOTAVAIL;
51
52 spin_lock_init(&eth->page_lock);
53 + spin_lock_init(&eth->irq_lock);
54
55 eth->ethsys = syscon_regmap_lookup_by_phandle(pdev->dev.of_node,
56 "mediatek,ethsys");
57 diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
58 index a5eb7c6..3159d2a 100644
59 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
60 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
61 @@ -373,6 +373,7 @@ struct mtk_eth {
62 void __iomem *base;
63 struct reset_control *rstc;
64 spinlock_t page_lock;
65 + spinlock_t irq_lock;
66 struct net_device dummy_dev;
67 struct net_device *netdev[MTK_MAX_DEVS];
68 struct mtk_mac *mac[MTK_MAX_DEVS];
69 --
70 1.7.10.4
71