public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy
@ 2025-10-25 18:48 Heiner Kallweit
  2025-10-25 18:49 ` [PATCH v3 net-next 1/4] " Heiner Kallweit
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Heiner Kallweit @ 2025-10-25 18:48 UTC (permalink / raw)
  To: Wei Fang, Shenwei Wang, Clark Wang, Siddharth Vadapalli,
	Roger Quadros, Andrew Lunn, Andrew Lunn, Russell King - ARM Linux,
	Paolo Abeni, Jakub Kicinski, Eric Dumazet, David Miller
  Cc: netdev@vger.kernel.org, linux-omap, imx

Add and use an iterator for all PHY's on a MII bus, and phy_find_next()
as a prerequisite.

v2:
- rename iterator to mdiobus_for_each_phy
v3:
- add missing return value description for phy_find_next

Heiner Kallweit (4):
  net: phy: add iterator mdiobus_for_each_phy
  net: fec: use new iterator mdiobus_for_each_phy
  net: davinci_mdio: use new iterator mdiobus_for_each_phy
  net: phy: use new iterator mdiobus_for_each_phy in
    mdiobus_prevent_c45_scan

 drivers/net/ethernet/freescale/fec_main.c |  8 ++------
 drivers/net/ethernet/ti/davinci_mdio.c    | 14 +++++---------
 drivers/net/phy/mdio_bus_provider.c       | 13 ++++---------
 drivers/net/phy/phy_device.c              | 16 +++++++++-------
 include/linux/phy.h                       | 11 ++++++++++-
 5 files changed, 30 insertions(+), 32 deletions(-)

-- 
2.51.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 net-next 1/4] net: phy: add iterator mdiobus_for_each_phy
  2025-10-25 18:48 [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy Heiner Kallweit
@ 2025-10-25 18:49 ` Heiner Kallweit
  2025-10-27  1:42   ` Wei Fang
  2025-10-25 18:50 ` [PATCH v3 net-next 2/4] net: fec: use new " Heiner Kallweit
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Heiner Kallweit @ 2025-10-25 18:49 UTC (permalink / raw)
  To: Wei Fang, Shenwei Wang, Clark Wang, Siddharth Vadapalli,
	Roger Quadros, Andrew Lunn, Andrew Lunn, Russell King - ARM Linux,
	Paolo Abeni, Jakub Kicinski, Eric Dumazet, David Miller
  Cc: netdev@vger.kernel.org, linux-omap, imx

Add an iterator for all PHY's on a MII bus, and phy_find_next()
as a prerequisite.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
v3:
- add missing return value description for phy_find_next
---
 drivers/net/phy/phy_device.c | 16 +++++++++-------
 include/linux/phy.h          | 11 ++++++++++-
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 7a67c900e..c4fbacbc3 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1214,22 +1214,24 @@ int phy_get_c45_ids(struct phy_device *phydev)
 EXPORT_SYMBOL(phy_get_c45_ids);
 
 /**
- * phy_find_first - finds the first PHY device on the bus
+ * phy_find_next - finds the next PHY device on the bus
  * @bus: the target MII bus
+ * @pos: cursor
+ *
+ * Return: next phy_device on the bus, or NULL
  */
-struct phy_device *phy_find_first(struct mii_bus *bus)
+struct phy_device *phy_find_next(struct mii_bus *bus, struct phy_device *pos)
 {
-	struct phy_device *phydev;
-	int addr;
+	for (int addr = pos ? pos->mdio.addr + 1 : 0;
+	     addr < PHY_MAX_ADDR; addr++) {
+		struct phy_device *phydev = mdiobus_get_phy(bus, addr);
 
-	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
-		phydev = mdiobus_get_phy(bus, addr);
 		if (phydev)
 			return phydev;
 	}
 	return NULL;
 }
-EXPORT_SYMBOL(phy_find_first);
+EXPORT_SYMBOL_GPL(phy_find_next);
 
 /**
  * phy_prepare_link - prepares the PHY layer to monitor link status
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 3c7634482..3809ca705 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1848,7 +1848,7 @@ int phy_sfp_probe(struct phy_device *phydev,
 	          const struct sfp_upstream_ops *ops);
 struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
 			      phy_interface_t interface);
-struct phy_device *phy_find_first(struct mii_bus *bus);
+struct phy_device *phy_find_next(struct mii_bus *bus, struct phy_device *pos);
 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 		      u32 flags, phy_interface_t interface);
 int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
@@ -1875,6 +1875,15 @@ bool phy_check_valid(int speed, int duplex, unsigned long *features);
 int phy_restart_aneg(struct phy_device *phydev);
 int phy_reset_after_clk_enable(struct phy_device *phydev);
 
+static inline struct phy_device *phy_find_first(struct mii_bus *bus)
+{
+	return phy_find_next(bus, NULL);
+}
+
+#define mdiobus_for_each_phy(_bus, _phydev)		\
+	for (_phydev = phy_find_first(_bus); _phydev;	\
+	     _phydev = phy_find_next(_bus, _phydev))
+
 #if IS_ENABLED(CONFIG_PHYLIB)
 int phy_start_cable_test(struct phy_device *phydev,
 			 struct netlink_ext_ack *extack);
-- 
2.51.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 net-next 2/4] net: fec: use new iterator mdiobus_for_each_phy
  2025-10-25 18:48 [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy Heiner Kallweit
  2025-10-25 18:49 ` [PATCH v3 net-next 1/4] " Heiner Kallweit
@ 2025-10-25 18:50 ` Heiner Kallweit
  2025-10-27  1:43   ` Wei Fang
  2025-10-25 18:52 ` [PATCH v3 net-next 3/4] net: davinci_mdio: " Heiner Kallweit
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Heiner Kallweit @ 2025-10-25 18:50 UTC (permalink / raw)
  To: Wei Fang, Shenwei Wang, Clark Wang, Siddharth Vadapalli,
	Roger Quadros, Andrew Lunn, Andrew Lunn, Russell King - ARM Linux,
	Paolo Abeni, Jakub Kicinski, Eric Dumazet, David Miller
  Cc: netdev@vger.kernel.org, linux-omap, imx

Use new iterator mdiobus_for_each_phy() to simplify the code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/ethernet/freescale/fec_main.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 1edcfaee6..c60ed8bac 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -2552,7 +2552,6 @@ static int fec_enet_mii_init(struct platform_device *pdev)
 	int err = -ENXIO;
 	u32 mii_speed, holdtime;
 	u32 bus_freq;
-	int addr;
 
 	/*
 	 * The i.MX28 dual fec interfaces are not equal.
@@ -2667,11 +2666,8 @@ static int fec_enet_mii_init(struct platform_device *pdev)
 	of_node_put(node);
 
 	/* find all the PHY devices on the bus and set mac_managed_pm to true */
-	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
-		phydev = mdiobus_get_phy(fep->mii_bus, addr);
-		if (phydev)
-			phydev->mac_managed_pm = true;
-	}
+	mdiobus_for_each_phy(fep->mii_bus, phydev)
+		phydev->mac_managed_pm = true;
 
 	mii_cnt++;
 
