From patchwork Wed Sep 11 21:27:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EC695EE57D7 for ; Wed, 11 Sep 2024 21:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8rqeH8IixeEEWajyVevr1Htj2CPvSE4kTjgluMfWNRM=; b=xNS00jUS6oQQhW2UArMB3tcfYf RP8Aa8ORRIRHBfSs3WUrWRLaQl+apTm7LGF8F1kvHDeUd2A5pWkr53Q/b9BiZ0q14CSRbv2KB/l3s 6lTTIT/L0g5PsN0yGYQVzjEy2FEdaN/iiJWLs0NdNqiZNxgegk38EYyDQeJU1Vs0J8hY+wJoCB1Nc sU1fKbXHxmTipuTUrbC7cJ7VABFJP/AZcmDBhVP5IyOsZ6PsC7FjwH3XhNHhjxN0lW5A4/l/5y1IA VnOVBOeZsT1lqKi+KfdsM9fAiT8vozhRytgnotBSWe0AawB69BHRqIUn3zCA2lk/U8s1E0a6ipZRx lUjS2Cww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUu2-0000000B3i1-20N8; Wed, 11 Sep 2024 21:29:30 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUrw-0000000B3Bb-1CO4 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:22 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 279D81C0005; Wed, 11 Sep 2024 21:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8rqeH8IixeEEWajyVevr1Htj2CPvSE4kTjgluMfWNRM=; b=gaHkeb+X0hYdtP+OMqx1viofufMrfCd8Zbtxg2hs15VCuqSBbdVlcZUnJBFYEHHUSy6HhT 88zFlZlTAw12gpqc676LuBGIBYvyrSehYZ11M7cDOuq44xrS7vKkcbqgTtUG1KjqOqIsN0 EiUP5OxaDSmA40hH/HGcSjlbnACW8nwqM7sBqrGN0anoXIEJXVfE4VGQUDoACNAAWH1hOn FwCriRIENAxX7OHMqA8610qLX/ZL5cHFGZKp3EiOOF5vZXbmmPe09ft9JkN38WWkFqoF9j WA8+8Hb3XqnJPHrtrpLRqfBz/5rMmwoebV2lSiUQ86xpMZ7clEbcazqulxAMSA== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 1/7] net: phy: allow isolating PHY devices Date: Wed, 11 Sep 2024 23:27:05 +0200 Message-ID: <20240911212713.2178943-2-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_142720_876953_18ACD3B4 X-CRM114-Status: GOOD ( 20.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The 802.3 specifications describes the isolation mode as setting the PHY's MII interface in high-impedance mode, thus isolating the PHY from that bus. This effectively breaks the link between the MAC and the PHY, but without necessarily disrupting the link between the PHY and the LP. This mode can be useful for testing purposes, but also when there are multiple PHYs on the same MII bus (a case that the 802.3 specification refers to). In Isolation mode, the PHY will still continue to respond to MDIO commands. Introduce a helper to set the phy in an isolated mode. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 76 +++++++++++++++++++++++++++++++++--- include/linux/phy.h | 4 ++ 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 560e338b307a..c468e72bef4b 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2127,6 +2127,38 @@ int phy_loopback(struct phy_device *phydev, bool enable) } EXPORT_SYMBOL(phy_loopback); +int phy_isolate(struct phy_device *phydev, bool enable) +{ + int ret = 0; + + if (!phydev->drv) + return -EIO; + + mutex_lock(&phydev->lock); + + if (enable && phydev->isolated) { + ret = -EBUSY; + goto out; + } + + if (!enable && !phydev->isolated) { + ret = -EINVAL; + goto out; + } + + ret = genphy_isolate(phydev, enable); + + if (ret) + goto out; + + phydev->isolated = enable; + +out: + mutex_unlock(&phydev->lock); + return ret; +} +EXPORT_SYMBOL(phy_isolate); + /** * phy_reset_after_clk_enable - perform a PHY reset if needed * @phydev: target phy_device struct @@ -2280,7 +2312,7 @@ int genphy_setup_forced(struct phy_device *phydev) ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); return phy_modify(phydev, MII_BMCR, - ~(BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN), ctl); + ~(BMCR_LOOPBACK | BMCR_PDOWN), ctl); } EXPORT_SYMBOL(genphy_setup_forced); @@ -2369,8 +2401,11 @@ EXPORT_SYMBOL(genphy_read_master_slave); */ int genphy_restart_aneg(struct phy_device *phydev) { - /* Don't isolate the PHY if we're negotiating */ - return phy_modify(phydev, MII_BMCR, BMCR_ISOLATE, + u16 mask = phydev->isolated ? 0 : BMCR_ISOLATE; + /* Don't isolate the PHY if we're negotiating, unless the PHY is + * explicitly isolated + */ + return phy_modify(phydev, MII_BMCR, mask, BMCR_ANENABLE | BMCR_ANRESTART); } EXPORT_SYMBOL(genphy_restart_aneg); @@ -2394,7 +2429,8 @@ int genphy_check_and_restart_aneg(struct phy_device *phydev, bool restart) if (ret < 0) return ret; - if (!(ret & BMCR_ANENABLE) || (ret & BMCR_ISOLATE)) + if (!(ret & BMCR_ANENABLE) || + ((ret & BMCR_ISOLATE) && !phydev->isolated)) restart = true; } @@ -2495,7 +2531,8 @@ int genphy_c37_config_aneg(struct phy_device *phydev) if (ctl < 0) return ctl; - if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE)) + if (!(ctl & BMCR_ANENABLE) || + ((ctl & BMCR_ISOLATE) && !phydev->isolated)) changed = 1; /* do restart aneg */ } @@ -2782,12 +2819,18 @@ EXPORT_SYMBOL(genphy_c37_read_status); int genphy_soft_reset(struct phy_device *phydev) { u16 res = BMCR_RESET; + u16 mask = 0; int ret; if (phydev->autoneg == AUTONEG_ENABLE) res |= BMCR_ANRESTART; - ret = phy_modify(phydev, MII_BMCR, BMCR_ISOLATE, res); + if (phydev->isolated) + res |= BMCR_ISOLATE; + else + mask |= BMCR_ISOLATE; + + ret = phy_modify(phydev, MII_BMCR, mask, res); if (ret < 0) return ret; @@ -2912,6 +2955,12 @@ int genphy_loopback(struct phy_device *phydev, bool enable) u16 ctl = BMCR_LOOPBACK; int ret, val; + /* Isolating and looping-back the MII interface doesn't really + * make sense + */ + if (phydev->isolated) + return -EINVAL; + ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); phy_modify(phydev, MII_BMCR, ~0, ctl); @@ -2924,6 +2973,8 @@ int genphy_loopback(struct phy_device *phydev, bool enable) } else { phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0); + genphy_isolate(phydev, phydev->isolated); + phy_config_aneg(phydev); } @@ -2931,6 +2982,19 @@ int genphy_loopback(struct phy_device *phydev, bool enable) } EXPORT_SYMBOL(genphy_loopback); +int genphy_isolate(struct phy_device *phydev, bool enable) +{ + u16 val = 0; + + if (enable) + val = BMCR_ISOLATE; + + phy_modify(phydev, MII_BMCR, BMCR_ISOLATE, val); + + return 0; +} +EXPORT_SYMBOL(genphy_isolate); + /** * phy_remove_link_mode - Remove a supported link mode * @phydev: phy_device structure to remove link mode from diff --git a/include/linux/phy.h b/include/linux/phy.h index a98bc91a0cde..ae33919aa0f5 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -573,6 +573,7 @@ struct macsec_ops; * @mac_managed_pm: Set true if MAC driver takes of suspending/resuming PHY * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN * enabled. + * @isolated: Set to true if the PHY's MII has been isolated. * @state: State of the PHY for management purposes * @dev_flags: Device-specific flags used by the PHY driver. * @@ -676,6 +677,7 @@ struct phy_device { unsigned is_on_sfp_module:1; unsigned mac_managed_pm:1; unsigned wol_enabled:1; + unsigned isolated:1; unsigned autoneg:1; /* The most recently read link state */ @@ -1781,6 +1783,7 @@ 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_isolate(struct phy_device *phydev, bool enable); 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); @@ -1894,6 +1897,7 @@ 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_isolate(struct phy_device *phydev, bool enable); int genphy_soft_reset(struct phy_device *phydev); irqreturn_t genphy_handle_interrupt_no_ack(struct phy_device *phydev); From patchwork Wed Sep 11 21:27:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801128 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 56A3CEE57D7 for ; Wed, 11 Sep 2024 21:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SuxJgxEerzFtn5NODnwFgah+RUsv6TT5UGmu+5Xa848=; b=qFPZztqZox9pVV+jsjOJ0BmuS9 QJqUGbJAZsOl93Q/B4RQQg/G8pvuM10bDU2DeSSnBEtW9CI6dDTR6i6x0x+CFVtGlcyMZnWwgWFFl NbEDjRJgHBP9s0C9CShymMOTVfUf+NDaOKGEDIlYE5ZwbZxV6prXQV+RGOHc3tf9jF5w2yU12U49h w5vfgs1ye6YGCL8EG9N4+uOJ0JvNJF/TcDKdDzolm8MZwzZP4AQ248M8qfSDnABMN6Vqa5aelYxBh T8b4pwTTOCb5+a023reIzQ5wdZq85KKR/e3uVSYekpnVss7vseFtd+JFeGZXoJdYntiuV/dYpZQyI 2POlrA1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUt1-0000000B3RK-0Sgc; Wed, 11 Sep 2024 21:28:27 +0000 Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUrw-0000000B3Bc-2Yx0 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:22 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 3E6FA1C0003; Wed, 11 Sep 2024 21:27:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SuxJgxEerzFtn5NODnwFgah+RUsv6TT5UGmu+5Xa848=; b=GdEnD/oidgYXzEkLwRFvbhcxVFoZiSIOA1TQ4oS8U2KzVlFicJreHBfWq2WAV3fY2CdpxN C+Nk/8lslx6XnDQfAI/IiNxgSAUz5r08L/MTgjRqZ1AYj6yYeTs67p1exeeD0djLrKtfcs auwKoj04AtDh+SUnmD1mulryVQWauaIuIBsxVV+y5sSgGdwoKV5Mdfsz0Ig4KnpC5gLFUf g4GK1es0TuLVv/WpAaP2JNM6yhgV3sQnRce4paI5LClQ3X8qzPnQ7NIiSQAoIwcw+i1ApH 3KK+FXDy+dUnV+3omhXocAxmuQjLQ7nbRZHGz+emld+txPGkl0YFllUdstx7gg== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 2/7] net: phy: Allow flagging PHY devices that can't isolate their MII Date: Wed, 11 Sep 2024 23:27:06 +0200 Message-ID: <20240911212713.2178943-3-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_142720_877288_FDFAB816 X-CRM114-Status: UNSURE ( 8.90 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some PHYs have malfunctionning isolation modes, where the MII lines aren't correctly set in high-impedance, potentially interfering with the MII bus in unexpected ways. Some other PHYs simply don't support it. Allow flagging these PHYs, and prevent isolating them altogether. Assume the PHY can isolate by default. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy_device.c | 11 +++++++++++ include/linux/phy.h | 1 + 2 files changed, 12 insertions(+) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index c468e72bef4b..2a3db1043626 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2127,6 +2127,14 @@ int phy_loopback(struct phy_device *phydev, bool enable) } EXPORT_SYMBOL(phy_loopback); +static bool phy_can_isolate(struct phy_device *phydev) +{ + if (phydev->drv) + return !(phydev->drv->flags & PHY_NO_ISOLATE); + + return true; +} + int phy_isolate(struct phy_device *phydev, bool enable) { int ret = 0; @@ -2134,6 +2142,9 @@ int phy_isolate(struct phy_device *phydev, bool enable) if (!phydev->drv) return -EIO; + if (!phy_can_isolate(phydev)) + return -EOPNOTSUPP; + mutex_lock(&phydev->lock); if (enable && phydev->isolated) { diff --git a/include/linux/phy.h b/include/linux/phy.h index ae33919aa0f5..f0a8a5459fbe 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -90,6 +90,7 @@ extern const int phy_10gbit_features_array[1]; #define PHY_RST_AFTER_CLK_EN 0x00000002 #define PHY_POLL_CABLE_TEST 0x00000004 #define PHY_ALWAYS_CALL_SUSPEND 0x00000008 +#define PHY_NO_ISOLATE 0x00000010 #define MDIO_DEVICE_IS_PHY 0x80000000 /** From patchwork Wed Sep 11 21:27:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801146 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A800EE57D7 for ; Wed, 11 Sep 2024 21:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YpnVXCGpzg8hKqd/cYNHTq4PwBhP9+SSj5neYt5kd/M=; b=Rjt/uIqYCUUTaJuH9HMsaKU1qt bfxcbWzkGT8fd7st4UffpmWlrv79EiVsOlGgFSO4y6PW3FcdJ5+v21YIPo9ZhS4lk5XqgezlYYhrI //8w551mz43PdCJ3O/vlmV/3MivUm8vZTKl7+ojDFNoroZf2FlTBLP6wuzEhjp+R7nt3yHbxWwGAd 8lH78CJMySoJtoJqtAo1kIJYKnxW7VZqyhVhK9hF9Fz9VTk0Wp5QTUWUbWSYppjJKXKV4fMNOD/KM zPmqeps7lhdaxEor8ex1nbHiVJ+s04FghnXEgEoX0dYPeRbx+mBhU3T9/u7lwqQDBJ9TKHYaoNPrU ToPpN1pA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soV07-0000000B4dG-1Um8; Wed, 11 Sep 2024 21:35:47 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUs3-0000000B3Du-2Iut for linux-arm-kernel@bombadil.infradead.org; Wed, 11 Sep 2024 21:27:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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; bh=YpnVXCGpzg8hKqd/cYNHTq4PwBhP9+SSj5neYt5kd/M=; b=mL+uCMxgxpGTz+8pZOK95Qc/Xr vXZgHAG6qJixDLpV73OZHtpaeePEgP6YLyq89czscy/XDs3Cq4anxAEb/CGXFu+sbxFVf9tCEFWuR 7BwxL+7+nlEH+js56SUCMNhAB98JOM3OKSeCVYGFvTh41oqO61ZVxP8bSl5ByPtLCFAjubWgZHPrk GtD68oeiTK+Ae4wDTk57GxiOr8Wj7NA1rNVsKR1fXjge8wLFHrpfslRAcfkGNH1kCsSEW9ZxspujV aaURT2gwCoQQAlmHP9IhCD3f61SlcyTky7hsPKYbzaSV2F8mz7UtMXfVofOsgXbBCB6sqVY4ah1mi 0wu8/pCg==; Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1soUs0-00000000F6E-0xyo for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:26 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 40A321C0006; Wed, 11 Sep 2024 21:27:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YpnVXCGpzg8hKqd/cYNHTq4PwBhP9+SSj5neYt5kd/M=; b=STJeG49ScfgmHR/SVqSBb4CbUMUsN9gDTA7yrzwfVGz9f8mnlIkqxkDWLLdngWBStaUMca Cy3nwPKET+P8w/V4d3nTDwDlbQJ88XKea6pOO/54KJqRw/890q9A22/3UGOGUoFl10RAvI CROGkPBaRgUBTmrDzKZWVhL+ubYZvBNc7lj1S4s5BsKUEEhRGD4X83OyKjY8oS2FwVYX9U gKweNOnmUQuTNH+OWmv0SVsaZaPZCuZHmybCKyZ96sNZuEbfCiQ6FKyxUmOjVm3iP9L66U UlGhSnYPSCks6hXq5pervRRW/6YkhA0/TQ9s85TcJQp7wjub5pK+srlYBNR7yQ== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 3/7] net: phy: lxt: Mark LXT973 PHYs as having a broken isolate mode Date: Wed, 11 Sep 2024 23:27:07 +0200 Message-ID: <20240911212713.2178943-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_222724_455838_A5AF913B X-CRM114-Status: UNSURE ( 9.64 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Testing showed that PHYs from the LXT973 family have a non-working isolate mode, where the MII lines aren't set in high-impedance as would be expected. Prevent isolating these PHYs. Signed-off-by: Maxime Chevallier --- drivers/net/phy/lxt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c index e3bf827b7959..55cf67391533 100644 --- a/drivers/net/phy/lxt.c +++ b/drivers/net/phy/lxt.c @@ -334,6 +334,7 @@ static struct phy_driver lxt97x_driver[] = { .read_status = lxt973a2_read_status, .suspend = genphy_suspend, .resume = genphy_resume, + .flags = PHY_NO_ISOLATE, }, { .phy_id = 0x00137a10, .name = "LXT973", @@ -344,6 +345,7 @@ static struct phy_driver lxt97x_driver[] = { .config_aneg = lxt973_config_aneg, .suspend = genphy_suspend, .resume = genphy_resume, + .flags = PHY_NO_ISOLATE, } }; module_phy_driver(lxt97x_driver); From patchwork Wed Sep 11 21:27:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801142 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8CE65EE57DB for ; Wed, 11 Sep 2024 21:31:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SokwzpJA0fMoxrnJj1s5WvcG+HbBKr5cR2wqdex0NKs=; b=hhKMXvzcqRx/G9Ab4PXkocBVSG BdqwY8X8rWHL64ZZxISGyFXeMfypIvJTUl9A3bGITZLZxiVG4TPFnHrXdEgqhL/CdPBK/gBm4ZG5D TsCKGMIHFClXhr+4r+9GdG2/jRnsojTNPMI+t9mp/mjxkukxcgfW2IHVP/Yao8kJPXASWBJVzRTpE xuR9gvkBC1Ns9159IWHykZiFLh0QM5BCEDfHDSwUReD6Q2d7Y1musvZiD0IEKQkSPkW6PEk7PbSvR +mHgCdtH+BzJ4XEJfZ+moqpsBXdekfYntIoD8Q7Rx517AoKj9sz7z0MFI81+J5ZDYgXOcqfK0O9rN j7oWZgqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUw4-0000000B466-0KuU; Wed, 11 Sep 2024 21:31:36 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUry-0000000B3CS-2LR5 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:23 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 47F801C0008; Wed, 11 Sep 2024 21:27:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SokwzpJA0fMoxrnJj1s5WvcG+HbBKr5cR2wqdex0NKs=; b=WtvCvv6/l1+JEs6vC9UHmtj0nd4SGsyoR1RJEqAlLH86Ok2zgas/39ckL9zUynbOY/0gsk orboBpQUlfTcTKcB9w8NvbbAGHBl14y7nJneAmO6j6iRnt3sS7xDnf8IUU3K8SkechwWa0 jXks+bFZewYzzTeae1FxtOhPy6YAVJAB0+307mMJJTabBNVio+wDcgY0S1udlujUI60onL W0iA9GlboolOYqpnzhXVU5Oy5BiFF9FMRX8tQXeI7KaW/6/DWci6eFjoC0vWJ1f/kP3ZCf pomr+HCSsGLwL64if3uC4y424kwA4qULlEaU6lrCSgZkLK77LOMJI3FSr0Z+Sg== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 4/7] net: phy: marvell10g: 88x3310 and 88x3340 don't support isolate mode Date: Wed, 11 Sep 2024 23:27:08 +0200 Message-ID: <20240911212713.2178943-5-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_142722_766557_090E25FD X-CRM114-Status: GOOD ( 10.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The 88x3310 and 88x3340 PHYs don't support the isolation mode, regardless of the MII mode being used (SGMII/1000BaseX/2500BaseX/5GBaseR/10GBaseR). Flag this in the driver. This was confirmed on the 88x3310 on a MacchiatoBin. Signed-off-by: Maxime Chevallier --- drivers/net/phy/marvell10g.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/phy/marvell10g.c b/drivers/net/phy/marvell10g.c index 6642eb642d4b..867fd1451b3f 100644 --- a/drivers/net/phy/marvell10g.c +++ b/drivers/net/phy/marvell10g.c @@ -1422,6 +1422,7 @@ static struct phy_driver mv3310_drivers[] = { .set_loopback = genphy_c45_loopback, .get_wol = mv3110_get_wol, .set_wol = mv3110_set_wol, + .flags = PHY_NO_ISOLATE, }, { .phy_id = MARVELL_PHY_ID_88X3310, @@ -1441,6 +1442,7 @@ static struct phy_driver mv3310_drivers[] = { .set_tunable = mv3310_set_tunable, .remove = mv3310_remove, .set_loopback = genphy_c45_loopback, + .flags = PHY_NO_ISOLATE, }, { .phy_id = MARVELL_PHY_ID_88E2110, From patchwork Wed Sep 11 21:27:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 11A9DEE57DB for ; Wed, 11 Sep 2024 21:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=r+zUuX3TEbTMb9kGTTFtZ/4QRQvlQbBoikmP33WrT2E=; b=aCzYdxmoZpn6eZoIbG6XVBZtNU CHjaeySQIEPPU07ESduE7X2qrkYg+TwRuafUmG0gjhFXqcc6CHWWecW4KjkOqwvABdyUSyErGAKSG gzN+Qcknw8DcXzN9VWZ+DKvAkpZHZPmX80PU1qyYxgQjyQi0WDb5N+rzxzQ2/kCntjrEBpnP2A2tv uLsaJPBLl8xjE2n3f9BVK3AEcmtpT05nvdgVsNYOEYm7koSow8b5rf5RlfbDHLIKy29e85EcARXFN obSFKsQejRLeH8KvXcKifXtFBD6B5w4TvKDeh8vVGEUzCVo3Jg4BwFnMLhbiY5xzcPxpXpVobhx/X H1vPhY1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUx5-0000000B4Da-1BnI; Wed, 11 Sep 2024 21:32:39 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUrz-0000000B3Ca-2Yio for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:25 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 5172A1C0009; Wed, 11 Sep 2024 21:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r+zUuX3TEbTMb9kGTTFtZ/4QRQvlQbBoikmP33WrT2E=; b=c7vVVkaR6qgBhveBee5BJEAHpUWbU/OeW8RhW1fEPvcE223RWBnwwv2ik8ZhCQRI5uN9VP hApM8iG52eyHVTB9FhDmil9D8qrYeNHh5myaY+P7CSaIjDZfWsgWlffg6vNJ5YC69ENbgx IVTMRQNoeolDZwpoED3jLm6lCLQwmornnPu+QZ5y2xQ4XpPqSOKdePn6ENt7Z8Y+XHqKLb c4XYeNDyQTqiG3ojp9kmioBAGLpNJMdtJ98ADHKA7cYKRFIEUOZ41b8EG6lBo5VfpsDi5e d/8URapmbAJnk9KE7HcG9Chh7UrNCTxPwlXM7zlNBIU4Y5NvRrtizGJUuetbVQ== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 5/7] net: phy: introduce ethtool_phy_ops to get and set phy configuration Date: Wed, 11 Sep 2024 23:27:09 +0200 Message-ID: <20240911212713.2178943-6-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_142723_944174_883F52B4 X-CRM114-Status: GOOD ( 16.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Expose phy-specific configuration hooks to get and set the state of an ethernet PHY's internal configuration. So far, these parameters include the loopback state of the PHY (host-side loopback) and the isolation state of the PHY. The .get_config() ethtool_phy_ops gets these status information from the phy_device's internal flags, while the .set_config() operation allows changing these configuration parameters. Signed-off-by: Maxime Chevallier --- drivers/net/phy/phy.c | 59 ++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy_device.c | 2 ++ include/linux/ethtool.h | 8 +++++ include/linux/phy.h | 21 +++++++++++++ 4 files changed, 90 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 4f3e742907cb..0cdb0fc30727 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1811,3 +1811,62 @@ int phy_ethtool_nway_reset(struct net_device *ndev) return ret; } EXPORT_SYMBOL(phy_ethtool_nway_reset); + +/** + * phy_get_config - Get PHY configuration parameters + * @phydev: the PHY device to act upon + * @phy_cfg: The configuration to apply + */ + +int phy_get_config(struct phy_device *phydev, + struct phy_device_config *phy_cfg) +{ + mutex_lock(&phydev->lock); + phy_cfg->isolate = phydev->isolated; + phy_cfg->loopback = phydev->loopback_enabled; + mutex_unlock(&phydev->lock); + + return 0; +} + +/** + * phy_set_config - Set PHY configuration parameters + * @phydev: the PHY device to act upon + * @phy_cfg: the configuration to apply + * @extack: a netlink extack for useful error reporting + */ + +int phy_set_config(struct phy_device *phydev, + const struct phy_device_config *phy_cfg, + struct netlink_ext_ack *extack) +{ + bool loopback_change, isolate_change; + int ret; + + /* As the phydev's loopback and isolation state are protected by the + * phy lock, check first if we'll need to perform the action, + * then do them as a second step. + */ + mutex_lock(&phydev->lock); + isolate_change = (phy_cfg->isolate != phydev->isolated); + loopback_change = (phy_cfg->loopback != phydev->loopback_enabled); + mutex_unlock(&phydev->lock); + + if (isolate_change) { + ret = phy_isolate(phydev, phy_cfg->isolate); + if (ret) { + NL_SET_ERR_MSG(extack, "Error while configuring PHY isolation"); + return ret; + } + } + + if (loopback_change) { + ret = phy_loopback(phydev, phy_cfg->loopback); + if (ret) { + NL_SET_ERR_MSG(extack, "Error while configuring PHY loopback"); + return ret; + } + } + + return 0; +} diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 2a3db1043626..0714a2b83d18 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -3845,6 +3845,8 @@ static const struct ethtool_phy_ops phy_ethtool_phy_ops = { .get_plca_status = phy_ethtool_get_plca_status, .start_cable_test = phy_start_cable_test, .start_cable_test_tdr = phy_start_cable_test_tdr, + .get_config = phy_get_config, + .set_config = phy_set_config, }; static const struct phylib_stubs __phylib_stubs = { diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index 12f6dc567598..480ee99a69a5 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -1140,6 +1140,7 @@ struct phy_device; struct phy_tdr_config; struct phy_plca_cfg; struct phy_plca_status; +struct phy_device_config; /** * struct ethtool_phy_ops - Optional PHY device options @@ -1151,6 +1152,8 @@ struct phy_plca_status; * @get_plca_status: Get PLCA configuration. * @start_cable_test: Start a cable test * @start_cable_test_tdr: Start a Time Domain Reflectometry cable test + * @get_config: Retrieve phy device configuration parameters + * @set_config: Set phy device configuration parameters * * All operations are optional (i.e. the function pointer may be set to %NULL) * and callers must take this into account. Callers must hold the RTNL lock. @@ -1172,6 +1175,11 @@ struct ethtool_phy_ops { int (*start_cable_test_tdr)(struct phy_device *phydev, struct netlink_ext_ack *extack, const struct phy_tdr_config *config); + int (*get_config)(struct phy_device *phydev, + struct phy_device_config *phy_cfg); + int (*set_config)(struct phy_device *phydev, + const struct phy_device_config *phy_cfg, + struct netlink_ext_ack *extack); }; /** diff --git a/include/linux/phy.h b/include/linux/phy.h index f0a8a5459fbe..ee0364d2afc3 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -887,6 +887,22 @@ enum phy_led_modes { __PHY_LED_MODES_NUM, }; +/** + * struct phy_device_config - General PHY device configuration parameters for + * status reporting and bulk configuration + * + * A structure containing generic PHY device information, allowing to expose + * internal status to userspace, and perform PHY configuration in a controlled + * manner. + * + * @isolate: The MII-side isolation status of the PHY + * @loopback: The loopback state of the PHY + */ +struct phy_device_config { + bool isolate; + bool loopback; +}; + /** * struct phy_led: An LED driven by the PHY * @@ -2067,6 +2083,11 @@ int phy_ethtool_set_plca_cfg(struct phy_device *phydev, struct netlink_ext_ack *extack); int phy_ethtool_get_plca_status(struct phy_device *phydev, struct phy_plca_status *plca_st); +int phy_get_config(struct phy_device *phydev, + struct phy_device_config *phy_cfg); +int phy_set_config(struct phy_device *phydev, + const struct phy_device_config *phy_cfg, + struct netlink_ext_ack *extack); int __phy_hwtstamp_get(struct phy_device *phydev, struct kernel_hwtstamp_config *config); From patchwork Wed Sep 11 21:27:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D1163EE57D7 for ; Wed, 11 Sep 2024 21:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iTHUsTokc6keqjCmtL8zLGzjeMZ5JmPR1O6Y5URBSdE=; b=zlCOQllZ3sV9xYHfxNXfb5+DAC B2HqGpr7TkfpRWXdk/Xij5MzyNDAuUILRliUoBIjuHwPJSVxgDo9qbJy3xtPkmf6MLmCUY6T4FshG pH+/1pwr+B9F5ScVv90coOLkLocgfNp+cTCSfgTnowk0GbFhnk4LXfrUg031QT7j0YkkSGf/efriB RgzV8J5+BQ3FZYF5uT9gZt3mnWICb1Q9q00YrXCQvM6xb1SOUvc/LhvemtXEXb+RevY1GsE4GiHx9 J+5UyuORhnFFE6YiFnFYo660MTmUMnsX/M/IHSORvQIu+I3hbLf9nqX0gER8wJqt1/7kKhP9rwNNX c8zb35Yg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUy5-0000000B4Lm-2YYb; Wed, 11 Sep 2024 21:33:41 +0000 Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUs0-0000000B3Cz-3FII for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:26 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 5FDE41C0007; Wed, 11 Sep 2024 21:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iTHUsTokc6keqjCmtL8zLGzjeMZ5JmPR1O6Y5URBSdE=; b=pVN0VytACzwRPUE34ySLv963Aa+9JfBNVXQgt+PFbBS7eNOkv6HIy0cmg9HWe7yF0tCQLd AZ2hRMNkcqY3hvJrLCjj9mGeAy4TjLtIQB4kQLDMF65W/rajiwfxmRDJ+WwSb/2Ua9swmO TOEf39F0u8r3h6owiIoNgPOaCEXfaH4nN0kDK/MdKkK81Hz6lbKrfnDDdd43qvIpBZWIrB 5Ca5uVqZ/5s13Q8onUC7y+NAqAsgp5L3KsQBeFQNKl611OcV5l97Sl9N28KTfLwkQSpN3I xouqjxvZ18o3h0EWCZfrdGiMa32mwK1EJreVrS0Ux26xeDuY6CPpDErwAyihBg== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 6/7] net: ethtool: phy: allow reporting and setting the phy isolate status Date: Wed, 11 Sep 2024 23:27:10 +0200 Message-ID: <20240911212713.2178943-7-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_142725_264039_7A075F9D X-CRM114-Status: GOOD ( 15.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add the isolate and loopback status information to the ETHTOOL_PHY_GET netlink command attributes, and allow changing these parameters from a newly-introduced ETHTOOL_PHY_SET command. Signed-off-by: Maxime Chevallier --- Documentation/networking/ethtool-netlink.rst | 2 + include/uapi/linux/ethtool_netlink.h | 3 + net/ethtool/netlink.c | 8 +++ net/ethtool/netlink.h | 1 + net/ethtool/phy.c | 75 ++++++++++++++++++++ 5 files changed, 89 insertions(+) diff --git a/Documentation/networking/ethtool-netlink.rst b/Documentation/networking/ethtool-netlink.rst index ba90457b8b2d..bbd4ca8b9dbd 100644 --- a/Documentation/networking/ethtool-netlink.rst +++ b/Documentation/networking/ethtool-netlink.rst @@ -2234,6 +2234,8 @@ Kernel response contents: bus, the name of this sfp bus ``ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME`` string if the phy controls an sfp bus, the name of the sfp bus + ``ETHTOOL_A_PHY_ISOLATE`` u8 The PHY Isolate status + ``ETHTOOL_A_PHY_LOOPBACK`` u8 The PHY Loopback status ===================================== ====== =============================== When ``ETHTOOL_A_PHY_UPSTREAM_TYPE`` is PHY_UPSTREAM_PHY, the PHY's parent is diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h index 283305f6b063..070565dcf497 100644 --- a/include/uapi/linux/ethtool_netlink.h +++ b/include/uapi/linux/ethtool_netlink.h @@ -59,6 +59,7 @@ enum { ETHTOOL_MSG_MM_SET, ETHTOOL_MSG_MODULE_FW_FLASH_ACT, ETHTOOL_MSG_PHY_GET, + ETHTOOL_MSG_PHY_SET, /* add new constants above here */ __ETHTOOL_MSG_USER_CNT, @@ -1079,6 +1080,8 @@ enum { ETHTOOL_A_PHY_UPSTREAM_INDEX, /* u32 */ ETHTOOL_A_PHY_UPSTREAM_SFP_NAME, /* string */ ETHTOOL_A_PHY_DOWNSTREAM_SFP_NAME, /* string */ + ETHTOOL_A_PHY_ISOLATE, /* u8 */ + ETHTOOL_A_PHY_LOOPBACK, /* u8 */ /* add new constants above here */ __ETHTOOL_A_PHY_CNT, diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c index e3f0ef6b851b..26982f47a934 100644 --- a/net/ethtool/netlink.c +++ b/net/ethtool/netlink.c @@ -394,6 +394,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_PLCA_GET_STATUS] = ðnl_plca_status_request_ops, [ETHTOOL_MSG_MM_GET] = ðnl_mm_request_ops, [ETHTOOL_MSG_MM_SET] = ðnl_mm_request_ops, + [ETHTOOL_MSG_PHY_SET] = ðnl_phy_request_ops, }; static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) @@ -1243,6 +1244,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .policy = ethnl_phy_get_policy, .maxattr = ARRAY_SIZE(ethnl_phy_get_policy) - 1, }, + { + .cmd = ETHTOOL_MSG_PHY_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_default_set_doit, + .policy = ethnl_phy_set_policy, + .maxattr = ARRAY_SIZE(ethnl_phy_set_policy) - 1, + }, }; static const struct genl_multicast_group ethtool_nl_mcgrps[] = { diff --git a/net/ethtool/netlink.h b/net/ethtool/netlink.h index 203b08eb6c6f..7ae73e2eab32 100644 --- a/net/ethtool/netlink.h +++ b/net/ethtool/netlink.h @@ -485,6 +485,7 @@ extern const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1]; extern const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1]; extern const struct nla_policy ethnl_module_fw_flash_act_policy[ETHTOOL_A_MODULE_FW_FLASH_PASSWORD + 1]; extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1]; +extern const struct nla_policy ethnl_phy_set_policy[ETHTOOL_A_PHY_MAX + 1]; int ethnl_set_features(struct sk_buff *skb, struct genl_info *info); int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info); diff --git a/net/ethtool/phy.c b/net/ethtool/phy.c index 99d2a8b6144c..cc1dc45a6264 100644 --- a/net/ethtool/phy.c +++ b/net/ethtool/phy.c @@ -30,10 +30,13 @@ ethnl_phy_reply_size(const struct ethnl_req_info *req_base, struct phy_req_info *req_info = PHY_REQINFO(req_base); struct phy_device_node *pdn = req_info->pdn; struct phy_device *phydev = pdn->phy; + const struct ethtool_phy_ops *ops; size_t size = 0; ASSERT_RTNL(); + ops = ethtool_phy_ops; + /* ETHTOOL_A_PHY_INDEX */ size += nla_total_size(sizeof(u32)); @@ -66,6 +69,14 @@ ethnl_phy_reply_size(const struct ethnl_req_info *req_base, size += nla_total_size(strlen(sfp_name) + 1); } + if (ops && ops->get_config) { + /* ETHTOOL_A_PHY_ISOLATE */ + size += nla_total_size(sizeof(u8)); + + /* ETHTOOL_A_PHY_LOOPBACK */ + size += nla_total_size(sizeof(u8)); + } + return size; } @@ -75,10 +86,20 @@ ethnl_phy_fill_reply(const struct ethnl_req_info *req_base, struct sk_buff *skb) struct phy_req_info *req_info = PHY_REQINFO(req_base); struct phy_device_node *pdn = req_info->pdn; struct phy_device *phydev = pdn->phy; + const struct ethtool_phy_ops *ops; + struct phy_device_config cfg; enum phy_upstream ptype; + int ret; ptype = pdn->upstream_type; + ops = ethtool_phy_ops; + if (ops && ops->get_config) { + ret = ops->get_config(phydev, &cfg); + if (ret) + return ret; + } + if (nla_put_u32(skb, ETHTOOL_A_PHY_INDEX, phydev->phyindex) || nla_put_string(skb, ETHTOOL_A_PHY_NAME, dev_name(&phydev->mdio.dev)) || nla_put_u32(skb, ETHTOOL_A_PHY_UPSTREAM_TYPE, ptype)) @@ -114,6 +135,14 @@ ethnl_phy_fill_reply(const struct ethnl_req_info *req_base, struct sk_buff *skb) return -EMSGSIZE; } + /* Append PHY configuration, if possible */ + if (!ops || !ops->get_config) + return 0; + + if (nla_put_u8(skb, ETHTOOL_A_PHY_ISOLATE, cfg.isolate) || + nla_put_u8(skb, ETHTOOL_A_PHY_LOOPBACK, cfg.loopback)) + return -EMSGSIZE; + return 0; } @@ -311,3 +340,49 @@ int ethnl_phy_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return ret; } + +const struct nla_policy ethnl_phy_set_policy[] = { + [ETHTOOL_A_PHY_HEADER] = + NLA_POLICY_NESTED(ethnl_header_policy_phy), + [ETHTOOL_A_PHY_ISOLATE] = NLA_POLICY_MAX(NLA_U8, 1), + [ETHTOOL_A_PHY_LOOPBACK] = NLA_POLICY_MAX(NLA_U8, 1), +}; + +static int ethnl_set_phy(struct ethnl_req_info *req_info, struct genl_info *info) +{ + struct netlink_ext_ack *extack = info->extack; + const struct ethtool_phy_ops *ops; + struct nlattr **tb = info->attrs; + struct phy_device_config cfg; + struct phy_device *phydev; + bool mod = false; + int ret; + + ops = ethtool_phy_ops; + if (!ops || !ops->set_config || !ops->get_config) + return -EOPNOTSUPP; + + /* We're running under rtnl */ + phydev = ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PHY_HEADER], + extack); + if (IS_ERR_OR_NULL(phydev)) + return -ENODEV; + + ret = ops->get_config(phydev, &cfg); + if (ret) + return ret; + + ethnl_update_bool(&cfg.isolate, tb[ETHTOOL_A_PHY_ISOLATE], &mod); + ethnl_update_bool(&cfg.loopback, tb[ETHTOOL_A_PHY_LOOPBACK], &mod); + + if (!mod) + return 0; + + /* Returning 0 is fine as we don't have a notification */ + return ops->set_config(phydev, &cfg, extack); +} + +const struct ethnl_request_ops ethnl_phy_request_ops = { + .hdr_attr = ETHTOOL_A_PHY_HEADER, + .set = ethnl_set_phy, +}; From patchwork Wed Sep 11 21:27:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 13801145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F335EE57DB for ; Wed, 11 Sep 2024 21:34:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YdYXHEU/uOE2Sd6g81/m5K7/IKN+TbDNAlXuginIRhQ=; b=XtMML5hpzMYtE7QblOpNRw9I4a WjmeHTELsgvdIKURFxaBhzg3UZFoKGGZ6KGq7jiVsw9rxdIH6akPFyr7IMWPMyhrF8hrxJRnzy7hq NbjVi8cKj9so1EFFeNfrQvBcUXyKVGTnDJSburDRqKt7gGIdWdFeCRyghf+fMpcWvZEWdet2vO9EZ chUgN2uFCrxDtfqgN+1EUGbiVzymJSNzrMl32Qlg5X/hEFJ6KsEGsQSHag0k4wm5HCcQUYe9z4Pfm +vFWYRucEoV2RbYxha99nxTjY7Rwq7qfixx+bF2Fds2gEYcPbiHpeX6NROlrgEfNlR943fegN/MqG WGRegkaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUz6-0000000B4RA-08Qw; Wed, 11 Sep 2024 21:34:44 +0000 Received: from relay5-d.mail.gandi.net ([2001:4b98:dc4:8::225]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1soUs1-0000000B3DJ-3m19 for linux-arm-kernel@lists.infradead.org; Wed, 11 Sep 2024 21:27:27 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 728551C000B; Wed, 11 Sep 2024 21:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1726090044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YdYXHEU/uOE2Sd6g81/m5K7/IKN+TbDNAlXuginIRhQ=; b=YqRjlVvP2tfn8WuvsoeqBmym460fVkKFf8kd6eC/OkjfcI1QacbuoMIG4OtaX0CKw5Gi1K 18wD+303mrjKp/JXo84nmo8MrW/6IHm+BYMe2enxyLck1PQVnLRZT1A88dKqBZzhZU+wRf VCVDovDAOu6vfg3szPxGBTtEmoQt+5XumzwVyUZ/xxs3k2RDofD8z4x2GF5W5wIQicJpaX VWyDyGv6+R0sAWamdWpwpJkPZeXq2HssIGDJ1l88/qNkOtzV9hiaUCnUi+lxEat+f9EBPP GU5iVN8motal+hpm70qPIxAhInwHLQod22uDMmMdnKUkAsJPEqBOJjuaWRjk0Q== From: Maxime Chevallier To: davem@davemloft.net Cc: Maxime Chevallier , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Andrew Lunn , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Russell King , linux-arm-kernel@lists.infradead.org, Christophe Leroy , Herve Codina , Florian Fainelli , Heiner Kallweit , Vladimir Oltean , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?K=C3=B6ry_Maince?= =?utf-8?q?nt?= , Oleksij Rempel Subject: [PATCH net-next 7/7] netlink: specs: introduce phy-set command along with configurable attributes Date: Wed, 11 Sep 2024 23:27:11 +0200 Message-ID: <20240911212713.2178943-8-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> References: <20240911212713.2178943-1-maxime.chevallier@bootlin.com> MIME-Version: 1.0 X-GND-Sasl: maxime.chevallier@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240911_142726_105433_B0D27C96 X-CRM114-Status: UNSURE ( 7.18 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Update the ethnl specification to include the newly introduced loopback and isolated attributes, and describe the newly introduced ETHTOOL_PHY_SET command. Signed-off-by: Maxime Chevallier --- Documentation/netlink/specs/ethtool.yaml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Documentation/netlink/specs/ethtool.yaml b/Documentation/netlink/specs/ethtool.yaml index 6a050d755b9c..f17ddd8783f7 100644 --- a/Documentation/netlink/specs/ethtool.yaml +++ b/Documentation/netlink/specs/ethtool.yaml @@ -1132,6 +1132,12 @@ attribute-sets: - name: downstream-sfp-name type: string + - + name: isolate + type: u8 + - + name: loopback + type: u8 operations: enum-model: directional @@ -1950,4 +1956,18 @@ operations: - upstream-index - upstream-sfp-name - downstream-sfp-name + - isolate + - loopback dump: *phy-get-op + - + name: phy-set + doc: Set configuration attributes for attached PHY devices + + attribute-set: phy + + do: + request: + attributes: + - header + - isolate + - loopback