From: Maxime Chevallier <maxime.chevallier@bootlin.com>
To: davem@davemloft.net, 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>,
Heiner Kallweit <hkallweit1@gmail.com>
Cc: "Maxime Chevallier" <maxime.chevallier@bootlin.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
thomas.petazzoni@bootlin.com,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Herve Codina" <herve.codina@bootlin.com>,
"Florian Fainelli" <f.fainelli@gmail.com>,
"Vladimir Oltean" <vladimir.oltean@nxp.com>,
"Köry Maincent" <kory.maincent@bootlin.com>,
"Marek Behún" <kabel@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>,
"Nicolò Veronese" <nicveronese@gmail.com>,
"Simon Horman" <horms@kernel.org>,
mwojtas@chromium.org,
"Romain Gantois" <romain.gantois@bootlin.com>,
"Daniel Golle" <daniel@makrotopia.org>,
"Dimitri Fedrau" <dimitri.fedrau@liebherr.com>
Subject: [PATCH net-next v5 10/13] net: phy: phy_port: Store information about a MII port's vacant state
Date: Thu, 5 Feb 2026 10:23:13 +0100 [thread overview]
Message-ID: <20260205092317.755906-11-maxime.chevallier@bootlin.com> (raw)
In-Reply-To: <20260205092317.755906-1-maxime.chevallier@bootlin.com>
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@bootlin.com>
---
drivers/net/phy/phy_device.c | 17 +++++++++++++----
drivers/net/phy/phylink.c | 6 ++++++
include/linux/phy_port.h | 4 ++++
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 0daa87413c66..35051ebe4d6b 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1550,6 +1550,7 @@ static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id)
struct phy_device *phydev = upstream;
const struct sfp_module_caps *caps;
struct phy_port *port;
+ int ret = 0;
phy_interface_t iface;
@@ -1578,9 +1579,12 @@ static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id)
phydev->port = caps->port;
if (port->ops && port->ops->configure_mii)
- return port->ops->configure_mii(port, true, iface);
+ ret = port->ops->configure_mii(port, true, iface);
- return 0;
+ if (!ret)
+ port->vacant = false;
+
+ return ret;
}
static void phy_sfp_module_remove(void *upstream)
@@ -1588,8 +1592,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 +1763,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 f26037ec7ba3..8a22cdc4e60b 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -3925,6 +3925,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;
@@ -3936,6 +3939,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
next prev parent reply other threads:[~2026-02-05 9:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-05 9:23 [PATCH net-next v5 00/13] net: phy_port: SFP modules representation and phy_port listing Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 01/13] net: phy: initialize the port support based on the PHY's for OF ports Maxime Chevallier
2026-02-11 9:36 ` Christophe Leroy (CS GROUP)
2026-02-05 9:23 ` [PATCH net-next v5 02/13] net: phy: phy_port: Cleanup the of-parsing logic for phy_port Maxime Chevallier
2026-02-11 9:38 ` Christophe Leroy (CS GROUP)
2026-02-05 9:23 ` [PATCH net-next v5 03/13] net: phy: phy_port: Correctly recompute the port's linkmodes Maxime Chevallier
2026-02-11 9:39 ` Christophe Leroy (CS GROUP)
2026-02-05 9:23 ` [PATCH net-next v5 04/13] net: phy: phy_link_topology: Add a helper for opportunistic alloc Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 05/13] net: phy: phy_link_topology: Track ports in phy_link_topology Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 06/13] net: phylink: Register a phy_port for MAC-driven SFP busses Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 07/13] net: phy: Create SFP phy_port before registering upstream Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 08/13] net: phy: Represent PHY-less SFP modules with phy_port Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 09/13] net: phylink: " Maxime Chevallier
2026-02-05 9:23 ` Maxime Chevallier [this message]
2026-02-05 9:23 ` [PATCH net-next v5 11/13] net: phy: phy_link_topology: Add a helper to retrieve ports Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 12/13] netlink: specs: Add ethernet port listing with ethtool Maxime Chevallier
2026-02-05 9:23 ` [PATCH net-next v5 13/13] net: ethtool: Introduce ethtool command to list ports Maxime Chevallier
2026-02-11 4:11 ` [PATCH net-next v5 00/13] net: phy_port: SFP modules representation and phy_port listing Jakub Kicinski
2026-02-11 7:42 ` Maxime Chevallier
2026-02-13 2:20 ` patchwork-bot+netdevbpf
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=20260205092317.755906-11-maxime.chevallier@bootlin.com \
--to=maxime.chevallier@bootlin.com \
--cc=andrew@lunn.ch \
--cc=christophe.leroy@csgroup.eu \
--cc=daniel@makrotopia.org \
--cc=davem@davemloft.net \
--cc=dimitri.fedrau@liebherr.com \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=herve.codina@bootlin.com \
--cc=hkallweit1@gmail.com \
--cc=horms@kernel.org \
--cc=kabel@kernel.org \
--cc=kory.maincent@bootlin.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mwojtas@chromium.org \
--cc=netdev@vger.kernel.org \
--cc=nicveronese@gmail.com \
--cc=o.rempel@pengutronix.de \
--cc=pabeni@redhat.com \
--cc=romain.gantois@bootlin.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