From nobody Sat Nov 30 03:50:38 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 E635A154BEA; Wed, 11 Sep 2024 21:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090048; cv=none; b=ppEGiVLLIpL0wfvYChSr0HuCQJ+izLzbCZCmGxqpK4ICBFNkocQujvB3xqkexTqOdEF3yNg6D16cxIPUsk8P/VBpd19B1NJtxT/zI/cZmd6OcJmVm3EIfG/krPL6UZctfC1KYZg9wUIu5B+Cu3ZhwEXU1C4laxLtD8tgWy/0gbQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090048; c=relaxed/simple; bh=ihls58iod8nG9VXs3DEc2Eys4zWPBkGLmJdZieaxOhg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kyMB7ui5AlOJBk2v2FUN97BIu1djafhAYVhYoFMm8xuW8NIWPQw5xrYnUqquQhXXmDyiLBYAOrQrSqeOoixow+prUsr6OYBCfcWuHQlHY5OSESdaX3kieqZQT8Mg/OSloHOwOBDE2SKMP7o1xjDtO+0yK939Svx2DslzsM93qrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=gaHkeb+X; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="gaHkeb+X" 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=20Beh=C3=BAn?= , =?UTF-8?q?K=C3=B6ry=20Maincent?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" 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 ena= ble) } EXPORT_SYMBOL(phy_loopback); =20 +int phy_isolate(struct phy_device *phydev, bool enable) +{ + int ret =3D 0; + + if (!phydev->drv) + return -EIO; + + mutex_lock(&phydev->lock); + + if (enable && phydev->isolated) { + ret =3D -EBUSY; + goto out; + } + + if (!enable && !phydev->isolated) { + ret =3D -EINVAL; + goto out; + } + + ret =3D genphy_isolate(phydev, enable); + + if (ret) + goto out; + + phydev->isolated =3D 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 =3D mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); =20 return phy_modify(phydev, MII_BMCR, - ~(BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN), ctl); + ~(BMCR_LOOPBACK | BMCR_PDOWN), ctl); } EXPORT_SYMBOL(genphy_setup_forced); =20 @@ -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 =3D 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; =20 - if (!(ret & BMCR_ANENABLE) || (ret & BMCR_ISOLATE)) + if (!(ret & BMCR_ANENABLE) || + ((ret & BMCR_ISOLATE) && !phydev->isolated)) restart =3D true; } =20 @@ -2495,7 +2531,8 @@ int genphy_c37_config_aneg(struct phy_device *phydev) if (ctl < 0) return ctl; =20 - if (!(ctl & BMCR_ANENABLE) || (ctl & BMCR_ISOLATE)) + if (!(ctl & BMCR_ANENABLE) || + ((ctl & BMCR_ISOLATE) && !phydev->isolated)) changed =3D 1; /* do restart aneg */ } =20 @@ -2782,12 +2819,18 @@ EXPORT_SYMBOL(genphy_c37_read_status); int genphy_soft_reset(struct phy_device *phydev) { u16 res =3D BMCR_RESET; + u16 mask =3D 0; int ret; =20 if (phydev->autoneg =3D=3D AUTONEG_ENABLE) res |=3D BMCR_ANRESTART; =20 - ret =3D phy_modify(phydev, MII_BMCR, BMCR_ISOLATE, res); + if (phydev->isolated) + res |=3D BMCR_ISOLATE; + else + mask |=3D BMCR_ISOLATE; + + ret =3D phy_modify(phydev, MII_BMCR, mask, res); if (ret < 0) return ret; =20 @@ -2912,6 +2955,12 @@ int genphy_loopback(struct phy_device *phydev, bool = enable) u16 ctl =3D BMCR_LOOPBACK; int ret, val; =20 + /* Isolating and looping-back the MII interface doesn't really + * make sense + */ + if (phydev->isolated) + return -EINVAL; + ctl |=3D mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); =20 phy_modify(phydev, MII_BMCR, ~0, ctl); @@ -2924,6 +2973,8 @@ int genphy_loopback(struct phy_device *phydev, bool e= nable) } else { phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0); =20 + genphy_isolate(phydev, phydev->isolated); + phy_config_aneg(phydev); } =20 @@ -2931,6 +2982,19 @@ int genphy_loopback(struct phy_device *phydev, bool = enable) } EXPORT_SYMBOL(genphy_loopback); =20 +int genphy_isolate(struct phy_device *phydev, bool enable) +{ + u16 val =3D 0; + + if (enable) + val =3D 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-L= AN * 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; =20 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 *phyde= v); 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); =20 --=20 2.46.0 From nobody Sat Nov 30 03:50:38 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 91EB0155CA8; Wed, 11 Sep 2024 21:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090048; cv=none; b=vE+O2zV4InDHzdyaTdE1mpvBzvVKCWktdFwIskGxAr5OV9HTECaG/fVhVXLRXRulkVJWemrlu4aLJEYVhCJisq3whNV33WYK0zhI1snbEnlxKn/xo1w3yiNnuUg3fVepx+xoWIUV5CGL/NPzvISOPhSv584INq9vGGBY5DCXeg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090048; c=relaxed/simple; bh=4XKgygHgHYU0HpYZiqp8Izesb809i6ACTGHuv9L2/zM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XBeE7rSkH0W9OMXym7ak+7ewSNSnyHu5qlryHh/ylNV1Wz3So21Jz6y7lwNWqS15G4bEaiq2+olrCdxPVVlh+bGKsk7PWPbvnaR2L0MlOkl/wYczEcSLvulJx7SrLP2I9mtbqBccipNDgjRA8Ra/Z/THfio0rfUnn53UIcD3YVc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=GdEnD/oi; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="GdEnD/oi" 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=20Beh=C3=BAn?= , =?UTF-8?q?K=C3=B6ry=20Maincent?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" 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 ena= ble) } EXPORT_SYMBOL(phy_loopback); =20 +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 =3D 0; @@ -2134,6 +2142,9 @@ int phy_isolate(struct phy_device *phydev, bool enabl= e) if (!phydev->drv) return -EIO; =20 + if (!phy_can_isolate(phydev)) + return -EOPNOTSUPP; + mutex_lock(&phydev->lock); =20 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 =20 /** --=20 2.46.0 From nobody Sat Nov 30 03:50:38 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 4A4661B532D; Wed, 11 Sep 2024 21:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090050; cv=none; b=ZFGE0qXDh+9ox5Ez5vvWY5rOdsYvqJBs0KSsYUHhBJ2/5AzmokvEv+fw+Ge/M7XcW1OuHzUpOP69s2k3IiXD8uVpGVnw7mo7cgaoxDAjrZ9xO+goZgFGVYl+8NfmfkbZCKprS1dd5sYBd1TfU9K7DUUlpqj3BztyLcdda6ALTgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090050; c=relaxed/simple; bh=AGeYrtRHeX5v4s4i46Ax+5MkFG9TJXzm9Vs49DsFi5A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a62rb+cP0xsYaqBMWON3yJ+QCk/VFt5FwhY1Td4Gv10mCG/6xMXVosJy/kSng3dspN+7Cf3hybwXfr4zbETwZcgsFdyR+EfG6K/90/GY7I98c9zM8rjuV6hXx1C9ingb+PztxTtit6Igl1Zv+T4X32HuKb51NUwuIVhyrUvbPfs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=STJeG49S; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="STJeG49S" 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=20Beh=C3=BAn?= , =?UTF-8?q?K=C3=B6ry=20Maincent?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" 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[] =3D { .read_status =3D lxt973a2_read_status, .suspend =3D genphy_suspend, .resume =3D genphy_resume, + .flags =3D PHY_NO_ISOLATE, }, { .phy_id =3D 0x00137a10, .name =3D "LXT973", @@ -344,6 +345,7 @@ static struct phy_driver lxt97x_driver[] =3D { .config_aneg =3D lxt973_config_aneg, .suspend =3D genphy_suspend, .resume =3D genphy_resume, + .flags =3D PHY_NO_ISOLATE, } }; =20 module_phy_driver(lxt97x_driver); --=20 2.46.0 From nobody Sat Nov 30 03:50:38 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 804091B9B45; Wed, 11 Sep 2024 21:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090050; cv=none; b=cEfVahnCyEEOGXxQBQlm+tJ0d+Oank0ATl/1IeCgMhqUyiK+10Y5LgU7z56xJgAVqQV5HoVHzssTqHlPH1H8dC+6FhnxpqIsKc1sM/Gql1XVGoyehyfgFCeI5acG0fPgbbic9ml+t2oo9wgE2sUy9eMpVjaRT8mS0rOnH9niw1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090050; c=relaxed/simple; bh=bX/7NEMB0erTJQ79eCExyrbTzgdjq2kQ7ang6pv/QWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s/CdfOguEM+dsBysi303VDvBEw5A6LiBVZ3AFkGPJs7cRQMab6ZCOXD7kot25y+J8ehZXXzxq01sy4H/h3ph5oxvzIMvdtjbwEdGySN18CDq1QJm3rxvFiOoMUMsy32ob4ixHnqy+ZKdxXyKLaK39lLdywDFaW36A92DVzShFus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=WtvCvv6/; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="WtvCvv6/" 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=20Beh=C3=BAn?= , =?UTF-8?q?K=C3=B6ry=20Maincent?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" 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[] =3D { .set_loopback =3D genphy_c45_loopback, .get_wol =3D mv3110_get_wol, .set_wol =3D mv3110_set_wol, + .flags =3D PHY_NO_ISOLATE, }, { .phy_id =3D MARVELL_PHY_ID_88X3310, @@ -1441,6 +1442,7 @@ static struct phy_driver mv3310_drivers[] =3D { .set_tunable =3D mv3310_set_tunable, .remove =3D mv3310_remove, .set_loopback =3D genphy_c45_loopback, + .flags =3D PHY_NO_ISOLATE, }, { .phy_id =3D MARVELL_PHY_ID_88E2110, --=20 2.46.0 From nobody Sat Nov 30 03:50:38 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 6717E1BBBCB; Wed, 11 Sep 2024 21:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090051; cv=none; b=WjFwzWFzkYlI469lGebgfuwuaGpJsjMgDT5ROJELAiy+OVYO+1kPh5WLyutgluA+UJx95RShSBXupA1IK6487AOWUN6aKZbYBuB1yI690fZ+/7a5M8zzKkKW4m00IohHLa5ekXv6tKVUNNS5GOQvSu7jvihA+og4uoO4eZ+zNQY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090051; c=relaxed/simple; bh=/R4ZU5IYO3Vn/DPYHuaQpJVae+A/JDPR9fxCl2uTiwA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zyq2BpHRNts0Zdq0OciICk5neQo8ifDeFazWor4LfUwvMbw04/jefuQmoB6JWuU7a/Ml6zQpMKvE8jnid7vBVelkuBJJQ94jjdW46p8XrjJc9PrZ8ZhhIcBm1rmj5X45jy9ou/0Z9imh9w1dk7IzQSayzH8ZfWBwdddF3XQ7LEc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=c7vVVkaR; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="c7vVVkaR" 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=20Beh=C3=BAn?= , =?UTF-8?q?K=C3=B6ry=20Maincent?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" 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 =3D phydev->isolated; + phy_cfg->loopback =3D 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 =3D (phy_cfg->isolate !=3D phydev->isolated); + loopback_change =3D (phy_cfg->loopback !=3D phydev->loopback_enabled); + mutex_unlock(&phydev->lock); + + if (isolate_change) { + ret =3D phy_isolate(phydev, phy_cfg->isolate); + if (ret) { + NL_SET_ERR_MSG(extack, "Error while configuring PHY isolation"); + return ret; + } + } + + if (loopback_change) { + ret =3D 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_o= ps =3D { .get_plca_status =3D phy_ethtool_get_plca_status, .start_cable_test =3D phy_start_cable_test, .start_cable_test_tdr =3D phy_start_cable_test_tdr, + .get_config =3D phy_get_config, + .set_config =3D phy_set_config, }; =20 static const struct phylib_stubs __phylib_stubs =3D { 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; =20 /** * 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 %N= ULL) * and callers must take this into account. Callers must hold the RTNL loc= k. @@ -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); }; =20 /** 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, }; =20 +/** + * struct phy_device_config - General PHY device configuration parameters = for + * status reporting and bulk configuration + * + * A structure containing generic PHY device information, allowing to expo= se + * internal status to userspace, and perform PHY configuration in a contro= lled + * 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 *phyd= ev, 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); =20 int __phy_hwtstamp_get(struct phy_device *phydev, struct kernel_hwtstamp_config *config); --=20 2.46.0 From nobody Sat Nov 30 03:50:38 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 D5AB73D3B8; Wed, 11 Sep 2024 21:27:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090047; cv=none; b=YDKbjBn4rNX2T2IbtdLOjL0yRSOCnaaLk0N/IY/qL7XxQd6cwxSygCalil9kYaJ+eBPSIljQHE9LjAgX5nj6vXNUR12/K+bSirxhnLESKBZmuV/Cf4gKtwxk4BtCTUbCZHMPJNyIWw50Hv2Xpo2joJAkWpg04ZpZvysO2XXmjPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090047; c=relaxed/simple; bh=61k1xxD3POH+Cv03/8iOHFG6UUq4CTctSR0CjEBqmi4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lylDIMysSwvaadNgxluv5ShhN0R4rORD3XcqPvLAN5Yb7wZGuZYD8Y5NFNFLe4xwEHIfVZjiKCp8dE+OwCQc5tsMzqXRVB1LEBQ+1Ioje2mw4LFyK1xGi+5o23/VcFHHzSZjrpwKqyqPvM0xrtWFdYxv0GtFTKMeD/+WsrawbgQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=pVN0VytA; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="pVN0VytA" 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=20Beh=C3=BAn?= , =?UTF-8?q?K=C3=B6ry=20Maincent?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" 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/n= etworking/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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 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/etht= ool_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, =20 /* 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 */ =20 /* 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] =3D { [ETHTOOL_MSG_PLCA_GET_STATUS] =3D ðnl_plca_status_request_ops, [ETHTOOL_MSG_MM_GET] =3D ðnl_mm_request_ops, [ETHTOOL_MSG_MM_SET] =3D ðnl_mm_request_ops, + [ETHTOOL_MSG_PHY_SET] =3D ðnl_phy_request_ops, }; =20 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *= cb) @@ -1243,6 +1244,13 @@ static const struct genl_ops ethtool_genl_ops[] =3D { .policy =3D ethnl_phy_get_policy, .maxattr =3D ARRAY_SIZE(ethnl_phy_get_policy) - 1, }, + { + .cmd =3D ETHTOOL_MSG_PHY_SET, + .flags =3D GENL_UNS_ADMIN_PERM, + .doit =3D ethnl_default_set_doit, + .policy =3D ethnl_phy_set_policy, + .maxattr =3D ARRAY_SIZE(ethnl_phy_set_policy) - 1, + }, }; =20 static const struct genl_multicast_group ethtool_nl_mcgrps[] =3D { 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[ETHT= OOL_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]; =20 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_b= ase, struct phy_req_info *req_info =3D PHY_REQINFO(req_base); struct phy_device_node *pdn =3D req_info->pdn; struct phy_device *phydev =3D pdn->phy; + const struct ethtool_phy_ops *ops; size_t size =3D 0; =20 ASSERT_RTNL(); =20 + ops =3D ethtool_phy_ops; + /* ETHTOOL_A_PHY_INDEX */ size +=3D nla_total_size(sizeof(u32)); =20 @@ -66,6 +69,14 @@ ethnl_phy_reply_size(const struct ethnl_req_info *req_ba= se, size +=3D nla_total_size(strlen(sfp_name) + 1); } =20 + if (ops && ops->get_config) { + /* ETHTOOL_A_PHY_ISOLATE */ + size +=3D nla_total_size(sizeof(u8)); + + /* ETHTOOL_A_PHY_LOOPBACK */ + size +=3D nla_total_size(sizeof(u8)); + } + return size; } =20 @@ -75,10 +86,20 @@ ethnl_phy_fill_reply(const struct ethnl_req_info *req_b= ase, struct sk_buff *skb) struct phy_req_info *req_info =3D PHY_REQINFO(req_base); struct phy_device_node *pdn =3D req_info->pdn; struct phy_device *phydev =3D pdn->phy; + const struct ethtool_phy_ops *ops; + struct phy_device_config cfg; enum phy_upstream ptype; + int ret; =20 ptype =3D pdn->upstream_type; =20 + ops =3D ethtool_phy_ops; + if (ops && ops->get_config) { + ret =3D 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; } =20 + /* 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; } =20 @@ -311,3 +340,49 @@ int ethnl_phy_dumpit(struct sk_buff *skb, struct netli= nk_callback *cb) =20 return ret; } + +const struct nla_policy ethnl_phy_set_policy[] =3D { + [ETHTOOL_A_PHY_HEADER] =3D + NLA_POLICY_NESTED(ethnl_header_policy_phy), + [ETHTOOL_A_PHY_ISOLATE] =3D NLA_POLICY_MAX(NLA_U8, 1), + [ETHTOOL_A_PHY_LOOPBACK] =3D 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 =3D info->extack; + const struct ethtool_phy_ops *ops; + struct nlattr **tb =3D info->attrs; + struct phy_device_config cfg; + struct phy_device *phydev; + bool mod =3D false; + int ret; + + ops =3D ethtool_phy_ops; + if (!ops || !ops->set_config || !ops->get_config) + return -EOPNOTSUPP; + + /* We're running under rtnl */ + phydev =3D ethnl_req_get_phydev(req_info, tb[ETHTOOL_A_PHY_HEADER], + extack); + if (IS_ERR_OR_NULL(phydev)) + return -ENODEV; + + ret =3D 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 =3D { + .hdr_attr =3D ETHTOOL_A_PHY_HEADER, + .set =3D ethnl_set_phy, +}; --=20 2.46.0 From nobody Sat Nov 30 03:50:38 2024 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 0357A155759; Wed, 11 Sep 2024 21:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090048; cv=none; b=DyrBdfDMhu+fQK8Rs5ceTAn0ErRHkg92f2nVuVG54H/ckh5Zd3gsJMezOwW2SLTUZFoQeSxOeeIVJneVRJIqbwjib9b8bqQqqpEOg96+4rZ2b4cxn441hAjfG5NddKh4McnADbrDZbzZV9SYiivxR+nd7u+fjRv+Pc994TdNHwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726090048; c=relaxed/simple; bh=qN8YMbE+d2ymnDXdbH4Hx/kcwVBIJqZAoWpEOTNc2tc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fgQGAZ/2ZpSjzNjUf7OFStVSRREDiYwhjRAYHZnzOibtPEwflWMHnYQ3R7cU/pHRE1ZoAGzZN29ur0JnoY5+pJsMc/8UTREKF784d6OxffecTsMoZ6TV6EoTwwdF+GlFOni7tjwjgqeNDGYF1A/CG8UEKF5Fsbp+g8GLlQRTqkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YqRjlVvP; arc=none smtp.client-ip=217.70.183.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YqRjlVvP" 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=20Beh=C3=BAn?= , =?UTF-8?q?K=C3=B6ry=20Maincent?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: maxime.chevallier@bootlin.com Content-Type: text/plain; charset="utf-8" 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/netli= nk/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 =20 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 --=20 2.46.0