Message ID | 20230619081633.589703-1-linux@rasmusvillemoes.dk |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2849924vqr; Mon, 19 Jun 2023 01:31:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ABEfkU9ihBF/iIfdUslWrV6ERehoukvzR4bMhh9ljYaFi/w4IN3wPo9Dgt4d5RLSbU/JL X-Received: by 2002:a17:90b:4b12:b0:25b:e0f8:7dbb with SMTP id lx18-20020a17090b4b1200b0025be0f87dbbmr4698649pjb.6.1687163509663; Mon, 19 Jun 2023 01:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687163509; cv=none; d=google.com; s=arc-20160816; b=hYe8kRMflpvtVZgtmR7Iz2RFuOlp9kiSWzhdjfRJPLf3a5Jv6PeFk5UXJAS4q0CYAN FAdWhYgeQ3qnE8hsCVmoS4FUGwJFOXsde/NBDHhd8nnhdL5iTcEJRLQJxBH2LrodT4lc iato3IHNS13g5RHtdvqvozsLxY/y3FDllFoOsA/lUfgPDMjQrdNQbHu/l6CTGvJ1G8xG O+pAnUQazx4kXaqllUY4NorBieZT/CulPBiTeJym0t9h6wUS3nAoUeyjC+DFRklYTE6o d1NqbnnCOvvJnVWlfn03GpS8TYtzhPYD9xd2YqrZbcBf4kQri8Q5GFAId1lxB6UyhNH6 /Jbw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=2Yv2rIjaXMDMpPLlwF9jwu6QeCtYranVnkffyN+HyQU=; b=OABi8cBYMtPr1r3M6BUYWmF+axTvvolTrfodTHUhFG5uCpDBFjEi8oV09j0vjdfAx7 K96nultrjlERoZDaydsUa+TBFgPyjPlXRSWPd2rngJ02H7hwG5upb6f64flMsen7jVtg +GryaM80dCjPbfHGdXyrcLgGixR8v6nCYCSx3WfWreOJqhP2SCPICEwPZvU/FSQP3Ged bMxxiGg7/IYMo1dywqTul6QhPxREWIARnoYKhlwIT7UtM9wOdghCNAXP/v9a10EoijSV eOiuxI8Gr0i16fMmFWWI4VztbYT1OVEVEFd56SF+rKvLQU26Y841Ps+uT/cLRiG6nMGm pK7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=PwoutS+B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv11-20020a17090af18b00b0024753ec4dccsi6781564pjb.124.2023.06.19.01.31.36; Mon, 19 Jun 2023 01:31:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=PwoutS+B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230160AbjFSIRe (ORCPT <rfc822;duw91626@gmail.com> + 99 others); Mon, 19 Jun 2023 04:17:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbjFSIRb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 19 Jun 2023 04:17:31 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A25AC10D for <linux-kernel@vger.kernel.org>; Mon, 19 Jun 2023 01:17:30 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f762b3227dso3795716e87.1 for <linux-kernel@vger.kernel.org>; Mon, 19 Jun 2023 01:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; t=1687162649; x=1689754649; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2Yv2rIjaXMDMpPLlwF9jwu6QeCtYranVnkffyN+HyQU=; b=PwoutS+BntF9MCQalJkmoo5F0NDU9r5BLunwlMmivEzDmJCqE0xV3ZIlYjX5JDEi/p T1imxKFaIUWUEf1c8DVAUeT0hwnmVlNhEgz8f3A1trJ8ZvDzPZUpL8GtWINkVb4XyxGN lGsmTavgOCfyEFps6M/vTYd7rLHJU07DiLGNo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687162649; x=1689754649; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2Yv2rIjaXMDMpPLlwF9jwu6QeCtYranVnkffyN+HyQU=; b=ceJJRyRdbpquGvNiSrDHIIjgdxE06Q1ntI2hAlfBDnZq3NcOsaE54Xp1KwPK2V+x7e BKpmzbp+oZrqEujD/LqOIfuYdXznDnS75f5K/ZtfsG9zp4owpvsEfVAcX+jFnovdGls1 ZsozijeDXksrgN2ZmFqs3LClVYWjX0OVnis+XfbOh7Q9tLvaVDi9FEMlw66I67XQdKjZ uqX71pBNn9w3eOlrbeoSI1NRYzbsTIiC6DMclMYaYfEDovYNBNZ1D20XcUuqz4mIg1j1 aTQZ2jo2mj+ZJemr8DHR8oAhhB/04CWnHr8iJuo1bcxshsVG3PY18ALbCanxT/cz6Rg1 47kg== X-Gm-Message-State: AC+VfDwBmtlelpiLw1ajQ3nuVF9yCUUM6b84YnP3bVsm1d3vIbYjxarC 3hMrYPoKmw0tkqAtx8tMVwHRKA== X-Received: by 2002:a05:6512:2ef:b0:4f4:ffae:7b93 with SMTP id m15-20020a05651202ef00b004f4ffae7b93mr2891866lfq.7.1687162648785; Mon, 19 Jun 2023 01:17:28 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id g23-20020a19ee17000000b004f4b3e9e0cesm4137924lfb.297.2023.06.19.01.17.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 01:17:28 -0700 (PDT) From: Rasmus Villemoes <linux@rasmusvillemoes.dk> To: Woojung Huh <woojung.huh@microchip.com>, UNGLinuxDriver@microchip.com, Andrew Lunn <andrew@lunn.ch>, Florian Fainelli <f.fainelli@gmail.com>, Vladimir Oltean <olteanv@gmail.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Robert Hancock <hancock@sedsystems.ca> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>, stable@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next] net: dsa: microchip: ksz9477: follow errata sheet when applying fixups Date: Mon, 19 Jun 2023 10:16:32 +0200 Message-Id: <20230619081633.589703-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769119163988314919?= X-GMAIL-MSGID: =?utf-8?q?1769119163988314919?= |
Series |
[net-next] net: dsa: microchip: ksz9477: follow errata sheet when applying fixups
|
|
Commit Message
Rasmus Villemoes
June 19, 2023, 8:16 a.m. UTC
The errata sheets for both ksz9477 and ksz9567 begin with
IMPORTANT NOTE
Multiple errata workarounds in this document call for changing PHY
registers for each PHY port. PHY registers 0x0 to 0x1F are in the
address range 0xN100 to 0xN13F, while indirect (MMD) PHY registers
are accessed via the PHY MMD Setup Register and the PHY MMD Data
Register.
Before configuring the PHY MMD registers, it is necessary to set the
PHY to 100 Mbps speed with auto-negotiation disabled by writing to
register 0xN100-0xN101. After writing the MMD registers, and after
all errata workarounds that involve PHY register settings, write
register 0xN100-0xN101 again to enable and restart auto-negotiation.
Without that explicit auto-neg restart, we do sometimes have problems
establishing link.
Rather than writing back the hardcoded 0x1340 value the errata sheet
suggests (which likely just corresponds to the most common strap
configuration), restore the original value, setting the
PORT_AUTO_NEG_RESTART bit if PORT_AUTO_NEG_ENABLE is set.
Fixes: 1fc33199185d ("net: dsa: microchip: Add PHY errata workarounds")
Cc: stable@vger.kernel.org
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
While I do believe this is a fix, I don't think it's post-rc7
material, hence targeting net-next with cc stable.
drivers/net/dsa/microchip/ksz9477.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
Comments
> static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port) > { > + u16 cr; > + > + /* Errata document says the PHY must be configured to 100Mbps > + * with auto-neg disabled before configuring the PHY MMD > + * registers. > + */ > + ksz_pread16(dev, port, REG_PORT_PHY_CTRL, &cr); > + ksz_pwrite16(dev, port, REG_PORT_PHY_CTRL, > + PORT_SPEED_100MBIT | PORT_FULL_DUPLEX); > + For this fix, these are fine. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Looking at the values of PORT_SPEED_100MBIT and PORT_FULL_DUPLEX, they are identical to BMCR_SPEED100 and BMCR_FULLDPLX. In fact, it looks like for 9477 this is a standard BMCR. Please could you add a follow up patch which replaces these #defines with the standard ones in include/uapi/linux/mii.h. The code is then more understandable by people who know the standard defines. Thanks Andrew
On Mon, 2023-06-19 at 10:16 +0200, Rasmus Villemoes wrote: > CAUTION: This email originated from outside of the organization. Do > not click links or open attachments unless you recognize the sender > and know the content is safe. > > The errata sheets for both ksz9477 and ksz9567 begin with > > IMPORTANT NOTE > > Multiple errata workarounds in this document call for changing PHY > registers for each PHY port. PHY registers 0x0 to 0x1F are in the > address range 0xN100 to 0xN13F, while indirect (MMD) PHY registers > are accessed via the PHY MMD Setup Register and the PHY MMD Data > Register. > > Before configuring the PHY MMD registers, it is necessary to set > the > PHY to 100 Mbps speed with auto-negotiation disabled by writing to > register 0xN100-0xN101. After writing the MMD registers, and after > all errata workarounds that involve PHY register settings, write > register 0xN100-0xN101 again to enable and restart auto- > negotiation. > > Without that explicit auto-neg restart, we do sometimes have problems > establishing link. > > Rather than writing back the hardcoded 0x1340 value the errata sheet > suggests (which likely just corresponds to the most common strap > configuration), restore the original value, setting the > PORT_AUTO_NEG_RESTART bit if PORT_AUTO_NEG_ENABLE is set. > > Fixes: 1fc33199185d ("net: dsa: microchip: Add PHY errata > workarounds") > Cc: stable@vger.kernel.org > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> > --- > While I do believe this is a fix, I don't think it's post-rc7 > material, hence targeting net-next with cc stable. I don't think this will apply to net-next as the relevant code has been moved to the Micrel PHY driver and removed from this one in the following commits, and effectively the same change to disable autoneg before the register writes and re-enable afterwards was incorporated: commit 26dd2974c5b5caef358784530c9e72715adc8f5b Author: Robert Hancock <robert.hancock@calian.com> Date: Mon Jun 5 09:39:42 2023 -0600 net: phy: micrel: Move KSZ9477 errata fixes to PHY driver commit 6068e6d7ba5001dfb96bb8b7b92e2ed2a5877786 Author: Robert Hancock <robert.hancock@calian.com> Date: Mon Jun 5 09:39:43 2023 -0600 net: dsa: microchip: remove KSZ9477 PHY errata handling However, your patch may be reasonable to apply to -rc7 or stable as a more targeted change for those releases. > > drivers/net/dsa/microchip/ksz9477.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/drivers/net/dsa/microchip/ksz9477.c > b/drivers/net/dsa/microchip/ksz9477.c > index bf13d47c26cf..9a712ea71ee7 100644 > --- a/drivers/net/dsa/microchip/ksz9477.c > +++ b/drivers/net/dsa/microchip/ksz9477.c > @@ -902,6 +902,16 @@ static void ksz9477_port_mmd_write(struct > ksz_device *dev, int port, > > static void ksz9477_phy_errata_setup(struct ksz_device *dev, int > port) > { > + u16 cr; > + > + /* Errata document says the PHY must be configured to 100Mbps > + * with auto-neg disabled before configuring the PHY MMD > + * registers. > + */ > + ksz_pread16(dev, port, REG_PORT_PHY_CTRL, &cr); > + ksz_pwrite16(dev, port, REG_PORT_PHY_CTRL, > + PORT_SPEED_100MBIT | PORT_FULL_DUPLEX); > + > /* Apply PHY settings to address errata listed in > * KSZ9477, KSZ9897, KSZ9896, KSZ9567, KSZ8565 > * Silicon Errata and Data Sheet Clarification documents: > @@ -943,6 +953,13 @@ static void ksz9477_phy_errata_setup(struct > ksz_device *dev, int port) > ksz9477_port_mmd_write(dev, port, 0x1c, 0x1d, 0xe7ff); > ksz9477_port_mmd_write(dev, port, 0x1c, 0x1e, 0xefff); > ksz9477_port_mmd_write(dev, port, 0x1c, 0x20, 0xeeee); > + > + /* Restore PHY CTRL register, restart auto-negotiation if > + * enabled in the original value. > + */ > + if (cr & PORT_AUTO_NEG_ENABLE) > + cr |= PORT_AUTO_NEG_RESTART; > + ksz_pwrite16(dev, port, REG_PORT_PHY_CTRL, cr); > } > > void ksz9477_get_caps(struct ksz_device *dev, int port, > -- > 2.37.2 > -- Robert Hancock <robert.hancock@calian.com>
On Mon, Jun 19, 2023 at 10:16:32AM +0200, Rasmus Villemoes wrote: > The errata sheets for both ksz9477 and ksz9567 begin with > > IMPORTANT NOTE > > Multiple errata workarounds in this document call for changing PHY > registers for each PHY port. PHY registers 0x0 to 0x1F are in the > address range 0xN100 to 0xN13F, while indirect (MMD) PHY registers > are accessed via the PHY MMD Setup Register and the PHY MMD Data > Register. > > Before configuring the PHY MMD registers, it is necessary to set the > PHY to 100 Mbps speed with auto-negotiation disabled by writing to > register 0xN100-0xN101. After writing the MMD registers, and after > all errata workarounds that involve PHY register settings, write > register 0xN100-0xN101 again to enable and restart auto-negotiation. > > Without that explicit auto-neg restart, we do sometimes have problems > establishing link. > > Rather than writing back the hardcoded 0x1340 value the errata sheet > suggests (which likely just corresponds to the most common strap > configuration), restore the original value, setting the > PORT_AUTO_NEG_RESTART bit if PORT_AUTO_NEG_ENABLE is set. > > Fixes: 1fc33199185d ("net: dsa: microchip: Add PHY errata workarounds") > Cc: stable@vger.kernel.org > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> > --- > While I do believe this is a fix, I don't think it's post-rc7 > material, hence targeting net-next with cc stable. Hi Rasmus, unfortunately this does not seem to apply to net-next. Please consider rebasing and reposting. Please include Andrew's Reviewed-by tag unless there are substantial changes (seems unlikely).
On 19/06/2023 19.31, Robert Hancock wrote: > On Mon, 2023-06-19 at 10:16 +0200, Rasmus Villemoes wrote: >> >> Fixes: 1fc33199185d ("net: dsa: microchip: Add PHY errata >> workarounds") >> Cc: stable@vger.kernel.org >> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> >> --- >> While I do believe this is a fix, I don't think it's post-rc7 >> material, hence targeting net-next with cc stable. > > I don't think this will apply to net-next as the relevant code has been > moved to the Micrel PHY driver and removed from this one in the > following commits, Ah, sorry about that. This code hadn't been touched in a very long time, so I didn't actually think to check -next. and effectively the same change to disable autoneg > before the register writes and re-enable afterwards was incorporated: Yes, except it seems to always enable autoneg, even if the phy was strapped otherwise. That's not a problem for our use case. > However, your patch may be reasonable to apply to -rc7 or stable as a > more targeted change for those releases. Well, yes, it could be backported, but then there'd be a (simple) conflict when net-next is to be merged in the next window. So I don't think it's worth it. Unless the net maintainers decide otherwise, please just drop this patch. Rasmus
diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index bf13d47c26cf..9a712ea71ee7 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -902,6 +902,16 @@ static void ksz9477_port_mmd_write(struct ksz_device *dev, int port, static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port) { + u16 cr; + + /* Errata document says the PHY must be configured to 100Mbps + * with auto-neg disabled before configuring the PHY MMD + * registers. + */ + ksz_pread16(dev, port, REG_PORT_PHY_CTRL, &cr); + ksz_pwrite16(dev, port, REG_PORT_PHY_CTRL, + PORT_SPEED_100MBIT | PORT_FULL_DUPLEX); + /* Apply PHY settings to address errata listed in * KSZ9477, KSZ9897, KSZ9896, KSZ9567, KSZ8565 * Silicon Errata and Data Sheet Clarification documents: @@ -943,6 +953,13 @@ static void ksz9477_phy_errata_setup(struct ksz_device *dev, int port) ksz9477_port_mmd_write(dev, port, 0x1c, 0x1d, 0xe7ff); ksz9477_port_mmd_write(dev, port, 0x1c, 0x1e, 0xefff); ksz9477_port_mmd_write(dev, port, 0x1c, 0x20, 0xeeee); + + /* Restore PHY CTRL register, restart auto-negotiation if + * enabled in the original value. + */ + if (cr & PORT_AUTO_NEG_ENABLE) + cr |= PORT_AUTO_NEG_RESTART; + ksz_pwrite16(dev, port, REG_PORT_PHY_CTRL, cr); } void ksz9477_get_caps(struct ksz_device *dev, int port,