[PATCH net-next v12 12/18] net: phy: marvell: Support SFP through phy_port interface

Maxime Chevallier posted 18 patches 3 weeks, 2 days ago
There is a newer version of this series
[PATCH net-next v12 12/18] net: phy: marvell: Support SFP through phy_port interface
Posted by Maxime Chevallier 3 weeks, 2 days ago
Convert the Marvell driver (especially the 88e1512 driver) to use the
phy_port interface to handle SFPs. This means registering a
.attach_port() handler to detect when a serdes line interface is used
(most likely, and SFP module).

Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
 drivers/net/phy/marvell.c | 94 ++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 61 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index 623292948fa7..467cf94e2d7f 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -29,10 +29,10 @@
 #include <linux/ethtool.h>
 #include <linux/ethtool_netlink.h>
 #include <linux/phy.h>
+#include <linux/phy_port.h>
 #include <linux/marvell_phy.h>
 #include <linux/bitfield.h>
 #include <linux/of.h>
-#include <linux/sfp.h>
 
 #include <linux/io.h>
 #include <asm/irq.h>
@@ -3561,42 +3561,38 @@ static int marvell_probe(struct phy_device *phydev)
 	return marvell_hwmon_probe(phydev);
 }
 
-static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
+static int m88e1510_port_configure_serdes(struct phy_port *port, bool enable,
+					  phy_interface_t interface)
 {
-	DECLARE_PHY_INTERFACE_MASK(interfaces);
-	struct phy_device *phydev = upstream;
-	phy_interface_t interface;
+	struct phy_device *phydev = port_phydev(port);
 	struct device *dev;
 	int oldpage;
 	int ret = 0;
 	u16 mode;
 
-	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = { 0, };
-
 	dev = &phydev->mdio.dev;
 
-	sfp_parse_support(phydev->sfp_bus, id, supported, interfaces);
-	interface = sfp_select_interface(phydev->sfp_bus, supported);
+	if (enable) {
+		switch (interface) {
+		case PHY_INTERFACE_MODE_1000BASEX:
+			mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X;
 
-	dev_info(dev, "%s SFP module inserted\n", phy_modes(interface));
+			break;
+		case PHY_INTERFACE_MODE_100BASEX:
+			mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX;
 
-	switch (interface) {
-	case PHY_INTERFACE_MODE_1000BASEX:
-		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X;
+			break;
+		case PHY_INTERFACE_MODE_SGMII:
+			mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII;
 
-		break;
-	case PHY_INTERFACE_MODE_100BASEX:
-		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX;
+			break;
+		default:
+			dev_err(dev, "Incompatible SFP module inserted\n");
 
-		break;
-	case PHY_INTERFACE_MODE_SGMII:
-		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII;
-
-		break;
-	default:
-		dev_err(dev, "Incompatible SFP module inserted\n");
-
-		return -EINVAL;
+			return -EINVAL;
+		}
+	} else {
+		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII;
 	}
 
 	oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE);
@@ -3613,49 +3609,24 @@ static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
 
 error:
 	return phy_restore_page(phydev, oldpage, ret);
-}
-
-static void m88e1510_sfp_remove(void *upstream)
-{
-	struct phy_device *phydev = upstream;
-	int oldpage;
-	int ret = 0;
-
-	oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE);
-	if (oldpage < 0)
-		goto error;
-
-	ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1,
-			   MII_88E1510_GEN_CTRL_REG_1_MODE_MASK,
-			   MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII);
-	if (ret < 0)
-		goto error;
-
-	ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1,
-			     MII_88E1510_GEN_CTRL_REG_1_RESET);
 
-error:
-	phy_restore_page(phydev, oldpage, ret);
+	return 0;
 }
 
-static const struct sfp_upstream_ops m88e1510_sfp_ops = {
-	.module_insert = m88e1510_sfp_insert,
-	.module_remove = m88e1510_sfp_remove,
-	.attach = phy_sfp_attach,
-	.detach = phy_sfp_detach,
-	.connect_phy = phy_sfp_connect_phy,
-	.disconnect_phy = phy_sfp_disconnect_phy,
+static const struct phy_port_ops m88e1510_serdes_port_ops = {
+	.configure_mii = m88e1510_port_configure_serdes,
 };
 
-static int m88e1510_probe(struct phy_device *phydev)
+static int m88e1510_attach_mii_port(struct phy_device *phy_device,
+				    struct phy_port *port)
 {
-	int err;
+	port->ops = &m88e1510_serdes_port_ops;
 
-	err = marvell_probe(phydev);
-	if (err)
-		return err;
+	__set_bit(PHY_INTERFACE_MODE_SGMII, port->interfaces);
+	__set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces);
+	__set_bit(PHY_INTERFACE_MODE_100BASEX, port->interfaces);
 
-	return phy_sfp_probe(phydev, &m88e1510_sfp_ops);
+	return 0;
 }
 
 static struct phy_driver marvell_drivers[] = {
@@ -3915,7 +3886,7 @@ static struct phy_driver marvell_drivers[] = {
 		.driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
 		.features = PHY_GBIT_FIBRE_FEATURES,
 		.flags = PHY_POLL_CABLE_TEST,
-		.probe = m88e1510_probe,
+		.probe = marvell_probe,
 		.config_init = m88e1510_config_init,
 		.config_aneg = m88e1510_config_aneg,
 		.read_status = marvell_read_status,
@@ -3941,6 +3912,7 @@ static struct phy_driver marvell_drivers[] = {
 		.led_hw_is_supported = m88e1318_led_hw_is_supported,
 		.led_hw_control_set = m88e1318_led_hw_control_set,
 		.led_hw_control_get = m88e1318_led_hw_control_get,
+		.attach_mii_port = m88e1510_attach_mii_port,
 	},
 	{
 		.phy_id = MARVELL_PHY_ID_88E1540,
-- 
2.49.0
Re: [PATCH net-next v12 12/18] net: phy: marvell: Support SFP through phy_port interface
Posted by Christophe Leroy 2 weeks, 1 day ago

Le 09/09/2025 à 17:26, Maxime Chevallier a écrit :
> Convert the Marvell driver (especially the 88e1512 driver) to use the
> phy_port interface to handle SFPs. This means registering a
> .attach_port() handler to detect when a serdes line interface is used
> (most likely, and SFP module).
> 
> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com>

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>

> ---
>   drivers/net/phy/marvell.c | 94 ++++++++++++++-------------------------
>   1 file changed, 33 insertions(+), 61 deletions(-)
> 
> diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
> index 623292948fa7..467cf94e2d7f 100644
> --- a/drivers/net/phy/marvell.c
> +++ b/drivers/net/phy/marvell.c
> @@ -29,10 +29,10 @@
>   #include <linux/ethtool.h>
>   #include <linux/ethtool_netlink.h>
>   #include <linux/phy.h>
> +#include <linux/phy_port.h>
>   #include <linux/marvell_phy.h>
>   #include <linux/bitfield.h>
>   #include <linux/of.h>
> -#include <linux/sfp.h>
>   
>   #include <linux/io.h>
>   #include <asm/irq.h>
> @@ -3561,42 +3561,38 @@ static int marvell_probe(struct phy_device *phydev)
>   	return marvell_hwmon_probe(phydev);
>   }
>   
> -static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
> +static int m88e1510_port_configure_serdes(struct phy_port *port, bool enable,
> +					  phy_interface_t interface)
>   {
> -	DECLARE_PHY_INTERFACE_MASK(interfaces);
> -	struct phy_device *phydev = upstream;
> -	phy_interface_t interface;
> +	struct phy_device *phydev = port_phydev(port);
>   	struct device *dev;
>   	int oldpage;
>   	int ret = 0;
>   	u16 mode;
>   
> -	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = { 0, };
> -
>   	dev = &phydev->mdio.dev;
>   
> -	sfp_parse_support(phydev->sfp_bus, id, supported, interfaces);
> -	interface = sfp_select_interface(phydev->sfp_bus, supported);
> +	if (enable) {
> +		switch (interface) {
> +		case PHY_INTERFACE_MODE_1000BASEX:
> +			mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X;
>   
> -	dev_info(dev, "%s SFP module inserted\n", phy_modes(interface));
> +			break;
> +		case PHY_INTERFACE_MODE_100BASEX:
> +			mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX;
>   
> -	switch (interface) {
> -	case PHY_INTERFACE_MODE_1000BASEX:
> -		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X;
> +			break;
> +		case PHY_INTERFACE_MODE_SGMII:
> +			mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII;
>   
> -		break;
> -	case PHY_INTERFACE_MODE_100BASEX:
> -		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX;
> +			break;
> +		default:
> +			dev_err(dev, "Incompatible SFP module inserted\n");
>   
> -		break;
> -	case PHY_INTERFACE_MODE_SGMII:
> -		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII;
> -
> -		break;
> -	default:
> -		dev_err(dev, "Incompatible SFP module inserted\n");
> -
> -		return -EINVAL;
> +			return -EINVAL;
> +		}
> +	} else {
> +		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII;
>   	}
>   
>   	oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE);
> @@ -3613,49 +3609,24 @@ static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
>   
>   error:
>   	return phy_restore_page(phydev, oldpage, ret);
> -}
> -
> -static void m88e1510_sfp_remove(void *upstream)
> -{
> -	struct phy_device *phydev = upstream;
> -	int oldpage;
> -	int ret = 0;
> -
> -	oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE);
> -	if (oldpage < 0)
> -		goto error;
> -
> -	ret = __phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1,
> -			   MII_88E1510_GEN_CTRL_REG_1_MODE_MASK,
> -			   MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII);
> -	if (ret < 0)
> -		goto error;
> -
> -	ret = __phy_set_bits(phydev, MII_88E1510_GEN_CTRL_REG_1,
> -			     MII_88E1510_GEN_CTRL_REG_1_RESET);
>   
> -error:
> -	phy_restore_page(phydev, oldpage, ret);
> +	return 0;
>   }
>   
> -static const struct sfp_upstream_ops m88e1510_sfp_ops = {
> -	.module_insert = m88e1510_sfp_insert,
> -	.module_remove = m88e1510_sfp_remove,
> -	.attach = phy_sfp_attach,
> -	.detach = phy_sfp_detach,
> -	.connect_phy = phy_sfp_connect_phy,
> -	.disconnect_phy = phy_sfp_disconnect_phy,
> +static const struct phy_port_ops m88e1510_serdes_port_ops = {
> +	.configure_mii = m88e1510_port_configure_serdes,
>   };
>   
> -static int m88e1510_probe(struct phy_device *phydev)
> +static int m88e1510_attach_mii_port(struct phy_device *phy_device,
> +				    struct phy_port *port)
>   {
> -	int err;
> +	port->ops = &m88e1510_serdes_port_ops;
>   
> -	err = marvell_probe(phydev);
> -	if (err)
> -		return err;
> +	__set_bit(PHY_INTERFACE_MODE_SGMII, port->interfaces);
> +	__set_bit(PHY_INTERFACE_MODE_1000BASEX, port->interfaces);
> +	__set_bit(PHY_INTERFACE_MODE_100BASEX, port->interfaces);
>   
> -	return phy_sfp_probe(phydev, &m88e1510_sfp_ops);
> +	return 0;
>   }
>   
>   static struct phy_driver marvell_drivers[] = {
> @@ -3915,7 +3886,7 @@ static struct phy_driver marvell_drivers[] = {
>   		.driver_data = DEF_MARVELL_HWMON_OPS(m88e1510_hwmon_ops),
>   		.features = PHY_GBIT_FIBRE_FEATURES,
>   		.flags = PHY_POLL_CABLE_TEST,
> -		.probe = m88e1510_probe,
> +		.probe = marvell_probe,
>   		.config_init = m88e1510_config_init,
>   		.config_aneg = m88e1510_config_aneg,
>   		.read_status = marvell_read_status,
> @@ -3941,6 +3912,7 @@ static struct phy_driver marvell_drivers[] = {
>   		.led_hw_is_supported = m88e1318_led_hw_is_supported,
>   		.led_hw_control_set = m88e1318_led_hw_control_set,
>   		.led_hw_control_get = m88e1318_led_hw_control_get,
> +		.attach_mii_port = m88e1510_attach_mii_port,
>   	},
>   	{
>   		.phy_id = MARVELL_PHY_ID_88E1540,