From patchwork Thu Oct 12 06:55:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksij Rempel X-Patchwork-Id: 151788 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1031791vqb; Wed, 11 Oct 2023 23:55:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFDUBm3S/KShFqZocU1pctIcZHLSGkxNhKe574pVm+6VoKHoWFnBxGqmpvgElUviMbbo7zn X-Received: by 2002:a05:6808:309b:b0:3a9:e8e2:579d with SMTP id bl27-20020a056808309b00b003a9e8e2579dmr27224735oib.2.1697093745564; Wed, 11 Oct 2023 23:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697093745; cv=none; d=google.com; s=arc-20160816; b=CjjU+GtdyW3pzo71InwfaXG39EEks7xm7ldvyyTSXX8uatPgPVfHKXsqFnQMiMYGWb RJu80eDPlR+OND+UGpmXv50k2dZJmAuPomLly52RbZcgO9P3tsuDJSPX+kyL8+VJThvU ZWnB/GyPYZNqwSNMTC3oV3X39/GUkCRDvzF3/BuyGq8WDng+9schb+3LPJI9HBiVqBPW DfNKbFOSMyDFiVrnVEEmHRB7rQJVNiRKG3N/lhcrqhv7FzP/HkQzs/AM+22aPGnz/asJ Qjveb1+FyAjmnRj6q7WLiGXOwjf9TRvczh6G0CZyX/H/1mhgz84MEftTNfUOpY9CjsC0 SB+w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=PvgQnjC2FXjsgc9dSQwC0PztCS1z1K6cVEs+eoZ412w=; fh=oLQ93Jj/lOpIDL9R7QhdcwQr3NPpWnMdqx90qGj8Dkw=; b=TRZ2RLLGYq/9gnPUKndkj65Ee5mhIEYE9uiHNLKR8ds2Z/h4uXB1vtMNke00stRjhE 1BwnUVN98YeMBL0w/0WcQMeo3mpZoBmJsi83pSIpBa6PVU+YRM/gklwBw/ZVHKTR5vHI dfZv7dHvowu++oi9ybkdgCwFE6uJ2oJuqIS2/JULF0LBmAot/IkTvMkB9zH+43sXkEZW H3PnWck0ZqATm5HIA6jFlMSVmpmMPMFYc75ajEz7LwLH8sLEBkfh4IimiAwYXzVDkYQl y/H5VSz+KYNmPjIGMImgjcJv32XmVBr68fVZgwD+yQslmnbwv6jsQ4tEj42o+gZH8NTf 5DPg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id f2-20020a631002000000b0057771e49c25si1542660pgl.693.2023.10.11.23.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 23:55:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id D37CE80743C0; Wed, 11 Oct 2023 23:55:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377620AbjJLGzc (ORCPT + 19 others); Thu, 12 Oct 2023 02:55:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347080AbjJLGza (ORCPT ); Thu, 12 Oct 2023 02:55:30 -0400 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1432C6 for ; Wed, 11 Oct 2023 23:55:24 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qqpb7-0000qz-T9; Thu, 12 Oct 2023 08:55:05 +0200 Received: from [2a0a:edc0:0:1101:1d::ac] (helo=dude04.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qqpb7-0015L6-Fc; Thu, 12 Oct 2023 08:55:05 +0200 Received: from ore by dude04.red.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1qqpb7-00CHmI-1L; Thu, 12 Oct 2023 08:55:05 +0200 From: Oleksij Rempel To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Heiner Kallweit Cc: Oleksij Rempel , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Russell King , netdev@vger.kernel.org, Alexander Stein Subject: [PATCH net-next v2 3/3] net: phy: micrel: Fix forced link mode for KSZ886X switches Date: Thu, 12 Oct 2023 08:55:02 +0200 Message-Id: <20231012065502.2928220-4-o.rempel@pengutronix.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231012065502.2928220-1-o.rempel@pengutronix.de> References: <20231012065502.2928220-1-o.rempel@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 11 Oct 2023 23:55:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779531771235807460 X-GMAIL-MSGID: 1779531771235807460 Address a link speed detection issue in KSZ886X PHY driver when in forced link mode. Previously, link partners like "ASIX AX88772B" with KSZ8873 could fall back to 10Mbit instead of configured 100Mbit. The issue arises as KSZ886X PHY continues sending Fast Link Pulses (FLPs) even with autonegotiation off, misleading link partners in autoneg mode, leading to incorrect link speed detection. Now, when autonegotiation is disabled, the driver sets the link state forcefully using KSZ886X_CTRL_FORCE_LINK bit. This action, beyond just disabling autonegotiation, makes the PHY state more reliably detected by link partners using parallel detection, thus fixing the link speed misconfiguration. With autonegotiation enabled, link state is not forced, allowing proper autonegotiation process participation. Signed-off-by: Oleksij Rempel --- drivers/net/phy/micrel.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 927d3d54658e..599ebf54fafe 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -1729,9 +1729,35 @@ static int ksz886x_config_aneg(struct phy_device *phydev) { int ret; - ret = genphy_config_aneg(phydev); - if (ret) - return ret; + if (phydev->autoneg != AUTONEG_ENABLE) { + ret = genphy_setup_forced(phydev); + if (ret) + return ret; + + /* When autonegotation is disabled, we need to manually force + * the link state. If we don't do this, the PHY will keep + * sending Fast Link Pulses (FLPs) which are part of the + * autonegotiation process. This is not desired when + * autonegotiation is off. + */ + ret = phy_set_bits(phydev, MII_KSZPHY_CTRL, + KSZ886X_CTRL_FORCE_LINK); + if (ret) + return ret; + } else { + /* If we had previously forced the link state, we need to + * clear KSZ886X_CTRL_FORCE_LINK bit now. Otherwise, the PHY + * will not perform autonegotiation. + */ + ret = phy_clear_bits(phydev, MII_KSZPHY_CTRL, + KSZ886X_CTRL_FORCE_LINK); + if (ret) + return ret; + + ret = genphy_config_aneg(phydev); + if (ret) + return ret; + } /* The MDI-X configuration is automatically changed by the PHY after * switching from autoneg off to on. So, take MDI-X configuration under