All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
To: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>,
	"David S . Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	<netdev@vger.kernel.org>, <linux-renesas-soc@vger.kernel.org>
Subject: [PATCH v2 09/14] ravb: fix invalid context bug while changing link options by ethtool
Date: Wed, 4 Jul 2018 11:14:51 +0300	[thread overview]
Message-ID: <20180704081451.7482-5-vladimir_zapolskiy@mentor.com> (raw)
In-Reply-To: <20180704081245.7395-1-vladimir_zapolskiy@mentor.com>

The change fixes sleep in atomic context bug, which is encountered
every time when link settings are changed by ethtool.

Since commit 35b5f6b1a82b ("PHYLIB: Locking fixes for PHY I/O
potentially sleeping") phy_start_aneg() function utilizes a mutex
to serialize changes to phy state, however that helper function is
called in atomic context under a grabbed spinlock, because
phy_start_aneg() is called by phy_ethtool_ksettings_set() and by
replaced phy_ethtool_sset() helpers from phylib.

Now duplex mode setting is enforced in ravb_adjust_link() only, also
now RX/TX is disabled when link is put down or modifications to E-MAC
registers ECMR and GECMR are expected for both cases of checked and
ignored link status pin state from E-MAC interrupt handler.

Fixes: a0d2f20650e8 ("Renesas Ethernet AVB PTP clock driver")
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
---
 drivers/net/ethernet/renesas/ravb_main.c | 49 ++++++++----------------
 1 file changed, 15 insertions(+), 34 deletions(-)

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index e7d6d1b6e7d6..40266fe01186 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -980,6 +980,13 @@ static void ravb_adjust_link(struct net_device *ndev)
 	struct ravb_private *priv = netdev_priv(ndev);
 	struct phy_device *phydev = ndev->phydev;
 	bool new_state = false;
+	unsigned long flags;
+
+	spin_lock_irqsave(&priv->lock, flags);
+
+	/* Disable TX and RX right over here, if E-MAC change is ignored */
+	if (priv->no_avb_link)
+		ravb_rcv_snd_disable(ndev);
 
 	if (phydev->link) {
 		if (phydev->duplex != priv->duplex) {
@@ -997,18 +1004,21 @@ static void ravb_adjust_link(struct net_device *ndev)
 			ravb_modify(ndev, ECMR, ECMR_TXF, 0);
 			new_state = true;
 			priv->link = phydev->link;
-			if (priv->no_avb_link)
-				ravb_rcv_snd_enable(ndev);
 		}
 	} else if (priv->link) {
 		new_state = true;
 		priv->link = 0;
 		priv->speed = 0;
 		priv->duplex = -1;
-		if (priv->no_avb_link)
-			ravb_rcv_snd_disable(ndev);
 	}
 
+	/* Enable TX and RX right over here, if E-MAC change is ignored */
+	if (priv->no_avb_link && phydev->link)
+		ravb_rcv_snd_enable(ndev);
+
+	mmiowb();
+	spin_unlock_irqrestore(&priv->lock, flags);
+
 	if (new_state && netif_msg_link(priv))
 		phy_print_status(phydev);
 }
