From patchwork Sat Apr 22 11:48:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1651503vqo; Sat, 22 Apr 2023 04:50:00 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/Iw2Nfaou+KIAHRH6m1iF9lYCOnkFz7LPlgOl3ilSLeX+w+T1uI2vfbUwr8t4S7mqQfiR X-Received: by 2002:a05:6a20:a49e:b0:f0:2893:8a34 with SMTP id y30-20020a056a20a49e00b000f028938a34mr7523139pzk.52.1682164200364; Sat, 22 Apr 2023 04:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682164200; cv=none; d=google.com; s=arc-20160816; b=xkd5fNq1cJyzGUU//YV4vx3dmAGamdkx+XXKC2S1kmlUiwm+k1NXLXa+cjDBFuiQgL Jrx1v9vkfvAxQ/fvhtyoIYOZUYgsi/wUDFbOZnfEUoCxe9BkyfM8383vfIu44Y87Y55N 36SDClLeQzqbDNhfEVGrzjZ47PVF5UwDr8VPlDf89XgX9wtctMAGzRQgV4rsO4f6z5AN zL8Oo3cLl5uXt+w7kiZZvmTOaIfFVbNlpAhYuwFgUnaNFo63/OhyaugSBNlB+9ueuobb AgWiVmVpsdhCdIXSw4dTf8zeiRVnQNnCDxp0Oy455QIUFJhpZcO4h6zF9soo4d+91oKC LVLw== 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=FWKXgP1ji1y6XvBTHwPcwVCq1o7eGDDCM7BRAY7FiBo=; b=LHWwTzCq/ltugNN54FV8QUYGwQxI1cBDxIaIW9MC1KoIAkRR+g/uE+vkMhdlDbMr8G iIWnCPH4fHoY8ClR8mOcxTtUkms2F1VXqm5DbZX6Dr3ITuj5zteJXQbJO7cj1B3x5UpD k9HGFsyfJKmrvp4rRKY+NlpZ/ocG8xnVo+6Jj8VaV/Lf3Z358q2vXk6VwXGzSaJoSa5s bzYcPnneXNjQmJXOMKyaAFWyLgpWBry8Pp9cC3OvE03f81znVdhyLS67HNt/QglCFRur GZzi2aULD5JXkGtiDrxFSnZuzWeV2zAxSrRKvRZ8mYEfE/d/GbFNg7eUr1/LD1EhGHVj 9WqA== 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 w4-20020a656944000000b0050bcb8e3a8csi6280890pgq.828.2023.04.22.04.49.47; Sat, 22 Apr 2023 04:50:00 -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 S229709AbjDVLs2 (ORCPT + 99 others); Sat, 22 Apr 2023 07:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjDVLsY (ORCPT ); Sat, 22 Apr 2023 07:48:24 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B9111FDE; Sat, 22 Apr 2023 04:48:23 -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 1pqBj3-00084E-29; Sat, 22 Apr 2023 13:48:21 +0200 Date: Sat, 22 Apr 2023 12:48:17 +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 1/8] net: phy: realtek: rtl8221: allow to configure SERDES mode Message-ID: <30e4fb909f5fac1734562c9822e5d72b5c0497cf.1682163424.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?1763877008478466333?= X-GMAIL-MSGID: =?utf-8?q?1763877008478466333?= From: Alexander Couzens The rtl8221 supports multiple SERDES modes: - SGMII - 2500base-x - HiSGMII Further it supports rate adaption on SERDES links to allow slow ethernet speeds (10/100/1000mbit) to work on 2500base-x/HiSGMII links without reducing the SERDES speed. When operating without rate adapters the SERDES link will follow the ethernet speed. Signed-off-by: Alexander Couzens --- drivers/net/phy/realtek.c | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 3d99fd6664d7a..6389abaab6d5a 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -53,6 +53,15 @@ RTL8201F_ISR_LINK) #define RTL8201F_IER 0x13 +#define RTL8221B_MMD_SERDES_CTRL MDIO_MMD_VEND1 +#define RTL8221B_MMD_PHY_CTRL MDIO_MMD_VEND2 +#define RTL8221B_SERDES_OPTION 0x697a +#define RTL8221B_SERDES_OPTION_MODE_MASK GENMASK(5, 0) +#define RTL8221B_SERDES_OPTION_MODE_2500BASEX_SGMII 0 +#define RTL8221B_SERDES_OPTION_MODE_HISGMII_SGMII 1 +#define RTL8221B_SERDES_OPTION_MODE_2500BASEX 2 +#define RTL8221B_SERDES_OPTION_MODE_HISGMII 3 + #define RTL8366RB_POWER_SAVE 0x15 #define RTL8366RB_POWER_SAVE_ON BIT(12) @@ -849,6 +858,48 @@ static irqreturn_t rtl9000a_handle_interrupt(struct phy_device *phydev) return IRQ_HANDLED; } +static int rtl8221b_config_init(struct phy_device *phydev) +{ + u16 option_mode; + + switch (phydev->interface) { + case PHY_INTERFACE_MODE_2500BASEX: + if (!phydev->is_c45) { + option_mode = RTL8221B_SERDES_OPTION_MODE_2500BASEX; + break; + } + fallthrough; + case PHY_INTERFACE_MODE_SGMII: + option_mode = RTL8221B_SERDES_OPTION_MODE_2500BASEX_SGMII; + break; + default: + return 0; + } + + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, + 0x75f3, 0); + + phy_modify_mmd_changed(phydev, RTL8221B_MMD_SERDES_CTRL, + RTL8221B_SERDES_OPTION, + RTL8221B_SERDES_OPTION_MODE_MASK, option_mode); + switch (option_mode) { + case RTL8221B_SERDES_OPTION_MODE_2500BASEX_SGMII: + case RTL8221B_SERDES_OPTION_MODE_2500BASEX: + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x6a04, 0x0503); + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x6f10, 0xd455); + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x6f11, 0x8020); + break; + case RTL8221B_SERDES_OPTION_MODE_HISGMII_SGMII: + case RTL8221B_SERDES_OPTION_MODE_HISGMII: + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x6a04, 0x0503); + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x6f10, 0xd433); + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x6f11, 0x8020); + break; + } + + return 0; +} + static struct phy_driver realtek_drvs[] = { { PHY_ID_MATCH_EXACT(0x00008201), @@ -1001,6 +1052,7 @@ static struct phy_driver realtek_drvs[] = { PHY_ID_MATCH_EXACT(0x001cc849), .name = "RTL8221B-VB-CG 2.5Gbps PHY", .get_features = rtl822x_get_features, + .config_init = rtl8221b_config_init, .config_aneg = rtl822x_config_aneg, .read_status = rtl822x_read_status, .suspend = genphy_suspend, @@ -1012,6 +1064,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8221B-VM-CG 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, + .config_init = rtl8221b_config_init, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, From patchwork Sat Apr 22 11:48:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1659700vqo; Sat, 22 Apr 2023 05:07:04 -0700 (PDT) X-Google-Smtp-Source: AKy350blhP+KU9/mNfI3wjxOF6exYzHP2/u3KK8zfgcD/29/k3cwKzDIneFL2aTPwDnSfEst8AG/ X-Received: by 2002:a05:6a21:339c:b0:d9:b024:4824 with SMTP id yy28-20020a056a21339c00b000d9b0244824mr10483997pzb.26.1682165223690; Sat, 22 Apr 2023 05:07:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682165223; cv=none; d=google.com; s=arc-20160816; b=OGwUqVzKJuahb3ej/TjHpPqeTBheA2bRupGbMpJ9dF6XGTXbqdlIDIwexJKqQdcvTk gv4R0wTf2Z4Vtp3IoXRes3FM9esF4zMzYaccKn9OLGBv93bR52aJ0XS9JZsvN7PmHFTy 4ztnoanchs/88bs9JudUAk5E/qTQ6vMqxL0R7LrjlIJEkofKGydNjjVy6JMCfr4ZuqIb B8H9Y5usAx9iAhN07u+QQql5SJwRT42Ah7WC+CFWKZQvjz9IZNnDgu/uqXxmp6wxIiMZ U/SUdiUSWoU7f8o0TjVFctJ5H7OMb9mHJJnHdIOnFYv4UdWRvmsJ5f9TmLlAph04+6z+ EFZA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j192-20020a638bc9000000b00513965a1e60si6412739pge.902.2023.04.22.05.06.49; Sat, 22 Apr 2023 05:07:03 -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 S229674AbjDVLst (ORCPT + 99 others); Sat, 22 Apr 2023 07:48:49 -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-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?1763878081752987326?= X-GMAIL-MSGID: =?utf-8?q?1763878081752987326?= 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) From patchwork Sat Apr 22 11:48:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1651560vqo; Sat, 22 Apr 2023 04:50:11 -0700 (PDT) X-Google-Smtp-Source: AKy350Z5ZqyJY+ETKPUzKv9QGdY0dV8K/ZwbIwuo0wpuHwee4swBFWAAjE24j64nbE/MFZBYBfCv X-Received: by 2002:a05:6a20:9190:b0:f2:dc4d:935d with SMTP id v16-20020a056a20919000b000f2dc4d935dmr4100782pzd.18.1682164210882; Sat, 22 Apr 2023 04:50:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682164210; cv=none; d=google.com; s=arc-20160816; b=u9txbVao23o3CuqttdV8fGHUTdbQXr6hVZWNFubJ9ryyNL24bFbnyTiUmZmHgb7C6D bU/bS8d0GTcY+NJrz9LXB+nFk3GFCaZsNNCMUzWCAYGM9NzlihJz+t9quF+txP19Ug+k wFEUVuY6czYkgTK4kZxgICPfBIx3y77XeA9pDX1lwBnxZopL+d5bm9blye2hXP5ZAFt8 Bz36x0AGG5/UGTzEb76MiQgnKHrpgsdF+FAFRXyjJ940YzlHBmmk+GT1DvqBoK92y6vM 7sYYNwKrkBo2QJ+Ojs28PHi/pmyqOjZbrwMnv6eaCY0E9bJIUOEHj6/g0VchQo3fRctX 5+Bg== 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=Ou2g3Kg8R5umMD/mLJWOWuDUgEzMBCCyBFU9A5jXPsY=; b=wPSJTvLzI4I9LczL/3dtPiAE/JmEOCH3NRoDuLsWNxTR9outs+OzxB5TMHsAjB95ru 3WiJ2zbRzmmJovUt/MXZ+ErCcXqXmeOw8xZOW/YF0HgkTBXM2L3gtKOLvaoa13Vpa7Xz Vmc9LMK1I4t5fah+Yb4LFHDZptc9MW3i6K/flWRY8cWkqqF5+suVxUsVfb4stNzENqqT wrPVfzsS4JM+TpdYOyq6qlLoaK2VBSw3FteJOoLNEkdpPmqZAMyU+J0ve77zzXywUsgW 7A/ISAkdnbpFmBphRmshDQkZNS9bXmdZnhx7OLaWFJ5Z2jD4XUC5enD7+5Ij7b65YRET 69yw== 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 t69-20020a638148000000b00524d36c5335si4645031pgd.177.2023.04.22.04.49.58; Sat, 22 Apr 2023 04:50:10 -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 S229596AbjDVLtG (ORCPT + 99 others); Sat, 22 Apr 2023 07:49:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbjDVLtE (ORCPT ); Sat, 22 Apr 2023 07:49:04 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 004322116; Sat, 22 Apr 2023 04:48:43 -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 1pqBjO-000853-1B; Sat, 22 Apr 2023 13:48:42 +0200 Date: Sat, 22 Apr 2023 12:48:38 +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 3/8] net: phy: realtek: use genphy_soft_reset for 2.5G PHYs Message-ID: <3ddae95741d87b94c9d135f3c0acfa1617f91836.1682163424.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?1763877019538184269?= X-GMAIL-MSGID: =?utf-8?q?1763877019538184269?= Some vendor bootloaders do weird things with those PHYs which result in link modes being reported wrongly. Start from a clean sheet by resetting the PHY. Reported-by: Yevhen Kolomeiko Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 34fd86b8ecf7d..9b477dd17fa56 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -1038,6 +1038,7 @@ static struct phy_driver realtek_drvs[] = { .write_page = rtl821x_write_page, .read_mmd = rtl822x_read_mmd, .write_mmd = rtl822x_write_mmd, + .soft_reset = genphy_soft_reset, }, { PHY_ID_MATCH_EXACT(0x001cc840), .name = "RTL8226B_RTL8221B 2.5Gbps PHY", @@ -1050,6 +1051,7 @@ static struct phy_driver realtek_drvs[] = { .write_page = rtl821x_write_page, .read_mmd = rtl822x_read_mmd, .write_mmd = rtl822x_write_mmd, + .soft_reset = genphy_soft_reset, }, { PHY_ID_MATCH_EXACT(0x001cc838), .name = "RTL8226-CG 2.5Gbps PHY", @@ -1060,6 +1062,7 @@ static struct phy_driver realtek_drvs[] = { .resume = rtlgen_resume, .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, + .soft_reset = genphy_soft_reset, }, { PHY_ID_MATCH_EXACT(0x001cc848), .name = "RTL8226B-CG_RTL8221B-CG 2.5Gbps PHY", @@ -1070,6 +1073,7 @@ static struct phy_driver realtek_drvs[] = { .resume = rtlgen_resume, .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, + .soft_reset = genphy_soft_reset, }, { PHY_ID_MATCH_EXACT(0x001cc849), .name = "RTL8221B-VB-CG 2.5Gbps PHY", @@ -1081,6 +1085,7 @@ static struct phy_driver realtek_drvs[] = { .resume = rtlgen_resume, .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, + .soft_reset = genphy_soft_reset, }, { PHY_ID_MATCH_EXACT(0x001cc84a), .name = "RTL8221B-VM-CG 2.5Gbps PHY", @@ -1092,6 +1097,7 @@ static struct phy_driver realtek_drvs[] = { .resume = rtlgen_resume, .read_page = rtl821x_read_page, .write_page = rtl821x_write_page, + .soft_reset = genphy_soft_reset, }, { PHY_ID_MATCH_EXACT(0x001cc961), .name = "RTL8366RB Gigabit Ethernet", From patchwork Sat Apr 22 11:48:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1653273vqo; Sat, 22 Apr 2023 04:55:25 -0700 (PDT) X-Google-Smtp-Source: AKy350YUelq9Z2KghyaGJYLeQvtvvDs5GHvilz5ls2egA6yxttJ2ZpvsJye1Z1LR161HYeMGmkKP X-Received: by 2002:a17:903:284:b0:1a6:be37:22c3 with SMTP id j4-20020a170903028400b001a6be3722c3mr7319262plr.67.1682164524660; Sat, 22 Apr 2023 04:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682164524; cv=none; d=google.com; s=arc-20160816; b=Ec2kv0QxUxgsXLWKTTDvWNfrhpjhDkD/yE+7U91ZivoqmHu2/fefwh7PL8MooZori5 RD55zNCMgV6/q2hA0hd53ls/ggQBSl12Q9/bsQg7vYt6mpGcE6iezozRtiyz0XTMOYgq HM+UqZsekuLKCcG1VE6UxhMY6doXhE9DpBWETgHMxUHnKrcgLZvw85i3G63dqWa8ankW rBNadaNBx7g/QqAi+aFXaK/I6rTSI9NtoZLM4Q1YpocE1gMgEUDHAe8j2hA7St+iatrn yFvOgtAMQ38DqsqgjXdfFMurYND5bCHMe7oElVQFDYLwb8ZsIeA4Q1V8Xy/6TFD/Zzz6 jikA== 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=U0OP4cxmvRIRQloik5rVQaaqL3GdttPr84OkqgTdvVQ=; b=IsQYWjpMr6whbyCBDmH5Hv9mJil12rI9aOcENTbxFd1vAa92PBIGIjWdf0KyIBgJLI QCqZL7Cpj/yqFzBdXnx9D1KSlkBeU9n5SsjHKCiSafWgJ8qPLD+27YuEF8wbt9HDyiDX iPrCokRP5Tr008VAm1iPCNbFFmDZo+PubqHpnGUqi8eYjzxxCA47Hu0McT22ePtnz2HN lT26IxBaEzbNxZ/wtR9wIPZr//KnBzz8beQd6hbT18mdz+/OzOv8MvJ1S50oq6EEhOI+ SXay9wUE8d3S23IrqlgXs66h0C2L68tI4/CSRQ9Ru84wgVYh34lCQXmzzFCdU1JpQPIx 5rww== 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 o17-20020a170902d4d100b0019a96849d6dsi7273391plg.605.2023.04.22.04.55.11; Sat, 22 Apr 2023 04:55:24 -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 S229824AbjDVLtT (ORCPT + 99 others); Sat, 22 Apr 2023 07:49:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbjDVLtJ (ORCPT ); Sat, 22 Apr 2023 07:49:09 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4912826AF; Sat, 22 Apr 2023 04:48:54 -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 1pqBjY-00085G-2M; Sat, 22 Apr 2023 13:48:52 +0200 Date: Sat, 22 Apr 2023 12:48:48 +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 4/8] net: phy: realtek: disable SGMII in-band AN for 2.5G PHYs Message-ID: <87f666009413e8c6edac1ba30533b8f97a4fee76.1682163424.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?1763877348997190903?= X-GMAIL-MSGID: =?utf-8?q?1763877348997190903?= MAC drivers don't use SGMII in-band autonegotiation unless told to do so in device tree using 'managed = "in-band-status"'. When using MDIO to access a PHY, in-band-status is unneeded as we have link-status via MDIO. Switch off SGMII in-band autonegotiation using magic values. Reported-by: Chen Minqiang Reported-by: Chukun Pan Reported-by: Yevhen Kolomeiko Tested-by: Yevhen Kolomeiko Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 9b477dd17fa56..f97b5e49fae58 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -883,6 +883,7 @@ static irqreturn_t rtl9000a_handle_interrupt(struct phy_device *phydev) static int rtl8221b_config_init(struct phy_device *phydev) { u16 option_mode; + int val; switch (phydev->interface) { case PHY_INTERFACE_MODE_2500BASEX: @@ -919,6 +920,13 @@ static int rtl8221b_config_init(struct phy_device *phydev) break; } + /* Disable SGMII AN */ + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x7588, 0x2); + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x7589, 0x71d0); + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, 0x7587, 0x3); + phy_read_mmd_poll_timeout(phydev, RTL8221B_MMD_SERDES_CTRL, 0x7587, + val, !(val & BIT(0)), 500, 100000, false); + return 0; } From patchwork Sat Apr 22 11:48:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1657595vqo; Sat, 22 Apr 2023 05:03:58 -0700 (PDT) X-Google-Smtp-Source: AKy350ZomboBW2AN8ECwDjwO/ecsGQppK8VU6wwRFYRZqxFYgRqdtctrYAJaoJSFzU04ufWOCBxo X-Received: by 2002:a05:6a00:1818:b0:634:10a8:538c with SMTP id y24-20020a056a00181800b0063410a8538cmr11452603pfa.12.1682165037705; Sat, 22 Apr 2023 05:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682165037; cv=none; d=google.com; s=arc-20160816; b=jBy5MNU1Br/XRXYQHf/vzf+HvSQxZKgFEwvvu16lTnBrqGn/nz3ZJ36ysGZV2Hp3Ks L3UzS+K0mF5SaZCVvaFgkxYFQyRQLZm4FTPlOrqUT4Zzli9L+fONcBDTD7F0ixSqA1Dw beJbZDb5ivFZuX8IkiRUYs5XglEuLsmZVievnKnLfVYaceTPUxL12SmssZowtCuK70IT pqolRdVUHeM1Ndj7otcoP3XVXyFbc8uf6b0/z9i0BUDtkgNRdggykhtmW/rUkbVudK52 rn5XSRdBJBT6vtGLiPqNt/Dyb4jmQ/Ytc66MYk6s22JU/3E0VsbBpJJQosnx3/oweWJN vZtQ== 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=Y9hKCZiGJTzdHH6bTMqKZ4wDLV8ZHMWepftXwHd2ktg=; b=OKqZfBfay+dYhLWj0vkPwP64X7CSFSvX0fYZ/leNus299626EJYRYXsroYJsD82vBM zuBoqbXV0Oq7JaXv/hMubOeCxKMzeqMFmUiz7Ax36sFmxQxYGd5xIWnnLzYipNhk7RKN hGenkm46lDEK/tSRVGacy9uu0f9TR9Ml3k5neMyZxeYLnU6kbNLX1z4CkUjF5vJ6HWnQ yKSPq8Kla47hLYY0xJScfUzwOSGagXfa0lQIhALiZd8gs1djb+fn0wPejrsP9v++iqvh UDhzyyZ4Go3CKjetMeBhdgZ5fvWdtjPjzNBXX+/nn6FISan9k1HRY0aOzYK0FgKS2slD sA3A== 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 g16-20020a63dd50000000b004dccf388f93si6193918pgj.522.2023.04.22.05.03.41; Sat, 22 Apr 2023 05:03:57 -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 S229812AbjDVLta (ORCPT + 99 others); Sat, 22 Apr 2023 07:49:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbjDVLtX (ORCPT ); Sat, 22 Apr 2023 07:49:23 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D3461FC8; Sat, 22 Apr 2023 04:49:05 -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 1pqBjj-00085Z-1c; Sat, 22 Apr 2023 13:49:03 +0200 Date: Sat, 22 Apr 2023 12:48:59 +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 5/8] net: phy: realtek: use phy_read_paged instead of open coding Message-ID: <85eb0791bd614ccfdeccdc6fe39be55e602c521c.1682163424.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?1763877886526270368?= X-GMAIL-MSGID: =?utf-8?q?1763877886526270368?= Instead of open coding a paged read, use the phy_read_paged function in rtlgen_supports_2_5gbps. Signed-off-by: Daniel Golle Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index f97b5e49fae58..62fb965b6d338 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -735,9 +735,7 @@ static bool rtlgen_supports_2_5gbps(struct phy_device *phydev) { int val; - phy_write(phydev, RTL821x_PAGE_SELECT, 0xa61); - val = phy_read(phydev, 0x13); - phy_write(phydev, RTL821x_PAGE_SELECT, 0); + val = phy_read_paged(phydev, 0xa61, 0x13); return val >= 0 && val & RTL_SUPPORTS_2500FULL; } From patchwork Sat Apr 22 11:49:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1653711vqo; Sat, 22 Apr 2023 04:56:43 -0700 (PDT) X-Google-Smtp-Source: AKy350asJCcu8xmghejTgBTXcsXTNDJ++7GFEfSeVPvldBESDN5V1jxTB4tXUSX0so/O2sJx3qIH X-Received: by 2002:a17:902:f547:b0:1a0:6bd4:ea9a with SMTP id h7-20020a170902f54700b001a06bd4ea9amr14703049plf.16.1682164603233; Sat, 22 Apr 2023 04:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682164603; cv=none; d=google.com; s=arc-20160816; b=HDhZJiHnTuEV0JzNgqmmxHrrYZ8TIQQN0tKkIq0G1nrBD19OwLVcFz5M/adsMiPhz3 DXHhInT9swbZ2Q5hA24VdAAKpM6Nm2Ajh1y/rc/pbXg/olsWmiHCPUfKmArLJ4634ORj f3oMSAfwH3QcH+26l2cBWtghAQssgeKtqReamytyznJ3QvK+HRTcRq9R/GPdDkrr5g0I FUc2b1CIZJDyk74CRyXLVPbuj847aKgOlNDQibvPZSLHbO+iyFxaL00FHxXciYNbac67 xMlbs1jIlOIxKaD50i+7dEIlDkgGb6lB4mWJihwC5DyS3+2Wj2m72K+N3dbF5Euj+DEG 7IFQ== 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=Isek/A4OtvX/p24ma3ttb5X8vJuMUeJmqbeUPAATjd4=; b=ynaZMit2+54xkRXvKKQoZ/76GWuHAG1sgkSDxatdcaHJZoif4qzvgJwP1JJjq+8ygn s/rjkt4+XhR0KiR2TqC6AP5ssCiBuUPguPiSPMjSOZbzR/CUNTvCMaQXg/OT8BfR1/Uh nffOBhqc3SaYRtcT99c2rcGRM7SKekWifbortCQ/tY2aPLDgpOzxVC9TSYe6lm4z9qrK HQqp5Nw/KjDy+kNle9iK2H7lbCIKaAvJpE5uuSlVB615rv/+drpR7nvmxSWjus/p0S5q kQ364wZpQ9GLKn55/pik65xW8IEmS24AtKAwE17fzJ+WP2f//dPCuF3RkanOL0XKfoCt 8ZjQ== 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 i8-20020a17090332c800b001a64b2dc495si7321201plr.462.2023.04.22.04.56.31; Sat, 22 Apr 2023 04:56: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 S229837AbjDVLtq (ORCPT + 99 others); Sat, 22 Apr 2023 07:49:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbjDVLth (ORCPT ); Sat, 22 Apr 2023 07:49:37 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 323C12D58; Sat, 22 Apr 2023 04:49:16 -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 1pqBju-000863-19; Sat, 22 Apr 2023 13:49:14 +0200 Date: Sat, 22 Apr 2023 12:49:10 +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 6/8] net: phy: realtek: use inline functions for 10GbE advertisement Message-ID: <9aec1a609fe9e67b43826537aab37081635292f2.1682163424.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?1763877431151128247?= X-GMAIL-MSGID: =?utf-8?q?1763877431151128247?= Use existing generic inline functions to encode local advertisement of 10GbE link modes as well as to decode link-partner advertisement. Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 62fb965b6d338..078f45447ddad 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -68,10 +68,6 @@ #define RTL_SUPPORTS_5000FULL BIT(14) #define RTL_SUPPORTS_2500FULL BIT(13) #define RTL_SUPPORTS_10000FULL BIT(0) -#define RTL_ADV_2500FULL BIT(7) -#define RTL_LPADV_10000FULL BIT(11) -#define RTL_LPADV_5000FULL BIT(6) -#define RTL_LPADV_2500FULL BIT(5) #define RTL9000A_GINMR 0x14 #define RTL9000A_GINMR_LINK_STATUS BIT(4) @@ -669,14 +665,11 @@ static int rtl822x_config_aneg(struct phy_device *phydev) int ret = 0; if (phydev->autoneg == AUTONEG_ENABLE) { - u16 adv2500 = 0; - - if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, - phydev->advertising)) - adv2500 = RTL_ADV_2500FULL; - ret = phy_modify_paged_changed(phydev, 0xa5d, 0x12, - RTL_ADV_2500FULL, adv2500); + MDIO_AN_10GBT_CTRL_ADV10G | + MDIO_AN_10GBT_CTRL_ADV5G | + MDIO_AN_10GBT_CTRL_ADV2_5G, + linkmode_adv_to_mii_10gbt_adv_t(phydev->advertising)); if (ret < 0) return ret; } @@ -713,12 +706,7 @@ static int rtl822x_read_status(struct phy_device *phydev) if (lpadv < 0) return lpadv; - linkmode_mod_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, - phydev->lp_advertising, lpadv & RTL_LPADV_10000FULL); - linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT, - phydev->lp_advertising, lpadv & RTL_LPADV_5000FULL); - linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, - phydev->lp_advertising, lpadv & RTL_LPADV_2500FULL); + mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, lpadv); } ret = rtlgen_read_status(phydev); From patchwork Sat Apr 22 11:49:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1653631vqo; Sat, 22 Apr 2023 04:56:30 -0700 (PDT) X-Google-Smtp-Source: AKy350bqIz0fpalakMP3ePYGLKbdcecbien6VCkYiZSQSYAai4RrHH70CH5RYpSOLy12C6OLjXQn X-Received: by 2002:a05:6a00:248e:b0:63f:185a:6db2 with SMTP id c14-20020a056a00248e00b0063f185a6db2mr7958028pfv.18.1682164590440; Sat, 22 Apr 2023 04:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682164590; cv=none; d=google.com; s=arc-20160816; b=yovStLV/M6WEn9jUUYdTS2xvd/bczPTGy5NKAqLXqzV1XExA2ocTXywQYEDBxO/z0X NI24a/SO0hCzZTg7pSt4Z/GlCWAAJET/YcB3/hri7Ahy8DpNZZVZoGfnFGT1ZipZGyJh Alm5Sj6XP1QrZTLLbNBrMTk/nNh7vBP1Xj01DIN2h3tom7226xrkPWDrPLHmV9E7LN5+ rpyTvJnyEnX+/8/sW3EZTmW3nIqu8PHXPSAARiOja2Ty4NG4EBH/QtyRs1Fih8HEm4/D iBUJNtX2OJ4Yz3bBR/5qtmozp2xlWsLWu/ylGyF+ZeVD4fbmpC9iOnF2Ic35zWaN6JhM Pmhw== 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=8duXBOr5nLfeKW89wCehrCNfii4pOEpbIxD70HKnG3o=; b=dEB4kWI17lyGfXnNHtyMPo/d9pa4YFG+jF3xSmQU/OYdMvUP6QgGxFvhdIldkEqEhI EhqVDQjcwjfa2C0RgZoAiDZj+qTO2+KmxYme1ySVovAHjyo+gHYE5XuglfzeTnF8SIfi 5TzpJMOYMJ26zyYlDIkwz7qirB100ru0SclfeG2fDLVNClf9Fo0AQSwJ+3lL1TKuUiAV mz9ctssPI4RprwcyauB4/uNAVs2xEPxT0mCIHhqnYrsix4FyOFBGM1yGBEvQ0Uj7Gx2s Bj0LxJ9PmL1H7m/NJ2tMty5QblCVnlP+9aM5/jzSvgRkgt4uvVlU2iw1L4vucqOXbwfR qi/A== 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 h5-20020a625305000000b0063d35b6d9ebsi6588197pfb.368.2023.04.22.04.56.17; Sat, 22 Apr 2023 04:56:30 -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 S229479AbjDVLuB (ORCPT + 99 others); Sat, 22 Apr 2023 07:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbjDVLt7 (ORCPT ); Sat, 22 Apr 2023 07:49:59 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9775272D; Sat, 22 Apr 2023 04:49:36 -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 1pqBkE-00086c-2R; Sat, 22 Apr 2023 13:49:34 +0200 Date: Sat, 22 Apr 2023 12:49:30 +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 7/8] net: phy: realtek: check validity of 10GbE link-partner advertisement Message-ID: <0c3e0e665945ecc5f248438f3231ed48f92764df.1682163424.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?1763877417744357293?= X-GMAIL-MSGID: =?utf-8?q?1763877417744357293?= Only use link-partner advertisement bits for 10GbE modes if they are actually valid. Check LOCALOK and REMOTEOK bits and clear 10GbE modes unless both of them are set. Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 078f45447ddad..de73049037891 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -706,6 +706,10 @@ static int rtl822x_read_status(struct phy_device *phydev) if (lpadv < 0) return lpadv; + if (!(lpadv & MDIO_AN_10GBT_STAT_REMOK) || + !(lpadv & MDIO_AN_10GBT_STAT_LOCOK)) + lpadv = 0; + mii_10gbt_stat_mod_linkmode_lpa_t(phydev->lp_advertising, lpadv); } From patchwork Sat Apr 22 11:49:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 86595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1660639vqo; Sat, 22 Apr 2023 05:08:47 -0700 (PDT) X-Google-Smtp-Source: AKy350Y8h96stZsscfgwS2TB9HqAtv0pPeybD1su11jTPwCaRd4D1kGdsAvZU93wtjFZOT+yMNUS X-Received: by 2002:a17:902:f681:b0:1a9:68d2:e4ae with SMTP id l1-20020a170902f68100b001a968d2e4aemr9143plg.2.1682165326760; Sat, 22 Apr 2023 05:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682165326; cv=none; d=google.com; s=arc-20160816; b=xJ6Va5xOmhL0Z4VfeGP65N1f2FcCKYwNaz0qY1stmAbz3iB8HOy8y1VPU1BBZmodjP gxEIDCB7uXYlJzalRE9OC0o9l7h/3U6g1ghTUQq4GjsbbaR862X4X6lyggedTwMFB3N0 HvQ5T6YBAp7340Zyqdl9K0m3Z8UEPVj/hYmi48g4GRMVpY8ZWiZNfOvXQ7DQ5JLR9UbU xAbZ3zm4cQttZP3fF4cap2xi/hr69x61207Qba2HHXaDCbMNoYJSUeIafpAInNQqV/tB 61vjrm0RwBKfqYBSUnY55m7o70adf8JJlGFS7ykRJUM64taMNAyIwmB13/LgDGSU9T7s 2b5g== 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=s5cTS7Ce8l5DgFaa7rd/10tljuIKq8+9W+5kxxfCjzM=; b=PzpiWtzMYh6DhuYPLd+EJOqrFiH9GoOWl9U/oBwIrhse99nhAXiVulvtZlFj7FLXxC vYIVhT3mfWEB3Jgz2CZK8CpZgj7Tnxbv28zzF4k5CgoD7KOUzY/fZwQLfzriabV4iDaA +0hV9saDJFbXC+FihgUUz70q7p5nCi4CfVu+kop7s3v12HkpuqHXUO1OClgNHgar2TEG 1zMtZf2MifagniPR0Joo6IlnqcYxvw45zxR81SrxU3wv6/u+2RizeojAqQ93qnYtn6Y+ 8Su7K25XXt8pTUyD/0U/OeFluBTukTLnTRHOTqwIS61LpJc+0VYHBS3AoBVLP9p1gzRR HLAw== 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 kw8-20020a170902f90800b001a1defc30cbsi6147657plb.479.2023.04.22.05.08.32; Sat, 22 Apr 2023 05:08:46 -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 S229790AbjDVLuX (ORCPT + 99 others); Sat, 22 Apr 2023 07:50:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjDVLuU (ORCPT ); Sat, 22 Apr 2023 07:50:20 -0400 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA2262139; Sat, 22 Apr 2023 04:49:54 -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 1pqBkT-00086z-1p; Sat, 22 Apr 2023 13:49:49 +0200 Date: Sat, 22 Apr 2023 12:49:45 +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 8/8] net: phy: realtek: setup ALDPS on RTL822x Message-ID: <19f9db255a1ca4afaab5701a6a829697c48ef0e1.1682163424.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?1763878189740413126?= X-GMAIL-MSGID: =?utf-8?q?1763878189740413126?= Setup Link Down Power Saving Mode according the DTS property just like for RTL821x 1GE PHYs. Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index de73049037891..a2324918c42db 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -62,6 +62,10 @@ #define RTL8221B_SERDES_OPTION_MODE_2500BASEX 2 #define RTL8221B_SERDES_OPTION_MODE_HISGMII 3 +#define RTL8221B_PHYCR1 0xa430 +#define RTL8221B_PHYCR1_ALDPS_EN BIT(2) +#define RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN BIT(12) + #define RTL8366RB_POWER_SAVE 0x15 #define RTL8366RB_POWER_SAVE_ON BIT(12) @@ -744,6 +748,25 @@ static int rtl8226_match_phy_device(struct phy_device *phydev) rtlgen_supports_2_5gbps(phydev); } +static int rtl822x_probe(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + int val; + + val = phy_read_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, RTL8221B_PHYCR1); + if (val < 0) + return val; + + if (of_property_read_bool(dev->of_node, "realtek,aldps-enable")) + val |= RTL8221B_PHYCR1_ALDPS_EN | RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN; + else + val &= ~(RTL8221B_PHYCR1_ALDPS_EN | RTL8221B_PHYCR1_ALDPS_XTAL_OFF_EN); + + phy_write_mmd(phydev, RTL8221B_MMD_SERDES_CTRL, RTL8221B_PHYCR1, val); + + return 0; +} + static int rtlgen_resume(struct phy_device *phydev) { int ret = genphy_resume(phydev); @@ -1029,6 +1052,7 @@ static struct phy_driver realtek_drvs[] = { .match_phy_device = rtl8226_match_phy_device, .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, + .probe = rtl822x_probe, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1042,6 +1066,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8226B_RTL8221B 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, + .probe = rtl822x_probe, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1055,6 +1080,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8226-CG 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, + .probe = rtl822x_probe, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1066,6 +1092,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8226B-CG_RTL8221B-CG 2.5Gbps PHY", .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, + .probe = rtl822x_probe, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1078,6 +1105,7 @@ static struct phy_driver realtek_drvs[] = { .get_features = rtl822x_get_features, .config_init = rtl8221b_config_init, .config_aneg = rtl822x_config_aneg, + .probe = rtl822x_probe, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1090,6 +1118,7 @@ static struct phy_driver realtek_drvs[] = { .get_features = rtl822x_get_features, .config_aneg = rtl822x_config_aneg, .config_init = rtl8221b_config_init, + .probe = rtl822x_probe, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume,