Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2567870lkm; Mon, 20 Sep 2021 18:55:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMndhkuDLu63KPTuSHK4RiHWHsPy+98CLtl64zV8z9zpWqjtnDqdafjWabz6mw0zsz7+i3 X-Received: by 2002:a5d:8185:: with SMTP id u5mr21469974ion.173.1632189005102; Mon, 20 Sep 2021 18:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189005; cv=none; d=google.com; s=arc-20160816; b=lT05kaLyDseTLJ5emn8/B8msFoWmvVSW3uYOFKrqrYVybLwPRhwHowA43+ypx2vKyL g7c/CZEZpSo8moDl1cKLxg7VnWXT6a2O+LeNTVOtMv/TuqqiDMBbuW3wmAMMeVpePjNb 7+pav1JA9DdfxRkoG8FQQsVAzzRUVERqqNJjsW8S7ENJC/eFBzTJiD1fK/5myFFM4oVE /FAkpTDDgKB67T96fmKT94zN8pTZzfEuewb2C2bM18Dkg5jRYBe9LQyGcAySbGTmJKZP txHhfaF1iZQKmSJ7+h3ff4YSrXX3C01sSP0BRMYdNNJYWgzrEQ2KREdfuCClFRBnwz6v /SvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GmO6ZVQTWi4iPUUXsK6Mjf5zNA1HB8lmNSBBnvl9iF0=; b=DWg+kKo+7KqS2bR8uu+OdT6DoWve2NkV5fObIIjGBTn4eMY0WaJe3z3hCD1DMdvwF7 C+T5BT+AG8VP/E6Zr0rajIJB2lLRWIWnV4+DAAE4UN0lojJScIf8H5iX1TVTFUlX1OKr hZR3wsRMFXRGd7MyKRc6dotitvQCYfdQTiIYTq8B7Tl5vIZQ+qMvoSJBdICmvHm/NpXo WKYGfVQXOPPiSJfSYbJUrun+7CbX93Z8HpzioFBoabxanSQsAc75cuA2l6Vgsflpjvl+ E1681RHyM7cq3mypwAgzHoF5OGzgqTbAj8juT60YCv/AeCIelT5wGyDaDIAVCsDLzFBR 8k4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FKVpPneH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u3si16970100iom.82.2021.09.20.18.49.54; Mon, 20 Sep 2021 18:50:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FKVpPneH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350350AbhITSBl (ORCPT + 99 others); Mon, 20 Sep 2021 14:01:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355490AbhITRyz (ORCPT ); Mon, 20 Sep 2021 13:54:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3A41661CF1; Mon, 20 Sep 2021 17:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158029; bh=KUe582VJtgGZabFDrgxZbLWdHNKJM0l/JO/BSUaJiU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FKVpPneHe3G2YjzZqtNHsPI1fT2B4kAOUPAiV5Hj0JZ9TSaaac9kl6MsePDvu8BCS W3gcJSkBnXpt27wxfp7MwSvdchmFDE1ZJMtuev4A1GfdAzs7f9Zc70KVR8LzHTjXeW VyNrNoBc9Q7OmoP6PWCQztTIpzsWEAlcLF+9dUUw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrius V , Darek Strugacz , Florian Fainelli , "David S. Miller" Subject: [PATCH 4.19 262/293] r6040: Restore MDIO clock frequency after MAC reset Date: Mon, 20 Sep 2021 18:43:44 +0200 Message-Id: <20210920163942.362731744@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Florian Fainelli commit e3f0cc1a945fcefec0c7c9d9dfd028a51daa1846 upstream. A number of users have reported that they were not able to get the PHY to successfully link up, especially after commit c36757eb9dee ("net: phy: consider AN_RESTART status when reading link status") where we stopped reading just BMSR, but we also read BMCR to determine the link status. Andrius at NetBSD did a wonderful job at debugging the problem and found out that the MDIO bus clock frequency would be incorrectly set back to its default value which would prevent the MDIO bus controller from reading PHY registers properly. Back when we only read BMSR, if we read all 1s, we could falsely indicate a link status, though in general there is a cable plugged in, so this went unnoticed. After a second read of BMCR was added, a wrong read will lead to the inability to determine a link UP condition which is when it started to be visibly broken, even if it was long before that. The fix consists in restoring the value of the MD_CSR register that was set prior to the MAC reset. Link: http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=53494 Fixes: 90f750a81a29 ("r6040: consolidate MAC reset to its own function") Reported-by: Andrius V Reported-by: Darek Strugacz Tested-by: Darek Strugacz Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/rdc/r6040.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/net/ethernet/rdc/r6040.c +++ b/drivers/net/ethernet/rdc/r6040.c @@ -133,6 +133,8 @@ #define PHY_ST 0x8A /* PHY status register */ #define MAC_SM 0xAC /* MAC status machine */ #define MAC_SM_RST 0x0002 /* MAC status machine reset */ +#define MD_CSC 0xb6 /* MDC speed control register */ +#define MD_CSC_DEFAULT 0x0030 #define MAC_ID 0xBE /* Identifier register */ #define TX_DCNT 0x80 /* TX descriptor count */ @@ -368,8 +370,9 @@ static void r6040_reset_mac(struct r6040 { void __iomem *ioaddr = lp->base; int limit = MAC_DEF_TIMEOUT; - u16 cmd; + u16 cmd, md_csc; + md_csc = ioread16(ioaddr + MD_CSC); iowrite16(MAC_RST, ioaddr + MCR1); while (limit--) { cmd = ioread16(ioaddr + MCR1); @@ -381,6 +384,10 @@ static void r6040_reset_mac(struct r6040 iowrite16(MAC_SM_RST, ioaddr + MAC_SM); iowrite16(0, ioaddr + MAC_SM); mdelay(5); + + /* Restore MDIO clock frequency */ + if (md_csc != MD_CSC_DEFAULT) + iowrite16(md_csc, ioaddr + MD_CSC); } static void r6040_init_mac_regs(struct net_device *dev)