net: phy: Add driver for Motorcomm yt8521 gigabit ethernet phy
Subsystems (4)
Frank
maintainerPATCH 1/1 net: phy: Add driver for Motorcomm yt8521 gigabit ethernet phy
Add a driver for the motorcomm yt8521 gigabit ethernet phy. We have verified the driver on StarFive VisionFive development board, which is developed by Shanghai StarFive Technology Co., Ltd.. On the board, yt8521 gigabit ethernet phy works in utp mode, RGMII interface, supports 1000M/100M/10M speeds, and wol(magic package).
---
patch v4.4:
Hi Jakub
Fix "warning: variable 'changed'"
patch v4.3:
Hi Jakub
Kernel 6.0-rc1 is cut on 2022-08-14, we update new patch for Kernel 6.0-rc1.
patch v4.2:
fix "=0D" and "=20" which in patch v4.1.
patch v4.1:
Hi Andrew
Thanks very much and based on your comments we modified the patch v4.1 as below.
Quoted 4 lines
You have interrupt bits defined, you enable the WoL interrupt, but you don't have an interrupt handler. PHY interrupts are generally level interrupts, so on WoL, don't you end up with an interrupt storm, because you don't have anything clearing the WoL interrupt?
in the driver, only the interrupt for WOL is used according to uplayer WOL configuration via .set_wol. If WOL is enalbed, then the WOL interrupt is enabled accordingly; you know, for a system support WOL, the WOL interrupt will be handled by user's WOL circuit, and it will not cause interrupt storm to CPU core system.
for WOL interrupt, by default, we configure to pulse trigger mode, that is a pulse from High to low change, and the low level will hold for 672ms. user's WOL circuit will detected such volt level change as a WOL event trigger.
patch v4:
Hi Andrew,Jakub
Thanks very much and based on your comments we modified the patch v4 as below.
We evaluated the Marvell 10G driver and at803x you suggested. The 2 drivers implement SFP module attach/detach functions and we think these functions do not help yt8521 to do UTP/Fiber register space arbitration which you may concern in previous patch.
Yt8521 can detect utp/fiber media link status automatically. For the case of both media are connected, driver arbitrates the priority of the media (by default, driver takes fiber as higher priority) and report the media status to up layer(MAC).
patch v3:
Hi Andrew
Thanks and based on your comments we modified the patch as below.
Quoted 5 lines
It is generally not that simple. Fibre, you probably want 1000BaseX, unless the fibre module is actually copper, and then you want SGMII. So you need something to talk to the fibre module and ask it what it is. That something is phylink. Phylink does not support both copper and fibre at the same time for one MAC.
yes, you said it and for MAC, it does not support copper and Fiber at same time. but from Physical Layer, you know, sometimes both Copper and Fiber cables are connected. in this case, Phy driver should do arbitration and report to MAC which media should be used and Link-up.
This is the reason that the driver has a "polling mode", and by default, also this driver takes fiber as first priority which matches phy chip default behavior.
patch v2:
Hi Andrew, Russell King, Peter,
Thanks and based on your comments we modified the patch as below.
Quoted 2 lines
So there's only two possible pages that can be used in the extended register space?
Yes,there is only two register space (utp and fiber).
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+/* Extended Register's Data Register */ +#define YTPHY_PAGE_DATA 0x1FThese are defined exactly the same way as below. Please reuse code where possible.
Yes, code will be reuse, but "YT8511_PAGE" need to be rename like "YTPHY_PAGE_DATA",as it is common register for yt phys.
patch v1:
Add a driver for the motorcomm yt8521 gigabit ethernet phy. We have verified the driver on StarFive VisionFive development board, which is developed by Shanghai StarFive Technology Co., Ltd.. On the board, yt8521 gigabit ethernet phy works in utp mode, RGMII interface, supports 1000M/100M/10M speeds, and wol(magic package).
Thanks and BR,
Frank
MAINTAINERS | 1 + drivers/net/phy/Kconfig | 2 +- drivers/net/phy/motorcomm.c | 1176 ++++++++++++++++++++++++++++++++++- 3 files changed, 1176 insertions(+), 3 deletions(-)
MAINTAINERS +1 -0
@@ -13780,6 +13780,7 @@ F: include/uapi/linux/meye.h MOTORCOMM PHY DRIVER M: Peter Geis <[email protected]> +M: Frank <[email protected]> L: [email protected] S: Maintained F: drivers/net/phy/motorcomm.c
drivers/net/phy/Kconfig +1 -1
@@ -260,7 +260,7 @@ config MOTORCOMM_PHY tristate "Motorcomm PHYs" help Enables support for Motorcomm network PHYs. - Currently supports the YT8511 gigabit PHY. + Currently supports the YT8511, YT8521 Gigabit Ethernet PHYs. config NATIONAL_PHY tristate "National Semiconductor PHYs"
drivers/net/phy/motorcomm.c +1174 -2
1,217 lines not on this page · raw message
Signature · 1 line
2.31.0.windows.1
Jakub Kicinski
maintainerQuoted 13 lines · On Wed, 17 Aug 2022 19:25:54 +0800 Frank wrote:
drivers/net/phy/motorcomm.c +13
-0+static int yt8521_fiber_config_aneg (struct phy_device *phydev) +{ +int err, changed; +u16 adv; + +if (phydev->autoneg !=AUTONEG_ENABLE ) +return yt8521_fiber_setup_forced (phydev); + + err =ytphy_modify_ext_with_lock (phydev,YTPHY_MISC_CONFIG_REG , +YTPHY_MCR_FIBER_SPEED_MASK , +YTPHY_MCR_FIBER_1000BX ); +if (err <0 ) +return err;
drivers/net/phy/motorcomm.c static int yt8511_config_init(struct phy_device *phydev) · line 1122
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+ +/* enable Fiber auto sensing */ + err =ytphy_modify_ext_with_lock (phydev,YT8521_LINK_TIMER_CFG2_REG , +0 ,YT8521_LTCR_EN_AUTOSEN ); +if (err <0 ) +return err; + +/* Setup fiber advertisement */ + adv =ADVERTISE_1000XFULL |ADVERTISE_1000XPAUSE | +ADVERTISE_1000XPSE_ASYM ;
Is it okay to ignore phydev->advertising and always set the same mask?
Quoted 4 lines
drivers/net/phy/motorcomm.c +4
-0+ err =phy_modify_changed (phydev,MII_ADVERTISE , +ADVERTISE_1000XHALF |ADVERTISE_1000XFULL | +ADVERTISE_1000XPAUSE |ADVERTISE_1000XPSE_ASYM , + adv);
Andrew Lunn
maintainerQuoted 18 lines · Jakub Kicinski
Quoted 17 lines · On Wed, 17 Aug 2022 19:25:54 +0800 Frank wrote:
drivers/net/phy/motorcomm.c +17
-0+static int yt8521_fiber_config_aneg (struct phy_device *phydev) +{ +int err, changed; +u16 adv; + +if (phydev->autoneg !=AUTONEG_ENABLE ) +return yt8521_fiber_setup_forced (phydev); + + err =ytphy_modify_ext_with_lock (phydev,YTPHY_MISC_CONFIG_REG , +YTPHY_MCR_FIBER_SPEED_MASK , +YTPHY_MCR_FIBER_1000BX ); +if (err <0 ) +return err; + +/* enable Fiber auto sensing */ + err =ytphy_modify_ext_with_lock (phydev,YT8521_LINK_TIMER_CFG2_REG , +0 ,YT8521_LTCR_EN_AUTOSEN );
Quoted 8 lines
drivers/net/phy/motorcomm.c static int yt8511_config_init(struct phy_device *phydev) · line 1122
Quoted 6 lines
drivers/net/phy/motorcomm.c +6
-0+if (err <0 ) +return err; + +/* Setup fiber advertisement */ + adv =ADVERTISE_1000XFULL |ADVERTISE_1000XPAUSE | +ADVERTISE_1000XPSE_ASYM ;Is it okay to ignore
phydev->advertisingand always set the same mask?
The user could of changed the pause settings, which are going to be ignored here. Also, you should not assume the MAC can actually do asymmetric pause, not all can. phydev->advertising will be set to only include what the MAC can actually do.
The whole concept of having two line sides connected to one MAC and seeing which gets link first is unsupported in Linux. In theory, you want to be able to configure each line side differently. Maybe you want autoneg on copper, but fixed on fibre, asymmetric pause with fibre, but symmetric pause on copper, etc. Since there is only one instance of phydev here, you don't have anywhere to store two sets of configuration, nor any sort of kAPI to deal with two phydev structures etc. So the user experience is not so great.
With the Marvell Switches which also have this capability, i actually ignore it, use the phy-mode it decide which should be used, either copper or fibre, and leave the other powered off so it can never get link. There is at least one Marvell PHY which does however support first up wins, so this behaviour is not new. I just don't recommend it.
And it gets even more interesting when the SFP is actually copper. But since the integration with phylink is missing in this driver, that is not supported here.
Andrew
Jakub Kicinski
maintainerQuoted 49 lines · On Tue, 23 Aug 2022 16:14:16 +0200 Andrew Lunn wrote:
Quoted 18 lines · Jakub Kicinski
Quoted 17 lines · On Wed, 17 Aug 2022 19:25:54 +0800 Frank wrote:
drivers/net/phy/motorcomm.c +17
-0+static int yt8521_fiber_config_aneg (struct phy_device *phydev) +{ +int err, changed; +u16 adv; + +if (phydev->autoneg !=AUTONEG_ENABLE ) +return yt8521_fiber_setup_forced (phydev); + + err =ytphy_modify_ext_with_lock (phydev,YTPHY_MISC_CONFIG_REG , +YTPHY_MCR_FIBER_SPEED_MASK , +YTPHY_MCR_FIBER_1000BX ); +if (err <0 ) +return err; + +/* enable Fiber auto sensing */ + err =ytphy_modify_ext_with_lock (phydev,YT8521_LINK_TIMER_CFG2_REG , +0 ,YT8521_LTCR_EN_AUTOSEN );Quoted 8 lines
drivers/net/phy/motorcomm.c static int yt8511_config_init(struct phy_device *phydev) · line 1122
Quoted 6 lines
drivers/net/phy/motorcomm.c +6
-0+if (err <0 ) +return err; + +/* Setup fiber advertisement */ + adv =ADVERTISE_1000XFULL |ADVERTISE_1000XPAUSE | +ADVERTISE_1000XPSE_ASYM ;Is it okay to ignore
phydev->advertisingand always set the same mask?The user could of changed the pause settings, which are going to be ignored here. Also, you should not assume the MAC can actually do asymmetric pause, not all can.
phydev->advertisingwill be set to only include what the MAC can actually do.The whole concept of having two line sides connected to one MAC and seeing which gets link first is unsupported in Linux. In theory, you want to be able to configure each line side differently. Maybe you want autoneg on copper, but fixed on fibre, asymmetric pause with fibre, but symmetric pause on copper, etc. Since there is only one instance of phydev here, you don't have anywhere to store two sets of configuration, nor any sort of kAPI to deal with two phydev structures etc. So the user experience is not so great.
With the Marvell Switches which also have this capability, i actually ignore it, use the phy-mode it decide which should be used, either copper or fibre, and leave the other powered off so it can never get link. There is at least one Marvell PHY which does however support first up wins, so this behaviour is not new. I just don't recommend it.
Quoted 3 lines
And it gets even more interesting when the SFP is actually copper. But since the integration with phylink is missing in this driver, that is not supported here.
Interesting. Just to confirm - regardless of the two-sided design.. -edness.. IIUC my question has merit and we need v5?
Andrew Lunn
maintainerQuoted 7 lines
Quoted 4 lines
The user could of changed the pause settings, which are going to be ignored here. Also, you should not assume the MAC can actually do asymmetric pause, not all can.
phydev->advertisingwill be set to only include what the MAC can actually do.Interesting. Just to confirm - regardless of the two-sided design.. -edness.. IIUC my question has merit and we need v5?
Yes, phydev->advertising should be take into account.
Andrew
Russell King (Oracle)
reviewerQuoted 9 lines · Andrew Lunn
Quoted 7 lines
Quoted 4 lines
The user could of changed the pause settings, which are going to be ignored here. Also, you should not assume the MAC can actually do asymmetric pause, not all can.
phydev->advertisingwill be set to only include what the MAC can actually do.Interesting. Just to confirm - regardless of the two-sided design.. -edness.. IIUC my question has merit and we need v5?
Yes,
phydev->advertisingshould be take into account.
It's worth pointing out that there is a helper for this - linkmode_adv_to_mii_adv_x().
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!