net: phy: dp83822: Fix RGMII TX delay configuration
Subsystems (3)
PATCH v2 1/1 net: phy: dp83822: Fix RGMII TX delay configuration
The logic for enabling the TX clock shift is inverse of enabling the RX clock shift. The TX clock shift is disabled when DP83822_TX_CLK_SHIFT is set. Correct the current behavior and always write the delay configuration to ensure consistent delay settings regardless of bootloader configuration.
Reference: https://www.ti.com/lit/ds/symlink/dp83822i.pdf p. 69
---
Changes in v2:
- Further cleanup of RGMII configuration
- Check for errors setting DP83822_RGMII_MODE_EN
--- drivers/net/phy/dp83822.c | 41 +++++++++++++-------------------------- 1 file changed, 14 insertions(+), 27 deletions(-)
drivers/net/phy/dp83822.c +14 -27
@@ -380,42 +380,29 @@ static int dp83822_config_init(struct phy_device *phydev) {struct dp83822_private *dp83822 = phydev->priv;struct device *dev = &phydev->mdio.dev; -int rgmii_delay; -s32 rx_int_delay; -s32 tx_int_delay; +int rcsr_mask =DP83822_RGMII_MODE_EN ; +int rcsr =0 ;int err =0 ;int bmcr;if (phy_interface_is_rgmii (phydev)) { - rx_int_delay =phy_get_internal_delay (phydev, dev,NULL ,0 , - true); + rcsr |=DP83822_RGMII_MODE_EN ; -if (rx_int_delay <=0 ) - rgmii_delay =0 ; -else - rgmii_delay =DP83822_RX_CLK_SHIFT ; +/* Set DP83822_RX_CLK_SHIFT to enable rx clk internal delay */ +if (phy_get_internal_delay (phydev, dev,NULL ,0 , true) >0 ) + rcsr |=DP83822_RX_CLK_SHIFT ; - tx_int_delay =phy_get_internal_delay (phydev, dev,NULL ,0 , - false); -if (tx_int_delay <=0 ) - rgmii_delay &= ~DP83822_TX_CLK_SHIFT ; -else - rgmii_delay |=DP83822_TX_CLK_SHIFT ; +/* Set DP83822_TX_CLK_SHIFT to disable tx clk internal delay */ +if (phy_get_internal_delay (phydev, dev,NULL ,0 , false) <=0 ) + rcsr |=DP83822_TX_CLK_SHIFT ; -if (rgmii_delay) { - err =phy_set_bits_mmd (phydev,DP83822_DEVADDR , -MII_DP83822_RCSR , rgmii_delay); -if (err) -return err; - } - -phy_set_bits_mmd (phydev,DP83822_DEVADDR , -MII_DP83822_RCSR ,DP83822_RGMII_MODE_EN ); - }else { -phy_clear_bits_mmd (phydev,DP83822_DEVADDR , -MII_DP83822_RCSR ,DP83822_RGMII_MODE_EN ); + rcsr_mask |=DP83822_RX_CLK_SHIFT |DP83822_TX_CLK_SHIFT ; } + err =phy_modify_mmd (phydev,DP83822_DEVADDR ,MII_DP83822_RCSR , rcsr_mask, rcsr); +if (err <0 ) +return err; +if (dp83822->fx_enabled) { err =phy_modify (phydev,MII_DP83822_CTRL_2 ,DP83822_FX_ENABLE ,1 );
Signature · 1 line
2.43.0
Paolo Abeni
maintainerQuoted 5 lines · Tim Pambor
The logic for enabling the TX clock shift is inverse of enabling the RX clock shift. The TX clock shift is disabled when
DP83822_TX_CLK_SHIFTis set. Correct the current behavior and always write the delay configuration to ensure consistent delay settings regardless of bootloader configuration.
Quoted 7 lines
Reference: https://www.ti.com/lit/ds/symlink/dp83822i.pdf p. 69
Fixes 8095295292b5 ("net: phy: DP83822: Add setting the fixed internal delay")Signed-off-by Tim Pambor <[email protected]>---
Changes in v2:
- Further cleanup of RGMII configuration
This overall makes the change more invasive, I'm unsure is in the direction pointed by Russell
Quoted 47 lines
- Check for errors setting
DP83822_RGMII_MODE_EN--- drivers/net/phy/dp83822.c | 41 +++++++++++++-------------------------- 1 file changed, 14 insertions(+), 27 deletions(-)drivers/net/phy/dp83822.c +9
-18@@ -380,42 +380,29 @@ static int dp83822_config_init(struct phy_device *phydev) {struct dp83822_private *dp83822 = phydev->priv;struct device *dev = &phydev->mdio.dev; -int rgmii_delay; -s32 rx_int_delay; -s32 tx_int_delay; +int rcsr_mask =DP83822_RGMII_MODE_EN ; +int rcsr =0 ;int err =0 ;int bmcr;if (phy_interface_is_rgmii (phydev)) { - rx_int_delay =phy_get_internal_delay (phydev, dev,NULL ,0 , - true); + rcsr |=DP83822_RGMII_MODE_EN ; -if (rx_int_delay <=0 ) - rgmii_delay =0 ; -else - rgmii_delay =DP83822_RX_CLK_SHIFT ; +/* Set DP83822_RX_CLK_SHIFT to enable rx clk internal delay */ +if (phy_get_internal_delay (phydev, dev,NULL ,0 , true) >0 ) + rcsr |=DP83822_RX_CLK_SHIFT ; - tx_int_delay =phy_get_internal_delay (phydev, dev,NULL ,0 , - false); -if (tx_int_delay <=0 ) - rgmii_delay &= ~DP83822_TX_CLK_SHIFT ; -else - rgmii_delay |=DP83822_TX_CLK_SHIFT ; +/* Set DP83822_TX_CLK_SHIFT to disable tx clk internal delay */ +if (phy_get_internal_delay (phydev, dev,NULL ,0 , false) <=0 ) + rcsr |=DP83822_TX_CLK_SHIFT ; -if (rgmii_delay) { - err =phy_set_bits_mmd (phydev,DP83822_DEVADDR , -MII_DP83822_RCSR , rgmii_delay);
drivers/net/phy/dp83822.c static int dp83822_config_init(struct phy_device *phydev) · line 399
Quoted 10 lines
drivers/net/phy/dp83822.c +1
-9-if (err) -return err; - } - -phy_set_bits_mmd (phydev,DP83822_DEVADDR , -MII_DP83822_RCSR ,DP83822_RGMII_MODE_EN ); - }else { -phy_clear_bits_mmd (phydev,DP83822_DEVADDR , -MII_DP83822_RCSR ,DP83822_RGMII_MODE_EN ); + rcsr_mask |=DP83822_RX_CLK_SHIFT |DP83822_TX_CLK_SHIFT ;
It looks like there is a change of behavior here. The current code clear the DP83822_RGMII_MODE_EN, while this patch will clear DP83822_RX_CLK_SHIFT | DP83822_TX_CLK_SHIFT, leaving DP83822_RGMII_MODE_EN unmodified.
It does not look correct to me.
Cheers,
Paolo
Hi Paolo,
Quoted 89 lines · Paolo Abeni
Quoted 9 lines · Tim Pambor
The logic for enabling the TX clock shift is inverse of enabling the RX
clock shift. The TX clock shift is disabled whenDP83822_TX_CLK_SHIFTis
set. Correct the current behavior and always write the delay configuration
to ensure consistent delay settings regardless of bootloader configuration.Quoted 8 lines
Reference: https://www.ti.com/lit/ds/symlink/dp83822i.pdf p. 69
Fixes 8095295292b5 ("net: phy: DP83822: Add setting the fixedinternal delay")
Signed-off-by Tim Pambor <[email protected]>---
Changes in v2:
- Further cleanup of RGMII configurationThis overall makes the change more invasive, I'm unsure is in the direction pointed by Russell
Quoted 67 lines
- Check for errors setting
DP83822_RGMII_MODE_EN
---
drivers/net/phy/dp83822.c | 41 +++++++++++++----------------------
----1 file changed, 14 insertions(+), 27 deletions(-)drivers/net/phy/dp83822.c +2
-3@@ -380,42 +380,29 @@ static int dp83822_config_init(struct phy_device *phydev) { struct dp83822_private *dp83822 = phydev->priv; struct device *dev = &phydev->mdio.dev; -int rgmii_delay; -s32 rx_int_delay; -s32 tx_int_delay; +int rcsr_mask =DP83822_RGMII_MODE_EN ; +int rcsr =0 ; int err = 0; int bmcr;
if (phy_interface_is_rgmii(phydev)) {drivers/net/phy/dp83822.c +0
-1- rx_int_delay = phy_get_internal_delay(phydev, dev,NULL, 0,
drivers/net/phy/dp83822.c +1
-1- true); + rcsr |=DP83822_RGMII_MODE_EN ;drivers/net/phy/dp83822.c +1
-4-if (rx_int_delay <=0 ) - rgmii_delay =0 ; -else - rgmii_delay =DP83822_RX_CLK_SHIFT ; +/* Set DP83822_RX_CLK_SHIFT to enable rx clk internal delay */
drivers/net/phy/dp83822.c +1
-0+ if (phy_get_internal_delay(phydev, dev, NULL, 0,true) > 0)
drivers/net/phy/dp83822.c +1
-0+ rcsr |=DP83822_RX_CLK_SHIFT ;drivers/net/phy/dp83822.c +0
-1- tx_int_delay = phy_get_internal_delay(phydev, dev,NULL, 0,
drivers/net/phy/dp83822.c +1
-5- false); -if (tx_int_delay <=0 ) - rgmii_delay &= ~DP83822_TX_CLK_SHIFT ; -else - rgmii_delay |=DP83822_TX_CLK_SHIFT ; +/* Set DP83822_TX_CLK_SHIFT to disable tx clk internal delay */
drivers/net/phy/dp83822.c +1
-0+ if (phy_get_internal_delay(phydev, dev, NULL, 0,false) <= 0)
drivers/net/phy/dp83822.c +1
-0+ rcsr |=DP83822_TX_CLK_SHIFT ;drivers/net/phy/dp83822.c +0
-2-if (rgmii_delay) { - err = phy_set_bits_mmd(phydev,
DP83822_DEVADDR,drivers/net/phy/dp83822.c +0
-1- MII_DP83822_RCSR,
rgmii_delay);drivers/net/phy/dp83822.c +0
-6-if (err) -return err; - } - - phy_set_bits_mmd(phydev, DP83822_DEVADDR, - MII_DP83822_RCSR,
DP83822_RGMII_MODE_EN);drivers/net/phy/dp83822.c +0
-3- }else { - phy_clear_bits_mmd(phydev, DP83822_DEVADDR, - MII_DP83822_RCSR,
Quoted 8 lines
Quoted 3 lines
DP83822_RGMII_MODE_EN);drivers/net/phy/dp83822.c +1
-0+ rcsr_mask |= DP83822_RX_CLK_SHIFT |
DP83822_TX_CLK_SHIFT;It looks like there is a change of behavior here. The current code clear the
DP83822_RGMII_MODE_EN, while this patch will clearDP83822_RX_CLK_SHIFT|DP83822_TX_CLK_SHIFT, leavingDP83822_RGMII_MODE_ENunmodified.
The behavior of DP83822_RGMII_MODE_EN should not have changed. DP83822_RGMII_MODE_EN is always set in rcsr_mask and if the interface is RGMII, DP83822_RX_CLK_SHIFT and DP83822_TX_CLK_SHIFT are added to the mask as well.
I also have tested this patch on hardware with a DP83822 phy in RGMII mode.
Quoted 7 lines
It does not look correct to me.
Cheers,
Paolo