From patchwork Wed May 10 22:53:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Couzens X-Patchwork-Id: 92323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3974956vqo; Wed, 10 May 2023 16:03:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7myeFHIIR34ET+WMe2nfXNiye27oASTJU4q3FjAZLYVngZ7bSsq/Mb96TmP+rINBCGjq80 X-Received: by 2002:a17:90b:3004:b0:246:b6f9:148a with SMTP id hg4-20020a17090b300400b00246b6f9148amr20188454pjb.21.1683759786320; Wed, 10 May 2023 16:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683759786; cv=none; d=google.com; s=arc-20160816; b=ea4wVeYpQiTCWwYt2aD477voSglI5IKVCwdhrkeu8eqRUQEXc6ITA9APKizOYumWpi T9LKX6hDFHiYWNdKKg1+UAkfPCzUfYYL021LXj7fEBM3nikqGexRhBIEJ3PBILfMUkC0 wVJ/t63e/HVXXMu0f/jZt9tKV918rxaHPhX1awPhJ4IPV2eydSA4cw7/NBbnJ1pIDlxv rLlKOtWbNx2nnV2H1y+SMDIk7JnAPV0GORNXVqGKCfiDp/kpT3SGBQU4EYw1ld/WqRei 7vXe0TGeOAp9Z3sD2Ed+tOFnzJcu8Wjf0Iq2bhN79KtoBlZdiWJ8YudI0ZR+wSqr1gpv CqwQ== 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=fX31fO+4/Oj5CsyND9+f9SOCsN9QEehIbnZaIUaOUZg=; b=ovfrB8yOefPGWJgW4MxaxzkTkF+28/tNwEzaX8ttn6SbPpRTc9A2Y6/LbGSuNA12JU voN3MHSqrkrdCj0XCUihVbRa5ivQOAG5QsM1sV/swJhhYrIgLhwNNkhoFz4Uw9RZOpkO 0hcM8+IjA3+kWa4/2WHNn6XqHRQHC10biTjSsFkIi4iUa3G5mGLcVB5gP4QMtVyMwEei mr9ZKIWDlviMnglsm2BhiFDJpmto2i0cU6KW8L69wPOW7PTeMqIQ2arAaDHtKwZgjPSO AbcjEnf+LBoVtIQ05FLM820NFz1ZyxdD27o1DItn0corBsgwL0lMtZVwRcsXzNrHqZHw CjWA== 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=fe80.eu Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x4-20020a63db44000000b0050bfc85d989si5254499pgi.154.2023.05.10.16.02.53; Wed, 10 May 2023 16:03:06 -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=fe80.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236693AbjEJW4C (ORCPT + 99 others); Wed, 10 May 2023 18:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236629AbjEJWz4 (ORCPT ); Wed, 10 May 2023 18:55:56 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C7216EA2; Wed, 10 May 2023 15:55:50 -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 1pwsir-0004Pe-1B; Wed, 10 May 2023 22:55:49 +0000 Date: Thu, 11 May 2023 00:53:55 +0200 From: Alexander Couzens 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 1/8] net: phy: realtek: rtl8221: allow to configure SERDES mode Message-ID: <302d982c5550f10d589735fc2e46cf27386c39f4.1683756691.git.daniel@makrotopia.org> References: MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765550101818684130?= X-GMAIL-MSGID: =?utf-8?q?1765550101818684130?= 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 Reviewed-by: Steen Hegelund --- drivers/net/phy/realtek.c | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 3d99fd6664d7..a7dd5a075135 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), @@ -970,6 +1021,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8226B_RTL8221B 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, @@ -992,6 +1044,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, + .config_init = rtl8221b_config_init, .read_status = rtl822x_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, @@ -1002,6 +1055,7 @@ static struct phy_driver realtek_drvs[] = { .name = "RTL8221B-VB-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, @@ -1012,6 +1066,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 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) From patchwork Wed May 10 22:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 92321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3974293vqo; Wed, 10 May 2023 16:02:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5I6HhKSEjYS0bK4B7EEb+Pn3CKvoqjQ8DmJlUhivzQj/uGbKLI2pwW12WzueShID8aoJKH X-Received: by 2002:a17:903:25d5:b0:1ac:a661:a4bd with SMTP id jc21-20020a17090325d500b001aca661a4bdmr6485137plb.20.1683759727047; Wed, 10 May 2023 16:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683759727; cv=none; d=google.com; s=arc-20160816; b=Z7kvHnHlUa4hyYOARvzM7PTq3wuJmk3DkOIJxz6LyDs0tM/mvGaPBRwrSe5iwkr1EF 7oqUnUBcfeojnyBTPvlsWZRG5MpqOXeTSIeuKicn+xyVMxjyGVoL0l/sFBGQiqFEW8nN xdjlFUhPfbWNifdmxwZIgASnDakTFz4BZ2upDjOdfN3iT80jajkgpXOZtC6Zj1HdD/AX K51HsMdfZh7xQfBscKlYm8stz0uUy8brRua1RW5BZt3MzwdFZ+nQ4Hcqa9XklkT10ILM /KXSbLyWCFM1zIu8LP0sXKUQxW7K20cQnprqC+sILdZUprl1L9BC9L7YfI1zZNy1HiWW DMiQ== 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=6qCndzjD/Ojhsa1S9OAfiPDCl5hixonzrj77+/sbsLo=; b=qeT54AOkEGrGMZWT2nQpHsnZZ1rpCISnEszNKhaX+bncpvY63SoM1BM0uhKfWJrCHx KPmqhqzbypQojI4MXdxZV/hAtVHC4kGCSg5HXQiZXg9UrzzkzFDYlaqyosL+1Ik0O7+Q UtmXy8xL0xjzmp8JbtSpntk7AKF0NIMLdg5tSpypbE8subNbPYgHuq/Zmmj6UahRK4Ey Huiz0e7KTIIMhWyDQvRuh8NDx3+AGqhKpyKlYcY6B2TaOo2M3JVGumlSsNJLk/mmzj20 xDYgrIu+pfl5s4UyYX3fqsqnoDiLFQaGAmMd10VNdm2qa8wygN2V3wBap7liS7hj/6FL Ckpg== 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 l2-20020a170902d34200b001a05d12eeb3si4811498plk.189.2023.05.10.16.01.53; Wed, 10 May 2023 16:02:07 -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 S231468AbjEJW52 (ORCPT + 99 others); Wed, 10 May 2023 18:57:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232030AbjEJW5Z (ORCPT ); Wed, 10 May 2023 18:57:25 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F8ED4690; Wed, 10 May 2023 15:57:17 -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 1pwskF-0004Qx-2b; Wed, 10 May 2023 22:57:16 +0000 Date: Thu, 11 May 2023 00:55:11 +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 3/8] net: phy: realtek: use genphy_soft_reset for 2.5G PHYs Message-ID: <0c1e578a5b02fe49e1114ea75e3c6282eb230ad3.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?1765550039266623628?= X-GMAIL-MSGID: =?utf-8?q?1765550039266623628?= 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 4a2c1ad02d48..0cf7846c9812 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", @@ -1051,6 +1052,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", @@ -1061,6 +1063,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", @@ -1072,6 +1075,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", @@ -1083,6 +1087,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", @@ -1094,6 +1099,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 Wed May 10 22:58: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: 92324 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3978271vqo; Wed, 10 May 2023 16:08:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4fMvjAomTodGzdFzTTTnZcDfmjxWkL4G7LkkAkrj4rs8NY7xf6vrrcwCHgcQ+gEO9CdAEP X-Received: by 2002:a17:902:bd44:b0:1a6:9d98:e763 with SMTP id b4-20020a170902bd4400b001a69d98e763mr18323665plx.26.1683760110797; Wed, 10 May 2023 16:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683760110; cv=none; d=google.com; s=arc-20160816; b=GGmwDYEEzeyGfV/UDW+o7QNi2pEaLA8hgr3Ql2YXeRRZPzeQFwAwPMs1U4+zyHlllB VmcMnH1AXCjtAWPPDih51CYdQ1WQkJQ9fBFeJ164uVnogcnItk3fq+NiuwtxaRuMrKK7 EwkOIr8ElW4JR3FbxgM2+jELENCWg3czkp89HsmvAYxdso1AnyyQKemWGmfQYOF84Vc7 bKIdg1L2UhgDxi1EVjFY5bvT2ZSlI0tySgAMJPZlrRY5GmYN8C07k2xjqJZAJ9r+My0L NRapZFQl4QsxZ1or8KsZ9GhrVuph6WzBRxAhBWGWSbdQTjeHr+gYBj5QzBGGY/KvfaWa dSfg== 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=2l9h8ojR3yYSLsGeKUCE1lyRpBTvO/ed7Mich777Tpw=; b=dmt5NAQuTExTJlEkxlZbFzXtualYHfpRxnH15KGSHC/w9N19nqTCCpv5tzRBPdH4N9 y2iZBvxyt0yzCPvuaW5TS8ctOGyqrFzds7OBGpbbzG3YBIeW7PXW7HF4QW4GbbPwRwaL BHgJ/IOuARQPP9V+sw8sWpGNvMz8YqOB5cIHwsRJyZH7uW9gx81Sl9o2TaqouWaKpN2m +L3HS0oeR1xTCfwPHca84qb0sE6eXoicyyd+pvxs9shtBGorIeU0Hi4Io/wuGAS/uweK ATdouhD81y9kzIpXFPAAHuRpake+XT+l7ME3MsaN7pl3cXpfmoh1hdIo6lz1UTvQDBeF tDBQ== 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 y13-20020a170902b48d00b001a52db202c7si4854027plr.382.2023.05.10.16.08.18; Wed, 10 May 2023 16:08: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 S235708AbjEJXAI (ORCPT + 99 others); Wed, 10 May 2023 19:00:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236614AbjEJXAH (ORCPT ); Wed, 10 May 2023 19:00:07 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E64F9E64; Wed, 10 May 2023 16:00:05 -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 1pwsmy-0004U1-1A; Wed, 10 May 2023 23:00:04 +0000 Date: Thu, 11 May 2023 00:58:10 +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 4/8] net: phy: realtek: disable SGMII in-band AN for 2.5G PHYs Message-ID: <574c9703523af5643af0623144db3aa385635e84.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?1765550441912209220?= X-GMAIL-MSGID: =?utf-8?q?1765550441912209220?= 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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index 0cf7846c9812..acadb6f0057b 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -666,7 +666,7 @@ static int rtl822x_get_features(struct phy_device *phydev) static int rtl822x_config_aneg(struct phy_device *phydev) { - int ret = 0; + int val, ret = 0; if (phydev->autoneg == AUTONEG_ENABLE) { u16 adv2500 = 0; @@ -681,6 +681,19 @@ static int rtl822x_config_aneg(struct phy_device *phydev) return ret; } + /* MACs using phylink assume SGMII in-band status is not used. + * Keep things as they are for MACs not using phylink such as + * RealTek PCIe chips which come with built-in PHYs + */ + if (phydev->phylink) { + /* 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 __genphy_config_aneg(phydev, ret); } From patchwork Wed May 10 22:58:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 92326 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3984380vqo; Wed, 10 May 2023 16:21:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6eXakhssu0Xppfs/2Pc7Wt97PCx5lQrEHGc2LcJ7AVB8FjILuBLIf+j7QEhFauPHGs9ClG X-Received: by 2002:a17:902:e550:b0:1a6:6f3f:bc3 with SMTP id n16-20020a170902e55000b001a66f3f0bc3mr26868653plf.57.1683760866452; Wed, 10 May 2023 16:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683760866; cv=none; d=google.com; s=arc-20160816; b=HjzBy8OFFpVWQpCHsFSDZd8fpL1GynP521OetCf4i7BMLlseB0vHTlzkanFNUKFw53 Lqdh7JNBpavZt/YCuoDvOV7o0f5Im8iF4QW0eIU3wuGsHcjj9av7jYDLdOnbGDZ3ZZ/D jOJzS/DrJPeVZuRiqYqxpkvZdthkUwlUYPkmbBob/xWvT4BhmfN32qvrVW5wrb76cde0 GWd4X/6wev9vNaUI5IVkh/delxaXBBJauTowO+PkNWDB9j5x754rU0gaGNhD74gX8Eh0 305ZLo2IpUPMAIKUlU58W0z6EIGbMnl2ZNc4QXDiAg6S4HYERlJ3dntelmm8vXJRRe0b gcCQ== 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=GIiS0fWEVQ/Ll22Lnm0hVFBDGpomp5UcSojoTi9HQnU=; b=Sqn/V3lOX/QFJ4wdbcW1e4R0ctaDZnmR6W9s9UMt98+dCb65mWLnpNKObNRcZu85gS 8MfRA0LUQ0pf34/LdFEmo9RPVwEOrO9k4QKuF6sbgG6QCWYRxmSwWndy2YTXl7vNdcUQ ZIfyOpmTR5a75v87aTtl3GWFTDg4NQkPiP5zB2sSVOhTl6xxJYgMtlMo2d9XRFzoysAd QZoTDaXoXxqZqXiDOafKKrAFawWGSckWbaPJ71w4rtOS1YAtMvTLL1k4lyPsVAVE23Vq xSQMHGpat4J2zPjylXOFHmFDjVaBprz2A9qkKq0JFRT9iv6dzYF9+t+WhYOX54GCK5B9 mZMA== 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 u18-20020a170903125200b0019f3064da41si5445031plh.383.2023.05.10.16.20.51; Wed, 10 May 2023 16:21:06 -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 S236690AbjEJXAs (ORCPT + 99 others); Wed, 10 May 2023 19:00:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236637AbjEJXAr (ORCPT ); Wed, 10 May 2023 19:00:47 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0A6610F5; Wed, 10 May 2023 16:00: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 1pwsnU-0004Uo-0h; Wed, 10 May 2023 23:00:36 +0000 Date: Thu, 11 May 2023 00:58:42 +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 5/8] net: phy: realtek: make sure paged read is protected by mutex 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?1765551234500012088?= X-GMAIL-MSGID: =?utf-8?q?1765551234500012088?= As we cannot rely on phy_read_paged function before the PHY is identified, the paged read in rtlgen_supports_2_5gbps needs to be open coded as it is being called by the match_phy_device function, ie. before .read_page and .write_page have been populated. Make sure it is also protected by the MDIO bus mutex and use rtl821x_write_page instead of 3 individually locked MDIO bus operations. Signed-off-by: Daniel Golle --- drivers/net/phy/realtek.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c index acadb6f0057b..e6a46c4d97b1 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -744,9 +744,11 @@ 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); + phy_lock_mdio_bus(phydev); + rtl821x_write_page(phydev, 0xa61); + val = __phy_read(phydev, 0x13); + rtl821x_write_page(phydev, 0); + phy_unlock_mdio_bus(phydev); return val >= 0 && val & RTL_SUPPORTS_2500FULL; } From patchwork Wed May 10 22:59: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: 92329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4012609vqo; Wed, 10 May 2023 17:26:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5oXLk1FWqHZEdQt827qqYYduDIxgwr4eT3YQRLpxCe6BiAgc2Py0JtLasPjc4zwCa2Dhzy X-Received: by 2002:a05:6a20:3d09:b0:ee:f290:5b5e with SMTP id y9-20020a056a203d0900b000eef2905b5emr24772774pzi.43.1683764816451; Wed, 10 May 2023 17:26:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683764816; cv=none; d=google.com; s=arc-20160816; b=CEEhrFOkOFzUekmTGn5gvUfXi3alimYdPnvKGANn3rFV+CUSDei9O3NEohGw4eQupO 4iUJZiTBLVQZj01C8GJzI48X+7StCyy58bPFzIN+878u2f1pYbHuRxX2FFgdeN6Ju0E0 Of2bFtTa8QwEP66sXFJUCHBKMgtwEFelqMyzL+a8GNCAH3gUez0NvtHZaUqdstU/rwL9 +XD67kPo1b2+pZkB/xz+2RNMYTqEO66ZWeLimnmP0UTyKGVsdtq47hZEmkSwNdfjai41 0alaK9smYZ1k7Rg8HADgxcZdONdzxd9elSs2ySWTiBHCu8fF4ODSSL0sybeNKtiB0pUo KHMA== 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=xwbZ1jtHL2M3/Q8IzuP1FSlh5IPZjJl2FYQVUtS7Ugo=; b=hZ5spafieXZqWOlwsBY5AMbi4ZRKGh7kX50I87TujnQXRMNk5QsQ6SM6eiXkY+Ywwz kKh3k2R2k+Ld4kD4qUxfdkvdNxi7LPMlDRBvm80aVxYVuYqYBs+ZizVU3Gz6EBAHwmYH M46DTae2vnF5x8JH1eJlk/Eihv4eWBSm3jCVWTQ26wWkqfCe/1ieq4Kv2WL/IdF6jwwR 17wCACeBr3eWOLrhFqFYQw629FTBd0PCZ7BdczLKVgdp/pZKRlWU45vhHSZIh3T7UtvR rC/w7PW49tUxfzMgwTOJMl8TpogIubjTijK5tshE7VpMnyDM4IQfKilpCIaWhsIVQl8q nzNQ== 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 b9-20020a637149000000b004c259db61fdsi5191483pgn.561.2023.05.10.17.26.39; Wed, 10 May 2023 17:26:56 -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 S236757AbjEJXBU (ORCPT + 99 others); Wed, 10 May 2023 19:01:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236708AbjEJXBT (ORCPT ); Wed, 10 May 2023 19:01:19 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 200DB40EB; Wed, 10 May 2023 16:01: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 1pwsny-0004VH-0l; Wed, 10 May 2023 23:01:06 +0000 Date: Thu, 11 May 2023 00:59: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 6/8] net: phy: realtek: use inline functions for 10GbE advertisement 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?1765555376558060429?= X-GMAIL-MSGID: =?utf-8?q?1765555376558060429?= 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 e6a46c4d97b1..cde61a30ac4c 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 val, 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; } @@ -722,12 +715,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 Wed May 10 22:59:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 92327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3999640vqo; Wed, 10 May 2023 16:59:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ48pj7V6/2JseqPOpBCjWfCyJtSuCXFuOj4VN+oQFifdAgTw3vfnumA1YvdZNi8NG2/6604 X-Received: by 2002:a17:902:e547:b0:1ac:b03c:a58e with SMTP id n7-20020a170902e54700b001acb03ca58emr5711810plf.25.1683763185873; Wed, 10 May 2023 16:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683763185; cv=none; d=google.com; s=arc-20160816; b=H7GAxwC16RKsFeCaKNnWNjfOApTsvcvQMaiAksWyfoo4wVlw06AzNcpvOsYg6WwC2B 3/nzdje+hnmbocWvDPVNUo+rf4Kt3Hr8olRTZS89rl9+X4vcBwCibld3QzUoqTrpVxA/ FcOXjFs0bulsf+0x0QXdvHpDtZdvhQc1ibQwY0Xy4/miDaheDcyyw8nqvD3fX4VdcHqO ++VANYGT41wm99DvhNYw4oaWlBwFay2C50iNdo34w1t3zRnk99MdIb/epvA/hzCBW040 rOTMY4QRLH1GDsnVbLhjZfR4NO9gRylrdAwSXqXTvKJUzL+JI81dwmrjJXhiO0j0B7dM KvEA== 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=h+3FQ3Pb3lJqR+IKZmMEYcEXjSkVddYPT3xYFpZW48U=; b=d4guhVENUwc1ULbHWRgM6KcE4GVZiCB8Vhwmhlg92p/QKuXg7YKg7nXC4rJa2aSX8n eZ/YHg0iTsgR6QScTD42ITrqqb9HMt6UXJNATBJwLUXRRFaLQuxdA6cBBVvrPGFu7g54 JRnUe3e5TcBHfhodtDR+VoyAitIFIC7bSDGCoYOi6SZY4v+mR8T5/xFc4pCC4sEX+GTU jaWH3gfKba/uUsVJ/Vh+jBD87YmXdGmUuY5aWT913ddz3JyBLt7BXyWNz9dFB4kuif8p njBs8nePJgxsPKsChzN5nFnkdDdblKIj5oeDBP15vANrz3KCqDhqNqVPW8eF9NhXHwqJ ofmQ== 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 j4-20020a17090276c400b001a95babe3c0si5038274plt.371.2023.05.10.16.59.29; Wed, 10 May 2023 16:59:45 -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 S236723AbjEJXBw (ORCPT + 99 others); Wed, 10 May 2023 19:01:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236801AbjEJXBr (ORCPT ); Wed, 10 May 2023 19:01:47 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A1F49D9; Wed, 10 May 2023 16:01:42 -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 1pwsoW-0004Vu-2l; Wed, 10 May 2023 23:01:41 +0000 Date: Thu, 11 May 2023 00:59:46 +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 7/8] net: phy: realtek: check validity of 10GbE link-partner advertisement Message-ID: <3722c3cf286bdaf89343c6d9e552d3eef79a2557.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?1765553666325853389?= X-GMAIL-MSGID: =?utf-8?q?1765553666325853389?= 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 cde61a30ac4c..29168f98f451 100644 --- a/drivers/net/phy/realtek.c +++ b/drivers/net/phy/realtek.c @@ -715,6 +715,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 Wed May 10 23:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 92325 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3983605vqo; Wed, 10 May 2023 16:19:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Kp+/6eksDRo9b3C3yD3V++blhVIULUhp1slCpA+++ak/hjc7qW2HWRoBaX0ytvIxbd4R3 X-Received: by 2002:a17:902:b946:b0:1a9:9a18:3458 with SMTP id h6-20020a170902b94600b001a99a183458mr19576124pls.31.1683760757418; Wed, 10 May 2023 16:19:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683760757; cv=none; d=google.com; s=arc-20160816; b=v2VL+QhrsIRoELyyRcNvRL3boiELLf36+5iRRfpDUZtxYVdWVQbrzeUtg75mrGIu7G fkFzgGaoWxDcomquZ6QwmPbtulfaUgXkx4QipuF5O5Z4h0eIxYzdeiZIwQ+P+evfLCbT ZA+H5bvLHcII80ziKCqEv3v8COwqetwtm2q5CwcdvUnLM9VCz1n+5JPkPjLrPqDgoGU0 9bu5wDNmHfb0vhuFGknurELQQD8vRdFrjxW7z7LUM4oz3m71sNFqSI3Mei2TWxAopBYo fo6yLDaMbIqLC9CQupqPtIu8nG/IRG/4d9Y762a0h1TbNVBQS9qRfIDkrb9D5l3V9RPP MuLQ== 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=7gkjpn6qo8GKo/OFPTXVmWj0Oe/mJ+FnTJe60gvg7hU=; b=sxS3ubq+jwovt4PEzEhbtwmHd2G2m8OiOWegtLgTntzWPFTscW7Bltxb5NnUGdv+h4 OnsH4qlLnoR8f0X18AvFdSwK5ZsgivQDQDs7O9OLSOnHJy6XMSi3fvaEIF0LjrPkDzPc 2NEwdagY512J0a9wGvFtFts8tdRIpqgqEqyVH4MKGfZnD70zd9vARhdbJT+vc0dCEjQE TTtgIG+BVQx8vKmqLPm7fSXjj/pVCCP3Hfwr1kbqV5xh3uX+EHGLM5H4et8ncOA9wSop 2O0SpdDLRQUAbcU+LJoyuXMytdsiSOawxyJQzsFsFz3tyew33oR4uE+gNuGsp/xisWg1 8Cdg== 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 f16-20020a63f110000000b0050f66d4e070si5302180pgi.417.2023.05.10.16.19.03; Wed, 10 May 2023 16:19:17 -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 S236774AbjEJXC3 (ORCPT + 99 others); Wed, 10 May 2023 19:02:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236497AbjEJXC2 (ORCPT ); Wed, 10 May 2023 19:02:28 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D06305249; Wed, 10 May 2023 16:02:26 -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 1pwspE-0004Wg-2T; Wed, 10 May 2023 23:02:25 +0000 Date: Thu, 11 May 2023 01:00:21 +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 8/8] net: phy: realtek: setup ALDPS on RTL8221B Message-ID: <701034ea45c08db557af926a5a44113e4e45c634.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?1765551120168019056?= X-GMAIL-MSGID: =?utf-8?q?1765551120168019056?= 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 29168f98f451..b5d7208004d8 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) @@ -757,6 +761,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); @@ -1034,6 +1057,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, @@ -1048,6 +1072,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, @@ -1061,6 +1086,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, @@ -1073,6 +1099,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, @@ -1085,6 +1112,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, @@ -1097,6 +1125,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,