Skip to contentSkip to conversation

net: phy: improve link partner capability detection

PATCH Applied Heiner Kallweit 4 participants 19 messages Apr 5, 2019 – Apr 8, 2019

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH 1/1 net: phy: improve link partner capability detection

genphy_read_status() so far checks phydev->supported, not the actual PHY capabilities. This can make a difference if the supported speeds have been limited by of_set_phy_supported() or phy_set_max_speed().

It seems that this issue only affects the link partner advertisements as displayed by ethtool. Also this patch wouldn't apply to older kernels because linkmode bitmaps have been introduced recently. Therefore net-next.

---
 drivers/net/phy/phy_device.c | 12 ++++++++----
 include/linux/phy.h          |  2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
drivers/net/phy/phy_device.c +8 -4
index f7a6d0ffb..dab3ecbb4 100644
@@ -1756,10 +1756,7 @@ int genphy_read_status(struct phy_device *phydev)
 	linkmode_zero(phydev->lp_advertising);
 
 	if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
-		if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
-				      phydev->supported) ||
-		    linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
-				      phydev->supported)) {
+		if (phydev->is_gigabit_capable) {
 			lpagb = phy_read(phydev, MII_STAT1000);
 			if (lpagb < 0)
 				return lpagb;
@@ -2154,6 +2151,13 @@ static int phy_probe(struct device *dev)
 	if (err)
 		goto out;
 
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+
 	of_set_phy_supported(phydev);
 	linkmode_copy(phydev->advertising, phydev->supported);
 
include/linux/phy.h +2 -0
index ab7439b3d..0f9552b17 100644
@@ -345,6 +345,7 @@ struct phy_c45_device_ids {
  * is_c45:  Set to true if this phy uses clause 45 addressing.
  * is_internal: Set to true if this phy is internal to a MAC.
  * is_pseudo_fixed_link: Set to true if this phy is an Ethernet switch, etc.
+ * is_gigabit_capable: Set to true if PHY supports 1000Mbps
  * has_fixups: Set to true if this phy has fixups/quirks.
  * suspended: Set to true if this phy has been suspended successfully.
  * sysfs_links: Internal boolean tracking sysfs symbolic links setup/removal.
@@ -382,6 +383,7 @@ struct phy_device {
 	unsigned is_c45:1;
 	unsigned is_internal:1;
 	unsigned is_pseudo_fixed_link:1;
+	unsigned is_gigabit_capable:1;
 	unsigned has_fixups:1;
 	unsigned suspended:1;
 	unsigned sysfs_links:1;
Signature · 1 line
2.21.0
maintainer
#1 lore raw
Quoted 8 lines · Heiner Kallweit

genphy_read_status() so far checks phydev->supported, not the actual PHY capabilities. This can make a difference if the supported speeds have been limited by of_set_phy_supported() or phy_set_max_speed().

It seems that this issue only affects the link partner advertisements as displayed by ethtool. Also this patch wouldn't apply to older kernels because linkmode bitmaps have been introduced recently. Therefore net-next.

Hi Heiner

Are you saying, if the local PHY/MAC does not support 1000Base-T, we should not check if the peer is advertising 1000Base-T? That seems wrong. We should report everything it offers. The fact we cannot make use of 1000Base-T should not matter, and resolving of the auto-get should do the right thing when presented with modes it cannot use.

What do we do in the c45 case? The peer can do 2.5G, 5G and 10G, but the local can only do 2.5G? Do we just report the peers 2.5G and skip the others? Or do we report them all?

Andrew

author maintainer
#2 lore raw
Quoted 5 lines · Andrew Lunn
Quoted 4 lines · Heiner Kallweit

genphy_read_status() so far checks phydev->supported, not the actual PHY capabilities. This can make a difference if the supported speeds have been limited by of_set_phy_supported() or phy_set_max_speed().

Quoted 7 lines
Quoted 4 lines

It seems that this issue only affects the link partner advertisements as displayed by ethtool. Also this patch wouldn't apply to older kernels because linkmode bitmaps have been introduced recently. Therefore net-next.

Hi Heiner

Hi Andrew,

Quoted 6 lines

Are you saying, if the local PHY/MAC does not support 1000Base-T, we should not check if the peer is advertising 1000Base-T? That seems wrong. We should report everything it offers. The fact we cannot make use of 1000Base-T should not matter, and resolving of the auto-get should do the right thing when presented with modes it cannot use.

Link partner gigabit advertisement is reported in register MII_STAT1000. If we have a 100MBit PHY w/o this register, then we will never know whether the link partner supports gigabit.
I would have to check the 802.3 specs, but it could even be that the gigabit autoneg is a separate step in the autoneg process. If this separate step isn't supported by a 100MBit PHY, then this PHY per se has no chance to detect whether link partner is gigabit-capable.

Quoted 4 lines

What do we do in the c45 case? The peer can do 2.5G, 5G and 10G, but the local can only do 2.5G? Do we just report the peers 2.5G and skip the others? Or do we report them all?

We report everything the chip reports. But similar to what I wrote about C22 and gigabit, what the chip reports may depend on which autoneg steps it does. Again I would have to check the standard whether e.g. NBase-T (2.5Gbps, 5Gbps) uses a separate autoneg step. If we don't advertise at least of these modes, then the PHY may decide to skip this autoneg step, and in the end we won't know whether link partner supports 2.5Gbps/5Gbps.

Quoted 2 lines

Andrew

Heiner

maintainer
#3 lore raw
Quoted 21 lines · Heiner Kallweit
Quoted 5 lines · Andrew Lunn
Quoted 4 lines · Heiner Kallweit

genphy_read_status() so far checks phydev->supported, not the actual PHY capabilities. This can make a difference if the supported speeds have been limited by of_set_phy_supported() or phy_set_max_speed().

Quoted 7 lines
Quoted 4 lines

It seems that this issue only affects the link partner advertisements as displayed by ethtool. Also this patch wouldn't apply to older kernels because linkmode bitmaps have been introduced recently. Therefore net-next.

Hi Heiner

Hi Andrew,

Quoted 6 lines

Are you saying, if the local PHY/MAC does not support 1000Base-T, we should not check if the peer is advertising 1000Base-T? That seems wrong. We should report everything it offers. The fact we cannot make use of 1000Base-T should not matter, and resolving of the auto-get should do the right thing when presented with modes it cannot use.

Quoted 3 lines

Link partner gigabit advertisement is reported in register MII_STAT1000. If we have a 100MBit PHY w/o this register, then we will never know whether the link partner supports gigabit.

Hi Heiner

There seems to be two uses cases:

A Fast MAC connected to a Fast PHY. In that case, MII_STAT1000 probably does not exist, so we should not read it. Hopefully .features says BASIC, or if we ask the PHY what is it, it reports it is a Fast PHY.

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

Andrew

author maintainer
#4 lore raw
Quoted 26 lines · Andrew Lunn
Quoted 21 lines · Heiner Kallweit
Quoted 5 lines · Andrew Lunn
Quoted 4 lines · Heiner Kallweit

genphy_read_status() so far checks phydev->supported, not the actual PHY capabilities. This can make a difference if the supported speeds have been limited by of_set_phy_supported() or phy_set_max_speed().

Quoted 7 lines
Quoted 4 lines

It seems that this issue only affects the link partner advertisements as displayed by ethtool. Also this patch wouldn't apply to older kernels because linkmode bitmaps have been introduced recently. Therefore net-next.

Hi Heiner

Hi Andrew,

Quoted 6 lines

Are you saying, if the local PHY/MAC does not support 1000Base-T, we should not check if the peer is advertising 1000Base-T? That seems wrong. We should report everything it offers. The fact we cannot make use of 1000Base-T should not matter, and resolving of the auto-get should do the right thing when presented with modes it cannot use.

Quoted 3 lines

Link partner gigabit advertisement is reported in register MII_STAT1000. If we have a 100MBit PHY w/o this register, then we will never know whether the link partner supports gigabit.

Quoted 9 lines

Hi Heiner

There seems to be two uses cases:

A Fast MAC connected to a Fast PHY. In that case, MII_STAT1000 probably does not exist, so we should not read it. Hopefully .features says BASIC, or if we ask the PHY what is it, it reports it is a Fast PHY.

Right. BMSR_ESTATEN should not be set on a Fast PHY. Handling of this case didn't change.

Quoted 4 lines

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

That's what we're doing now with this patch.

Quoted 2 lines

Andrew

Heiner

maintainer
#5 lore raw
Quoted 8 lines

Right. BMSR_ESTATEN should not be set on a Fast PHY. Handling of this case didn't change.

Quoted 4 lines

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

That's what we're doing now with this patch.

Hi Heiner

What i don't get is why we need to do anything based on the MAC. All we need to do is look at BMSR_ESTATEN, and from that decided if we should look at MII_STAT1000 or not. When reporting what the peer can do, we should not care what the local MAC can do.

Andrew

author maintainer
#6 lore raw
Quoted 7 lines · Andrew Lunn
Quoted 7 lines

Right. BMSR_ESTATEN should not be set on a Fast PHY. Handling of this case didn't change.

Quoted 4 lines

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

Quoted 9 lines
Quoted 1 line

That's what we're doing now with this patch.

Hi Heiner

What i don't get is why we need to do anything based on the MAC. All we need to do is look at BMSR_ESTATEN, and from that decided if we should look at MII_STAT1000 or not. When reporting what the peer can do, we should not care what the local MAC can do.

Do we have a misunderstanding? What you describe is exactly what we're doing now. BMSR_ESTATEN is read by genphy_read_abilities(). I just don't want to read BMSR whenever genphy_read_status() is called.

Quoted 2 lines

Andrew

Heiner

#7 lore raw
Quoted 12 lines · Heiner Kallweit
Quoted 11 lines · Andrew Lunn
Quoted 8 lines

Right. BMSR_ESTATEN should not be set on a Fast PHY. Handling of this case didn't change.

Quoted 4 lines

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

That's what we're doing now with this patch.

Hi Heiner

Quoted 8 lines
Quoted 5 lines

What i don't get is why we need to do anything based on the MAC. All we need to do is look at BMSR_ESTATEN, and from that decided if we should look at MII_STAT1000 or not. When reporting what the peer can do, we should not care what the local MAC can do.

Do we have a misunderstanding? What you describe is exactly what we're doing now. BMSR_ESTATEN is read by genphy_read_abilities(). I just don't want to read BMSR whenever genphy_read_status() is called.

You have to read the BMSR to determine the link status anyway, did you
mean: have to check BMSR_ESTATEN whenever genphy_read_status() is called?

Signature · 1 line
Florian
author maintainer
#8 lore raw
Quoted 18 lines · Florian Fainelli
Quoted 17 lines · Heiner Kallweit
Quoted 16 lines · Andrew Lunn
Quoted 8 lines

Right. BMSR_ESTATEN should not be set on a Fast PHY. Handling of this case didn't change.

Quoted 4 lines

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

That's what we're doing now with this patch.

Hi Heiner

What i don't get is why we need to do anything based on the MAC. All we need to do is look at BMSR_ESTATEN, and from that decided if we should look at MII_STAT1000 or not. When reporting what the peer can do, we should not care what the local MAC can do.

Quoted 7 lines
Quoted 3 lines

Do we have a misunderstanding? What you describe is exactly what we're doing now. BMSR_ESTATEN is read by genphy_read_abilities(). I just don't want to read BMSR whenever genphy_read_status() is called.

You have to read the BMSR to determine the link status anyway, did you
mean: have to check BMSR_ESTATEN whenever genphy_read_status() is called?

I would have to add extra logic to propagate BMSR_ESTATEN from genphy_update_link() to genphy_read_status(). BMSR_ESTATEN has a fixed value and therefore it's sufficient to read it initially.

author maintainer
#9 lore raw
Quoted 23 lines · Heiner Kallweit
Quoted 22 lines · Florian Fainelli
Quoted 20 lines · Heiner Kallweit
Quoted 7 lines · Andrew Lunn
Quoted 7 lines

Right. BMSR_ESTATEN should not be set on a Fast PHY. Handling of this case didn't change.

Quoted 4 lines

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

Quoted 9 lines
Quoted 1 line

That's what we're doing now with this patch.

Hi Heiner

What i don't get is why we need to do anything based on the MAC. All we need to do is look at BMSR_ESTATEN, and from that decided if we should look at MII_STAT1000 or not. When reporting what the peer can do, we should not care what the local MAC can do.

Do we have a misunderstanding? What you describe is exactly what we're doing now. BMSR_ESTATEN is read by genphy_read_abilities(). I just don't want to read BMSR whenever genphy_read_status() is called.

Quoted 7 lines
Quoted 3 lines

You have to read the BMSR to determine the link status anyway, did you
mean: have to check BMSR_ESTATEN whenever genphy_read_status() is called?

I would have to add extra logic to propagate BMSR_ESTATEN from genphy_update_link() to genphy_read_status(). BMSR_ESTATEN has a fixed value and therefore it's sufficient to read it initially.

In addition: BMSR_ESTATEN being set isn't a guarantee yet that the PHY supports gigabit. Still in MII_ESTATUS the gigabit bits couldn't be set. A Fast PHY could use some IP which is gigabit-prepared.
I don't know if such a PHY exists, but it would be totally compliant with C22.

#10 lore raw
Quoted 31 lines · Heiner Kallweit
Quoted 23 lines · Heiner Kallweit
Quoted 22 lines · Florian Fainelli
Quoted 20 lines · Heiner Kallweit
Quoted 7 lines · Andrew Lunn
Quoted 7 lines

Right. BMSR_ESTATEN should not be set on a Fast PHY. Handling of this case didn't change.

Quoted 4 lines

A Fast MAC connected to a Giga PHY. The MAC driver will of used phy_set_max_speed() to indicate its limits. In that case, MII_STAT1000 does exist and we should report what the peer is advertising.

Quoted 9 lines
Quoted 1 line

That's what we're doing now with this patch.

Hi Heiner

What i don't get is why we need to do anything based on the MAC. All we need to do is look at BMSR_ESTATEN, and from that decided if we should look at MII_STAT1000 or not. When reporting what the peer can do, we should not care what the local MAC can do.

Do we have a misunderstanding? What you describe is exactly what we're doing now. BMSR_ESTATEN is read by genphy_read_abilities(). I just don't want to read BMSR whenever genphy_read_status() is called.

Quoted 7 lines
Quoted 3 lines

You have to read the BMSR to determine the link status anyway, did you
mean: have to check BMSR_ESTATEN whenever genphy_read_status() is called?

I would have to add extra logic to propagate BMSR_ESTATEN from genphy_update_link() to genphy_read_status(). BMSR_ESTATEN has a fixed value and therefore it's sufficient to read it initially.

Quoted 6 lines

In addition: BMSR_ESTATEN being set isn't a guarantee yet that the PHY supports gigabit. Still in MII_ESTATUS the gigabit bits couldn't be set. A Fast PHY could use some IP which is gigabit-prepared.
I don't know if such a PHY exists, but it would be totally compliant with C22.

There are Gigabit PHYs that are being limited in software to 10/100 because the Ethernet MAC is not capable, yet it's easier/cheaper to populate a gigabit capable PHY (Simmon's use case is one of them I believe, but I have come across that too).

Signature · 1 line
Florian
maintainer
#11 lore raw
In reply to Heiner Kallweit

drivers/net/phy/phy_device.c static int phy_probe(struct device *dev) · line 2160

Quoted 7 lines
drivers/net/phy/phy_device.c +7 -0
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+

What i'm trying to get at is, why do we need this bit of the patch? Why do we need this flag? The hardware should tell us if it can do gigabit.

Andrew

author maintainer
#12 lore raw
Quoted 12 lines · Andrew Lunn

drivers/net/phy/phy_device.c static int phy_probe(struct device *dev) · line 2160

Quoted 7 lines
drivers/net/phy/phy_device.c +7 -0
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+

What i'm trying to get at is, why do we need this bit of the patch? Why do we need this flag? The hardware should tell us if it can do gigabit.

The code to query BMSR_ESTATEN and MII_ESTATUS is in genphy_read_status. However we also have to cover the case that this function isn't used. Therefore I query phydev->supported before the speed could be limited. (relying on the PHY driver not lying about gigabit capability) This part of the patch is directly before of_set_phy_supported().

I just see that we can re-use is_gigabit_capable also in genphy_config_advert.

Of course I can read in every place the hardware for gigabit support. But IMO this creates unnecessary code duplication.

Quoted 2 lines

Andrew

Heiner

author maintainer
#13 lore raw
Quoted 19 lines · Heiner Kallweit
Quoted 12 lines · Andrew Lunn

drivers/net/phy/phy_device.c static int phy_probe(struct device *dev) · line 2160

Quoted 7 lines
drivers/net/phy/phy_device.c +7 -0
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+

What i'm trying to get at is, why do we need this bit of the patch? Why do we need this flag? The hardware should tell us if it can do gigabit.

The code to query BMSR_ESTATEN and MII_ESTATUS is in genphy_read_status. However we also have to cover the case that this function isn't used. Therefore I query phydev->supported before the speed could be limited. (relying on the PHY driver not lying about gigabit capability) This part of the patch is directly before of_set_phy_supported().

Quoted 6 lines

I just see that we can re-use is_gigabit_capable also in genphy_config_advert.

Of course I can read in every place the hardware for gigabit support. But IMO this creates unnecessary code duplication.

I just see that we can reuse is_gigabit_capable also in genphy_config_advert().

And when checking occurrences of BMSR_ESTATEN there seems to be more work waiting: In swphy BMSR_ESTATEN is set, but MII_ESTATUS isn't configured. It just works by chance becausing reading this register returns the default 0xffff.

Quoted 4 lines
Quoted 2 lines

Andrew

Heiner

#14 lore raw
Quoted 26 lines · Heiner Kallweit
Quoted 19 lines · Heiner Kallweit
Quoted 12 lines · Andrew Lunn

drivers/net/phy/phy_device.c static int phy_probe(struct device *dev) · line 2160

Quoted 7 lines
drivers/net/phy/phy_device.c +7 -0
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+

What i'm trying to get at is, why do we need this bit of the patch? Why do we need this flag? The hardware should tell us if it can do gigabit.

The code to query BMSR_ESTATEN and MII_ESTATUS is in genphy_read_status. However we also have to cover the case that this function isn't used. Therefore I query phydev->supported before the speed could be limited. (relying on the PHY driver not lying about gigabit capability) This part of the patch is directly before of_set_phy_supported().

Quoted 6 lines

I just see that we can re-use is_gigabit_capable also in genphy_config_advert.

Of course I can read in every place the hardware for gigabit support. But IMO this creates unnecessary code duplication.

Quoted 7 lines

I just see that we can reuse is_gigabit_capable also in genphy_config_advert().

And when checking occurrences of BMSR_ESTATEN there seems to be more work waiting: In swphy BMSR_ESTATEN is set, but MII_ESTATUS isn't configured. It just works by chance becausing reading this register returns the default 0xffff.

It is not clear to me what we are trying to optimize for here, given everything is pretty much a slow path anyway. I am concerned though about mis-behaving PHYs where caching of BMSR_ESTATEN could result in incorrect behaviors, I don't have any data to back that claim, but reading the registers should always be the safest way to determine what HW is capable of (famous last words). Not feeling strongly about either direction though...

Signature · 1 line
Florian
author maintainer
#15 lore raw
Quoted 35 lines · Florian Fainelli
Quoted 26 lines · Heiner Kallweit
Quoted 19 lines · Heiner Kallweit
Quoted 12 lines · Andrew Lunn

drivers/net/phy/phy_device.c static int phy_probe(struct device *dev) · line 2160

Quoted 7 lines
drivers/net/phy/phy_device.c +7 -0
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+

What i'm trying to get at is, why do we need this bit of the patch? Why do we need this flag? The hardware should tell us if it can do gigabit.

The code to query BMSR_ESTATEN and MII_ESTATUS is in genphy_read_status. However we also have to cover the case that this function isn't used. Therefore I query phydev->supported before the speed could be limited. (relying on the PHY driver not lying about gigabit capability) This part of the patch is directly before of_set_phy_supported().

Quoted 6 lines

I just see that we can re-use is_gigabit_capable also in genphy_config_advert.

Of course I can read in every place the hardware for gigabit support. But IMO this creates unnecessary code duplication.

Quoted 7 lines

I just see that we can reuse is_gigabit_capable also in genphy_config_advert().

And when checking occurrences of BMSR_ESTATEN there seems to be more work waiting: In swphy BMSR_ESTATEN is set, but MII_ESTATUS isn't configured. It just works by chance becausing reading this register returns the default 0xffff.

Quoted 8 lines

It is not clear to me what we are trying to optimize for here, given everything is pretty much a slow path anyway. I am concerned though about mis-behaving PHYs where caching of BMSR_ESTATEN could result in incorrect behaviors, I don't have any data to back that claim, but reading the registers should always be the safest way to determine what HW is capable of (famous last words). Not feeling strongly about either direction though...

At this point I have to quote Einstein:
"If you can't explain it simply, you don't understand it well enough." Means I'll spend few more thoughts on it ..

#16 lore raw
Quoted 45 lines · Heiner Kallweit
Quoted 35 lines · Florian Fainelli
Quoted 26 lines · Heiner Kallweit
Quoted 19 lines · Heiner Kallweit
Quoted 12 lines · Andrew Lunn

drivers/net/phy/phy_device.c static int phy_probe(struct device *dev) · line 2160

Quoted 7 lines
drivers/net/phy/phy_device.c +7 -0
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+	if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
+			      phydev->supported))
+		phydev->is_gigabit_capable = 1;
+

What i'm trying to get at is, why do we need this bit of the patch? Why do we need this flag? The hardware should tell us if it can do gigabit.

The code to query BMSR_ESTATEN and MII_ESTATUS is in genphy_read_status. However we also have to cover the case that this function isn't used. Therefore I query phydev->supported before the speed could be limited. (relying on the PHY driver not lying about gigabit capability) This part of the patch is directly before of_set_phy_supported().

Quoted 6 lines

I just see that we can re-use is_gigabit_capable also in genphy_config_advert.

Of course I can read in every place the hardware for gigabit support. But IMO this creates unnecessary code duplication.

Quoted 7 lines

I just see that we can reuse is_gigabit_capable also in genphy_config_advert().

And when checking occurrences of BMSR_ESTATEN there seems to be more work waiting: In swphy BMSR_ESTATEN is set, but MII_ESTATUS isn't configured. It just works by chance becausing reading this register returns the default 0xffff.

Quoted 8 lines

It is not clear to me what we are trying to optimize for here, given everything is pretty much a slow path anyway. I am concerned though about mis-behaving PHYs where caching of BMSR_ESTATEN could result in incorrect behaviors, I don't have any data to back that claim, but reading the registers should always be the safest way to determine what HW is capable of (famous last words). Not feeling strongly about either direction though...

Quoted 3 lines

At this point I have to quote Einstein:
"If you can't explain it simply, you don't understand it well enough." Means I'll spend few more thoughts on it ..

I have re-read the patch more carefully now and understand what it is fixing, sorry for the pointless discussion.

Signature · 1 line
Florian
Reviewed-by on v1 1/1
#17 lore raw
In reply to Heiner Kallweit
Quoted 10 lines · Heiner Kallweit

genphy_read_status() so far checks phydev->supported, not the actual PHY capabilities. This can make a difference if the supported speeds have been limited by of_set_phy_supported() or phy_set_max_speed().

It seems that this issue only affects the link partner advertisements as displayed by ethtool. Also this patch wouldn't apply to older kernels because linkmode bitmaps have been introduced recently. Therefore net-next.

Signature · 1 line
Florian
maintainer Applied
#18 lore raw
In reply to Heiner Kallweit

From: Heiner Kallweit <[email protected]>
Date: Fri, 5 Apr 2019 21:23:13 +0200

Quoted 10 lines

genphy_read_status() so far checks phydev->supported, not the actual PHY capabilities. This can make a difference if the supported speeds have been limited by of_set_phy_supported() or phy_set_max_speed().

It seems that this issue only affects the link partner advertisements as displayed by ethtool. Also this patch wouldn't apply to older kernels because linkmode bitmaps have been introduced recently. Therefore net-next.

Applied, thanks Heiner.