Commit 136ff9ca authored by Florian Fainelli's avatar Florian Fainelli Committed by Greg Kroah-Hartman

net: systemport: Protect stop from timeout

[ Upstream commit 7cb6a2a2 ]

A timing hazard exists when the network interface is stopped that
allows a watchdog timeout to be processed by a separate core in
parallel. This creates the potential for the timeout handler to
wake the queues while the driver is shutting down, or access
registers after their clocks have been removed.

The more common case is that the watchdog timeout will produce a
warning message which doesn't lead to a crash. The chances of this
are greatly increased by the fact that bcm_sysport_netif_stop stops
the transmit queues which can easily precipitate a watchdog time-
out because of stale trans_start data in the queues.

This commit corrects the behavior by ensuring that the watchdog
timeout is disabled before enterring bcm_sysport_netif_stop. There
are currently only two users of the bcm_sysport_netif_stop function:
close and suspend.

The close case already handles the issue by exiting the RUNNING
state before invoking the driver close service.

The suspend case now performs the netif_device_detach to exit the
PRESENT state before the call to bcm_sysport_netif_stop rather than
after it.

These behaviors prevent any future scheduling of the driver timeout
service during the window. The netif_tx_stop_all_queues function
in bcm_sysport_netif_stop is replaced with netif_tx_disable to ensure
synchronization with any transmit or timeout threads that may
already be executing on other cores.

For symmetry, the netif_device_attach call upon resume is moved to
after the call to bcm_sysport_netif_start. Since it wakes the transmit
queues it is not necessary to invoke netif_tx_start_all_queues from
bcm_sysport_netif_start so it is moved into the driver open service.

Fixes: 40755a0f ("net: systemport: add suspend and resume support")
Fixes: 80105bef ("net: systemport: add Broadcom SYSTEMPORT Ethernet MAC driver")
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 453fcc4b
...@@ -1774,9 +1774,6 @@ static void bcm_sysport_netif_start(struct net_device *dev) ...@@ -1774,9 +1774,6 @@ static void bcm_sysport_netif_start(struct net_device *dev)
intrl2_1_mask_clear(priv, 0xffffffff); intrl2_1_mask_clear(priv, 0xffffffff);
else else
intrl2_0_mask_clear(priv, INTRL2_0_TDMA_MBDONE_MASK); intrl2_0_mask_clear(priv, INTRL2_0_TDMA_MBDONE_MASK);
/* Last call before we start the real business */
netif_tx_start_all_queues(dev);
} }
static void rbuf_init(struct bcm_sysport_priv *priv) static void rbuf_init(struct bcm_sysport_priv *priv)
...@@ -1922,6 +1919,8 @@ static int bcm_sysport_open(struct net_device *dev) ...@@ -1922,6 +1919,8 @@ static int bcm_sysport_open(struct net_device *dev)
bcm_sysport_netif_start(dev); bcm_sysport_netif_start(dev);
netif_tx_start_all_queues(dev);
return 0; return 0;
out_clear_rx_int: out_clear_rx_int:
...@@ -1945,7 +1944,7 @@ static void bcm_sysport_netif_stop(struct net_device *dev) ...@@ -1945,7 +1944,7 @@ static void bcm_sysport_netif_stop(struct net_device *dev)
struct bcm_sysport_priv *priv = netdev_priv(dev); struct bcm_sysport_priv *priv = netdev_priv(dev);
/* stop all software from updating hardware */ /* stop all software from updating hardware */
netif_tx_stop_all_queues(dev); netif_tx_disable(dev);
napi_disable(&priv->napi); napi_disable(&priv->napi);
phy_stop(dev->phydev); phy_stop(dev->phydev);
...@@ -2267,12 +2266,12 @@ static int bcm_sysport_suspend(struct device *d) ...@@ -2267,12 +2266,12 @@ static int bcm_sysport_suspend(struct device *d)
if (!netif_running(dev)) if (!netif_running(dev))
return 0; return 0;
netif_device_detach(dev);
bcm_sysport_netif_stop(dev); bcm_sysport_netif_stop(dev);
phy_suspend(dev->phydev); phy_suspend(dev->phydev);
netif_device_detach(dev);
/* Disable UniMAC RX */ /* Disable UniMAC RX */
umac_enable_set(priv, CMD_RX_EN, 0); umac_enable_set(priv, CMD_RX_EN, 0);
...@@ -2356,8 +2355,6 @@ static int bcm_sysport_resume(struct device *d) ...@@ -2356,8 +2355,6 @@ static int bcm_sysport_resume(struct device *d)
goto out_free_rx_ring; goto out_free_rx_ring;
} }
netif_device_attach(dev);
/* RX pipe enable */ /* RX pipe enable */
topctrl_writel(priv, 0, RX_FLUSH_CNTL); topctrl_writel(priv, 0, RX_FLUSH_CNTL);
...@@ -2402,6 +2399,8 @@ static int bcm_sysport_resume(struct device *d) ...@@ -2402,6 +2399,8 @@ static int bcm_sysport_resume(struct device *d)
bcm_sysport_netif_start(dev); bcm_sysport_netif_start(dev);
netif_device_attach(dev);
return 0; return 0;
out_free_rx_ring: out_free_rx_ring:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment