From patchwork Fri Jan 10 14:48:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13935101 X-Patchwork-Delegate: kuba@kernel.org Received: from mx18lb.world4you.com (mx18lb.world4you.com [81.19.149.128]) (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 653AC20A5FB for ; Fri, 10 Jan 2025 15:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.128 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736524754; cv=none; b=mjDwQdiEc0mLcqcKNe2QF69SRaGX8cDJXOhsJNBbkAH3UEpU3mU+9iu9tpI7rlh5KC7SjFxXtLyJPNKzN9WZHhVtO5+3pYCzXqka88+rTGPS1rnPhroWa3I/xlsJuyFikzpoUn5yDkY3RIZQZVRZoGsymA728kkyWGgTVgU8anA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736524754; c=relaxed/simple; bh=zw42o0v43lIyeYFOEDbXhPjbJBlTtXfAPtAXlAGPVl0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=k6vaxiOisXu7dTUXnqNaZDGlBJc1rYSUvaBeLfTxwcIAw0ao2sAZA9JXyDzTh2sQCeucDx5ngdwCzPuAeSzEsJUqe6hC/Jfp4Yo9HSfqvf504hriIb74srQEgsC00XySmoANVfAj2h7qlTxvFgDH3ssbqcQ+CfK2VpiRsVLkMhk= 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=m2CoqN0x; arc=none smtp.client-ip=81.19.149.128 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="m2CoqN0x" 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=06TjeaZB0/3C5wmvjNENTmji5WjR+pykPnVfI8HiptA=; b=m2CoqN0xrU/vOtRJVb4hAo+Qnn LsN7f/qg0yS1CLLR18H9Nik/vKEUDzM0xVOOQFywgfInZoWPwrdDJiVh2hgdixeLu/4xUIwP8pEQ4 Kx/GxFlNtoavIYlotJ6APEnB6hXpvYVCu4/CTBI20Rwt2l0S384lYGJPtT4so6OAgesk=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx18lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tWGJX-000000006oP-2YRb; Fri, 10 Jan 2025 15:48: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: [PATCH net-next v2 1/5] net: phy: Allow loopback speed selection for PHY drivers Date: Fri, 10 Jan 2025 15:48:24 +0100 Message-Id: <20250110144828.4943-2-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110144828.4943-1-gerhard@engleder-embedded.com> References: <20250110144828.4943-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 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 85f910e2d4fb..dd8cce925668 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 4120385c5a79..b10ad482d566 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 ffe223ad9e5f..1b7b2cb792b4 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 a8ccf257c109..e4cfabb308a6 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 bdc997f59779..f3b3781e7baa 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 5bc71d59910c..7d460e53cadf 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1160,8 +1160,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 */ @@ -1961,7 +1969,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); @@ -2003,7 +2011,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 10 14:48:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13935075 X-Patchwork-Delegate: kuba@kernel.org Received: from mx18lb.world4you.com (mx18lb.world4you.com [81.19.149.128]) (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 807A820E715 for ; Fri, 10 Jan 2025 15:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.128 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736524351; cv=none; b=m9RAroN0T7UEhPOSiJGAb94wDH3RWAD4PfLLKhzJcg3COeXUmtR5nKbS1WQCylk6IjTPhyCx+mmib7KXi7wnKMYuof8ftH89sXiQ/50atCk2vK8uAlDGowqlk9z4wf3XIi/kizDQhzeNJkKXLMFYq2NgU+C3ARyT3GVQqitiIok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736524351; c=relaxed/simple; bh=vz4+tupHz3qWEbPutlvtVU4EdxD8RN+0UKicvCEvkQ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oEajAM2qlwQdOMkbxH3OPceNbluuxY4egDyPLHPVwLAWSEdfd6DMY9KsyGUNbawjO4IwK4OV2PkhkJxyXy4hUjRIYb6FiOFQJuE0V976WLH7z74rgj1hiE+DmSYDMi9y8fRxNqmnmMavLm1BXrFbU2gdggCR0SChTRI7lroLho4= 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=G0OZOtOz; arc=none smtp.client-ip=81.19.149.128 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="G0OZOtOz" 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=1lIq9HM9HDdXJwUlCTUsFgqjvznxcTRBQ1sDdVc5n8c=; b=G0OZOtOzItqpeGzldGYRerEwhN +TxMs+XwRjF7yyBACV+8usFHK6Rk4EjkaHoCwGkOAMTZNWU6OEtLOHpyP1dOvQBzBNJg/XJO71qp+ /z7PlRICi8HkVuKAiT90h1CBoH3m+4cuZmCR+LKC7jaF/kGrQTsHyBlnG8U5SHDHPnxs=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx18lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tWGJZ-000000006oP-23yo; Fri, 10 Jan 2025 15:48:45 +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: [PATCH net-next v2 2/5] net: phy: Support speed selection for PHY loopback Date: Fri, 10 Jan 2025 15:48:25 +0100 Message-Id: <20250110144828.4943-3-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110144828.4943-1-gerhard@engleder-embedded.com> References: <20250110144828.4943-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 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 | 79 +++++++++++++++++++ drivers/net/phy/phy_device.c | 35 -------- include/linux/phy.h | 2 +- net/core/selftests.c | 4 +- 9 files changed, 92 insertions(+), 48 deletions(-) diff --git a/drivers/net/ethernet/engleder/tsnep_main.c b/drivers/net/ethernet/engleder/tsnep_main.c index e4ce8575ff76..5c501e4f9e3e 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 05942fa78b11..b2ac1a9aa426 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c @@ -7849,7 +7849,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, @@ -7857,7 +7857,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 e4b04cdaa995..06b9a7455908 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1640,6 +1640,85 @@ 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; + + /* update PHY state */ + flush_delayed_work(&phydev->state_queue); + + 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_init_eee - init and check the EEE feature * @phydev: target phy_device struct diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index f3b3781e7baa..f6c98affc867 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 7d460e53cadf..47aaabfd5f40 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1854,7 +1854,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 10 14:48:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13935074 X-Patchwork-Delegate: kuba@kernel.org Received: from mx18lb.world4you.com (mx18lb.world4you.com [81.19.149.128]) (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 27D0021018D for ; Fri, 10 Jan 2025 15:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.128 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736524218; cv=none; b=TK9v8YsfAhLdzvcEdknZMMrxao8uL9pYWlpmNhiQAdwO6rsj0WnT5kitypVkyCqC3GqnYoC1E3Q2PCYmyC1lOkqkoHJ9D7c5lJMEWLG61ikV5Ctmf2g2ZaZD5crsC6S5LS+mkz9UDVgO+b1XP4oBp2plGQrMG+dh6yqUk02fvgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736524218; c=relaxed/simple; bh=DSsW3vrm0aYSEVzZsqYe16f8khyyQpSVAk08r3ZuTCY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rwqx+3+lzVbOAviNkAz1D+5TtxJQ3dVRiTKNyhkI8kh+eqlbUXEOIFJcC/UUpD2l3D33E79Dh/uFHa7nApAbFYAeVwG2P6kgSliue6Ubpr1BsWjEj3/l2WbIrP+sl2cddMOVPb3bFkrowRU6OnkmXoTv857rOuM9nR3XGbDg9xU= 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=QSXJjmt6; arc=none smtp.client-ip=81.19.149.128 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="QSXJjmt6" 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=Swyt6ce3R2DPW0msbNHf2SwxBBxz7FeCeQXxpm6euP8=; b=QSXJjmt6f3pIsIChmujYpekByI X2jrjMek4q2bhdzI7BrU254R2RegmVBs3opFpB+ply0UyLluuBxaDOHsguDZvtHfDJFtKVUbo9INl MRfQjS+pgWOkIRgOi2t8CeKMG2KWMDG3vfnqUTZqYdllCaPKLRX3GbQBIJpbsj/MailI=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx18lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tWGJb-000000006oP-0Z46; Fri, 10 Jan 2025 15:48:47 +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: [PATCH net-next v2 3/5] net: phy: micrel: Add loopback support Date: Fri, 10 Jan 2025 15:48:26 +0100 Message-Id: <20250110144828.4943-4-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110144828.4943-1-gerhard@engleder-embedded.com> References: <20250110144828.4943-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 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 eeb33eb181ac..bf7d601f8ab0 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 10 14:48:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13934783 X-Patchwork-Delegate: kuba@kernel.org Received: from mx18lb.world4you.com (mx18lb.world4you.com [81.19.149.128]) (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 19406211464 for ; Fri, 10 Jan 2025 14:48:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.128 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736520533; cv=none; b=tH/ggNSVX7j4XFy7w6FSt11/ecuFFjkHAEPhF99o5jJ5qChWx1KRck1kg+7P/UEL6CL1x+4w1uROLvTunkUoc3D3NkeLq486VcKhaJawggnifGtbcHCCJ2LJLi+c0bxgwJ6MW6kS5Ys42GJJNUDWI8U/1oQCFKg7YjG0r0r6Uc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736520533; c=relaxed/simple; bh=mcXzb1go+vbgLR6N1Q5XbVtquExUot5h4o/0jh7/Jjw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y2suLf27gPmNCj7JBbhF0aj0cuAkVdFqwcYyNdLmX6xDdnbanFwNmXTukdFFn6VVmGlAaHHWIQgIqCzYGYGLRojDo328A6Zyo7FgL8kpQGASmvyIBLGhlm/ig/78ft4QLahf5hsURXk7ASNVldVwoLI8qvBD3UXvRgDKn3tzCNk= 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=Rq7pdy/O; arc=none smtp.client-ip=81.19.149.128 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="Rq7pdy/O" 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=gSlvKuY0FEC4Nr9uEiEPuKjaqvh7m3V2qy8cgmrwRLI=; b=Rq7pdy/OtkBL4N29D3hBXQOEQp oPL+ZKBVre1czVgd1KV14XGWzMg8Da48fQjkr7xO2SiN82T1aUYZUwEROMFmJe+sDrXs+1AGFIuhO okmGmmGMt/oCa5wKnLjR8xDP9XcfSeVc593uG8j7DeJrdzwRpnQdTdnXfHcy6sJok14w=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx18lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tWGJc-000000006oP-33bT; Fri, 10 Jan 2025 15:48:48 +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: [PATCH net-next v2 4/5] tsnep: Select speed for loopback Date: Fri, 10 Jan 2025 15:48:27 +0100 Message-Id: <20250110144828.4943-5-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110144828.4943-1-gerhard@engleder-embedded.com> References: <20250110144828.4943-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 Use 100 Mbps only if the PHY is configured to this speed. Otherwise use always the maximum speed of 1000 Mbps. Signed-off-by: Gerhard Engleder --- drivers/net/ethernet/engleder/tsnep_main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/engleder/tsnep_main.c b/drivers/net/ethernet/engleder/tsnep_main.c index 5c501e4f9e3e..45b9f5780902 100644 --- a/drivers/net/ethernet/engleder/tsnep_main.c +++ b/drivers/net/ethernet/engleder/tsnep_main.c @@ -229,8 +229,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; + int speed; - retval = phy_loopback(adapter->phydev, enable, 0); + if (enable) { + if (adapter->phydev->autoneg == AUTONEG_DISABLE && + adapter->phydev->speed == SPEED_100) + speed = SPEED_100; + else + speed = SPEED_1000; + } else { + speed = 0; + } + + retval = phy_loopback(adapter->phydev, enable, speed); /* PHY link state change is not signaled if loopback is enabled, it * would delay a working loopback anyway, let's ensure that loopback From patchwork Fri Jan 10 14:48:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Engleder X-Patchwork-Id: 13934784 X-Patchwork-Delegate: kuba@kernel.org Received: from mx18lb.world4you.com (mx18lb.world4you.com [81.19.149.128]) (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 76E382116FA for ; Fri, 10 Jan 2025 14:48:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=81.19.149.128 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736520536; cv=none; b=JDpCHbXWvZa9+xSugNxnRA93G6kjNBPjxhv4F1SsSfTXM3blPaEjCFag7T2/kFpARN6lqG5j4tBKskOHa44XeofhBreqVEZodUlbdKxCFr3oyRfa/y4s1M16YAC2yTz8UvQlNbkflU1W7ycig5cShXjyZqiIH/Xm8xPyRStajvM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736520536; c=relaxed/simple; bh=RP4iAOMiYWPmZfvfi6JYM5Rulo7FN1lLtRDLhDzde+E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KhazEDzcyPo//tTS7fuh9xnLgLE3feOTC8G7Q0xlEr39dDZnkDIT7Jbt5axLm4RwoNsw5Rjsyod0NNbbC7MtSMg/x4rwJsE2R1Qg0cP6ej4t+0OnLL9f4R0WdwuLMfOqbCd0BS3w5ZuiqPGS1HuCIDVHzvfkuBNun/LqS97Iivg= 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=NhZLACGx; arc=none smtp.client-ip=81.19.149.128 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="NhZLACGx" 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=qiXKnp0/R+VzL4hPDH8IkATHqdh0qsfStNlOsPcKIRU=; b=NhZLACGx73zd1dSQ5+MF8Dgnc9 +GS/TFsZarABSUsM6T7qzRK6eiFkY0MHkLuxnidXKMP/w8J0NQ5gndz//BgZfCsv6xqijO1QfcKaO WRM6RMSDUQqDEvy6C6TGsySD1AzhNpig9RBLAtb8Dw8p3wXXhgbFzoHZIMY6ZLEfKzgY=; Received: from 88-117-60-28.adsl.highway.telekom.at ([88.117.60.28] helo=hornet.engleder.at) by mx18lb.world4you.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1tWGJe-000000006oP-3EN2; Fri, 10 Jan 2025 15:48:50 +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: [PATCH net-next v2 5/5] tsnep: Add PHY loopback selftests Date: Fri, 10 Jan 2025 15:48:28 +0100 Message-Id: <20250110144828.4943-6-gerhard@engleder-embedded.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250110144828.4943-1-gerhard@engleder-embedded.com> References: <20250110144828.4943-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 Add loopback selftests on PHY level. This enables quick testing of loopback functionality to ensure working loopback for testing. Signed-off-by: Gerhard Engleder --- .../net/ethernet/engleder/tsnep_selftests.c | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/net/ethernet/engleder/tsnep_selftests.c b/drivers/net/ethernet/engleder/tsnep_selftests.c index 8a9145f93147..0a3f92ac35cd 100644 --- a/drivers/net/ethernet/engleder/tsnep_selftests.c +++ b/drivers/net/ethernet/engleder/tsnep_selftests.c @@ -10,6 +10,7 @@ enum tsnep_test { TSNEP_TEST_TAPRIO, TSNEP_TEST_TAPRIO_CHANGE, TSNEP_TEST_TAPRIO_EXTENSION, + TSNEP_TEST_PHY_LOOPBACK, }; static const char tsnep_test_strings[][ETH_GSTRING_LEN] = { @@ -17,6 +18,7 @@ static const char tsnep_test_strings[][ETH_GSTRING_LEN] = { "TAPRIO (offline)", "TAPRIO change (offline)", "TAPRIO extension (offline)", + "PHY loopback (offline)", }; #define TSNEP_TEST_COUNT (sizeof(tsnep_test_strings) / ETH_GSTRING_LEN) @@ -754,6 +756,98 @@ static bool tsnep_test_taprio_extension(struct tsnep_adapter *adapter) return false; } +static bool 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 = 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_loopback(struct tsnep_adapter *adapter) +{ + /* 1000Mbps loopback */ + if (!loopback(adapter, 1000)) + goto failed; + + /* 100Mbps loopback */ + if (!loopback(adapter, 100)) + goto failed; + + /* 1000Mbps loopback after autonegotiation */ + if (!set_speed(adapter, 0)) + goto failed; + if (!loopback(adapter, 1000)) + goto failed; + + /* 100Mbps loopback after autonegotiation */ + if (!set_speed(adapter, 0)) + goto failed; + if (!loopback(adapter, 100)) + goto failed; + + /* 1000Mbps loopback after 100Mbps fixed speed */ + if (!set_speed(adapter, 0)) + goto failed; + if (!loopback(adapter, 1000)) + goto failed; + + /* 100Mbps loopback after 100Mbps fixed speed */ + if (!set_speed(adapter, 0)) + goto failed; + if (!loopback(adapter, 100)) + goto failed; + + /* 1000Mbps loopback after 1000Mbps fixed speed */ + if (!set_speed(adapter, 0)) + goto failed; + if (!loopback(adapter, 1000)) + goto failed; + + /* 100Mbps loopback after 1000Mbps fixed speed */ + if (!set_speed(adapter, 0)) + goto failed; + if (!loopback(adapter, 100)) + goto failed; + + return true; + +failed: + phy_loopback(adapter->phydev, false, 0); + return false; +} + int tsnep_ethtool_get_test_count(void) { return TSNEP_TEST_COUNT; @@ -777,6 +871,7 @@ void tsnep_ethtool_self_test(struct net_device *netdev, data[TSNEP_TEST_TAPRIO] = 0; data[TSNEP_TEST_TAPRIO_CHANGE] = 0; data[TSNEP_TEST_TAPRIO_EXTENSION] = 0; + data[TSNEP_TEST_PHY_LOOPBACK] = 0; return; } @@ -808,4 +903,11 @@ 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_loopback(adapter)) { + data[TSNEP_TEST_PHY_LOOPBACK] = 0; + } else { + eth_test->flags |= ETH_TEST_FL_FAILED; + data[TSNEP_TEST_PHY_LOOPBACK] = 1; + } }