Re: [PATCH net-next v10 07/15] net: phy: Introduce generic SFP handling for PHY drivers
From: Andrew Lunn <andrew@lunn.ch>
Date: 2025-07-26 21:05:45
Also in:
linux-arm-kernel, linux-arm-msm, linux-devicetree, lkml
On Tue, Jul 22, 2025 at 02:16:12PM +0200, Maxime Chevallier wrote:
There are currently 4 PHY drivers that can drive downstream SFPs: marvell.c, marvell10g.c, at803x.c and marvell-88x2222.c. Most of the logic is boilerplate, either calling into generic phylib helpers (for SFP PHY attach, bus attach, etc.) or performing the same tasks with a bit of validation : - Getting the module's expected interface mode - Making sure the PHY supports it - Optionnaly perform some configuration to make sure the PHY outputs
Too man n's.
+static int phy_sfp_module_insert(void *upstream, const struct sfp_eeprom_id *id)
+{
+ struct phy_device *phydev = upstream;
+ struct phy_port *port = phy_get_sfp_port(phydev);Strictly speeding, this is not allowed, reverse Christmas tree... The assignment needs to move into the body of the function.
+ if (linkmode_empty(sfp_support)) {
+ dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
+ return -EINVAL;
+ }
+
+ iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
+
+ /* Check that this interface is supported */
+ if (!test_bit(iface, port->interfaces)) {
+ dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");Maybe make this string different to the previous one, so somebody debugging issues knows which happened?
+/**
+ * phy_get_sfp_port() - Returns the first valid SFP port of a PHY
+ * @phydev: pointer to the PHY device to get the SFP port from
+ *
+ * Returns: The first active SFP (serdes) port of a PHY device, NULL if none
+ * exist.
+ */
+struct phy_port *phy_get_sfp_port(struct phy_device *phydev)
+{
+ struct phy_port *port;
+
+ list_for_each_entry(port, &phydev->ports, head)
+ if (port->active && port->is_mii)Naming is hard, but this actually returns the first mii port. Is there a clear 1:1 mapping? I don't think i've ever seen it, but such a SERDES port could be connected to a Ethernet switch? And when you get further, add support for a MUX, could it be connected to a MUX? Andrew