mediatek: various additional ethernet fixes
[openwrt/openwrt.git] / target / linux / mediatek / patches-4.9 / 0061-eth-up_down_lock.patch
1 Index: linux-4.9.44/drivers/net/ethernet/mediatek/mtk_eth_soc.c
2 ===================================================================
3 --- linux-4.9.44.orig/drivers/net/ethernet/mediatek/mtk_eth_soc.c
4 +++ linux-4.9.44/drivers/net/ethernet/mediatek/mtk_eth_soc.c
5 @@ -1904,12 +1904,16 @@ static int mtk_open(struct net_device *d
6 struct mtk_mac *mac = netdev_priv(dev);
7 struct mtk_eth *eth = mac->hw;
8
9 + spin_lock(&eth->iface_lock);
10 +
11 /* we run 2 netdevs on the same dma ring so we only bring it up once */
12 if (!atomic_read(&eth->dma_refcnt)) {
13 int err = mtk_start_dma(eth);
14
15 - if (err)
16 + if (err) {
17 + spin_unlock(&eth->iface_lock);
18 return err;
19 + }
20
21 napi_enable(&eth->tx_napi);
22 napi_enable(&eth->rx_napi);
23 @@ -1923,6 +1927,7 @@ static int mtk_open(struct net_device *d
24
25 phy_start(dev->phydev);
26 netif_start_queue(dev);
27 + spin_unlock(&eth->iface_lock);
28
29 return 0;
30 }
31 @@ -1955,12 +1960,15 @@ static int mtk_stop(struct net_device *d
32 struct mtk_mac *mac = netdev_priv(dev);
33 struct mtk_eth *eth = mac->hw;
34
35 + spin_lock(&eth->iface_lock);
36 netif_tx_disable(dev);
37 phy_stop(dev->phydev);
38
39 /* only shutdown DMA if this is the last user */
40 - if (!atomic_dec_and_test(&eth->dma_refcnt))
41 + if (!atomic_dec_and_test(&eth->dma_refcnt)) {
42 + spin_unlock(&eth->iface_lock);
43 return 0;
44 + }
45
46 del_timer(&eth->napi_timer);
47
48 @@ -1974,6 +1982,8 @@ static int mtk_stop(struct net_device *d
49
50 mtk_dma_free(eth);
51
52 + spin_unlock(&eth->iface_lock);
53 +
54 return 0;
55 }
56
57 @@ -2623,6 +2633,7 @@ static int mtk_probe(struct platform_dev
58 if (IS_ERR(eth->base))
59 return PTR_ERR(eth->base);
60
61 + spin_lock_init(&eth->iface_lock);
62 spin_lock_init(&eth->page_lock);
63 spin_lock_init(&eth->tx_irq_lock);
64 spin_lock_init(&eth->rx_irq_lock);
65 Index: linux-4.9.44/drivers/net/ethernet/mediatek/mtk_eth_soc.h
66 ===================================================================
67 --- linux-4.9.44.orig/drivers/net/ethernet/mediatek/mtk_eth_soc.h
68 +++ linux-4.9.44/drivers/net/ethernet/mediatek/mtk_eth_soc.h
69 @@ -573,6 +573,7 @@ struct mtk_rx_ring {
70 struct mtk_eth {
71 struct device *dev;
72 void __iomem *base;
73 + spinlock_t iface_lock;
74 spinlock_t page_lock;
75 spinlock_t tx_irq_lock;
76 spinlock_t rx_irq_lock;