From patchwork Fri Nov 30 09:25:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunihiko Hayashi X-Patchwork-Id: 152502 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3430700ljp; Fri, 30 Nov 2018 01:25:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/UxLK4OvbFBMq0Dwhvljf8wbHXYA/+8vZtDzmSvhwuw6ed0+H1FYXEeonWpu0A6WxjzyubM X-Received: by 2002:a62:4c5:: with SMTP id 188mr4963640pfe.130.1543569941881; Fri, 30 Nov 2018 01:25:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543569941; cv=none; d=google.com; s=arc-20160816; b=VcAtvF41eysrUAPGvYdgpZsf9wrZaD/MwkRJ2VgwbZwUmt3uFOZLIX6mlnW/D+LT0g 7a2O5YLdznrBfkSPS3TJ5aZztQVE7lba/muT5z0BHZ5tTndPsRcByyYuR+4EvZ+/VsoS eV5F8pz+I1dohMMn4R2otWx8uHQ/NHMtIE5p+YfBzQnB4TnP2CM/tOkC8+RMa3GBVYcB bFI1/MnAC+LAj3nS3bAx6zeRlcGQmOhVNoNMJilz6/Z+3JNDKrTyaxpXwg3ErDIabLe9 ckrtNNeYQ75KhSckC8CNsbd6rtwP8lusFZx6pMt1wf664EYVTguapxKGuI6jVUJo0wFJ bM/A== 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; bh=usSUQi6yrLRgz/vABjsbbSUdt7oIeEjdLt8AiEbefZs=; b=K/25OPuEys+H8kP7sQRIe43xiv2US68vex62qzpLPUuOJ4yQop9k/7sJ7UQ/HQktGO WsPywmV27r2YhPk563fCg1iQlWAj8mvk2w8jiH/WlXc7u/YipbJfPOkIHHn/cRHQK07h 5mjzmG3yHyIAQ9SPGRpTvTe//zi/eLVgKIvxtyamuWmNHnqMJHZEDN645JJqAUm6bHuI job0N7R7iEIKQ93UHeM+Q9K0m7hPKjo863htnKIQB0DX4yb3KgI2GgiwTLGMs9mYg5ld CBjfujlOy8bCsxYWFUoYUdqKXcOvzypPhtM1unJ4n/AyDI48Us3QwqwOUt96MT059IiQ EBFg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si4469316pll.384.2018.11.30.01.25.37; Fri, 30 Nov 2018 01:25:41 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726789AbeK3UeO (ORCPT + 32 others); Fri, 30 Nov 2018 15:34:14 -0500 Received: from mx.socionext.com ([202.248.49.38]:19593 "EHLO mx.socionext.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbeK3UeO (ORCPT ); Fri, 30 Nov 2018 15:34:14 -0500 Received: from unknown (HELO kinkan-ex.css.socionext.com) ([172.31.9.52]) by mx.socionext.com with ESMTP; 30 Nov 2018 18:25:32 +0900 Received: from mail.mfilter.local (m-filter-1 [10.213.24.61]) by kinkan-ex.css.socionext.com (Postfix) with ESMTP id 8C281180B47; Fri, 30 Nov 2018 18:25:32 +0900 (JST) Received: from 172.31.9.51 (172.31.9.51) by m-FILTER with ESMTP; Fri, 30 Nov 2018 18:25:32 +0900 Received: from plum.e01.socionext.com (unknown [10.213.132.32]) by kinkan.css.socionext.com (Postfix) with ESMTP id CFCFB1A1210; Fri, 30 Nov 2018 18:25:31 +0900 (JST) From: Kunihiko Hayashi To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kunihiko Hayashi Subject: [RFC PATCH net v2] net: phy: Fix the issue that netif always links up after resuming Date: Fri, 30 Nov 2018 18:25:16 +0900 Message-Id: <1543569916-8714-1-git-send-email-hayashi.kunihiko@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Even though the link is down before entering hibernation, there is an issue that the network interface always links up after resuming from hibernation. The phydev->state is PHY_READY before enabling the network interface, so the link is down. After resuming from hibernation, the phydev->state is forcibly set to PHY_UP in mdio_bus_phy_restore(), and the link becomes up. This patch adds a new convenient function to check whether the PHY is in a started state, and expects to solve the issue by changing phydev->state to PHY_UP and calling phy_start_machine() only when the PHY is started. Suggested-by: Heiner Kallweit Signed-off-by: Kunihiko Hayashi --- drivers/net/phy/phy.c | 2 +- drivers/net/phy/phy_device.c | 9 +++++---- include/linux/phy.h | 10 ++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 1d73ac3..f484d03 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -670,7 +670,7 @@ void phy_stop_machine(struct phy_device *phydev) cancel_delayed_work_sync(&phydev->state_queue); mutex_lock(&phydev->lock); - if (phydev->state > PHY_UP && phydev->state != PHY_HALTED) + if (phy_is_started(phydev)) phydev->state = PHY_UP; mutex_unlock(&phydev->lock); } diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index ab33d17..2c39717 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -309,10 +309,11 @@ static int mdio_bus_phy_restore(struct device *dev) return ret; /* The PHY needs to renegotiate. */ - phydev->link = 0; - phydev->state = PHY_UP; - - phy_start_machine(phydev); + if (phy_is_started(phydev)) { + phydev->link = 0; + phydev->state = PHY_UP; + phy_start_machine(phydev); + } return 0; } diff --git a/include/linux/phy.h b/include/linux/phy.h index 3ea87f7..c194b45 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -898,6 +898,16 @@ static inline bool phy_is_pseudo_fixed_link(struct phy_device *phydev) } /** + * phy_is_started - Convenience function for testing whether a PHY is in + * a started state + * @phydev: the phy_device struct + */ +static inline bool phy_is_started(struct phy_device *phydev) +{ + return phydev->state >= PHY_UP && phydev->state != PHY_HALTED; +} + +/** * phy_write_mmd - Convenience function for writing a register * on an MMD on a given PHY. * @phydev: The phy_device struct