netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v1 1/1] ethtool: netlink: do not return SQI value if link is down
@ 2024-07-04  5:40 Oleksij Rempel
  2024-07-04 14:01 ` Andrew Lunn
  2024-07-06  1:00 ` Jakub Kicinski
  0 siblings, 2 replies; 5+ messages in thread
From: Oleksij Rempel @ 2024-07-04  5:40 UTC (permalink / raw)
  To: Michal Kubecek, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Jiri Pirko, Vladimir Oltean, Andrew Lunn,
	Arun Ramadoss, Woojung.Huh
  Cc: Oleksij Rempel, kernel, netdev, UNGLinuxDriver, linux-kernel

Do not attach SQI value if link is down. "SQI values are only valid if link-up
condition is present" per OpenAlliance specification of 100Base-T1
Interoperability Test suite [1]. The same rule would apply for other link
types.

[1] https://opensig.org/automotive-ethernet-specifications/#

Fixes: 8066021915924 ("ethtool: provide UAPI for PHY Signal Quality Index (SQI)")
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 net/ethtool/linkstate.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c
index b2de2108b356a..370ae628b13a4 100644
--- a/net/ethtool/linkstate.c
+++ b/net/ethtool/linkstate.c
@@ -37,6 +37,8 @@ static int linkstate_get_sqi(struct net_device *dev)
 	mutex_lock(&phydev->lock);
 	if (!phydev->drv || !phydev->drv->get_sqi)
 		ret = -EOPNOTSUPP;
+	else if (!phydev->link)
+		ret = -ENETDOWN;
 	else
 		ret = phydev->drv->get_sqi(phydev);
 	mutex_unlock(&phydev->lock);
@@ -55,6 +57,8 @@ static int linkstate_get_sqi_max(struct net_device *dev)
 	mutex_lock(&phydev->lock);
 	if (!phydev->drv || !phydev->drv->get_sqi_max)
 		ret = -EOPNOTSUPP;
+	else if (!phydev->link)
+		ret = -ENETDOWN;
 	else
 		ret = phydev->drv->get_sqi_max(phydev);
 	mutex_unlock(&phydev->lock);
@@ -93,12 +97,12 @@ static int linkstate_prepare_data(const struct ethnl_req_info *req_base,
 	data->link = __ethtool_get_link(dev);
 
 	ret = linkstate_get_sqi(dev);
-	if (ret < 0 && ret != -EOPNOTSUPP)
+	if (ret < 0 && ret != -EOPNOTSUPP && ret != -ENETDOWN)
 		goto out;
 	data->sqi = ret;
 
 	ret = linkstate_get_sqi_max(dev);
-	if (ret < 0 && ret != -EOPNOTSUPP)
+	if (ret < 0 && ret != -EOPNOTSUPP && ret != -ENETDOWN)
 		goto out;
 	data->sqi_max = ret;
 
@@ -136,10 +140,10 @@ static int linkstate_reply_size(const struct ethnl_req_info *req_base,
 	len = nla_total_size(sizeof(u8)) /* LINKSTATE_LINK */
 		+ 0;
 
-	if (data->sqi != -EOPNOTSUPP)
+	if (data->sqi != -EOPNOTSUPP && data->sqi != -ENETDOWN)
 		len += nla_total_size(sizeof(u32));
 
-	if (data->sqi_max != -EOPNOTSUPP)
+	if (data->sqi_max != -EOPNOTSUPP && data->sqi_max != -ENETDOWN)
 		len += nla_total_size(sizeof(u32));
 
 	if (data->link_ext_state_provided)
@@ -164,11 +168,11 @@ static int linkstate_fill_reply(struct sk_buff *skb,
 	    nla_put_u8(skb, ETHTOOL_A_LINKSTATE_LINK, !!data->link))
 		return -EMSGSIZE;
 
-	if (data->sqi != -EOPNOTSUPP &&
+	if (data->sqi != -EOPNOTSUPP && data->sqi != -ENETDOWN &&
 	    nla_put_u32(skb, ETHTOOL_A_LINKSTATE_SQI, data->sqi))
 		return -EMSGSIZE;
 
-	if (data->sqi_max != -EOPNOTSUPP &&
+	if (data->sqi_max != -EOPNOTSUPP && data->sqi_max != -ENETDOWN &&
 	    nla_put_u32(skb, ETHTOOL_A_LINKSTATE_SQI_MAX, data->sqi_max))
 		return -EMSGSIZE;
 
-- 
2.39.2


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

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

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-04  5:40 [PATCH net v1 1/1] ethtool: netlink: do not return SQI value if link is down Oleksij Rempel
2024-07-04 14:01 ` Andrew Lunn
2024-07-05  7:05   ` Oleksij Rempel
2024-07-08 13:29     ` Andrew Lunn
2024-07-06  1:00 ` Jakub Kicinski

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).