[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <16b42275-a7c5-4009-8e12-a650fd9ff9e6@engleder-embedded.com>
Date: Fri, 17 Oct 2025 22:51:00 +0200
From: Gerhard Engleder <gerhard@...leder-embedded.com>
To: Heiner Kallweit <hkallweit1@...il.com>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>, imx@...ts.linux.dev,
linux-omap@...r.kernel.org, Andrew Lunn <andrew@...n.ch>,
Andrew Lunn <andrew+netdev@...n.ch>,
Russell King - ARM Linux <linux@...linux.org.uk>,
Paolo Abeni <pabeni@...hat.com>, Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <edumazet@...gle.com>, David Miller <davem@...emloft.net>,
Wei Fang <wei.fang@....com>, Shenwei Wang <shenwei.wang@....com>,
Clark Wang <xiaoning.wang@....com>, Siddharth Vadapalli
<s-vadapalli@...com>, Roger Quadros <rogerq@...nel.org>
Subject: Re: [PATCH net-next 1/4] net: phy: add iterator phy_for_each
On 17.10.25 22:41, Heiner Kallweit wrote:
> Add an iterator for all PHY's on a MII bus, and phy_find_next()
> as a prerequisite.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
> ---
> drivers/net/phy/phy_device.c | 14 +++++++-------
> include/linux/phy.h | 11 ++++++++++-
> 2 files changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 7a67c900e..72d58b38d 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
> @@ -1214,22 +1214,22 @@ 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
> */
> -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..b0497f47b 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 phy_for_each(_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);
Reviewed-by: Gerhard Engleder <gerhard@...leder-embedded.com>
Powered by blists - more mailing lists