From patchwork Fri Jan 24 22:05:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13949974 X-Patchwork-Delegate: kuba@kernel.org Received: from mx10lb.world4you.com (mx10lb.world4you.com [81.19.149.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0FFF1E98FC for ; Fri, 24 Jan 2025 22:32:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737757939; cv=none; b=ZtSKTgo0f8U4zGgjbK3MtEqC5FcLgt+hMFIive0G0xybGIN4JYWhAdun5T+wzprwKAuCKGgci6yWpsjRtlVP3pTGLPCaTc9mTZIXkq0BZdmeNFLikddkN2inC1fi6Kv0CkFf4WMEYrs/Z1it1KyelVXKd2YyDs9bATkL73a8uAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737757939; c=relaxed/simple; bh=xdXwkAGyAlsxSKy/kmwlzfZ9HMEg8WhkwCfzFxHFsLc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jdiUzbIXV2EzPnx+GUeMmSc1NLL2H8ap+bJM95mPGFz/1nbSS31k2RSAq8kWP/Npp9QXACbMEqd0rqIQvmC1SIEluiHC1sGJl6/iiSxmGwFbpPSBQkaiERbg9PK+NAuDZXU91fF1Ylxqq3p4pLP4oxqjBOfZuD1Zl5vNsyaVS2Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=w/US+93Q; arc=none smtp.client-ip=81.19.149.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="w/US+93Q" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LIyg/QQgFIPrTGKoX9Ccwm4JDKA/xTAf+3XCS+ERIeE=; b=w/US+93Qr+ThJbApvx2YtnZ9oq 0+OpEczCpDfXCMPy3gc2qnEM7k3jQoBlgybU/U3GkEiaAj9GuSLpZpPgx3VBtqYRYpx+xP7Z9hjdn ddLGapc2HT5A6WHJksNGX5sHwcuto0dSBw8+XtP0QdRjvyO0NoL1NY424CNZrOkF4GXY=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx10lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tbRnt-000000005Ng-3hTG; Fri, 24 Jan 2025 23:05:30 +0100 From: Gerhard Engleder To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next v3 1/7] net: phy: Allow loopback speed selection for PHY drivers Date: Fri, 24 Jan 2025 23:05:10 +0100 Message-Id: <20250124220516.113798-2-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250124220516.113798-1-gerhard@engleder-embedded.com> References: <20250124220516.113798-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC PHY drivers support loopback mode, but it is not possible to select the speed of the loopback mode. The speed is chosen by the set_loopback() operation of the PHY driver. Same is valid for genphy_loopback(). There are PHYs that support loopback with different speeds. Extend set_loopback() to make loopback speed selection possible. Signed-off-by: Gerhard Engleder --- drivers/net/phy/adin1100.c | 5 ++++- drivers/net/phy/dp83867.c | 5 ++++- drivers/net/phy/marvell.c | 8 +++++++- drivers/net/phy/mxl-gpy.c | 11 +++++++---- drivers/net/phy/phy-c45.c | 5 ++++- drivers/net/phy/phy_device.c | 12 +++++++++--- drivers/net/phy/xilinx_gmii2rgmii.c | 7 ++++--- include/linux/phy.h | 16 ++++++++++++---- 8 files changed, 51 insertions(+), 18 deletions(-) diff --git a/drivers/net/phy/adin1100.c b/drivers/net/phy/adin1100.c index 6bb469429b9d..bd7a47a903ac 100644 --- a/drivers/net/phy/adin1100.c +++ b/drivers/net/phy/adin1100.c @@ -215,8 +215,11 @@ static int adin_resume(struct phy_device *phydev) return adin_set_powerdown_mode(phydev, false); } -static int adin_set_loopback(struct phy_device *phydev, bool enable) +static int adin_set_loopback(struct phy_device *phydev, bool enable, int speed) { + if (enable && speed) + return -EOPNOTSUPP; + if (enable) return phy_set_bits_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_10T1L_CTRL, BMCR_LOOPBACK); diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index c1451df430ac..063266cafe9c 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -1009,8 +1009,11 @@ static void dp83867_link_change_notify(struct phy_device *phydev) } } -static int dp83867_loopback(struct phy_device *phydev, bool enable) +static int dp83867_loopback(struct phy_device *phydev, bool enable, int speed) { + if (enable && speed) + return -EOPNOTSUPP; + return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, enable ? BMCR_LOOPBACK : 0); } diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 44e1927de499..4ed7ec1be74f 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -2131,13 +2131,19 @@ static void marvell_get_stats_simple(struct phy_device *phydev, data[i] = marvell_get_stat_simple(phydev, i); } -static int m88e1510_loopback(struct phy_device *phydev, bool enable) +static int m88e1510_loopback(struct phy_device *phydev, bool enable, int speed) { int err; if (enable) { u16 bmcr_ctl, mscr2_ctl = 0; + if (speed == SPEED_10 || speed == SPEED_100 || + speed == SPEED_1000) + phydev->speed = speed; + else if (speed) + return -EINVAL; + bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); err = phy_write(phydev, MII_BMCR, bmcr_ctl); diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c index 94d9cb727121..a6cca8d43253 100644 --- a/drivers/net/phy/mxl-gpy.c +++ b/drivers/net/phy/mxl-gpy.c @@ -813,7 +813,7 @@ static void gpy_get_wol(struct phy_device *phydev, wol->wolopts = priv->wolopts; } -static int gpy_loopback(struct phy_device *phydev, bool enable) +static int gpy_loopback(struct phy_device *phydev, bool enable, int speed) { struct gpy_priv *priv = phydev->priv; u16 set = 0; @@ -822,6 +822,9 @@ static int gpy_loopback(struct phy_device *phydev, bool enable) if (enable) { u64 now = get_jiffies_64(); + if (speed) + return -EOPNOTSUPP; + /* wait until 3 seconds from last disable */ if (time_before64(now, priv->lb_dis_to)) msleep(jiffies64_to_msecs(priv->lb_dis_to - now)); @@ -845,15 +848,15 @@ static int gpy_loopback(struct phy_device *phydev, bool enable) return 0; } -static int gpy115_loopback(struct phy_device *phydev, bool enable) +static int gpy115_loopback(struct phy_device *phydev, bool enable, int speed) { struct gpy_priv *priv = phydev->priv; if (enable) - return gpy_loopback(phydev, enable); + return gpy_loopback(phydev, enable, speed); if (priv->fw_minor > 0x76) - return gpy_loopback(phydev, 0); + return gpy_loopback(phydev, 0, 0); return genphy_soft_reset(phydev); } diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c index 0dac08e85304..84c24e8847c3 100644 --- a/drivers/net/phy/phy-c45.c +++ b/drivers/net/phy/phy-c45.c @@ -1230,8 +1230,11 @@ int gen10g_config_aneg(struct phy_device *phydev) } EXPORT_SYMBOL_GPL(gen10g_config_aneg); -int genphy_c45_loopback(struct phy_device *phydev, bool enable) +int genphy_c45_loopback(struct phy_device *phydev, bool enable, int speed) { + if (enable && speed) + return -EOPNOTSUPP; + return phy_modify_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, MDIO_PCS_CTRL1_LOOPBACK, enable ? MDIO_PCS_CTRL1_LOOPBACK : 0); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 5b34d39d1d52..19f4deac59a6 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2122,9 +2122,9 @@ int phy_loopback(struct phy_device *phydev, bool enable) } if (phydev->drv->set_loopback) - ret = phydev->drv->set_loopback(phydev, enable); + ret = phydev->drv->set_loopback(phydev, enable, 0); else - ret = genphy_loopback(phydev, enable); + ret = genphy_loopback(phydev, enable, 0); if (ret) goto out; @@ -2893,12 +2893,18 @@ int genphy_resume(struct phy_device *phydev) } EXPORT_SYMBOL(genphy_resume); -int genphy_loopback(struct phy_device *phydev, bool enable) +int genphy_loopback(struct phy_device *phydev, bool enable, int speed) { if (enable) { u16 ctl = BMCR_LOOPBACK; int ret, val; + if (speed == SPEED_10 || speed == SPEED_100 || + speed == SPEED_1000) + phydev->speed = speed; + else if (speed) + return -EINVAL; + ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); phy_modify(phydev, MII_BMCR, ~0, ctl); diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 7c51daecf18e..2024d8ef36d9 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -64,15 +64,16 @@ static int xgmiitorgmii_read_status(struct phy_device *phydev) return 0; } -static int xgmiitorgmii_set_loopback(struct phy_device *phydev, bool enable) +static int xgmiitorgmii_set_loopback(struct phy_device *phydev, bool enable, + int speed) { struct gmii2rgmii *priv = mdiodev_get_drvdata(&phydev->mdio); int err; if (priv->phy_drv->set_loopback) - err = priv->phy_drv->set_loopback(phydev, enable); + err = priv->phy_drv->set_loopback(phydev, enable, speed); else - err = genphy_loopback(phydev, enable); + err = genphy_loopback(phydev, enable, speed); if (err < 0) return err; diff --git a/include/linux/phy.h b/include/linux/phy.h index afaae74d0949..fe61ae958a6c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1207,8 +1207,16 @@ struct phy_driver { int (*set_tunable)(struct phy_device *dev, struct ethtool_tunable *tuna, const void *data); - /** @set_loopback: Set the loopback mood of the PHY */ - int (*set_loopback)(struct phy_device *dev, bool enable); + /** + * @set_loopback: Set the loopback mode of the PHY + * enable selects if the loopback mode is enabled or disabled. If the + * loopback mode is enabled, then the speed of the loopback mode can be + * requested with the speed argument. If the speed argument is zero, + * then any speed can be selected. If the speed argument is > 0, then + * this speed shall be selected for the loopback mode or EOPNOTSUPP + * shall be returned if speed selection is not supported. + */ + int (*set_loopback)(struct phy_device *dev, bool enable, int speed); /** @get_sqi: Get the signal quality indication */ int (*get_sqi)(struct phy_device *dev); /** @get_sqi_max: Get the maximum signal quality indication */ @@ -2011,7 +2019,7 @@ int genphy_read_status(struct phy_device *phydev); int genphy_read_master_slave(struct phy_device *phydev); int genphy_suspend(struct phy_device *phydev); int genphy_resume(struct phy_device *phydev); -int genphy_loopback(struct phy_device *phydev, bool enable); +int genphy_loopback(struct phy_device *phydev, bool enable, int speed); int genphy_soft_reset(struct phy_device *phydev); irqreturn_t genphy_handle_interrupt_no_ack(struct phy_device *phydev); @@ -2053,7 +2061,7 @@ int genphy_c45_pma_baset1_read_master_slave(struct phy_device *phydev); int genphy_c45_read_status(struct phy_device *phydev); int genphy_c45_baset1_read_status(struct phy_device *phydev); int genphy_c45_config_aneg(struct phy_device *phydev); -int genphy_c45_loopback(struct phy_device *phydev, bool enable); +int genphy_c45_loopback(struct phy_device *phydev, bool enable, int speed); int genphy_c45_pma_resume(struct phy_device *phydev); int genphy_c45_pma_suspend(struct phy_device *phydev); int genphy_c45_fast_retrain(struct phy_device *phydev, bool enable); From patchwork Fri Jan 24 22:05:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13949975 X-Patchwork-Delegate: kuba@kernel.org Received: from mx10lb.world4you.com (mx10lb.world4you.com [81.19.149.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF1091EEA28 for ; Fri, 24 Jan 2025 22:32:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737757943; cv=none; b=qlBg/zCSm5IXT4PnkiafrtvbmjAAggXF061Gf5mZt/ug3kLEwvslNV8ObC76E6PrmMwhPpIxeiFi+wsG/raXcQFAo/G2FLj6u0mLu/ApWWVYAOcEykgxbsb6LWhSa8YKPFdh/hl0CIT/PYA/0l5V9U1aDlo5YoccL5PBVWgqR2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737757943; c=relaxed/simple; bh=Pf8YxtFwo9EOKCrQ0vyUm3DOfXzF0dgB4pi4/36ysjk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=imVSA9pOjzcbM9I0tcfxYzUhMZFOyTPn00VDXNxs8rfwBwPpxHsLYpNnKHxWjslltNTpLNkRGr4fC6DCjWgOOihTw/hWPPYr3Zaf8VRl9RbQZpIYsmU+KnQlUmn1voq2z/n0R3tSCbOv8+yaTVbRjBkJScxdzDqIejtBWqujsWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=jsIentGE; arc=none smtp.client-ip=81.19.149.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="jsIentGE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=r5ZZKWI0odZXRg8ljY3tN+GWITlBmL3GldUOdCkK6nE=; b=jsIentGEGXRW2BuSQIOSMxzQf0 OsqTvBOvy9vCZSA0tk0fn9aXX/OJXC17weoavY3SPBgQ3v2aQ5S0H9YsMqRZg4TWTynMTNWMur31k nWaRJI2mMGW1lJEhigQ5JJ9zWMC6DLBwUshvP1FTE2Z/Uk7RiT/BsfmLTovA7evD8Plc=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx10lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tbRnw-000000005Ng-0skn; Fri, 24 Jan 2025 23:05:32 +0100 From: Gerhard Engleder To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next v3 2/7] net: phy: Support speed selection for PHY loopback Date: Fri, 24 Jan 2025 23:05:11 +0100 Message-Id: <20250124220516.113798-3-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250124220516.113798-1-gerhard@engleder-embedded.com> References: <20250124220516.113798-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC phy_loopback() leaves it to the PHY driver to select the speed of the loopback mode. Thus, the speed of the loopback mode depends on the PHY driver in use. Add support for speed selection to phy_loopback() to enable loopback with defined speeds. Ensure that link up is signaled if speed changes as speed is not allowed to change during link up. Link down and up is necessary for a new speed. Signed-off-by: Gerhard Engleder --- drivers/net/ethernet/engleder/tsnep_main.c | 2 +- .../net/ethernet/hisilicon/hns/hns_ethtool.c | 4 +- .../hisilicon/hns3/hns3pf/hclge_main.c | 4 +- .../hisilicon/hns3/hns3pf/hclge_mdio.c | 2 +- .../stmicro/stmmac/stmmac_selftests.c | 8 +- drivers/net/phy/phy.c | 76 +++++++++++++++++++ drivers/net/phy/phy_device.c | 35 --------- include/linux/phy.h | 2 +- net/core/selftests.c | 4 +- 9 files changed, 89 insertions(+), 48 deletions(-) diff --git a/drivers/net/ethernet/engleder/tsnep_main.c b/drivers/net/ethernet/engleder/tsnep_main.c index 18df6a5cbfc6..a16b12137edb 100644 --- a/drivers/net/ethernet/engleder/tsnep_main.c +++ b/drivers/net/ethernet/engleder/tsnep_main.c @@ -230,7 +230,7 @@ static int tsnep_phy_loopback(struct tsnep_adapter *adapter, bool enable) { int retval; - retval = phy_loopback(adapter->phydev, enable); + retval = phy_loopback(adapter->phydev, enable, 0); /* PHY link state change is not signaled if loopback is enabled, it * would delay a working loopback anyway, let's ensure that loopback diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c index 6c458f037262..60a586a951a0 100644 --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c @@ -266,9 +266,9 @@ static int hns_nic_config_phy_loopback(struct phy_device *phy_dev, u8 en) if (err) goto out; - err = phy_loopback(phy_dev, true); + err = phy_loopback(phy_dev, true, 0); } else { - err = phy_loopback(phy_dev, false); + err = phy_loopback(phy_dev, false, 0); if (err) goto out; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c index db7845009252..3826b982fef8 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -7875,7 +7875,7 @@ static int hclge_enable_phy_loopback(struct hclge_dev *hdev, if (ret) return ret; - return phy_loopback(phydev, true); + return phy_loopback(phydev, true, 0); } static int hclge_disable_phy_loopback(struct hclge_dev *hdev, @@ -7883,7 +7883,7 @@ static int hclge_disable_phy_loopback(struct hclge_dev *hdev, { int ret; - ret = phy_loopback(phydev, false); + ret = phy_loopback(phydev, false, 0); if (ret) return ret; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c index 80079657afeb..9a456ebf9b7c 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mdio.c @@ -258,7 +258,7 @@ void hclge_mac_start_phy(struct hclge_dev *hdev) if (!phydev) return; - phy_loopback(phydev, false); + phy_loopback(phydev, false, 0); phy_start(phydev); } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c index 3ca1c2a816ff..a01bc394d1ac 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c @@ -382,14 +382,14 @@ static int stmmac_test_phy_loopback(struct stmmac_priv *priv) if (!priv->dev->phydev) return -EOPNOTSUPP; - ret = phy_loopback(priv->dev->phydev, true); + ret = phy_loopback(priv->dev->phydev, true, 0); if (ret) return ret; attr.dst = priv->dev->dev_addr; ret = __stmmac_test_loopback(priv, &attr); - phy_loopback(priv->dev->phydev, false); + phy_loopback(priv->dev->phydev, false, 0); return ret; } @@ -1985,7 +1985,7 @@ void stmmac_selftest_run(struct net_device *dev, case STMMAC_LOOPBACK_PHY: ret = -EOPNOTSUPP; if (dev->phydev) - ret = phy_loopback(dev->phydev, true); + ret = phy_loopback(dev->phydev, true, 0); if (!ret) break; fallthrough; @@ -2018,7 +2018,7 @@ void stmmac_selftest_run(struct net_device *dev, case STMMAC_LOOPBACK_PHY: ret = -EOPNOTSUPP; if (dev->phydev) - ret = phy_loopback(dev->phydev, false); + ret = phy_loopback(dev->phydev, false, 0); if (!ret) break; fallthrough; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index c008fe050245..b16ffdf79832 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1703,6 +1703,82 @@ void phy_mac_interrupt(struct phy_device *phydev) } EXPORT_SYMBOL(phy_mac_interrupt); +/** + * phy_loopback - Configure loopback mode of PHY + * @phydev: target phy_device struct + * @enable: enable or disable loopback mode + * @speed: enable loopback mode with speed + * + * Configure loopback mode of PHY and signal link down and link up if speed is + * changing. + */ +int phy_loopback(struct phy_device *phydev, bool enable, int speed) +{ + bool link_up = false; + int ret = 0; + + if (!phydev->drv) + return -EIO; + + mutex_lock(&phydev->lock); + + if (enable && phydev->loopback_enabled) { + ret = -EBUSY; + goto out; + } + + if (!enable && !phydev->loopback_enabled) { + ret = -EINVAL; + goto out; + } + + if (enable) { + /* + * Link up is signaled with a defined speed. If speed changes, + * then first link down and after that link up needs to be + * signaled. + */ + if (phydev->link && phydev->state == PHY_RUNNING) { + /* link is up and signaled */ + if (speed && phydev->speed != speed) { + /* signal link down and up for new speed */ + phydev->link = false; + phydev->state = PHY_NOLINK; + phy_link_down(phydev); + + link_up = true; + } + } else { + /* link is not signaled */ + if (speed) { + /* signal link up for new speed */ + link_up = true; + } + } + } + + if (phydev->drv->set_loopback) + ret = phydev->drv->set_loopback(phydev, enable, speed); + else + ret = genphy_loopback(phydev, enable, speed); + + if (ret) + goto out; + + if (link_up) { + phydev->link = true; + phydev->state = PHY_RUNNING; + phy_link_up(phydev); + } + + phydev->loopback_enabled = enable; + +out: + mutex_unlock(&phydev->lock); + return ret; +} +EXPORT_SYMBOL(phy_loopback); + /** * phy_eee_rx_clock_stop() - configure PHY receive clock in LPI * @phydev: target phy_device struct diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 19f4deac59a6..d98ac0bd6d48 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2102,41 +2102,6 @@ int phy_resume(struct phy_device *phydev) } EXPORT_SYMBOL(phy_resume); -int phy_loopback(struct phy_device *phydev, bool enable) -{ - int ret = 0; - - if (!phydev->drv) - return -EIO; - - mutex_lock(&phydev->lock); - - if (enable && phydev->loopback_enabled) { - ret = -EBUSY; - goto out; - } - - if (!enable && !phydev->loopback_enabled) { - ret = -EINVAL; - goto out; - } - - if (phydev->drv->set_loopback) - ret = phydev->drv->set_loopback(phydev, enable, 0); - else - ret = genphy_loopback(phydev, enable, 0); - - if (ret) - goto out; - - phydev->loopback_enabled = enable; - -out: - mutex_unlock(&phydev->lock); - return ret; -} -EXPORT_SYMBOL(phy_loopback); - /** * phy_reset_after_clk_enable - perform a PHY reset if needed * @phydev: target phy_device struct diff --git a/include/linux/phy.h b/include/linux/phy.h index fe61ae958a6c..868798b6d9e8 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1904,7 +1904,7 @@ int phy_init_hw(struct phy_device *phydev); int phy_suspend(struct phy_device *phydev); int phy_resume(struct phy_device *phydev); int __phy_resume(struct phy_device *phydev); -int phy_loopback(struct phy_device *phydev, bool enable); +int phy_loopback(struct phy_device *phydev, bool enable, int speed); int phy_sfp_connect_phy(void *upstream, struct phy_device *phy); void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy); void phy_sfp_attach(void *upstream, struct sfp_bus *bus); diff --git a/net/core/selftests.c b/net/core/selftests.c index 8f801e6e3b91..e99ae983fca9 100644 --- a/net/core/selftests.c +++ b/net/core/selftests.c @@ -299,7 +299,7 @@ static int net_test_phy_loopback_enable(struct net_device *ndev) if (!ndev->phydev) return -EOPNOTSUPP; - return phy_loopback(ndev->phydev, true); + return phy_loopback(ndev->phydev, true, 0); } static int net_test_phy_loopback_disable(struct net_device *ndev) @@ -307,7 +307,7 @@ static int net_test_phy_loopback_disable(struct net_device *ndev) if (!ndev->phydev) return -EOPNOTSUPP; - return phy_loopback(ndev->phydev, false); + return phy_loopback(ndev->phydev, false, 0); } static int net_test_phy_loopback_udp(struct net_device *ndev) From patchwork Fri Jan 24 22:05:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13949976 X-Patchwork-Delegate: kuba@kernel.org Received: from mx10lb.world4you.com (mx10lb.world4you.com [81.19.149.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4F471E98FC for ; Fri, 24 Jan 2025 22:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737757947; cv=none; b=NQbD8Yd7QfT55jKUqbpHBS8ACfvpiT8iqXjVo6KTGAnT+1zTaJgWVIOqfJA7iD4IwqP8mxB4xM0+feE/R9laZVYxmmj+eL1GZjIUgmaIyp1Z9QVhet8oVY8TeUI2xO2MIUGEtyrKkrPxheBhOJLshcS01GeRr3yvMcJ0pkzSFw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737757947; c=relaxed/simple; bh=QunuxMjW5Ydt490SFL68VMYXIJqmr7rmBnAwzwJfq/g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=goSb4Rer6yAbWM7jPB78lMampBiCS2oacJ/Dndidfyt9SoqkcwSgpaQlGL0SKJmqtOvM68IepDoFlf2jouCUs1GCfoM9TBGCE+QjL/hedirvXQg2L57hjsX3KzBBqTkc8uclyvWu2mjrKfcv+TZpO+PSCcoJ4wmAGNW9ai9EJT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=Lha/IGd7; arc=none smtp.client-ip=81.19.149.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="Lha/IGd7" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hoa2uBgB0cK+6yFYS5AMqSXYocqmNE1Ym9X1PxGFp+A=; b=Lha/IGd7UCqQGTkUckb5HpjNod 03nLQ7ZF6tu+Rii3LI+mVww2FIID6MqRkK5ggAh17FB1DXIjT8RWjUEPdMm/SFsOeh/MBhC+zindH r3yLatNRlEfyzMxW/wCmEBfI/WP0alkwlYJy8cZ6jDU1uqfh9+t05Y+DYFxb5WVjHZHE=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx10lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tbRny-000000005Ng-0lyq; Fri, 24 Jan 2025 23:05:34 +0100 From: Gerhard Engleder To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next v3 3/7] net: phy: micrel: Add loopback support Date: Fri, 24 Jan 2025 23:05:12 +0100 Message-Id: <20250124220516.113798-4-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250124220516.113798-1-gerhard@engleder-embedded.com> References: <20250124220516.113798-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The KSZ9031 PHYs requires full duplex for loopback mode. Add PHY specific set_loopback() to ensure this. Signed-off-by: Gerhard Engleder --- drivers/net/phy/micrel.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 9c0b1c229af6..f0cecd898312 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -1030,6 +1030,33 @@ static int ksz9021_config_init(struct phy_device *phydev) #define MII_KSZ9031RN_EDPD 0x23 #define MII_KSZ9031RN_EDPD_ENABLE BIT(0) +static int ksz9031_set_loopback(struct phy_device *phydev, bool enable, + int speed) +{ + u16 ctl = BMCR_LOOPBACK; + int ret, val; + + if (!enable) + return genphy_loopback(phydev, enable, 0); + + if (speed == SPEED_10 || speed == SPEED_100 || speed == SPEED_1000) + phydev->speed = speed; + else if (speed) + return -EINVAL; + phydev->duplex = DUPLEX_FULL; + + ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); + + phy_modify(phydev, MII_BMCR, ~0, ctl); + + ret = phy_read_poll_timeout(phydev, MII_BMSR, val, val & BMSR_LSTATUS, + 5000, 500000, true); + if (ret) + return ret; + + return 0; +} + static int ksz9031_of_load_skew_values(struct phy_device *phydev, const struct device_node *of_node, u16 reg, size_t field_sz, @@ -5564,6 +5591,7 @@ static struct phy_driver ksphy_driver[] = { .resume = kszphy_resume, .cable_test_start = ksz9x31_cable_test_start, .cable_test_get_status = ksz9x31_cable_test_get_status, + .set_loopback = ksz9031_set_loopback, }, { .phy_id = PHY_ID_LAN8814, .phy_id_mask = MICREL_PHY_ID_MASK, From patchwork Fri Jan 24 22:05:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13949968 X-Patchwork-Delegate: kuba@kernel.org Received: from mx10lb.world4you.com (mx10lb.world4you.com [81.19.149.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A695114D430 for ; Fri, 24 Jan 2025 22:05:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756341; cv=none; b=GXKyUIEz1/KiUNbLPlGHRBJ2eSTYO80cd08tYk17MiA+YWCzcpbmMxjZWTlu4K/2VXQ64tG5jYi/QWfCTxnO7FZKE5pYcYOF9Nd9LxdnNLqhECd4GuYryfC56v/gJ3lT1iw5VMX4PFi9DzpKaLRuly5jBY63A/UsxJmmdwJD1Rg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756341; c=relaxed/simple; bh=8ye0a9/fdhMZZ0ytbbI4m36+PkOdsLRg1d8Da9EOIe4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XjlQgo+y8j3jQPOGBLwvnyjxpy13kJ7PLIBVI5xy7JMHlDPqus/9RIORda4PIcB3oz1a3Nf3M661+n59GCam2PtsHpDWCTU6knEFL5OB9U9I5RHeRS9i94okrcSAS69SR0+U3JAWm/hcsP2aeEwFR4/XelajJjJVbxIRLC3+Xd4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=xwWI/P6z; arc=none smtp.client-ip=81.19.149.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="xwWI/P6z" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=FI62flwppvBCl5cLI4ZTmqK7t8EmrqPHcCaIoTN1mBk=; b=xwWI/P6zUHrtdgTbEWoi9QJ4qr HBL2gKJF0LLxqEB5VdyfM30PP//v6CKQG/MM/GM3ijotGXwalg3aG3wROWhM5aZMEcWVlaM1vrtK1 7Iw2TyFMSi7QQRd/pDiMfgd/dpuVlv0FiddJ2T6I1BeMVQITRqlN2IVLaLY/duGdRqRE=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx10lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tbRo0-000000005Ng-0Ke9; Fri, 24 Jan 2025 23:05:36 +0100 From: Gerhard Engleder To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next v3 4/7] net: phy: marvell: Align set_loopback() implementation Date: Fri, 24 Jan 2025 23:05:13 +0100 Message-Id: <20250124220516.113798-5-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250124220516.113798-1-gerhard@engleder-embedded.com> References: <20250124220516.113798-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use genphy_loopback() to disable loopback like ksz9031_set_loopback(). This way disable loopback is implemented only once within genphy_loopback() and the set_loopback() implementations look similar. Also fix comment about msleep() in the out-of loopback case which is not executed in the out-of loopback case. Suggested-by: Andrew Lunn Signed-off-by: Gerhard Engleder --- drivers/net/phy/marvell.c | 72 ++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c index 4ed7ec1be74f..ca8b7d97c964 100644 --- a/drivers/net/phy/marvell.c +++ b/drivers/net/phy/marvell.c @@ -2133,56 +2133,50 @@ static void marvell_get_stats_simple(struct phy_device *phydev, static int m88e1510_loopback(struct phy_device *phydev, bool enable, int speed) { + u16 bmcr_ctl, mscr2_ctl = 0; int err; - if (enable) { - u16 bmcr_ctl, mscr2_ctl = 0; + if (!enable) + return genphy_loopback(phydev, enable, 0); - if (speed == SPEED_10 || speed == SPEED_100 || - speed == SPEED_1000) - phydev->speed = speed; - else if (speed) - return -EINVAL; - - bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); - - err = phy_write(phydev, MII_BMCR, bmcr_ctl); - if (err < 0) - return err; + if (speed == SPEED_10 || speed == SPEED_100 || speed == SPEED_1000) + phydev->speed = speed; + else if (speed) + return -EINVAL; - if (phydev->speed == SPEED_1000) - mscr2_ctl = BMCR_SPEED1000; - else if (phydev->speed == SPEED_100) - mscr2_ctl = BMCR_SPEED100; + bmcr_ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); - err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE, - MII_88E1510_MSCR_2, BMCR_SPEED1000 | - BMCR_SPEED100, mscr2_ctl); - if (err < 0) - return err; + err = phy_write(phydev, MII_BMCR, bmcr_ctl); + if (err < 0) + return err; - /* Need soft reset to have speed configuration takes effect */ - err = genphy_soft_reset(phydev); - if (err < 0) - return err; + if (phydev->speed == SPEED_1000) + mscr2_ctl = BMCR_SPEED1000; + else if (phydev->speed == SPEED_100) + mscr2_ctl = BMCR_SPEED100; - err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, - BMCR_LOOPBACK); + err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE, + MII_88E1510_MSCR_2, BMCR_SPEED1000 | + BMCR_SPEED100, mscr2_ctl); + if (err < 0) + return err; - if (!err) { - /* It takes some time for PHY device to switch - * into/out-of loopback mode. - */ - msleep(1000); - } + /* Need soft reset to have speed configuration takes effect */ + err = genphy_soft_reset(phydev); + if (err < 0) return err; - } else { - err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0); - if (err < 0) - return err; - return phy_config_aneg(phydev); + err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, + BMCR_LOOPBACK); + + if (!err) { + /* + * It takes some time for PHY device to switch into loopback + * mode. + */ + msleep(1000); } + return err; } static int marvell_vct5_wait_complete(struct phy_device *phydev) From patchwork Fri Jan 24 22:05:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13949969 X-Patchwork-Delegate: kuba@kernel.org Received: from mx10lb.world4you.com (mx10lb.world4you.com [81.19.149.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4D701E9913 for ; Fri, 24 Jan 2025 22:05:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756343; cv=none; b=a2zqEdX6OzJ0d8L/MUY/sWwBF2OwDtcT5LrCZ6wY+sVQPJcaxO6K/PkC833aSC6WSDOVlNHxnNyIeT1yQr2KNbP4JtdyrYdFTgns2FyJiBNXXSWUwAntDq8nyWKqq6fUeZ2z8bCL4eUNdal9EjfrUnhEiIzX+hByuU3mSJONJQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756343; c=relaxed/simple; bh=3o17YmOzA7WR7Cr0v92ZJBUQStTL8kr2ScupHii+TQo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FFTYSQ1/qJsT0QcISFQImWMa/L+rM0L+or4qmdxDA8iyQpTiLsQJ5ioFbKhle8Y+5IyPdoyd6s78YKaSXE50PWcNUTLnd1Mvr3/t/+qIKz18fabYLeeZTRZFjHDHBJblInlnFEfDDVEXK4+mLlHZKaJkCVWHQRvoWYDRARhrw64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=f6Xf042/; arc=none smtp.client-ip=81.19.149.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="f6Xf042/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ze69fUJSKANAoIvDAXRHBxnEpe6Ys/LNFmN7SGuZ7B8=; b=f6Xf042/6miOGnRgiFowEXnIZn G5RdV6aVCFf0fm69oxWR6r0AOTNvugFlnCyqjbHi/bfZAlXc+ZIi4ne/oDSCJ1njBqF6VOlBee3DH 4ay/e73MLKPNXcDYlYRlPjGaImhHBIX5AwmhnzbcpV911air1mzaPvoOTbPPMHfF3Qjk=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx10lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tbRo2-000000005Ng-0Ybn; Fri, 24 Jan 2025 23:05:38 +0100 From: Gerhard Engleder To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next v3 5/7] tsnep: Select speed for loopback Date: Fri, 24 Jan 2025 23:05:14 +0100 Message-Id: <20250124220516.113798-6-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250124220516.113798-1-gerhard@engleder-embedded.com> References: <20250124220516.113798-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use 100 Mbps only if the PHY is configured to this speed. Otherwise use always the maximum speed of 1000 Mbps. Also remove explicit setting of carrier on and link mode after loopback. This is not needed anymore, because phy_loopback() with selected speed signals the link and the speed to the MAC. Signed-off-by: Gerhard Engleder --- drivers/net/ethernet/engleder/tsnep_main.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/engleder/tsnep_main.c b/drivers/net/ethernet/engleder/tsnep_main.c index a16b12137edb..d77a5b423c4c 100644 --- a/drivers/net/ethernet/engleder/tsnep_main.c +++ b/drivers/net/ethernet/engleder/tsnep_main.c @@ -228,20 +228,19 @@ static void tsnep_phy_link_status_change(struct net_device *netdev) static int tsnep_phy_loopback(struct tsnep_adapter *adapter, bool enable) { - int retval; - - retval = phy_loopback(adapter->phydev, enable, 0); + int speed; - /* PHY link state change is not signaled if loopback is enabled, it - * would delay a working loopback anyway, let's ensure that loopback - * is working immediately by setting link mode directly - */ - if (!retval && enable) { - netif_carrier_on(adapter->netdev); - tsnep_set_link_mode(adapter); + if (enable) { + if (adapter->phydev->autoneg == AUTONEG_DISABLE && + adapter->phydev->speed == SPEED_100) + speed = SPEED_100; + else + speed = SPEED_1000; + } else { + speed = 0; } - return retval; + return phy_loopback(adapter->phydev, enable, speed); } static int tsnep_phy_open(struct tsnep_adapter *adapter) From patchwork Fri Jan 24 22:05:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13949970 X-Patchwork-Delegate: kuba@kernel.org Received: from mx10lb.world4you.com (mx10lb.world4you.com [81.19.149.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4161B1EEA28 for ; Fri, 24 Jan 2025 22:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756346; cv=none; b=uvNsoswpJXOzDoc5gN01njLSh+TiTPJER4mx7y1sg3EacoXJupqZTOcVznUCeL+hIdcwaZtbo2zPa7C7lpculphG4IC7p+SQ96vwzmIaBK7bFLtRd6mqN+rEGtGTdmwlM/Hr7D5mykf0++/2Do1i2iyFR26KxYH+nfVuHM3Pwuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756346; c=relaxed/simple; bh=dfQP0WoauTKb6Py4vcA/XMasi9saWi6X8ysSGiKYQFE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s248ANkuCrRo+m7LNtQV8/rSFXI4EE7S76JMXOFYr/vjJEoXSUurzJ8eonNZvVL5aKBG5+pHiEKuMRZn06AncOT1vV1DByYuqD+VIUbW/wX8DCT2X5oIUYxSV8uUpPAYRpGDEg6XC3sbmFmq1c/cRFGpAoSBV2qS5g4jc8884x8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=TirayajO; arc=none smtp.client-ip=81.19.149.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="TirayajO" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MPpfoW73ud7QEvlwLua4h4ohdG+Bz8uoUYyGfb35tvM=; b=TirayajOP+NDxzOovgqTGAzAAz m41BH4GLYIyptrXRujJDIelm8z7YlmymMgdGKrpTQ37d6iptaouzw/JOWq/JUZ9Xvz+l6w5cZT3eH UCPVY8Vt89HMGbubSMEAD7ZLjgusjUGU2od5jF+UYUae91TVcVnpqVhnKnGOXtsArnQE=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx10lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tbRo5-000000005Ng-1VsY; Fri, 24 Jan 2025 23:05:41 +0100 From: Gerhard Engleder To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, Gerhard Engleder , Oleksij Rempel Subject: [RFC PATCH net-next v3 6/7] net: selftests: Export net_test_phy_loopback_* Date: Fri, 24 Jan 2025 23:05:15 +0100 Message-Id: <20250124220516.113798-7-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250124220516.113798-1-gerhard@engleder-embedded.com> References: <20250124220516.113798-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC net_selftests() provides a generic set of selftests for netdevs with PHY. Those selftests rely on an existing link to inherit the speed for the loopback mode. net_selftests() is not designed to extend existing selftests of drivers, but with net_test_phy_loopback_* it contains useful test infrastructure. Export net_test_phy_loopback_* to enable reuse in existing selftests of other drivers. This also enables driver specific loopback modes, which don't rely on an existing link. Signed-off-by: Gerhard Engleder CC: Oleksij Rempel --- include/net/selftests.h | 19 +++++++++++++++++++ net/core/selftests.c | 9 ++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/net/selftests.h b/include/net/selftests.h index e65e8d230d33..38459af4962b 100644 --- a/include/net/selftests.h +++ b/include/net/selftests.h @@ -6,6 +6,10 @@ #if IS_ENABLED(CONFIG_NET_SELFTESTS) +int net_test_phy_loopback_udp(struct net_device *ndev); +int net_test_phy_loopback_udp_mtu(struct net_device *ndev); +int net_test_phy_loopback_tcp(struct net_device *ndev); + void net_selftest(struct net_device *ndev, struct ethtool_test *etest, u64 *buf); int net_selftest_get_count(void); @@ -13,6 +17,21 @@ void net_selftest_get_strings(u8 *data); #else +static inline int net_test_phy_loopback_udp(struct net_device *ndev) +{ + return 0; +} + +static int net_test_phy_loopback_udp_mtu(struct net_device *ndev) +{ + return 0; +} + +static int net_test_phy_loopback_tcp(struct net_device *ndev) +{ + return 0; +} + static inline void net_selftest(struct net_device *ndev, struct ethtool_test *etest, u64 *buf) { diff --git a/net/core/selftests.c b/net/core/selftests.c index e99ae983fca9..d4e0e2eff991 100644 --- a/net/core/selftests.c +++ b/net/core/selftests.c @@ -310,15 +310,16 @@ static int net_test_phy_loopback_disable(struct net_device *ndev) return phy_loopback(ndev->phydev, false, 0); } -static int net_test_phy_loopback_udp(struct net_device *ndev) +int net_test_phy_loopback_udp(struct net_device *ndev) { struct net_packet_attrs attr = { }; attr.dst = ndev->dev_addr; return __net_test_loopback(ndev, &attr); } +EXPORT_SYMBOL_GPL(net_test_phy_loopback_udp); -static int net_test_phy_loopback_udp_mtu(struct net_device *ndev) +int net_test_phy_loopback_udp_mtu(struct net_device *ndev) { struct net_packet_attrs attr = { }; @@ -326,8 +327,9 @@ static int net_test_phy_loopback_udp_mtu(struct net_device *ndev) attr.max_size = ndev->mtu; return __net_test_loopback(ndev, &attr); } +EXPORT_SYMBOL_GPL(net_test_phy_loopback_udp_mtu); -static int net_test_phy_loopback_tcp(struct net_device *ndev) +int net_test_phy_loopback_tcp(struct net_device *ndev) { struct net_packet_attrs attr = { }; @@ -335,6 +337,7 @@ static int net_test_phy_loopback_tcp(struct net_device *ndev) attr.tcp = true; return __net_test_loopback(ndev, &attr); } +EXPORT_SYMBOL_GPL(net_test_phy_loopback_tcp); static const struct net_test { char name[ETH_GSTRING_LEN]; From patchwork Fri Jan 24 22:05:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13949971 X-Patchwork-Delegate: kuba@kernel.org Received: from mx10lb.world4you.com (mx10lb.world4you.com [81.19.149.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 638881EEA2D for ; Fri, 24 Jan 2025 22:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.120 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756349; cv=none; b=b5R5EbD4FkBbwGIczb9h0Xnfz2HFzNxANho25XQbmXO5uTLBihB4CsjX0HSzdDtL52Hgjg9s6cK5NUPJy5elUku0CzOgjLOQFsKYVTcuA1fCn+W7rKaFjfnaP1TEu/blIlIKDkiD10B/s2qCSzD+g1pHgvENRlwwrSHP1K1NDzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737756349; c=relaxed/simple; bh=vS4sQVfb16y9DLPEwlNhNIiEXXsLUpY2oHAQ+Oa7gG4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LvhxymrEM7iVEWEPtb0kXD9EaJvk9QZDAJCePFTftio32hceQaBkbYV74oIXz4wUcDd11TqJCj4xu2+AGFRxM1/AstY+kgACYki9Nk1LyLwwgZe0ufoF4pe/rF7Hk8wqnt17OFu/sF931pR3P8Z8dP2XFzOMzxDDCyHAJ8nJEyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com; spf=pass smtp.mailfrom=engleder-embedded.com; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b=C8g5GiW1; arc=none smtp.client-ip=81.19.149.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=engleder-embedded.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=engleder-embedded.com header.i=@engleder-embedded.com header.b="C8g5GiW1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=engleder-embedded.com; s=dkim11; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=2D5GiUUykY89hChn3aAP5ndnXdPq65QEBMcFLEpBzdc=; b=C8g5GiW1hofohvQzbqPN+IVCKG ydPFtheRD2lJ+JueM0HQTcW/tq1dz7SeNgRJ+Dyc2LFh2Hv5+64OO+RCu7Ts9lVE8HvQZNeb17Z/+ IEX+zJM8TVFBjpXHRnaL5fnnD4S0hHodX3qlIwjOz2f3Mci66aIuRXysCz5tluaEOKow=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx10lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tbRo7-000000005Ng-2xit; Fri, 24 Jan 2025 23:05:43 +0100 From: Gerhard Engleder To: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, Gerhard Engleder Subject: [RFC PATCH net-next v3 7/7] tsnep: Add PHY loopback selftests Date: Fri, 24 Jan 2025 23:05:16 +0100 Message-Id: <20250124220516.113798-8-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250124220516.113798-1-gerhard@engleder-embedded.com> References: <20250124220516.113798-1-gerhard@engleder-embedded.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-AV-Do-Run: Yes X-ACL-Warn: X-W4Y-Internal X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add loopback selftests on PHY level. This enables quick testing of loopback functionality to ensure working loopback for testing. Signed-off-by: Gerhard Engleder --- drivers/net/ethernet/engleder/Kconfig | 1 + .../net/ethernet/engleder/tsnep_selftests.c | 153 +++++++++++++++++- 2 files changed, 150 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/engleder/Kconfig b/drivers/net/ethernet/engleder/Kconfig index 3df6bf476ae7..8245a9c4377d 100644 --- a/drivers/net/ethernet/engleder/Kconfig +++ b/drivers/net/ethernet/engleder/Kconfig @@ -32,6 +32,7 @@ config TSNEP_SELFTESTS bool "TSN endpoint self test support" default n depends on TSNEP + imply NET_SELFTESTS help This enables self test support within the TSN endpoint driver. diff --git a/drivers/net/ethernet/engleder/tsnep_selftests.c b/drivers/net/ethernet/engleder/tsnep_selftests.c index 8a9145f93147..c9857e5a8033 100644 --- a/drivers/net/ethernet/engleder/tsnep_selftests.c +++ b/drivers/net/ethernet/engleder/tsnep_selftests.c @@ -4,12 +4,15 @@ #include "tsnep.h" #include +#include enum tsnep_test { TSNEP_TEST_ENABLE = 0, TSNEP_TEST_TAPRIO, TSNEP_TEST_TAPRIO_CHANGE, TSNEP_TEST_TAPRIO_EXTENSION, + TSNEP_TEST_PHY_1000_LOOPBACK, + TSNEP_TEST_PHY_100_LOOPBACK, }; static const char tsnep_test_strings[][ETH_GSTRING_LEN] = { @@ -17,6 +20,8 @@ static const char tsnep_test_strings[][ETH_GSTRING_LEN] = { "TAPRIO (offline)", "TAPRIO change (offline)", "TAPRIO extension (offline)", + "PHY 1000Mbps loopback (offline)", + "PHY 100Mbps loopback (offline)", }; #define TSNEP_TEST_COUNT (sizeof(tsnep_test_strings) / ETH_GSTRING_LEN) @@ -754,6 +759,133 @@ static bool tsnep_test_taprio_extension(struct tsnep_adapter *adapter) return false; } +static bool test_loopback(struct tsnep_adapter *adapter, int speed) +{ + struct phy_device *phydev = adapter->phydev; + int retval; + + retval = phy_loopback(phydev, true, speed); + if (retval || !phydev->loopback_enabled || !phydev->link || + phydev->speed != speed) + return false; + + retval = net_test_phy_loopback_udp(adapter->netdev); + if (retval) + return false; + + retval = net_test_phy_loopback_udp_mtu(adapter->netdev); + if (retval) + return false; + + retval = net_test_phy_loopback_tcp(adapter->netdev); + if (retval) + return false; + + retval = phy_loopback(phydev, false, 0); + if (retval || phydev->loopback_enabled) + return false; + + return true; +} + +static bool set_speed(struct tsnep_adapter *adapter, int speed) +{ + struct ethtool_link_ksettings cmd; + int retval; + + retval = tsnep_ethtool_ops.get_link_ksettings(adapter->netdev, &cmd); + if (retval) + return false; + + if (speed) { + cmd.base.speed = speed; + cmd.base.duplex = DUPLEX_FULL; + cmd.base.autoneg = AUTONEG_DISABLE; + } else { + cmd.base.autoneg = AUTONEG_ENABLE; + } + + retval = tsnep_ethtool_ops.set_link_ksettings(adapter->netdev, &cmd); + if (retval) + return false; + + return true; +} + +static bool tsnep_test_phy_1000_loopback(struct tsnep_adapter *adapter) +{ + if (!adapter->netdev->phydev) + return false; + + if (!test_loopback(adapter, 1000)) + goto failed; + + /* after autonegotiation */ + if (!set_speed(adapter, 0)) + goto failed; + if (!test_loopback(adapter, 1000)) + goto failed; + + /* after 100Mbps fixed speed */ + if (!set_speed(adapter, 100)) + goto failed; + if (!test_loopback(adapter, 1000)) + goto failed; + + /* after 1000Mbps fixed speed */ + if (!set_speed(adapter, 1000)) + goto failed; + if (!test_loopback(adapter, 1000)) + goto failed; + + if (!set_speed(adapter, 0)) + goto failed; + + return true; + +failed: + phy_loopback(adapter->phydev, false, 0); + set_speed(adapter, 0); + return false; +} + +static bool tsnep_test_phy_100_loopback(struct tsnep_adapter *adapter) +{ + if (!adapter->netdev->phydev) + return false; + + if (!test_loopback(adapter, 100)) + goto failed; + + /* after autonegotiation */ + if (!set_speed(adapter, 0)) + goto failed; + if (!test_loopback(adapter, 100)) + goto failed; + + /* 100Mbps fixed speed */ + if (!set_speed(adapter, 100)) + goto failed; + if (!test_loopback(adapter, 100)) + goto failed; + + /* 1000Mbps fixed speed */ + if (!set_speed(adapter, 1000)) + goto failed; + if (!test_loopback(adapter, 100)) + goto failed; + + if (!set_speed(adapter, 0)) + goto failed; + + return true; + +failed: + phy_loopback(adapter->phydev, false, 0); + set_speed(adapter, 0); + return false; +} + int tsnep_ethtool_get_test_count(void) { return TSNEP_TEST_COUNT; @@ -768,15 +900,14 @@ void tsnep_ethtool_self_test(struct net_device *netdev, struct ethtool_test *eth_test, u64 *data) { struct tsnep_adapter *adapter = netdev_priv(netdev); + int i; eth_test->len = TSNEP_TEST_COUNT; if (eth_test->flags != ETH_TEST_FL_OFFLINE) { /* no tests are done online */ - data[TSNEP_TEST_ENABLE] = 0; - data[TSNEP_TEST_TAPRIO] = 0; - data[TSNEP_TEST_TAPRIO_CHANGE] = 0; - data[TSNEP_TEST_TAPRIO_EXTENSION] = 0; + for (i = 0; i < TSNEP_TEST_COUNT; i++) + data[i] = 0; return; } @@ -808,4 +939,18 @@ void tsnep_ethtool_self_test(struct net_device *netdev, eth_test->flags |= ETH_TEST_FL_FAILED; data[TSNEP_TEST_TAPRIO_EXTENSION] = 1; } + + if (tsnep_test_phy_1000_loopback(adapter)) { + data[TSNEP_TEST_PHY_1000_LOOPBACK] = 0; + } else { + eth_test->flags |= ETH_TEST_FL_FAILED; + data[TSNEP_TEST_PHY_1000_LOOPBACK] = 1; + } + + if (tsnep_test_phy_100_loopback(adapter)) { + data[TSNEP_TEST_PHY_100_LOOPBACK] = 0; + } else { + eth_test->flags |= ETH_TEST_FL_FAILED; + data[TSNEP_TEST_PHY_100_LOOPBACK] = 1; + } }