Commit 1384e138 authored by Maxime Chevallier's avatar Maxime Chevallier Committed by Jakub Kicinski
Browse files

net: phy: marvell: Support SFP through phy_port interface



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

Reviewed-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Tested-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarMaxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20260108080041.553250-10-maxime.chevallier@bootlin.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ea317f07
Loading
Loading
Loading
Loading
+32 −60
Original line number Diff line number Diff line
@@ -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>
@@ -3598,11 +3598,10 @@ 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)
{
	struct phy_device *phydev = upstream;
	const struct sfp_module_caps *caps;
	phy_interface_t interface;
	struct phy_device *phydev = port_phydev(port);
	struct device *dev;
	int oldpage;
	int ret = 0;
@@ -3610,11 +3609,7 @@ static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)

	dev = &phydev->mdio.dev;

	caps = sfp_get_module_caps(phydev->sfp_bus);
	interface = sfp_select_interface(phydev->sfp_bus, caps->link_modes);

	dev_info(dev, "%s SFP module inserted\n", phy_modes(interface));

	if (enable) {
		switch (interface) {
		case PHY_INTERFACE_MODE_1000BASEX:
			mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X;
@@ -3633,6 +3628,9 @@ static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)

			return -EINVAL;
		}
	} else {
		mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII;
	}

	oldpage = phy_select_page(phydev, MII_MARVELL_MODE_PAGE);
	if (oldpage < 0)
@@ -3650,47 +3648,20 @@ static int m88e1510_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
	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);
}

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[] = {
@@ -3950,7 +3921,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,
@@ -3976,6 +3947,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,