Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'net-phy-add-iterator-mdiobus_for_each_phy'

Heiner Kallweit says:

====================
net: phy: add iterator mdiobus_for_each_phy

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

Link: https://patch.msgid.link/07fc63e8-53fd-46aa-853e-96187bba9d44@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+30 -32
+2 -6
drivers/net/ethernet/freescale/fec_main.c
··· 2548 2548 int err = -ENXIO; 2549 2549 u32 mii_speed, holdtime; 2550 2550 u32 bus_freq; 2551 - int addr; 2552 2551 2553 2552 /* 2554 2553 * The i.MX28 dual fec interfaces are not equal. ··· 2662 2663 of_node_put(node); 2663 2664 2664 2665 /* find all the PHY devices on the bus and set mac_managed_pm to true */ 2665 - for (addr = 0; addr < PHY_MAX_ADDR; addr++) { 2666 - phydev = mdiobus_get_phy(fep->mii_bus, addr); 2667 - if (phydev) 2668 - phydev->mac_managed_pm = true; 2669 - } 2666 + mdiobus_for_each_phy(fep->mii_bus, phydev) 2667 + phydev->mac_managed_pm = true; 2670 2668 2671 2669 mii_cnt++; 2672 2670
+5 -9
drivers/net/ethernet/ti/davinci_mdio.c
··· 541 541 struct davinci_mdio_data *data; 542 542 struct resource *res; 543 543 struct phy_device *phy; 544 - int ret, addr; 545 544 int autosuspend_delay_ms = -1; 545 + int ret; 546 546 547 547 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 548 548 if (!data) ··· 645 645 goto bail_out; 646 646 647 647 /* scan and dump the bus */ 648 - for (addr = 0; addr < PHY_MAX_ADDR; addr++) { 649 - phy = mdiobus_get_phy(data->bus, addr); 650 - if (phy) { 651 - dev_info(dev, "phy[%d]: device %s, driver %s\n", 652 - phy->mdio.addr, phydev_name(phy), 653 - phy->drv ? phy->drv->name : "unknown"); 654 - } 655 - } 648 + mdiobus_for_each_phy(data->bus, phy) 649 + dev_info(dev, "phy[%d]: device %s, driver %s\n", 650 + phy->mdio.addr, phydev_name(phy), 651 + phy->drv ? phy->drv->name : "unknown"); 656 652 657 653 return 0; 658 654
+4 -9
drivers/net/phy/mdio_bus_provider.c
··· 249 249 */ 250 250 static bool mdiobus_prevent_c45_scan(struct mii_bus *bus) 251 251 { 252 - int i; 252 + struct phy_device *phydev; 253 253 254 - for (i = 0; i < PHY_MAX_ADDR; i++) { 255 - struct phy_device *phydev; 256 - u32 oui; 257 - 258 - phydev = mdiobus_get_phy(bus, i); 259 - if (!phydev) 260 - continue; 261 - oui = phydev->phy_id >> 10; 254 + mdiobus_for_each_phy(bus, phydev) { 255 + u32 oui = phydev->phy_id >> 10; 262 256 263 257 if (oui == MICREL_OUI) 264 258 return true; 265 259 } 260 + 266 261 return false; 267 262 } 268 263
+9 -7
drivers/net/phy/phy_device.c
··· 1224 1224 EXPORT_SYMBOL(phy_get_c45_ids); 1225 1225 1226 1226 /** 1227 - * phy_find_first - finds the first PHY device on the bus 1227 + * phy_find_next - finds the next PHY device on the bus 1228 1228 * @bus: the target MII bus 1229 + * @pos: cursor 1230 + * 1231 + * Return: next phy_device on the bus, or NULL 1229 1232 */ 1230 - struct phy_device *phy_find_first(struct mii_bus *bus) 1233 + struct phy_device *phy_find_next(struct mii_bus *bus, struct phy_device *pos) 1231 1234 { 1232 - struct phy_device *phydev; 1233 - int addr; 1235 + for (int addr = pos ? pos->mdio.addr + 1 : 0; 1236 + addr < PHY_MAX_ADDR; addr++) { 1237 + struct phy_device *phydev = mdiobus_get_phy(bus, addr); 1234 1238 1235 - for (addr = 0; addr < PHY_MAX_ADDR; addr++) { 1236 - phydev = mdiobus_get_phy(bus, addr); 1237 1239 if (phydev) 1238 1240 return phydev; 1239 1241 } 1240 1242 return NULL; 1241 1243 } 1242 - EXPORT_SYMBOL(phy_find_first); 1244 + EXPORT_SYMBOL_GPL(phy_find_next); 1243 1245 1244 1246 /** 1245 1247 * phy_prepare_link - prepares the PHY layer to monitor link status
+10 -1
include/linux/phy.h
··· 1869 1869 const struct sfp_upstream_ops *ops); 1870 1870 struct phy_device *phy_attach(struct net_device *dev, const char *bus_id, 1871 1871 phy_interface_t interface); 1872 - struct phy_device *phy_find_first(struct mii_bus *bus); 1872 + struct phy_device *phy_find_next(struct mii_bus *bus, struct phy_device *pos); 1873 1873 int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, 1874 1874 u32 flags, phy_interface_t interface); 1875 1875 int phy_connect_direct(struct net_device *dev, struct phy_device *phydev, ··· 1895 1895 1896 1896 int phy_restart_aneg(struct phy_device *phydev); 1897 1897 int phy_reset_after_clk_enable(struct phy_device *phydev); 1898 + 1899 + static inline struct phy_device *phy_find_first(struct mii_bus *bus) 1900 + { 1901 + return phy_find_next(bus, NULL); 1902 + } 1903 + 1904 + #define mdiobus_for_each_phy(_bus, _phydev) \ 1905 + for (_phydev = phy_find_first(_bus); _phydev; \ 1906 + _phydev = phy_find_next(_bus, _phydev)) 1898 1907 1899 1908 #if IS_ENABLED(CONFIG_PHYLIB) 1900 1909 int phy_start_cable_test(struct phy_device *phydev,