xref: /linux/drivers/net/phy/marvell10g.c (revision 0d3755428d6990637cf6dc45f007980a1dce28d1)
1a2443fd1SAndrew Lunn // SPDX-License-Identifier: GPL-2.0+
220b2af32SRussell King /*
320b2af32SRussell King  * Marvell 10G 88x3310 PHY driver
420b2af32SRussell King  *
520b2af32SRussell King  * Based upon the ID registers, this PHY appears to be a mixture of IPs
620b2af32SRussell King  * from two different companies.
720b2af32SRussell King  *
820b2af32SRussell King  * There appears to be several different data paths through the PHY which
920b2af32SRussell King  * are automatically managed by the PHY.  The following has been determined
1005ca1b32SRussell King  * via observation and experimentation for a setup using single-lane Serdes:
1120b2af32SRussell King  *
1220b2af32SRussell King  *       SGMII PHYXS -- BASE-T PCS -- 10G PMA -- AN -- Copper (for <= 1G)
1320b2af32SRussell King  *  10GBASE-KR PHYXS -- BASE-T PCS -- 10G PMA -- AN -- Copper (for 10G)
1420b2af32SRussell King  *  10GBASE-KR PHYXS -- BASE-R PCS -- Fiber
1520b2af32SRussell King  *
1605ca1b32SRussell King  * With XAUI, observation shows:
1705ca1b32SRussell King  *
1805ca1b32SRussell King  *        XAUI PHYXS -- <appropriate PCS as above>
1905ca1b32SRussell King  *
2005ca1b32SRussell King  * and no switching of the host interface mode occurs.
2105ca1b32SRussell King  *
2220b2af32SRussell King  * If both the fiber and copper ports are connected, the first to gain
2320b2af32SRussell King  * link takes priority and the other port is completely locked out.
2420b2af32SRussell King  */
250d3ad854SRussell King #include <linux/ctype.h>
268d8963c3SRussell King #include <linux/delay.h>
270d3ad854SRussell King #include <linux/hwmon.h>
28952b6b3bSAntoine Tenart #include <linux/marvell_phy.h>
290d3ad854SRussell King #include <linux/phy.h>
3036023da1SRussell King #include <linux/sfp.h>
3120b2af32SRussell King 
32c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_MASK	0xfffffffe
33c47455f9SMaxime Chevallier #define MV_PHY_ALASKA_NBT_QUIRK_REV	(MARVELL_PHY_ID_88X3310 | 0xa)
34c47455f9SMaxime Chevallier 
3520b2af32SRussell King enum {
36dd649b4fSRussell King 	MV_PMA_FW_VER0		= 0xc011,
37dd649b4fSRussell King 	MV_PMA_FW_VER1		= 0xc012,
383d3ced2eSRussell King 	MV_PMA_BOOT		= 0xc050,
393d3ced2eSRussell King 	MV_PMA_BOOT_FATAL	= BIT(0),
403d3ced2eSRussell King 
4120b2af32SRussell King 	MV_PCS_BASE_T		= 0x0000,
4220b2af32SRussell King 	MV_PCS_BASE_R		= 0x1000,
4320b2af32SRussell King 	MV_PCS_1000BASEX	= 0x2000,
4420b2af32SRussell King 
458d8963c3SRussell King 	MV_PCS_CSCR1		= 0x8000,
46a585c03eSRussell King 	MV_PCS_CSCR1_ED_MASK	= 0x0300,
47a585c03eSRussell King 	MV_PCS_CSCR1_ED_OFF	= 0x0000,
48a585c03eSRussell King 	MV_PCS_CSCR1_ED_RX	= 0x0200,
49a585c03eSRussell King 	MV_PCS_CSCR1_ED_NLP	= 0x0300,
508d8963c3SRussell King 	MV_PCS_CSCR1_MDIX_MASK	= 0x0060,
518d8963c3SRussell King 	MV_PCS_CSCR1_MDIX_MDI	= 0x0000,
528d8963c3SRussell King 	MV_PCS_CSCR1_MDIX_MDIX	= 0x0020,
538d8963c3SRussell King 	MV_PCS_CSCR1_MDIX_AUTO	= 0x0060,
548d8963c3SRussell King 
55c84786faSRussell King 	MV_PCS_CSSR1		= 0x8008,
56c84786faSRussell King 	MV_PCS_CSSR1_SPD1_MASK	= 0xc000,
57c84786faSRussell King 	MV_PCS_CSSR1_SPD1_SPD2	= 0xc000,
58c84786faSRussell King 	MV_PCS_CSSR1_SPD1_1000	= 0x8000,
59c84786faSRussell King 	MV_PCS_CSSR1_SPD1_100	= 0x4000,
60c84786faSRussell King 	MV_PCS_CSSR1_SPD1_10	= 0x0000,
61c84786faSRussell King 	MV_PCS_CSSR1_DUPLEX_FULL= BIT(13),
62c84786faSRussell King 	MV_PCS_CSSR1_RESOLVED	= BIT(11),
63c84786faSRussell King 	MV_PCS_CSSR1_MDIX	= BIT(6),
64c84786faSRussell King 	MV_PCS_CSSR1_SPD2_MASK	= 0x000c,
65c84786faSRussell King 	MV_PCS_CSSR1_SPD2_5000	= 0x0008,
66c84786faSRussell King 	MV_PCS_CSSR1_SPD2_2500	= 0x0004,
67c84786faSRussell King 	MV_PCS_CSSR1_SPD2_10000	= 0x0000,
68ea4efe25SRussell King 
69c3e302edSBaruch Siach 	/* Temperature read register (88E2110 only) */
70c3e302edSBaruch Siach 	MV_PCS_TEMP		= 0x8042,
71c3e302edSBaruch Siach 
7220b2af32SRussell King 	/* These registers appear at 0x800X and 0xa00X - the 0xa00X control
7320b2af32SRussell King 	 * registers appear to set themselves to the 0x800X when AN is
7420b2af32SRussell King 	 * restarted, but status registers appear readable from either.
7520b2af32SRussell King 	 */
7620b2af32SRussell King 	MV_AN_CTRL1000		= 0x8000, /* 1000base-T control register */
7720b2af32SRussell King 	MV_AN_STAT1000		= 0x8001, /* 1000base-T status register */
780d3ad854SRussell King 
790d3ad854SRussell King 	/* Vendor2 MMD registers */
80af3e28cbSAntoine Tenart 	MV_V2_PORT_CTRL		= 0xf001,
818f48c2acSRussell King 	MV_V2_PORT_CTRL_SWRST	= BIT(15),
828f48c2acSRussell King 	MV_V2_PORT_CTRL_PWRDOWN	= BIT(11),
83bd79d9aaSMarek Behún 	MV_V2_PORT_CTRL_MACTYPE_MASK = 0x7,
84bd79d9aaSMarek Behún 	MV_V2_PORT_CTRL_MACTYPE_RATE_MATCH = 0x6,
85c3e302edSBaruch Siach 	/* Temperature control/read registers (88X3310 only) */
860d3ad854SRussell King 	MV_V2_TEMP_CTRL		= 0xf08a,
870d3ad854SRussell King 	MV_V2_TEMP_CTRL_MASK	= 0xc000,
880d3ad854SRussell King 	MV_V2_TEMP_CTRL_SAMPLE	= 0x0000,
890d3ad854SRussell King 	MV_V2_TEMP_CTRL_DISABLE	= 0xc000,
900d3ad854SRussell King 	MV_V2_TEMP		= 0xf08c,
910d3ad854SRussell King 	MV_V2_TEMP_UNKNOWN	= 0x9600, /* unknown function */
920d3ad854SRussell King };
930d3ad854SRussell King 
940d3ad854SRussell King struct mv3310_priv {
95dd649b4fSRussell King 	u32 firmware_ver;
96e1170333SBaruch Siach 	bool rate_match;
97dd649b4fSRussell King 
980d3ad854SRussell King 	struct device *hwmon_dev;
990d3ad854SRussell King 	char *hwmon_name;
10020b2af32SRussell King };
10120b2af32SRussell King 
1020d3ad854SRussell King #ifdef CONFIG_HWMON
1030d3ad854SRussell King static umode_t mv3310_hwmon_is_visible(const void *data,
1040d3ad854SRussell King 				       enum hwmon_sensor_types type,
1050d3ad854SRussell King 				       u32 attr, int channel)
1060d3ad854SRussell King {
1070d3ad854SRussell King 	if (type == hwmon_chip && attr == hwmon_chip_update_interval)
1080d3ad854SRussell King 		return 0444;
1090d3ad854SRussell King 	if (type == hwmon_temp && attr == hwmon_temp_input)
1100d3ad854SRussell King 		return 0444;
1110d3ad854SRussell King 	return 0;
1120d3ad854SRussell King }
1130d3ad854SRussell King 
114c3e302edSBaruch Siach static int mv3310_hwmon_read_temp_reg(struct phy_device *phydev)
115c3e302edSBaruch Siach {
116c3e302edSBaruch Siach 	return phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP);
117c3e302edSBaruch Siach }
118c3e302edSBaruch Siach 
119c3e302edSBaruch Siach static int mv2110_hwmon_read_temp_reg(struct phy_device *phydev)
120c3e302edSBaruch Siach {
121c3e302edSBaruch Siach 	return phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_TEMP);
122c3e302edSBaruch Siach }
123c3e302edSBaruch Siach 
124c3e302edSBaruch Siach static int mv10g_hwmon_read_temp_reg(struct phy_device *phydev)
125c3e302edSBaruch Siach {
126c3e302edSBaruch Siach 	if (phydev->drv->phy_id == MARVELL_PHY_ID_88X3310)
127c3e302edSBaruch Siach 		return mv3310_hwmon_read_temp_reg(phydev);
128c3e302edSBaruch Siach 	else /* MARVELL_PHY_ID_88E2110 */
129c3e302edSBaruch Siach 		return mv2110_hwmon_read_temp_reg(phydev);
130c3e302edSBaruch Siach }
131c3e302edSBaruch Siach 
1320d3ad854SRussell King static int mv3310_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
1330d3ad854SRussell King 			     u32 attr, int channel, long *value)
1340d3ad854SRussell King {
1350d3ad854SRussell King 	struct phy_device *phydev = dev_get_drvdata(dev);
1360d3ad854SRussell King 	int temp;
1370d3ad854SRussell King 
1380d3ad854SRussell King 	if (type == hwmon_chip && attr == hwmon_chip_update_interval) {
1390d3ad854SRussell King 		*value = MSEC_PER_SEC;
1400d3ad854SRussell King 		return 0;
1410d3ad854SRussell King 	}
1420d3ad854SRussell King 
1430d3ad854SRussell King 	if (type == hwmon_temp && attr == hwmon_temp_input) {
144c3e302edSBaruch Siach 		temp = mv10g_hwmon_read_temp_reg(phydev);
1450d3ad854SRussell King 		if (temp < 0)
1460d3ad854SRussell King 			return temp;
1470d3ad854SRussell King 
1480d3ad854SRussell King 		*value = ((temp & 0xff) - 75) * 1000;
1490d3ad854SRussell King 
1500d3ad854SRussell King 		return 0;
1510d3ad854SRussell King 	}
1520d3ad854SRussell King 
1530d3ad854SRussell King 	return -EOPNOTSUPP;
1540d3ad854SRussell King }
1550d3ad854SRussell King 
1560d3ad854SRussell King static const struct hwmon_ops mv3310_hwmon_ops = {
1570d3ad854SRussell King 	.is_visible = mv3310_hwmon_is_visible,
1580d3ad854SRussell King 	.read = mv3310_hwmon_read,
1590d3ad854SRussell King };
1600d3ad854SRussell King 
1610d3ad854SRussell King static u32 mv3310_hwmon_chip_config[] = {
1620d3ad854SRussell King 	HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL,
1630d3ad854SRussell King 	0,
1640d3ad854SRussell King };
1650d3ad854SRussell King 
1660d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_chip = {
1670d3ad854SRussell King 	.type = hwmon_chip,
1680d3ad854SRussell King 	.config = mv3310_hwmon_chip_config,
1690d3ad854SRussell King };
1700d3ad854SRussell King 
1710d3ad854SRussell King static u32 mv3310_hwmon_temp_config[] = {
1720d3ad854SRussell King 	HWMON_T_INPUT,
1730d3ad854SRussell King 	0,
1740d3ad854SRussell King };
1750d3ad854SRussell King 
1760d3ad854SRussell King static const struct hwmon_channel_info mv3310_hwmon_temp = {
1770d3ad854SRussell King 	.type = hwmon_temp,
1780d3ad854SRussell King 	.config = mv3310_hwmon_temp_config,
1790d3ad854SRussell King };
1800d3ad854SRussell King 
1810d3ad854SRussell King static const struct hwmon_channel_info *mv3310_hwmon_info[] = {
1820d3ad854SRussell King 	&mv3310_hwmon_chip,
1830d3ad854SRussell King 	&mv3310_hwmon_temp,
1840d3ad854SRussell King 	NULL,
1850d3ad854SRussell King };
1860d3ad854SRussell King 
1870d3ad854SRussell King static const struct hwmon_chip_info mv3310_hwmon_chip_info = {
1880d3ad854SRussell King 	.ops = &mv3310_hwmon_ops,
1890d3ad854SRussell King 	.info = mv3310_hwmon_info,
1900d3ad854SRussell King };
1910d3ad854SRussell King 
1920d3ad854SRussell King static int mv3310_hwmon_config(struct phy_device *phydev, bool enable)
1930d3ad854SRussell King {
1940d3ad854SRussell King 	u16 val;
1950d3ad854SRussell King 	int ret;
1960d3ad854SRussell King 
197c3e302edSBaruch Siach 	if (phydev->drv->phy_id != MARVELL_PHY_ID_88X3310)
198c3e302edSBaruch Siach 		return 0;
199c3e302edSBaruch Siach 
2000d3ad854SRussell King 	ret = phy_write_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP,
2010d3ad854SRussell King 			    MV_V2_TEMP_UNKNOWN);
2020d3ad854SRussell King 	if (ret < 0)
2030d3ad854SRussell King 		return ret;
2040d3ad854SRussell King 
2050d3ad854SRussell King 	val = enable ? MV_V2_TEMP_CTRL_SAMPLE : MV_V2_TEMP_CTRL_DISABLE;
2060d3ad854SRussell King 
207b06d8e5aSHeiner Kallweit 	return phy_modify_mmd(phydev, MDIO_MMD_VEND2, MV_V2_TEMP_CTRL,
208b06d8e5aSHeiner Kallweit 			      MV_V2_TEMP_CTRL_MASK, val);
2090d3ad854SRussell King }
2100d3ad854SRussell King 
2110d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev)
2120d3ad854SRussell King {
2130d3ad854SRussell King 	struct device *dev = &phydev->mdio.dev;
2140d3ad854SRussell King 	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
2150d3ad854SRussell King 	int i, j, ret;
2160d3ad854SRussell King 
2170d3ad854SRussell King 	priv->hwmon_name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL);
2180d3ad854SRussell King 	if (!priv->hwmon_name)
2190d3ad854SRussell King 		return -ENODEV;
2200d3ad854SRussell King 
2210d3ad854SRussell King 	for (i = j = 0; priv->hwmon_name[i]; i++) {
2220d3ad854SRussell King 		if (isalnum(priv->hwmon_name[i])) {
2230d3ad854SRussell King 			if (i != j)
2240d3ad854SRussell King 				priv->hwmon_name[j] = priv->hwmon_name[i];
2250d3ad854SRussell King 			j++;
2260d3ad854SRussell King 		}
2270d3ad854SRussell King 	}
2280d3ad854SRussell King 	priv->hwmon_name[j] = '\0';
2290d3ad854SRussell King 
2300d3ad854SRussell King 	ret = mv3310_hwmon_config(phydev, true);
2310d3ad854SRussell King 	if (ret)
2320d3ad854SRussell King 		return ret;
2330d3ad854SRussell King 
2340d3ad854SRussell King 	priv->hwmon_dev = devm_hwmon_device_register_with_info(dev,
2350d3ad854SRussell King 				priv->hwmon_name, phydev,
2360d3ad854SRussell King 				&mv3310_hwmon_chip_info, NULL);
2370d3ad854SRussell King 
2380d3ad854SRussell King 	return PTR_ERR_OR_ZERO(priv->hwmon_dev);
2390d3ad854SRussell King }
2400d3ad854SRussell King #else
2410d3ad854SRussell King static inline int mv3310_hwmon_config(struct phy_device *phydev, bool enable)
2420d3ad854SRussell King {
2430d3ad854SRussell King 	return 0;
2440d3ad854SRussell King }
2450d3ad854SRussell King 
2460d3ad854SRussell King static int mv3310_hwmon_probe(struct phy_device *phydev)
2470d3ad854SRussell King {
2480d3ad854SRussell King 	return 0;
2490d3ad854SRussell King }
2500d3ad854SRussell King #endif
2510d3ad854SRussell King 
252c9cc1c81SRussell King static int mv3310_power_down(struct phy_device *phydev)
253c9cc1c81SRussell King {
254c9cc1c81SRussell King 	return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
255c9cc1c81SRussell King 				MV_V2_PORT_CTRL_PWRDOWN);
256c9cc1c81SRussell King }
257c9cc1c81SRussell King 
258c9cc1c81SRussell King static int mv3310_power_up(struct phy_device *phydev)
259c9cc1c81SRussell King {
2608f48c2acSRussell King 	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
2618f48c2acSRussell King 	int ret;
2628f48c2acSRussell King 
2638f48c2acSRussell King 	ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
264c9cc1c81SRussell King 				 MV_V2_PORT_CTRL_PWRDOWN);
2658f48c2acSRussell King 
266829e7573SBaruch Siach 	if (phydev->drv->phy_id != MARVELL_PHY_ID_88X3310 ||
267829e7573SBaruch Siach 	    priv->firmware_ver < 0x00030000)
2688f48c2acSRussell King 		return ret;
2698f48c2acSRussell King 
2708f48c2acSRussell King 	return phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL,
2718f48c2acSRussell King 				MV_V2_PORT_CTRL_SWRST);
272c9cc1c81SRussell King }
273c9cc1c81SRussell King 
2748d8963c3SRussell King static int mv3310_reset(struct phy_device *phydev, u32 unit)
2758d8963c3SRussell King {
2768964a217SDejin Zheng 	int val, err;
2778d8963c3SRussell King 
2788d8963c3SRussell King 	err = phy_modify_mmd(phydev, MDIO_MMD_PCS, unit + MDIO_CTRL1,
2798d8963c3SRussell King 			     MDIO_CTRL1_RESET, MDIO_CTRL1_RESET);
2808d8963c3SRussell King 	if (err < 0)
2818d8963c3SRussell King 		return err;
2828d8963c3SRussell King 
2838964a217SDejin Zheng 	return phy_read_mmd_poll_timeout(phydev, MDIO_MMD_PCS,
2848964a217SDejin Zheng 					 unit + MDIO_CTRL1, val,
2858964a217SDejin Zheng 					 !(val & MDIO_CTRL1_RESET),
2868964a217SDejin Zheng 					 5000, 100000, true);
2878d8963c3SRussell King }
2888d8963c3SRussell King 
289a585c03eSRussell King static int mv3310_get_edpd(struct phy_device *phydev, u16 *edpd)
290a585c03eSRussell King {
291a585c03eSRussell King 	int val;
292a585c03eSRussell King 
293a585c03eSRussell King 	val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1);
294a585c03eSRussell King 	if (val < 0)
295a585c03eSRussell King 		return val;
296a585c03eSRussell King 
297a585c03eSRussell King 	switch (val & MV_PCS_CSCR1_ED_MASK) {
298a585c03eSRussell King 	case MV_PCS_CSCR1_ED_NLP:
299a585c03eSRussell King 		*edpd = 1000;
300a585c03eSRussell King 		break;
301a585c03eSRussell King 	case MV_PCS_CSCR1_ED_RX:
302a585c03eSRussell King 		*edpd = ETHTOOL_PHY_EDPD_NO_TX;
303a585c03eSRussell King 		break;
304a585c03eSRussell King 	default:
305a585c03eSRussell King 		*edpd = ETHTOOL_PHY_EDPD_DISABLE;
306a585c03eSRussell King 		break;
307a585c03eSRussell King 	}
308a585c03eSRussell King 	return 0;
309a585c03eSRussell King }
310a585c03eSRussell King 
311a585c03eSRussell King static int mv3310_set_edpd(struct phy_device *phydev, u16 edpd)
312a585c03eSRussell King {
313a585c03eSRussell King 	u16 val;
314a585c03eSRussell King 	int err;
315a585c03eSRussell King 
316a585c03eSRussell King 	switch (edpd) {
317a585c03eSRussell King 	case 1000:
318a585c03eSRussell King 	case ETHTOOL_PHY_EDPD_DFLT_TX_MSECS:
319a585c03eSRussell King 		val = MV_PCS_CSCR1_ED_NLP;
320a585c03eSRussell King 		break;
321a585c03eSRussell King 
322a585c03eSRussell King 	case ETHTOOL_PHY_EDPD_NO_TX:
323a585c03eSRussell King 		val = MV_PCS_CSCR1_ED_RX;
324a585c03eSRussell King 		break;
325a585c03eSRussell King 
326a585c03eSRussell King 	case ETHTOOL_PHY_EDPD_DISABLE:
327a585c03eSRussell King 		val = MV_PCS_CSCR1_ED_OFF;
328a585c03eSRussell King 		break;
329a585c03eSRussell King 
330a585c03eSRussell King 	default:
331a585c03eSRussell King 		return -EINVAL;
332a585c03eSRussell King 	}
333a585c03eSRussell King 
334a585c03eSRussell King 	err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1,
335a585c03eSRussell King 				     MV_PCS_CSCR1_ED_MASK, val);
336a585c03eSRussell King 	if (err > 0)
337a585c03eSRussell King 		err = mv3310_reset(phydev, MV_PCS_BASE_T);
338a585c03eSRussell King 
339a585c03eSRussell King 	return err;
340a585c03eSRussell King }
341a585c03eSRussell King 
34236023da1SRussell King static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
34336023da1SRussell King {
34436023da1SRussell King 	struct phy_device *phydev = upstream;
34536023da1SRussell King 	__ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
34636023da1SRussell King 	phy_interface_t iface;
34736023da1SRussell King 
34836023da1SRussell King 	sfp_parse_support(phydev->sfp_bus, id, support);
349a4516c70SRussell King 	iface = sfp_select_interface(phydev->sfp_bus, support);
35036023da1SRussell King 
351e0f909bcSRussell King 	if (iface != PHY_INTERFACE_MODE_10GBASER) {
35236023da1SRussell King 		dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
35336023da1SRussell King 		return -EINVAL;
35436023da1SRussell King 	}
35536023da1SRussell King 	return 0;
35636023da1SRussell King }
35736023da1SRussell King 
35836023da1SRussell King static const struct sfp_upstream_ops mv3310_sfp_ops = {
35936023da1SRussell King 	.attach = phy_sfp_attach,
36036023da1SRussell King 	.detach = phy_sfp_detach,
36136023da1SRussell King 	.module_insert = mv3310_sfp_insert,
36236023da1SRussell King };
36336023da1SRussell King 
36420b2af32SRussell King static int mv3310_probe(struct phy_device *phydev)
36520b2af32SRussell King {
3660d3ad854SRussell King 	struct mv3310_priv *priv;
36720b2af32SRussell King 	u32 mmd_mask = MDIO_DEVS_PMAPMD | MDIO_DEVS_AN;
3680d3ad854SRussell King 	int ret;
36920b2af32SRussell King 
37020b2af32SRussell King 	if (!phydev->is_c45 ||
37120b2af32SRussell King 	    (phydev->c45_ids.devices_in_package & mmd_mask) != mmd_mask)
37220b2af32SRussell King 		return -ENODEV;
37320b2af32SRussell King 
3743d3ced2eSRussell King 	ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_BOOT);
3753d3ced2eSRussell King 	if (ret < 0)
3763d3ced2eSRussell King 		return ret;
3773d3ced2eSRussell King 
3783d3ced2eSRussell King 	if (ret & MV_PMA_BOOT_FATAL) {
3793d3ced2eSRussell King 		dev_warn(&phydev->mdio.dev,
3803d3ced2eSRussell King 			 "PHY failed to boot firmware, status=%04x\n", ret);
3813d3ced2eSRussell King 		return -ENODEV;
3823d3ced2eSRussell King 	}
3833d3ced2eSRussell King 
3840d3ad854SRussell King 	priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
3850d3ad854SRussell King 	if (!priv)
3860d3ad854SRussell King 		return -ENOMEM;
3870d3ad854SRussell King 
3880d3ad854SRussell King 	dev_set_drvdata(&phydev->mdio.dev, priv);
3890d3ad854SRussell King 
390dd649b4fSRussell King 	ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_FW_VER0);
391dd649b4fSRussell King 	if (ret < 0)
392dd649b4fSRussell King 		return ret;
393dd649b4fSRussell King 
394dd649b4fSRussell King 	priv->firmware_ver = ret << 16;
395dd649b4fSRussell King 
396dd649b4fSRussell King 	ret = phy_read_mmd(phydev, MDIO_MMD_PMAPMD, MV_PMA_FW_VER1);
397dd649b4fSRussell King 	if (ret < 0)
398dd649b4fSRussell King 		return ret;
399dd649b4fSRussell King 
400dd649b4fSRussell King 	priv->firmware_ver |= ret;
401dd649b4fSRussell King 
402dd649b4fSRussell King 	phydev_info(phydev, "Firmware version %u.%u.%u.%u\n",
403dd649b4fSRussell King 		    priv->firmware_ver >> 24, (priv->firmware_ver >> 16) & 255,
404dd649b4fSRussell King 		    (priv->firmware_ver >> 8) & 255, priv->firmware_ver & 255);
405dd649b4fSRussell King 
406c9cc1c81SRussell King 	/* Powering down the port when not in use saves about 600mW */
407c9cc1c81SRussell King 	ret = mv3310_power_down(phydev);
408c9cc1c81SRussell King 	if (ret)
409c9cc1c81SRussell King 		return ret;
410c9cc1c81SRussell King 
4110d3ad854SRussell King 	ret = mv3310_hwmon_probe(phydev);
4120d3ad854SRussell King 	if (ret)
4130d3ad854SRussell King 		return ret;
4140d3ad854SRussell King 
41536023da1SRussell King 	return phy_sfp_probe(phydev, &mv3310_sfp_ops);
41620b2af32SRussell King }
41720b2af32SRussell King 
4181b8ef142SMarek Behún static void mv3310_remove(struct phy_device *phydev)
4191b8ef142SMarek Behún {
4201b8ef142SMarek Behún 	mv3310_hwmon_config(phydev, false);
4211b8ef142SMarek Behún }
4221b8ef142SMarek Behún 
4230d3ad854SRussell King static int mv3310_suspend(struct phy_device *phydev)
4240d3ad854SRussell King {
425c9cc1c81SRussell King 	return mv3310_power_down(phydev);
4260d3ad854SRussell King }
4270d3ad854SRussell King 
4280d3ad854SRussell King static int mv3310_resume(struct phy_device *phydev)
4290d3ad854SRussell King {
430af3e28cbSAntoine Tenart 	int ret;
431af3e28cbSAntoine Tenart 
432c9cc1c81SRussell King 	ret = mv3310_power_up(phydev);
433af3e28cbSAntoine Tenart 	if (ret)
434af3e28cbSAntoine Tenart 		return ret;
435af3e28cbSAntoine Tenart 
4360d3ad854SRussell King 	return mv3310_hwmon_config(phydev, true);
4370d3ad854SRussell King }
4380d3ad854SRussell King 
439c47455f9SMaxime Chevallier /* Some PHYs in the Alaska family such as the 88X3310 and the 88E2010
440c47455f9SMaxime Chevallier  * don't set bit 14 in PMA Extended Abilities (1.11), although they do
441c47455f9SMaxime Chevallier  * support 2.5GBASET and 5GBASET. For these models, we can still read their
442c47455f9SMaxime Chevallier  * 2.5G/5G extended abilities register (1.21). We detect these models based on
443c47455f9SMaxime Chevallier  * the PMA device identifier, with a mask matching models known to have this
444c47455f9SMaxime Chevallier  * issue
445c47455f9SMaxime Chevallier  */
446c47455f9SMaxime Chevallier static bool mv3310_has_pma_ngbaset_quirk(struct phy_device *phydev)
447c47455f9SMaxime Chevallier {
448c47455f9SMaxime Chevallier 	if (!(phydev->c45_ids.devices_in_package & MDIO_DEVS_PMAPMD))
449c47455f9SMaxime Chevallier 		return false;
450c47455f9SMaxime Chevallier 
451c47455f9SMaxime Chevallier 	/* Only some revisions of the 88X3310 family PMA seem to be impacted */
452c47455f9SMaxime Chevallier 	return (phydev->c45_ids.device_ids[MDIO_MMD_PMAPMD] &
453c47455f9SMaxime Chevallier 		MV_PHY_ALASKA_NBT_QUIRK_MASK) == MV_PHY_ALASKA_NBT_QUIRK_REV;
454c47455f9SMaxime Chevallier }
455c47455f9SMaxime Chevallier 
45620b2af32SRussell King static int mv3310_config_init(struct phy_device *phydev)
45720b2af32SRussell King {
458e1170333SBaruch Siach 	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
459c9cc1c81SRussell King 	int err;
460e1170333SBaruch Siach 	int val;
461c9cc1c81SRussell King 
46220b2af32SRussell King 	/* Check that the PHY interface type is compatible */
46320b2af32SRussell King 	if (phydev->interface != PHY_INTERFACE_MODE_SGMII &&
464e555e5b1SMaxime Chevallier 	    phydev->interface != PHY_INTERFACE_MODE_2500BASEX &&
465*0d375542SMarek Behún 	    phydev->interface != PHY_INTERFACE_MODE_5GBASER &&
46620b2af32SRussell King 	    phydev->interface != PHY_INTERFACE_MODE_XAUI &&
46720b2af32SRussell King 	    phydev->interface != PHY_INTERFACE_MODE_RXAUI &&
468*0d375542SMarek Behún 	    phydev->interface != PHY_INTERFACE_MODE_10GBASER &&
469*0d375542SMarek Behún 	    phydev->interface != PHY_INTERFACE_MODE_USXGMII)
47020b2af32SRussell King 		return -ENODEV;
47120b2af32SRussell King 
4728d8963c3SRussell King 	phydev->mdix_ctrl = ETH_TP_MDI_AUTO;
4738d8963c3SRussell King 
474c9cc1c81SRussell King 	/* Power up so reset works */
475c9cc1c81SRussell King 	err = mv3310_power_up(phydev);
476c9cc1c81SRussell King 	if (err)
477c9cc1c81SRussell King 		return err;
478c9cc1c81SRussell King 
479e1170333SBaruch Siach 	val = phy_read_mmd(phydev, MDIO_MMD_VEND2, MV_V2_PORT_CTRL);
480e1170333SBaruch Siach 	if (val < 0)
481e1170333SBaruch Siach 		return val;
482bd79d9aaSMarek Behún 	priv->rate_match = ((val & MV_V2_PORT_CTRL_MACTYPE_MASK) ==
483bd79d9aaSMarek Behún 			MV_V2_PORT_CTRL_MACTYPE_RATE_MATCH);
484e1170333SBaruch Siach 
485a585c03eSRussell King 	/* Enable EDPD mode - saving 600mW */
486a585c03eSRussell King 	return mv3310_set_edpd(phydev, ETHTOOL_PHY_EDPD_DFLT_TX_MSECS);
48774145424SMaxime Chevallier }
48874145424SMaxime Chevallier 
48974145424SMaxime Chevallier static int mv3310_get_features(struct phy_device *phydev)
49074145424SMaxime Chevallier {
49174145424SMaxime Chevallier 	int ret, val;
49274145424SMaxime Chevallier 
493ac3f5533SMaxime Chevallier 	ret = genphy_c45_pma_read_abilities(phydev);
494ac3f5533SMaxime Chevallier 	if (ret)
495ac3f5533SMaxime Chevallier 		return ret;
49620b2af32SRussell King 
497c47455f9SMaxime Chevallier 	if (mv3310_has_pma_ngbaset_quirk(phydev)) {
498c47455f9SMaxime Chevallier 		val = phy_read_mmd(phydev, MDIO_MMD_PMAPMD,
499c47455f9SMaxime Chevallier 				   MDIO_PMA_NG_EXTABLE);
500c47455f9SMaxime Chevallier 		if (val < 0)
501c47455f9SMaxime Chevallier 			return val;
502c47455f9SMaxime Chevallier 
503c47455f9SMaxime Chevallier 		linkmode_mod_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
504c47455f9SMaxime Chevallier 				 phydev->supported,
505c47455f9SMaxime Chevallier 				 val & MDIO_PMA_NG_EXTABLE_2_5GBT);
506c47455f9SMaxime Chevallier 
507c47455f9SMaxime Chevallier 		linkmode_mod_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
508c47455f9SMaxime Chevallier 				 phydev->supported,
509c47455f9SMaxime Chevallier 				 val & MDIO_PMA_NG_EXTABLE_5GBT);
510c47455f9SMaxime Chevallier 	}
511c47455f9SMaxime Chevallier 
51220b2af32SRussell King 	return 0;
51320b2af32SRussell King }
51420b2af32SRussell King 
5158d8963c3SRussell King static int mv3310_config_mdix(struct phy_device *phydev)
5168d8963c3SRussell King {
5178d8963c3SRussell King 	u16 val;
5188d8963c3SRussell King 	int err;
5198d8963c3SRussell King 
5208d8963c3SRussell King 	switch (phydev->mdix_ctrl) {
5218d8963c3SRussell King 	case ETH_TP_MDI_AUTO:
5228d8963c3SRussell King 		val = MV_PCS_CSCR1_MDIX_AUTO;
5238d8963c3SRussell King 		break;
5248d8963c3SRussell King 	case ETH_TP_MDI_X:
5258d8963c3SRussell King 		val = MV_PCS_CSCR1_MDIX_MDIX;
5268d8963c3SRussell King 		break;
5278d8963c3SRussell King 	case ETH_TP_MDI:
5288d8963c3SRussell King 		val = MV_PCS_CSCR1_MDIX_MDI;
5298d8963c3SRussell King 		break;
5308d8963c3SRussell King 	default:
5318d8963c3SRussell King 		return -EINVAL;
5328d8963c3SRussell King 	}
5338d8963c3SRussell King 
5348d8963c3SRussell King 	err = phy_modify_mmd_changed(phydev, MDIO_MMD_PCS, MV_PCS_CSCR1,
5358d8963c3SRussell King 				     MV_PCS_CSCR1_MDIX_MASK, val);
5368d8963c3SRussell King 	if (err > 0)
5378d8963c3SRussell King 		err = mv3310_reset(phydev, MV_PCS_BASE_T);
5388d8963c3SRussell King 
5398d8963c3SRussell King 	return err;
5408d8963c3SRussell King }
5418d8963c3SRussell King 
54220b2af32SRussell King static int mv3310_config_aneg(struct phy_device *phydev)
54320b2af32SRussell King {
54420b2af32SRussell King 	bool changed = false;
5453c1bcc86SAndrew Lunn 	u16 reg;
54620b2af32SRussell King 	int ret;
54720b2af32SRussell King 
5488d8963c3SRussell King 	ret = mv3310_config_mdix(phydev);
5498d8963c3SRussell King 	if (ret < 0)
5508d8963c3SRussell King 		return ret;
551ea4efe25SRussell King 
55230de65c3SHeiner Kallweit 	if (phydev->autoneg == AUTONEG_DISABLE)
55330de65c3SHeiner Kallweit 		return genphy_c45_pma_setup_forced(phydev);
55420b2af32SRussell King 
5553de97f3cSAndrew Lunn 	ret = genphy_c45_an_config_aneg(phydev);
55620b2af32SRussell King 	if (ret < 0)
55720b2af32SRussell King 		return ret;
55820b2af32SRussell King 	if (ret > 0)
55920b2af32SRussell King 		changed = true;
56020b2af32SRussell King 
5613de97f3cSAndrew Lunn 	/* Clause 45 has no standardized support for 1000BaseT, therefore
5623de97f3cSAndrew Lunn 	 * use vendor registers for this mode.
5633de97f3cSAndrew Lunn 	 */
5643c1bcc86SAndrew Lunn 	reg = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
565b06d8e5aSHeiner Kallweit 	ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MV_AN_CTRL1000,
5663c1bcc86SAndrew Lunn 			     ADVERTISE_1000FULL | ADVERTISE_1000HALF, reg);
56720b2af32SRussell King 	if (ret < 0)
56820b2af32SRussell King 		return ret;
56920b2af32SRussell King 	if (ret > 0)
57020b2af32SRussell King 		changed = true;
57120b2af32SRussell King 
5726b4cb6cbSHeiner Kallweit 	return genphy_c45_check_and_restart_aneg(phydev, changed);
57320b2af32SRussell King }
57420b2af32SRussell King 
57520b2af32SRussell King static int mv3310_aneg_done(struct phy_device *phydev)
57620b2af32SRussell King {
57720b2af32SRussell King 	int val;
57820b2af32SRussell King 
57920b2af32SRussell King 	val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1);
58020b2af32SRussell King 	if (val < 0)
58120b2af32SRussell King 		return val;
58220b2af32SRussell King 
58320b2af32SRussell King 	if (val & MDIO_STAT1_LSTATUS)
58420b2af32SRussell King 		return 1;
58520b2af32SRussell King 
58620b2af32SRussell King 	return genphy_c45_aneg_done(phydev);
58720b2af32SRussell King }
58820b2af32SRussell King 
58936c4449aSRussell King static void mv3310_update_interface(struct phy_device *phydev)
59036c4449aSRussell King {
591e1170333SBaruch Siach 	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
592e1170333SBaruch Siach 
593e1170333SBaruch Siach 	/* In "XFI with Rate Matching" mode the PHY interface is fixed at
594e1170333SBaruch Siach 	 * 10Gb. The PHY adapts the rate to actual wire speed with help of
595e1170333SBaruch Siach 	 * internal 16KB buffer.
596e1170333SBaruch Siach 	 */
597e1170333SBaruch Siach 	if (priv->rate_match) {
598e1170333SBaruch Siach 		phydev->interface = PHY_INTERFACE_MODE_10GBASER;
599e1170333SBaruch Siach 		return;
600e1170333SBaruch Siach 	}
601e1170333SBaruch Siach 
60236c4449aSRussell King 	if ((phydev->interface == PHY_INTERFACE_MODE_SGMII ||
603e555e5b1SMaxime Chevallier 	     phydev->interface == PHY_INTERFACE_MODE_2500BASEX ||
604*0d375542SMarek Behún 	     phydev->interface == PHY_INTERFACE_MODE_5GBASER ||
605e0f909bcSRussell King 	     phydev->interface == PHY_INTERFACE_MODE_10GBASER) &&
606e0f909bcSRussell King 	    phydev->link) {
60736c4449aSRussell King 		/* The PHY automatically switches its serdes interface (and
608e0f909bcSRussell King 		 * active PHYXS instance) between Cisco SGMII, 10GBase-R and
609e555e5b1SMaxime Chevallier 		 * 2500BaseX modes according to the speed.  Florian suggests
610e555e5b1SMaxime Chevallier 		 * setting phydev->interface to communicate this to the MAC.
611e555e5b1SMaxime Chevallier 		 * Only do this if we are already in one of the above modes.
61236c4449aSRussell King 		 */
613e555e5b1SMaxime Chevallier 		switch (phydev->speed) {
614e555e5b1SMaxime Chevallier 		case SPEED_10000:
615e0f909bcSRussell King 			phydev->interface = PHY_INTERFACE_MODE_10GBASER;
616e555e5b1SMaxime Chevallier 			break;
617*0d375542SMarek Behún 		case SPEED_5000:
618*0d375542SMarek Behún 			phydev->interface = PHY_INTERFACE_MODE_5GBASER;
619*0d375542SMarek Behún 			break;
620e555e5b1SMaxime Chevallier 		case SPEED_2500:
621e555e5b1SMaxime Chevallier 			phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
622e555e5b1SMaxime Chevallier 			break;
623e555e5b1SMaxime Chevallier 		case SPEED_1000:
624e555e5b1SMaxime Chevallier 		case SPEED_100:
625e555e5b1SMaxime Chevallier 		case SPEED_10:
62636c4449aSRussell King 			phydev->interface = PHY_INTERFACE_MODE_SGMII;
627e555e5b1SMaxime Chevallier 			break;
628e555e5b1SMaxime Chevallier 		default:
629e555e5b1SMaxime Chevallier 			break;
630e555e5b1SMaxime Chevallier 		}
63136c4449aSRussell King 	}
63236c4449aSRussell King }
63336c4449aSRussell King 
63420b2af32SRussell King /* 10GBASE-ER,LR,LRM,SR do not support autonegotiation. */
635c84786faSRussell King static int mv3310_read_status_10gbaser(struct phy_device *phydev)
63620b2af32SRussell King {
63720b2af32SRussell King 	phydev->link = 1;
63820b2af32SRussell King 	phydev->speed = SPEED_10000;
63920b2af32SRussell King 	phydev->duplex = DUPLEX_FULL;
6404217a64eSMichael Walle 	phydev->port = PORT_FIBRE;
64120b2af32SRussell King 
64220b2af32SRussell King 	return 0;
64320b2af32SRussell King }
64420b2af32SRussell King 
645c84786faSRussell King static int mv3310_read_status_copper(struct phy_device *phydev)
64620b2af32SRussell King {
647c84786faSRussell King 	int cssr1, speed, val;
64820b2af32SRussell King 
649998a8a83SHeiner Kallweit 	val = genphy_c45_read_link(phydev);
65020b2af32SRussell King 	if (val < 0)
65120b2af32SRussell King 		return val;
65220b2af32SRussell King 
65320b2af32SRussell King 	val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_STAT1);
65420b2af32SRussell King 	if (val < 0)
65520b2af32SRussell King 		return val;
65620b2af32SRussell King 
657c84786faSRussell King 	cssr1 = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_CSSR1);
658c84786faSRussell King 	if (cssr1 < 0)
659c84786faSRussell King 		return val;
660c84786faSRussell King 
661c84786faSRussell King 	/* If the link settings are not resolved, mark the link down */
662c84786faSRussell King 	if (!(cssr1 & MV_PCS_CSSR1_RESOLVED)) {
663c84786faSRussell King 		phydev->link = 0;
664c84786faSRussell King 		return 0;
665c84786faSRussell King 	}
666c84786faSRussell King 
667c84786faSRussell King 	/* Read the copper link settings */
668c84786faSRussell King 	speed = cssr1 & MV_PCS_CSSR1_SPD1_MASK;
669c84786faSRussell King 	if (speed == MV_PCS_CSSR1_SPD1_SPD2)
670c84786faSRussell King 		speed |= cssr1 & MV_PCS_CSSR1_SPD2_MASK;
671c84786faSRussell King 
672c84786faSRussell King 	switch (speed) {
673c84786faSRussell King 	case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_10000:
674c84786faSRussell King 		phydev->speed = SPEED_10000;
675c84786faSRussell King 		break;
676c84786faSRussell King 
677c84786faSRussell King 	case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_5000:
678c84786faSRussell King 		phydev->speed = SPEED_5000;
679c84786faSRussell King 		break;
680c84786faSRussell King 
681c84786faSRussell King 	case MV_PCS_CSSR1_SPD1_SPD2 | MV_PCS_CSSR1_SPD2_2500:
682c84786faSRussell King 		phydev->speed = SPEED_2500;
683c84786faSRussell King 		break;
684c84786faSRussell King 
685c84786faSRussell King 	case MV_PCS_CSSR1_SPD1_1000:
686c84786faSRussell King 		phydev->speed = SPEED_1000;
687c84786faSRussell King 		break;
688c84786faSRussell King 
689c84786faSRussell King 	case MV_PCS_CSSR1_SPD1_100:
690c84786faSRussell King 		phydev->speed = SPEED_100;
691c84786faSRussell King 		break;
692c84786faSRussell King 
693c84786faSRussell King 	case MV_PCS_CSSR1_SPD1_10:
694c84786faSRussell King 		phydev->speed = SPEED_10;
695c84786faSRussell King 		break;
696c84786faSRussell King 	}
697c84786faSRussell King 
698c84786faSRussell King 	phydev->duplex = cssr1 & MV_PCS_CSSR1_DUPLEX_FULL ?
699c84786faSRussell King 			 DUPLEX_FULL : DUPLEX_HALF;
7004217a64eSMichael Walle 	phydev->port = PORT_TP;
701c84786faSRussell King 	phydev->mdix = cssr1 & MV_PCS_CSSR1_MDIX ?
702c84786faSRussell King 		       ETH_TP_MDI_X : ETH_TP_MDI;
703c84786faSRussell King 
70420b2af32SRussell King 	if (val & MDIO_AN_STAT1_COMPLETE) {
70520b2af32SRussell King 		val = genphy_c45_read_lpa(phydev);
70620b2af32SRussell King 		if (val < 0)
70720b2af32SRussell King 			return val;
70820b2af32SRussell King 
709cc1122b0SColin Ian King 		/* Read the link partner's 1G advertisement */
71020b2af32SRussell King 		val = phy_read_mmd(phydev, MDIO_MMD_AN, MV_AN_STAT1000);
71120b2af32SRussell King 		if (val < 0)
71220b2af32SRussell King 			return val;
71320b2af32SRussell King 
71478a24df3SAndrew Lunn 		mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, val);
71520b2af32SRussell King 
716c84786faSRussell King 		/* Update the pause status */
717c84786faSRussell King 		phy_resolve_aneg_pause(phydev);
71820b2af32SRussell King 	}
71920b2af32SRussell King 
720c84786faSRussell King 	return 0;
72120b2af32SRussell King }
72220b2af32SRussell King 
723c84786faSRussell King static int mv3310_read_status(struct phy_device *phydev)
724c84786faSRussell King {
725c84786faSRussell King 	int err, val;
726ea4efe25SRussell King 
727c84786faSRussell King 	phydev->speed = SPEED_UNKNOWN;
728c84786faSRussell King 	phydev->duplex = DUPLEX_UNKNOWN;
729c84786faSRussell King 	linkmode_zero(phydev->lp_advertising);
730c84786faSRussell King 	phydev->link = 0;
731c84786faSRussell King 	phydev->pause = 0;
732c84786faSRussell King 	phydev->asym_pause = 0;
733ea4efe25SRussell King 	phydev->mdix = ETH_TP_MDI_INVALID;
734ea4efe25SRussell King 
735c84786faSRussell King 	val = phy_read_mmd(phydev, MDIO_MMD_PCS, MV_PCS_BASE_R + MDIO_STAT1);
736c84786faSRussell King 	if (val < 0)
737c84786faSRussell King 		return val;
738c84786faSRussell King 
739c84786faSRussell King 	if (val & MDIO_STAT1_LSTATUS)
740c84786faSRussell King 		err = mv3310_read_status_10gbaser(phydev);
741c84786faSRussell King 	else
742c84786faSRussell King 		err = mv3310_read_status_copper(phydev);
743c84786faSRussell King 	if (err < 0)
744c84786faSRussell King 		return err;
745c84786faSRussell King 
746c84786faSRussell King 	if (phydev->link)
74736c4449aSRussell King 		mv3310_update_interface(phydev);
74820b2af32SRussell King 
74920b2af32SRussell King 	return 0;
75020b2af32SRussell King }
75120b2af32SRussell King 
752a585c03eSRussell King static int mv3310_get_tunable(struct phy_device *phydev,
753a585c03eSRussell King 			      struct ethtool_tunable *tuna, void *data)
754a585c03eSRussell King {
755a585c03eSRussell King 	switch (tuna->id) {
756a585c03eSRussell King 	case ETHTOOL_PHY_EDPD:
757a585c03eSRussell King 		return mv3310_get_edpd(phydev, data);
758a585c03eSRussell King 	default:
759a585c03eSRussell King 		return -EOPNOTSUPP;
760a585c03eSRussell King 	}
761a585c03eSRussell King }
762a585c03eSRussell King 
763a585c03eSRussell King static int mv3310_set_tunable(struct phy_device *phydev,
764a585c03eSRussell King 			      struct ethtool_tunable *tuna, const void *data)
765a585c03eSRussell King {
766a585c03eSRussell King 	switch (tuna->id) {
767a585c03eSRussell King 	case ETHTOOL_PHY_EDPD:
768a585c03eSRussell King 		return mv3310_set_edpd(phydev, *(u16 *)data);
769a585c03eSRussell King 	default:
770a585c03eSRussell King 		return -EOPNOTSUPP;
771a585c03eSRussell King 	}
772a585c03eSRussell King }
773a585c03eSRussell King 
77420b2af32SRussell King static struct phy_driver mv3310_drivers[] = {
77520b2af32SRussell King 	{
776631ba906SMaxime Chevallier 		.phy_id		= MARVELL_PHY_ID_88X3310,
777952b6b3bSAntoine Tenart 		.phy_id_mask	= MARVELL_PHY_ID_MASK,
77820b2af32SRussell King 		.name		= "mv88x3310",
77974145424SMaxime Chevallier 		.get_features	= mv3310_get_features,
78020b2af32SRussell King 		.config_init	= mv3310_config_init,
7810d3ad854SRussell King 		.probe		= mv3310_probe,
7820d3ad854SRussell King 		.suspend	= mv3310_suspend,
7830d3ad854SRussell King 		.resume		= mv3310_resume,
78420b2af32SRussell King 		.config_aneg	= mv3310_config_aneg,
78520b2af32SRussell King 		.aneg_done	= mv3310_aneg_done,
78620b2af32SRussell King 		.read_status	= mv3310_read_status,
787a585c03eSRussell King 		.get_tunable	= mv3310_get_tunable,
788a585c03eSRussell King 		.set_tunable	= mv3310_set_tunable,
7891b8ef142SMarek Behún 		.remove		= mv3310_remove,
790d137c70dSWong Vee Khee 		.set_loopback	= genphy_c45_loopback,
79120b2af32SRussell King 	},
79262d01535SMaxime Chevallier 	{
79362d01535SMaxime Chevallier 		.phy_id		= MARVELL_PHY_ID_88E2110,
79462d01535SMaxime Chevallier 		.phy_id_mask	= MARVELL_PHY_ID_MASK,
79562d01535SMaxime Chevallier 		.name		= "mv88x2110",
79662d01535SMaxime Chevallier 		.probe		= mv3310_probe,
797e02c4a9dSAntoine Tenart 		.suspend	= mv3310_suspend,
798e02c4a9dSAntoine Tenart 		.resume		= mv3310_resume,
79962d01535SMaxime Chevallier 		.config_init	= mv3310_config_init,
80062d01535SMaxime Chevallier 		.config_aneg	= mv3310_config_aneg,
80162d01535SMaxime Chevallier 		.aneg_done	= mv3310_aneg_done,
80262d01535SMaxime Chevallier 		.read_status	= mv3310_read_status,
803a585c03eSRussell King 		.get_tunable	= mv3310_get_tunable,
804a585c03eSRussell King 		.set_tunable	= mv3310_set_tunable,
8051b8ef142SMarek Behún 		.remove		= mv3310_remove,
806d137c70dSWong Vee Khee 		.set_loopback	= genphy_c45_loopback,
80762d01535SMaxime Chevallier 	},
80820b2af32SRussell King };
80920b2af32SRussell King 
81020b2af32SRussell King module_phy_driver(mv3310_drivers);
81120b2af32SRussell King 
81220b2af32SRussell King static struct mdio_device_id __maybe_unused mv3310_tbl[] = {
813631ba906SMaxime Chevallier 	{ MARVELL_PHY_ID_88X3310, MARVELL_PHY_ID_MASK },
81462d01535SMaxime Chevallier 	{ MARVELL_PHY_ID_88E2110, MARVELL_PHY_ID_MASK },
81520b2af32SRussell King 	{ },
81620b2af32SRussell King };
81720b2af32SRussell King MODULE_DEVICE_TABLE(mdio, mv3310_tbl);
81820b2af32SRussell King MODULE_DESCRIPTION("Marvell Alaska X 10Gigabit Ethernet PHY driver (MV88X3310)");
81920b2af32SRussell King MODULE_LICENSE("GPL");
820