Skip to contentSkip to conversation

net:phy:dp83867: add some fixes

PATCH Superseded Max Uvarov 2 participants 9 messages May 24, 2019

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Max Uvarov

author
#0 lore raw

cover net:phy:dp83867: add some fixes

Patch "fix speed 10 in sgmii mode" I already sent before and the was no mutch objections. Just resending it.

Patch "increase SGMII autoneg timer duration" fixes autoneg between mac and the phy.

And the latest "do not call config_init twice" is the logical code clean up.

BR,
Max.

Max Uvarov (3):
net:phy:dp83867: fix speed 10 in sgmii mode net:phy:dp83867: increase SGMII autoneg timer duration net:phy:dp83867: do not call config_init twice

 drivers/net/phy/dp83867.c | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH 2/3 net:phy:dp83867: increase SGMII autoneg timer duration

After reset SGMII Autoneg timer is set to 2us (bits 6 and 5 are 01). That us not enough to finalize autonegatiation on some devices. Increase this timer duration to maximum supported 16ms.

---
 drivers/net/phy/dp83867.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/phy/dp83867.c +13 -0
index afd31c516cc7..66b0a09ad094 100644
@@ -297,6 +297,19 @@ static int dp83867_config_init(struct phy_device *phydev)
 			WARN_ONCE(1, "dp83867: err DP83867_10M_SGMII_CFG\n");
 			return ret;
 		}
+
+		/* After reset SGMII Autoneg timer is set to 2us (bits 6 and 5
+		 * are 01). That us not enough to finalize autoneg on some
+		 * devices. Increase this timer duration to maximum 16ms.
+		 */
+		val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
+		val &= ~(BIT(5) | BIT(6));
+		ret = phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
+		if (ret) {
+			WARN_ONCE(1, "dp83867: error config sgmii auto-neg timer\n");
+			return ret;
+		}
+
 	}
 
 	/* Enable Interrupt output INT_OE in CFG3 register */
Signature · 1 line
2.17.1
author
#8 lore raw

PATCH 3/3 net:phy:dp83867: do not call config_init twice

In reply to Max Uvarov

Phy state machine calls _config_init just after
reset.

---
 drivers/net/phy/dp83867.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/phy/dp83867.c +1 -1
index 66b0a09ad094..2984fd5ae495 100644
@@ -342,7 +342,7 @@ static int dp83867_phy_reset(struct phy_device *phydev)
 
 	usleep_range(10, 20);
 
-	return dp83867_config_init(phydev);
+	return 0;
 }
 
 static struct phy_driver dp83867_driver[] = {
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/3 net:phy:dp83867: fix speed 10 in sgmii mode

In reply to Max Uvarov

For support 10Mps sped in SGMII mode DP83867_10M_SGMII_RATE_ADAPT bit of DP83867_10M_SGMII_CFG register has to be cleared by software. That does not affect speeds 100 and 1000 so can be done on init.

---
 drivers/net/phy/dp83867.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/net/phy/dp83867.c +22 -0
index fd35131a0c39..afd31c516cc7 100644
@@ -30,6 +30,7 @@
 #define DP83867_STRAP_STS1	0x006E
 #define DP83867_RGMIIDCTL	0x0086
 #define DP83867_IO_MUX_CFG	0x0170
+#define DP83867_10M_SGMII_CFG  0x016F
 
 #define DP83867_SW_RESET	BIT(15)
 #define DP83867_SW_RESTART	BIT(14)
@@ -74,6 +75,9 @@
 /* CFG4 bits */
 #define DP83867_CFG4_PORT_MIRROR_EN              BIT(0)
 
+/* 10M_SGMII_CFG bits */
+#define DP83867_10M_SGMII_RATE_ADAPT		 BIT(7)
+
 enum {
 	DP83867_PORT_MIRROING_KEEP,
 	DP83867_PORT_MIRROING_EN,
@@ -277,6 +281,24 @@ static int dp83867_config_init(struct phy_device *phydev)
 				       DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL);
 	}
 
+	if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+		/* For support SPEED_10 in SGMII mode
+		 * DP83867_10M_SGMII_RATE_ADAPT bit
+		 * has to be cleared by software. That
+		 * does not affect SPEED_100 and
+		 * SPEED_1000.
+		 */
+		val = phy_read_mmd(phydev, DP83867_DEVADDR,
+				   DP83867_10M_SGMII_CFG);
+		val &= ~DP83867_10M_SGMII_RATE_ADAPT;
+		ret = phy_write_mmd(phydev, DP83867_DEVADDR,
+				    DP83867_10M_SGMII_CFG, val);
+		if (ret) {
+			WARN_ONCE(1, "dp83867: err DP83867_10M_SGMII_CFG\n");
+			return ret;
+		}
+	}
+
 	/* Enable Interrupt output INT_OE in CFG3 register */
 	if (phy_interrupt_is_valid(phydev)) {
 		val = phy_read(phydev, DP83867_CFG3);
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 1/3] net:phy:dp83867: fix speed 10 in sgmii mode

Quoted 37 lines · Max Uvarov

For support 10Mps sped in SGMII mode DP83867_10M_SGMII_RATE_ADAPT bit of DP83867_10M_SGMII_CFG register has to be cleared by software. That does not affect speeds 100 and 1000 so can be done on init.

---
 drivers/net/phy/dp83867.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/net/phy/dp83867.c +6 -0
index fd35131a0c39..afd31c516cc7 100644
@@ -30,6 +30,7 @@
 #define DP83867_STRAP_STS1	0x006E
 #define DP83867_RGMIIDCTL	0x0086
 #define DP83867_IO_MUX_CFG	0x0170
+#define DP83867_10M_SGMII_CFG  0x016F
 
 #define DP83867_SW_RESET	BIT(15)
 #define DP83867_SW_RESTART	BIT(14)
@@ -74,6 +75,9 @@
 /* CFG4 bits */
 #define DP83867_CFG4_PORT_MIRROR_EN              BIT(0)
 
+/* 10M_SGMII_CFG bits */
+#define DP83867_10M_SGMII_RATE_ADAPT		 BIT(7)
+
 enum {
 	DP83867_PORT_MIRROING_KEEP,
 	DP83867_PORT_MIRROING_EN,
@@ -277,6 +281,24 @@ static int dp83867_config_init(struct phy_device *phydev)
 				       DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL);
 	}
 
+	if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+		/* For support SPEED_10 in SGMII mode

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 295

Quoted 10 lines
drivers/net/phy/dp83867.c +10 -0
+		 * DP83867_10M_SGMII_RATE_ADAPT bit
+		 * has to be cleared by software. That
+		 * does not affect SPEED_100 and
+		 * SPEED_1000.
+		 */
+		val = phy_read_mmd(phydev, DP83867_DEVADDR,
+				   DP83867_10M_SGMII_CFG);
+		val &= ~DP83867_10M_SGMII_RATE_ADAPT;
+		ret = phy_write_mmd(phydev, DP83867_DEVADDR,
+				    DP83867_10M_SGMII_CFG, val);

This could be simplified by using phy_modify_mmd().

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 297

Quoted 2 lines
drivers/net/phy/dp83867.c +2 -0
+		if (ret) {
+			WARN_ONCE(1, "dp83867: err DP83867_10M_SGMII_CFG\n");

This error message says more or less nothing. The context is visible in the stack trace, so you can remove the message w/o losing anything. As we're in the config_init callback, I don't think the "ONCE" version is needed. So you could simply use WARN_ON(1). Typically just the errno is returned w/o additional message, so you could also simply do:
return phy_modify_mmd(phydev, ...)

Quoted 8 lines
drivers/net/phy/dp83867.c +4 -0
+			return ret;
+		}
+	}
+
 	/* Enable Interrupt output INT_OE in CFG3 register */
 	if (phy_interrupt_is_valid(phydev)) {
 		val = phy_read(phydev, DP83867_CFG3);
maintainer
#5 lore raw

Re: [PATCH 2/3] net:phy:dp83867: increase SGMII autoneg timer duration

In reply to Max Uvarov
Quoted 14 lines · Max Uvarov

After reset SGMII Autoneg timer is set to 2us (bits 6 and 5 are 01). That us not enough to finalize autonegatiation on some devices. Increase this timer duration to maximum supported 16ms.

---
 drivers/net/phy/dp83867.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/net/phy/dp83867.c +0 -0
index afd31c516cc7..66b0a09ad094 100644

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 304

Quoted 8 lines
drivers/net/phy/dp83867.c +5 -0
@@ -297,6 +297,19 @@ static int dp83867_config_init(struct phy_device *phydev)
 			WARN_ONCE(1, "dp83867: err DP83867_10M_SGMII_CFG\n");
 			return ret;
 		}
+
+		/* After reset SGMII Autoneg timer is set to 2us (bits 6 and 5
+		 * are 01). That us not enough to finalize autoneg on some
+		 * devices. Increase this timer duration to maximum 16ms.
+		 */

