From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: davem@davemloft.net
Cc: "Maxime Chevallier" <maxime.chevallier@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
thomas.petazzoni@bootlin.com, "Andrew Lunn" <andrew@lunn.ch>,
"Jakub Kicinski" <kuba@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"Paolo Abeni" <pabeni@redhat.com>,
"Russell King" <linux@armlinux.org.uk>,
linux-arm-kernel@lists.infradead.org,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Herve Codina" <herve.codina@bootlin.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Heiner Kallweit" <hkallweit1@gmail.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Marek Behún" <kabel@kernel.org>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: [PATCH net-next v2 1/9] net: phy: allow isolating PHY devices
Date: Fri, 4 Oct 2024 18:15:51 +0200 [thread overview]
Message-ID: <20241004161601.2932901-2-maxime.chevallier@bootlin.com> (raw)
In-Reply-To: <20241004161601.2932901-1-maxime.chevallier@bootlin.com>
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 <maxime.chevallier@bootlin.com>
---
V2 : No change
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);
--
2.46.1
next prev parent reply other threads:[~2024-10-04 16:16 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-04 16:15 [PATCH net-next v2 0/9] Allow isolating PHY devices Maxime Chevallier
2024-10-04 16:15 ` Maxime Chevallier [this message]
2024-10-04 16:15 ` [PATCH net-next v2 2/9] net: phy: Introduce phy_shutdown for device quiescence Maxime Chevallier
2024-10-04 16:15 ` [PATCH net-next v2 3/9] net: phy: Allow PHY drivers to report isolation support Maxime Chevallier
2024-10-04 16:46 ` Oleksij Rempel
2024-10-07 9:52 ` Maxime Chevallier
2024-10-04 18:20 ` Andrew Lunn
2024-10-07 10:27 ` Maxime Chevallier
2024-10-04 16:15 ` [PATCH net-next v2 4/9] net: phy: lxt: Mark LXT973 PHYs as having a broken isolate mode Maxime Chevallier
2024-10-04 16:15 ` [PATCH net-next v2 5/9] net: phy: marvell10g: 88x3310 and 88x3340 don't support " Maxime Chevallier
2024-10-04 16:15 ` [PATCH net-next v2 6/9] net: phy: marvell: mv88e1111 doesn't support isolate in SGMII mode Maxime Chevallier
2024-10-04 16:15 ` [PATCH net-next v2 7/9] net: phy: introduce ethtool_phy_ops to get and set phy configuration Maxime Chevallier
2024-10-04 18:42 ` Andrew Lunn
2024-10-04 19:02 ` Russell King (Oracle)
2024-10-07 10:37 ` Maxime Chevallier
2024-10-07 13:01 ` Andrew Lunn
2024-10-07 13:48 ` Maxime Chevallier
2024-10-07 16:10 ` Russell King (Oracle)
2024-10-08 7:07 ` Maxime Chevallier
2024-10-07 16:37 ` Andrew Lunn
2024-10-08 7:25 ` Maxime Chevallier
2024-10-08 13:00 ` Andrew Lunn
2024-10-08 13:22 ` Russell King (Oracle)
2024-10-08 14:57 ` Maxime Chevallier
2024-10-08 15:27 ` Russell King (Oracle)
2024-10-08 16:41 ` Maxime Chevallier
2024-10-08 17:05 ` Russell King (Oracle)
2024-10-08 17:19 ` Maxime Chevallier
2024-10-04 16:15 ` [PATCH net-next v2 8/9] net: ethtool: phy: allow reporting and setting the phy isolate status Maxime Chevallier
2024-10-04 16:15 ` [PATCH net-next v2 9/9] netlink: specs: introduce phy-set command along with configurable attributes Maxime Chevallier
2024-10-04 17:02 ` [PATCH net-next v2 0/9] Allow isolating PHY devices Russell King (Oracle)
2024-10-07 10:25 ` Maxime Chevallier
2024-10-07 15:53 ` Russell King (Oracle)
2024-10-07 16:43 ` Andrew Lunn
2024-10-08 6:28 ` Maxime Chevallier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241004161601.2932901-2-maxime.chevallier@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=andrew@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox