netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/2] net: phylib: fix fixed-speed >= 1G
@ 2024-08-08 11:40 Russell King (Oracle)
  2024-08-08 11:41 ` [PATCH net-next v2 1/2] net: mii: constify advertising mask Russell King (Oracle)
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Russell King (Oracle) @ 2024-08-08 11:40 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev,
	Paolo Abeni

Hi,

This is v2 of the patch (now patches) adding support for ethtool
!autoneg while respecting the requirements of IEEE 802.3.

v2 fixes the build errors in the previous patch by first constifying
the "advertisement" argument to the linkmode functions that only
read from this pointer. It also fixes the incorrectly named
linkmode_set function.

 drivers/net/phy/phy_device.c | 34 +++++++++++++++++++++++++---------
 include/linux/mii.h          |  7 ++++---
 2 files changed, 29 insertions(+), 12 deletions(-)

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next v2 1/2] net: mii: constify advertising mask
  2024-08-08 11:40 [PATCH net-next v2 0/2] net: phylib: fix fixed-speed >= 1G Russell King (Oracle)
@ 2024-08-08 11:41 ` Russell King (Oracle)
  2024-08-11 16:11   ` Andrew Lunn
  2024-08-08 11:41 ` [PATCH net-next v2 2/2] net: phylib: do not disable autoneg for fixed speeds >= 1G Russell King (Oracle)
  2024-08-11 16:12 ` [PATCH net-next v2 0/2] net: phylib: fix fixed-speed " patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Russell King (Oracle) @ 2024-08-08 11:41 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev,
	Paolo Abeni

Constify the advertising mask to linkmode functions that only read from
the advertising mask.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 include/linux/mii.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/linux/mii.h b/include/linux/mii.h
index d5a959ce4877..b8f26d4513c3 100644
--- a/include/linux/mii.h
+++ b/include/linux/mii.h
@@ -140,7 +140,7 @@ static inline u32 ethtool_adv_to_mii_adv_t(u32 ethadv)
  * settings to phy autonegotiation advertisements for the
  * MII_ADVERTISE register.
  */
-static inline u32 linkmode_adv_to_mii_adv_t(unsigned long *advertising)
+static inline u32 linkmode_adv_to_mii_adv_t(const unsigned long *advertising)
 {
 	u32 result = 0;
 
@@ -215,7 +215,8 @@ static inline u32 ethtool_adv_to_mii_ctrl1000_t(u32 ethadv)
  * settings to phy autonegotiation advertisements for the
  * MII_CTRL1000 register when in 1000T mode.
  */
-static inline u32 linkmode_adv_to_mii_ctrl1000_t(unsigned long *advertising)
+static inline u32
+linkmode_adv_to_mii_ctrl1000_t(const unsigned long *advertising)
 {
 	u32 result = 0;
 
@@ -453,7 +454,7 @@ static inline void mii_ctrl1000_mod_linkmode_adv_t(unsigned long *advertising,
  * A small helper function that translates linkmode advertising to LVL
  * pause capabilities.
  */
-static inline u32 linkmode_adv_to_lcl_adv_t(unsigned long *advertising)
+static inline u32 linkmode_adv_to_lcl_adv_t(const unsigned long *advertising)
 {
 	u32 lcl_adv = 0;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v2 2/2] net: phylib: do not disable autoneg for fixed speeds >= 1G
  2024-08-08 11:40 [PATCH net-next v2 0/2] net: phylib: fix fixed-speed >= 1G Russell King (Oracle)
  2024-08-08 11:41 ` [PATCH net-next v2 1/2] net: mii: constify advertising mask Russell King (Oracle)
