Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2836769imm; Thu, 24 May 2018 17:13:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoUMCC18VNARD0Dqy9V35MqfwqGIsMAes60MrOk6qfMrgOHvLaczTSVAOvmiHZziyuWjD9X X-Received: by 2002:a63:384d:: with SMTP id h13-v6mr121116pgn.209.1527207236644; Thu, 24 May 2018 17:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527207236; cv=none; d=google.com; s=arc-20160816; b=gdzfyiDs4U0sgpR2vF9o/+fWbhZ8aGTkhVyVT5HtSK75Ot1lrBk14YgHoaYO5wqq+P 8vDJBAgLPfOavMSm4k2kwrGctzM8VsHYk91LX8BASskA6ho1kC96H6vE8z/0PiPT3/fG cysiaTWExmAuAgu1NaajWuCsdAf+nxdSqiTyFEPw9pY945w7eFT2ZJP0viGGhn6BBvYa +ZAFOFv0a1/AkjC86UJlWXCnyRWJ9wTd518Pc1PC5VZC/foFkxZgETjtduehQDCjl+Gc uZ/GebGfH6aqU//kEBbBRGIV9W4Qv6IlEkDq5v5KX4gky1olCD1FYdqhQtqMnDlzLNC9 jRzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=zb4Q6BwWbCU1MdiYMOm2RttegGdwxsOMvfpqIfVc/OA=; b=oszjP6UN2/2a1g5ZBSBKVFBPZfavm79wijmHLC20xuz+CcnHQjHwkwXgf4knRpEDFY 05uPEZnqZPvVMs/W9yZfF2pNInSsJiStY4B+HME0+YzPFlUs96xb6J9IW8JiStJiXgma /01Bf2K8udvBNkuLcLkaibyGicOHwAC46tC7jL9DYijomFJhDYWbpLFYOJatIPoIr9+0 HBbkLCioI01VVXSxzNnNLAAeYKRaV2F55E2xksU24mmmbuJQP/0pMLDO8ZPZlrb7JsaK J+gElTwQ1FgyA2QeG8QrAzvdqdHBDcUt0Sh6z3TkRHsOwvFkuvLStB3Mm7pzyuPffYok aR/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JweMFoCk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v64-v6si17724996pgv.528.2018.05.24.17.13.42; Thu, 24 May 2018 17:13:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JweMFoCk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S970360AbeEXOJQ (ORCPT + 99 others); Thu, 24 May 2018 10:09:16 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:44770 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967730AbeEXOJL (ORCPT ); Thu, 24 May 2018 10:09:11 -0400 Received: by mail-wr0-f195.google.com with SMTP id y15-v6so3381831wrg.11; Thu, 24 May 2018 07:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=zb4Q6BwWbCU1MdiYMOm2RttegGdwxsOMvfpqIfVc/OA=; b=JweMFoCkGev6AZGbj/JOsN63hApkTksD3E2p68oYT4MSgtZnpaoYogy5sXG/7ejH3p L+zPq3Ch6iOvwO0EWWtVVF1BFIBz+uGBfHKGD0teDXcQD47SxrKXhFKYfC1k9K/Z77Mw 5yonaVHhnKLKEkvdd6aYTdhOErRESilgVOZ3pxq2gdWzMahQ778fpALsoJwG4ov66zpi mfqMDwD15ZAmlP3yNmXsblRqUAQ7PLZU99IlDzMuZUgnv39xRX+Ezwu0TX+xzPTiSoGt zHW4CN9Udo95mHdr5Q62rXWqV0boUNW7rH9vwf+x8JmybHIbsNKhxvgLWKO6KMquSbWy aimg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zb4Q6BwWbCU1MdiYMOm2RttegGdwxsOMvfpqIfVc/OA=; b=jvSR/4b5S+szcFAEwzh/0Gwckb8SH9XAN5Z30pZg2161O8docJT8tGuR+f2aUgUUvT 9yTWy1RIbKHyBoKfucOIYkDosOqrVxf24JYLpcE7ULs5V0eTSE4QvACnpjHEXwqbZxX5 yHmxd4e3kzyGgXPmqT8iOa6lHLZK4bVOhbEYlVEjnEPKDfCc9U9BzG/F/WLbimXFbDkt yHDbZoJ3finoE4bZkRVFdVcLqhfuY1ciCUOFLwpdVmPPWaeBmMkmyiUbGR3GoZnAV8qC QVKNPSD2wWMYgwGfxpbZ0H6wUs6ldz6OOag8EBt5eBRQaQ33yDKo4Gbjul+Nw/wOqZOk 8Gqw== X-Gm-Message-State: ALKqPwfSHp+IFtwPrbOJWqsjCPxRnUzleTs4Jk8cAgsj98Q39FkuY0Hr 6hS6h5H62Gi+kSnFXAetkc4= X-Received: by 2002:adf:afe4:: with SMTP id y36-v6mr6353881wrd.107.1527170950020; Thu, 24 May 2018 07:09:10 -0700 (PDT) Received: from localhost (p2E5BE9A1.dip0.t-ipconnect.de. [46.91.233.161]) by smtp.gmail.com with ESMTPSA id j9-v6sm3567035wmh.28.2018.05.24.07.09.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 May 2018 07:09:09 -0700 (PDT) From: Thierry Reding To: "David S. Miller" Cc: Giuseppe Cavallaro , Alexandre Torgue , Jon Hunter , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net: stmmac: Use mutex instead of spinlock Date: Thu, 24 May 2018 16:09:07 +0200 Message-Id: <20180524140907.24197-1-thierry.reding@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thierry Reding Some drivers, such as DWC EQOS on Tegra, need to perform operations that can sleep under this lock (clk_set_rate() in tegra_eqos_fix_speed()) for proper operation. Since there is no need for this lock to be a spinlock, convert it to a mutex instead. Fixes: e6ea2d16fc61 ("net: stmmac: dwc-qos: Add Tegra186 support") Reported-by: Jon Hunter Signed-off-by: Thierry Reding --- This applies on top of net-next. drivers/net/ethernet/stmicro/stmmac/stmmac.h | 2 +- .../ethernet/stmicro/stmmac/stmmac_ethtool.c | 12 +++---- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 31 +++++++++---------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 42fc76e76bf9..5a2570b8d540 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -121,7 +121,7 @@ struct stmmac_priv { struct net_device *dev; struct device *device; struct mac_device_info *hw; - spinlock_t lock; + struct mutex lock; /* RX Queue */ struct stmmac_rx_queue rx_queue[MTL_MAX_RX_QUEUES]; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 6d82b3ef5c3b..5710864fa809 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -390,9 +390,9 @@ stmmac_ethtool_set_link_ksettings(struct net_device *dev, ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full); - spin_lock(&priv->lock); + mutex_lock(&priv->lock); stmmac_pcs_ctrl_ane(priv, priv->ioaddr, 1, priv->hw->ps, 0); - spin_unlock(&priv->lock); + mutex_unlock(&priv->lock); return 0; } @@ -632,12 +632,12 @@ static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) { struct stmmac_priv *priv = netdev_priv(dev); - spin_lock_irq(&priv->lock); + mutex_lock(&priv->lock); if (device_can_wakeup(priv->device)) { wol->supported = WAKE_MAGIC | WAKE_UCAST; wol->wolopts = priv->wolopts; } - spin_unlock_irq(&priv->lock); + mutex_unlock(&priv->lock); } static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) @@ -666,9 +666,9 @@ static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) disable_irq_wake(priv->wol_irq); } - spin_lock_irq(&priv->lock); + mutex_lock(&priv->lock); priv->wolopts = wol->wolopts; - spin_unlock_irq(&priv->lock); + mutex_unlock(&priv->lock); return 0; } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index d9dbe1355896..8cc63da79a80 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -381,7 +381,6 @@ bool stmmac_eee_init(struct stmmac_priv *priv) { struct net_device *ndev = priv->dev; int interface = priv->plat->interface; - unsigned long flags; bool ret = false; if ((interface != PHY_INTERFACE_MODE_MII) && @@ -408,7 +407,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv) * changed). * In that case the driver disable own timers. */ - spin_lock_irqsave(&priv->lock, flags); + mutex_lock(&priv->lock); if (priv->eee_active) { netdev_dbg(priv->dev, "disable EEE\n"); del_timer_sync(&priv->eee_ctrl_timer); @@ -416,11 +415,11 @@ bool stmmac_eee_init(struct stmmac_priv *priv) tx_lpi_timer); } priv->eee_active = 0; - spin_unlock_irqrestore(&priv->lock, flags); + mutex_unlock(&priv->lock); goto out; } /* Activate the EEE and start timers */ - spin_lock_irqsave(&priv->lock, flags); + mutex_lock(&priv->lock); if (!priv->eee_active) { priv->eee_active = 1; timer_setup(&priv->eee_ctrl_timer, @@ -435,7 +434,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv) stmmac_set_eee_pls(priv, priv->hw, ndev->phydev->link); ret = true; - spin_unlock_irqrestore(&priv->lock, flags); + mutex_unlock(&priv->lock); netdev_dbg(priv->dev, "Energy-Efficient Ethernet initialized\n"); } @@ -811,13 +810,12 @@ static void stmmac_adjust_link(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); struct phy_device *phydev = dev->phydev; - unsigned long flags; bool new_state = false; if (!phydev) return; - spin_lock_irqsave(&priv->lock, flags); + mutex_lock(&priv->lock); if (phydev->link) { u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG); @@ -876,7 +874,7 @@ static void stmmac_adjust_link(struct net_device *dev) if (new_state && netif_msg_link(priv)) phy_print_status(phydev); - spin_unlock_irqrestore(&priv->lock, flags); + mutex_unlock(&priv->lock); if (phydev->is_pseudo_fixed_link) /* Stop PHY layer to call the hook to adjust the link in case @@ -4337,7 +4335,7 @@ int stmmac_dvr_probe(struct device *device, (8 * priv->plat->rx_queues_to_use)); } - spin_lock_init(&priv->lock); + mutex_init(&priv->lock); /* If a specific clk_csr value is passed from the platform * this means that the CSR Clock Range selection cannot be @@ -4421,6 +4419,7 @@ int stmmac_dvr_remove(struct device *dev) priv->hw->pcs != STMMAC_PCS_RTBI) stmmac_mdio_unregister(ndev); destroy_workqueue(priv->wq); + mutex_destroy(&priv->lock); free_netdev(ndev); return 0; @@ -4438,7 +4437,6 @@ int stmmac_suspend(struct device *dev) { struct net_device *ndev = dev_get_drvdata(dev); struct stmmac_priv *priv = netdev_priv(ndev); - unsigned long flags; if (!ndev || !netif_running(ndev)) return 0; @@ -4446,7 +4444,7 @@ int stmmac_suspend(struct device *dev) if (ndev->phydev) phy_stop(ndev->phydev); - spin_lock_irqsave(&priv->lock, flags); + mutex_lock(&priv->lock); netif_device_detach(ndev); stmmac_stop_all_queues(priv); @@ -4467,7 +4465,7 @@ int stmmac_suspend(struct device *dev) clk_disable(priv->plat->pclk); clk_disable(priv->plat->stmmac_clk); } - spin_unlock_irqrestore(&priv->lock, flags); + mutex_unlock(&priv->lock); priv->oldlink = false; priv->speed = SPEED_UNKNOWN; @@ -4512,7 +4510,6 @@ int stmmac_resume(struct device *dev) { struct net_device *ndev = dev_get_drvdata(dev); struct stmmac_priv *priv = netdev_priv(ndev); - unsigned long flags; if (!netif_running(ndev)) return 0; @@ -4524,9 +4521,9 @@ int stmmac_resume(struct device *dev) * from another devices (e.g. serial console). */ if (device_may_wakeup(priv->device)) { - spin_lock_irqsave(&priv->lock, flags); + mutex_lock(&priv->lock); stmmac_pmt(priv, priv->hw, 0); - spin_unlock_irqrestore(&priv->lock, flags); + mutex_unlock(&priv->lock); priv->irq_wake = 0; } else { pinctrl_pm_select_default_state(priv->device); @@ -4540,7 +4537,7 @@ int stmmac_resume(struct device *dev) netif_device_attach(ndev); - spin_lock_irqsave(&priv->lock, flags); + mutex_lock(&priv->lock); stmmac_reset_queues_param(priv); @@ -4554,7 +4551,7 @@ int stmmac_resume(struct device *dev) stmmac_start_all_queues(priv); - spin_unlock_irqrestore(&priv->lock, flags); + mutex_unlock(&priv->lock); if (ndev->phydev) phy_start(ndev->phydev); -- 2.17.0