From patchwork Tue Jan 27 06:05:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Fainelli X-Patchwork-Id: 433193 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1AE2A140188 for ; Tue, 27 Jan 2015 17:06:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbbA0GGN (ORCPT ); Tue, 27 Jan 2015 01:06:13 -0500 Received: from mail-pd0-f169.google.com ([209.85.192.169]:36398 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751671AbbA0GGG (ORCPT ); Tue, 27 Jan 2015 01:06:06 -0500 Received: by mail-pd0-f169.google.com with SMTP id g10so16880092pdj.0 for ; Mon, 26 Jan 2015 22:06:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AFfE1GHvvoX0TU2i4eUmJYIbVwmlIRuFoU7zN1C1Iag=; b=jH2+J8eesz96E7D4zXpPp7pbtc39CtCBxhF43aJwgABjrbyV5gEog2ZDb8e1d09Rb7 qb4W4fBzBeAyy8ZuIkYA6Fln34NVaHoOJK44UlqafhfL4GZuZnQMyeyM/9OrHx564q0N 9Q4PsLNR4IgwfQSDWw/gEgZ53LH52sGL5X+Edc+cpLqoYJLqAlN0T6NpDRbnMHgVeKem JGD8iE7qjgpOxDvjFrO7DP9RN6HNl+CxtxfaTrSKbcqeRjU4nUSg3LBmswOU1tErktw4 FYCX+1/mmhCTMKq+DHaKZXAQoaTlhv4rY2a6+BTF+0qMVwYLhuknBYRvDyWcEBSv1A0T hAEQ== X-Received: by 10.68.112.194 with SMTP id is2mr1590001pbb.161.1422338765753; Mon, 26 Jan 2015 22:06:05 -0800 (PST) Received: from fainelli-desktop.broadcom.com (5520-maca-inet1-outside.broadcom.com. [216.31.211.11]) by mx.google.com with ESMTPSA id t7sm304862pbs.90.2015.01.26.22.06.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Jan 2015 22:06:05 -0800 (PST) From: Florian Fainelli To: netdev@vger.kernel.org Cc: davem@davemloft.net, s.hauer@pengutronix.de, b38611@freescale.com, Florian Fainelli Subject: [PATCH net-next v2 4/4] net: phy: avoid suspending twice a PHY Date: Mon, 26 Jan 2015 22:05:40 -0800 Message-Id: <1422338740-18418-5-git-send-email-f.fainelli@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422338740-18418-1-git-send-email-f.fainelli@gmail.com> References: <1422338740-18418-1-git-send-email-f.fainelli@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. Acked-by: Fugang Duan Tested-by: Fugang Duan Signed-off-by: Florian Fainelli --- Changess in v2: - added Fugang's tags 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.