[PATCH net-next 09/13] net: phy: phy_port: Store information about a MII port's occupancy

Maxime Chevallier posted 13 patches 1 week, 5 days ago
There is a newer version of this series
[PATCH net-next 09/13] net: phy: phy_port: Store information about a MII port's occupancy
Posted by Maxime Chevallier 1 week, 5 days ago
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 "occupied" bit to know whether or not a MII port is currently
front-facing (i.e. there's no module in the SFP cage), or occupied (i.e.
there's an SFP module).

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/phy/phy_device.c | 4 ++++
 drivers/net/phy/phylink.c    | 4 ++++
 include/linux/phy_port.h     | 3 +++
 3 files changed, 11 insertions(+)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 12c8c2ff2c06..1dba5f06124f 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1636,6 +1636,8 @@ static int phy_sfp_connect_nophy(void *upstream)
 		}
 	}
 
+	phydev->sfp_bus_port->occupied = true;
+
 	/* we don't use phy_add_port() here as the module port isn't a direct
 	 * interface from the PHY, but rather an extension to the sfp-bus, that
 	 * is already represented by its own phy_port
@@ -1649,6 +1651,8 @@ static void phy_sfp_disconnect_nophy(void *upstream)
 {
 	struct phy_device *phydev = upstream;
 
+	phydev->sfp_bus_port->occupied = false;
+
 	if (phydev->attached_dev)
 		phy_link_topo_del_port(phydev->attached_dev, phydev->mod_port);
 
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index 6c62604b00a6..3f76b1bbb627 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -4044,6 +4044,8 @@ static int phylink_sfp_connect_nophy(void *upstream)
 		}
 	}
 
+	pl->sfp_bus_port->occupied = true;
+
 	pl->mod_port = port;
 
 	return 0;
@@ -4053,6 +4055,8 @@ static void phylink_sfp_disconnect_nophy(void *upstream)
 {
 	struct phylink *pl = upstream;
 
+	pl->sfp_bus_port->occupied = false;
+
 	if (pl->netdev)
 		phy_link_topo_del_port(pl->netdev, pl->mod_port);
 
diff --git a/include/linux/phy_port.h b/include/linux/phy_port.h
index 4e2a3fdd2f2e..8d4f20bfd9dd 100644
--- a/include/linux/phy_port.h
+++ b/include/linux/phy_port.h
@@ -51,6 +51,8 @@ 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.
+ * @occupied: Indicates if this port feeds into an another component that has
+ *	      a front-facing interface.
  */
 struct phy_port {
 	u32 id;
@@ -71,6 +73,7 @@ struct phy_port {
 	unsigned int active:1;
 	unsigned int is_mii:1;
 	unsigned int is_sfp:1;
+	unsigned int occupied:1;
 };
 
 struct phy_port *phy_port_alloc(void);
-- 
2.49.0
Re: [PATCH net-next 09/13] net: phy: phy_port: Store information about a MII port's occupancy
Posted by Romain Gantois 1 week, 4 days ago
On Tuesday, 27 January 2026 14:41:57 CET Maxime Chevallier wrote:
> 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 "occupied" bit to know whether or not a MII port is currently
> front-facing (i.e. there's no module in the SFP cage), or occupied (i.e.
> there's an SFP module).

To me, "front-facing" refers to things like user ports on a switch versus CPU-
facing ports, I don't find it intuitive to use it to qualify a port's state of 
being connected to an empty SFP cage.

Why not use something like "vacant" or "empty" instead?

Thanks,

-- 
Romain Gantois, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Re: [PATCH net-next 09/13] net: phy: phy_port: Store information about a MII port's occupancy
Posted by Maxime Chevallier 1 week, 2 days ago

On 28/01/2026 17:08, Romain Gantois wrote:
> On Tuesday, 27 January 2026 14:41:57 CET Maxime Chevallier wrote:
>> 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 "occupied" bit to know whether or not a MII port is currently
>> front-facing (i.e. there's no module in the SFP cage), or occupied (i.e.
>> there's an SFP module).
> 
> To me, "front-facing" refers to things like user ports on a switch versus CPU-
> facing ports, I don't find it intuitive to use it to qualify a port's state of 
> being connected to an empty SFP cage.
> 
> Why not use something like "vacant" or "empty" instead?

ah 'vacant' was the term I was looking for !

OK I'll update, I like that better :)

Maxime

> 
> Thanks,
>