netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, s.hauer@pengutronix.de,
	b38611@freescale.com, Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net-next 4/4] net: phy: avoid suspending twice a PHY
Date: Mon, 26 Jan 2015 16:31:13 -0800	[thread overview]
Message-ID: <1422318673-9418-5-git-send-email-f.fainelli@gmail.com> (raw)
In-Reply-To: <1422318673-9418-1-git-send-email-f.fainelli@gmail.com>

As part of a call to ndo_close() a netdevice driver may call
phy_disconnect() -> phy_detach() -> phy_suspend(), such that the PHY is
suspsended at this point and a netdevice driver may clock gate the
backing peripheral providing MDIO bus accessses as well.

Update mdio_bus_phy_may_suspend() to return whether a PHY is allowed to
be suspended and conversely resumed if and only if it was not previously
suspended before while it is currently in detached (netdev pointer is
NULL) state.

This fixes bus errors seen during S2/S3 suspend/resume cycles for
netdevice drivers such as GENET which clock gates the entire Ethernet
MAC, including the MDIO bus block.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/phy/mdio_bus.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 20447741893a..095ef3fe369a 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -443,9 +443,13 @@ static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
 	if (!drv || !phydrv->suspend)
 		return false;
 
-	/* PHY not attached? May suspend. */
+	/* PHY not attached? May suspend if the PHY has not already been
+	 * suspended as part of a prior call to phy_disconnect() ->
+	 * phy_detach() -> phy_suspend() because the parent netdev might be the
+	 * MDIO bus driver and clock gated at this point.
+	 */
 	if (!netdev)
-		return true;
+		return !phydev->suspended;
 
 	/* Don't suspend PHY if the attched netdev parent may wakeup.
 	 * The parent may point to a PCI device, as in tg3 driver.
-- 
2.1.0

  parent reply	other threads:[~2015-01-27  0:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27  0:31 [PATCH net-next 0/4] net: phy: prevent double suspend Florian Fainelli
2015-01-27  0:31 ` [PATCH net-next 1/4] net: phy: utilize phy_suspend and phy_resume Florian Fainelli
2015-01-27  2:42   ` fugang.duan
2015-01-27  0:31 ` [PATCH net-next 2/4] net: phy: document has_fixups field Florian Fainelli
2015-01-27  0:31 ` [PATCH net-next 3/4] net: phy: keep track of the PHY suspend state Florian Fainelli
2015-01-27  2:43   ` fugang.duan
2015-01-27  5:55     ` Florian Fainelli
2015-01-27  0:31 ` Florian Fainelli [this message]
2015-01-27  2:44   ` [PATCH net-next 4/4] net: phy: avoid suspending twice a PHY fugang.duan

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=1422318673-9418-5-git-send-email-f.fainelli@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=b38611@freescale.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=s.hauer@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).