Giga Lite is a Realtek proprietary mode which runs at 500 Mbps over two pairs. Expose it as 500baseT2/Full on the generic FE-GE PHY when the MAC driver sets RTL_PHY_F_GIGA_LITE, and report SPEED_500 for it. The PHY enables Giga Lite when page 0xa42, reg 0x14, bit 9 is set, and negotiates it on its own regardless of the C22 advertisement. With the bit set, the link came up at Giga Lite even when only 10/100 was advertised. So set the bit only when autonegotiating with 500baseT2/Full advertised, and clear it otherwise, so that the advertisement set with ethtool is respected. 500baseT2/Full is advertised by default. It is added in config_init() rather than get_features(), as dev_flags is not yet set when the PHY is probed. Signed-off-by: Hee-Suk Kim <hsk…@dilluti0n.com> --- MAINTAINERS | 1 + drivers/net/phy/realtek/realtek_main.c | 52 ++++++++++++++++++++++++++++++++++ include/linux/realtek_phy.h | 10 +++++++ 3 files changed, 63 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index bfa5a7248973..07e4c8f80682 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10066,6 +10066,7 @@ F: include/linux/phy_fixed.h F: include/linux/phy_link_topology.h F: include/linux/phylib_stubs.h F: include/linux/platform_data/mdio-bcm-unimac.h +F: include/linux/realtek_phy.h F: include/net/phy/ F: include/trace/events/mdio.h F: include/uapi/linux/mdio.h diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c index a39ad18382f2..bf62823252d9 100644 --- a/drivers/net/phy/realtek/realtek_main.c +++ b/drivers/net/phy/realtek/realtek_main.c @@ -14,6 +14,7 @@ #include <linux/of.h> #include <linux/phy.h> #include <linux/pm_wakeirq.h> +#include <linux/realtek_phy.h> #include <linux/netdevice.h> #include <linux/module.h> #include <linux/delay.h> @@ -1708,6 +1709,9 @@ static void rtlgen_decode_physr(struct phy_device *phydev, int val) case 0x0020: phydev->speed = SPEED_1000; break; + case 0x0030: /* Giga Lite */ + phydev->speed = SPEED_500; + break; case 0x0200: phydev->speed = SPEED_10000; break; @@ -1735,6 +1739,52 @@ static void rtlgen_decode_physr(struct phy_device *phydev, int val) } } +/* Giga Lite is a Realtek proprietary mode which runs at 500 Mbps over + * two pairs. It is negotiated on its own and does not depend on 1000baseT + * being advertised, so it is exposed as the 500baseT2/Full link mode. + * + * The PHY ID is shared by all PHYs integrated into the RTL8168 family, so + * the MAC driver tells us whether the chip supports it. dev_flags is not + * known before the MAC driver has attached, hence the link mode is added + * here instead of in get_features(). + */ +static int rtlgen_config_init(struct phy_device *phydev) +{ + if (!(phydev->dev_flags & RTL_PHY_F_GIGA_LITE)) + return 0; + + /* Advertise it by default, but only the first time, so that the + * user setting survives a later phy_init_hw(). + */ + if (!linkmode_test_bit(ETHTOOL_LINK_MODE_500baseT2_Full_BIT, + phydev->supported)) { + linkmode_set_bit(ETHTOOL_LINK_MODE_500baseT2_Full_BIT, + phydev->supported); + linkmode_set_bit(ETHTOOL_LINK_MODE_500baseT2_Full_BIT, + phydev->advertising); + } + + return 0; +} + +static int rtlgen_config_aneg(struct phy_device *phydev) +{ + int ret = 0; + + if (phydev->dev_flags & RTL_PHY_F_GIGA_LITE) { + bool en = phydev->autoneg == AUTONEG_ENABLE && + linkmode_test_bit(ETHTOOL_LINK_MODE_500baseT2_Full_BIT, + phydev->advertising); + + ret = phy_modify_paged_changed(phydev, 0xa42, 0x14, BIT(9), + en ? BIT(9) : 0); + if (ret < 0) + return ret; + } + + return __genphy_config_aneg(phydev, ret > 0); +} + static int rtlgen_read_status(struct phy_device *phydev) { int ret, val; @@ -3286,6 +3336,8 @@ static struct phy_driver realtek_drvs[] = { }, { .name = "Generic FE-GE Realtek PHY", .match_phy_device = rtlgen_match_phy_device, + .config_init = rtlgen_config_init, + .config_aneg = rtlgen_config_aneg, .read_status = rtlgen_read_status, .suspend = genphy_suspend, .resume = rtlgen_resume, diff --git a/include/linux/realtek_phy.h b/include/linux/realtek_phy.h new file mode 100644 index 000000000000..7fcde616c070 --- /dev/null +++ b/include/linux/realtek_phy.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _REALTEK_PHY_H +#define _REALTEK_PHY_H + +#include <linux/bits.h> + +/* phy_device::dev_flags */ +#define RTL_PHY_F_GIGA_LITE BIT(0) + +#endif /* _REALTEK_PHY_H */
-- 2.56.1