Skip to contentSkip to conversation

net: phy_port: SFP modules representation and phy_port listing

PATCH Superseded Maxime Chevallier 2 participants 25 messages Feb 1 – Feb 9

Subsystems (9)

v3 of 19 Superseded Latest is v19 →

lore
Share & tools
lore

Maxime Chevallier

author maintainer
#0 lore raw

v3 cover net: phy_port: SFP modules representation and phy_port listing

Hello everyone,

Here's V3 of the second phy_port series, this time bringing support for more phy_port use especially for SFP, as well as the begining of a ethnl uAPI.

V3 addresses Romain's and AI's review, and removes the _nophy sfp bus ops per Russell's review, which now makes it a 11 patch series.

It builds on the recent addition of phy_port representation to enable listing the front-facing ports of an interface. For now, we don't control these ports, we merely list their presence and their capabilities.

As the most common use-case of multi-port interfaces is combo-ports that provide both RJ45 and SFP connectors on a single MAC, there's a lot of SFP stuff in this series.

This series is in 2 main parts. The first one aims at representing the SFP cages and modules using phy_port, as combo-ports with RJ45 + SFP are by far the most common cases for multi-connector setups.

The second part is the netlink interface to list those ports, now that most use-cases are covered.

Let's see what we can do with some examples of the new ethtool API :

- Get MII interfaces supported by an empty SFP cage :

# ethtool --show-ports eth3

Port for eth3:
Port id: 1
Vacant: yes
Supported MII interfaces : sgmii, 1000base-x, 2500base-x Port type: sfp

- Get Combo-ports supported modes, on each port :

# ethtool --show-ports eth1

Port for eth1:

	Port id: 1
	Vacant: no
	Supported link modes:  10baseT/Half 10baseT/Full
	                       100baseT/Half 100baseT/Full
	                       1000baseT/Full
	                       10000baseT/Full
	                       2500baseT/Full
	                       5000baseT/Full

	Port type: mdi

Port for eth1:
Port id: 2
Vacant: yes
Supported MII interfaces : 10gbase-r
Port type: sfp

- Get Achievable linkmodes on a SFP module (combo port with a DAC in the SFP cage)

# ethtool --show-ports eth1

Port for eth1:

	Port id: 1
	Vacant: no
	Supported link modes:  10baseT/Half 10baseT/Full
	                       100baseT/Half 100baseT/Full
	                       1000baseT/Full
	                       10000baseT/Full
	                       2500baseT/Full
	                       5000baseT/Full
	Port type: mdi

Port for eth1:
Port id: 2
Vacant: no
Supported MII interfaces : 10gbase-r
Port type: sfp

Port for eth1:
Port id: 3
Vacant: no
Supported link modes: 10000baseCR/Full
Port type: mdi

Note that here, we have 3 ports :
- The Copper port
- The SFP Cage itself, marked as 'occupied'
- The SFP module

This series builds on top of phy_port and phy_link_topology to allow tracking the ports of an interface. We maintain a list of supported linkmodes/interfaces on each port, which allows for fine-grained reporting of each port's capability.

What this series doesn't do :
- We don't support selecting which port is active. This is the next step.
- We only support PHY-driven combo ports. The end-goal of this whole journey that started with phy_link_topology is to get support for MII muxes, such as the one we have on the Turris Omnia. This will eventually be upstreamed as well.

If you want to play around with it, here's [1] the patched ethtool that I've been using to produce the outputs above.

Thanks !

Maxime

[1] : https://github.com/minimaxwell/ethtool/tree/mc/ethtool_port

Changelog :

Changes in V3:
- Remove the sfp bus ops for nophy, and use .module_start() as suggested by Russell
- Added missing cleanup for the topology, as per AI review
- Fixed a few typos as per Romain's review
- Changed "occupied" to "vacant" as per Romain's review
- Added missing checks for null ports, per AI review

Changes in V2:
V2: https://lore.kernel.org/netdev/[email protected]/
- Fix the cleanup path of phy_link_topo_add_phy, as per AI review
- Fix the cleanup path of phy_sfp_probe, as per AI review
- Fix the call-site of the disconnect_nophy sfp bus ops, per AI review
- Fix the netdev-less case uin phylink, per AI review
- Fix the prototype of phy_link_topo_get_port for the stubs
- Dropped patch 11. It ended-up breaking 'allnoconfig', so instead we built a phy_interface_names array in net/ethtool/netlink.c
- Fix an ethool-netlink spec discrepancy with the type of an attribute
- Fix the size computation in the netlink port API
- Fix the cleanup path in the netlink port API

V1: https://lore.kernel.org/netdev/[email protected]/

Maxime Chevallier (11):
net: phy: phy_port: Correctly recompute the port's linkmodes
net: phy: phy_link_topology: Add a helper for opportunistic alloc
net: phy: phy_link_topology: Track ports in phy_link_topology
net: phylink: Register a phy_port for MAC-driven SFP busses
net: phy: Create SFP phy_port before registering usptream
net: phy: Represent PHY-less SFP modules with phy_port
net: phylink: Represent PHY-less SFP modules with phy_port
net: phy: phy_port: Store information about a MII port's vacant state
net: phy: phy_link_topology: Add a helper to retrieve ports
netlink: specs: Add ethernet port listing with ethtool
net: ethtool: Introduce ethtool command to list ports

 Documentation/netlink/specs/ethtool.yaml      |  50 +++
 Documentation/networking/ethtool-netlink.rst  |  35 ++
 MAINTAINERS                                   |   1 +
 drivers/net/phy/phy-caps.h                    |   2 +
 drivers/net/phy/phy_caps.c                    |  26 ++
 drivers/net/phy/phy_device.c                  | 138 ++++++-
 drivers/net/phy/phy_link_topology.c           |  82 +++-
 drivers/net/phy/phy_port.c                    |  19 +-
 drivers/net/phy/phylink.c                     | 131 ++++++
 include/linux/phy.h                           |   6 +
 include/linux/phy_link_topology.h             |  35 ++
 include/linux/phy_port.h                      |   6 +
 .../uapi/linux/ethtool_netlink_generated.h    |  19 +
 net/core/dev.c                                |   1 +
 net/ethtool/Makefile                          |   2 +-
 net/ethtool/netlink.c                         |  26 ++
 net/ethtool/netlink.h                         |   8 +
 net/ethtool/port.c                            | 376 ++++++++++++++++++
 18 files changed, 932 insertions(+), 31 deletions(-)
 create mode 100644 net/ethtool/port.c
Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH v3 2/11 net: phy: phy_link_topology: Add a helper for opportunistic alloc

The phy_link_topology structure stores information about the PHY-related components connected to a net_device. It is opportunistically allocated, when we add the first item to the topology, as this is not relevant for all kinds of net_devices.

In preparation for the addition of phy_port tracking in the topology, let's make a dedicated helper for that allocation sequence.

---
 drivers/net/phy/phy_link_topology.c | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)
drivers/net/phy/phy_link_topology.c +21 -8
index 0e9e987f37dd..7dc2ff10c74a 100644
@@ -27,21 +27,34 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev)
 	return 0;
 }
 
