Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1007524yba; Thu, 4 Apr 2019 02:16:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqy43MVgqWthqccF0oPdQEOVJqNJqaTAIyuR0QIjM2kEdeFvi8fNpgw3pG74rHyOLdf9Pl/a X-Received: by 2002:a62:70c6:: with SMTP id l189mr4739661pfc.139.1554369418024; Thu, 04 Apr 2019 02:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369418; cv=none; d=google.com; s=arc-20160816; b=bra2nNI0aCbUnwaWU2MTgDm5dI7EDcTFepzjHKAybvuffIHeBUvDwD+n2LqZWRqAwx 8Wekv+Sx17r4eVJKKrDCkwISJb95Ic9rDBxSnLaD1IcHhd9KBIyzvQ+I0IJQ56FVP0de qioqgSWh0H1WSNSYJ0ynlJJIcaZC3F4hhbSOfiACe+tCKg+DAg1DisEF/1XgcBS1bnom 1qdXOkOsRVUaZqJUZyrzYPZODNk9VOzkoD6hkgT3G6MmF9mCXlP3eH87Ouu/sCITuvu/ RoZNnwKuHOg48aB+EhWcICiMSZ90RtMbAd7S9m44wwEaj37lRiCeogJ9tNECO1k4nkgg t7cg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ERzszxlJzLOlnY5/vE+Mxqdc0ewaJPCt6A0Jd3K+NNg=; b=KCSEWGsc61ScwmWU31MyPo6OAeRVIZZ+JfacQXTMZuUJCKNobpcjilvMHIRaX7BriG uZ+2ldtSUicGCVg9hV/8/xc4iFqab8weCwdiD5KedEbwxO2oAZjdp90DT9/o6U+7p5Zx C0DXlzJCViBAcjy6jSmggwQDhZ8dmEi4WVg19Pe4PWrAMDgE4yz+ixPeO5Mt63ar/bZG IDkT7zQPKXUZUpI8OfPhXFe0KxfWdvMMpSOWSsGrwwnOIMe1GEDTc0ZLO+FV88ZNXjtb Tvc0w/LOt8wvt0piSRpES83qjONwHJiaFQlyi6p5vw/TH8K/5ovSbp2XEurxRO2M6Y7j sd9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HSDGgqEH; 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 v5si14720852pfm.134.2019.04.04.02.16.43; Thu, 04 Apr 2019 02:16:58 -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=HSDGgqEH; 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 S2387793AbfDDJO6 (ORCPT + 99 others); Thu, 4 Apr 2019 05:14:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:55790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387786AbfDDJO4 (ORCPT ); Thu, 4 Apr 2019 05:14:56 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2BCB42054F; Thu, 4 Apr 2019 09:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369295; bh=IbPcy0E3XWWTakrYe9lPkMq0MC0r4YM+cWYRHjWsCFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSDGgqEHAlTctCVO6nYOgshX1062xAhogjgWRjTA4tLDLk1XHM6hj1qwGGrd7a1WC I5HLjwBNG+7Z2NX++gjxHGqUvtMMfJ+w7JYuvKBVjHlY/rTSRh3ThbSkSA9fEWB9PB 4oW+y+a5jmdqJObZVVgbiY1pAi377LtBfpYenG4A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heiner Kallweit , "David S. Miller" , Sasha Levin Subject: [PATCH 5.0 157/246] net: phy: consider latched link-down status in polling mode Date: Thu, 4 Apr 2019 10:47:37 +0200 Message-Id: <20190404084624.668164669@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 739434fe04fa..adf79614c2db 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