@@ -263,6 +263,7 @@ int stmmac_dvr_remove(struct device *dev);
int stmmac_dvr_probe(struct device *device,
struct plat_stmmacenet_data *plat_dat,
struct stmmac_resources *res);
+bool stmmac_is_up(struct stmmac_priv *priv);
void stmmac_disable_eee_mode(struct stmmac_priv *priv);
bool stmmac_eee_init(struct stmmac_priv *priv);
int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt);
@@ -402,7 +402,9 @@ static void stmmac_ethtool_setmsglevel(struct net_device *dev, u32 level)
static int stmmac_check_if_running(struct net_device *dev)
{
- if (!netif_running(dev))
+ struct stmmac_priv *priv = netdev_priv(dev);
+
+ if (!stmmac_is_up(priv))
return -EBUSY;
return 0;
}
@@ -2804,6 +2804,20 @@ static void stmmac_hw_teardown(struct net_device *dev)
stmmac_mac_set(priv, priv->ioaddr, false);
}
+/**
+ * stmmac_is_up - test STMMAC state
+ * @priv: driver private structure
+ * Description:
+ * Detects the current network adapter state just by testing the MAC
+ * initialization completion flag.
+ * Return value:
+ * true if the STMMAC network is setup, false otherwise.
+ */
+bool stmmac_is_up(struct stmmac_priv *priv)
+{
+ return test_bit(STMMAC_UP, &priv->state);
+}
+
/**
* stmmac_open - open entry point of the driver
* @dev : pointer to the device structure.
@@ -4046,7 +4060,7 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
txfifosz /= priv->plat->tx_queues_to_use;
- if (netif_running(dev)) {
+ if (stmmac_is_up(priv)) {
netdev_err(priv->dev, "must be stopped to change its MTU\n");
return -EBUSY;
}
@@ -4217,7 +4231,7 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
pm_wakeup_event(priv->device, 0);
/* Check if adapter is up */
- if (!test_bit(STMMAC_UP, &priv->state))
+ if (!stmmac_is_up(priv))
return IRQ_HANDLED;
/* Check if a fatal error happened */
if (stmmac_safety_feat_interrupt(priv))
@@ -4290,7 +4304,7 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
struct stmmac_priv *priv = netdev_priv (dev);
int ret = -EOPNOTSUPP;
- if (!netif_running(dev))
+ if (!stmmac_is_up(priv))
return -EINVAL;
switch (cmd) {
@@ -4743,7 +4757,7 @@ static const struct net_device_ops stmmac_netdev_ops = {
static void stmmac_reset_subtask(struct stmmac_priv *priv)
{
- if (!test_bit(STMMAC_UP, &priv->state))
+ if (!stmmac_is_up(priv))
return;
netdev_err(priv->dev, "Reset adapter.\n");
@@ -4915,7 +4929,7 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)
struct stmmac_priv *priv = netdev_priv(dev);
int ret = 0;
- if (netif_running(dev))
+ if (stmmac_is_up(priv))
stmmac_release(dev);
stmmac_napi_del(dev);
@@ -4925,7 +4939,7 @@ int stmmac_reinit_queues(struct net_device *dev, u32 rx_cnt, u32 tx_cnt)
stmmac_napi_add(dev);
- if (netif_running(dev))
+ if (stmmac_is_up(priv))
ret = stmmac_open(dev);
return ret;
@@ -4936,13 +4950,13 @@ int stmmac_reinit_ringparam(struct net_device *dev, u32 rx_size, u32 tx_size)
struct stmmac_priv *priv = netdev_priv(dev);
int ret = 0;
- if (netif_running(dev))
+ if (stmmac_is_up(priv))
stmmac_release(dev);
priv->dma_rx_size = rx_size;
priv->dma_tx_size = tx_size;
- if (netif_running(dev))
+ if (stmmac_is_up(priv))
ret = stmmac_open(dev);
return ret;
@@ -5253,7 +5267,7 @@ int stmmac_suspend(struct device *dev)
struct stmmac_priv *priv = netdev_priv(ndev);
u32 chan;
- if (!ndev || !netif_running(ndev))
+ if (!stmmac_is_up(priv))
return 0;
phylink_mac_change(priv->phylink, false);
@@ -5343,7 +5357,7 @@ int stmmac_resume(struct device *dev)
struct stmmac_priv *priv = netdev_priv(ndev);
int ret;
- if (!netif_running(ndev))
+ if (!stmmac_is_up(priv))
return 0;
/* Power Down bit, into the PM register, is cleared
Since the STMMAC driver has internal STMMAC_UP flag declared to indicate the STMMAC network setup state, let's define the flag getter and use it in the driver code to get the current NIC state. We can also convert the netif_running() method invocation to calling the stmmac_is_up() function instead because the latter gives more accurate notion of the network state as the flag is set only after all the NIC initializations are finished. Signed-off-by: Serge Semin <Sergey.Semin@baikalelectronics.ru> --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 1 + .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 4 ++- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 34 +++++++++++++------ 3 files changed, 28 insertions(+), 11 deletions(-)