Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7988070rwr; Wed, 10 May 2023 16:05:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7UtnuMXeaGeK/IWpW1gF2YFK71Y39ECefsNwocNzQpLGSTYKi6d1B0DdXwbgEjJWvGVNFE X-Received: by 2002:a05:6a00:1a86:b0:63b:7ac8:1be4 with SMTP id e6-20020a056a001a8600b0063b7ac81be4mr24001029pfv.25.1683759938336; Wed, 10 May 2023 16:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683759938; cv=none; d=google.com; s=arc-20160816; b=opetBrclWDZISMH7JR4v2z5dLVbU4wd/bEgr8vjrCu50kH/meDBpLshUHSpgFn+Bkw 57lviRlLaOlUeUnvOT0mjkD1EiyNq97hLxydiHQ93cr7zRg2tCaWGtPAkcrT+Haoyn9R NoGOaQ/twDYgoNkDiNuxQ+1yR1RX+EkACCtagGOHCJkPjlYiqkQsveSprWktyiYsAYKg 5Gsh4qo8Yoe5K8YyZZRVEKjvkRUjLi2RkaegpSBLZeALsTDE9/PzcQGg7ya3erVXW/XR IC2eaVGuThjHed6NsiKDFQNdY5IpIxKaCjr+XIuJbLCBgbSiq7pzlQYFVeSiGMnsOknk IFxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:to:from:date; bh=hCWlB98ZjrrVV4FLrz+myH0C2AtSbTflHoFyq21uLP8=; b=vQadaEOTjG7WZuru3hlaY7c/lx+YP7HEXq97jxV8UIEOuKIrFAf0n8n50cImCO+MeJ 4ZUCt1+RXyrvs1VmyIiLUxGf0WWH0HSuDn4CyHmaMkqu2ijxYZ+Pw08oHvqNDxac309g qQtkGATjDYeQ9wBw5bs4lUmSFxH9hkNZzrg8+Austhdioi0cvljDoqxhsVPiH5bdqQDs JR8llghuMZW10JFTvKON5+hy3nnrpeET19WZ+N1Z1Cr9Q1dB34jKAdS7p5cyFR+OPmW6 KDODcuibUSDsokCQFYZ4xypBLGLP+tckMr21Tmyoy2PS7QCjpcE/VkCI8dayj/BgwclK iHjQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=jmu.edu.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m29-20020a638c1d000000b0052868a865d1si5025741pgd.272.2023.05.10.16.05.26; Wed, 10 May 2023 16:05:38 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=jmu.edu.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236568AbjEJW4x (ORCPT + 99 others); Wed, 10 May 2023 18:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236654AbjEJW4n (ORCPT ); Wed, 10 May 2023 18:56:43 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F57E5FE7; Wed, 10 May 2023 15:56:34 -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 1pwsjY-0004QI-1d; Wed, 10 May 2023 22:56:32 +0000 Date: Thu, 11 May 2023 00:54:36 +0200 From: Chukun Pan To: netdev@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , AngeloGioacchino Del Regno Subject: [PATCH net-next 2/8] net: phy: realtek: switch interface mode for RTL822x series Message-ID: <537a12131132614ce9600ca9370dab823a262347.1683756691.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: daniel@makrotopia.org X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no 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 The RTL822x phy can work in Cisco SGMII and 2500BASE-X modes respectively. Add interface automatic switching MAC-side interface mode for RTL822x phy to match various wire speeds when using Clause-45 MDIO. Signed-off-by: Chukun Pan Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index a7dd5a075135..4a2c1ad02d48 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -684,6 +684,25 @@ static int rtl822x_config_aneg(struct phy_device *phydev) return __genphy_config_aneg(phydev, ret); } +static void rtl822x_update_interface(struct phy_device *phydev) +{ + /* Automatically switch SERDES interface between + * SGMII and 2500-BaseX according to speed. + */ + switch (phydev->speed) { + case SPEED_2500: + phydev->interface = PHY_INTERFACE_MODE_2500BASEX; + break; + case SPEED_1000: + case SPEED_100: + case SPEED_10: + phydev->interface = PHY_INTERFACE_MODE_SGMII; + break; + default: + break; + } +} + static int rtl822x_read_status(struct phy_device *phydev) { int ret; @@ -702,11 +721,14 @@ static int rtl822x_read_status(struct phy_device *phydev) phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL); } - ret = genphy_read_status(phydev); + ret = rtlgen_read_status(phydev); if (ret < 0) return ret; - return rtlgen_get_speed(phydev); + if (phydev->is_c45 && phydev->link) + rtl822x_update_interface(phydev); + + return 0; } static bool rtlgen_supports_2_5gbps(struct phy_device *phydev) -- 2.40.0