netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	David Miller <davem@davemloft.net>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next 1/2] net: phy: improve phy_resolve_aneg_linkmode
Date: Fri, 15 Feb 2019 14:57:14 +0100	[thread overview]
Message-ID: <20190215135714.GI5699@lunn.ch> (raw)
In-Reply-To: <1571d9d1-b3ad-8c96-a476-4ae18d20abfe@gmail.com>

On Thu, Feb 14, 2019 at 10:15:31PM +0100, Heiner Kallweit wrote:
> We have the settings array of modes which is sorted based on aneg
> priority. Instead of checking each mode manually let's simply iterate
> over the sorted settings.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/phy/phy-core.c | 43 +++++++-------------------------------
>  1 file changed, 7 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
> index cdea028d1..5d43106fe 100644
> --- a/drivers/net/phy/phy-core.c
> +++ b/drivers/net/phy/phy-core.c
> @@ -349,45 +349,16 @@ size_t phy_speeds(unsigned int *speeds, size_t size,
>  void phy_resolve_aneg_linkmode(struct phy_device *phydev)
>  {
>  	__ETHTOOL_DECLARE_LINK_MODE_MASK(common);
> +	int i;
>  
>  	linkmode_and(common, phydev->lp_advertising, phydev->advertising);
>  
> -	if (linkmode_test_bit(ETHTOOL_LINK_MODE_10000baseT_Full_BIT, common)) {
> -		phydev->speed = SPEED_10000;
> -		phydev->duplex = DUPLEX_FULL;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_5000;
> -		phydev->duplex = DUPLEX_FULL;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_2500;
> -		phydev->duplex = DUPLEX_FULL;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_1000;
> -		phydev->duplex = DUPLEX_FULL;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_1000;
> -		phydev->duplex = DUPLEX_HALF;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_100;
> -		phydev->duplex = DUPLEX_FULL;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_100;
> -		phydev->duplex = DUPLEX_HALF;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_10;
> -		phydev->duplex = DUPLEX_FULL;
> -	} else if (linkmode_test_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT,
> -				     common)) {
> -		phydev->speed = SPEED_10;
> -		phydev->duplex = DUPLEX_HALF;
> -	}
> +	for (i = 0; i < ARRAY_SIZE(settings); i++)
> +		if (test_bit(settings[i].bit, common)) {
> +			phydev->speed = settings[i].speed;
> +			phydev->duplex = settings[i].duplex;
> +			break;
> +		}

Hi Heiner

Nice simplification.

I just have one thought about this. The original code was limited to
baseT. The new code could in theory return a non BaseT speed. For that
to happen, it would require that phydev->lp_advertising and
phydev->advertising contain a non BaseT link mode? Is that possible?
I don't think it is.

  Andrew

  reply	other threads:[~2019-02-15 13:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-14 21:12 [PATCH net-next 0/2] net: phy: improve and use phy_resolve_aneg_linkmode Heiner Kallweit
2019-02-14 21:15 ` [PATCH net-next 1/2] net: phy: improve phy_resolve_aneg_linkmode Heiner Kallweit
2019-02-15 13:57   ` Andrew Lunn [this message]
2019-02-15 18:57     ` Heiner Kallweit
2019-02-14 21:16 ` [PATCH net-next 2/2] net: phy: use phy_resolve_aneg_linkmode in genphy_read_status Heiner Kallweit
2019-02-17 23:22 ` [PATCH net-next 0/2] net: phy: improve and use phy_resolve_aneg_linkmode David Miller

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=20190215135714.GI5699@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=hkallweit1@gmail.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).