[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260201151249.642015-9-maxime.chevallier@bootlin.com>
Date: Sun, 1 Feb 2026 16:12:45 +0100
From: Maxime Chevallier <maxime.chevallier@...tlin.com>
To: davem@...emloft.net,
Andrew Lunn <andrew@...n.ch>,
Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Russell King <linux@...linux.org.uk>,
Heiner Kallweit <hkallweit1@...il.com>
Cc: Maxime Chevallier <maxime.chevallier@...tlin.com>,
netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
thomas.petazzoni@...tlin.com,
Christophe Leroy <christophe.leroy@...roup.eu>,
Herve Codina <herve.codina@...tlin.com>,
Florian Fainelli <f.fainelli@...il.com>,
Vladimir Oltean <vladimir.oltean@....com>,
Köry Maincent <kory.maincent@...tlin.com>,
Marek Behún <kabel@...nel.org>,
Oleksij Rempel <o.rempel@...gutronix.de>,
Nicolò Veronese <nicveronese@...il.com>,
Simon Horman <horms@...nel.org>,
mwojtas@...omium.org,
Romain Gantois <romain.gantois@...tlin.com>,
Daniel Golle <daniel@...rotopia.org>,
Dimitri Fedrau <dimitri.fedrau@...bherr.com>
Subject: [PATCH net-next v3 08/11] net: phy: phy_port: Store information about a MII port's vacant state
MII phy_ports are not meant to be connected directly to a link partner.
They are meant to feed into some media converter devices, so far we only
support SFP modules for that.
We have information about what MII they can handle, however we don't
store anything about whether they are currently connected to an SFP
module or not. As phy_port aims at listing the front-facing ports, let's
store an "vacant" bit to know whether or not a MII port is currently
vacant (i.e. there's no module in the SFP cage), or not (i.e.
there's an SFP module).
Signed-off-by: Maxime Chevallier <maxime.chevallier@...tlin.com>
---
drivers/net/phy/phy_device.c | 11 +++++++++--
drivers/net/phy/phylink.c | 6 ++++++
include/linux/phy_port.h | 4 ++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 37efde56e54a..2a3d24310235 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1580,6 +1580,8 @@ static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id)
if (port->ops && port->ops->configure_mii)
return port->ops->configure_mii(port, true, iface);
+ port->vacant = false;
+
return 0;
}
@@ -1588,8 +1590,12 @@ static void phy_sfp_module_remove(void *upstream)
struct phy_device *phydev = upstream;
struct phy_port *port = phy_get_sfp_port(phydev);
- if (port && port->ops && port->ops->configure_mii)
- port->ops->configure_mii(port, false, PHY_INTERFACE_MODE_NA);
+ if (port) {
+ if (port->ops && port->ops->configure_mii)
+ port->ops->configure_mii(port, false,
+ PHY_INTERFACE_MODE_NA);
+ port->vacant = true;
+ }
if (phydev->n_ports == 1)
phydev->port = PORT_NONE;
@@ -1755,6 +1761,7 @@ static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)
*/
port->is_mii = true;
port->is_sfp = true;
+ port->vacant = true;
/* The port->supported and port->interfaces list will be populated
* when attaching the port to the phydev.
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index d65fa6cd1ebb..95bd86d43f19 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -3924,6 +3924,9 @@ static int phylink_sfp_module_insert(void *upstream,
pl->sfp_may_have_phy = caps->may_have_phy;
pl->sfp_port = caps->port;
+ if (pl->sfp_bus_port)
+ pl->sfp_bus_port->vacant = false;
+
/* If this module may have a PHY connecting later, defer until later */
if (pl->sfp_may_have_phy)
return 0;
@@ -3935,6 +3938,9 @@ static void phylink_sfp_module_remove(void *upstream)
{
struct phylink *pl = upstream;
+ if (pl->sfp_bus_port)
+ pl->sfp_bus_port->vacant = true;
+
phy_interface_zero(pl->sfp_interfaces);
}
diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h
index 4e2a3fdd2f2e..b0b1fa6a67a9 100644
--- a/include/linux/phy_port.h
+++ b/include/linux/phy_port.h
@@ -51,6 +51,9 @@ struct phy_port_ops {
* @is_mii: Indicates if this port is MII (Media Independent Interface),
* or MDI (Media Dependent Interface).
* @is_sfp: Indicates if this port drives an SFP cage.
+ * @vacant: For MII ports, indicates whether or not the port has a connection to
+ * another device (e.g. for SFP ports, indicates the absence or presence
+ * of an SFP module)
*/
struct phy_port {
u32 id;
@@ -71,6 +74,7 @@ struct phy_port {
unsigned int active:1;
unsigned int is_mii:1;
unsigned int is_sfp:1;
+ unsigned int vacant:1;
};
struct phy_port *phy_port_alloc(void);
--
2.49.0
Powered by blists - more mailing lists