Skip to contentSkip to conversation

net: phy: Rename KSZ9477 get features function (to ksz9131_get_features)

PATCH In review Lukasz Majewski 4 participants 22 messages Aug 30, 2023 – Aug 31, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net: phy: Rename KSZ9477 get features function (to ksz9131_get_features)

The KSZ9131 differs in supported features from KSZ9477 - namely in the EEE (Energy Efficient Ethernet) support.

To prepare the code for upcoming changes the ksz9477_get_features has been renamed to ksz9131_get_features.

---
 drivers/net/phy/micrel.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/phy/micrel.c +3 -3
index b6d7981b2d1e..87b090ad2874 100644
@@ -1398,7 +1398,7 @@ static int ksz9131_config_aneg(struct phy_device *phydev)
 	return genphy_config_aneg(phydev);
 }
 
-static int ksz9477_get_features(struct phy_device *phydev)
+static int ksz9131_get_features(struct phy_device *phydev)
 {
 	int ret;
 
@@ -4829,7 +4829,7 @@ static struct phy_driver ksphy_driver[] = {
 	.resume		= kszphy_resume,
 	.cable_test_start	= ksz9x31_cable_test_start,
 	.cable_test_get_status	= ksz9x31_cable_test_get_status,
-	.get_features	= ksz9477_get_features,
+	.get_features	= ksz9131_get_features,
 }, {
 	.phy_id		= PHY_ID_KSZ8873MLL,
 	.phy_id_mask	= MICREL_PHY_ID_MASK,
@@ -4871,7 +4871,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9477_get_features,
+	.get_features	= ksz9131_get_features,
 } };
 
 module_phy_driver(ksphy_driver);
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +30 -1
index 87b090ad2874..469dcd8a5711 100644
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct phy_device *phydev)
 	return 0;
 }
 
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature select must be
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not fully
+	 *   operational. It must be manually disabled through register
+	 *   controls. If not disabled, the PHY ports can auto-negotiate
+	 *   to enable EEE, and this feature can cause link drops when linked
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that EEE is
+	 *   operational one needs to manualy clear them to follow the chip
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported, zero);
+
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,
 } };
 
 module_phy_driver(ksphy_driver);
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 8 lines · Lukasz Majewski

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

Hi,

As the net is target you should add fixes tag which the commit that your changes is fixing (workarounding :) )

Quoted 9 lines
---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +0 -0
index 87b090ad2874..469dcd8a5711 100644

drivers/net/phy/micrel.c static int ksz9131_get_features(struct phy_device *phydev) · line 1423

Quoted 6 lines
drivers/net/phy/micrel.c +3 -0
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct phy_device *phydev)
 	return 0;
 }
 
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };

= { 0 };

Quoted 41 lines
drivers/net/phy/micrel.c +27 -1
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature select must be
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not fully
+	 *   operational. It must be manually disabled through register
+	 *   controls. If not disabled, the PHY ports can auto-negotiate
+	 *   to enable EEE, and this feature can cause link drops when linked
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that EEE is
+	 *   operational one needs to manualy clear them to follow the chip
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported, zero);
+
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,
 } };
 
 module_phy_driver(ksphy_driver);
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Hi Michal,

Quoted 5 lines · Lukasz Majewski
Quoted 4 lines

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

Quoted 9 lines
Quoted 4 lines

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

Hi,

As the net is target you should add fixes tag which the commit that your changes is fixing (workarounding :) )

I'm applying code for vendor's errata.

I will search when it has been modified.

Quoted 12 lines
Quoted 12 lines
---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +0 -0
index 87b090ad2874..469dcd8a5711 100644
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct
 phy_device *phydev) return 0;
 }
 
Quoted 4 lines

drivers/net/phy/micrel.c static int ksz9131_get_features(struct phy_device *phydev) · line 1423

Quoted 3 lines
drivers/net/phy/micrel.c +3 -0
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };  

= { 0 };

Ok.

Quoted 45 lines
Quoted 45 lines
drivers/net/phy/micrel.c +9 -0
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature

select must be

drivers/net/phy/micrel.c +2 -0
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not

fully

drivers/net/phy/micrel.c +1 -0
+	 *   operational. It must be manually disabled through

register

drivers/net/phy/micrel.c +1 -0
+	 *   controls. If not disabled, the PHY ports can

auto-negotiate

drivers/net/phy/micrel.c +1 -0
+	 *   to enable EEE, and this feature can cause link drops

when linked

drivers/net/phy/micrel.c +4 -0
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that

EEE is

drivers/net/phy/micrel.c +1 -0
+	 *   operational one needs to manualy clear them to follow

the chip

drivers/net/phy/micrel.c +3 -0
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported,

zero); +

drivers/net/phy/micrel.c +4 -1
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,
 } };
 
Quoted 4 lines
Quoted 4 lines
drivers/net/phy/micrel.c +0 -0
 module_phy_driver(ksphy_driver);
Signature · 1 line
2.20.1

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#4 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

