Message ID | 20250219083910.2255981-4-SkyLake.Huang@mediatek.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Add 2.5G ethernet phy support on MT7988 | expand |
On Wed, Feb 19, 2025 at 04:39:10PM +0800, Sky Huang wrote: > +static int mt798x_2p5ge_phy_config_init(struct phy_device *phydev) > +{ > + struct pinctrl *pinctrl; > + int ret; > + > + /* Check if PHY interface type is compatible */ > + if (phydev->interface != PHY_INTERFACE_MODE_INTERNAL) > + return -ENODEV; > + > + ret = mt798x_2p5ge_phy_load_fw(phydev); > + if (ret < 0) > + return ret; Firmware should not be loaded in the .config_init method. The above call will block while holding the RTNL which will prevent all other network configuration until the firmware has been loaded or the load fails. Thanks.
On Wed, Feb 19, 2025 at 09:33:44AM +0000, Russell King (Oracle) wrote: > On Wed, Feb 19, 2025 at 04:39:10PM +0800, Sky Huang wrote: > > +static int mt798x_2p5ge_phy_config_init(struct phy_device *phydev) > > +{ > > + struct pinctrl *pinctrl; > > + int ret; > > + > > + /* Check if PHY interface type is compatible */ > > + if (phydev->interface != PHY_INTERFACE_MODE_INTERNAL) > > + return -ENODEV; > > + > > + ret = mt798x_2p5ge_phy_load_fw(phydev); > > + if (ret < 0) > > + return ret; > > Firmware should not be loaded in the .config_init method. The above > call will block while holding the RTNL which will prevent all other > network configuration until the firmware has been loaded or the load > fails. The aquantia and qt2025 drivers are good examples to copy. Andrew
> +config MEDIATEK_2P5GE_PHY > + tristate "MediaTek 2.5Gb Ethernet PHYs" > + depends on (ARM64 && ARCH_MEDIATEK) || COMPILE_TEST > + select MTK_NET_PHYLIB > + help > + Supports MediaTek SoC built-in 2.5Gb Ethernet PHYs. > + > + This will load necessary firmware and add appropriate time delay. > + Accelerate this procedure through internal pbus instead of MDIO > + bus. Certain link-up issues will also be fixed here. Please keep the file sorted, this should be the first entry. > diff --git a/drivers/net/phy/mediatek/Makefile b/drivers/net/phy/mediatek/Makefile > index 814879d0abe5..c6db8abd2c9c 100644 > --- a/drivers/net/phy/mediatek/Makefile > +++ b/drivers/net/phy/mediatek/Makefile > @@ -2,3 +2,4 @@ > obj-$(CONFIG_MTK_NET_PHYLIB) += mtk-phy-lib.o > obj-$(CONFIG_MEDIATEK_GE_PHY) += mtk-ge.o > obj-$(CONFIG_MEDIATEK_GE_SOC_PHY) += mtk-ge-soc.o > +obj-$(CONFIG_MEDIATEK_2P5GE_PHY) += mtk-2p5ge.o I suppose you could say this file is sorted in reverse order so is correct? > diff --git a/drivers/net/phy/mediatek/mtk-2p5ge.c b/drivers/net/phy/mediatek/mtk-2p5ge.c > new file mode 100644 > index 000000000000..adb03df331ab > --- /dev/null > +++ b/drivers/net/phy/mediatek/mtk-2p5ge.c > @@ -0,0 +1,346 @@ > +// SPDX-License-Identifier: GPL-2.0+ > +#include <linux/bitfield.h> > +#include <linux/firmware.h> > +#include <linux/module.h> > +#include <linux/nvmem-consumer.h> Is this header needed? > +#include <linux/of_address.h> > +#include <linux/of_platform.h> > +#include <linux/pinctrl/consumer.h> > +#include <linux/phy.h> > +#include <linux/pm_domain.h> > +#include <linux/pm_runtime.h> And these two? Please only use those that are needed. > +static int mt798x_2p5ge_phy_load_fw(struct phy_device *phydev) > +{ > + > + writew(reg & ~MD32_EN, mcu_csr_base + MD32_EN_CFG); > + writew(reg | MD32_EN, mcu_csr_base + MD32_EN_CFG); > + phy_set_bits(phydev, MII_BMCR, BMCR_RESET); > + /* We need a delay here to stabilize initialization of MCU */ > + usleep_range(7000, 8000); Does the reset bit clear when the MCU is ready? That is what 802.3 defines. phy_poll_reset() might do what you need. > + dev_info(dev, "Firmware loading/trigger ok.\n"); dev_dbg(), if at all. You have already spammed the log with the firmware version, so this adds nothing useful. > + phydev->duplex = DUPLEX_FULL; > + /* FIXME: > + * The current firmware always enables rate adaptation mode. > + */ > + phydev->rate_matching = RATE_MATCH_PAUSE; Can we tell current firmware for future firmware? Is this actually fixable? > + } > + > + return 0; > +} > + > +static int mt798x_2p5ge_phy_probe(struct phy_device *phydev) > +{ > + struct mtk_i2p5ge_phy_priv *priv; > + > + priv = devm_kzalloc(&phydev->mdio.dev, > + sizeof(struct mtk_i2p5ge_phy_priv), GFP_KERNEL); > + if (!priv) > + return -ENOMEM; > + > + switch (phydev->drv->phy_id) { > + case MTK_2P5GPHY_ID_MT7988: > + /* The original hardware only sets MDIO_DEVS_PMAPMD */ What do you mean by "original hardware"? You use PHY_ID_MATCH_MODEL(MTK_2P5GPHY_ID_MT7988), so do you mean revision 0 is broken, but revision 1 fixed it? > + phydev->c45_ids.mmds_present |= MDIO_DEVS_PCS | > + MDIO_DEVS_AN | > + MDIO_DEVS_VEND1 | > + MDIO_DEVS_VEND2; > + break; > + default: > + return -EINVAL; > + } > + > + priv->fw_loaded = false; > + phydev->priv = priv; > + > + mtk_phy_leds_state_init(phydev); The LEDs work without firmware? Andrew --- pw-bot: cr
On Wed, 2025-02-19 at 09:33 +0000, Russell King (Oracle) wrote: > > External email : Please do not click links or open attachments until > you have verified the sender or the content. > > > On Wed, Feb 19, 2025 at 04:39:10PM +0800, Sky Huang wrote: > > +static int mt798x_2p5ge_phy_config_init(struct phy_device *phydev) > > +{ > > + struct pinctrl *pinctrl; > > + int ret; > > + > > + /* Check if PHY interface type is compatible */ > > + if (phydev->interface != PHY_INTERFACE_MODE_INTERNAL) > > + return -ENODEV; > > + > > + ret = mt798x_2p5ge_phy_load_fw(phydev); > > + if (ret < 0) > > + return ret; > > Firmware should not be loaded in the .config_init method. The above > call will block while holding the RTNL which will prevent all other > network configuration until the firmware has been loaded or the load > fails. > > Thanks. > > -- > RMK's Patch system: > https://urldefense.com/v3/__https://www.armlinux.org.uk/developer/patches/__;!!CTRNKA9wMg0ARbw!iV-1ViPFsUV-lLj7aIycan8nery6sQO3t6mkpdlb_GW8hswhxc4ejJozxqkU3s2WzxSizs4kfdC77yr7HGGRIuU$ > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! Hi Russell, mt798x_p5ge_phy_load_fw() will only load firmware once after driver is probed through priv->fw_loaded. And actually, firmware loading procedure only takes about 11ms. This was discussed earlier in: https://patchwork.kernel.org/project/linux-mediatek/patch/20240520113456.21675-6-SkyLake.Huang@mediatek.com/#25856462 https://patchwork.kernel.org/project/linux-mediatek/patch/20240520113456.21675-6-SkyLake.Huang@mediatek.com/#25857174 BRs, Sky
On Wed, Feb 26, 2025 at 06:48:34AM +0000, SkyLake Huang (黃啟澤) wrote: > On Wed, 2025-02-19 at 09:33 +0000, Russell King (Oracle) wrote: > > > > External email : Please do not click links or open attachments until > > you have verified the sender or the content. > > > > > > On Wed, Feb 19, 2025 at 04:39:10PM +0800, Sky Huang wrote: > > > +static int mt798x_2p5ge_phy_config_init(struct phy_device *phydev) > > > +{ > > > + struct pinctrl *pinctrl; > > > + int ret; > > > + > > > + /* Check if PHY interface type is compatible */ > > > + if (phydev->interface != PHY_INTERFACE_MODE_INTERNAL) > > > + return -ENODEV; > > > + > > > + ret = mt798x_2p5ge_phy_load_fw(phydev); > > > + if (ret < 0) > > > + return ret; > > > > Firmware should not be loaded in the .config_init method. The above > > call will block while holding the RTNL which will prevent all other > > network configuration until the firmware has been loaded or the load > > fails. > > > > Thanks. > > > > -- > > RMK's Patch system: > > https://urldefense.com/v3/__https://www.armlinux.org.uk/developer/patches/__;!!CTRNKA9wMg0ARbw!iV-1ViPFsUV-lLj7aIycan8nery6sQO3t6mkpdlb_GW8hswhxc4ejJozxqkU3s2WzxSizs4kfdC77yr7HGGRIuU$ > > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! > Hi Russell, > mt798x_p5ge_phy_load_fw() will only load firmware once after driver is > probed through priv->fw_loaded. And actually, firmware loading > procedure only takes about 11ms. This was discussed earlier in: > https://patchwork.kernel.org/project/linux-mediatek/patch/20240520113456.21675-6-SkyLake.Huang@mediatek.com/#25856462 > https://patchwork.kernel.org/project/linux-mediatek/patch/20240520113456.21675-6-SkyLake.Huang@mediatek.com/#25857174 1. Wouldn't it be a good idea to include the loading time in the patch description or a comment in the patch? 2. What about the time it takes for request_firmware() uses the sysfs fallback, which essentially passes the firmware request to userspace to deal with? That can block for an indeterminate amount of time.
On Wed, Feb 26, 2025 at 06:48:34AM +0000, SkyLake Huang (黃啟澤) wrote: > On Wed, 2025-02-19 at 09:33 +0000, Russell King (Oracle) wrote: > > > > External email : Please do not click links or open attachments until > > you have verified the sender or the content. > > > > > > On Wed, Feb 19, 2025 at 04:39:10PM +0800, Sky Huang wrote: > > > +static int mt798x_2p5ge_phy_config_init(struct phy_device *phydev) > > > +{ > > > + struct pinctrl *pinctrl; > > > + int ret; > > > + > > > + /* Check if PHY interface type is compatible */ > > > + if (phydev->interface != PHY_INTERFACE_MODE_INTERNAL) > > > + return -ENODEV; > > > + > > > + ret = mt798x_2p5ge_phy_load_fw(phydev); > > > + if (ret < 0) > > > + return ret; > > > > Firmware should not be loaded in the .config_init method. The above > > call will block while holding the RTNL which will prevent all other > > network configuration until the firmware has been loaded or the load > > fails. > > > > Thanks. > > > > -- > > RMK's Patch system: > > https://urldefense.com/v3/__https://www.armlinux.org.uk/developer/patches/__;!!CTRNKA9wMg0ARbw!iV-1ViPFsUV-lLj7aIycan8nery6sQO3t6mkpdlb_GW8hswhxc4ejJozxqkU3s2WzxSizs4kfdC77yr7HGGRIuU$ > > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! > Hi Russell, > mt798x_p5ge_phy_load_fw() will only load firmware once after driver is > probed through priv->fw_loaded. And actually, firmware loading > procedure only takes about 11ms. This was discussed earlier in: > https://patchwork.kernel.org/project/linux-mediatek/patch/20240520113456.21675-6-SkyLake.Huang@mediatek.com/#25856462 > https://patchwork.kernel.org/project/linux-mediatek/patch/20240520113456.21675-6-SkyLake.Huang@mediatek.com/#25857174 Ideally, all PHY drivers should look like each other. That makes maintenance simpler. Currently, air_en8811h.c, aquantia_main.c, and qt2025.rs load firmware in there probe function. Is there a good reason this driver needs to be different? Andrew
diff --git a/MAINTAINERS b/MAINTAINERS index 42ec8b8d03bf..250ffe90b056 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14720,6 +14720,7 @@ M: Sky Huang <SkyLake.Huang@mediatek.com> L: netdev@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/mediatek,2p5gphy-fw.yaml +F: drivers/net/phy/mediatek/mtk-2p5ge.c F: drivers/net/phy/mediatek/mtk-ge-soc.c F: drivers/net/phy/mediatek/mtk-phy-lib.c F: drivers/net/phy/mediatek/mtk-ge.c diff --git a/drivers/net/phy/mediatek/Kconfig b/drivers/net/phy/mediatek/Kconfig index 2a8ac5aed0f8..02d0c215cfe0 100644 --- a/drivers/net/phy/mediatek/Kconfig +++ b/drivers/net/phy/mediatek/Kconfig @@ -25,3 +25,14 @@ config MEDIATEK_GE_SOC_PHY the MT7981 and MT7988 SoCs. These PHYs need calibration data present in the SoCs efuse and will dynamically calibrate VCM (common-mode voltage) during startup. + +config MEDIATEK_2P5GE_PHY + tristate "MediaTek 2.5Gb Ethernet PHYs" + depends on (ARM64 && ARCH_MEDIATEK) || COMPILE_TEST + select MTK_NET_PHYLIB + help + Supports MediaTek SoC built-in 2.5Gb Ethernet PHYs. + + This will load necessary firmware and add appropriate time delay. + Accelerate this procedure through internal pbus instead of MDIO + bus. Certain link-up issues will also be fixed here. diff --git a/drivers/net/phy/mediatek/Makefile b/drivers/net/phy/mediatek/Makefile index 814879d0abe5..c6db8abd2c9c 100644 --- a/drivers/net/phy/mediatek/Makefile +++ b/drivers/net/phy/mediatek/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_MTK_NET_PHYLIB) += mtk-phy-lib.o obj-$(CONFIG_MEDIATEK_GE_PHY) += mtk-ge.o obj-$(CONFIG_MEDIATEK_GE_SOC_PHY) += mtk-ge-soc.o +obj-$(CONFIG_MEDIATEK_2P5GE_PHY) += mtk-2p5ge.o diff --git a/drivers/net/phy/mediatek/mtk-2p5ge.c b/drivers/net/phy/mediatek/mtk-2p5ge.c new file mode 100644 index 000000000000..adb03df331ab --- /dev/null +++ b/drivers/net/phy/mediatek/mtk-2p5ge.c @@ -0,0 +1,346 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include <linux/bitfield.h> +#include <linux/firmware.h> +#include <linux/module.h> +#include <linux/nvmem-consumer.h> +#include <linux/of_address.h> +#include <linux/of_platform.h> +#include <linux/pinctrl/consumer.h> +#include <linux/phy.h> +#include <linux/pm_domain.h> +#include <linux/pm_runtime.h> + +#include "mtk.h" + +#define MTK_2P5GPHY_ID_MT7988 (0x00339c11) + +#define MT7988_2P5GE_PMB_FW "mediatek/mt7988/i2p5ge-phy-pmb.bin" +#define MT7988_2P5GE_PMB_FW_SIZE (0x20000) +#define MD32_EN_CFG (0x18) +#define MD32_EN BIT(0) + +#define BASE100T_STATUS_EXTEND (0x10) +#define BASE1000T_STATUS_EXTEND (0x11) +#define EXTEND_CTRL_AND_STATUS (0x16) + +#define PHY_AUX_CTRL_STATUS (0x1d) +#define PHY_AUX_DPX_MASK GENMASK(5, 5) +#define PHY_AUX_SPEED_MASK GENMASK(4, 2) + +/* Registers on MDIO_MMD_VEND1 */ +#define MTK_PHY_LPI_PCS_DSP_CTRL (0x121) +#define MTK_PHY_LPI_SIG_EN_LO_THRESH100_MASK GENMASK(12, 8) + +#define MTK_PHY_HOST_CMD1 0x800e +#define MTK_PHY_HOST_CMD2 0x800f +/* Registers on Token Ring debug nodes */ +/* ch_addr = 0x0, node_addr = 0xf, data_addr = 0x3c */ +#define AUTO_NP_10XEN BIT(6) + +struct mtk_i2p5ge_phy_priv { + bool fw_loaded; +}; + +enum { + PHY_AUX_SPD_10 = 0, + PHY_AUX_SPD_100, + PHY_AUX_SPD_1000, + PHY_AUX_SPD_2500, +}; + +static int mt798x_2p5ge_phy_load_fw(struct phy_device *phydev) +{ + struct mtk_i2p5ge_phy_priv *priv = phydev->priv; + void __iomem *mcu_csr_base, *pmb_addr; + struct device *dev = &phydev->mdio.dev; + const struct firmware *fw; + struct device_node *np; + int ret, i; + u32 reg; + + if (priv->fw_loaded) + return 0; + + np = of_find_compatible_node(NULL, NULL, "mediatek,2p5gphy-fw"); + if (!np) + return -ENOENT; + + pmb_addr = of_iomap(np, 1); + if (!pmb_addr) + return -ENOMEM; + mcu_csr_base = of_iomap(np, 2); + if (!mcu_csr_base) { + ret = -ENOMEM; + goto free_pmb; + } + + ret = request_firmware(&fw, MT7988_2P5GE_PMB_FW, dev); + if (ret) { + dev_err(dev, "failed to load firmware: %s, ret: %d\n", + MT7988_2P5GE_PMB_FW, ret); + goto free; + } + + if (fw->size != MT7988_2P5GE_PMB_FW_SIZE) { + dev_err(dev, "Firmware size 0x%zx != 0x%x\n", + fw->size, MT7988_2P5GE_PMB_FW_SIZE); + ret = -EINVAL; + goto release_fw; + } + + reg = readw(mcu_csr_base + MD32_EN_CFG); + if (reg & MD32_EN) { + phy_set_bits(phydev, MII_BMCR, BMCR_RESET); + usleep_range(10000, 11000); + } + phy_set_bits(phydev, MII_BMCR, BMCR_PDOWN); + + /* Write magic number to safely stall MCU */ + phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_HOST_CMD1, 0x1100); + phy_write_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_HOST_CMD2, 0x00df); + + for (i = 0; i < MT7988_2P5GE_PMB_FW_SIZE - 1; i += 4) + writel(*((uint32_t *)(fw->data + i)), pmb_addr + i); + dev_info(dev, "Firmware date code: %x/%x/%x, version: %x.%x\n", + be16_to_cpu(*((__be16 *)(fw->data + + MT7988_2P5GE_PMB_FW_SIZE - 8))), + *(fw->data + MT7988_2P5GE_PMB_FW_SIZE - 6), + *(fw->data + MT7988_2P5GE_PMB_FW_SIZE - 5), + *(fw->data + MT7988_2P5GE_PMB_FW_SIZE - 2), + *(fw->data + MT7988_2P5GE_PMB_FW_SIZE - 1)); + + writew(reg & ~MD32_EN, mcu_csr_base + MD32_EN_CFG); + writew(reg | MD32_EN, mcu_csr_base + MD32_EN_CFG); + phy_set_bits(phydev, MII_BMCR, BMCR_RESET); + /* We need a delay here to stabilize initialization of MCU */ + usleep_range(7000, 8000); + dev_info(dev, "Firmware loading/trigger ok.\n"); + + priv->fw_loaded = true; + +release_fw: + release_firmware(fw); +free: + iounmap(mcu_csr_base); +free_pmb: + iounmap(pmb_addr); + + return ret; +} + +static int mt798x_2p5ge_phy_config_init(struct phy_device *phydev) +{ + struct pinctrl *pinctrl; + int ret; + + /* Check if PHY interface type is compatible */ + if (phydev->interface != PHY_INTERFACE_MODE_INTERNAL) + return -ENODEV; + + ret = mt798x_2p5ge_phy_load_fw(phydev); + if (ret < 0) + return ret; + + /* Setup LED */ + phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED0_ON_CTRL, + MTK_PHY_LED_ON_POLARITY | MTK_PHY_LED_ON_LINK10 | + MTK_PHY_LED_ON_LINK100 | MTK_PHY_LED_ON_LINK1000 | + MTK_PHY_LED_ON_LINK2500); + phy_set_bits_mmd(phydev, MDIO_MMD_VEND2, MTK_PHY_LED1_ON_CTRL, + MTK_PHY_LED_ON_FDX | MTK_PHY_LED_ON_HDX); + + /* Switch pinctrl after setting polarity to avoid bogus blinking */ + pinctrl = devm_pinctrl_get_select(&phydev->mdio.dev, "i2p5gbe-led"); + if (IS_ERR(pinctrl)) + dev_err(&phydev->mdio.dev, "Fail to set LED pins!\n"); + + phy_modify_mmd(phydev, MDIO_MMD_VEND1, MTK_PHY_LPI_PCS_DSP_CTRL, + MTK_PHY_LPI_SIG_EN_LO_THRESH100_MASK, 0); + + /* Enable 16-bit next page exchange bit if 1000-BT isn't advertising */ + mtk_tr_modify(phydev, 0x0, 0xf, 0x3c, AUTO_NP_10XEN, + FIELD_PREP(AUTO_NP_10XEN, 0x1)); + + /* Enable HW auto downshift */ + phy_modify_paged(phydev, MTK_PHY_PAGE_EXTENDED_1, + MTK_PHY_AUX_CTRL_AND_STATUS, + 0, MTK_PHY_ENABLE_DOWNSHIFT); + + return 0; +} + +static int mt798x_2p5ge_phy_config_aneg(struct phy_device *phydev) +{ + bool changed = false; + u32 adv; + int ret; + + ret = genphy_c45_an_config_aneg(phydev); + if (ret < 0) + return ret; + if (ret > 0) + changed = true; + + /* Clause 45 doesn't define 1000BaseT support. Use Clause 22 instead in + * our design. + */ + adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising); + ret = phy_modify_changed(phydev, MII_CTRL1000, ADVERTISE_1000FULL, adv); + if (ret < 0) + return ret; + if (ret > 0) + changed = true; + + return __genphy_config_aneg(phydev, changed); +} + +static int mt798x_2p5ge_phy_get_features(struct phy_device *phydev) +{ + int ret; + + ret = genphy_c45_pma_read_abilities(phydev); + if (ret) + return ret; + + /* This phy can't handle collision, and neither can (XFI)MAC it's + * connected to. Although it can do HDX handshake, it doesn't support + * CSMA/CD that HDX requires. + */ + linkmode_clear_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, + phydev->supported); + + return 0; +} + +static int mt798x_2p5ge_phy_read_status(struct phy_device *phydev) +{ + int ret; + + /* When MDIO_STAT1_LSTATUS is raised genphy_c45_read_link(), this phy + * actually hasn't finished AN. So use CL22's link update function + * instead. + */ + ret = genphy_update_link(phydev); + if (ret) + return ret; + + phydev->speed = SPEED_UNKNOWN; + phydev->duplex = DUPLEX_UNKNOWN; + phydev->pause = 0; + phydev->asym_pause = 0; + + /* We'll read link speed through vendor specific registers down below. + * So remove phy_resolve_aneg_linkmode (AN on) & genphy_c45_read_pma + * (AN off). + */ + if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { + ret = genphy_c45_read_lpa(phydev); + if (ret < 0) + return ret; + + /* Clause 45 doesn't define 1000BaseT support. Read the link + * partner's 1G advertisement via Clause 22. + */ + ret = phy_read(phydev, MII_STAT1000); + if (ret < 0) + return ret; + mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, ret); + } else if (phydev->autoneg == AUTONEG_DISABLE) { + linkmode_zero(phydev->lp_advertising); + } + + if (phydev->link) { + ret = phy_read(phydev, PHY_AUX_CTRL_STATUS); + if (ret < 0) + return ret; + + switch (FIELD_GET(PHY_AUX_SPEED_MASK, ret)) { + case PHY_AUX_SPD_10: + phydev->speed = SPEED_10; + break; + case PHY_AUX_SPD_100: + phydev->speed = SPEED_100; + break; + case PHY_AUX_SPD_1000: + phydev->speed = SPEED_1000; + break; + case PHY_AUX_SPD_2500: + phydev->speed = SPEED_2500; + break; + } + + phydev->duplex = DUPLEX_FULL; + /* FIXME: + * The current firmware always enables rate adaptation mode. + */ + phydev->rate_matching = RATE_MATCH_PAUSE; + } + + return 0; +} + +static int mt798x_2p5ge_phy_get_rate_matching(struct phy_device *phydev, + phy_interface_t iface) +{ + return RATE_MATCH_PAUSE; +} + +static int mt798x_2p5ge_phy_probe(struct phy_device *phydev) +{ + struct mtk_i2p5ge_phy_priv *priv; + + priv = devm_kzalloc(&phydev->mdio.dev, + sizeof(struct mtk_i2p5ge_phy_priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + switch (phydev->drv->phy_id) { + case MTK_2P5GPHY_ID_MT7988: + /* The original hardware only sets MDIO_DEVS_PMAPMD */ + phydev->c45_ids.mmds_present |= MDIO_DEVS_PCS | + MDIO_DEVS_AN | + MDIO_DEVS_VEND1 | + MDIO_DEVS_VEND2; + break; + default: + return -EINVAL; + } + + priv->fw_loaded = false; + phydev->priv = priv; + + mtk_phy_leds_state_init(phydev); + + return 0; +} + +static struct phy_driver mtk_2p5gephy_driver[] = { + { + PHY_ID_MATCH_MODEL(MTK_2P5GPHY_ID_MT7988), + .name = "MediaTek MT7988 2.5GbE PHY", + .probe = mt798x_2p5ge_phy_probe, + .config_init = mt798x_2p5ge_phy_config_init, + .config_aneg = mt798x_2p5ge_phy_config_aneg, + .get_features = mt798x_2p5ge_phy_get_features, + .read_status = mt798x_2p5ge_phy_read_status, + .get_rate_matching = mt798x_2p5ge_phy_get_rate_matching, + .suspend = genphy_suspend, + .resume = genphy_resume, + .read_page = mtk_phy_read_page, + .write_page = mtk_phy_write_page, + }, +}; + +module_phy_driver(mtk_2p5gephy_driver); + +static struct mdio_device_id __maybe_unused mtk_2p5ge_phy_tbl[] = { + { PHY_ID_MATCH_VENDOR(0x00339c00) }, + { } +}; + +MODULE_DESCRIPTION("MediaTek 2.5Gb Ethernet PHY driver"); +MODULE_AUTHOR("SkyLake Huang <SkyLake.Huang@mediatek.com>"); +MODULE_LICENSE("GPL"); + +MODULE_DEVICE_TABLE(mdio, mtk_2p5ge_phy_tbl); +MODULE_FIRMWARE(MT7988_2P5GE_PMB_FW);