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

Merge branch 'net-phy-remove-fixed_phy_add-and-first-its-users'

Heiner Kallweit says:

====================
net: phy: remove fixed_phy_add and first its users

fixed_phy_add() has a number of problems/disadvantages:
- It uses phy address 0 w/o checking whether a fixed phy with this
address exists already.
- A subsequent call to fixed_phy_register() would also use phy address 0,
because fixed_phy_add() doesn't mark it as used.
- fixed_phy_add() is used from platform code, therefore requires that
fixed phy code is built-in.

fixed_phy_add() has only two users
- coldfire/5272, using fec
- bcm47xx, using b44

So migrate fec and b44 to use fixed_phy_register_100fd(), afterwards
remove usage of fixed_phy_add() from the two platforms, and eventually
remove fixed_phy_add().
====================

Link: https://patch.msgid.link/0285fcb0-0fb5-4f6f-823c-7b6e85e28ba3@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+66 -73
-15
arch/m68k/coldfire/m5272.c
··· 16 16 #include <linux/init.h> 17 17 #include <linux/io.h> 18 18 #include <linux/phy.h> 19 - #include <linux/phy_fixed.h> 20 19 #include <asm/machdep.h> 21 20 #include <asm/coldfire.h> 22 21 #include <asm/mcfsim.h> ··· 102 103 103 104 /***************************************************************************/ 104 105 105 - /* 106 - * Some 5272 based boards have the FEC ethernet directly connected to 107 - * an ethernet switch. In this case we need to use the fixed phy type, 108 - * and we need to declare it early in boot. 109 - */ 110 - static const struct fixed_phy_status nettel_fixed_phy_status __initconst = { 111 - .link = 1, 112 - .speed = 100, 113 - .duplex = 0, 114 - }; 115 - 116 - /***************************************************************************/ 117 - 118 106 static int __init init_BSP(void) 119 107 { 120 108 m5272_uarts_init(); 121 - fixed_phy_add(&nettel_fixed_phy_status); 122 109 clkdev_add_table(m5272_clk_lookup, ARRAY_SIZE(m5272_clk_lookup)); 123 110 return 0; 124 111 }
-7
arch/mips/bcm47xx/setup.c
··· 256 256 } 257 257 arch_initcall(bcm47xx_cpu_fixes); 258 258 259 - static const struct fixed_phy_status bcm47xx_fixed_phy_status __initconst = { 260 - .link = 1, 261 - .speed = SPEED_100, 262 - .duplex = DUPLEX_FULL, 263 - }; 264 - 265 259 static int __init bcm47xx_register_bus_complete(void) 266 260 { 267 261 switch (bcm47xx_bus_type) { ··· 276 282 bcm47xx_leds_register(); 277 283 bcm47xx_workarounds(); 278 284 279 - fixed_phy_add(&bcm47xx_fixed_phy_status); 280 285 return 0; 281 286 } 282 287 device_initcall(bcm47xx_register_bus_complete);
+1
drivers/net/ethernet/broadcom/Kconfig
··· 25 25 select SSB 26 26 select MII 27 27 select PHYLIB 28 + select FIXED_PHY if BCM47XX 28 29 help 29 30 If you have a network (Ethernet) controller of this type, say Y 30 31 or M here.
+20 -17
drivers/net/ethernet/broadcom/b44.c
··· 31 31 #include <linux/ssb/ssb.h> 32 32 #include <linux/slab.h> 33 33 #include <linux/phy.h> 34 + #include <linux/phy_fixed.h> 34 35 35 36 #include <linux/uaccess.h> 36 37 #include <asm/io.h> ··· 2234 2233 struct mii_bus *mii_bus; 2235 2234 struct ssb_device *sdev = bp->sdev; 2236 2235 struct phy_device *phydev; 2237 - char bus_id[MII_BUS_ID_SIZE + 3]; 2238 2236 struct ssb_sprom *sprom = &sdev->bus->sprom; 2239 2237 int err; 2240 2238 ··· 2260 2260 goto err_out_mdiobus; 2261 2261 } 2262 2262 2263 - if (!mdiobus_is_registered_device(bp->mii_bus, bp->phy_addr) && 2264 - (sprom->boardflags_lo & (B44_BOARDFLAG_ROBO | B44_BOARDFLAG_ADM))) { 2265 - 2263 + phydev = mdiobus_get_phy(bp->mii_bus, bp->phy_addr); 2264 + if (!phydev && 2265 + sprom->boardflags_lo & (B44_BOARDFLAG_ROBO | B44_BOARDFLAG_ADM)) { 2266 2266 dev_info(sdev->dev, 2267 2267 "could not find PHY at %i, use fixed one\n", 2268 2268 bp->phy_addr); 2269 2269 2270 - bp->phy_addr = 0; 2271 - snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, "fixed-0", 2272 - bp->phy_addr); 2273 - } else { 2274 - snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, mii_bus->id, 2275 - bp->phy_addr); 2270 + phydev = fixed_phy_register_100fd(); 2271 + if (!IS_ERR(phydev)) 2272 + bp->phy_addr = phydev->mdio.addr; 2276 2273 } 2277 2274 2278 - phydev = phy_connect(bp->dev, bus_id, &b44_adjust_link, 2279 - PHY_INTERFACE_MODE_MII); 2280 - if (IS_ERR(phydev)) { 2275 + if (IS_ERR_OR_NULL(phydev)) 2276 + err = -ENODEV; 2277 + else 2278 + err = phy_connect_direct(bp->dev, phydev, &b44_adjust_link, 2279 + PHY_INTERFACE_MODE_MII); 2280 + if (err) { 2281 2281 dev_err(sdev->dev, "could not attach PHY at %i\n", 2282 2282 bp->phy_addr); 2283 - err = PTR_ERR(phydev); 2284 2283 goto err_out_mdiobus_unregister; 2285 2284 } 2286 2285 ··· 2292 2293 linkmode_copy(phydev->advertising, phydev->supported); 2293 2294 2294 2295 bp->old_link = 0; 2295 - bp->phy_addr = phydev->mdio.addr; 2296 2296 2297 2297 phy_attached_info(phydev); 2298 2298 ··· 2309 2311 2310 2312 static void b44_unregister_phy_one(struct b44 *bp) 2311 2313 { 2312 - struct net_device *dev = bp->dev; 2313 2314 struct mii_bus *mii_bus = bp->mii_bus; 2315 + struct net_device *dev = bp->dev; 2316 + struct phy_device *phydev; 2314 2317 2315 - phy_disconnect(dev->phydev); 2318 + phydev = dev->phydev; 2319 + 2320 + phy_disconnect(phydev); 2321 + if (phy_is_pseudo_fixed_link(phydev)) 2322 + fixed_phy_unregister(phydev); 2316 2323 mdiobus_unregister(mii_bus); 2317 2324 mdiobus_free(mii_bus); 2318 2325 }
+1
drivers/net/ethernet/freescale/Kconfig
··· 28 28 depends on PTP_1588_CLOCK_OPTIONAL 29 29 select CRC32 30 30 select PHYLIB 31 + select FIXED_PHY if M5272 31 32 select PAGE_POOL 32 33 imply PAGE_POOL_STATS 33 34 imply NET_SELFTESTS
+26 -26
drivers/net/ethernet/freescale/fec_main.c
··· 52 52 #include <linux/of_net.h> 53 53 #include <linux/phy.h> 54 54 #include <linux/pinctrl/consumer.h> 55 + #include <linux/phy_fixed.h> 55 56 #include <linux/platform_device.h> 56 57 #include <linux/pm_runtime.h> 57 58 #include <linux/prefetch.h> ··· 2473 2472 static int fec_enet_mii_probe(struct net_device *ndev) 2474 2473 { 2475 2474 struct fec_enet_private *fep = netdev_priv(ndev); 2476 - struct phy_device *phy_dev = NULL; 2477 - char mdio_bus_id[MII_BUS_ID_SIZE]; 2478 - char phy_name[MII_BUS_ID_SIZE + 3]; 2479 - int phy_id; 2480 - int dev_id = fep->dev_id; 2475 + struct phy_device *phy_dev; 2476 + int ret; 2481 2477 2482 2478 if (fep->phy_node) { 2483 2479 phy_dev = of_phy_connect(ndev, fep->phy_node, ··· 2486 2488 } 2487 2489 } else { 2488 2490 /* check for attached phy */ 2489 - for (phy_id = 0; (phy_id < PHY_MAX_ADDR); phy_id++) { 2490 - if (!mdiobus_is_registered_device(fep->mii_bus, phy_id)) 2491 - continue; 2492 - if (dev_id--) 2493 - continue; 2494 - strscpy(mdio_bus_id, fep->mii_bus->id, MII_BUS_ID_SIZE); 2495 - break; 2496 - } 2491 + phy_dev = phy_find_first(fep->mii_bus); 2492 + if (fep->dev_id && phy_dev) 2493 + phy_dev = phy_find_next(fep->mii_bus, phy_dev); 2497 2494 2498 - if (phy_id >= PHY_MAX_ADDR) { 2495 + if (!phy_dev) { 2499 2496 netdev_info(ndev, "no PHY, assuming direct connection to switch\n"); 2500 - strscpy(mdio_bus_id, "fixed-0", MII_BUS_ID_SIZE); 2501 - phy_id = 0; 2497 + phy_dev = fixed_phy_register_100fd(); 2498 + if (IS_ERR(phy_dev)) { 2499 + netdev_err(ndev, "could not register fixed PHY\n"); 2500 + return PTR_ERR(phy_dev); 2501 + } 2502 2502 } 2503 2503 2504 - snprintf(phy_name, sizeof(phy_name), 2505 - PHY_ID_FMT, mdio_bus_id, phy_id); 2506 - phy_dev = phy_connect(ndev, phy_name, &fec_enet_adjust_link, 2507 - fep->phy_interface); 2508 - } 2504 + ret = phy_connect_direct(ndev, phy_dev, &fec_enet_adjust_link, 2505 + fep->phy_interface); 2506 + if (ret) { 2507 + if (phy_is_pseudo_fixed_link(phy_dev)) 2508 + fixed_phy_unregister(phy_dev); 2509 + netdev_err(ndev, "could not attach to PHY\n"); 2510 + return ret; 2511 + } 2509 2512 2510 - if (IS_ERR(phy_dev)) { 2511 - netdev_err(ndev, "could not attach to PHY\n"); 2512 - return PTR_ERR(phy_dev); 2513 2513 } 2514 2514 2515 2515 /* mask with MAC supported features */ ··· 3612 3616 fec_enet_close(struct net_device *ndev) 3613 3617 { 3614 3618 struct fec_enet_private *fep = netdev_priv(ndev); 3619 + struct phy_device *phy_dev = ndev->phydev; 3615 3620 3616 - phy_stop(ndev->phydev); 3621 + phy_stop(phy_dev); 3617 3622 3618 3623 if (netif_device_present(ndev)) { 3619 3624 napi_disable(&fep->napi); ··· 3622 3625 fec_stop(ndev); 3623 3626 } 3624 3627 3625 - phy_disconnect(ndev->phydev); 3628 + phy_disconnect(phy_dev); 3629 + 3630 + if (!fep->phy_node && phy_is_pseudo_fixed_link(phy_dev)) 3631 + fixed_phy_unregister(phy_dev); 3626 3632 3627 3633 if (fep->quirks & FEC_QUIRK_ERR006687) 3628 3634 imx6q_cpuidle_fec_irqs_unused();
+12 -6
drivers/net/phy/fixed_phy.c
··· 131 131 return 0; 132 132 } 133 133 134 - void fixed_phy_add(const struct fixed_phy_status *status) 135 - { 136 - __fixed_phy_add(0, status); 137 - } 138 - EXPORT_SYMBOL_GPL(fixed_phy_add); 139 - 140 134 static DEFINE_IDA(phy_fixed_ida); 141 135 142 136 static void fixed_phy_del(int phy_addr) ··· 220 226 return phy; 221 227 } 222 228 EXPORT_SYMBOL_GPL(fixed_phy_register); 229 + 230 + struct phy_device *fixed_phy_register_100fd(void) 231 + { 232 + static const struct fixed_phy_status status = { 233 + .link = 1, 234 + .speed = SPEED_100, 235 + .duplex = DUPLEX_FULL, 236 + }; 237 + 238 + return fixed_phy_register(&status, NULL); 239 + } 240 + EXPORT_SYMBOL_GPL(fixed_phy_register_100fd); 223 241 224 242 void fixed_phy_unregister(struct phy_device *phy) 225 243 {
+6 -2
include/linux/phy_fixed.h
··· 17 17 18 18 #if IS_ENABLED(CONFIG_FIXED_PHY) 19 19 extern int fixed_phy_change_carrier(struct net_device *dev, bool new_carrier); 20 - void fixed_phy_add(const struct fixed_phy_status *status); 21 20 struct phy_device *fixed_phy_register(const struct fixed_phy_status *status, 22 21 struct device_node *np); 22 + struct phy_device *fixed_phy_register_100fd(void); 23 23 24 24 extern void fixed_phy_unregister(struct phy_device *phydev); 25 25 extern int fixed_phy_set_link_update(struct phy_device *phydev, 26 26 int (*link_update)(struct net_device *, 27 27 struct fixed_phy_status *)); 28 28 #else 29 - static inline void fixed_phy_add(const struct fixed_phy_status *status) {} 30 29 static inline struct phy_device * 31 30 fixed_phy_register(const struct fixed_phy_status *status, 32 31 struct device_node *np) 32 + { 33 + return ERR_PTR(-ENODEV); 34 + } 35 + 36 + static inline struct phy_device *fixed_phy_register_100fd(void) 33 37 { 34 38 return ERR_PTR(-ENODEV); 35 39 }