@ 2024-08-08 11:41 ` Russell King (Oracle)
  2024-08-11 16:13   ` Andrew Lunn
  2024-08-11 16:12 ` [PATCH net-next v2 0/2] net: phylib: fix fixed-speed " patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: Russell King (Oracle) @ 2024-08-08 11:41 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, netdev,
	Paolo Abeni

We have an increasing number of drivers that are forcing
auto-negotiation to be enabled for speeds of 1G or faster.

It would appear that auto-negotiation is mandatory for speeds above
100M. In 802.3, Annex 40C's state diagrams seems to imply that
mr_autoneg_enable (BMCR AN ENABLE) doesn't affect whether or not the
AN state machines work for 1000base-T, and some PHY datasheets (e.g.
Marvell Alaska) state that disabling mr_autoneg_enable leaves AN
enabled but forced to 1G full duplex.

Other PHY datasheets imply that BMCR AN ENABLE should not be cleared
for >= 1G.

Thus, this should be handled in phylib rather than in each driver.

Rather than erroring out, arrange to implement the Marvell Alaska
solution but in software for all PHYs: generate an appropriate
single-speed advertisement for the requested speed, and keep AN
enabled to the PHY driver. However, to avoid userspace API breakage,
continue to report to userspace that we have AN disabled.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/phy_device.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 29a4225cb712..69fe207ac2eb 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -2103,22 +2103,20 @@ EXPORT_SYMBOL(phy_reset_after_clk_enable);
 /**
  * genphy_config_advert - sanitize and advertise auto-negotiation parameters
  * @phydev: target phy_device struct
+ * @advert: auto-negotiation parameters to advertise
  *
  * Description: Writes MII_ADVERTISE with the appropriate values,
  *   after sanitizing the values to make sure we only advertise
  *   what is supported.  Returns < 0 on error, 0 if the PHY's advertisement
  *   hasn't changed, and > 0 if it has changed.
  */
-static int genphy_config_advert(struct phy_device *phydev)
+static int genphy_config_advert(struct phy_device *phydev,
+				const unsigned long *advert)
 {
 	int err, bmsr, changed = 0;
 	u32 adv;
 
-	/* Only allow advertising what this PHY supports */
-	linkmode_and(phydev->advertising, phydev->advertising,
-		     phydev->supported);
-
-	adv = linkmode_adv_to_mii_adv_t(phydev->advertising);
+	adv = linkmode_adv_to_mii_adv_t(advert);
 
 	/* Setup standard advertisement */
 	err = phy_modify_changed(phydev, MII_ADVERTISE,
@@ -2141,7 +2139,7 @@ static int genphy_config_advert(struct phy_device *phydev)
 	if (!(bmsr & BMSR_ESTATEN))
 		return changed;
 
-	adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
+	adv = linkmode_adv_to_mii_ctrl1000_t(advert);
 
 	err = phy_modify_changed(phydev, MII_CTRL1000,
 				 ADVERTISE_1000FULL | ADVERTISE_1000HALF,
@@ -2365,6 +2363,9 @@ EXPORT_SYMBOL(genphy_check_and_restart_aneg);
  */
 int __genphy_config_aneg(struct phy_device *phydev, bool changed)
 {
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(fixed_advert);
+	const struct phy_setting *set;
+	unsigned long *advert;
 	int err;
 
 	err = genphy_c45_an_config_eee_aneg(phydev);
@@ -2379,10 +2380,25 @@ int __genphy_config_aneg(struct phy_device *phydev, bool changed)
 	else if (err)
 		changed = true;
 
-	if (AUTONEG_ENABLE != phydev->autoneg)
+	if (phydev->autoneg == AUTONEG_ENABLE) {
+		/* Only allow advertising what this PHY supports */
+		linkmode_and(phydev->advertising, phydev->advertising,
+			     phydev->supported);
+		advert = phydev->advertising;
+	} else if (phydev->speed < SPEED_1000) {
 		return genphy_setup_forced(phydev);
+	} else {
+		linkmode_zero(fixed_advert);
+
+		set = phy_lookup_setting(phydev->speed, phydev->duplex,
+					 phydev->supported, true);
+		if (set)
+			linkmode_set_bit(set->bit, fixed_advert);
+
+		advert = fixed_advert;
+	}
 
-	err = genphy_config_advert(phydev);
+	err = genphy_config_advert(phydev, advert);
 	if (err < 0) /* error */
 		return err;
 	else if (err)
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2 1/2] net: mii: constify advertising mask
  2024-08-08 11:41 ` [PATCH net-next v2 1/2] net: mii: constify advertising mask Russell King (Oracle)
