Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp998857yba; Thu, 4 Apr 2019 02:05:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyz7fuaURLNjIGNymUFCN89iiWzN6cgiMl0MMN0sbIl6NzJGERBmw4bF2EBGO/ryNbSBump X-Received: by 2002:a17:902:4681:: with SMTP id p1mr5181841pld.42.1554368738229; Thu, 04 Apr 2019 02:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368738; cv=none; d=google.com; s=arc-20160816; b=lXuGz6DZD1QAoRZyz27dBFoYWW3MbsQ0fPdOlDyAxvis5Wy/qw9EYxsSbd72d3AJxm 5rt756XneK4EIKuK9tNObdUgCND5KTR2UrJ9JnOZdDq0kAEJP7HSb33fC+jbCP5ZmBMa JYS8g2ASVRBytrUlEhM17CxQXfw+OIG5XRBaD+zCFsvcYkp9fK8CFl7q/WtXJ5NBzJA0 fHSHA+AJMcvp6CoiPLFO/h8YryKCpImsqJu2WgTOew14bVcOEcNX/qrEdEaliQZNyAc5 9ubeiHcxOdlJxrYZ8pwxp9p02HeeUw+4jOBCiAJHxqac9g+gsca/wqxcDxCIKjmKuKnO a2FA== 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=GDKzS5smPtbOILu7AHGn5S4q59/mtb0oh4tUWf1eoF0=; b=W6hN1pC1lUxFX8ciVut8xAwCBlEoei9OY5aSeiw6EOP57Gui52rewN019hvYkjyDoV v4Ribh06lmJ3jJwdtfmf7+QVKYcIszPU1eo2bQ4Mn+Rf6j/6Nlc6nbRnwm/HwF9gfe3o 50xqXL8zRU+U2p/el1cNWnZhDa0hnKD+coBLCvnvw8VOwKNza7q5RbCRR1H0WSL/z/e8 /N/1pLlH7gN4Sxv7itq5kXoWS5RHteustNaQXI+6w8/OafGG2J+3zvofEj7fgZ+uqC4i 2NU6WaP16AGWmtrgwpNKHAYeqllrSJqKMCV/sEnZ8evHIg/CmGJ5aDA15CLmC6uTgjKd XdrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MFwpExGr; 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 d2si8314145pld.78.2019.04.04.02.05.22; Thu, 04 Apr 2019 02:05:38 -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=MFwpExGr; 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 S1731922AbfDDJEO (ORCPT + 99 others); Thu, 4 Apr 2019 05:04:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731901AbfDDJEM (ORCPT ); Thu, 4 Apr 2019 05:04:12 -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 384352147C; Thu, 4 Apr 2019 09:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368650; bh=d0l9pjau2bgQ4b11jOXXfLeBvYCetLuAOUSam/BmH4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MFwpExGr9vumNkCE3lusY6zQ8Xo7/gwOjnnTyxKGro8X818Wy+P6zEYKrHDaVl2/X AtR+FrFuUbcI3RGr3QeefFMl5m2FCVio2zIXirZ2FhJ1a5ua66DeyG2GoJ5NJEwEr3 OquwGHIzLBqz22TZLM4Kw6Johp9+suUWfZFiOPDk= 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 4.19 118/187] net: phy: consider latched link-down status in polling mode Date: Thu, 4 Apr 2019 10:47:35 +0200 Message-Id: <20190404084608.813854619@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@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 4.19-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 e1225545362d..0ba3607585bd 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 2c32c795f5dd..8a96d985a52f 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1503,10 +1503,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