From patchwork Wed May 10 22:57:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 92322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3974704vqo; Wed, 10 May 2023 16:02:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PbKt/x/hPuLgUnCWMgRl+0Es62f+pNjnViiQws6SmgQR5s249+sb2YcDYoQJ+jQo9RFDJ X-Received: by 2002:a05:6a20:32aa:b0:101:7bab:2e67 with SMTP id g42-20020a056a2032aa00b001017bab2e67mr5644477pzd.6.1683759763495; Wed, 10 May 2023 16:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683759763; cv=none; d=google.com; s=arc-20160816; b=GrxRHTH8VJjtCBeUjEfAZx9NJPrJAJof0qga5sRv0NDWJdtl8ToPzN4RhKRxzUZQ9I 205rUDbc4LnIPiLJ5WKD3J4zAqFbg1wfy/ozu7JkktpJ/Box8Y5rkhT0id+veYW9AZbe HpSqnqvXXCMWyrFSRF8CqnPKc7CBwRfGwFy3g9QveX4wcACl+W1l3tpS0yyilPPAjs7D 12tocQItGIciVJSUfPZ31imTC+LX0YNL64SJITDOFbC7+FjeCFuWivULiOKPess/C+mj 7x3Z3NU/7GKtPyHqA5cBlmeQ95kOVEzNGOki1gr2VRg6Yh7Un1jqep5iKcIcWlX6bmmC lzxA== 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:to:from:date; bh=GtIRfzBWNCVjDKwV8mbFdZt74qrvU55EqTM6YceujnU=; b=perIvXECRarnoklj1zDlzT9cNL/z5cGGOVxnLuRDgjOrMcqynXgj/i91QoBBRajRFi sLcVIMDcxdSBnhgtaDGoYD6iQj3q3UpJXkSh4YV8nsiJOWhrHdRw8ZmAQONvX5yp2iYm fMDg63cS7/hTgulr28dg0hg0s3wu3ayFksUQUpGw1c/7xlOdf/uBYGbJ8v1XaGzDSBdz h7CiFhbu9z0DXP//4Xc82ImEevA2UGD4C9cSE/0ucdFyrjrGzHFiMb9VKt44pLyzsPqC NCeJS4qdf5aT7AuY5X19oCOBW6+9SL6iQc5Jqx/qJCicHF0O7Uz2kfPkgrVFZYUAt9r1 E3Aw== 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 v202-20020a6361d3000000b0050bede17e7bsi5074022pgb.347.2023.05.10.16.02.31; Wed, 10 May 2023 16:02:43 -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 S236486AbjEJW7J (ORCPT + 99 others); Wed, 10 May 2023 18:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230316AbjEJW7I (ORCPT ); Wed, 10 May 2023 18:59:08 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 336F1E64; Wed, 10 May 2023 15:59:07 -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 1pwsm1-0004Sm-1k; Wed, 10 May 2023 22:59:05 +0000 Date: Thu, 11 May 2023 00:57:12 +0200 From: Daniel Golle 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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765550077958340957?= X-GMAIL-MSGID: =?utf-8?q?1765550077958340957?= 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 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)