@@ -1115,39 +1125,10 @@ static int ravb_get_link_ksettings(struct net_device *ndev,
 static int ravb_set_link_ksettings(struct net_device *ndev,
 				   const struct ethtool_link_ksettings *cmd)
 {
-	struct ravb_private *priv = netdev_priv(ndev);
-	unsigned long flags;
-	int error;
-
 	if (!ndev->phydev)
 		return -ENODEV;
 
-	spin_lock_irqsave(&priv->lock, flags);
-
-	/* Disable TX and RX */
-	ravb_rcv_snd_disable(ndev);
-
-	error = phy_ethtool_ksettings_set(ndev->phydev, cmd);
-	if (error)
-		goto error_exit;
-
-	if (cmd->base.duplex == DUPLEX_FULL)
-		priv->duplex = 1;
-	else
-		priv->duplex = 0;
-
-	ravb_set_duplex(ndev);
-
-error_exit:
-	mdelay(1);
-
-	/* Enable TX and RX */
-	ravb_rcv_snd_enable(ndev);
-
-	mmiowb();
-	spin_unlock_irqrestore(&priv->lock, flags);
-
-	return error;
+	return phy_ethtool_ksettings_set(ndev->phydev, cmd);
 }
 
 static int ravb_nway_reset(struct net_device *ndev)
-- 
2.17.1

  parent reply	other threads:[~2018-07-04  8:15 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-04  8:12 [PATCH v2 00/14] ravb/sh_eth: fix sleep in atomic by reusing shared ethtool handlers Vladimir Zapolskiy
2018-07-04  8:12 ` [PATCH v2 01/14] sh_eth: fix invalid context bug while calling auto-negotiation by ethtool Vladimir Zapolskiy
2018-07-06 15:39   ` Sergei Shtylyov
2018-07-04  8:12 ` [PATCH v2 02/14] sh_eth: fix invalid context bug while changing link options " Vladimir Zapolskiy
2018-07-06 18:43   ` Sergei Shtylyov
2018-07-04  8:12 ` [PATCH v2 03/14] sh_eth: simplify link auto-negotiation " Vladimir Zapolskiy
2018-07-06 18:48   ` Sergei Shtylyov
2018-07-04  8:12 ` [PATCH v2 04/14] sh_eth: remove custom .nway_reset from ethtool ops Vladimir Zapolskiy
2018-07-06 19:04   ` Sergei Shtylyov
2018-07-04  8:14 ` [PATCH v2 05/14] sh_eth: remove useless serialization in sh_eth_get_link_ksettings() Vladimir Zapolskiy
2018-07-06 19:06   ` Sergei Shtylyov
2018-07-04  8:14 ` [PATCH v2 06/14] sh_eth: remove custom .get_link_ksettings from ethtool ops Vladimir Zapolskiy
2018-07-06 19:08   ` Sergei Shtylyov
2018-07-04  8:14 ` [PATCH v2 07/14] sh_eth: remove custom .set_link_ksettings " Vladimir Zapolskiy
2018-07-06 19:15   ` Sergei Shtylyov
2018-07-04  8:14 ` [PATCH v2 08/14] ravb: fix invalid context bug while calling auto-negotiation by ethtool Vladimir Zapolskiy
2018-07-05  6:09   ` Vladimir Zapolskiy
2018-07-05  6:09     ` Vladimir Zapolskiy
2018-07-05  8:27     ` Sergei Shtylyov
2018-07-06 19:47   ` Sergei Shtylyov
2018-07-04  8:14 ` Vladimir Zapolskiy [this message]
2018-07-05  6:09   ` [PATCH v2 09/14] ravb: fix invalid context bug while changing link options " Vladimir Zapolskiy
2018-07-05  6:09     ` Vladimir Zapolskiy
2018-07-06 19:58   ` Sergei Shtylyov
2018-07-04  8:16 ` [PATCH v2 10/14] ravb: simplify link auto-negotiation " Vladimir Zapolskiy
2018-07-06 20:30   ` Sergei Shtylyov
2018-07-04  8:16 ` [PATCH v2 11/14] ravb: remove custom .nway_reset from ethtool ops Vladimir Zapolskiy
2018-07-06 20:30   ` Sergei Shtylyov
2018-07-04  8:16 ` [PATCH v2 12/14] ravb: remove useless serialization in ravb_get_link_ksettings() Vladimir Zapolskiy
2018-07-06 20:31   ` Sergei Shtylyov
2018-07-04  8:16 ` [PATCH v2 13/14] ravb: remove custom .get_link_ksettings from ethtool ops Vladimir Zapolskiy
2018-07-06 20:39   ` Sergei Shtylyov
2018-07-04  8:16 ` [PATCH v2 14/14] ravb: remove custom .set_link_ksettings " Vladimir Zapolskiy
2018-07-06 20:41   ` Sergei Shtylyov
2018-07-05  0:56 ` [PATCH v2 00/14] ravb/sh_eth: fix sleep in atomic by reusing shared ethtool handlers David Miller
2018-07-05  5:59   ` Vladimir Zapolskiy
2018-07-05  5:59     ` Vladimir Zapolskiy
2018-07-05 19:13     ` Sergei Shtylyov
2018-07-05  7:21 ` Geert Uytterhoeven
2018-07-07  1:47 ` David Miller
2018-07-07 15:22   ` Sergei Shtylyov
2018-07-07 23:58     ` David Miller
2018-07-08 23:24       ` Sergei Shtylyov
2018-07-08 23:33         ` Sergei Shtylyov
2018-07-09 18:16         ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180704081451.7482-5-vladimir_zapolskiy@mentor.com \
    --to=vladimir_zapolskiy@mentor.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=geert@linux-m68k.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sergei.shtylyov@cogentembedded.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.