From patchwork Thu Aug 17 12:04:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 136258 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp2485186vqi; Sun, 20 Aug 2023 06:42:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF9rrbtsBbmucI15nETMiveP0LMUFBJlytcpCVfYrBBFpCezeyAsVxlNYrL0dtOXaTXmlzz X-Received: by 2002:a17:902:ee4d:b0:1b8:ae24:c207 with SMTP id 13-20020a170902ee4d00b001b8ae24c207mr2518553plo.68.1692538953535; Sun, 20 Aug 2023 06:42:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692538953; cv=none; d=google.com; s=arc-20160816; b=L2J6uNTs8DMcUmOghv0HaIHVL1QBRYLuyB/EmDL9zhm5Lvo2/K4JAab8X+S//2Xg9s uNVxDzI4bvPtQHd3vJI6OXt36Kqbq9X5wEgdWCTVgyl6xwfxSM0Hc+o8mPxNQEwys32w l23YZCGEs0zG6AEUqD8g+xW5slS1iImDq0ARtEghYNm5nOVKSYDZib7uX2fRbKXxFtxM UIgZf7SjxZEUSMlCSKtDFChkYEEr0c7E1Mohu5eMHDp0eKooLNeKG4N056cThgD3jGLg cgRxHhcC2Bu+ZxrAsO2Y0NOw59EZX4bfIpN3rmfhJZqoe6MxKyYfM1ZruL2DbYPsTKg/ m5Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=brA8GoAvDNp8q8xbP+QJWVaL+zpV7fP9YmTxAqc9jSQ=; fh=UHMNjJiuxKuA03v9I9ZORlBFAtuL/SiP8nCBgfAAnpQ=; b=QIDkEcercBlCFO7oIjYY6IGiI2VbPwlmhnvqnP9QCCQLUKDrvEj/CzYBHIHW1106ae +N2gZdGETVhCmPBQSii8K0tBkVga+1+56GIKKmc9M4elgC/iAwsCIZtWu4fojVKhxtRM /CCP9AOSd9a5DU7x7wzPit4Wrb+7tDfbH4S1sV6mCMNBGUsCm3wZiWs53qZveGb/5vTC CaulIBsp72oIwjfuEscJI1pS1qMh5ILsUT+iEXnyMNn9rR5oEOir5t5y4if5WFj54vCc HYbbYIUNVczKRGcksisjiGM9XaOMJnvwOg9/2HFHVpUhz/D/WiOV3nOz2EB5XvFXrY8y 4w4A== 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:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id z15-20020a170903018f00b001b8ae34f1b7si5493478plg.631.2023.08.20.06.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 06:42:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7AB0F31F233; Sat, 19 Aug 2023 11:59:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244280AbjHQMFO (ORCPT + 99 others); Thu, 17 Aug 2023 08:05:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350720AbjHQMFE (ORCPT ); Thu, 17 Aug 2023 08:05:04 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C4663599; Thu, 17 Aug 2023 05:04:39 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qWbjj-0001mN-0l; Thu, 17 Aug 2023 12:04:23 +0000 Date: Thu, 17 Aug 2023 13:04:06 +0100 From: Daniel Golle To: Alexander Couzens , Daniel Golle , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH net-next] net: pcs: lynxi: fully reconfigure if link is down Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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: INBOX X-GMAIL-THRID: 1774556973122763560 X-GMAIL-MSGID: 1774755725812357911 On MT7988 When switching from 10GBase-R/5GBase-R/USXGMII to one of the interface modes provided by mtk-pcs-lynxi we need to make sure to always perform a full configuration of the PHYA. As the idea behind not doing that was mostly to prevent an existing link going down without any need for it to do so. Hence we can just always perform a full confinguration in case the link is down. Signed-off-by: Daniel Golle --- drivers/net/pcs/pcs-mtk-lynxi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/net/pcs/pcs-mtk-lynxi.c b/drivers/net/pcs/pcs-mtk-lynxi.c index b0f3ede945d96..788c2ccde064e 100644 --- a/drivers/net/pcs/pcs-mtk-lynxi.c +++ b/drivers/net/pcs/pcs-mtk-lynxi.c @@ -108,8 +108,8 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode, bool permit_pause_to_mac) { struct mtk_pcs_lynxi *mpcs = pcs_to_mtk_pcs_lynxi(pcs); - bool mode_changed = false, changed; - unsigned int rgc3, sgm_mode, bmcr; + bool mode_changed = false, changed, link; + unsigned int bm, rgc3, sgm_mode, bmcr; int advertise, link_timer; advertise = phylink_mii_c22_pcs_encode_advertisement(interface, @@ -117,6 +117,10 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode, if (advertise < 0) return advertise; + /* Check if link is currently up */ + regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &bm); + link = !!(FIELD_GET(SGMII_BMSR, bm) & BMSR_LSTATUS); + /* Clearing IF_MODE_BIT0 switches the PCS to BASE-X mode, and * we assume that fixes it's speed at bitrate = line rate (in * other words, 1000Mbps or 2500Mbps). @@ -137,7 +141,10 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode, bmcr = 0; } - if (mpcs->interface != interface) { + /* Do a full reconfiguration only if the link is down or the interface + * mode has changed + */ + if (mpcs->interface != interface || !link) { link_timer = phylink_get_link_timer_ns(interface); if (link_timer < 0) return link_timer;