-- 
2.51.1




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 net-next 3/4] net: davinci_mdio: use new iterator mdiobus_for_each_phy
  2025-10-25 18:48 [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy Heiner Kallweit
  2025-10-25 18:49 ` [PATCH v3 net-next 1/4] " Heiner Kallweit
  2025-10-25 18:50 ` [PATCH v3 net-next 2/4] net: fec: use new " Heiner Kallweit
@ 2025-10-25 18:52 ` Heiner Kallweit
  2025-10-25 18:52 ` [PATCH v3 net-next 4/4] net: phy: use new iterator mdiobus_for_each_phy in mdiobus_prevent_c45_scan Heiner Kallweit
  2025-10-30  2:10 ` [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy patchwork-bot+netdevbpf
  4 siblings, 0 replies; 8+ messages in thread
From: Heiner Kallweit @ 2025-10-25 18:52 UTC (permalink / raw)
  To: Wei Fang, Shenwei Wang, Clark Wang, Siddharth Vadapalli,
	Roger Quadros, Andrew Lunn, Andrew Lunn, Russell King - ARM Linux,
	Paolo Abeni, Jakub Kicinski, Eric Dumazet, David Miller
  Cc: netdev@vger.kernel.org, linux-omap, imx

Use new iterator mdiobus_for_each_phy() to simplify the code.

Reviewed-by: Siddharth Vadapalli <s-vadapalli@ti.com>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/ethernet/ti/davinci_mdio.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/ti/davinci_mdio.c b/drivers/net/ethernet/ti/davinci_mdio.c
index 68507126b..713ed4ef6 100644
--- a/drivers/net/ethernet/ti/davinci_mdio.c
+++ b/drivers/net/ethernet/ti/davinci_mdio.c
@@ -548,8 +548,8 @@ static int davinci_mdio_probe(struct platform_device *pdev)
 	struct davinci_mdio_data *data;
 	struct resource *res;
 	struct phy_device *phy;
-	int ret, addr;
 	int autosuspend_delay_ms = -1;
+	int ret;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -652,14 +652,10 @@ static int davinci_mdio_probe(struct platform_device *pdev)
 		goto bail_out;
 
 	/* scan and dump the bus */
-	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
-		phy = mdiobus_get_phy(data->bus, addr);
-		if (phy) {
-			dev_info(dev, "phy[%d]: device %s, driver %s\n",
-				 phy->mdio.addr, phydev_name(phy),
-				 phy->drv ? phy->drv->name : "unknown");
-		}
-	}
+	mdiobus_for_each_phy(data->bus, phy)
+		dev_info(dev, "phy[%d]: device %s, driver %s\n",
+			 phy->mdio.addr, phydev_name(phy),
+			 phy->drv ? phy->drv->name : "unknown");
 
 	return 0;
 
-- 
2.51.1




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 net-next 4/4] net: phy: use new iterator mdiobus_for_each_phy in mdiobus_prevent_c45_scan
  2025-10-25 18:48 [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy Heiner Kallweit
                   ` (2 preceding siblings ...)
  2025-10-25 18:52 ` [PATCH v3 net-next 3/4] net: davinci_mdio: " Heiner Kallweit
@ 2025-10-25 18:52 ` Heiner Kallweit
  2025-10-30  2:10 ` [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy patchwork-bot+netdevbpf
  4 siblings, 0 replies; 8+ messages in thread
From: Heiner Kallweit @ 2025-10-25 18:52 UTC (permalink / raw)
  To: Wei Fang, Shenwei Wang, Clark Wang, Siddharth Vadapalli,
	Roger Quadros, Andrew Lunn, Andrew Lunn, Russell King - ARM Linux,
	Paolo Abeni, Jakub Kicinski, Eric Dumazet, David Miller
  Cc: netdev@vger.kernel.org, linux-omap, imx

Use new iterator mdiobus_for_each_phy() to simplify the code.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/phy/mdio_bus_provider.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/net/phy/mdio_bus_provider.c b/drivers/net/phy/mdio_bus_provider.c
index a2391d4b7..4b0637405 100644
--- a/drivers/net/phy/mdio_bus_provider.c
+++ b/drivers/net/phy/mdio_bus_provider.c
@@ -249,20 +249,15 @@ static int mdiobus_scan_bus_c45(struct mii_bus *bus)
  */
 static bool mdiobus_prevent_c45_scan(struct mii_bus *bus)
 {
-	int i;
+	struct phy_device *phydev;
 
-	for (i = 0; i < PHY_MAX_ADDR; i++) {
-		struct phy_device *phydev;
-		u32 oui;
-
-		phydev = mdiobus_get_phy(bus, i);
-		if (!phydev)
-			continue;
-		oui = phydev->phy_id >> 10;
+	mdiobus_for_each_phy(bus, phydev) {
+		u32 oui = phydev->phy_id >> 10;
 
 		if (oui == MICREL_OUI)
 			return true;
 	}
+
 	return false;
 }
 
-- 
2.51.1




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH v3 net-next 1/4] net: phy: add iterator mdiobus_for_each_phy
  2025-10-25 18:49 ` [PATCH v3 net-next 1/4] " Heiner Kallweit
@ 2025-10-27  1:42   ` Wei Fang
  0 siblings, 0 replies; 8+ messages in thread
From: Wei Fang @ 2025-10-27  1:42 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Shenwei Wang, Clark Wang, Siddharth Vadapalli, Roger Quadros,
	Andrew Lunn, Andrew Lunn, Russell King - ARM Linux, Paolo Abeni,
	Jakub Kicinski, Eric Dumazet, David Miller,
	netdev@vger.kernel.org, linux-omap@vger.kernel.org,
	imx@lists.linux.dev

> Add an iterator for all PHY's on a MII bus, and phy_find_next()
> as a prerequisite.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> v3:
> - add missing return value description for phy_find_next
> ---
>  drivers/net/phy/phy_device.c | 16 +++++++++-------
>  include/linux/phy.h          | 11 ++++++++++-
>  2 files changed, 19 insertions(+), 8 deletions(-)

Reviewed-by: Wei Fang <wei.fang@nxp.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH v3 net-next 2/4] net: fec: use new iterator mdiobus_for_each_phy
  2025-10-25 18:50 ` [PATCH v3 net-next 2/4] net: fec: use new " Heiner Kallweit
@ 2025-10-27  1:43   ` Wei Fang
  0 siblings, 0 replies; 8+ messages in thread
From: Wei Fang @ 2025-10-27  1:43 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: netdev@vger.kernel.org, linux-omap@vger.kernel.org,
	imx@lists.linux.dev, Shenwei Wang, Clark Wang,
	Siddharth Vadapalli, Roger Quadros, Andrew Lunn, Andrew Lunn,
	Russell King - ARM Linux, Paolo Abeni, Jakub Kicinski,
	Eric Dumazet, David Miller

> Use new iterator mdiobus_for_each_phy() to simplify the code.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/ethernet/freescale/fec_main.c | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/freescale/fec_main.c
> b/drivers/net/ethernet/freescale/fec_main.c
> index 1edcfaee6..c60ed8bac 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
> @@ -2552,7 +2552,6 @@ static int fec_enet_mii_init(struct platform_device
> *pdev)
>  	int err = -ENXIO;
>  	u32 mii_speed, holdtime;
>  	u32 bus_freq;
> -	int addr;
> 
>  	/*
>  	 * The i.MX28 dual fec interfaces are not equal.
> @@ -2667,11 +2666,8 @@ static int fec_enet_mii_init(struct platform_device
> *pdev)
>  	of_node_put(node);
> 
>  	/* find all the PHY devices on the bus and set mac_managed_pm to true */
> -	for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
> -		phydev = mdiobus_get_phy(fep->mii_bus, addr);
> -		if (phydev)
> -			phydev->mac_managed_pm = true;
> -	}
> +	mdiobus_for_each_phy(fep->mii_bus, phydev)
> +		phydev->mac_managed_pm = true;
> 
>  	mii_cnt++;
> 
> --
> 2.51.1
> 
> 

Reviewed-by: Wei Fang <wei.fang@nxp.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy
  2025-10-25 18:48 [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy Heiner Kallweit
                   ` (3 preceding siblings ...)
  2025-10-25 18:52 ` [PATCH v3 net-next 4/4] net: phy: use new iterator mdiobus_for_each_phy in mdiobus_prevent_c45_scan Heiner Kallweit
@ 2025-10-30  2:10 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 8+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-10-30  2:10 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: wei.fang, shenwei.wang, xiaoning.wang, s-vadapalli, rogerq,
	andrew, andrew+netdev, linux, pabeni, kuba, edumazet, davem,
	netdev, linux-omap, imx

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sat, 25 Oct 2025 20:48:20 +0200 you wrote:
> Add and use an iterator for all PHY's on a MII bus, and phy_find_next()
> as a prerequisite.
> 
> v2:
> - rename iterator to mdiobus_for_each_phy
> v3:
> - add missing return value description for phy_find_next
> 
> [...]

Here is the summary with links:
  - [v3,net-next,1/4] net: phy: add iterator mdiobus_for_each_phy
    https://git.kernel.org/netdev/net-next/c/26888de97b2f
  - [v3,net-next,2/4] net: fec: use new iterator mdiobus_for_each_phy
    https://git.kernel.org/netdev/net-next/c/0514010d553a
  - [v3,net-next,3/4] net: davinci_mdio: use new iterator mdiobus_for_each_phy
    https://git.kernel.org/netdev/net-next/c/4575875065de
  - [v3,net-next,4/4] net: phy: use new iterator mdiobus_for_each_phy in mdiobus_prevent_c45_scan
    https://git.kernel.org/netdev/net-next/c/d4780abb8cce

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] 8+ messages in thread

end of thread, other threads:[~2025-10-30  2:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-25 18:48 [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy Heiner Kallweit
2025-10-25 18:49 ` [PATCH v3 net-next 1/4] " Heiner Kallweit
2025-10-27  1:42   ` Wei Fang
2025-10-25 18:50 ` [PATCH v3 net-next 2/4] net: fec: use new " Heiner Kallweit
2025-10-27  1:43   ` Wei Fang
2025-10-25 18:52 ` [PATCH v3 net-next 3/4] net: davinci_mdio: " Heiner Kallweit
2025-10-25 18:52 ` [PATCH v3 net-next 4/4] net: phy: use new iterator mdiobus_for_each_phy in mdiobus_prevent_c45_scan Heiner Kallweit
2025-10-30  2:10 ` [PATCH v3 net-next 0/4] net: phy: add iterator mdiobus_for_each_phy 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