netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>
Cc: 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 17:04:03 +0100	[thread overview]
Message-ID: <ZGed83w9IlHnTgsC@shell.armlinux.org.uk> (raw)
In-Reply-To: <808c6158-5e30-402b-b686-462ca17e2a2c@lunn.ch>

On Fri, May 19, 2023 at 05:59:02PM +0200, Andrew Lunn wrote:
> 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.
> 
> Hi Russell
> 
> I think these are useful, but i'm wondering about naming. In the PHY
> drivers we use these macros:
> 
> #define PHY_ID_MATCH_EXACT(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 0)
> #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)
> 
> when creating the tables. 
> 
> > diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c
> > index 3f81bb8dac44..2094d49025a7 100644
> > --- a/drivers/net/phy/micrel.c
> > +++ b/drivers/net/phy/micrel.c
> > @@ -637,7 +637,7 @@ static int ksz8051_ksz8795_match_phy_device(struct phy_device *phydev,
> >  {
> >  	int ret;
> >  
> > -	if ((phydev->phy_id & MICREL_PHY_ID_MASK) != PHY_ID_KSZ8051)
> > +	if (!phy_id_compare(phydev->phy_id, PHY_ID_KSZ8051, MICREL_PHY_ID_MASK))
> >  		return 0;
> 
> This could be phy_id_compare_model() 

Note that this can't access phydev->drv, because this is a match method
and in all likelyhood, phydev->drv is NULL here.

> phy_id_compare_exact() could be used in a number of places, eg.
> 
> vitesse.c:			(phydev->drv->phy_id == PHY_ID_VSC8234 ||
> vitesse.c:			 phydev->drv->phy_id == PHY_ID_VSC8244 ||
> vitesse.c:			 phydev->drv->phy_id == PHY_ID_VSC8572 ||
> vitesse.c:			 phydev->drv->phy_id == PHY_ID_VSC8601) ?
> motorcomm.c:	} else if (phydev->drv->phy_id == PHY_ID_YT8531S) {
> marvell10g.c:	if (phydev->drv->phy_id != MARVELL_PHY_ID_88X3310)

However, these are not comparing the PHY ID, they're comparing the
driver's idea of the PHY ID. I would expect phy_id_compare_exact()
to be comparing phydev->phy_id!

Many places can use phydev->drv->phy_id == foo to identify which
driver was matched. If the driver's phy_id is set my a macro
definition, then that same macro identifier can be used with a
straight compare like the above, and I think open coding those
like that is entirely reasonable and proper.

However, phydev->phy_id is much more complex because it generally
needs the revision masking away, which is what these helpers are
achieving.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

  reply	other threads:[~2023-05-19 16:04 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
2023-05-19 15:59 ` Andrew Lunn
2023-05-19 16:04   ` Russell King (Oracle) [this message]
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=ZGed83w9IlHnTgsC@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --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 \
    /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).