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: Christophe Leroy <christophe.leroy@csgroup.eu> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Tested-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Maxime Chevallier <maxime.chevallier@bootlin.com> Link: https://patch.msgid.link/20260108080041.553250-10-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
ea317f077a
commit
1384e13838
|
|
@ -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,28 +3609,27 @@ 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);
|
||||
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);
|
||||
|
|
@ -3650,47 +3648,20 @@ 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);
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue