From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Woojung.Huh@microchip.com
Cc: mkubecek@suse.cz, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, jiri@resnulli.us,
vladimir.oltean@nxp.com, andrew@lunn.ch,
Arun.Ramadoss@microchip.com, kernel@pengutronix.de,
netdev@vger.kernel.org, UNGLinuxDriver@microchip.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2 1/1] ethtool: netlink: do not return SQI value if link is down
Date: Tue, 9 Jul 2024 07:48:58 +0200 [thread overview]
Message-ID: <ZozPSl6opHYYdO-A@pengutronix.de> (raw)
In-Reply-To: <BL0PR11MB29139867F521F90347B6904EE7DA2@BL0PR11MB2913.namprd11.prod.outlook.com>
Hi Woojung,
On Mon, Jul 08, 2024 at 04:31:53PM +0000, Woojung.Huh@microchip.com wrote:
> Hi Oleksij,
>
> > diff --git a/net/ethtool/linkstate.c b/net/ethtool/linkstate.c
> > index b2de2108b356a..4efd327ba5d92 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);
> > @@ -62,6 +66,16 @@ static int linkstate_get_sqi_max(struct net_device *dev)
> > return ret;
> > };
> >
> > +static bool linkstate_sqi_critical_error(int sqi)
> > +{
> > + return sqi < 0 && sqi != -EOPNOTSUPP && sqi != -ENETDOWN;
> > +}
> > +
> > +static bool linkstate_sqi_valid(struct linkstate_reply_data *data)
> > +{
> > + return data->sqi >= 0 && data->sqi_max >= 0;
>
> If PHY driver has get_sqi, but not get_sqi_max, then data->sqi could have
> a valid value, but data->sqi_max will have -EOPNOTSUPP.
> In this case, linkstate_sqi_valid() will return FALSE and not getting
> SQI value at all.
SQI without max will not able to describe quality of the link, it is
just value saying nothing to the user.
> If both APIs are required, then we could add another condition of
> data->sqi <= data->sqi_max in linkstate_sqi_valid()
Ack. I was thinking about it, but was not sure if it is a good idea. This
will silently filer our a bag. Passing a baggy value to the users space
is not good too. I'll fix.
> And, beside this, calling linkstate_get_sqi and linkstate_get_sqi_max
> could be moved under "if (dev->flags & IFF_UP)" with setting default
> value to data->sqi & data->sqi_max.
IFF_UP is administrative up state, it is not the link/L1 up. sqi_max and
sqi should be initialized anyway, otherwise we will show 0/0 if
interface is in admin down.
Regards,
Oleksij
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2024-07-09 5:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-06 5:49 [PATCH net v2 1/1] ethtool: netlink: do not return SQI value if link is down Oleksij Rempel
2024-07-08 13:33 ` Andrew Lunn
2024-07-08 16:31 ` Woojung.Huh
2024-07-09 5:48 ` Oleksij Rempel [this message]
2024-07-09 18:02 ` Woojung.Huh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZozPSl6opHYYdO-A@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=Arun.Ramadoss@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vladimir.oltean@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox