public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
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 v3 08/11] net: phy: phy_port: Store information about a MII port's vacant state
Date: Sun,  1 Feb 2026 16:12:45 +0100	[thread overview]
Message-ID: <20260201151249.642015-9-maxime.chevallier@bootlin.com> (raw)
In-Reply-To: <20260201151249.642015-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 | 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


  parent reply	other threads:[~2026-02-01 15:13 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-01 15:12 [PATCH net-next v3 00/11] net: phy_port: SFP modules representation and phy_port listing Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 01/11] net: phy: phy_port: Correctly recompute the port's linkmodes Maxime Chevallier
2026-02-03 17:58   ` [net-next,v3,01/11] " Simon Horman
2026-02-03 18:13     ` Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 02/11] net: phy: phy_link_topology: Add a helper for opportunistic alloc Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 03/11] net: phy: phy_link_topology: Track ports in phy_link_topology Maxime Chevallier
2026-02-03 18:02   ` [net-next,v3,03/11] " Simon Horman
2026-02-03 18:11     ` Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 04/11] net: phylink: Register a phy_port for MAC-driven SFP busses Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 05/11] net: phy: Create SFP phy_port before registering usptream Maxime Chevallier
2026-02-03 17:52   ` Simon Horman
2026-02-03 18:09     ` Maxime Chevallier
2026-02-09 16:25       ` Simon Horman
2026-02-03 18:03   ` [net-next,v3,05/11] " Simon Horman
2026-02-03 18:12     ` Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 06/11] net: phy: Represent PHY-less SFP modules with phy_port Maxime Chevallier
2026-02-03 19:57   ` [net-next,v3,06/11] " Simon Horman
2026-02-01 15:12 ` [PATCH net-next v3 07/11] net: phylink: " Maxime Chevallier
2026-02-01 15:12 ` Maxime Chevallier [this message]
2026-02-01 15:12 ` [PATCH net-next v3 09/11] net: phy: phy_link_topology: Add a helper to retrieve ports Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 10/11] netlink: specs: Add ethernet port listing with ethtool Maxime Chevallier
2026-02-03 17:55   ` Simon Horman
2026-02-03 18:14     ` Maxime Chevallier
2026-02-01 15:12 ` [PATCH net-next v3 11/11] net: ethtool: Introduce ethtool command to list ports Maxime Chevallier
2026-02-02  7:56 ` [PATCH net-next v3 00/11] net: phy_port: SFP modules representation and phy_port listing 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=20260201151249.642015-9-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