Skip to contentSkip to conversation

net: phy: dp83867: add some fixes

PATCH Superseded Max Uvarov 3 participants 11 messages May 27, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Max Uvarov

author
#0 lore raw

v2 cover net: phy: dp83867: add some fixes

v2: fix minor comments by Heiner Kallweit and Florian Fainelli.

Max Uvarov (4):
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
net: phy: dp83867: Set up RGMII TX delay

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

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

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.

Cc Heiner Kallweit <[email protected]>
---
 drivers/net/phy/dp83867.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/phy/dp83867.c +20 -0
index fd35131a0c39..75861b8f3b4d 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,22 @@ 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)
+			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 v2 1/4] net: phy: dp83867: fix speed 10 in sgmii mode

Quoted 38 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.

Cc Heiner Kallweit <[email protected]>
---
 drivers/net/phy/dp83867.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/phy/dp83867.c +6 -0
index fd35131a0c39..75861b8f3b4d 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,22 @@ 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);

I think I mentioned it before: This can be simplified by using phy_modify_mmd(). Same applies to patch 2.

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

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

In reply to Max Uvarov
Quoted 3 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.

s/support/supporting/
s/sped/speed/

Quoted 30 lines
Cc Heiner Kallweit <[email protected]>
---
 drivers/net/phy/dp83867.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
drivers/net/phy/dp83867.c +4 -0
index fd35131a0c39..75861b8f3b4d 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,

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

Quoted 9 lines
drivers/net/phy/dp83867.c +6 -0
@@ -277,6 +281,22 @@ 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.

Likewise, s/support/supporting/ with that and Heiner's suggestion to use phy_modify_mmd():

Quoted 14 lines
drivers/net/phy/dp83867.c +10 -0
+		 */
+		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)
+			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
Florian
author
#4 lore raw

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

In reply to 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.

Cc Heiner Kallweit <[email protected]>
---
 drivers/net/phy/dp83867.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/phy/dp83867.c +10 -0
index 75861b8f3b4d..5fafcc091525 100644
@@ -295,6 +295,16 @@ static int dp83867_config_init(struct phy_device *phydev)
 				    DP83867_10M_SGMII_CFG, val);
 		if (ret)
 			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)
+			return ret;
 	}
 
 	/* Enable Interrupt output INT_OE in CFG3 register */
Signature · 1 line
2.17.1
maintainer
#5 lore raw

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

Quoted 15 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.

Cc Heiner Kallweit <[email protected]>
---
 drivers/net/phy/dp83867.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/phy/dp83867.c +0 -0
index 75861b8f3b4d..5fafcc091525 100644

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

Quoted 10 lines
drivers/net/phy/dp83867.c +7 -0
@@ -295,6 +295,16 @@ static int dp83867_config_init(struct phy_device *phydev)
 				    DP83867_10M_SGMII_CFG, val);
 		if (ret)
 			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));

Using bit numbers directly isn't nice. Better define a mask and constants for the different combinations of bit 5 and 6 like:
#define FOO_SGMII_ANEG_TIMER_MASK 0x60
#define FOO_SGMII_ANEG_TIMER_2US 0x20
#define FOO_SGMII_ANEG_TIMER_16MS 0x60
And then use the constants in phy_modify_mmd().

Quoted 7 lines
drivers/net/phy/dp83867.c +3 -0
+		ret = phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
+		if (ret)
+			return ret;
 	}
 
 	/* Enable Interrupt output INT_OE in CFG3 register */
Reviewed-by on v2 2/4
#6 lore raw

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

In reply to Max Uvarov
Quoted 2 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.

s/us/is/

Quoted 16 lines

Increase this timer duration to maximum supported 16ms.

Cc Heiner Kallweit <[email protected]>
---
 drivers/net/phy/dp83867.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/net/phy/dp83867.c +0 -0
index 75861b8f3b4d..5fafcc091525 100644

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

Quoted 6 lines
drivers/net/phy/dp83867.c +3 -0
@@ -295,6 +295,16 @@ static int dp83867_config_init(struct phy_device *phydev)
 				    DP83867_10M_SGMII_CFG, val);
 		if (ret)
 			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

Likewise, same typo was carried over here. With that fixed and Heiner's suggestions addressed:

Signature · 1 line
Florian
author
#7 lore raw

PATCH v2 3/4 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 5fafcc091525..a1c0b2128de2 100644
@@ -337,7 +337,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
#9 lore raw

PATCH v2 4/4 net: phy: dp83867: Set up RGMII TX delay

In reply to Max Uvarov

PHY_INTERFACE_MODE_RGMII_RXID is less then TXID so code to set tx delay is never called.

Fixes 2a10154abcb75 ("net: phy: dp83867: Add TI dp83867 phy")
Cc Florian Fainelli <[email protected]>
---
 drivers/net/phy/dp83867.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/phy/dp83867.c +1 -3
index a1c0b2128de2..69e36d3d0968 100644
@@ -251,10 +251,8 @@ static int dp83867_config_init(struct phy_device *phydev)
 		ret = phy_write(phydev, MII_DP83867_PHYCTRL, val);
 		if (ret)
 			return ret;
-	}
 
-	if ((phydev->interface >= PHY_INTERFACE_MODE_RGMII_ID) &&
-	    (phydev->interface <= PHY_INTERFACE_MODE_RGMII_RXID)) {
+		/* Set up RGMII delays */
 		val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL);
 
 		if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
Signature · 1 line
2.17.1