In reply to Lukasz Majewski
Quoted 53 lines · Lukasz Majewski

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +29 -0
index 87b090ad2874..469dcd8a5711 100644
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct phy_device *phydev)
 	return 0;
 }
 
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature select must be
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not fully
+	 *   operational. It must be manually disabled through register
+	 *   controls. If not disabled, the PHY ports can auto-negotiate
+	 *   to enable EEE, and this feature can cause link drops when linked
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that EEE is
+	 *   operational one needs to manualy clear them to follow the chip
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported, zero);
+
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = { · line 4903

Quoted 5 lines
drivers/net/phy/micrel.c +1 -1
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,

Sorry, i didn't described all details how to implement it.

This code will break EEE support for the KSZ8563R switch.

Please search for MICREL_KSZ8_P1_ERRATA in the kernel source. Then add new flag, for example MICREL_NO_EEE and use it in a similar way how MICREL_KSZ8_P1_ERRATA was set and used. With this implementation, first patch is not needed.

The code will be something like this:
if (dev_flags & MICREL_NO_EEE)

      /* lots of comments */
      linkmode_and(phydev->supported_eee, phydev->supported, zero);
   else
      /* lots of other comments */
      linkmode_and(phydev->supported_eee, phydev->supported,
                   PHY_EEE_CAP1_FEATURES);

On the switch driver side i would expect something like this:
ksz_get_phy_flags(struct dsa_switch *ds, int port)

       swtich (dev->chip_id)
       case KSZ8830_CHIP_ID:
         ....
         break;
       case KSZ9477_CHIP_ID:
         return MICREL_NO_EEE;

Regards,
Oleksij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Hi Oleksij,

Quoted 69 lines · Lukasz Majewski
Quoted 60 lines

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +12 -0
index 87b090ad2874..469dcd8a5711 100644
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct
 phy_device *phydev) return 0;
 }
 
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature

select must be

drivers/net/phy/micrel.c +2 -0
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not

fully

drivers/net/phy/micrel.c +1 -0
+	 *   operational. It must be manually disabled through

register

drivers/net/phy/micrel.c +1 -0
+	 *   controls. If not disabled, the PHY ports can

auto-negotiate

drivers/net/phy/micrel.c +1 -0
+	 *   to enable EEE, and this feature can cause link drops

when linked

drivers/net/phy/micrel.c +4 -0
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that

EEE is

drivers/net/phy/micrel.c +1 -0
+	 *   operational one needs to manualy clear them to follow

the chip

drivers/net/phy/micrel.c +3 -0
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported,

zero); +

drivers/net/phy/micrel.c +3 -0
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = { · line 4903

Quoted 5 lines
drivers/net/phy/micrel.c +1 -1
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,  

Sorry, i didn't described all details how to implement it.

Quoted 2 lines

This code will break EEE support for the KSZ8563R switch.

And then another switch (KSZ8563R) pops up.... with regression....

In the micrel.c the ksz9477_get_features was only present in:
https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/micrel.c#L4832
https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/micrel.c#L4874
so I only changed it there.

Apparently the KSZ8563R re-uses the KSZ9477 code.

Quoted 17 lines

Please search for MICREL_KSZ8_P1_ERRATA in the kernel source. Then add new flag, for example MICREL_NO_EEE and use it in a similar way how MICREL_KSZ8_P1_ERRATA was set and used. With this implementation, first patch is not needed.

The code will be something like this:

   if (dev_flags & MICREL_NO_EEE)
      /* lots of comments */
      linkmode_and(phydev->supported_eee, phydev->supported, zero);
   else
      /* lots of other comments */
      linkmode_and(phydev->supported_eee, phydev->supported,
                   PHY_EEE_CAP1_FEATURES);

On the switch driver side i would expect something like this:
ksz_get_phy_flags(struct dsa_switch *ds, int port)

Quoted 7 lines
       swtich (dev->chip_id)
       case KSZ8830_CHIP_ID:
         ....
         break;
       case KSZ9477_CHIP_ID:
         return MICREL_NO_EEE;

Ok.

Quoted 3 lines

Regards,
Oleksij

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#6 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 71 lines · Lukasz Majewski

Hi Oleksij,

Quoted 69 lines · Lukasz Majewski
Quoted 60 lines

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +12 -0
index 87b090ad2874..469dcd8a5711 100644
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct
 phy_device *phydev) return 0;
 }
 
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature

select must be

drivers/net/phy/micrel.c +2 -0
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not

fully

drivers/net/phy/micrel.c +1 -0
+	 *   operational. It must be manually disabled through

register

drivers/net/phy/micrel.c +1 -0
+	 *   controls. If not disabled, the PHY ports can

auto-negotiate

drivers/net/phy/micrel.c +1 -0
+	 *   to enable EEE, and this feature can cause link drops

when linked

drivers/net/phy/micrel.c +4 -0
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that

EEE is

drivers/net/phy/micrel.c +1 -0
+	 *   operational one needs to manualy clear them to follow

the chip

drivers/net/phy/micrel.c +3 -0
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported,

zero); +

drivers/net/phy/micrel.c +3 -0
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = { · line 4903

Quoted 5 lines
drivers/net/phy/micrel.c +1 -1
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,  

Sorry, i didn't described all details how to implement it.

Quoted 4 lines
Quoted 2 lines

This code will break EEE support for the KSZ8563R switch.

And then another switch (KSZ8563R) pops up.... with regression....

Initially ksz9477_get_features() was introduced to fix KSZ8563R.

Quoted 6 lines

In the micrel.c the ksz9477_get_features was only present in:
https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/micrel.c#L4832
https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/micrel.c#L4874
so I only changed it there.

Apparently the KSZ8563R re-uses the KSZ9477 code.

Most (all?) switch variant support by the ksz9477 DSA driver share the same PHYid, so it is not possible to identify it by the micrel.c PHY driver. As far as a know, the only commonly accepted way to notify about some quirks between this both drivers is not user dev_flags.

Regards,
Oleskij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#7 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Hi Oleksij,

Quoted 84 lines · Lukasz Majewski
Quoted 71 lines

Hi Oleksij,

Quoted 69 lines · Lukasz Majewski
Quoted 60 lines

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +12 -0
index 87b090ad2874..469dcd8a5711 100644
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct
 phy_device *phydev) return 0;
 }
 
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature

select must be

drivers/net/phy/micrel.c +2 -0
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is

not fully

drivers/net/phy/micrel.c +1 -0
+	 *   operational. It must be manually disabled through

register

drivers/net/phy/micrel.c +1 -0
+	 *   controls. If not disabled, the PHY ports can

auto-negotiate

drivers/net/phy/micrel.c +1 -0
+	 *   to enable EEE, and this feature can cause link

drops when linked

drivers/net/phy/micrel.c +4 -0
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that

EEE is

drivers/net/phy/micrel.c +1 -0
+	 *   operational one needs to manualy clear them to

follow the chip

drivers/net/phy/micrel.c +3 -0
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported,

zero); +

drivers/net/phy/micrel.c +3 -0
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = · line 4903