In the public datasheet the bits are described as reserved. However, based on the value, I suppose it's not a timer value but the timer resolution.

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 310

Quoted 6 lines
drivers/net/phy/dp83867.c +6 -0
+		val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
+		val &= ~(BIT(5) | BIT(6));
+		ret = phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
+		if (ret) {
+			WARN_ONCE(1, "dp83867: error config sgmii auto-neg timer\n");
+			return ret;

Same comment as for patch 1.

Quoted 6 lines
drivers/net/phy/dp83867.c +2 -0
+		}
+
 	}
 
 	/* Enable Interrupt output INT_OE in CFG3 register */
#3 lore raw

Re: [PATCH 1/3] net:phy:dp83867: fix speed 10 in sgmii mode

In reply to Heiner Kallweit

пт, 24 мая 2019 г. в 20:24, Heiner Kallweit <[email protected]>:

Quoted 55 lines · Max Uvarov
Quoted 37 lines

For support 10Mps sped in SGMII mode DP83867_10M_SGMII_RATE_ADAPT bit of DP83867_10M_SGMII_CFG register has to be cleared by software. That does not affect speeds 100 and 1000 so can be done on init.

---
 drivers/net/phy/dp83867.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/net/phy/dp83867.c +6 -0
index fd35131a0c39..afd31c516cc7 100644
@@ -30,6 +30,7 @@
 #define DP83867_STRAP_STS1   0x006E
 #define DP83867_RGMIIDCTL    0x0086
 #define DP83867_IO_MUX_CFG   0x0170
+#define DP83867_10M_SGMII_CFG  0x016F
 
 #define DP83867_SW_RESET     BIT(15)
 #define DP83867_SW_RESTART   BIT(14)
@@ -74,6 +75,9 @@
 /* CFG4 bits */
 #define DP83867_CFG4_PORT_MIRROR_EN              BIT(0)
 
+/* 10M_SGMII_CFG bits */
+#define DP83867_10M_SGMII_RATE_ADAPT          BIT(7)
+
 enum {
      DP83867_PORT_MIRROING_KEEP,
      DP83867_PORT_MIRROING_EN,
@@ -277,6 +281,24 @@ static int dp83867_config_init(struct phy_device *phydev)
                                     DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL);
      }
 
+     if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
+             /* For support SPEED_10 in SGMII mode

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 295

Quoted 10 lines
drivers/net/phy/dp83867.c +10 -0
+              * DP83867_10M_SGMII_RATE_ADAPT bit
+              * has to be cleared by software. That
+              * does not affect SPEED_100 and
+              * SPEED_1000.
+              */
+             val = phy_read_mmd(phydev, DP83867_DEVADDR,
+                                DP83867_10M_SGMII_CFG);
+             val &= ~DP83867_10M_SGMII_RATE_ADAPT;
+             ret = phy_write_mmd(phydev, DP83867_DEVADDR,
+                                 DP83867_10M_SGMII_CFG, val);

This could be simplified by using phy_modify_mmd().

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 297

Quoted 2 lines
drivers/net/phy/dp83867.c +2 -0
+             if (ret) {
+                     WARN_ONCE(1, "dp83867: err DP83867_10M_SGMII_CFG\n");
Quoted 6 lines

This error message says more or less nothing. The context is visible in the stack trace, so you can remove the message w/o losing anything. As we're in the config_init callback, I don't think the "ONCE" version is needed. So you could simply use WARN_ON(1). Typically just the errno is returned w/o additional message, so you could also simply do:
return phy_modify_mmd(phydev, ...)

The error shoud indicate that something is wrong with mdio bus. I.e. write returned error. And it's more likely hardware bug which needs to be fixed. Once I used to not print this error on each ifconfig up/down.

Max.

Quoted 10 lines
Quoted 9 lines
drivers/net/phy/dp83867.c +4 -0
+                     return ret;
+             }
+     }
+
      /* Enable Interrupt output INT_OE in CFG3 register */
      if (phy_interrupt_is_valid(phydev)) {
              val = phy_read(phydev, DP83867_CFG3);
Signature · 2 lines
Best regards,
Maxim Uvarov
#6 lore raw

Re: [PATCH 2/3] net:phy:dp83867: increase SGMII autoneg timer duration

In reply to Heiner Kallweit

пт, 24 мая 2019 г. в 20:24, Heiner Kallweit <[email protected]>:

Quoted 11 lines · Max Uvarov
Quoted 9 lines

After reset SGMII Autoneg timer is set to 2us (bits 6 and 5 are 01). That us not enough to finalize autonegatiation on some devices. Increase this timer duration to maximum supported 16ms.

---
 drivers/net/phy/dp83867.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Quoted 15 lines

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 304

Quoted 13 lines
drivers/net/phy/dp83867.c +5 -0
index afd31c516cc7..66b0a09ad094 100644
@@ -297,6 +297,19 @@ static int dp83867_config_init(struct phy_device *phydev)
                      WARN_ONCE(1, "dp83867: err DP83867_10M_SGMII_CFG\n");
                      return ret;
              }
