Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3398821rwr; Sat, 22 Apr 2023 04:50:27 -0700 (PDT) X-Google-Smtp-Source: AKy350ZkK9k5vbFo8FBVT32sXc6CawqEKEqRnEiAl/F37v5TrxsMTlrf9g+yqehda2GW+s6LaXoa X-Received: by 2002:a17:90a:1994:b0:244:b4ea:add4 with SMTP id 20-20020a17090a199400b00244b4eaadd4mr7408762pji.3.1682164227441; Sat, 22 Apr 2023 04:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682164227; cv=none; d=google.com; s=arc-20160816; b=oZ7sDQpZqQyYO2VjOW0VGET2wwvaziaOrUFj+u4KN7lpnAmKWemyvJFzXOpD66d36b utYPU0uDqvekpusVXlYFhbSer6oFR6+fsBMei2RLFm2UG16+oidUd9sg0kxj8ywaZN8c r+f9cpS4N3fAxaHfjaVOUKLGZJtfcA8CSxXvRWVrS+J2/onX/l6P+Mcd7+4uvYzESeFh CdY7B34yjHlHfncernSYbaxcFMFovVZ9ZFpC+7ONie79PFomiBoJlIhvEqD7Nejgs4xM H7P5z8mrS/xE2DmDjvTa/yutAHWHmBk/xcm1ltvm4cXWRHc5N2Lj/SoqG4KyXwIJHgjq I8Zw== 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=toVWAnUspOiELnQmIPnDYQLeinRjm7rXO1BJoKccurY=; b=bu0MTY/Ceted/01snVFCsP/CFBZJCsLdBW7/J0+Q0HUZsJKhxC8QsBh3B5XFmvpMKr kJzI5UEr/DGRIR80Xk/rNN7P1ZgVrMCSeGgSPaBSEd7GuAKqjeFz4At2puif6xMCMvFr GWqci2Y41aEeRLwhit05YlG18Lq/P7aDKcvKZ43D9JNdUq9XAshEbc1ayAOZaEZd1guf b7qEpPuOnOBPWkeZb8cUc5zvKq0rvzp1bp9//+MHGPhwBjn9Xl5V398epa4p/Z49bM0L TTdzDaWaEmTL7wbIVXRdiigclHwqI7Fw19QD+p6nVE1P+2YoflxxXxUxa+khXMCsbos+ QDbg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z31-20020a630a5f000000b0051372ef848fsi6706591pgk.697.2023.04.22.04.50.11; Sat, 22 Apr 2023 04:50:27 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbjDVLss (ORCPT + 99 others); Sat, 22 Apr 2023 07:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229747AbjDVLsi (ORCPT ); Sat, 22 Apr 2023 07:48:38 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B92B71FEC; Sat, 22 Apr 2023 04:48:33 -0700 (PDT) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pqBjE-00084X-0q; Sat, 22 Apr 2023 13:48:32 +0200 Date: Sat, 22 Apr 2023 12:48:28 +0100 From: Daniel Golle To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Chen Minqiang , Chukun Pan , Yevhen Kolomeiko , Alexander Couzens Subject: [RFC PATCH net-next 2/8] net: phy: realtek: switch interface mode for RTL822x series Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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: X-Mailing-List: linux-kernel@vger.kernel.org From: Chukun Pan 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 6389abaab6d5a..34fd86b8ecf7d 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