Quoted 5 lines
drivers/net/phy/micrel.c +1 -1
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] =
 { .handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,    

Sorry, i didn't described all details how to implement it.

Quoted 4 lines
Quoted 2 lines

This code will break EEE support for the KSZ8563R switch.

And then another switch (KSZ8563R) pops up.... with regression....

Initially ksz9477_get_features() was introduced to fix KSZ8563R.

Quoted 5 lines

In the micrel.c the ksz9477_get_features was only present in:
https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/micrel.c#L4832
https://elixir.bootlin.com/linux/latest/source/drivers/net/phy/micrel.c#L4874
so I only changed it there.

Quoted 8 lines
Quoted 1 line

Apparently the KSZ8563R re-uses the KSZ9477 code.

Most (all?) switch variant support by the ksz9477 DSA driver share the same PHYid, so it is not possible to identify it by the micrel.c PHY driver. As far as a know, the only commonly accepted way to notify about some quirks between this both drivers is not user dev_flags.

We would need another idea on fixing this problem as there is following order of function calls:

-> ksz9477_setup
-> ksz9477_get_features (here we are supposed to use the MICREL_NO_EEE flag)
-> ksz_get_phy_flags (here we are supposed to set the MICREL_NO_EEE flag)

The ksz9477_get_features is called early.

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

It would clear the 7.60 per-port register with two ksz_write16 functions.

That exactly follows the recommendation for KSZ9477 Errata Module4.

Quoted 2 lines

Regards,
Oleskij

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#8 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 5 lines · Lukasz Majewski

Hi Oleksij,

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

In this case, please add the reason why it would work on this HW and will not break by any changes in PHYlib or micrel.c driver.

If I remember it correctly, in KSZ9477 variants, if you write to EEE advertisement register, it will affect the state of a EEE capability register. Which break IEEE 802.3 specification and the reason why ksz9477_get_features() actually exist. But can be used as workaround if it is written early enough before PHYlib tried to read EEE capability register.

Please confirm my assumption by applying your workaround and testing it with ethtool --show-eee lanX.

It should be commented in the code with all kind of warnings:
Don't move!!! We use one bug to workaround another bug!!! If PHYlib start scanning PHYs before this code is executed, then thing may break!!

... it is broken as hell....

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#9 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 17 lines · Oleksij Rempel
Quoted 5 lines · Lukasz Majewski

Hi Oleksij,

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

In this case, please add the reason why it would work on this HW and will not break by any changes in PHYlib or micrel.c driver.

If I remember it correctly, in KSZ9477 variants, if you write to EEE advertisement register, it will affect the state of a EEE capability register. Which break IEEE 802.3 specification and the reason why ksz9477_get_features() actually exist. But can be used as workaround if it is written early enough before PHYlib tried to read EEE capability register.

Quoted 6 lines

Please confirm my assumption by applying your workaround and testing it with ethtool --show-eee lanX.

It should be commented in the code with all kind of warnings:
Don't move!!! We use one bug to workaround another bug!!! If PHYlib start scanning PHYs before this code is executed, then thing may break!!

Why would phylib's scanning cause breakage?

phylib's scanning for PHYs is about reading the ID registers etc. It doesn't do anything until the PHY has been found, and then the first thing that happens when the phy_device structure is created is an appropriate driver is located, and the driver's ->probe function is called.

If that is successful, then the fewatures are read. If the PHY driver's ->features member is set, then that initialises the "supported" mask and we read the EEE abilities.

If ->features is not set, then we look to see whether the driver provides a ->get_features method, and call that.

Otherwise we use the generic genphy_c45_pma_read_abilities() or genphy_read_abilities() depending whether the PHY's is_c45 is set or not.

So, if you want to do something very early before features are read, then either don't set .features, and do it early in .get_features before calling anything else, or do it in the ->probe function.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#10 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 40 lines · Russell King (Oracle)
Quoted 17 lines · Oleksij Rempel
Quoted 5 lines · Lukasz Majewski

Hi Oleksij,

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

In this case, please add the reason why it would work on this HW and will not break by any changes in PHYlib or micrel.c driver.

If I remember it correctly, in KSZ9477 variants, if you write to EEE advertisement register, it will affect the state of a EEE capability register. Which break IEEE 802.3 specification and the reason why ksz9477_get_features() actually exist. But can be used as workaround if it is written early enough before PHYlib tried to read EEE capability register.

Quoted 6 lines

Please confirm my assumption by applying your workaround and testing it with ethtool --show-eee lanX.

It should be commented in the code with all kind of warnings:
Don't move!!! We use one bug to workaround another bug!!! If PHYlib start scanning PHYs before this code is executed, then thing may break!!

Why would phylib's scanning cause breakage?

phylib's scanning for PHYs is about reading the ID registers etc. It doesn't do anything until the PHY has been found, and then the first thing that happens when the phy_device structure is created is an appropriate driver is located, and the driver's ->probe function is called.

If that is successful, then the fewatures are read. If the PHY driver's ->features member is set, then that initialises the "supported" mask and we read the EEE abilities.

If ->features is not set, then we look to see whether the driver provides a ->get_features method, and call that.

Quoted 7 lines

Otherwise we use the generic genphy_c45_pma_read_abilities() or genphy_read_abilities() depending whether the PHY's is_c45 is set or not.

So, if you want to do something very early before features are read, then either don't set .features, and do it early in .get_features before calling anything else, or do it in the ->probe function.

Let me summarize my view on the problem, so may be you can suggest a better way to solve it.
- KSZ9477, KSZ8565, KSZ9893, KSZ9563, seems to have different quirks by the same PHYid. micrel.c driver do now know what exact HW is actually in use.
- A set of PHY workarounds was moved from dsa/microchip/ksz9477.c to micrel.c, one of this workaround was clearing EEE advertisement register, which by accident was clearing EEE capability register. Since EEE cap was cleared by the dsa/microchip/ksz9477.c code before micrel.c was probed, PHYlib was assuming that his PHY do not supports EEE and dint tried to use it.
After moving this code to micrel.c, it is now trying to change EEE advertisement state without letting PHYlib to know about it and PHYlib re enables it as actually excepted.
- so far, only KSZ9477 seems to be broken beyond repair, so it is better to disable EEE without giving it as a choice for user configuration.

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#11 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 49 lines · Oleksij Rempel
Quoted 40 lines · Russell King (Oracle)
Quoted 17 lines · Oleksij Rempel
Quoted 5 lines · Lukasz Majewski

Hi Oleksij,

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

In this case, please add the reason why it would work on this HW and will not break by any changes in PHYlib or micrel.c driver.

If I remember it correctly, in KSZ9477 variants, if you write to EEE advertisement register, it will affect the state of a EEE capability register. Which break IEEE 802.3 specification and the reason why ksz9477_get_features() actually exist. But can be used as workaround if it is written early enough before PHYlib tried to read EEE capability register.

Quoted 6 lines

Please confirm my assumption by applying your workaround and testing it with ethtool --show-eee lanX.

It should be commented in the code with all kind of warnings:
Don't move!!! We use one bug to workaround another bug!!! If PHYlib start scanning PHYs before this code is executed, then thing may break!!

Why would phylib's scanning cause breakage?

phylib's scanning for PHYs is about reading the ID registers etc. It doesn't do anything until the PHY has been found, and then the first thing that happens when the phy_device structure is created is an appropriate driver is located, and the driver's ->probe function is called.

If that is successful, then the fewatures are read. If the PHY driver's ->features member is set, then that initialises the "supported" mask and we read the EEE abilities.

If ->features is not set, then we look to see whether the driver provides a ->get_features method, and call that.

Quoted 7 lines

Otherwise we use the generic genphy_c45_pma_read_abilities() or genphy_read_abilities() depending whether the PHY's is_c45 is set or not.

So, if you want to do something very early before features are read, then either don't set .features, and do it early in .get_features before calling anything else, or do it in the ->probe function.

Quoted 16 lines

Let me summarize my view on the problem, so may be you can suggest a better way to solve it.
- KSZ9477, KSZ8565, KSZ9893, KSZ9563, seems to have different quirks by the same PHYid. micrel.c driver do now know what exact HW is actually in use.
- A set of PHY workarounds was moved from dsa/microchip/ksz9477.c to micrel.c, one of this workaround was clearing EEE advertisement register, which by accident was clearing EEE capability register. Since EEE cap was cleared by the dsa/microchip/ksz9477.c code before micrel.c was probed, PHYlib was assuming that his PHY do not supports EEE and dint tried to use it.
After moving this code to micrel.c, it is now trying to change EEE advertisement state without letting PHYlib to know about it and PHYlib re enables it as actually excepted.
- so far, only KSZ9477 seems to be broken beyond repair, so it is better to disable EEE without giving it as a choice for user configuration.

We do have support in phylib for "broken EEE modes" which DT could set for the broken PHYs, and as it is possible to describe the DSA PHYs in DT. This sets phydev->eee_broken_modes.

phydev->eee_broken_modes gets looked at when genphy_config_aneg() or genphy_c45_an_config_aneg() gets called - which will happen when the PHY is being "started".

So, you could add the DT properties as appropriate to disable all the EEE modes.

Alternatively, in your .config_init function, you could detect your flag and force eee_broken_modes to all-ones.

The problem with clearing ->supported_eee is that will stop genphy_c45_write_eee_adv() writing the advertisement register - which means if bits are set in the register, they won't be cleared because phylib thinks the registers aren't supported. So you won't actually be disabling anything by clearing ->supported_eee.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#12 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 75 lines · Russell King (Oracle)
Quoted 49 lines · Oleksij Rempel
Quoted 40 lines · Russell King (Oracle)
Quoted 17 lines · Oleksij Rempel
Quoted 5 lines · Lukasz Majewski

Hi Oleksij,

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

In this case, please add the reason why it would work on this HW and will not break by any changes in PHYlib or micrel.c driver.

If I remember it correctly, in KSZ9477 variants, if you write to EEE advertisement register, it will affect the state of a EEE capability register. Which break IEEE 802.3 specification and the reason why ksz9477_get_features() actually exist. But can be used as workaround if it is written early enough before PHYlib tried to read EEE capability register.

Quoted 6 lines

Please confirm my assumption by applying your workaround and testing it with ethtool --show-eee lanX.

It should be commented in the code with all kind of warnings:
Don't move!!! We use one bug to workaround another bug!!! If PHYlib start scanning PHYs before this code is executed, then thing may break!!

Why would phylib's scanning cause breakage?

phylib's scanning for PHYs is about reading the ID registers etc. It doesn't do anything until the PHY has been found, and then the first thing that happens when the phy_device structure is created is an appropriate driver is located, and the driver's ->probe function is called.

If that is successful, then the fewatures are read. If the PHY driver's ->features member is set, then that initialises the "supported" mask and we read the EEE abilities.

If ->features is not set, then we look to see whether the driver provides a ->get_features method, and call that.

Quoted 7 lines

Otherwise we use the generic genphy_c45_pma_read_abilities() or genphy_read_abilities() depending whether the PHY's is_c45 is set or not.

So, if you want to do something very early before features are read, then either don't set .features, and do it early in .get_features before calling anything else, or do it in the ->probe function.

Quoted 16 lines

Let me summarize my view on the problem, so may be you can suggest a better way to solve it.
- KSZ9477, KSZ8565, KSZ9893, KSZ9563, seems to have different quirks by the same PHYid. micrel.c driver do now know what exact HW is actually in use.
- A set of PHY workarounds was moved from dsa/microchip/ksz9477.c to micrel.c, one of this workaround was clearing EEE advertisement register, which by accident was clearing EEE capability register. Since EEE cap was cleared by the dsa/microchip/ksz9477.c code before micrel.c was probed, PHYlib was assuming that his PHY do not supports EEE and dint tried to use it.
After moving this code to micrel.c, it is now trying to change EEE advertisement state without letting PHYlib to know about it and PHYlib re enables it as actually excepted.
- so far, only KSZ9477 seems to be broken beyond repair, so it is better to disable EEE without giving it as a choice for user configuration.

We do have support in phylib for "broken EEE modes" which DT could set for the broken PHYs, and as it is possible to describe the DSA PHYs in DT. This sets phydev->eee_broken_modes.

phydev->eee_broken_modes gets looked at when genphy_config_aneg() or genphy_c45_an_config_aneg() gets called - which will happen when the PHY is being "started".

Quoted 5 lines

So, you could add the DT properties as appropriate to disable all the EEE modes.

Alternatively, in your .config_init function, you could detect your flag and force eee_broken_modes to all-ones.

@Lukasz,

can you please try to set eee_broken_modes to all-ones. Somewhat like this:
ksz9477_config_init()
...
...quirks...

   if (phydev->dev_flages & .. NO_EEE...)
       phydev->eee_broken_modes = -1;

   err = genphy_restart_aneg(phydev);
   ...

@Russell, thx!

Regards,
Oleksij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#13 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 10 lines · Oleksij Rempel

@Lukasz,

can you please try to set eee_broken_modes to all-ones. Somewhat like this:
ksz9477_config_init()
...
...quirks...

   if (phydev->dev_flages & .. NO_EEE...)
       phydev->eee_broken_modes = -1;

That's fine in config_init().

Quoted 1 line
   err = genphy_restart_aneg(phydev);

That isn't necessary, and in any case, calling it will just cause the AN enable and AN restart bits in BMCR to be set, nothing will be reprogrammed.

However, at a later point, when the PHY is started (by phy_start() being called) the state will be set to PHY_UP, and the state machine triggered. That sets needs_aneg which will then call phy_start_aneg().

That then goes on to call phy_config_aneg(), which will either call the driver specific config_aneg() function, or one of the two generic genphy.*config_aneg() functions. These will then program the EEE advertisement.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#14 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 12 lines · Russell King (Oracle)
Quoted 10 lines · Oleksij Rempel

@Lukasz,

can you please try to set eee_broken_modes to all-ones. Somewhat like this:
ksz9477_config_init()
...
...quirks...

   if (phydev->dev_flages & .. NO_EEE...)
       phydev->eee_broken_modes = -1;
Quoted 7 lines

That's fine in config_init().

Quoted 1 line
   err = genphy_restart_aneg(phydev);

That isn't necessary, and in any case, calling it will just cause the AN enable and AN restart bits in BMCR to be set, nothing will be reprogrammed.

ack. It is already existing code, see:
https://elixir.bootlin.com/linux/v6.5/source/drivers/net/phy/micrel.c#L1822

Setting eee_broken_modes probably can be done at any plaice in this function.

Regards,
Oleksij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#15 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

In reply to Oleksij Rempel

Hi Oleksij,

Quoted 97 lines · Russell King (Oracle)
Quoted 82 lines · Oleksij Rempel
Quoted 64 lines
Quoted 44 lines · Russell King (Oracle)
Quoted 19 lines · Oleksij Rempel
Quoted 5 lines · Lukasz Majewski

Hi Oleksij,

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

In this case, please add the reason why it would work on this HW and will not break by any changes in PHYlib or micrel.c driver.

If I remember it correctly, in KSZ9477 variants, if you write to EEE advertisement register, it will affect the state of a EEE capability register. Which break IEEE 802.3 specification and the reason why ksz9477_get_features() actually exist. But can be used as workaround if it is written early enough before PHYlib tried to read EEE capability register.

Quoted 7 lines

Please confirm my assumption by applying your workaround and testing it with ethtool --show-eee lanX.

It should be commented in the code with all kind of warnings:
Don't move!!! We use one bug to workaround another bug!!! If PHYlib start scanning PHYs before this code is executed, then thing may break!!

Why would phylib's scanning cause breakage?

phylib's scanning for PHYs is about reading the ID registers etc. It doesn't do anything until the PHY has been found, and then the first thing that happens when the phy_device structure is created is an appropriate driver is located, and the driver's ->probe function is called.

If that is successful, then the fewatures are read. If the PHY driver's ->features member is set, then that initialises the "supported" mask and we read the EEE abilities.

If ->features is not set, then we look to see whether the driver provides a ->get_features method, and call that.

Quoted 8 lines

Otherwise we use the generic genphy_c45_pma_read_abilities() or genphy_read_abilities() depending whether the PHY's is_c45 is set or not.

So, if you want to do something very early before features are read, then either don't set .features, and do it early in .get_features before calling anything else, or do it in the ->probe function.

Let me summarize my view on the problem, so may be you can suggest a better way to solve it.
- KSZ9477, KSZ8565, KSZ9893, KSZ9563, seems to have different quirks by the same PHYid. micrel.c driver do now know what exact HW is actually in use.
- A set of PHY workarounds was moved from dsa/microchip/ksz9477.c to micrel.c, one of this workaround was clearing EEE advertisement register, which by accident was clearing EEE capability
register. Since EEE cap was cleared by the

Quoted 8 lines

dsa/microchip/ksz9477.c code before micrel.c was probed, PHYlib was assuming that his PHY do not supports EEE and dint tried to use it. After moving this code to micrel.c, it is now trying to change EEE advertisement state without letting PHYlib to know about it and PHYlib re enables it as actually excepted.
- so far, only KSZ9477 seems to be broken beyond repair, so it is better to disable EEE without giving it as a choice for user configuration.

We do have support in phylib for "broken EEE modes" which DT could set for the broken PHYs, and as it is possible to describe the DSA PHYs in DT. This sets phydev->eee_broken_modes.

phydev->eee_broken_modes gets looked at when genphy_config_aneg() or genphy_c45_an_config_aneg() gets called - which will happen when the PHY is being "started".

Quoted 5 lines

So, you could add the DT properties as appropriate to disable all the EEE modes.

Alternatively, in your .config_init function, you could detect your flag and force eee_broken_modes to all-ones.

@Lukasz,

can you please try to set eee_broken_modes to all-ones. Somewhat like this:
ksz9477_config_init()
...
...quirks...

Quoted 6 lines
   if (phydev->dev_flages & .. NO_EEE...)
       phydev->eee_broken_modes = -1;

   err = genphy_restart_aneg(phydev);
   ...

The implementation as you suggested seems to work :-)