+
+             /* After reset SGMII Autoneg timer is set to 2us (bits 6 and 5
+              * are 01). That us not enough to finalize autoneg on some
+              * devices. Increase this timer duration to maximum 16ms.
+              */

In the public datasheet the bits are described as reserved. However, based on the value, I suppose it's not a timer value but the timer resolution.

No, it's public:
http://www.ti.com/lit/ds/symlink/dp83867e.pdf page 72.

SGMII Auto-Negotiation Timer Duration.

Quoted 9 lines

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 310

Quoted 7 lines
drivers/net/phy/dp83867.c +6 -0
+             val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
+             val &= ~(BIT(5) | BIT(6));
+             ret = phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
+             if (ret) {
+                     WARN_ONCE(1, "dp83867: error config sgmii auto-neg timer\n");
+                     return ret;

Same comment as for patch 1.

Yes, the same answer. I want to capture hardware error then silently return error and then debug it.
WARN is more informative then some random "phy not detected" things.

Max.

Quoted 8 lines
Quoted 7 lines
drivers/net/phy/dp83867.c +2 -0
+             }
+
      }
 
      /* Enable Interrupt output INT_OE in CFG3 register */
maintainer
#7 lore raw

Re: [PATCH 2/3] net:phy:dp83867: increase SGMII autoneg timer duration

Quoted 28 lines · Maxim Uvarov

пт, 24 мая 2019 г. в 20:24, Heiner Kallweit <[email protected]>:

Quoted 11 lines · Max Uvarov
Quoted 9 lines

After reset SGMII Autoneg timer is set to 2us (bits 6 and 5 are 01). That us not enough to finalize autonegatiation on some devices. Increase this timer duration to maximum supported 16ms.

---
 drivers/net/phy/dp83867.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
Quoted 15 lines

drivers/net/phy/dp83867.c static int dp83867_config_init(struct phy_device *phydev) · line 304

Quoted 13 lines
drivers/net/phy/dp83867.c +5 -0
index afd31c516cc7..66b0a09ad094 100644
@@ -297,6 +297,19 @@ static int dp83867_config_init(struct phy_device *phydev)
                      WARN_ONCE(1, "dp83867: err DP83867_10M_SGMII_CFG\n");
                      return ret;
              }
+
+             /* After reset SGMII Autoneg timer is set to 2us (bits 6 and 5
+              * are 01). That us not enough to finalize autoneg on some
+              * devices. Increase this timer duration to maximum 16ms.
+              */

In the public datasheet the bits are described as reserved. However, based on the value, I suppose it's not a timer value but the timer resolution.

Quoted 3 lines

No, it's public:
http://www.ti.com/lit/ds/symlink/dp83867e.pdf page 72.

I just searched for Dp83867 and found this one:
http://www.ti.com/lit/ds/symlink/dp83867cr.pdf
This PHY seems to have the same ID, but the timer bits are at least not documented.

Quoted 2 lines

SGMII Auto-Negotiation Timer Duration.

I see, we talk about SGMII aneg, not PHY aneg. My bad.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/net/phy/dp83867.c +6 -0
+             val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
+             val &= ~(BIT(5) | BIT(6));
+             ret = phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
+             if (ret) {
+                     WARN_ONCE(1, "dp83867: error config sgmii auto-neg timer\n");
+                     return ret;
Quoted 4 lines
Quoted 1 line

Same comment as for patch 1.

Yes, the same answer. I want to capture hardware error then silently return error and then debug it.

If you have hardware with buggy MDIO support, then the problem could occur in any MDIO access. I think then the WARN should be in the MDIO bus ops.

Quoted 13 lines

WARN is more informative then some random "phy not detected" things.

Max.

Quoted 8 lines
Quoted 7 lines
drivers/net/phy/dp83867.c +2 -0
+             }
+
      }
 
      /* Enable Interrupt output INT_OE in CFG3 register */