[PATCH net-next v1] mlxbf_gige: report unknown speed and duplex when link is down

Chris Babroski posted 1 patch 1 month, 3 weeks ago
.../mellanox/mlxbf_gige/mlxbf_gige_ethtool.c  | 26 ++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
[PATCH net-next v1] mlxbf_gige: report unknown speed and duplex when link is down
Posted by Chris Babroski 1 month, 3 weeks ago
The "Speed" and "Duplex" fields displayed by ethtool should report
"Unknown" when the link is down. Currently, the driver always reports
the initially configured link speed and duplex, regardless of the actual
link state.

Implement a get_link_ksettings() callback to update the values reported
to ethtool based on the link state. When the link is down, the driver
now reports unknown speed and duplex as expected.

Signed-off-by: Chris Babroski <cbabroski@nvidia.com>
---
 .../mellanox/mlxbf_gige/mlxbf_gige_ethtool.c  | 26 ++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_ethtool.c b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_ethtool.c
index 8b63968bbee9..c519eeb8ec48 100644
--- a/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlxbf_gige/mlxbf_gige_ethtool.c
@@ -159,6 +159,30 @@ static void mlxbf_gige_get_pause_stats(struct net_device *netdev,
 	}
 }
 
+static int mlxbf_gige_get_link_ksettings(struct net_device *ndev,
+					 struct ethtool_link_ksettings *cmd)
+{
+	struct phy_device *phydev;
+	int ret;
+
+	ret = phy_ethtool_get_link_ksettings(ndev, cmd);
+	if (ret)
+		return ret;
+
+	phydev = ndev->phydev;
+	if (!phydev)
+		return -ENODEV;
+
+	mutex_lock(&phydev->lock);
+	if (!phydev->link) {
+		cmd->base.speed = SPEED_UNKNOWN;
+		cmd->base.duplex = DUPLEX_UNKNOWN;
+	}
+	mutex_unlock(&phydev->lock);
+
+	return 0;
+}
+
 const struct ethtool_ops mlxbf_gige_ethtool_ops = {
 	.get_link		= ethtool_op_get_link,
 	.get_ringparam		= mlxbf_gige_get_ringparam,
@@ -170,6 +194,6 @@ const struct ethtool_ops mlxbf_gige_ethtool_ops = {
 	.nway_reset		= phy_ethtool_nway_reset,
 	.get_pauseparam		= mlxbf_gige_get_pauseparam,
 	.get_pause_stats	= mlxbf_gige_get_pause_stats,
-	.get_link_ksettings	= phy_ethtool_get_link_ksettings,
+	.get_link_ksettings	= mlxbf_gige_get_link_ksettings,
 	.set_link_ksettings	= phy_ethtool_set_link_ksettings,
 };

base-commit: d9104cec3e8fe4b458b74709853231385779001f
-- 
2.34.1
Re: [PATCH net-next v1] mlxbf_gige: report unknown speed and duplex when link is down
Posted by Jakub Kicinski 1 month, 2 weeks ago
On Wed, 13 Aug 2025 12:33:46 -0400 Chris Babroski wrote:
> The "Speed" and "Duplex" fields displayed by ethtool should report
> "Unknown" when the link is down. Currently, the driver always reports
> the initially configured link speed and duplex, regardless of the actual
> link state.
> 
> Implement a get_link_ksettings() callback to update the values reported
> to ethtool based on the link state. When the link is down, the driver
> now reports unknown speed and duplex as expected.

If that's the correct thing to do why is
phy_ethtool_get_link_ksettings() not doing it?

Please explain what makes mlxbf special, and make sure to CC PHY
maintainers on v2.
-- 
pw-bot: cr
Re: [PATCH net-next v1] mlxbf_gige: report unknown speed and duplex when link is down
Posted by Chris Babroski 1 month, 1 week ago
Hi Jakub,

Thanks for the feedback.

> If that's the correct thing to do why is
> phy_ethtool_get_link_ksettings() not doing it?

If I understand correctly, phy_ethtool_get_link_ksettings() reads
cached values that are updated when phy_read_status() is called by the
phy state machine. Doing "ifconfig down" will eventually trigger
phy_stop() in the ndo_stop() handler. This halts the phy state machine
and sets phydev->link without calling phy_read_status() or explicitly
setting other values, like speed and duplex.

It seems this is expected behavior with phylib, but I'm not familiar
with the implementation history. CC'd PHY maintainers for additional
input.

> Please explain what makes mlxbf special

BlueField is unique in that the phy is hardwired to an internal switch
and so the physical link between the phy and link partner is always
up. This will also affect what link settings are reported by the phy.

This patch comes from a desire for ethtool output behavior to be the
same when an administrative link down is issued on the BlueField OOB
(mlxbf_gige) and NIC (mlx5) interfaces. The mlx5 driver implements
custom get_link_ksettings() handlers and does not use phylib.

Best,
Chris