The ksz_get_phy_flags() - where the MICREL_NO_EEE is set is executed before ksz9477_config_init().

And then the eee_broken_modes are taken into account.

# ethtool --show-eee lan1
EEE Settings for lan1:
        EEE status: disabled
        Tx LPI: 0 (us)
        Supported EEE link modes:  100baseT/Full 
                                   1000baseT/Full 
        Advertised EEE link modes:  Not reported
        Link partner advertised EEE link modes:  Not reported

I will prepare tomorrow a proper patch.

Quoted 4 lines

@Russell, thx!

Regards,
Oleksij

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#16 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Hi Lukasz,

Quoted 18 lines · Lukasz Majewski

Hi Oleksij,

The implementation as you suggested seems to work :-)

The ksz_get_phy_flags() - where the MICREL_NO_EEE is set is executed before ksz9477_config_init().

And then the eee_broken_modes are taken into account.

# ethtool --show-eee lan1
EEE Settings for lan1:
        EEE status: disabled
        Tx LPI: 0 (us)
        Supported EEE link modes:  100baseT/Full 
                                   1000baseT/Full 
        Advertised EEE link modes:  Not reported
        Link partner advertised EEE link modes:  Not reported
Quoted 1 line

I will prepare tomorrow a proper patch.

can you please by the way remove this line:
https://elixir.bootlin.com/linux/v6.5/source/drivers/net/phy/micrel.c#L1803

