net: phy: marvell: add RGMII-to-Copper mode configuration
Subsystems (3)
v2 cover net: phy: marvell: add RGMII-to-Copper mode configuration
Hi,
This series add the configuration of the RGMII-to-Copper MAC interface for Marvell 88E1510/88E1518/88E1512/88E1514 PHYs.
Patch #1, #2, #3 are cleanup commits.
---
Changes in v2:
- Reword patches to be more accurate.
- Added a patch to deduplicate the mode setting code in
m88e1510_config_init(), as suggested by Marek.
- When setting RGMII system interface, avoid erasing existing mode that
uses RGMII but a different media interface. This issue was raised by
Sashiko.
- Added a patch to rework the EEE errata code by using
phy_select_page() and phy_restore_page(), avoiding useless bus lock.
- Link to v1: https://patch.msgid.link/[email protected]
---
Paul Louvel (4):
net: phy: marvell: move mode configuration into standalone function
net: phy: marvell: de-duplicate mode initialization code
net: phy: marvell: factor out EEE errata initialization
net: phy: marvell: add RGMII-to-Copper mode configuration
drivers/net/phy/marvell.c | 127 ++++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 56 deletions(-)
---
base-commit: 7b6ab4dbc156e2f96419715130b3d5738a306c93
change-id: 20261109-marvell-phy-rgmii-60a8bf619582
Best regards,
Signature · 3 lines
Paul Louvel, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v2 1/4 net: phy: marvell: move mode configuration into standalone function
Move the configuration of the m88e151x out of the m88e1510_port_configure_serdes() function, so that other parts of the driver can use it.
--- drivers/net/phy/marvell.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
drivers/net/phy/marvell.c +22 -16
@@ -1332,6 +1332,27 @@ static int m88e1318_config_init(struct phy_device *phydev)return marvell_config_init (phydev); } +static int m88e1510_config_mode (struct phy_device *phydev,u16 mode) +{ +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 , mode); +if (ret <0 ) + goto error; + + ret =__phy_set_bits (phydev,MII_88E1510_GEN_CTRL_REG_1 , +MII_88E1510_GEN_CTRL_REG_1_RESET ); + +error: +return phy_restore_page (phydev, oldpage, ret); +} +static int m88e1510_config_init (struct phy_device *phydev) { static const struct {
@@ -3656,8 +3677,6 @@ static int m88e1510_port_configure_serdes(struct phy_port *port, bool enable, {struct phy_device *phydev =port_phydev (port);struct device *dev; -int oldpage; -int ret =0 ;u16 mode; dev = &phydev->mdio.dev;
@@ -3685,20 +3704,7 @@ static int m88e1510_port_configure_serdes(struct phy_port *port, bool enable, mode =MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII ; } - 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 , mode); -if (ret <0 ) - goto error; - - ret =__phy_set_bits (phydev,MII_88E1510_GEN_CTRL_REG_1 , -MII_88E1510_GEN_CTRL_REG_1_RESET ); - -error: -return phy_restore_page (phydev, oldpage, ret); +return m88e1510_config_mode (phydev, mode); }static const struct phy_port_ops m88e1510_serdes_port_ops = {
Signature · 1 line
2.56.1
Re: [PATCH net-next v2 1/4] net: phy: marvell: move mode configuration into standalone function
Quoted 5 lines · Paul Louvel
Move the configuration of the m88e151x out of the
m88e1510_port_configure_serdes()function, so that other parts of the driver can use it.Signed-off-by Paul Louvel (Schneider Electric) <[email protected]>
Andrew
PATCH v2 2/4 net: phy: marvell: de-duplicate mode initialization code
In reply to Paul LouvelThe code that initializes the m88e151x PHYs to use the SGMII-to-Copper interface is duplicated, and does not restore the old page in case of an error.
Instead, use m88e1510_config_mode().
--- drivers/net/phy/marvell.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-)
drivers/net/phy/marvell.c +4 -23
@@ -1395,30 +1395,11 @@ static int m88e1510_config_init(struct phy_device *phydev)return err;/* SGMII-to-Copper mode initialization */ -if (phydev->interface ==PHY_INTERFACE_MODE_SGMII ) { -/* Select page 18 */ - err =marvell_set_page (phydev,18 ); -if (err <0 ) -return err; - -/* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */ - err =phy_modify (phydev,MII_88E1510_GEN_CTRL_REG_1 , -MII_88E1510_GEN_CTRL_REG_1_MODE_MASK , -MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII ); -if (err <0 ) -return err; - -/* PHY reset is necessary after changing MODE[2:0] */ - err =phy_set_bits (phydev,MII_88E1510_GEN_CTRL_REG_1 , -MII_88E1510_GEN_CTRL_REG_1_RESET ); -if (err <0 ) -return err; +if (phydev->interface ==PHY_INTERFACE_MODE_SGMII ) + err =m88e1510_config_mode (phydev,MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII ); +if (err <0 ) +return err; -/* Reset page selection */ - err =marvell_set_page (phydev,MII_MARVELL_COPPER_PAGE ); -if (err <0 ) -return err; - } err =m88e1011_set_downshift (phydev,3 );if (err <0 )return err;
Signature · 1 line
2.56.1
Re: [PATCH net-next v2 2/4] net: phy: marvell: de-duplicate mode initialization code
Quoted 7 lines · Paul Louvel
The code that initializes the m88e151x PHYs to use the SGMII-to-Copper interface is duplicated, and does not restore the old page in case of an error.
Instead, use
m88e1510_config_mode().Signed-off-by Paul Louvel (Schneider Electric) <[email protected]>
Andrew
PATCH v2 3/4 net: phy: marvell: factor out EEE errata initialization
In reply to Paul LouvelThe 88E151x EEE errata sequence writes four register pairs on page 0xFF. Using phy_write() for each access takes and releases the MDIO bus lock every time, and returning early on error leaves the PHY on the errata page.
Move the sequence into m88e1510_eee_errata() and use phy_select_page() and phy_restore_page().
This reduces the number of bus lock/unlock cycles and restores the previous page if one of the errata writes fails.
--- drivers/net/phy/marvell.c | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-)
drivers/net/phy/marvell.c +25 -16
@@ -1353,7 +1353,7 @@ static int m88e1510_config_mode(struct phy_device *phydev, u16 mode)return phy_restore_page (phydev, oldpage, ret); } -static int m88e1510_config_init (struct phy_device *phydev) +static int m88e1510_eee_errata (struct phy_device *phydev) { static const struct { u16 reg17, reg16;
@@ -1363,31 +1363,40 @@ static int m88e1510_config_init(struct phy_device *phydev) { 0xb233, 0x214d }, { 0xcc0c, 0x2159 }, }; -int err; -int i; +int i, oldpage, ret =0 ;/* As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512/ * 88E1514 Rev A0, Errata Section 5.1: * If EEE is intended to be used, the following register writes * must be done once after every hardware reset. */ - err =marvell_set_page (phydev,0x00FF ); -if (err <0 ) -return err; + oldpage =phy_select_page (phydev,0x00FF ); +if (oldpage <0 ) + goto restore;for (i =0 ; i <ARRAY_SIZE (errata_vals); ++i) { - err =phy_write (phydev,17 , errata_vals[i].reg17); -if (err) -return err; - err =phy_write (phydev,16 , errata_vals[i].reg16); -if (err) -return err; + ret =__phy_write (phydev,17 , errata_vals[i].reg17); +if (ret) + goto restore; + + ret =__phy_write (phydev,16 , errata_vals[i].reg16); +if (ret) + goto restore; } - err =marvell_set_page (phydev,0x00FB ); -if (err <0 ) -return err; - err =phy_write (phydev,07 ,0xC00D ); +restore: + ret =phy_restore_page (phydev, oldpage, ret); +if (ret <0 ) +return ret; + +return phy_write_paged (phydev,0x00FB ,07 ,0xC00D ); +} + +static int m88e1510_config_init (struct phy_device *phydev) +{ +int err; + + err =m88e1510_eee_errata (phydev);if (err <0 )return err; err =marvell_set_page (phydev,MII_MARVELL_COPPER_PAGE );
Signature · 1 line
2.56.1
Re: [PATCH net-next v2 3/4] net: phy: marvell: factor out EEE errata initialization
Quoted 11 lines · Paul Louvel
The 88E151x EEE errata sequence writes four register pairs on page
0xFF. Usingphy_write()for each access takes and releases the MDIO bus lock every time, and returning early on error leaves the PHY on the errata page.Move the sequence into
m88e1510_eee_errata()and usephy_select_page()andphy_restore_page().
This reduces the number of bus lock/unlock cycles and restores the previous page if one of the errata writes fails.Signed-off-by Paul Louvel (Schneider Electric) <[email protected]>
Andrew
[email protected]
AI reviewRe: [PATCH net-next v2 3/4] net: phy: marvell: factor out EEE errata initialization
In reply to Paul LouvelThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In m88e1510_eee_errata() (drivers/net/phy/marvell.c), the patch changes the sequence of register writes the PHY receives even when…
--
net: phy: marvell: factor out EEE errata initialization
This patch moves the 88E151x EEE errata register sequence out of m88e1510_config_init() and into a new helper, m88e1510_eee_errata(). The page 0xFF writes now go through phy_select_page(), __phy_write() and phy_restore_page(). The final page 0xFB write now uses phy_write_paged().
Quoted 4 lines
drivers/net/phy/marvell.c +0
-0
[ ... ]
Quoted 21 lines
drivers/net/phy/marvell.c +4
-5@@ -1363,31 +1363,40 @@ static int m88e1510_config_init(struct phy_device *phydev) { 0xb233, 0x214d }, { 0xcc0c, 0x2159 }, }; -int err; -int i; +int i, oldpage, ret =0 ;/* As per Marvell Release Notes - Alaska 88E1510/88E1518/88E1512/ * 88E1514 Rev A0, Errata Section 5.1: * If EEE is intended to be used, the following register writes * must be done once after every hardware reset. */ - err =marvell_set_page (phydev,0x00FF ); -if (err <0 ) -return err; + oldpage =phy_select_page (phydev,0x00FF ); +if (oldpage <0 ) + goto restore;for (i =0 ; i <ARRAY_SIZE (errata_vals); ++i) {
[ ... ]
drivers/net/phy/marvell.c static int m88e1510_config_init(struct phy_device *phydev) · line 1392
Quoted 12 lines
drivers/net/phy/marvell.c +6
-4} - err =marvell_set_page (phydev,0x00FB ); -if (err <0 ) -return err; - err =phy_write (phydev,07 ,0xC00D ); +restore: + ret =phy_restore_page (phydev, oldpage, ret); +if (ret <0 ) +return ret; + +return phy_write_paged (phydev,0x00FB ,07 ,0xC00D );
[Severity: Low]
Is it intended that the PHY now gets a different sequence of MDIO accesses when nothing fails, and not only on the error path?
Before this patch, m88e1510_config_init() did:
write page 0xFF
write reg17/reg16 x4
write page 0xFB
write reg 7 = 0xC00DAfter this patch, m88e1510_eee_errata() does:
phy_select_page() read page, write page 0xFF
__phy_write() write reg17/reg16 x4
phy_restore_page() write original page
phy_write_paged() read page, write page 0xFB, write reg 7 = 0xC00D,
write original page
The PHY now switches back to the original page (normally the copper page after reset) between the page 0xFF part and the page 0xFB part of the vendor errata sequence. The number of MDIO transactions also goes from 11 to about 15.
These are undocumented vendor registers, so it isn't clear whether the extra page switch matters to the hardware.
The commit message only says:
"This reduces the number of bus lock/unlock cycles and restores the previous page if one of the errata writes fails."
Could the commit message also mention the changed write sequence on the success path? Could it also say whether this was tested on 88E1510/1518/ 1512/1514 Rev A0 parts?
The last patch of the series, "net: phy: marvell: add RGMII-to-Copper mode configuration", leaves this code as it is.
Quoted 10 lines
drivers/net/phy/marvell.c +7
-0+} + +static int m88e1510_config_init (struct phy_device *phydev) +{ +int err; + + err =m88e1510_eee_errata (phydev);if (err <0 )return err; err =marvell_set_page (phydev,MII_MARVELL_COPPER_PAGE );
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-marvell-phy-rgmii-v2-0-e04dca67e89a%40bootlin.com
PATCH v2 4/4 net: phy: marvell: add RGMII-to-Copper mode configuration
In reply to Paul LouvelThe driver currently programs the mode only for SGMII-to-Copper, based on the PHY interface mode.
Some MACs connect to the PHY via RGMII. Add code in m88e1510_config_init() to configure the device.
Do not overwrite the media interface mode configured via m88e1510_port_configure_serdes().
--- drivers/net/phy/marvell.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/net/phy/marvell.c +20 -1
@@ -1341,6 +1341,23 @@ static int m88e1510_config_mode(struct phy_device *phydev, u16 mode)if (oldpage <0 ) goto error; + ret =__phy_read (phydev,MII_88E1510_GEN_CTRL_REG_1 ); +if (ret <0 ) + goto error; + +if (mode ==MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII ) { +switch (FIELD_GET (MII_88E1510_GEN_CTRL_REG_1_MODE_MASK , ret)) { +case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII : +case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X : +case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX : +case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII : + ret =0 ; + goto error; +default : +break ; + } + } + ret =__phy_modify (phydev,MII_88E1510_GEN_CTRL_REG_1 ,MII_88E1510_GEN_CTRL_REG_1_MODE_MASK , mode);if (ret <0 )
@@ -1403,9 +1420,11 @@ static int m88e1510_config_init(struct phy_device *phydev)if (err <0 )return err; -/* SGMII-to-Copper mode initialization */ +/* RGMII/SGMII-to-Copper mode initialization */ if (phydev->interface ==PHY_INTERFACE_MODE_SGMII ) err =m88e1510_config_mode (phydev,MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII ); +else if (phy_interface_is_rgmii (phydev)) + err =m88e1510_config_mode (phydev,MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII );if (err <0 )return err;
Signature · 1 line
2.56.1
Hi Paul,
Quoted 10 lines · Paul Louvel
The driver currently programs the mode only for SGMII-to-Copper, based on the PHY interface mode.
Some MACs connect to the PHY via RGMII. Add code in
m88e1510_config_init()to configure the device.Do not overwrite the media interface mode configured via
m88e1510_port_configure_serdes().Signed-off-by Paul Louvel (Schneider Electric) <[email protected]>
FWIW I've tested that on a SGMII-to-Copper 88e1512 PHY, and no regressions found. I can't test on RGMII though :)
Maxime
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] This patch breaks the SFP-removal (serdes disable) path.
- [Medium] The new RGMII config_init path does not achieve its stated purpose ('Add code in m88e1510_config_init() to configure the device')…
--
net: phy: marvell: add RGMII-to-Copper mode configuration
With this commit, m88e1510_config_init() programs the RGMII-to-Copper mode in GEN_CTRL_REG_1 when the PHY interface is RGMII. It also adds a check to m88e1510_config_mode() so that an RGMII request does not overwrite an RGMII media mode already present in the register.
Quoted 14 lines
drivers/net/phy/marvell.c +6
-0@@ -1341,6 +1341,23 @@ static int m88e1510_config_mode(struct phy_device *phydev, u16 mode)if (oldpage <0 ) goto error; + ret =__phy_read (phydev,MII_88E1510_GEN_CTRL_REG_1 ); +if (ret <0 ) + goto error; + +if (mode ==MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII ) { +switch (FIELD_GET (MII_88E1510_GEN_CTRL_REG_1_MODE_MASK , ret)) {
drivers/net/phy/marvell.c static int m88e1510_config_mode(struct phy_device *phydev, u16 mode) · line 1359
Quoted 10 lines
drivers/net/phy/marvell.c +10
-0+case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII : +case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_1000X : +case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_100FX : +case MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII : + ret =0 ; + goto error; +default : +break ; + } + }
[Severity: High]
This check sits in the shared helper. Does it also change the SFP removal path in m88e1510_port_configure_serdes()?
When an SFP module is inserted, phy_sfp_module_insert() calls configure_mii(port, true, iface). That writes RGMII_1000X, RGMII_100FX or RGMII_SGMII into the mode field. On removal the call chain is:
phy_sfp_module_remove()
m88e1510_port_configure_serdes(port, false, PHY_INTERFACE_MODE_NA)
mode = MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII;
m88e1510_config_mode(phydev, mode)The register still holds one of the serdes modes at that point. The new switch matches it, sets ret = 0 and jumps to error. That skips both the __phy_modify() of the mode field and the MII_88E1510_GEN_CTRL_REG_1_RESET soft reset.
Does that leave the PHY in RGMII-to-fiber/SGMII mode after the module is removed, even though the caller sees success?
On resume or re-attach, m88e1510_config_init() also requests MODE_RGMII for RGMII interfaces, so it would hit the same early return. Is a hardware reset the only way to get back to copper mode?
Before this patch, the disable path always wrote MODE_RGMII and then did the soft reset.
Could this be decided explicitly, through a caller argument or driver state, instead of from the current register value?
drivers/net/phy/marvell.c static int m88e1510_config_init(struct phy_device *phydev) · line 1427
Quoted 13 lines
drivers/net/phy/marvell.c +3
-1ret =__phy_modify (phydev,MII_88E1510_GEN_CTRL_REG_1 ,MII_88E1510_GEN_CTRL_REG_1_MODE_MASK , mode);if (ret <0 )@@ -1403,9 +1420,11 @@ static int m88e1510_config_init(struct phy_device *phydev)if (err <0 )return err; -/* SGMII-to-Copper mode initialization */ +/* RGMII/SGMII-to-Copper mode initialization */ if (phydev->interface ==PHY_INTERFACE_MODE_SGMII ) err =m88e1510_config_mode (phydev,MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII ); +else if (phy_interface_is_rgmii (phydev)) + err =m88e1510_config_mode (phydev,MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII );
[Severity: Medium]
The commit message says:
Do not overwrite the media interface mode configured via m88e1510_port_configure_serdes().
However, the check in m88e1510_config_mode() only looks at the hardware mode field. It keeps any RGMII_1000X, RGMII_100FX or RGMII_SGMII value, whoever wrote it.
Suppose an RGMII board comes up with GEN_CTRL_REG_1[2:0] already set to one of those values. The source could be the bootloader, strapping, or state left over across kexec or a driver rebind. Would this call then skip both the mode write and the soft reset, and leave the PHY out of copper mode?
As written, the new RGMII call seems to take effect only when the field reads 0x1 or 0x5-0x7. Is that intended?
The driver does not record whether the serdes mode came from m88e1510_port_configure_serdes(). Could that be tracked in driver state so the code does what the commit message describes? The same change would also fix the SFP removal issue above.
Quoted 3 lines
drivers/net/phy/marvell.c +0
-0if (err <0 )return err;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-marvell-phy-rgmii-v2-0-e04dca67e89a%40bootlin.com