From patchwork Mon Feb 8 14:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 12075695 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADBB6C433DB for ; Mon, 8 Feb 2021 14:20:53 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C7F0F64E30 for ; Mon, 8 Feb 2021 14:20:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7F0F64E30 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baikalelectronics.ru Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sLD1Sd5e8sQ8BqFpBTV6GWxaRhsmHkQ97vcRTgMGBBw=; b=lcPt4EYeGjPFKfnOVe0qliiJl Dd6XZKCnibTaQJhUaiga4DMxcpKgzy7G6QnU2WUlstKGyPCKXff4EzJ5JQl7U644kyZEhexYE0rYz EY42eHlUS7q65Je4r3AV2nPH4o+8FcHHlcXc7E1OLL/tEZybKfgqwk/U7OZMOBsIdU+Y4nrvRwykq ZpmIrvD0UWIDvMD1Qtg61B+E6M75GVOFWeVmEAStY8tIwtJnkF8k4Qy0rgUlSJROJWDPAvuKQ0odV BCvFePyYmm9MAczrI9GgpR1DC0efzN274xXhzDd6YmyzEPum9Hm0h/JTF0SSLlWnrtlkwGW7HY671 ntpRv/0Uw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l97Na-0002Qs-4j; Mon, 08 Feb 2021 14:19:07 +0000 Received: from mail.baikalelectronics.com ([87.245.175.226] helo=mail.baikalelectronics.ru) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l97DO-0005IN-TU for linux-arm-kernel@lists.infradead.org; Mon, 08 Feb 2021 14:08:44 +0000 From: Serge Semin To: Rob Herring , Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , "David S. Miller" , Jakub Kicinski , Maxime Coquelin Subject: [PATCH 11/16] net: stmmac: Add STMMAC state getter Date: Mon, 8 Feb 2021 17:08:15 +0300 Message-ID: <20210208140820.10410-12-Sergey.Semin@baikalelectronics.ru> In-Reply-To: <20210208140820.10410-1-Sergey.Semin@baikalelectronics.ru> References: <20210208140820.10410-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210208_090835_290305_336ECE4F X-CRM114-Status: GOOD ( 18.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Serge Semin , Alexey Malahov , Serge Semin , Vyacheslav Mitrofanov , Pavel Parkhomenko , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index ab8b1e04ed22..c993dcd1c7d9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -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); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 0ed287edbc2d..19debbd7f981 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -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; } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index f458d728825c..b37f49f3dc03 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -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