it is obsolet by eee_broken_modes.

Regards,
Oleksij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#17 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 21 lines · Oleksij Rempel

Hi Lukasz,

Quoted 18 lines · Lukasz Majewski

Hi Oleksij,

The implementation as you suggested seems to work :-)

The ksz_get_phy_flags() - where the MICREL_NO_EEE is set is executed before ksz9477_config_init().

And then the eee_broken_modes are taken into account.

# ethtool --show-eee lan1
EEE Settings for lan1:
        EEE status: disabled
        Tx LPI: 0 (us)
        Supported EEE link modes:  100baseT/Full 
                                   1000baseT/Full 
        Advertised EEE link modes:  Not reported
        Link partner advertised EEE link modes:  Not reported
Quoted 6 lines
Quoted 1 line

I will prepare tomorrow a proper patch.

can you please by the way remove this line:
https://elixir.bootlin.com/linux/v6.5/source/drivers/net/phy/micrel.c#L1803

it is obsolet by eee_broken_modes.

... and if possible verify on the link partner side that indeed no EEE modes are being advertised by the Micrel device.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#18 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

In reply to Oleksij Rempel

Hi Oleksij,

Quoted 10 lines · Lukasz Majewski
Quoted 5 lines

Hi Oleksij,

It looks like the most optimal solution would be the one proposed by Tristam:
https://www.spinics.net/lists/netdev/msg932044.html

