netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <simon.horman@corigine.com>
To: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org
Subject: Re: [PATCH net-next] net: phy: add helpers for comparing phy IDs
Date: Fri, 19 May 2023 15:43:49 +0200	[thread overview]
Message-ID: <ZGd9FZ5vaLOdBN+M@corigine.com> (raw)
In-Reply-To: <E1pzzm3-006BZJ-Bi@rmk-PC.armlinux.org.uk>

On Fri, May 19, 2023 at 02:03:59PM +0100, Russell King wrote:
> There are several places which open code comparing PHY IDs. Provide a
> couple of helpers to assist with this, using a slightly simpler test
> than the original:
> 
> - phy_id_compare() compares two arbitary PHY IDs and a mask of the
>   significant bits in the ID.
> - phydev_id_compare() compares the bound phydev with the specified
>   PHY ID, using the bound driver's mask.
> 
> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>

Thanks Russell,

Reviewed-by: Simon Horman <simon.horman@corigine.com>

...

> diff --git a/include/linux/phy.h b/include/linux/phy.h
> index d8cd7115c773..2da87a36200d 100644
> --- a/include/linux/phy.h
> +++ b/include/linux/phy.h
> @@ -1112,6 +1112,34 @@ struct phy_driver {
>  #define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 4)
>  #define PHY_ID_MATCH_VENDOR(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 10)
>  
> +/**
> + * phy_id_compare - compare @id1 with @id2 taking account of @mask
> + * @id1: first PHY ID
> + * @id2: second PHY ID
> + * @mask: the PHY ID mask, set bits are significant in matching
> + *
> + * Return true if the bits from @id1 and @id2 specified by @mask match.
> + * This uses an equivalent test to (@id & @mask) == (@phy_id & @mask).
> + */
> +static inline bool phy_id_compare(u32 id1, u32 id2, u32 mask)
> +{
> +	return !((id1 ^ id2) & mask);
> +}

I wonder if, at some point, it would be worth generalising this further.
It seems likely such an operation is used outside of the context of phy_id.

  reply	other threads:[~2023-05-19 13:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 13:03 [PATCH net-next] net: phy: add helpers for comparing phy IDs Russell King
2023-05-19 13:43 ` Simon Horman [this message]
2023-05-19 15:59 ` Andrew Lunn
2023-05-19 16:04   ` Russell King (Oracle)
2023-05-21 15:09 ` Andrew Lunn
2023-05-22 10:30 ` patchwork-bot+netdevbpf

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=ZGd9FZ5vaLOdBN+M@corigine.com \
    --to=simon.horman@corigine.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rmk+kernel@armlinux.org.uk \
    /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).