[PATCH v2] net: sh_eth: do not advertise Gigabit capabilities when not available

Subsystems: networking drivers, renesas superh ethernet driver, the rest

STALE3237d

4 messages, 3 authors, 2017-12-08 · open the first message on its own page

[PATCH v2] net: sh_eth: do not advertise Gigabit capabilities when not available

From: Thomas Petazzoni <hidden>
Date: 2017-12-05 09:30:07

Not all variants of the sh_eth hardware have Gigabit
support. Unfortunately, the current driver doesn't tell the PHY about
the limited MAC capabilities. Due to this, if you have a Gigabit
capable PHY, the PHY will advertise its Gigabit capability and
establish a link at 1Gbit/s, even though the MAC doesn't support it.

In order to avoid this, we use the recently introduced
phy_set_max_speed() to tell the PHY to not advertise speed higher than
100 MBit/s.

Tested on a SH7786 platform, with a Gigabit PHY.

Signed-off-by: Thomas Petazzoni <redacted>
---
Changes since v1:
 - Use phy_set_max_speed(), as suggested by Sergei Shtylyov
   [off-list ref].
---
 drivers/net/ethernet/renesas/sh_eth.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index db72d13cebb9..44ff2835c954 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -1860,6 +1860,7 @@ static int sh_eth_phy_init(struct net_device *ndev)
 	struct device_node *np = ndev->dev.parent->of_node;
 	struct sh_eth_private *mdp = netdev_priv(ndev);
 	struct phy_device *phydev;
+	int err;
 
 	mdp->link = 0;
 	mdp->speed = 0;
@@ -1892,9 +1893,22 @@ static int sh_eth_phy_init(struct net_device *ndev)
 		return PTR_ERR(phydev);
 	}
 
+	/* mask with MAC supported features */
+	if (mdp->cd->register_type != SH_ETH_REG_GIGABIT) {
+		err = phy_set_max_speed(phydev, SPEED_100);
+		if (err) {
+			netdev_err(ndev, "failed to limit PHY to 100 Mbit/s\n");
+			goto err_phy_disconnect;
+		}
+	}
+
 	phy_attached_info(phydev);
 
 	return 0;
+
+err_phy_disconnect:
+	phy_disconnect(phydev);
+	return err;
 }
 
 /* PHY control start function */
-- 
2.13.6

Re: [PATCH v2] net: sh_eth: do not advertise Gigabit capabilities when not available

From: Andrew Lunn <andrew@lunn.ch>
Date: 2017-12-05 17:55:22

On Tue, Dec 05, 2017 at 10:29:52AM +0100, Thomas Petazzoni wrote:
Not all variants of the sh_eth hardware have Gigabit
support. Unfortunately, the current driver doesn't tell the PHY about
the limited MAC capabilities. Due to this, if you have a Gigabit
capable PHY, the PHY will advertise its Gigabit capability and
establish a link at 1Gbit/s, even though the MAC doesn't support it.

In order to avoid this, we use the recently introduced
phy_set_max_speed() to tell the PHY to not advertise speed higher than
100 MBit/s.

Tested on a SH7786 platform, with a Gigabit PHY.

Signed-off-by: Thomas Petazzoni <redacted>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

Re: [PATCH v2] net: sh_eth: do not advertise Gigabit capabilities when not available

From: Sergei Shtylyov <hidden>
Date: 2017-12-05 19:02:24

Hello!

On 12/05/2017 12:29 PM, Thomas Petazzoni wrote:
quoted hunk
Not all variants of the sh_eth hardware have Gigabit
support. Unfortunately, the current driver doesn't tell the PHY about
the limited MAC capabilities. Due to this, if you have a Gigabit
capable PHY, the PHY will advertise its Gigabit capability and
establish a link at 1Gbit/s, even though the MAC doesn't support it.

In order to avoid this, we use the recently introduced
phy_set_max_speed() to tell the PHY to not advertise speed higher than
100 MBit/s.

Tested on a SH7786 platform, with a Gigabit PHY.

Signed-off-by: Thomas Petazzoni <redacted>
---
Changes since v1:
  - Use phy_set_max_speed(), as suggested by Sergei Shtylyov
    [off-list ref].
---
  drivers/net/ethernet/renesas/sh_eth.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index db72d13cebb9..44ff2835c954 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
[...]
quoted hunk
@@ -1892,9 +1893,22 @@ static int sh_eth_phy_init(struct net_device *ndev)
  		return PTR_ERR(phydev);
  	}
  
+	/* mask with MAC supported features */
+	if (mdp->cd->register_type != SH_ETH_REG_GIGABIT) {
+		err = phy_set_max_speed(phydev, SPEED_100);
+		if (err) {
+			netdev_err(ndev, "failed to limit PHY to 100 Mbit/s\n");
+			goto err_phy_disconnect;
   Er, why do we need a *goto* here at all? Just call phy_disconnect() here and be done with that...
quoted hunk
+		}
+	}
+
  	phy_attached_info(phydev);
  
  	return 0;
+
+err_phy_disconnect:
+	phy_disconnect(phydev);
+	return err;
  }
  
  /* PHY control start function */
MBR, Sergei

Re: [PATCH v2] net: sh_eth: do not advertise Gigabit capabilities when not available

From: Thomas Petazzoni <hidden>
Date: 2017-12-08 15:36:34

Hello,

On Tue, 5 Dec 2017 22:02:20 +0300, Sergei Shtylyov wrote:
quoted
+	/* mask with MAC supported features */
+	if (mdp->cd->register_type != SH_ETH_REG_GIGABIT) {
+		err = phy_set_max_speed(phydev, SPEED_100);
+		if (err) {
+			netdev_err(ndev, "failed to limit PHY to 100 Mbit/s\n");
+			goto err_phy_disconnect;  
    Er, why do we need a *goto* here at all? Just call phy_disconnect() here 
and be done with that...
Thanks for the feedback, I've sent a v3 that takes into account this
comment.

Thanks!

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help