In this case, please add the reason why it would work on this HW and will not break by any changes in PHYlib or micrel.c driver.

The ksz9477_config_cpu_port() is called from ksz_setup. In this function we would clear 7.60 MMD register for EEE advertisement.

Only after the switch initialization, the phy code reads 7.60 register for each port and on that basis decides if the EEE is supported or not.

(And only then ksz9477_get_features() is executed. Finally ksz_get_phy_flags() is called.

Quoted 10 lines

If I remember it correctly, in KSZ9477 variants, if you write to EEE advertisement register, it will affect the state of a EEE capability register. Which break IEEE 802.3 specification and the reason why ksz9477_get_features() actually exist. But can be used as workaround if it is written early enough before PHYlib tried to read EEE capability register.

Please confirm my assumption by applying your workaround and testing it with ethtool --show-eee lanX.

# ethtool --show-eee lan1
EEE Settings for lan1:
        EEE status: disabled
        Tx LPI: 0 (us)
        Supported EEE link modes:  100baseT/Full 
                                   1000baseT/Full 
        Advertised EEE link modes:  Not reported
        Link partner advertised EEE link modes:  Not reported
# 
# ethtool --show-eee lan2
EEE Settings for lan2:
        EEE status: disabled
        Tx LPI: 0 (us)
        Supported EEE link modes:  100baseT/Full 
                                   1000baseT/Full 
        Advertised EEE link modes:  Not reported
        Link partner advertised EEE link modes:  Not reported
Quoted 2 lines

It should be commented in the code with all kind of warnings:
Don't move!!! We use one bug to workaround another bug!!!

As I've pointed out in the previous e-mail. This kind of bug cannot be easily fixed with modifying flags in ksz_get_phy_flags() as this function is called after ksz9477_get_features().

I'm open for ideas to do it right...

Quoted 3 lines

If PHYlib
start scanning PHYs before this code is executed, then thing may break!!

Is it possible that PHY lib will start scanning for phys before the DSA switch IC is probed with SPI?

KSZ9477-EVB DTS is not using "mdio" node - i.e. the "old" scheme for DSA switch is used.

Quoted 3 lines

... it is broken as hell....

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]

