Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1490801ybl; Thu, 22 Aug 2019 15:44:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyc65HnPrHzROwotpf4Qyml2V6pG8EtRaehJJ3TzLLjwV4wAmlIKtvdJnoc6Txio3ByDZo+ X-Received: by 2002:aa7:9a12:: with SMTP id w18mr1792366pfj.110.1566513866603; Thu, 22 Aug 2019 15:44:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566513866; cv=none; d=google.com; s=arc-20160816; b=POE8J42LrjTmjEBSA+Ijw0t2vtHPLChrmQqIsxuS3d+i7GsL5bu7l50ddRS84esGUj McHaB9i4kEUEgrAZHy8hPuh8cEy02tKpUybyDQjG4jBPDr3OdZGo4tHao60uSJRh/q9G ER4EunNgaM+ccrjfLdqHxCgZD6M5G+Oh2jrqLnPhja0nheLLrJN8S7vNwUTc8L4PrsZZ CV3do5L2SNcXmDSL82J2IKkrTLbFOTwgxp9Akdpixcwu+HiDD4vuwrNMKTMtg0M6NYX5 fkW7r5le8Bnb18+EliQlBbq15lT2y8U+0022ZWuCdAPhy+WgVnxuCZJDnC+1SwILu/Y7 4m+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zVV31AdUpcVzSHUd7eS097uSdQ+N+067I7nGvB55zq0=; b=rBJaaVrcwclUrX9mNZvHP+X35EpAO1lKgIpaGtgQJeN23vdyeSFaDp7lItFfNdW/sR OmNW4aW2AO6trN/VEPcoBHWYgs0b13qp0P0pz0KZmRySevHKqwePMhXrLPu0h0uqy1Vg UV84oQPahqbcIrPTLHb8FCKVZ/UWM6D4ZTPw8EcXUG6ecMNwwVti38WKJqvYdfYn3L0Z KSRRvfAaKQpaLZIVsq6PYY8zRyi2mnf0L1VNHzCwvArM4zIogHGvcjUSHsFQmIzQm+sD CxQBoyU4GyG5fxIjiKcMJAz5+ROFiOJSchm+N/ECzU6P+LBTN6C6KjOC3/iZNBx5RS/8 GG5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yp+KrW1a; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i188si875123pfb.45.2019.08.22.15.44.10; Thu, 22 Aug 2019 15:44:26 -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=@kernel.org header.s=default header.b=Yp+KrW1a; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390830AbfHVRJt (ORCPT + 99 others); Thu, 22 Aug 2019 13:09:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:59656 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388988AbfHVRJ0 (ORCPT ); Thu, 22 Aug 2019 13:09:26 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CDCEB233FC; Thu, 22 Aug 2019 17:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493766; bh=uJ8/sfbdlDqAU12PFDiJWwX+LpQ0OAKi2RRJzveFS8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yp+KrW1aiAVgJaYFHjH3f/k4arr6dfNsqalYpoW0i9QDwSN7xc2O7BhaW5EO8L8V0 5OG/8+4bpxjhEjzFJQFLAs/LmOpAKPyM48Bo5jWIOmxLyt1qKTU4AigbxY3FS2FdVF Abb3E0X+2ngc6rfvbu36sYe6KExiZqoKe6bDMIXo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Heiner Kallweit , Yonglong Liu , Andrew Lunn , Jakub Kicinski , Greg Kroah-Hartman Subject: [PATCH 5.2 133/135] net: phy: consider AN_RESTART status when reading link status Date: Thu, 22 Aug 2019 13:08:09 -0400 Message-Id: <20190822170811.13303-134-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heiner Kallweit [ Upstream commit c36757eb9dee13681227ad3676d37f14b3a2b2af ] After configuring and restarting aneg we immediately try to read the link status. On some systems the PHY may not yet have cleared the "aneg complete" and "link up" bits, resulting in a false link-up signal. See [0] for a report. Clause 22 and 45 both require the PHY to keep the AN_RESTART bit set until the PHY actually starts auto-negotiation. Let's consider this in the generic functions for reading link status. The commit marked as fixed is the first one where the patch applies cleanly. [0] https://marc.info/?t=156518400300003&r=1&w=2 Fixes: c1164bb1a631 ("net: phy: check PMAPMD link status only in genphy_c45_read_link") Tested-by: Yonglong Liu Signed-off-by: Heiner Kallweit Reviewed-by: Andrew Lunn Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/phy-c45.c | 14 ++++++++++++++ drivers/net/phy/phy_device.c | 12 +++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c index b9d4145781caa..58bb25e4af106 100644 --- a/drivers/net/phy/phy-c45.c +++ b/drivers/net/phy/phy-c45.c @@ -219,6 +219,20 @@ int genphy_c45_read_link(struct phy_device *phydev) int val, devad; bool link = true; + if (phydev->c45_ids.devices_in_package & MDIO_DEVS_AN) { + val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_CTRL1); + if (val < 0) + return val; + + /* Autoneg is being started, therefore disregard current + * link status and report link as down. + */ + if (val & MDIO_AN_CTRL1_RESTART) { + phydev->link = 0; + return 0; + } + } + while (mmd_mask && link) { devad = __ffs(mmd_mask); mmd_mask &= ~BIT(devad); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index ffa402732aea8..3af0af495cf14 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1708,7 +1708,17 @@ EXPORT_SYMBOL(genphy_aneg_done); */ int genphy_update_link(struct phy_device *phydev) { - int status; + int status = 0, bmcr; + + bmcr = phy_read(phydev, MII_BMCR); + if (bmcr < 0) + return bmcr; + + /* Autoneg is being started, therefore disregard BMSR value and + * report link as down. + */ + if (bmcr & BMCR_ANRESTART) + goto done; /* The link state is latched low so that momentary link * drops can be detected. Do not double-read the status -- 2.20.1