@ 2024-08-11 16:11   ` Andrew Lunn
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2024-08-11 16:11 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Heiner Kallweit, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni

On Thu, Aug 08, 2024 at 12:41:17PM +0100, Russell King (Oracle) wrote:
> Constify the advertising mask to linkmode functions that only read from
> the advertising mask.
> 
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2 0/2] net: phylib: fix fixed-speed >= 1G
  2024-08-08 11:40 [PATCH net-next v2 0/2] net: phylib: fix fixed-speed >= 1G Russell King (Oracle)
  2024-08-08 11:41 ` [PATCH net-next v2 1/2] net: mii: constify advertising mask Russell King (Oracle)
  2024-08-08 11:41 ` [PATCH net-next v2 2/2] net: phylib: do not disable autoneg for fixed speeds >= 1G Russell King (Oracle)
@ 2024-08-11 16:12 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-11 16:12 UTC (permalink / raw)
  To: Russell King; +Cc: andrew, hkallweit1, davem, edumazet, kuba, netdev, pabeni

Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu, 8 Aug 2024 12:40:36 +0100 you wrote:
> Hi,
> 
> This is v2 of the patch (now patches) adding support for ethtool
> !autoneg while respecting the requirements of IEEE 802.3.
> 
> v2 fixes the build errors in the previous patch by first constifying
> the "advertisement" argument to the linkmode functions that only
> read from this pointer. It also fixes the incorrectly named
> linkmode_set function.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/2] net: mii: constify advertising mask
    https://git.kernel.org/netdev/net-next/c/aa9fbc5dd9da
  - [net-next,v2,2/2] net: phylib: do not disable autoneg for fixed speeds >= 1G
    https://git.kernel.org/netdev/net-next/c/6ff3cddc365b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v2 2/2] net: phylib: do not disable autoneg for fixed speeds >= 1G
  2024-08-08 11:41 ` [PATCH net-next v2 2/2] net: phylib: do not disable autoneg for fixed speeds >= 1G Russell King (Oracle)
@ 2024-08-11 16:13   ` Andrew Lunn
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Lunn @ 2024-08-11 16:13 UTC (permalink / raw)
  To: Russell King (Oracle)
  Cc: Heiner Kallweit, David S. Miller, Eric Dumazet, Jakub Kicinski,
	netdev, Paolo Abeni

On Thu, Aug 08, 2024 at 12:41:22PM +0100, Russell King (Oracle) wrote:
> We have an increasing number of drivers that are forcing
> auto-negotiation to be enabled for speeds of 1G or faster.
> 
> It would appear that auto-negotiation is mandatory for speeds above
> 100M. In 802.3, Annex 40C's state diagrams seems to imply that
> mr_autoneg_enable (BMCR AN ENABLE) doesn't affect whether or not the
> AN state machines work for 1000base-T, and some PHY datasheets (e.g.
> Marvell Alaska) state that disabling mr_autoneg_enable leaves AN
> enabled but forced to 1G full duplex.
> 
> Other PHY datasheets imply that BMCR AN ENABLE should not be cleared
> for >= 1G.
> 
> Thus, this should be handled in phylib rather than in each driver.
> 
> Rather than erroring out, arrange to implement the Marvell Alaska
> solution but in software for all PHYs: generate an appropriate
> single-speed advertisement for the requested speed, and keep AN
> enabled to the PHY driver. However, to avoid userspace API breakage,
> continue to report to userspace that we have AN disabled.
> 
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-08-11 16:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 11:40 [PATCH net-next v2 0/2] net: phylib: fix fixed-speed >= 1G Russell King (Oracle)
2024-08-08 11:41 ` [PATCH net-next v2 1/2] net: mii: constify advertising mask Russell King (Oracle)
2024-08-11 16:11   ` Andrew Lunn
2024-08-08 11:41 ` [PATCH net-next v2 2/2] net: phylib: do not disable autoneg for fixed speeds >= 1G Russell King (Oracle)
2024-08-11 16:13   ` Andrew Lunn
2024-08-11 16:12 ` [PATCH net-next v2 0/2] net: phylib: fix fixed-speed " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).