Skip to contentSkip to conversation

net: phy: initialise phydev speed and duplex sanely

PATCH Applied Russell King 3 participants 3 messages Nov 22, 2019 – Nov 23, 2019

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

PATCH 1/1 net: phy: initialise phydev speed and duplex sanely

When a phydev is created, the speed and duplex are set to zero and -1 respectively, rather than using the predefined SPEED_UNKNOWN and DUPLEX_UNKNOWN constants.

There is a window at initialisation time where we may report link down using the 0/-1 values. Tidy this up and use the predefined constants, so debug doesn't complain with:

"Unsupported (update phy-core.c)/Unsupported (update phy-core.c)"

when the speed and duplex settings are printed.

---
 drivers/net/phy/phy_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy_device.c +2 -2
index 232ad33b1159..8186aad4ef90 100644
@@ -597,8 +597,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
 	mdiodev->device_free = phy_mdio_device_free;
 	mdiodev->device_remove = phy_mdio_device_remove;
 
-	dev->speed = 0;
-	dev->duplex = -1;
+	dev->speed = SPEED_UNKNOWN;
+	dev->duplex = DUPLEX_UNKNOWN;
 	dev->pause = 0;
 	dev->asym_pause = 0;
 	dev->link = 0;
Signature · 1 line
2.20.1
#1 lore raw

Unfortunately, Andrew dropped the 'g' from the netdev email address, and Zach's email address doesn't seem to work.

Forwarding this to netdev (with appropriate threading) for archival purposes.

----- Forwarded message from Russell King - ARM Linux admin <[email protected]> -----

Date: Fri, 22 Nov 2019 16:03:23 +0000
From: Russell King - ARM Linux admin <[email protected]>
To: Andrew Lunn <[email protected]>
Cc: [email protected], Florian Fainelli <[email protected]>, Heiner Kallweit
<[email protected]>, "David S. Miller" <[email protected]>, [email protected]
Subject: Re: [PATCH net-next] net: phy: initialise phydev speed and duplex
sanely

Quoted 48 lines · Russell King - ARM Linux admin
Quoted 36 lines · Andrew Lunn
Quoted 22 lines · Russell King

When a phydev is created, the speed and duplex are set to zero and -1 respectively, rather than using the predefined SPEED_UNKNOWN and DUPLEX_UNKNOWN constants.

There is a window at initialisation time where we may report link down using the 0/-1 values. Tidy this up and use the predefined constants, so debug doesn't complain with:

"Unsupported (update phy-core.c)/Unsupported (update phy-core.c)"

when the speed and duplex settings are printed.

---
 drivers/net/phy/phy_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/phy/phy_device.c +0 -0
index 232ad33b1159..8186aad4ef90 100644

drivers/net/phy/phy_device.c struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id, · line 604

Quoted 10 lines
drivers/net/phy/phy_device.c +2 -2
@@ -597,8 +597,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
 	mdiodev->device_free = phy_mdio_device_free;
 	mdiodev->device_remove = phy_mdio_device_remove;
 
-	dev->speed = 0;
-	dev->duplex = -1;
+	dev->speed = SPEED_UNKNOWN;
+	dev->duplex = DUPLEX_UNKNOWN;
 	dev->pause = 0;
 	dev->asym_pause = 0;
 	dev->link = 0;

Hi Russell, Zach

Quoted 4 lines

Does phy_led_trigger_change_speed() need to change? It has

        if (phy->speed == 0)
                return;

I'm not sure what that's trying to achieve.

From what I can see, phy_speed_to_led_trigger() looks up the speed in the table of triggers, which is populated from the PHYs supported speeds, which will never contain zero or SPEED_UNKNOWN.

Quoted 7 lines

Note that genphy will return SPEED_UNKNOWN if autoneg_complete is false (see genphy_read_status()). However, in that case, ->link will be false, just like it is at initialisation time, and hence we won't reach that statement (we'll go off to phy_led_trigger_no_link()).

So I think the test is entirely unnecessary.

... unless there's a buggy phylib driver, in which case we shouldn't be working around it in this code (as it would affect network drivers as well) but should be fixing the broken phylib driver.

Signature · 10 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

----- End forwarded message -----

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#2 lore raw
In reply to Russell King
Quoted 8 lines · Russell King

When a phydev is created, the speed and duplex are set to zero and -1 respectively, rather than using the predefined SPEED_UNKNOWN and DUPLEX_UNKNOWN constants.

There is a window at initialisation time where we may report link down using the 0/-1 values. Tidy this up and use the predefined constants, so debug doesn't complain with:

Quoted 5 lines

"Unsupported (update phy-core.c)/Unsupported (update phy-core.c)"

when the speed and duplex settings are printed.

Applied, thank you!