+From ca6be00ca1d3a2f5b8794894e2dae175e63768f5 Mon Sep 17 00:00:00 2001
+From: Sieng Piaw Liew <liew.s.piaw@gmail.com>
+Date: Tue, 16 Feb 2021 16:23:08 +0800
+Subject: [PATCH] bcm63xx_enet: Fix sporadic kernel panic
+
+In ndo_stop functions, netdev_completed_queue() is called during forced
+tx reclaim, after netdev_reset_queue(). This may trigger kernel panic if
+there is any tx skb left.
+
+This patch moves netdev_reset_queue() to after tx reclaim, so BQL can
+complete successfully then reset.
+
+Signed-off-by: Sieng Piaw Liew <liew.s.piaw@gmail.com>
+---
+ drivers/net/ethernet/broadcom/bcm63xx_enet.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
-@@ -1105,6 +1105,8 @@ static int bcm_enet_open(struct net_devi
- else
- bcm_enet_adjust_link(dev);
-
-+ netdev_reset_queue(dev);
-+
- netif_start_queue(dev);
- return 0;
-
-@@ -1193,7 +1195,6 @@ static int bcm_enet_stop(struct net_devi
+@@ -1193,7 +1193,6 @@ static int bcm_enet_stop(struct net_devi
kdev = &priv->pdev->dev;
netif_stop_queue(dev);
napi_disable(&priv->napi);
if (priv->has_phy)
phy_stop(dev->phydev);
-@@ -2267,6 +2268,7 @@ static int bcm_enetsw_open(struct net_de
- enet_dmac_writel(priv, ENETDMAC_IR_PKTDONE_MASK,
- ENETDMAC_IRMASK, priv->tx_chan);
+@@ -1232,6 +1231,9 @@ static int bcm_enet_stop(struct net_devi
+ if (priv->has_phy)
+ phy_disconnect(dev->phydev);
++ /* reset BQL after forced tx reclaim to not kernel panic */
+ netdev_reset_queue(dev);
- netif_carrier_on(dev);
- netif_start_queue(dev);
++
+ return 0;
+ }
@@ -2348,7 +2350,6 @@ static int bcm_enetsw_stop(struct net_de
napi_disable(&priv->napi);
del_timer_sync(&priv->rx_timeout);
+@@ -2376,6 +2377,9 @@ static int bcm_enetsw_stop(struct net_de
+ free_irq(priv->irq_tx, dev);
+ free_irq(priv->irq_rx, dev);
+
++ /* reset BQL after forced tx reclaim to not kernel panic */
++ netdev_reset_queue(dev);
++
+ return 0;
+ }
+
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
-@@ -1630,7 +1630,7 @@ static int bcm_enet_change_mtu(struct ne
+@@ -1631,7 +1631,7 @@ static int bcm_enet_change_mtu(struct ne
return -EBUSY;
/* add ethernet header + vlan tag size */
else
bcm_enet_adjust_link(dev);
-@@ -1133,10 +1110,6 @@ out_freeirq_rx:
+@@ -1131,10 +1108,6 @@ out_freeirq_rx:
out_freeirq:
free_irq(dev->irq, dev);
return ret;
}
-@@ -1229,10 +1202,6 @@ static int bcm_enet_stop(struct net_devi
+@@ -1227,10 +1200,6 @@ static int bcm_enet_stop(struct net_devi
free_irq(priv->irq_rx, dev);
free_irq(dev->irq, dev);
- if (priv->has_phy)
- phy_disconnect(dev->phydev);
-
- return 0;
- }
+ /* reset BQL after forced tx reclaim to not kernel panic */
+ netdev_reset_queue(dev);
-@@ -1801,14 +1770,47 @@ static int bcm_enet_probe(struct platfor
+@@ -1802,14 +1771,47 @@ static int bcm_enet_probe(struct platfor
/* do minimal hardware init to be able to probe mii bus */
bcm_enet_hw_preinit(priv);
}
bus = priv->mii_bus;
-@@ -1832,6 +1834,26 @@ static int bcm_enet_probe(struct platfor
+@@ -1833,6 +1835,26 @@ static int bcm_enet_probe(struct platfor
dev_err(&pdev->dev, "unable to register mdio bus\n");
goto out_free_mdio;
}
} else {
/* run platform code to initialize PHY device */
-@@ -1839,45 +1861,16 @@ static int bcm_enet_probe(struct platfor
+@@ -1840,45 +1862,16 @@ static int bcm_enet_probe(struct platfor
pd->mii_config(dev, 1, bcm_enet_mdio_read_mii,
bcm_enet_mdio_write_mii)) {
dev_err(&pdev->dev, "unable to configure mdio bus\n");
if (priv->mii_bus)
mdiobus_unregister(priv->mii_bus);
-@@ -1885,6 +1878,9 @@ out_free_mdio:
+@@ -1886,6 +1879,9 @@ out_free_mdio:
if (priv->mii_bus)
mdiobus_free(priv->mii_bus);
out_uninit_hw:
/* turn off mdc clock */
enet_writel(priv, 0, ENET_MIISC_REG);
-@@ -1915,6 +1911,7 @@ static int bcm_enet_remove(struct platfo
+@@ -1916,6 +1912,7 @@ static int bcm_enet_remove(struct platfo
enet_writel(priv, 0, ENET_MIISC_REG);
if (priv->has_phy) {
#define ENETSW_MDIOC_EXT_MASK (1 << 16)
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
-@@ -2184,6 +2184,18 @@ static int bcm_enetsw_open(struct net_de
+@@ -2185,6 +2185,18 @@ static int bcm_enetsw_open(struct net_de
priv->sw_port_link[i] = 0;
}
#include <bcm63xx_dev_enet.h>
#include "bcm63xx_enet.h"
-@@ -1931,7 +1932,8 @@ static int bcm_enet_remove(struct platfo
+@@ -1932,7 +1933,8 @@ static int bcm_enet_remove(struct platfo
return 0;
}
.probe = bcm_enet_probe,
.remove = bcm_enet_remove,
.driver = {
-@@ -1940,6 +1942,42 @@ struct platform_driver bcm63xx_enet_driv
+@@ -1941,6 +1943,42 @@ struct platform_driver bcm63xx_enet_driv
},
};
/*
* switch mii access callbacks
*/
-@@ -2196,29 +2234,6 @@ static int bcm_enetsw_open(struct net_de
+@@ -2197,29 +2235,6 @@ static int bcm_enetsw_open(struct net_de
enetsw_writeb(priv, rgmii_ctrl, ENETSW_RGMII_CTRL_REG(i));
}
/* initialize flow control buffer allocation */
enet_dma_writel(priv, ENETDMA_BUFALLOC_FORCE_MASK | 0,
ENETDMA_BUFALLOC_REG(priv->rx_chan));
-@@ -2652,6 +2667,9 @@ static int bcm_enetsw_probe(struct platf
+@@ -2655,6 +2670,9 @@ static int bcm_enetsw_probe(struct platf
struct bcm63xx_enetsw_platform_data *pd;
struct resource *res_mem;
int ret, irq_rx, irq_tx;
if (!bcm_enet_shared_base[0])
return -EPROBE_DEFER;
-@@ -2732,6 +2750,43 @@ static int bcm_enetsw_probe(struct platf
+@@ -2735,6 +2753,43 @@ static int bcm_enetsw_probe(struct platf
priv->pdev = pdev;
priv->net_dev = dev;
return 0;
out_disable_clk:
-@@ -2753,6 +2808,9 @@ static int bcm_enetsw_remove(struct plat
+@@ -2756,6 +2811,9 @@ static int bcm_enetsw_remove(struct plat
priv = netdev_priv(dev);
unregister_netdev(dev);
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
-@@ -2711,9 +2711,9 @@ static int bcm_enetsw_probe(struct platf
+@@ -2714,9 +2714,9 @@ static int bcm_enetsw_probe(struct platf
if (ret)
goto out;
--- a/drivers/net/ethernet/broadcom/bcm63xx_enet.c
+++ b/drivers/net/ethernet/broadcom/bcm63xx_enet.c
-@@ -2231,6 +2231,10 @@ static int bcm_enetsw_open(struct net_de
+@@ -2232,6 +2232,10 @@ static int bcm_enetsw_open(struct net_de
rgmii_ctrl = enetsw_readb(priv, ENETSW_RGMII_CTRL_REG(i));
rgmii_ctrl |= ENETSW_RGMII_CTRL_GMII_CLK_EN;