+static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *dev)
+{
+	int ret;
+
+	if (dev->link_topo)
+		return dev->link_topo;
+
+	/* The topology is allocated the first time we add an object to it.
+	 * It is freed alongside the netdev.
+	 */
+	ret = netdev_alloc_phy_link_topology(dev);
+	if (ret)
+		return ERR_PTR(ret);
+
+	return dev->link_topo;
+}
+
 int phy_link_topo_add_phy(struct net_device *dev,
 			  struct phy_device *phy,
 			  enum phy_upstream upt, void *upstream)
 {
-	struct phy_link_topology *topo = dev->link_topo;
+	struct phy_link_topology *topo;
 	struct phy_device_node *pdn;
 	int ret;
 
-	if (!topo) {
-		ret = netdev_alloc_phy_link_topology(dev);
-		if (ret)
-			return ret;
-
-		topo = dev->link_topo;
-	}
+	topo = phy_link_topo_get_or_alloc(dev);
+	if (IS_ERR(topo))
+		return PTR_ERR(topo);
 
 	pdn = kzalloc(sizeof(*pdn), GFP_KERNEL);
 	if (!pdn)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH v3 1/11 net: phy: phy_port: Correctly recompute the port's linkmodes

In reply to Maxime Chevallier

a PHY-driven phy_port contains a 'supported' field containing the linkmodes available on this port. This is populated based on :
- The PHY's reported features
- The DT representation of the connector
- The PHY's attach_mdi() callback

As these different attrbution methods work in conjunction, the helper phy_port_update_supported() recomputes the final 'supported' value based on the populated mediums, linkmodes and pairs.

However this recompute wasn't correctly implemented, and added more modes than necessary by or'ing the medium-specific modes to the existing support. Let's fix this and properly filter the modes.

Fixes 589e934d2735 ("net: phy: Introduce PHY ports representation")
---
 drivers/net/phy/phy_port.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/net/phy/phy_port.c +13 -6
index ec93c8ca051e..6c1d3c487b13 100644
@@ -117,12 +117,6 @@ void phy_port_update_supported(struct phy_port *port)
 	unsigned long mode;
 	int i;
 
-	for_each_set_bit(i, &port->mediums, __ETHTOOL_LINK_MEDIUM_LAST) {
-		linkmode_zero(supported);
-		phy_caps_medium_get_supported(supported, i, port->pairs);
-		linkmode_or(port->supported, port->supported, supported);
-	}
-
 	/* If there's no pairs specified, we grab the default number of
 	 * pairs as the max of the default pairs for each linkmode
 	 */
@@ -132,6 +126,19 @@ void phy_port_update_supported(struct phy_port *port)
 			port->pairs = max_t(int, port->pairs,
 					    ethtool_linkmode_n_pairs(mode));
 
+	if (linkmode_empty(port->supported)) {
+		for_each_set_bit(i, &port->mediums,
+				 __ETHTOOL_LINK_MEDIUM_LAST) {
+			__ETHTOOL_DECLARE_LINK_MODE_MASK(med_supported) = {0};
+
+			phy_caps_medium_get_supported(med_supported, i,
+						      port->pairs);
+			linkmode_or(supported, supported, med_supported);
+		}
+
+		linkmode_and(port->supported, port->supported, supported);
+	}
+
 	/* Serdes ports supported through SFP may not have any medium set,
 	 * as they will output PHY_INTERFACE_MODE_XXX modes. In that case, derive
 	 * the supported list based on these interfaces
Signature · 1 line
2.49.0
author maintainer
#5 lore raw

PATCH v3 3/11 net: phy: phy_link_topology: Track ports in phy_link_topology

In reply to Maxime Chevallier

phy_port is aimed at representing the various physical interfaces of a net_device. They can be controlled by various components in the link, such as the Ethernet PHY, the Ethernet MAC, and SFP module, etc.

Let's therefore make so we keep track of all the ports connected to a netdev in phy_link_topology. The only ports added for now are phy-driven ports.

---
 drivers/net/phy/phy_link_topology.c | 53 +++++++++++++++++++++++++++++
 include/linux/phy_link_topology.h   | 18 ++++++++++
 include/linux/phy_port.h            |  2 ++
 net/core/dev.c                      |  1 +
 4 files changed, 74 insertions(+)
drivers/net/phy/phy_link_topology.c +53 -0
index 7dc2ff10c74a..456f1144e83e 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
 #include <linux/phy.h>
 #include <linux/rtnetlink.h>
 #include <linux/xarray.h>
@@ -22,6 +23,9 @@ static int netdev_alloc_phy_link_topology(struct net_device *dev)
 	xa_init_flags(&topo->phys, XA_FLAGS_ALLOC1);
 	topo->next_phy_index = 1;
 
+	xa_init_flags(&topo->ports, XA_FLAGS_ALLOC1);
+	topo->next_port_index = 1;
+
 	dev->link_topo = topo;
 
 	return 0;
@@ -44,12 +48,45 @@ static struct phy_link_topology *phy_link_topo_get_or_alloc(struct net_device *d
 	return dev->link_topo;
 }
 
+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port)
+{
+	struct phy_link_topology *topo;
+	int ret;
+
+	topo = phy_link_topo_get_or_alloc(dev);
+	if (IS_ERR(topo))
+		return PTR_ERR(topo);
+
+	/* Attempt to re-use a previously allocated port_id */
+	if (port->id)
+		ret = xa_insert(&topo->ports, port->id, port, GFP_KERNEL);
+	else
+		ret = xa_alloc_cyclic(&topo->ports, &port->id, port,
+				      xa_limit_32b, &topo->next_port_index,
+				      GFP_KERNEL);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(phy_link_topo_add_port);
+
+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port)
+{
+	struct phy_link_topology *topo = dev->link_topo;
+
+	if (!topo)
+		return;
+
+	xa_erase(&topo->ports, port->id);
+}
+EXPORT_SYMBOL_GPL(phy_link_topo_del_port);
+
 int phy_link_topo_add_phy(struct net_device *dev,
 			  struct phy_device *phy,
 			  enum phy_upstream upt, void *upstream)
 {
 	struct phy_link_topology *topo;
 	struct phy_device_node *pdn;
+	struct phy_port *port;
 	int ret;
 
 	topo = phy_link_topo_get_or_alloc(dev);
@@ -89,8 +126,20 @@ int phy_link_topo_add_phy(struct net_device *dev,
 	if (ret < 0)
 		goto err;
 
+	/* Add all the PHY's ports to the topology */
+	list_for_each_entry(port, &phy->ports, head) {
+		ret = phy_link_topo_add_port(dev, port);
+		if (ret)
+			goto del_ports;
+	}
+
 	return 0;
 
+del_ports:
+	list_for_each_entry_from_reverse(port, &phy->ports, head)
+		phy_link_topo_del_port(dev, port);
+
+	xa_erase(&topo->phys, phy->phyindex);
 err:
 	kfree(pdn);
 	return ret;
@@ -102,10 +151,14 @@ void phy_link_topo_del_phy(struct net_device *dev,
 {
 	struct phy_link_topology *topo = dev->link_topo;
 	struct phy_device_node *pdn;
+	struct phy_port *port;
 
 	if (!topo)
 		return;
 
+	list_for_each_entry(port, &phy->ports, head)
+		phy_link_topo_del_port(dev, port);
+
 	pdn = xa_erase(&topo->phys, phy->phyindex);
 
 	/* We delete the PHY from the topology, however we don't re-set the
include/linux/phy_link_topology.h +18 -0
index 68a59e25821c..66bceff72b19 100644
@@ -16,11 +16,15 @@
 
 struct xarray;
 struct phy_device;
+struct phy_port;
 struct sfp_bus;
 
 struct phy_link_topology {
 	struct xarray phys;
 	u32 next_phy_index;
+
+	struct xarray ports;
+	u32 next_port_index;
 };
 
 struct phy_device_node {
@@ -43,6 +47,9 @@ int phy_link_topo_add_phy(struct net_device *dev,
 
 void phy_link_topo_del_phy(struct net_device *dev, struct phy_device *phy);
 
+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port);
+void phy_link_topo_del_port(struct net_device *dev, struct phy_port *port);
+
 static inline struct phy_device *
 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 {
@@ -72,6 +79,17 @@ static inline void phy_link_topo_del_phy(struct net_device *dev,
 {
 }
 
+static inline int phy_link_topo_add_port(struct net_device *dev,
+					 struct phy_port *port)
+{
+	return 0;
+}
+
+static inline void phy_link_topo_del_port(struct net_device *dev,
+					  struct phy_port *port)
+{
+}
+
 static inline struct phy_device *
 phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 {
include/linux/phy_port.h +2 -0
index 0ef0f5ce4709..4e2a3fdd2f2e 100644
@@ -36,6 +36,7 @@ struct phy_port_ops {
 /**
  * struct phy_port - A representation of a network device physical interface
  *
+ * @id: Unique identifier for the port within the topology
  * @head: Used by the port's parent to list ports
  * @parent_type: The type of device this port is directly connected to
  * @phy: If the parent is PHY_PORT_PHYDEV, the PHY controlling that port
@@ -52,6 +53,7 @@ struct phy_port_ops {
  * @is_sfp: Indicates if this port drives an SFP cage.
  */
 struct phy_port {
+	u32 id;
 	struct list_head head;
 	enum phy_port_parent parent_type;
 	union {
net/core/dev.c +1 -0
index 43de5af0d6ec..fe2dfcc95400 100644
@@ -11277,6 +11277,7 @@ static void netdev_free_phy_link_topology(struct net_device *dev)
 
 	if (IS_ENABLED(CONFIG_PHYLIB) && topo) {
 		xa_destroy(&topo->phys);
+		xa_destroy(&topo->ports);
 		kfree(topo);
 		dev->link_topo = NULL;
 	}
Signature · 1 line
2.49.0
author maintainer
#8 lore raw

PATCH v3 4/11 net: phylink: Register a phy_port for MAC-driven SFP busses

In reply to Maxime Chevallier

phy_port tracks the interfaces that a netdevice feeds into. SFP cages are such ports, but so far we are only tracking the ones that are driven by PHYs acting as media-converters.

Let's populate a phy_port for MAC driver SFP cages, handled by phylink.

This phy_port represents the SFP cage itself, and not the module that may be plugged into it. It's therefore not an MDI interface, so only the 'interfaces' field is relevant here.

The phy_port is only populated for 'NETDEV' phylink instances, as otherwise we don't have any topology to attach the port to.

---
 drivers/net/phy/phylink.c | 53 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
drivers/net/phy/phylink.c +53 -0
index e1f01d7fc4da..7a07de1d42bb 100644
@@ -14,6 +14,8 @@
 #include <linux/of_mdio.h>
 #include <linux/phy.h>
 #include <linux/phy_fixed.h>
+#include <linux/phy_link_topology.h>
+#include <linux/phy_port.h>
 #include <linux/phylink.h>
 #include <linux/rtnetlink.h>
 #include <linux/spinlock.h>
@@ -93,6 +95,7 @@ struct phylink {
 	DECLARE_PHY_INTERFACE_MASK(sfp_interfaces);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
 	u8 sfp_port;
+	struct phy_port *sfp_bus_port;
 
 	struct eee_config eee_cfg;
 
@@ -1758,6 +1761,46 @@ static void phylink_fixed_poll(struct timer_list *t)
 
 static const struct sfp_upstream_ops sfp_phylink_ops;
 
+static int phylink_create_sfp_port(struct phylink *pl)
+{
+	struct phy_port *port;
+	int ret = 0;
+
+	if (!pl->netdev || !pl->sfp_bus)
+		return 0;
+
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->is_sfp = true;
+	port->is_mii = true;
+	port->active = true;
+
+	phy_interface_and(port->interfaces, pl->config->supported_interfaces,
+			  phylink_sfp_interfaces);
+	phy_port_update_supported(port);
+
+	ret = phy_link_topo_add_port(pl->netdev, port);
+	if (ret)
+		phy_port_destroy(port);
+	else
+		pl->sfp_bus_port = port;
+
+	return ret;
+}
+
+static void phylink_destroy_sfp_port(struct phylink *pl)
+{
+	if (pl->netdev && pl->sfp_bus_port)
+		phy_link_topo_del_port(pl->netdev, pl->sfp_bus_port);
+
+	if (pl->sfp_bus_port)
+		phy_port_destroy(pl->sfp_bus_port);
+
+	pl->sfp_bus_port = NULL;
+}
+
 static int phylink_register_sfp(struct phylink *pl,
 				const struct fwnode_handle *fwnode)
 {
@@ -1775,9 +1818,18 @@ static int phylink_register_sfp(struct phylink *pl,
 
 	pl->sfp_bus = bus;
 
+	ret = phylink_create_sfp_port(pl);
+	if (ret) {
+		sfp_bus_put(bus);
+		return ret;
+	}
+
 	ret = sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops);
 	sfp_bus_put(bus);
 
+	if (ret)
+		phylink_destroy_sfp_port(pl);
+
 	return ret;
 }
 
@@ -1939,6 +1991,7 @@ EXPORT_SYMBOL_GPL(phylink_create);
 void phylink_destroy(struct phylink *pl)
 {
 	sfp_bus_del_upstream(pl->sfp_bus);
+	phylink_destroy_sfp_port(pl);
 	if (pl->link_gpio)
 		gpiod_put(pl->link_gpio);
 
Signature · 1 line
2.49.0
author maintainer
#9 lore raw

PATCH v3 5/11 net: phy: Create SFP phy_port before registering usptream

In reply to Maxime Chevallier

When dealing with PHY-driven SFP, we create a phy_port representing the SFP bus when we know we have such a bus.

We can move the port creation before registering the sfp upstream ops, as long as we know the SFP bus is there. This will allow passing the phy_port along with the upstream information to the SFP bus.

---
 drivers/net/phy/phy_device.c | 42 ++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 14 deletions(-)
drivers/net/phy/phy_device.c +28 -14
index 8a3eb1839a3d..49696b1a2f13 100644
@@ -1665,13 +1665,13 @@ static void phy_del_port(struct phy_device *phydev, struct phy_port *port)
 	phydev->n_ports--;
 }
 
-static int phy_setup_sfp_port(struct phy_device *phydev)
+static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)
 {
 	struct phy_port *port = phy_port_alloc();
 	int ret;
 
 	if (!port)
-		return -ENOMEM;
+		return ERR_PTR(-ENOMEM);
 
 	port->parent_type = PHY_PORT_PHY;
 	port->phy = phydev;
@@ -1686,10 +1686,12 @@ static int phy_setup_sfp_port(struct phy_device *phydev)
 	 * when attaching the port to the phydev.
 	 */
 	ret = phy_add_port(phydev, port);
-	if (ret)
+	if (ret) {
 		phy_port_destroy(port);
+		return ERR_PTR(ret);
+	}
 
-	return ret;
+	return port;
 }
 
 /**
@@ -1698,22 +1700,34 @@ static int phy_setup_sfp_port(struct phy_device *phydev)
  */
 static int phy_sfp_probe(struct phy_device *phydev)
 {
+	struct phy_port *port;
 	struct sfp_bus *bus;
-	int ret = 0;
+	int ret;
 
-	if (phydev->mdio.dev.fwnode) {
-		bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
-		if (IS_ERR(bus))
-			return PTR_ERR(bus);
+	if (!phydev->mdio.dev.fwnode)
+		return 0;
+
+	bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
+	if (IS_ERR(bus))
+		return PTR_ERR(bus);
 
-		phydev->sfp_bus = bus;
+	phydev->sfp_bus = bus;
 
-		ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
-		sfp_bus_put(bus);
+	if (bus) {
+		port = phy_setup_sfp_port(phydev);
+		if (IS_ERR(port)) {
+			sfp_bus_put(bus);
+			return PTR_ERR(port);
+		}
 	}
 
-	if (!ret && phydev->sfp_bus)
-		ret = phy_setup_sfp_port(phydev);
+	ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
+	sfp_bus_put(bus);
+
+	if (ret && port) {
+		phy_del_port(phydev, port);
+		phy_port_destroy(port);
+	}
 
 	return ret;
 }
Signature · 1 line
2.49.0
author maintainer
#15 lore raw

PATCH v3 6/11 net: phy: Represent PHY-less SFP modules with phy_port

In reply to Maxime Chevallier

Now that the SFP bus infrastructure notifies when PHY-less modules are connected, we can create a phy_port to represent it. Instead of letting the SFP subsystem handle that, the Bus' upstream is in charge of maintaining that phy_port and register it to the topology, as the upstream (in this case a phy device) is directly interacting with the underlying net_device.

Add a phy_caps helper to get the achievable modes on this module based on what the phy_port representing the bus supports.

---
 drivers/net/phy/phy-caps.h   |  2 +
 drivers/net/phy/phy_caps.c   | 26 +++++++++++
 drivers/net/phy/phy_device.c | 87 +++++++++++++++++++++++++++++++++++-
 include/linux/phy.h          |  6 +++
 4 files changed, 120 insertions(+), 1 deletion(-)
drivers/net/phy/phy-caps.h +2 -0
index 421088e6f6e8..ec3d39a0ae06 100644
@@ -66,5 +66,7 @@ void phy_caps_medium_get_supported(unsigned long *supported,
 				   enum ethtool_link_medium medium,
 				   int lanes);
 u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes);
+void phy_caps_linkmode_filter_ifaces(unsigned long *to, const unsigned long *from,
+				     const unsigned long *interfaces);
 
 #endif /* __PHY_CAPS_H */
drivers/net/phy/phy_caps.c +26 -0
index 942d43191561..558e4df4d63c 100644
@@ -445,3 +445,29 @@ u32 phy_caps_mediums_from_linkmodes(unsigned long *linkmodes)
 	return mediums;
 }
 EXPORT_SYMBOL_GPL(phy_caps_mediums_from_linkmodes);
+
+/**
+ * phy_caps_linkmode_filter_ifaces() - Filter linkmodes with an interface list
+ * @to: Stores the filtered linkmodes
+ * @from: Linkmodes to filter
+ * @interfaces: Bitfield of phy_interface_t that we use for filtering
+ *
+ * Filter the provided linkmodes, only to keep the ones we can possibly achieve
+ * when using any of the provided MII interfaces.
+ */
+void phy_caps_linkmode_filter_ifaces(unsigned long *to,
+				     const unsigned long *from,
+				     const unsigned long *interfaces)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(ifaces_supported) = {};
+	unsigned int ifaces_caps = 0;
+	phy_interface_t interface;
+
+	for_each_set_bit(interface, interfaces, PHY_INTERFACE_MODE_MAX)
+		ifaces_caps |= phy_caps_from_interface(interface);
+
+	phy_caps_linkmodes(ifaces_caps, ifaces_supported);
+
+	linkmode_and(to, from, ifaces_supported);
+}
+EXPORT_SYMBOL_GPL(phy_caps_linkmode_filter_ifaces);
drivers/net/phy/phy_device.c +86 -1

141 lines not on this page · raw message

include/linux/phy.h +6 -0
index 6f9979a26892..9114fdff4c4f 100644
@@ -582,6 +582,7 @@ struct phy_oatc14_sqi_capability {
  * @wol_enabled: Set to true if the PHY or the attached MAC have Wake-on-LAN
  * 		 enabled.
  * @is_genphy_driven: PHY is driven by one of the generic PHY drivers
+ * @has_sfp_mod_phy: Set true if downstream SFP bus's module contains a PHY
  * @state: State of the PHY for management purposes
  * @dev_flags: Device-specific flags used by the PHY driver.
  *
@@ -594,6 +595,8 @@ struct phy_oatc14_sqi_capability {
  * @phylink: Pointer to phylink instance for this PHY
  * @sfp_bus_attached: Flag indicating whether the SFP bus has been attached
  * @sfp_bus: SFP bus attached to this PHY's fiber port
+ * @sfp_bus_port: The phy_port connected to the downstream SFP bus
+ * @mod_port: phy_port representing the SFP module, if it is phy-less
  * @attached_dev: The attached enet driver's device instance ptr
  * @adjust_link: Callback for the enet controller to respond to changes: in the
  *               link state.
@@ -704,6 +707,7 @@ struct phy_device {
 	unsigned irq_rerun:1;
 
 	unsigned default_timestamp:1;
+	unsigned has_sfp_mod_phy:1;
 
 	int rate_matching;
 
@@ -782,6 +786,8 @@ struct phy_device {
 	/* This may be modified under the rtnl lock */
 	bool sfp_bus_attached;
 	struct sfp_bus *sfp_bus;
+	struct phy_port *sfp_bus_port;
+	struct phy_port *mod_port;
 	struct phylink *phylink;
 	struct net_device *attached_dev;
 	struct mii_timestamper *mii_ts;
Signature · 1 line
2.49.0
author maintainer
#17 lore raw

PATCH v3 7/11 net: phylink: Represent PHY-less SFP modules with phy_port

In reply to Maxime Chevallier

Let phylink handle the phy_port for PHY-less modules, and register it to the topology.

---
 drivers/net/phy/phylink.c | 76 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 74 insertions(+), 2 deletions(-)
drivers/net/phy/phylink.c +74 -2
index 7a07de1d42bb..d65fa6cd1ebb 100644
@@ -96,6 +96,7 @@ struct phylink {
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
 	u8 sfp_port;
 	struct phy_port *sfp_bus_port;
+	struct phy_port *mod_port;
 
 	struct eee_config eee_cfg;
 
@@ -1787,13 +1788,31 @@ static int phylink_create_sfp_port(struct phylink *pl)
 	else
 		pl->sfp_bus_port = port;
 
+	if (pl->mod_port) {
+		ret = phy_link_topo_add_port(pl->netdev, pl->mod_port);
+		if (ret)
+			goto out_bus_port;
+	}
+
+	return 0;
+out_bus_port:
+	phy_link_topo_del_port(pl->netdev, port);
+	phy_port_destroy(port);
 	return ret;
 }
 
 static void phylink_destroy_sfp_port(struct phylink *pl)
 {
-	if (pl->netdev && pl->sfp_bus_port)
-		phy_link_topo_del_port(pl->netdev, pl->sfp_bus_port);
+	if (pl->netdev) {
+		if (pl->sfp_bus_port)
+			phy_link_topo_del_port(pl->netdev, pl->sfp_bus_port);
+
+		/* Only remove it from the topology, it will be destroyed at
+		 * module removal.
+		 */
+		if (pl->mod_port)
+			phy_link_topo_del_port(pl->netdev, pl->mod_port);
+	}
 
 	if (pl->sfp_bus_port)
 		phy_port_destroy(pl->sfp_bus_port);
@@ -3919,14 +3938,65 @@ static void phylink_sfp_module_remove(void *upstream)
 	phy_interface_zero(pl->sfp_interfaces);
 }
 
+static int phylink_add_sfp_mod_port(struct phylink *pl)
+{
+	const struct sfp_module_caps *caps;
+	struct phy_port *port;
+	int ret = 0;
+
+	if (!pl->sfp_bus_port)
+		return 0;
+
+	/* Create mod port */
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->active = true;
+
+	caps = sfp_get_module_caps(pl->sfp_bus);
+
+	phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes,
+					pl->sfp_bus_port->interfaces);
+
+	if (pl->netdev) {
+		ret = phy_link_topo_add_port(pl->netdev, port);
+		if (ret) {
+			phy_port_destroy(port);
+			return ret;
+		}
+	}
+
+	pl->mod_port = port;
+
+	return 0;
+}
+
+static void phylink_del_sfp_mod_port(struct phylink *pl)
+{
+	if (!pl->mod_port)
+		return;
+
+	if (pl->netdev)
+		phy_link_topo_del_port(pl->netdev, pl->mod_port);
+
+	phy_port_destroy(pl->mod_port);
+	pl->mod_port = NULL;
+}
+
 static int phylink_sfp_module_start(void *upstream)
 {
 	struct phylink *pl = upstream;
+	int ret;
 
 	/* If this SFP module has a PHY, start the PHY now. */
 	if (pl->phydev) {
 		phy_start(pl->phydev);
 		return 0;
+	} else {
+		ret = phylink_add_sfp_mod_port(pl);
+		if (ret)
+			return ret;
 	}
 
 	/* If the module may have a PHY but we didn't detect one we
@@ -3945,6 +4015,8 @@ static void phylink_sfp_module_stop(void *upstream)
 	/* If this SFP module has a PHY, stop it. */
 	if (pl->phydev)
 		phy_stop(pl->phydev);
+	else
+		phylink_del_sfp_mod_port(pl);
 }
 
 static void phylink_sfp_link_down(void *upstream)
Signature · 1 line
2.49.0
author maintainer
#18 lore raw

PATCH v3 8/11 net: phy: phy_port: Store information about a MII port's vacant state

In reply to Maxime Chevallier

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).

---
 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(-)
drivers/net/phy/phy_device.c +9 -2
index 37efde56e54a..2a3d24310235 100644
@@ -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.
drivers/net/phy/phylink.c +6 -0
index d65fa6cd1ebb..95bd86d43f19 100644
@@ -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);
 }
 
include/linux/phy_port.h +4 -0
index 4e2a3fdd2f2e..b0b1fa6a67a9 100644
@@ -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);
Signature · 1 line
2.49.0
author maintainer
#19 lore raw

PATCH v3 9/11 net: phy: phy_link_topology: Add a helper to retrieve ports

In reply to Maxime Chevallier

In order to allow netlink access to phy_ports, let's add a helper to retrieve them. When handling a port coming from phy_link_topology, the caller must hold rtnl until it's done with it.

---
 include/linux/phy_link_topology.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/linux/phy_link_topology.h +17 -0
index 66bceff72b19..b05858086e42 100644
@@ -66,6 +66,17 @@ phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 	return NULL;
 }
 
+static inline struct phy_port *
+phy_link_topo_get_port(struct net_device *dev, u32 port_id)
+{
+	struct phy_link_topology *topo = dev->link_topo;
+
+	if (!topo)
+		return NULL;
+
+	return xa_load(&topo->ports, port_id);
+}
+
 #else
 static inline int phy_link_topo_add_phy(struct net_device *dev,
 					struct phy_device *phy,
@@ -95,6 +106,12 @@ phy_link_topo_get_phy(struct net_device *dev, u32 phyindex)
 {
 	return NULL;
 }
+
+static inline struct phy_port *
+phy_link_topo_get_port(struct net_device *dev, u32 port_id)
+{
+	return NULL;
+}
 #endif
 
 #endif /* __PHY_LINK_TOPOLOGY_H */
Signature · 1 line
2.49.0
author maintainer
#20 lore raw

PATCH v3 10/11 netlink: specs: Add ethernet port listing with ethtool

In reply to Maxime Chevallier

Ethernet network interfaces may have more than one front-facing port. The phy_port infrastructure was introduced to keep track of these ports, and allow userspace to know about the presence and capability of these ports. Add a ethnl netlink message to report this information.

---
 Documentation/netlink/specs/ethtool.yaml      | 50 +++++++++++++++++++
 Documentation/networking/ethtool-netlink.rst  | 35 +++++++++++++
 .../uapi/linux/ethtool_netlink_generated.h    | 19 +++++++
 3 files changed, 104 insertions(+)
Documentation/netlink/specs/ethtool.yaml +50 -0
index 0a2d2343f79a..ab0ff17d9195 100644
@@ -210,6 +210,10 @@ definitions:
       -
         name: discard
         value: 31
+  -
+    name: port-type
+    type: enum
+    entries: [mdi, sfp]
 
 attribute-sets:
   -
@@ -1890,6 +1894,32 @@ attribute-sets:
         name: link
         type: nest
         nested-attributes: mse-snapshot
+  -
+    name: port
+    attr-cnt-name: --ethtool-a-port-cnt
+    attributes:
+      -
+        name: header
+        type: nest
+        nested-attributes: header
+      -
+        name: id
+        type: u32
+      -
+        name: supported-modes
+        type: nest
+        nested-attributes: bitset
+      -
+        name: supported-interfaces
+        type: nest
+        nested-attributes: bitset
+      -
+        name: type
+        type: u8
+        enum: port-type
+      -
+        name: vacant
+        type: u8
 
 operations:
   enum-model: directional
@@ -2842,6 +2872,26 @@ operations:
             - worst-channel
             - link
       dump: *mse-get-op
+    -
+      name: port-get
+      doc: Get ports attached to an interface
+
+      attribute-set: port
+
+      do: &port-get-op
+        request:
+          attributes:
+            - header
+            - id
+        reply:
+          attributes:
+            - header
+            - id
+            - supported-modes
+            - supported-interfaces
+            - type
+            - vacant
+      dump: *port-get-op
 
 mcast-groups:
   list:
Documentation/networking/ethtool-netlink.rst +35 -0
index af56c304cef4..3e673755800b 100644
@@ -2522,6 +2522,40 @@ Within each channel nest, only the metrics supported by the PHY will be present.
 See ``struct phy_mse_snapshot`` kernel documentation in
 ``include/linux/phy.h``.
 
+PORT_GET
+========
+
+Retrieve information about the physical connection points of a network device,
+referred to as "ports". User needs to specify a PORT_ID for the DO operation,
+in which case the DO request returns information about that specific port.
+
+As there can be more than one port, the DUMP operation can be used to list the
+ports present on a given interface, by passing an interface index or name in
+the dump request.
+
+Request contents:
+
+====================================  ======  =================================
+  ``ETHTOOL_A_PORT_HEADER``             nested  request header
+  ``ETHTOOL_A_PORT_ID``                 u32     port id
+  ====================================  ======  ===============================
+
+Kernel response contents:
+
+  =====================================   ======  =============================
+  ``ETHTOOL_A_PORT_HEADER``               nested  request header
+  ``ETHTOOL_A_PORT_ID``                   u32     the port's unique identifier,
+                                                  per netdevice.
+  ``ETHTOOL_A_PORT_SUPPORTED_MODES``      bitset  bitset of supported linkmodes
+  ``ETHTOOL_A_PORT_SUPPORTED_INTERFACES`` bitset  bitset of supported MII
+                                                  interfaces
+  ``ETHTOOL_A_PORT_TYPE``                 u8      the port type
+  ``ETHTOOL_A_PORT_VACANT``               u8      for non-mdi ports, indicates
+                                                  if the port is connected to
+                                                  another device that could
+                                                  expose a MDI
+  =====================================   ======  =============================
+
 Request translation
 ===================
 
@@ -2632,4 +2666,5 @@ are netlink only.
   n/a                                 ``ETHTOOL_MSG_PHY_GET``
   ``SIOCGHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_GET``
   ``SIOCSHWTSTAMP``                   ``ETHTOOL_MSG_TSCONFIG_SET``
+  n/a                                 ``ETHTOOL_MSG_PORT_GET``
   =================================== =====================================
include/uapi/linux/ethtool_netlink_generated.h +19 -0
index 556a0c834df5..f2a5bb666c4c 100644
@@ -78,6 +78,11 @@ enum ethtool_pse_event {
 	ETHTOOL_PSE_EVENT_SW_PW_CONTROL_ERROR = 64,
 };
 
+enum ethtool_port_type {
+	ETHTOOL_PORT_TYPE_MDI,
+	ETHTOOL_PORT_TYPE_SFP,
+};
+
 enum {
 	ETHTOOL_A_HEADER_UNSPEC,
 	ETHTOOL_A_HEADER_DEV_INDEX,
@@ -837,6 +842,18 @@ enum {
 	ETHTOOL_A_MSE_MAX = (__ETHTOOL_A_MSE_CNT - 1)
 };
 
+enum {
+	ETHTOOL_A_PORT_HEADER = 1,
+	ETHTOOL_A_PORT_ID,
+	ETHTOOL_A_PORT_SUPPORTED_MODES,
+	ETHTOOL_A_PORT_SUPPORTED_INTERFACES,
+	ETHTOOL_A_PORT_TYPE,
+	ETHTOOL_A_PORT_VACANT,
+
+	__ETHTOOL_A_PORT_CNT,
+	ETHTOOL_A_PORT_MAX = (__ETHTOOL_A_PORT_CNT - 1)
+};
+
 enum {
 	ETHTOOL_MSG_USER_NONE = 0,
 	ETHTOOL_MSG_STRSET_GET = 1,
@@ -890,6 +907,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_ACT,
 	ETHTOOL_MSG_RSS_DELETE_ACT,
 	ETHTOOL_MSG_MSE_GET,
+	ETHTOOL_MSG_PORT_GET,
 
 	__ETHTOOL_MSG_USER_CNT,
 	ETHTOOL_MSG_USER_MAX = (__ETHTOOL_MSG_USER_CNT - 1)
@@ -951,6 +969,7 @@ enum {
 	ETHTOOL_MSG_RSS_CREATE_NTF,
 	ETHTOOL_MSG_RSS_DELETE_NTF,
 	ETHTOOL_MSG_MSE_GET_REPLY,
+	ETHTOOL_MSG_PORT_GET_REPLY,
 
 	__ETHTOOL_MSG_KERNEL_CNT,
 	ETHTOOL_MSG_KERNEL_MAX = (__ETHTOOL_MSG_KERNEL_CNT - 1)
Signature · 1 line
2.49.0
author maintainer
#23 lore raw

PATCH v3 11/11 net: ethtool: Introduce ethtool command to list ports

In reply to Maxime Chevallier

Expose the phy_port information to userspace, so that we can know how many ports are available on a given interface, as well as their capabilities. For MDI ports, we report the list of supported linkmodes based on what the PHY that drives this port says.
For MII ports, i.e. empty SFP cages, we report the MII linkmodes that we can output on this port.

---
 MAINTAINERS           |   1 +
 net/ethtool/Makefile  |   2 +-
 net/ethtool/netlink.c |  26 +++
 net/ethtool/netlink.h |   8 +
 net/ethtool/port.c    | 376 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 412 insertions(+), 1 deletion(-)
 create mode 100644 net/ethtool/port.c
MAINTAINERS +1 -0
index 0caa8aee5840..cc8999191357 100644
@@ -18219,6 +18219,7 @@ F:	Documentation/devicetree/bindings/net/ethernet-connector.yaml
 F:	Documentation/networking/phy-port.rst
 F:	drivers/net/phy/phy_port.c
 F:	include/linux/phy_port.h
+F:	net/ethtool/port.c
 K:	struct\s+phy_port|phy_port_
 
 NETWORKING [GENERAL]
net/ethtool/Makefile +1 -1
index 629c10916670..9b5b09670008 100644
@@ -9,4 +9,4 @@ ethtool_nl-y	:= netlink.o bitset.o strset.o linkinfo.o linkmodes.o rss.o \
 		   channels.o coalesce.o pause.o eee.o tsinfo.o cabletest.o \
 		   tunnels.o fec.o eeprom.o stats.o phc_vclocks.o mm.o \
 		   module.o cmis_fw_update.o cmis_cdb.o pse-pd.o plca.o \
-		   phy.o tsconfig.o mse.o
+		   phy.o tsconfig.o mse.o port.o
net/ethtool/netlink.c +26 -0
index 6e5f0f4f815a..90674aed7777 100644
@@ -18,6 +18,8 @@ static u32 ethnl_bcast_seq;
 			     ETHTOOL_FLAG_OMIT_REPLY)
 #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS)
 
+char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN] __ro_after_init;
+
 const struct nla_policy ethnl_header_policy[] = {
 	[ETHTOOL_A_HEADER_DEV_INDEX]	= { .type = NLA_U32 },
 	[ETHTOOL_A_HEADER_DEV_NAME]	= { .type = NLA_NUL_STRING,
@@ -421,6 +423,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
 	[ETHTOOL_MSG_TSCONFIG_SET]	= &ethnl_tsconfig_request_ops,
 	[ETHTOOL_MSG_PHY_GET]		= &ethnl_phy_request_ops,
 	[ETHTOOL_MSG_MSE_GET]		= &ethnl_mse_request_ops,
+	[ETHTOOL_MSG_PORT_GET]		= &ethnl_port_request_ops,
 };
 
 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
@@ -1544,6 +1547,16 @@ static const struct genl_ops ethtool_genl_ops[] = {
 		.policy = ethnl_mse_get_policy,
 		.maxattr = ARRAY_SIZE(ethnl_mse_get_policy) - 1,
 	},
+	{
+		.cmd	= ETHTOOL_MSG_PORT_GET,
+		.doit	= ethnl_default_doit,
+		.start	= ethnl_port_dump_start,
+		.dumpit	= ethnl_port_dumpit,
+		.done	= ethnl_port_dump_done,
+		.policy = ethnl_port_get_policy,
+		.maxattr = ARRAY_SIZE(ethnl_port_get_policy) - 1,
+	},
+
 };
 
 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
@@ -1566,10 +1579,23 @@ static struct genl_family ethtool_genl_family __ro_after_init = {
 
 /* module setup */
 
+static void __init ethnl_phy_names_populate(void)
+{
+	const char *name;
+	int i;
+
+	for (i = 0; i < PHY_INTERFACE_MODE_MAX; i++) {
+		name = phy_modes(i);
+		strscpy(phy_interface_names[i], name, ETH_GSTRING_LEN);
+	}
+}
+
 static int __init ethnl_init(void)
 {
 	int ret;
 
+	ethnl_phy_names_populate();
+
 	ret = genl_register_family(&ethtool_genl_family);
 	if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
 		return ret;
net/ethtool/netlink.h +8 -0
index 89010eaa67df..e849bc63ac58 100644
@@ -5,11 +5,14 @@
 
 #include <linux/ethtool_netlink.h>
 #include <linux/netdevice.h>
+#include <linux/phy.h>
 #include <net/genetlink.h>
 #include <net/sock.h>
 
 struct ethnl_req_info;
 
+extern char phy_interface_names[PHY_INTERFACE_MODE_MAX][ETH_GSTRING_LEN];
+
 u32 ethnl_bcast_seq_next(void);
 int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
 			       const struct nlattr *nest, struct net *net,
@@ -443,6 +446,7 @@ extern const struct ethnl_request_ops ethnl_mm_request_ops;
 extern const struct ethnl_request_ops ethnl_phy_request_ops;
 extern const struct ethnl_request_ops ethnl_tsconfig_request_ops;
 extern const struct ethnl_request_ops ethnl_mse_request_ops;
+extern const struct ethnl_request_ops ethnl_port_request_ops;
 
 extern const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_FLAGS + 1];
 extern const struct nla_policy ethnl_header_policy_stats[ETHTOOL_A_HEADER_FLAGS + 1];
@@ -499,6 +503,7 @@ extern const struct nla_policy ethnl_phy_get_policy[ETHTOOL_A_PHY_HEADER + 1];
 extern const struct nla_policy ethnl_tsconfig_get_policy[ETHTOOL_A_TSCONFIG_HEADER + 1];
 extern const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1];
 extern const struct nla_policy ethnl_mse_get_policy[ETHTOOL_A_MSE_HEADER + 1];
+extern const struct nla_policy ethnl_port_get_policy[ETHTOOL_A_PORT_ID + 1];
 
 int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
 int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info);
@@ -514,6 +519,9 @@ int ethnl_tsinfo_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 int ethnl_tsinfo_done(struct netlink_callback *cb);
 int ethnl_rss_create_doit(struct sk_buff *skb, struct genl_info *info);
 int ethnl_rss_delete_doit(struct sk_buff *skb, struct genl_info *info);
+int ethnl_port_dump_start(struct netlink_callback *cb);
+int ethnl_port_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
+int ethnl_port_dump_done(struct netlink_callback *cb);
 
 extern const char stats_std_names[__ETHTOOL_STATS_CNT][ETH_GSTRING_LEN];
 extern const char stats_eth_phy_names[__ETHTOOL_A_STATS_ETH_PHY_CNT][ETH_GSTRING_LEN];
net/ethtool/port.c new file +376 -0

376 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#24 lore raw
In reply to Maxime Chevallier

Hi,

Quoted 6 lines · Maxime Chevallier

Hello everyone,

Here's V3 of the second phy_port series, this time bringing support for more phy_port use especially for SFP, as well as the begining of a ethnl uAPI.

I saw there are some more AI reviews, I'll sift through these :)

Maxime

reviewer
#10 lore raw

Re: [PATCH net-next v3 05/11] net: phy: Create SFP phy_port before registering usptream

In reply to Maxime Chevallier
Quoted 8 lines · Maxime Chevallier

When dealing with PHY-driven SFP, we create a phy_port representing the SFP bus when we know we have such a bus.

We can move the port creation before registering the sfp upstream ops, as long as we know the SFP bus is there. This will allow passing the phy_port along with the upstream information to the SFP bus.

...

Quoted 29 lines
drivers/net/phy/phy_device.c +13 -8
@@ -1698,22 +1700,34 @@ static int phy_setup_sfp_port(struct phy_device *phydev)
  */
 static int phy_sfp_probe(struct phy_device *phydev)
 {
+	struct phy_port *port;
 	struct sfp_bus *bus;
-	int ret = 0;
+	int ret;
 
-	if (phydev->mdio.dev.fwnode) {
-		bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
-		if (IS_ERR(bus))
-			return PTR_ERR(bus);
+	if (!phydev->mdio.dev.fwnode)
+		return 0;
+
+	bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode);
+	if (IS_ERR(bus))
+		return PTR_ERR(bus);
 
-		phydev->sfp_bus = bus;
+	phydev->sfp_bus = bus;
 
-		ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
-		sfp_bus_put(bus);
+	if (bus) {
+		port = phy_setup_sfp_port(phydev);
+		if (IS_ERR(port)) {
+			sfp_bus_put(bus);

drivers/net/phy/phy_device.c static int phy_setup_sfp_port(struct phy_device *phydev) · line 1727

Quoted 10 lines
drivers/net/phy/phy_device.c +6 -2
+			return PTR_ERR(port);
+		}
 	}
 
-	if (!ret && phydev->sfp_bus)
-		ret = phy_setup_sfp_port(phydev);
+	ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
+	sfp_bus_put(bus);
+
+	if (ret && port) {

Hi Maxime,

If bus is NULL then port will not be set here.

Flagged by Smatch.

Quoted 9 lines
drivers/net/phy/phy_device.c +3 -0
+		phy_del_port(phydev, port);
+		phy_port_destroy(port);
+	}
 
 	return ret;
 }
Signature · 1 line
2.49.0
reviewer
#21 lore raw

Re: [PATCH net-next v3 10/11] netlink: specs: Add ethernet port listing with ethtool

In reply to Maxime Chevallier

On Sun, Feb 01, 2026 at 04:12:47PM +0100, Maxime Chevallier wrote:

...

Quoted 12 lines
Documentation/networking/ethtool-netlink.rst +4 -0
index af56c304cef4..3e673755800b 100644
@@ -2522,6 +2522,40 @@ Within each channel nest, only the metrics supported by the PHY will be present.
 See ``struct phy_mse_snapshot`` kernel documentation in
 ``include/linux/phy.h``.
 
+PORT_GET
+========
+
+Retrieve information about the physical connection points of a network device,

Documentation/networking/ethtool-netlink.rst Within each channel nest, only the metrics supported by the PHY will be present. · line 2538

Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +10 -0
+referred to as "ports". User needs to specify a PORT_ID for the DO operation,
+in which case the DO request returns information about that specific port.
+
+As there can be more than one port, the DUMP operation can be used to list the
+ports present on a given interface, by passing an interface index or name in
+the dump request.
+
+Request contents:
+
+====================================  ======  =================================

Hi Maxime,

make htmldocs complains that "Bottom/header table border does not match top border.".

Quoted 23 lines
Documentation/networking/ethtool-netlink.rst +20 -0
+  ``ETHTOOL_A_PORT_HEADER``             nested  request header
+  ``ETHTOOL_A_PORT_ID``                 u32     port id
+  ====================================  ======  ===============================
+
+Kernel response contents:
+
+  =====================================   ======  =============================
+  ``ETHTOOL_A_PORT_HEADER``               nested  request header
+  ``ETHTOOL_A_PORT_ID``                   u32     the port's unique identifier,
+                                                  per netdevice.
+  ``ETHTOOL_A_PORT_SUPPORTED_MODES``      bitset  bitset of supported linkmodes
+  ``ETHTOOL_A_PORT_SUPPORTED_INTERFACES`` bitset  bitset of supported MII
+                                                  interfaces
+  ``ETHTOOL_A_PORT_TYPE``                 u8      the port type
+  ``ETHTOOL_A_PORT_VACANT``               u8      for non-mdi ports, indicates
+                                                  if the port is connected to
+                                                  another device that could
+                                                  expose a MDI
+  =====================================   ======  =============================
+
 Request translation
 ===================
 
reviewer
#2 lore raw

Re: [net-next,v3,01/11] net: phy: phy_port: Correctly recompute the port's linkmodes

In reply to Maxime Chevallier

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: phy_port: Correctly recompute the port's linkmodes

This commit fixes phy_port_update_supported() to properly filter linkmodes instead of incorrectly or'ing medium-specific modes to the existing support. It moves the medium iteration inside a check for empty port->supported.

Fixes 589e934d2735 ("net: phy: Introduce PHY ports representation")
Quoted 3 lines
drivers/net/phy/phy_port.c +0 -0

[ ... ]

Quoted 6 lines
drivers/net/phy/phy_port.c +2 -0
@@ -132,6 +126,19 @@ void phy_port_update_supported(struct phy_port *port)
 			port->pairs = max_t(int, port->pairs,
 					    ethtool_linkmode_n_pairs(mode));
 
+	if (linkmode_empty(port->supported)) {
+		for_each_set_bit(i, &port->mediums,

drivers/net/phy/phy_port.c void phy_port_update_supported(struct phy_port *port) · line 140

Quoted 10 lines
drivers/net/phy/phy_port.c +10 -0
+				 __ETHTOOL_LINK_MEDIUM_LAST) {
+			__ETHTOOL_DECLARE_LINK_MODE_MASK(med_supported) = {0};
+
+			phy_caps_medium_get_supported(med_supported, i,
+						      port->pairs);
+			linkmode_or(supported, supported, med_supported);
+		}
+
+		linkmode_and(port->supported, port->supported, supported);
+	}

Jakub Kicinski raised a concern in v2 about the AND operation when port->supported starts empty. The v3 fix adds the
'if (linkmode_empty(port->supported))' check, but then still performs:

    linkmode_and(port->supported, port->supported, supported);

inside that block. Since we just confirmed port->supported is empty, ANDing it with anything will always produce an empty result.

Should this be linkmode_copy() or linkmode_or() instead of linkmode_and() when port->supported starts empty?

Reference: https://lore.kernel.org/all/[email protected]/

reviewer
#6 lore raw

Re: [net-next,v3,03/11] net: phy: phy_link_topology: Track ports in phy_link_topology

In reply to Maxime Chevallier

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: phy_link_topology: Track ports in phy_link_topology

This commit adds port tracking to phy_link_topology, keeping track of all ports connected to a netdev. Ports are added when a PHY is attached and removed when it is detached.

Quoted 4 lines
drivers/net/phy/phy_link_topology.c +0 -0
index 7dc2ff10c74a..456f1144e83e 100644

[ ... ]

Quoted 19 lines
drivers/net/phy/phy_link_topology.c +19 -0
+int phy_link_topo_add_port(struct net_device *dev, struct phy_port *port)
+{
+	struct phy_link_topology *topo;
+	int ret;
+
+	topo = phy_link_topo_get_or_alloc(dev);
+	if (IS_ERR(topo))
+		return PTR_ERR(topo);
+
+	/* Attempt to re-use a previously allocated port_id */
+	if (port->id)
+		ret = xa_insert(&topo->ports, port->id, port, GFP_KERNEL);
+	else
+		ret = xa_alloc_cyclic(&topo->ports, &port->id, port,
+				      xa_limit_32b, &topo->next_port_index,
+				      GFP_KERNEL);
+
+	return ret;
+}

[ ... ]

drivers/net/phy/phy_link_topology.c int phy_link_topo_add_phy(struct net_device *dev, · line 133

Quoted 9 lines
drivers/net/phy/phy_link_topology.c +6 -0
@@ -89,8 +126,20 @@ int phy_link_topo_add_phy(struct net_device *dev,
 	if (ret < 0)
 		goto err;
+
+	/* Add all the PHY's ports to the topology */
+	list_for_each_entry(port, &phy->ports, head) {
+		ret = phy_link_topo_add_port(dev, port);
+		if (ret)
+			goto del_ports;
                   ^^^

xa_alloc_cyclic() returns 1 when ID allocation wraps around, which is still a successful allocation. The check at line 126 above correctly uses if (ret < 0) for the phyindex allocation:

    ret = xa_alloc_cyclic(&topo->phys, &phy->phyindex, pdn, ...);
    if (ret < 0)
        goto err;

Should this use if (ret < 0) as well for consistency? With the current code, when the port ID wraps around, the PHY attachment will fail and trigger rollback of all successfully added ports even though the allocation succeeded.

reviewer
#13 lore raw

Re: [net-next,v3,05/11] net: phy: Create SFP phy_port before registering usptream

In reply to Maxime Chevallier

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: Create SFP phy_port before registering usptream

This commit moves the creation of the SFP phy_port to occur before registering the SFP upstream ops. This reordering allows passing the phy_port along with the upstream information to the SFP bus.

Quoted 1 line

net: phy: Create SFP phy_port before registering usptream

This isn't a bug, but there's a typo in the subject line: "usptream" should be "upstream".

author maintainer
#11 lore raw

Re: [PATCH net-next v3 05/11] net: phy: Create SFP phy_port before registering usptream

In reply to Simon Horman

Hi Simon,

Quoted 10 lines · Simon Horman

drivers/net/phy/phy_device.c static int phy_setup_sfp_port(struct phy_device *phydev) · line 1727

Quoted 6 lines
drivers/net/phy/phy_device.c +4 -2
-	if (!ret && phydev->sfp_bus)
-		ret = phy_setup_sfp_port(phydev);
+	ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
+	sfp_bus_put(bus);
+
+	if (ret && port) {

Hi Maxime,

If bus is NULL then port will not be set here.

Arg... I though smatch was running in the NIPA ingst-mdir script, but I was wrong :(

I'll address that in V5 as the problme is still in V4, thank you for the report

Maxime

author maintainer
#7 lore raw

Re: [net-next,v3,03/11] net: phy: phy_link_topology: Track ports in phy_link_topology

In reply to Simon Horman

Hi Simon,

Quoted 7 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

xa_alloc_cyclic() returns 1 when ID allocation wraps around, which is still a successful allocation. The check at line 126 above correctly uses if (ret < 0) for the phyindex allocation:

I already reported that to Chris, this review is incorrect.

xa_alloc_cyclic() doesn't return 1 upon wraparound. __xa_alloc_cyclic() does :)

Maxime

author maintainer
#14 lore raw

Re: [net-next,v3,05/11] net: phy: Create SFP phy_port before registering usptream

In reply to Simon Horman

Hi Simon,

Quoted 7 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: Create SFP phy_port before registering usptream

Quoted 8 lines

This commit moves the creation of the SFP phy_port to occur before registering the SFP upstream ops. This reordering allows passing the phy_port along with the upstream information to the SFP bus.

Quoted 1 line

net: phy: Create SFP phy_port before registering usptream

This isn't a bug, but there's a typo in the subject line: "usptream" should be "upstream".

That's aleady addressed in V4 :)

Maxime

author maintainer
#3 lore raw

Re: [net-next,v3,01/11] net: phy: phy_port: Correctly recompute the port's linkmodes

In reply to Simon Horman

Hi Simon

Quoted 23 lines · Simon Horman

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: phy_port: Correctly recompute the port's linkmodes

This commit fixes phy_port_update_supported() to properly filter linkmodes instead of incorrectly or'ing medium-specific modes to the existing support. It moves the medium iteration inside a check for empty port->supported.

Fixes 589e934d2735 ("net: phy: Introduce PHY ports representation")
Quoted 3 lines
drivers/net/phy/phy_port.c +0 -0

[ ... ]

Quoted 4 lines
drivers/net/phy/phy_port.c +0 -0
@@ -132,6 +126,19 @@ void phy_port_update_supported(struct phy_port *port)
 			port->pairs = max_t(int, port->pairs,
 					    ethtool_linkmode_n_pairs(mode));
 
Quoted 11 lines

drivers/net/phy/phy_port.c void phy_port_update_supported(struct phy_port *port) · line 139

Quoted 11 lines
drivers/net/phy/phy_port.c +11 -0
+	if (linkmode_empty(port->supported)) {
+		for_each_set_bit(i, &port->mediums,
+				 __ETHTOOL_LINK_MEDIUM_LAST) {
+			__ETHTOOL_DECLARE_LINK_MODE_MASK(med_supported) = {0};
+
+			phy_caps_medium_get_supported(med_supported, i,
+						      port->pairs);
+			linkmode_or(supported, supported, med_supported);
+		}
+
+		linkmode_and(port->supported, port->supported, supported);

Yeah :(

Quoted 8 lines

drivers/net/phy/phy_port.c void phy_port_update_supported(struct phy_port *port) · line 140

Quoted 1 line
drivers/net/phy/phy_port.c +1 -0
+	}

Jakub Kicinski raised a concern in v2 about the AND operation when port->supported starts empty. The v3 fix adds the
'if (linkmode_empty(port->supported))' check, but then still performs:

    linkmode_and(port->supported, port->supported, supported);
Quoted 7 lines

inside that block. Since we just confirmed port->supported is empty, ANDing it with anything will always produce an empty result.

Should this be linkmode_copy() or linkmode_or() instead of linkmode_and() when port->supported starts empty?

Reference: https://lore.kernel.org/all/[email protected]/

True, that's already addressed in V4 :)

Maxime

author maintainer
#22 lore raw

Re: [PATCH net-next v3 10/11] netlink: specs: Add ethernet port listing with ethtool

In reply to Simon Horman

Hi Simon,

Quoted 29 lines · Simon Horman

On Sun, Feb 01, 2026 at 04:12:47PM +0100, Maxime Chevallier wrote:

...

Quoted 12 lines
Documentation/networking/ethtool-netlink.rst +4 -0
index af56c304cef4..3e673755800b 100644
@@ -2522,6 +2522,40 @@ Within each channel nest, only the metrics supported by the PHY will be present.
 See ``struct phy_mse_snapshot`` kernel documentation in
 ``include/linux/phy.h``.
 
+PORT_GET
+========
+
+Retrieve information about the physical connection points of a network device,

Documentation/networking/ethtool-netlink.rst Within each channel nest, only the metrics supported by the PHY will be present. · line 2538

Quoted 10 lines
Documentation/networking/ethtool-netlink.rst +10 -0
+referred to as "ports". User needs to specify a PORT_ID for the DO operation,
+in which case the DO request returns information about that specific port.
+
+As there can be more than one port, the DUMP operation can be used to list the
+ports present on a given interface, by passing an interface index or name in
+the dump request.
+
+Request contents:
+
+====================================  ======  =================================

Hi Maxime,

Quoted 2 lines

make htmldocs complains that "Bottom/header table border does not match top border.".

Ah indeed ! I'll address this in V5 then. Thank you for the report !

Maxime

reviewer
#16 lore raw

Re: [net-next,v3,06/11] net: phy: Represent PHY-less SFP modules with phy_port

In reply to Maxime Chevallier

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: phy: Represent PHY-less SFP modules with phy_port

Now that the SFP bus infrastructure notifies when PHY-less modules are connected, we can create a phy_port to represent it. Instead of letting the SFP subsystem handle that, the Bus' upstream is in charge of maintaining that phy_port and register it to the topology, as the upstream (in this case a phy device) is directly interacting with the underlying net_device.

Add a phy_caps helper to get the achievable modes on this module based on what the phy_port representing the bus supports.

Quoted 3 lines
drivers/net/phy/phy_device.c +0 -0

[ ... ]

Quoted 8 lines
drivers/net/phy/phy_device.c +7 -0
@@ -1609,6 +1613,74 @@ static void phy_sfp_link_down(void *upstream)
+static int phy_add_sfp_mod_port(struct phy_device *phydev)
+{
+	const struct sfp_module_caps *caps;
+	struct phy_port *port;
+	int ret = 0;
+
+	/* Create mod port */

drivers/net/phy/phy_device.c static void phy_sfp_link_down(void *upstream) · line 1629

Quoted 10 lines
drivers/net/phy/phy_device.c +10 -0
+	port = phy_port_alloc();
+	if (!port)
+		return -ENOMEM;
+
+	port->active = true;
+
+	caps = sfp_get_module_caps(phydev->sfp_bus);
+
+	phy_caps_linkmode_filter_ifaces(port->supported, caps->link_modes,
+					phydev->sfp_bus_port->interfaces);

At line 1638, phy_add_sfp_mod_port() dereferences phydev->sfp_bus_port without checking for NULL. Can this be NULL here?

Looking at the initialization in phy_sfp_probe(), when sfp_bus_add_upstream() fails, the error path frees the port but then unconditionally stores it in phydev->sfp_bus_port:

Quoted 9 lines
drivers/net/phy/phy_device.c +1 -1
@@ -1700,7 +1774,7 @@ static struct phy_port *phy_setup_sfp_port(struct phy_device *phydev)
 static int phy_sfp_probe(struct phy_device *phydev)
 {
-	struct phy_port *port;
+	struct phy_port *port = NULL;
 	struct sfp_bus *bus;
 	int ret;
 

drivers/net/phy/phy_device.c static int phy_sfp_probe(struct phy_device *phydev) · line 1809

Quoted 7 lines
drivers/net/phy/phy_device.c +2 -0
@@ -1729,6 +1803,8 @@ static int phy_sfp_probe(struct phy_device *phydev)
 		phy_port_destroy(port);
 	}
 
+	phydev->sfp_bus_port = port;
+
 	return ret;
 }

If sfp_bus_add_upstream() returns an error at line 1800, the cleanup path at line 1802 checks 'ret && port', then calls phy_del_port() and phy_port_destroy() to free the port. However, line 1806 still executes 'phydev->sfp_bus_port = port', which assigns the freed pointer to the phydev structure.

When phy_sfp_probe() returns an error, probe fails and the PHY device is not properly initialized. Later, if a PHY-less SFP module is inserted, the SFP subsystem calls phy_sfp_module_start(), which calls phy_add_sfp_mod_port(), which dereferences phydev->sfp_bus_port->interfaces at line 1638.

Should the assignment at line 1806 be conditional, or should port be set to NULL after freeing?

reviewer
#12 lore raw

Re: [PATCH net-next v3 05/11] net: phy: Create SFP phy_port before registering usptream

In reply to Maxime Chevallier
Quoted 13 lines · Maxime Chevallier

Hi Simon,

Quoted 9 lines · Simon Horman

drivers/net/phy/phy_device.c static int phy_setup_sfp_port(struct phy_device *phydev) · line 1727

Quoted 6 lines
drivers/net/phy/phy_device.c +4 -2
-	if (!ret && phydev->sfp_bus)
-		ret = phy_setup_sfp_port(phydev);
+	ret = sfp_bus_add_upstream(bus, phydev, &sfp_phydev_ops);
+	sfp_bus_put(bus);
+
+	if (ret && port) {

Hi Maxime,

Quoted 4 lines
Quoted 1 line

If bus is NULL then port will not be set here.

Arg... I though smatch was running in the NIPA ingst-mdir script, but I was wrong :(

FWWIW, I think it would be nice if it did.
But I'm also not sure how well it works when applied to a full allmodconfig build. Which, AFAIK, is how NIPA tends to run.

Quoted 8 lines

I'll address that in V5 as the problme is still in V4, thank you for the report

Maxime