* [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper
@ 2025-08-23 13:44 Christian Marangi
2025-08-23 13:44 ` [net-next PATCH v2 2/2] net: phy: as21xxx: better handle PHY HW reset on soft-reboot Christian Marangi
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Christian Marangi @ 2025-08-23 13:44 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
Introduce phy_id_compare_vendor() PHY ID helper to compare a PHY ID with
the PHY ID Vendor using the generic PHY ID Vendor mask.
While at it also rework the PHY_ID_MATCH macro and move the mask to
dedicated define so that PHY driver can make use of the mask if needed.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
Changes v2:
- Fix kdoc error
include/linux/phy.h | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 74c1bcf64b3c..66153ac1f728 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1260,9 +1260,13 @@ struct phy_driver {
#define to_phy_driver(d) container_of_const(to_mdio_common_driver(d), \
struct phy_driver, mdiodrv)
-#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)
+#define PHY_ID_MATCH_EXTACT_MASK GENMASK(31, 0)
+#define PHY_ID_MATCH_MODEL_MASK GENMASK(31, 4)
+#define PHY_ID_MATCH_VENDOR_MASK GENMASK(31, 10)
+
+#define PHY_ID_MATCH_EXACT(id) .phy_id = (id), .phy_id_mask = PHY_ID_MATCH_EXTACT_MASK
+#define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = PHY_ID_MATCH_MODEL_MASK
+#define PHY_ID_MATCH_VENDOR(id) .phy_id = (id), .phy_id_mask = PHY_ID_MATCH_VENDOR_MASK
/**
* phy_id_compare - compare @id1 with @id2 taking account of @mask
@@ -1278,6 +1282,19 @@ static inline bool phy_id_compare(u32 id1, u32 id2, u32 mask)
return !((id1 ^ id2) & mask);
}
+/**
+ * phy_id_compare_vendor - compare @id with @vendor mask
+ * @id: PHY ID
+ * @vendor_mask: PHY Vendor mask
+ *
+ * Return: true if the bits from @id match @vendor using the
+ * generic PHY Vendor mask.
+ */
+static inline bool phy_id_compare_vendor(u32 id, u32 vendor_mask)
+{
+ return phy_id_compare(id, vendor_mask, PHY_ID_MATCH_VENDOR_MASK);
+}
+
/**
* phydev_id_compare - compare @id with the PHY's Clause 22 ID
* @phydev: the PHY device
--
2.50.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [net-next PATCH v2 2/2] net: phy: as21xxx: better handle PHY HW reset on soft-reboot
2025-08-23 13:44 [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Christian Marangi
@ 2025-08-23 13:44 ` Christian Marangi
2025-08-24 16:08 ` [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Andrew Lunn
2025-08-27 0:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Christian Marangi @ 2025-08-23 13:44 UTC (permalink / raw)
To: Christian Marangi, Andrew Lunn, Heiner Kallweit, Russell King,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev, linux-kernel
On soft-reboot, with a reset GPIO defined for an Aeonsemi PHY, the
special match_phy_device fails to correctly identify that the PHY
needs to load the firmware again.
This is caused by the fact that PHY ID is read BEFORE the PHY reset
GPIO (if present) is asserted, so we can be in the scenario where the
phydev have the previous PHY ID (with the PHY firmware loaded) but
after reset the generic AS21xxx PHY is present in the PHY ID registers.
To better handle this, skip reading the PHY ID register only for the PHY
that are not AS21xxx (by matching for the Aeonsemi Vendor) and always
read the PHY ID for the other case to handle both firmware already
loaded or an HW reset.
Fixes: 830877d89edc ("net: phy: Add support for Aeonsemi AS21xxx PHYs")
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/phy/as21xxx.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/phy/as21xxx.c b/drivers/net/phy/as21xxx.c
index 92697f43087d..005277360656 100644
--- a/drivers/net/phy/as21xxx.c
+++ b/drivers/net/phy/as21xxx.c
@@ -884,11 +884,12 @@ static int as21xxx_match_phy_device(struct phy_device *phydev,
u32 phy_id;
int ret;
- /* Skip PHY that are not AS21xxx or already have firmware loaded */
- if (phydev->c45_ids.device_ids[MDIO_MMD_PCS] != PHY_ID_AS21XXX)
+ /* Skip PHY that are not AS21xxx */
+ if (!phy_id_compare_vendor(phydev->c45_ids.device_ids[MDIO_MMD_PCS],
+ PHY_VENDOR_AEONSEMI))
return genphy_match_phy_device(phydev, phydrv);
- /* Read PHY ID to handle firmware just loaded */
+ /* Read PHY ID to handle firmware loaded or HW reset */
ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MII_PHYSID1);
if (ret < 0)
return ret;
--
2.50.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper
2025-08-23 13:44 [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Christian Marangi
2025-08-23 13:44 ` [net-next PATCH v2 2/2] net: phy: as21xxx: better handle PHY HW reset on soft-reboot Christian Marangi
@ 2025-08-24 16:08 ` Andrew Lunn
2025-08-24 16:10 ` Christian Marangi
2025-08-27 0:20 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2025-08-24 16:08 UTC (permalink / raw)
To: Christian Marangi
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
On Sat, Aug 23, 2025 at 03:44:28PM +0200, Christian Marangi wrote:
> Introduce phy_id_compare_vendor() PHY ID helper to compare a PHY ID with
> the PHY ID Vendor using the generic PHY ID Vendor mask.
>
> While at it also rework the PHY_ID_MATCH macro and move the mask to
> dedicated define so that PHY driver can make use of the mask if needed.
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Hi Christian
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> +/**
> + * phy_id_compare_vendor - compare @id with @vendor mask
> + * @id: PHY ID
> + * @vendor_mask: PHY Vendor mask
> + *
> + * Return: true if the bits from @id match @vendor using the
> + * generic PHY Vendor mask.
> + */
> +static inline bool phy_id_compare_vendor(u32 id, u32 vendor_mask)
> +{
> + return phy_id_compare(id, vendor_mask, PHY_ID_MATCH_VENDOR_MASK);
> +}
> +
broadcom.c: if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) {
broadcom.c: if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM57780) {
broadcom.c: if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
broadcom.c: if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54210E ||
broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54810 ||
broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54811)
broadcom.c: if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
It looks like there is a use case of phy_id_compare_model(), if you
feel like adding it.
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper
2025-08-24 16:08 ` [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Andrew Lunn
@ 2025-08-24 16:10 ` Christian Marangi
0 siblings, 0 replies; 5+ messages in thread
From: Christian Marangi @ 2025-08-24 16:10 UTC (permalink / raw)
To: Andrew Lunn
Cc: Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, netdev, linux-kernel
On Sun, Aug 24, 2025 at 06:08:34PM +0200, Andrew Lunn wrote:
> On Sat, Aug 23, 2025 at 03:44:28PM +0200, Christian Marangi wrote:
> > Introduce phy_id_compare_vendor() PHY ID helper to compare a PHY ID with
> > the PHY ID Vendor using the generic PHY ID Vendor mask.
> >
> > While at it also rework the PHY_ID_MATCH macro and move the mask to
> > dedicated define so that PHY driver can make use of the mask if needed.
> >
> > Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
>
> Hi Christian
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
>
> > +/**
> > + * phy_id_compare_vendor - compare @id with @vendor mask
> > + * @id: PHY ID
> > + * @vendor_mask: PHY Vendor mask
> > + *
> > + * Return: true if the bits from @id match @vendor using the
> > + * generic PHY Vendor mask.
> > + */
> > +static inline bool phy_id_compare_vendor(u32 id, u32 vendor_mask)
> > +{
> > + return phy_id_compare(id, vendor_mask, PHY_ID_MATCH_VENDOR_MASK);
> > +}
> > +
>
> broadcom.c: if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
> broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) {
> broadcom.c: if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM57780) {
> broadcom.c: if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
> broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
> broadcom.c: if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54210E ||
> broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54810 ||
> broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54811)
> broadcom.c: if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
> broadcom.c: BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
>
> It looks like there is a use case of phy_id_compare_model(), if you
> feel like adding it.
>
Thanks for pointing this out, I wasn't sure to add a _model() variant as
there wasn't an user for it. I will submit a new series after this gets
merged introducing also this variant.
--
Ansuel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper
2025-08-23 13:44 [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Christian Marangi
2025-08-23 13:44 ` [net-next PATCH v2 2/2] net: phy: as21xxx: better handle PHY HW reset on soft-reboot Christian Marangi
2025-08-24 16:08 ` [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Andrew Lunn
@ 2025-08-27 0:20 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-27 0:20 UTC (permalink / raw)
To: Christian Marangi
Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev,
linux-kernel
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 23 Aug 2025 15:44:28 +0200 you wrote:
> Introduce phy_id_compare_vendor() PHY ID helper to compare a PHY ID with
> the PHY ID Vendor using the generic PHY ID Vendor mask.
>
> While at it also rework the PHY_ID_MATCH macro and move the mask to
> dedicated define so that PHY driver can make use of the mask if needed.
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
>
> [...]
Here is the summary with links:
- [net-next,v2,1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper
https://git.kernel.org/netdev/net-next/c/1abe21ef1adf
- [net-next,v2,2/2] net: phy: as21xxx: better handle PHY HW reset on soft-reboot
https://git.kernel.org/netdev/net-next/c/b4d5cd20507b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-27 0:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-23 13:44 [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Christian Marangi
2025-08-23 13:44 ` [net-next PATCH v2 2/2] net: phy: as21xxx: better handle PHY HW reset on soft-reboot Christian Marangi
2025-08-24 16:08 ` [net-next PATCH v2 1/2] net: phy: introduce phy_id_compare_vendor() PHY ID helper Andrew Lunn
2025-08-24 16:10 ` Christian Marangi
2025-08-27 0:20 ` patchwork-bot+netdevbpf
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).