#19 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

In reply to Oleksij Rempel
Quoted 69 lines · Oleksij Rempel
Quoted 53 lines · Lukasz Majewski

The KSZ9477 errata points out (in 'Module 4') the link up/down problem when EEE (Energy Efficient Ethernet) is enabled in the device to which the KSZ9477 tries to auto negotiate.

The suggested workaround is to clear advertisement of EEE for PHYs in this chip driver.

---
 drivers/net/phy/micrel.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +29 -0
index 87b090ad2874..469dcd8a5711 100644
@@ -1418,6 +1418,35 @@ static int ksz9131_get_features(struct phy_device *phydev)
 	return 0;
 }
 
+static int ksz9477_get_features(struct phy_device *phydev)
+{
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(zero) = { 0, };
+	int ret;
+
+	ret = genphy_read_abilities(phydev);
+	if (ret)
+		return ret;
+
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature select must be
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not fully
+	 *   operational. It must be manually disabled through register
+	 *   controls. If not disabled, the PHY ports can auto-negotiate
+	 *   to enable EEE, and this feature can cause link drops when linked
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that EEE is
+	 *   operational one needs to manualy clear them to follow the chip
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported, zero);
+
+	return 0;
+}
+
 #define KSZ8873MLL_GLOBAL_CONTROL_4	0x06
 #define KSZ8873MLL_GLOBAL_CONTROL_4_DUPLEX	BIT(6)
 #define KSZ8873MLL_GLOBAL_CONTROL_4_SPEED	BIT(4)

drivers/net/phy/micrel.c static struct phy_driver ksphy_driver[] = { · line 4903

Quoted 5 lines
drivers/net/phy/micrel.c +1 -1
@@ -4871,7 +4900,7 @@ static struct phy_driver ksphy_driver[] = {
 	.handle_interrupt = kszphy_handle_interrupt,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-	.get_features	= ksz9131_get_features,
+	.get_features	= ksz9477_get_features,

Sorry, i didn't described all details how to implement it.

This code will break EEE support for the KSZ8563R switch.

Please search for MICREL_KSZ8_P1_ERRATA in the kernel source. Then add new flag, for example MICREL_NO_EEE and use it in a similar way how MICREL_KSZ8_P1_ERRATA was set and used. With this implementation, first patch is not needed.

Quoted 4 lines

The code will be something like this:

   if (dev_flags & MICREL_NO_EEE)
      /* lots of comments */
      linkmode_and(phydev->supported_eee, phydev->supported, zero);

I can't believe two people are writing code like this...

	linkmode_zero(phydev->supported_eee);

will work just as well.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#20 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

In reply to Lukasz Majewski
Quoted 6 lines · Lukasz Majewski
drivers/net/phy/micrel.c +6 -0
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature select must be
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not fully
+	 *   operational. It must be manually disabled through register

drivers/net/phy/micrel.c static int ksz9131_get_features(struct phy_device *phydev) · line 1445

Quoted 10 lines
drivers/net/phy/micrel.c +10 -0
+	 *   controls. If not disabled, the PHY ports can auto-negotiate
+	 *   to enable EEE, and this feature can cause link drops when linked
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that EEE is
+	 *   operational one needs to manualy clear them to follow the chip
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported, zero);

Hi,

I'm wondering whether you had a reason to write the above, rather than use the simpler:

	linkmode_zero(phydev->supported_eee);

Thanks.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#21 lore raw

Re: [PATCH 2/2] net: phy: Provide Module 4 KSZ9477 errata (DS80000754C)

Quoted 20 lines · Russell King (Oracle)
Quoted 6 lines · Lukasz Majewski
drivers/net/phy/micrel.c +6 -0
+	/* KSZ9477 Errata DS80000754C
+	 *
+	 * Module 4: Energy Efficient Ethernet (EEE) feature select must be
+	 * manually disabled
+	 *   The EEE feature is enabled by default, but it is not fully
+	 *   operational. It must be manually disabled through register

drivers/net/phy/micrel.c static int ksz9131_get_features(struct phy_device *phydev) · line 1445

Quoted 10 lines
drivers/net/phy/micrel.c +10 -0
+	 *   controls. If not disabled, the PHY ports can auto-negotiate
+	 *   to enable EEE, and this feature can cause link drops when linked
+	 *   to another device supporting EEE.
+	 *
+	 *   Although, the KSZ9477 MMD register
+	 *   (MMD_DEVICE_ID_EEE_ADV.MMD_EEE_ADV) advertise that EEE is
+	 *   operational one needs to manualy clear them to follow the chip
+	 *   errata.
+	 */
+	linkmode_and(phydev->supported_eee, phydev->supported, zero);

Hi,

Quoted 4 lines

I'm wondering whether you had a reason to write the above, rather than use the simpler:

	linkmode_zero(phydev->supported_eee);

Ah, I wondered what was the proper name for this and was not able to found it.

Thank you!

Regards,
Oleksij

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |