From patchwork Tue Mar 7 15:53:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 65653 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:570d:b0:a1:2e52:cf23 with SMTP id h13csp1980615dyk; Tue, 7 Mar 2023 07:58:50 -0800 (PST) X-Google-Smtp-Source: AK7set+szZLUFSJ4rmCU17ylME+FjXbvT+d2pqAQM6+/LAaVghV+nkZZw67Q7WAbxswAZ3BDKByW X-Received: by 2002:a17:90b:1b04:b0:237:d2b0:dac6 with SMTP id nu4-20020a17090b1b0400b00237d2b0dac6mr16319992pjb.33.1678204730191; Tue, 07 Mar 2023 07:58:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678204730; cv=none; d=google.com; s=arc-20160816; b=UtVg7XiBSfcd1ITiT+tvPnOcvwVYDlGK0y5si6k+U2Urayk1kOFe/tk4iXced/36a1 NqekOSNRXXBoifO9ZKmSf0vs4r6OqUY+yq+4SExxXzpL7OuTlnTPnTrjAfSG3U2f0V+v /yb/9ZXAcpk+NDrTo5Dx7zjU98fKmLWkFzqLHErPCvM1jaM5XgZ6K+ACpGfP6rh+kXvh aIycYDeXT1JT5lF+b2nBSBUSl0Q7aU/j63If77HA7ctjbSY/kvd7XaTHU24KQbhPf3P2 1aEMencGHl7ypmt+CsaxaTmBIdkEWdQVQEaEjHmIcUk87lsbbVNS2JOLrFLaMASFW5Hr LlgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=0HfoUyn5+ovWJh8xz+qq6Vp7zPUUAYZvXM5HH2VsaY0=; b=J/LaiPn6irH+fO8gG9U6gX29CfV471qHagcvp/CEuf8UbHrcgUKW0GzFB1/DQGOzcs k3PA3fLW+9mS2KV+/UASy+rhkS7LwfI/zIQQyyyVOTy3pQKRCVSSM1aNDREn3iJjWQB8 6/lcJOF+c2vJXTfFl/Yiq1rWY5N+NJREmwtRDUOE6Rj8KPQkU0gXIvwrJQVH5y0E2lud 0A5BFtNEr7/BALtiwxmzDSMqI0V6veiIPT+3c20lmHHBnjAjhJ8sLbD/G9IXVaCwNOOQ 7xLIe0OWwYVHxOB4oMQTGmmYHl7RbDBvWm+ntzk7c/K9XOZCfTZW5JeppFpHFhva2s3x eOTQ== ARC-Authentication-Results: i=1; mx.google.com; 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 on11-20020a17090b1d0b00b0022c320a4d27si16923544pjb.189.2023.03.07.07.58.37; Tue, 07 Mar 2023 07:58:50 -0800 (PST) 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; 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 S231572AbjCGP4m (ORCPT + 99 others); Tue, 7 Mar 2023 10:56:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231598AbjCGP4I (ORCPT ); Tue, 7 Mar 2023 10:56:08 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99B3E8F530; Tue, 7 Mar 2023 07:55:37 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pZZf5-0001rV-2X; Tue, 07 Mar 2023 16:55:35 +0100 Date: Tue, 7 Mar 2023 15:53:58 +0000 From: Daniel Golle To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Russell King , Heiner Kallweit , Lorenzo Bianconi , Mark Lee , John Crispin , Felix Fietkau , AngeloGioacchino Del Regno , Matthias Brugger , DENG Qingfang , Landen Chao , Sean Wang , Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" , Vladimir Oltean , Florian Fainelli , Andrew Lunn , Vladimir Oltean Cc: Jianhui Zhao , =?iso-8859-1?q?Bj=F8rn?= Mork , Frank Wunderlich , Alexander Couzens Subject: [PATCH net-next v12 08/18] net: ethernet: mtk_eth_soc: fix 1000Base-X and 2500Base-X modes Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759725203128188270?= X-GMAIL-MSGID: =?utf-8?q?1759725203128188270?= After conversion to phylink_pcs the 1000Base-X and 2500Base-X modes would work only after `ethtool -s eth1 autoneg off`. As ethtool autoneg and the ETHTOOL_LINK_MODE_Autoneg_BIT is supposed to control auto-negotiation on the external interface it doesn't make much sense to use it to control on-board SGMII auto-negotiation between MAC and PHY. Set correct values to really only enable SGMII auto-negotiation when actually operating in SGMII mode. For 1000Base-X and 2500Base-X mode, enable remote-fault detection only if in-band-status is enabled. This fixes using 1000Base-X and 2500Base-X SFPs on the BananaPi R3 board and also makes it possible to use interface-mode-switching PHYs operating in either SGMII mode for 10M/100M/1000M or in 2500Base-X for 2500M mode on other boards. Fixes: 14a44ab0330d ("net: mtk_eth_soc: partially convert to phylink_pcs") Signed-off-by: Daniel Golle Tested-by: Frank Wunderlich --- drivers/net/ethernet/mediatek/mtk_sgmii.c | 24 +++++------------------ 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_sgmii.c b/drivers/net/ethernet/mediatek/mtk_sgmii.c index 61bd9986466a..58d8cb3aa7f4 100644 --- a/drivers/net/ethernet/mediatek/mtk_sgmii.c +++ b/drivers/net/ethernet/mediatek/mtk_sgmii.c @@ -38,9 +38,9 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, const unsigned long *advertising, bool permit_pause_to_mac) { - bool mode_changed = false, changed, use_an; struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs); - unsigned int rgc3, sgm_mode, bmcr; + unsigned int rgc3, sgm_mode = 0, bmcr = 0; + bool mode_changed = false, changed; int advertise, link_timer; advertise = phylink_mii_c22_pcs_encode_advertisement(interface, @@ -55,27 +55,13 @@ static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, if (interface == PHY_INTERFACE_MODE_SGMII) { sgm_mode = SGMII_IF_MODE_SGMII; if (phylink_autoneg_inband(mode)) { + bmcr = SGMII_AN_ENABLE; sgm_mode |= SGMII_REMOTE_FAULT_DIS | SGMII_SPEED_DUPLEX_AN; - use_an = true; - } else { - use_an = false; } - } else if (phylink_autoneg_inband(mode)) { - /* 1000base-X or 2500base-X autoneg */ - sgm_mode = SGMII_REMOTE_FAULT_DIS; - use_an = linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, - advertising); - } else { + } else if (!phylink_autoneg_inband(mode)) { /* 1000base-X or 2500base-X without autoneg */ - sgm_mode = 0; - use_an = false; - } - - if (use_an) { - bmcr = SGMII_AN_ENABLE; - } else { - bmcr = 0; + sgm_mode = SGMII_REMOTE_FAULT_DIS; } if (mpcs->interface != interface) {