Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5646249img; Wed, 27 Mar 2019 12:21:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgO1Pu7S3RHVmfei9cVuYic5GYvSS3iPzzBdVP8QBpGCKcteeGG8/0rj7ekmKNOTnBHy0T X-Received: by 2002:a17:902:8e82:: with SMTP id bg2mr39130233plb.217.1553714499680; Wed, 27 Mar 2019 12:21:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714499; cv=none; d=google.com; s=arc-20160816; b=Zba5cOqNxQrpNcquev54cvQc6magjl4BI+nQYVTyMOg/r3L2bzfLWPwoDYKSDHaBqI VIbhpYz54ajZuVJdOYjkYQOuIsz1f0Y+dRhYs3yrV7IYqldu3ARHqzwSwOB5VP0CJySs kqkPSocKPnu2i1YD3AKTKR3uBuTPQRNvpQjwzW+yAShYXWrtlsncrDWqhu6/zTSR0sT0 4OzIovUOIQtbq7JLSwEPYJrHquCi0IrwudFwPfmr0z8EkCQLAY89/EJkKr2/JBN1HdUj TzlMpx9h/BcBovPJEHC6Ih3GEUJBzNH4StYGW4CRNxzLSZM2v1nWki370ObHyiuIiLIi qSUA== 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=vFzvOSCgRaG3vfkPsx2Kzz20PoaUGl2clxqHCONnPGI=; b=zYt0vNPqRniw9I+ZvikXCIELSXbMAOmEurkMYkudUUg4puFps/2HzLAX2bcG8EMQjT 14YYP7GQgNyW4UXd7XU1w2VA+dp65/y8d3jWkWtqeQgzxN14gYFtJUloIPZF7knLLGfe yFmsrqidY0rQoVkr9hfVvTpb8WhggD5us0Zg0r9n9QwHOd5Uy1/j8QuFCTWPUrU2jOO5 axYdxeVuispt4jMYJT5jpeCysjUrskQXJTjgl9Hurie+4jsvAmrymZ5ewa/539H8H15N p3b/X+rKJZHbH+b9pJx1JHcnDRWWfJvcWbgv3CRJymn6fQi9MG4vQX/3avAMtdI3ZZfm fIkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jsZ8MQMI; 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 n4si18480851pgq.198.2019.03.27.12.21.24; Wed, 27 Mar 2019 12:21:39 -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=jsZ8MQMI; 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 S2388578AbfC0TUj (ORCPT + 99 others); Wed, 27 Mar 2019 15:20:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:49098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388120AbfC0SHR (ORCPT ); Wed, 27 Mar 2019 14:07:17 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 5F8A8217F9; Wed, 27 Mar 2019 18:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710036; bh=4QeUpAm9uf4hKkkPetnR2jOpZ/R93cT3mmnxji3B1L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jsZ8MQMIFQU4LYCmuXo1QDmJF2Nl/+ITmy9/RsoQCSh7GwqsjHFrhU18RMtASy57E /fNK3mR+gN78aNzVYXpj881PHiNpNbP3cDw7DouHebtYVMkgC1jXLqixDKOY5bNrAY SAJdQlYktSv4VOT/UdWgdiEiU3u6ewIIW0HPmaqQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Heiner Kallweit , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 167/262] net: phy: consider latched link-down status in polling mode Date: Wed, 27 Mar 2019 14:00:22 -0400 Message-Id: <20190327180158.10245-167-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 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 93c0970493c71f264e6c3c7caf1ff24a9e1de786 ] The link status value latches link-down events. To get the current status we read the register twice in genphy_update_link(). There's a potential risk that we miss a link-down event in polling mode. This may cause issues if the user e.g. connects his machine to a different network. On the other hand reading the latched value may cause issues in interrupt mode. Following scenario: - After boot link goes up - phy_start() is called triggering an aneg restart, hence link goes down and link-down info is latched. - After aneg has finished link goes up and triggers an interrupt. Interrupt handler reads link status, means it reads the latched "link is down" info. But there won't be another interrupt as long as link stays up, therefore phylib will never recognize that link is up. Deal with both scenarios by reading the register twice in interrupt mode only. Signed-off-by: Heiner Kallweit Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/phy/phy-c45.c | 10 ++++++++-- drivers/net/phy/phy_device.c | 13 +++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c index 03af927fa5ad..e39bf0428dd9 100644 --- a/drivers/net/phy/phy-c45.c +++ b/drivers/net/phy/phy-c45.c @@ -147,9 +147,15 @@ int genphy_c45_read_link(struct phy_device *phydev, u32 mmd_mask) mmd_mask &= ~BIT(devad); /* The link state is latched low so that momentary link - * drops can be detected. Do not double-read the status - * register if the link is down. + * drops can be detected. Do not double-read the status + * in polling mode to detect such short link drops. */ + if (!phy_polling_mode(phydev)) { + val = phy_read_mmd(phydev, devad, MDIO_STAT1); + if (val < 0) + return val; + } + val = phy_read_mmd(phydev, devad, MDIO_STAT1); if (val < 0) return val; diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 46c86725a693..b3d564592ad4 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1683,10 +1683,15 @@ int genphy_update_link(struct phy_device *phydev) { int status; - /* Do a fake read */ - status = phy_read(phydev, MII_BMSR); - if (status < 0) - return status; + /* The link state is latched low so that momentary link + * drops can be detected. Do not double-read the status + * in polling mode to detect such short link drops. + */ + if (!phy_polling_mode(phydev)) { + status = phy_read(phydev, MII_BMSR); + if (status < 0) + return status; + } /* Read link and autonegotiation status */ status = phy_read(phydev, MII_BMSR); -- 2.19.1