From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DA17139F for ; Tue, 9 Jul 2024 05:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720504164; cv=none; b=VnbhB1WjX8IXKYOofZl7VbKHY87yrOAEM9UGBIuyqTnyvXhDS66+gYy5rB1TRocx+lgm+CzNzw7wdUkm+Wft2vdlIdzfYy4FEuhNBeqGj0a4LDzdPVbiDygelZHrVPL0jbGQ8QbTcWP2257cNP6dOKh5PxJHK9O+yyPM9/nt7BQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720504164; c=relaxed/simple; bh=It03ltIjjO9lEvQ29pwF5UNKmsPsL/vaE5d/+86fbTQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=alRp+pTWpCLukcrxjXWgYVufQpdya5p/jmUwBrHA//2cIU0ZzpK7j35KqleQ0II/aNqro/dz8zT8lYAVsIsdBO1cw3MhtNRmsG5Ga+ECA4PLEdxUiamOwUB2vF+PVIhYNWapUlr2LfJOnxW11H3J9bYpe/KoVIm2/wguXLL9KLY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sR3in-0002au-3M; Tue, 09 Jul 2024 07:49:01 +0200 Received: from [2a0a:edc0:2:b01:1d::c5] (helo=pty.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sR3ik-008D9L-Fz; Tue, 09 Jul 2024 07:48:58 +0200 Received: from ore by pty.whiteo.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1sR3ik-006RHF-1E; Tue, 09 Jul 2024 07:48:58 +0200 Date: Tue, 9 Jul 2024 07:48:58 +0200 From: Oleksij Rempel 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 Message-ID: References: <20240706054900.1288111-1-o.rempel@pengutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org 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 |