Lines Matching +full:ethernet +full:- +full:pse
1 // SPDX-License-Identifier: GPL-2.0+
29 #include <linux/pse-pd/pse.h>
206 put_device(&phydev->mdio.dev); in phy_device_free()
220 fwnode_handle_put(dev->fwnode); in phy_device_release()
239 struct device_driver *drv = phydev->mdio.dev.driver; in mdio_bus_phy_may_suspend()
241 struct net_device *netdev = phydev->attached_dev; in mdio_bus_phy_may_suspend()
243 if (!drv || !phydrv->suspend) in mdio_bus_phy_may_suspend()
247 * suspended as part of a prior call to phy_disconnect() -> in mdio_bus_phy_may_suspend()
248 * phy_detach() -> phy_suspend() because the parent netdev might be the in mdio_bus_phy_may_suspend()
254 if (netdev->wol_enabled) in mdio_bus_phy_may_suspend()
262 if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent)) in mdio_bus_phy_may_suspend()
269 if (device_may_wakeup(&netdev->dev)) in mdio_bus_phy_may_suspend()
273 return !phydev->suspended; in mdio_bus_phy_may_suspend()
280 if (phydev->mac_managed_pm) in mdio_bus_phy_suspend()
288 phydev->irq_suspended = 1; in mdio_bus_phy_suspend()
289 synchronize_irq(phydev->irq); in mdio_bus_phy_suspend()
293 * control, possibly with the phydev->lock held. Upon resume, netdev in mdio_bus_phy_suspend()
297 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_suspend()
303 phydev->suspended_by_mdio_bus = 1; in mdio_bus_phy_suspend()
313 if (phydev->mac_managed_pm) in mdio_bus_phy_resume()
316 if (!phydev->suspended_by_mdio_bus) in mdio_bus_phy_resume()
319 phydev->suspended_by_mdio_bus = 0; in mdio_bus_phy_resume()
326 WARN_ON(phydev->state != PHY_HALTED && phydev->state != PHY_READY && in mdio_bus_phy_resume()
327 phydev->state != PHY_UP); in mdio_bus_phy_resume()
338 phydev->irq_suspended = 0; in mdio_bus_phy_resume()
339 synchronize_irq(phydev->irq); in mdio_bus_phy_resume()
344 if (phydev->irq_rerun) { in mdio_bus_phy_resume()
345 phydev->irq_rerun = 0; in mdio_bus_phy_resume()
346 enable_irq(phydev->irq); in mdio_bus_phy_resume()
347 irq_wake_thread(phydev->irq, phydev); in mdio_bus_phy_resume()
351 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_resume()
361 * phy_register_fixup - creates a new phy_fixup and adds it to the list
362 * @bus_id: A string which matches phydev->mdio.dev.bus_id (or PHY_ANY_ID)
363 * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY)
365 * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before
375 return -ENOMEM; in phy_register_fixup()
377 strscpy(fixup->bus_id, bus_id, sizeof(fixup->bus_id)); in phy_register_fixup()
378 fixup->phy_uid = phy_uid; in phy_register_fixup()
379 fixup->phy_uid_mask = phy_uid_mask; in phy_register_fixup()
380 fixup->run = run; in phy_register_fixup()
383 list_add_tail(&fixup->list, &phy_fixup_list); in phy_register_fixup()
407 * phy_unregister_fixup - remove a phy_fixup from the list
408 * @bus_id: A string matches fixup->bus_id (or PHY_ANY_ID) in phy_fixup_list
409 * @phy_uid: A phy id matches fixup->phy_id (or PHY_ANY_UID) in phy_fixup_list
410 * @phy_uid_mask: Applied to phy_uid and fixup->phy_uid before comparison
418 ret = -ENODEV; in phy_unregister_fixup()
424 if ((!strcmp(fixup->bus_id, bus_id)) && in phy_unregister_fixup()
425 ((fixup->phy_uid & phy_uid_mask) == in phy_unregister_fixup()
427 list_del(&fixup->list); in phy_unregister_fixup()
458 if (strcmp(fixup->bus_id, phydev_name(phydev)) != 0) in phy_needs_fixup()
459 if (strcmp(fixup->bus_id, PHY_ANY_ID) != 0) in phy_needs_fixup()
462 if ((fixup->phy_uid & fixup->phy_uid_mask) != in phy_needs_fixup()
463 (phydev->phy_id & fixup->phy_uid_mask)) in phy_needs_fixup()
464 if (fixup->phy_uid != PHY_ANY_UID) in phy_needs_fixup()
478 int err = fixup->run(phydev); in phy_scan_fixups()
484 phydev->has_fixups = true; in phy_scan_fixups()
496 const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids); in phy_bus_match()
499 if (!(phydrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY)) in phy_bus_match()
502 if (phydrv->match_phy_device) in phy_bus_match()
503 return phydrv->match_phy_device(phydev); in phy_bus_match()
505 if (phydev->is_c45) { in phy_bus_match()
507 if (phydev->c45_ids.device_ids[i] == 0xffffffff) in phy_bus_match()
510 if ((phydrv->phy_id & phydrv->phy_id_mask) == in phy_bus_match()
511 (phydev->c45_ids.device_ids[i] & in phy_bus_match()
512 phydrv->phy_id_mask)) in phy_bus_match()
517 return (phydrv->phy_id & phydrv->phy_id_mask) == in phy_bus_match()
518 (phydev->phy_id & phydrv->phy_id_mask); in phy_bus_match()
527 return sysfs_emit(buf, "0x%.8lx\n", (unsigned long)phydev->phy_id); in phy_id_show()
540 mode = phy_modes(phydev->interface); in phy_interface_show()
552 return sysfs_emit(buf, "%d\n", phydev->has_fixups); in phy_has_fixups_show()
562 return sysfs_emit(buf, "0x%08x\n", phydev->dev_flags); in phy_dev_flags_show()
590 * Accept -ENOENT because this may occur in case no initramfs exists, in phy_request_driver_module()
593 if (IS_ENABLED(CONFIG_MODULES) && ret < 0 && ret != -ENOENT) { in phy_request_driver_module()
613 return ERR_PTR(-ENOMEM); in phy_device_create()
615 mdiodev = &dev->mdio; in phy_device_create()
616 mdiodev->dev.parent = &bus->dev; in phy_device_create()
617 mdiodev->dev.bus = &mdio_bus_type; in phy_device_create()
618 mdiodev->dev.type = &mdio_bus_phy_type; in phy_device_create()
619 mdiodev->bus = bus; in phy_device_create()
620 mdiodev->bus_match = phy_bus_match; in phy_device_create()
621 mdiodev->addr = addr; in phy_device_create()
622 mdiodev->flags = MDIO_DEVICE_FLAG_PHY; in phy_device_create()
623 mdiodev->device_free = phy_mdio_device_free; in phy_device_create()
624 mdiodev->device_remove = phy_mdio_device_remove; in phy_device_create()
626 dev->speed = SPEED_UNKNOWN; in phy_device_create()
627 dev->duplex = DUPLEX_UNKNOWN; in phy_device_create()
628 dev->pause = 0; in phy_device_create()
629 dev->asym_pause = 0; in phy_device_create()
630 dev->link = 0; in phy_device_create()
631 dev->port = PORT_TP; in phy_device_create()
632 dev->interface = PHY_INTERFACE_MODE_GMII; in phy_device_create()
634 dev->autoneg = AUTONEG_ENABLE; in phy_device_create()
636 dev->pma_extable = -ENODATA; in phy_device_create()
637 dev->is_c45 = is_c45; in phy_device_create()
638 dev->phy_id = phy_id; in phy_device_create()
640 dev->c45_ids = *c45_ids; in phy_device_create()
641 dev->irq = bus->irq[addr]; in phy_device_create()
643 dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr); in phy_device_create()
644 device_initialize(&mdiodev->dev); in phy_device_create()
646 dev->state = PHY_DOWN; in phy_device_create()
648 mutex_init(&dev->lock); in phy_device_create()
649 INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); in phy_device_create()
656 * -- because it relies on the device staying around for long in phy_device_create()
662 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in phy_device_create()
666 if (c45_ids->device_ids[i] == 0xffffffff) in phy_device_create()
670 c45_ids->device_ids[i]); in phy_device_create()
679 put_device(&mdiodev->dev); in phy_device_create()
687 /* phy_c45_probe_present - checks to see if a MMD is present in the package
709 /* get_phy_c45_devs_in_pkg - reads a MMD's devices in package registers.
718 * Returns: 0 on success, -EIO on failure.
727 return -EIO; in get_phy_c45_devs_in_pkg()
732 return -EIO; in get_phy_c45_devs_in_pkg()
739 * get_phy_c45_ids - reads the specified addr for its 802.3-c45 IDs.
748 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
754 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in get_phy_c45_ids()
758 /* Find first non-zero Devices In package. Device zero is reserved in get_phy_c45_ids()
765 * address before reading the devices-in-package in get_phy_c45_ids()
772 return -EIO; in get_phy_c45_ids()
779 return -EIO; in get_phy_c45_ids()
789 return -EIO; in get_phy_c45_ids()
793 return -ENODEV; in get_phy_c45_ids()
816 return -EIO; in get_phy_c45_ids()
817 c45_ids->device_ids[i] = phy_reg << 16; in get_phy_c45_ids()
821 return -EIO; in get_phy_c45_ids()
822 c45_ids->device_ids[i] |= phy_reg; in get_phy_c45_ids()
825 c45_ids->devices_in_package = devs_in_pkg; in get_phy_c45_ids()
827 c45_ids->mmds_present = devs_in_pkg & ~BIT(0); in get_phy_c45_ids()
833 * get_phy_c22_id - reads the specified addr for its clause 22 ID.
840 * valid, %-EIO on bus access error, or %-ENODEV if no device responds
850 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
851 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
859 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
860 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
867 return -ENODEV; in get_phy_c22_id()
873 * ethernet-phy-idAAAA.BBBB.
885 if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) != 2) in fwnode_get_phy_id()
886 return -EINVAL; in fwnode_get_phy_id()
894 * get_phy_device - reads the specified PHY device and returns its @phy_device
909 * Returns an allocated &struct phy_device on success, %-ENODEV if there is
910 * no PHY present, or %-EIO on bus access error.
935 if (!is_c45 && phy_id == 0 && bus->probe_capabilities >= MDIOBUS_C45) { in get_phy_device()
947 * phy_device_register - Register the phy device on the MDIO bus
954 err = mdiobus_register_device(&phydev->mdio); in phy_device_register()
968 err = device_add(&phydev->mdio.dev); in phy_device_register()
980 mdiobus_unregister_device(&phydev->mdio); in phy_device_register()
986 * phy_device_remove - Remove a previously registered phy device from the MDIO bus
995 unregister_mii_timestamper(phydev->mii_ts); in phy_device_remove()
996 pse_control_put(phydev->psec); in phy_device_remove()
998 device_del(&phydev->mdio.dev); in phy_device_remove()
1003 mdiobus_unregister_device(&phydev->mdio); in phy_device_remove()
1008 * phy_get_c45_ids - Read 802.3-c45 IDs for phy device.
1009 * @phydev: phy_device structure to read 802.3-c45 IDs
1011 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
1016 return get_phy_c45_ids(phydev->mdio.bus, phydev->mdio.addr, in phy_get_c45_ids()
1017 &phydev->c45_ids); in phy_get_c45_ids()
1022 * phy_find_first - finds the first PHY device on the bus
1041 struct net_device *netdev = phydev->attached_dev; in phy_link_change()
1047 phydev->adjust_link(netdev); in phy_link_change()
1048 if (phydev->mii_ts && phydev->mii_ts->link_state) in phy_link_change()
1049 phydev->mii_ts->link_state(phydev->mii_ts, phydev); in phy_link_change()
1053 * phy_prepare_link - prepares the PHY layer to monitor link status
1067 phydev->adjust_link = handler; in phy_prepare_link()
1071 * phy_connect_direct - connect an ethernet device to a specific phy_device
1084 return -EINVAL; in phy_connect_direct()
1086 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_connect_direct()
1099 * phy_connect - connect an ethernet device to a PHY device
1105 * Description: Convenience function for connecting ethernet
1127 return ERR_PTR(-ENODEV); in phy_connect()
1141 * phy_disconnect - disable interrupts, stop state machine, and detach a PHY
1153 phydev->adjust_link = NULL; in phy_disconnect()
1160 * phy_poll_reset - Safely wait until a PHY reset has properly completed
1172 * even *REQUIRE* a soft-reset to properly restart autonegotiation. In an
1175 * and reapply all driver-specific and board-specific fixups.
1200 if (!phydev->drv) in phy_init_hw()
1203 if (phydev->drv->soft_reset) { in phy_init_hw()
1204 ret = phydev->drv->soft_reset(phydev); in phy_init_hw()
1207 phydev->suspended = 0; in phy_init_hw()
1217 if (phydev->drv->config_init) { in phy_init_hw()
1218 ret = phydev->drv->config_init(phydev); in phy_init_hw()
1223 if (phydev->drv->config_intr) { in phy_init_hw()
1224 ret = phydev->drv->config_intr(phydev); in phy_init_hw()
1245 switch(phydev->irq) { in phy_attached_info_irq()
1253 snprintf(irq_num, sizeof(irq_num), "%d", phydev->irq); in phy_attached_info_irq()
1264 const char *unbound = phydev->drv ? "" : "[unbound] "; in phy_attached_print()
1286 struct net_device *dev = phydev->attached_dev; in phy_sysfs_create_links()
1292 err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, in phy_sysfs_create_links()
1297 err = sysfs_create_link_nowarn(&dev->dev.kobj, in phy_sysfs_create_links()
1298 &phydev->mdio.dev.kobj, in phy_sysfs_create_links()
1301 dev_err(&dev->dev, "could not add device link to %s err %d\n", in phy_sysfs_create_links()
1302 kobject_name(&phydev->mdio.dev.kobj), in phy_sysfs_create_links()
1304 /* non-fatal - some net drivers can use one netdevice in phy_sysfs_create_links()
1309 phydev->sysfs_links = true; in phy_sysfs_create_links()
1318 return sysfs_emit(buf, "%d\n", !phydev->attached_dev); in phy_standalone_show()
1323 * phy_sfp_attach - attach the SFP bus to the PHY upstream network device
1333 if (phydev->attached_dev) in phy_sfp_attach()
1334 phydev->attached_dev->sfp_bus = bus; in phy_sfp_attach()
1335 phydev->sfp_bus_attached = true; in phy_sfp_attach()
1340 * phy_sfp_detach - detach the SFP bus from the PHY upstream network device
1350 if (phydev->attached_dev) in phy_sfp_detach()
1351 phydev->attached_dev->sfp_bus = NULL; in phy_sfp_detach()
1352 phydev->sfp_bus_attached = false; in phy_sfp_detach()
1357 * phy_sfp_probe - probe for a SFP cage attached to this PHY device
1367 if (phydev->mdio.dev.fwnode) { in phy_sfp_probe()
1368 bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); in phy_sfp_probe()
1372 phydev->sfp_bus = bus; in phy_sfp_probe()
1382 * phy_attach_direct - attach a network device to a given PHY device pointer
1399 struct mii_bus *bus = phydev->mdio.bus; in phy_attach_direct()
1400 struct device *d = &phydev->mdio.dev; in phy_attach_direct()
1405 /* For Ethernet device drivers that register their own MDIO bus, we in phy_attach_direct()
1406 * will have bus->owner match ndev_mod, so we do not want to increment in phy_attach_direct()
1407 * our own module->refcnt here, otherwise we would not be able to in phy_attach_direct()
1411 ndev_owner = dev->dev.parent->driver->owner; in phy_attach_direct()
1412 if (ndev_owner != bus->owner && !try_module_get(bus->owner)) { in phy_attach_direct()
1414 return -EIO; in phy_attach_direct()
1422 if (!d->driver) { in phy_attach_direct()
1423 if (phydev->is_c45) in phy_attach_direct()
1424 d->driver = &genphy_c45_driver.mdiodrv.driver; in phy_attach_direct()
1426 d->driver = &genphy_driver.mdiodrv.driver; in phy_attach_direct()
1431 if (!try_module_get(d->driver->owner)) { in phy_attach_direct()
1433 err = -EIO; in phy_attach_direct()
1438 err = d->driver->probe(d); in phy_attach_direct()
1446 if (phydev->attached_dev) { in phy_attach_direct()
1447 dev_err(&dev->dev, "PHY already attached\n"); in phy_attach_direct()
1448 err = -EBUSY; in phy_attach_direct()
1452 phydev->phy_link_change = phy_link_change; in phy_attach_direct()
1454 phydev->attached_dev = dev; in phy_attach_direct()
1455 dev->phydev = phydev; in phy_attach_direct()
1457 if (phydev->sfp_bus_attached) in phy_attach_direct()
1458 dev->sfp_bus = phydev->sfp_bus; in phy_attach_direct()
1459 else if (dev->sfp_bus) in phy_attach_direct()
1460 phydev->is_on_sfp_module = true; in phy_attach_direct()
1463 /* Some Ethernet drivers try to connect to a PHY device before in phy_attach_direct()
1464 * calling register_netdevice() -> netdev_register_kobject() and in phy_attach_direct()
1465 * does the dev->dev.kobj initialization. Here we only check for in phy_attach_direct()
1471 phydev->sysfs_links = false; in phy_attach_direct()
1475 if (!phydev->attached_dev) { in phy_attach_direct()
1476 err = sysfs_create_file(&phydev->mdio.dev.kobj, in phy_attach_direct()
1482 phydev->dev_flags |= flags; in phy_attach_direct()
1484 phydev->interface = interface; in phy_attach_direct()
1486 phydev->state = PHY_READY; in phy_attach_direct()
1488 phydev->interrupts = PHY_INTERRUPT_DISABLED; in phy_attach_direct()
1496 phydev->port = PORT_MII; in phy_attach_direct()
1502 netif_carrier_off(phydev->attached_dev); in phy_attach_direct()
1523 module_put(d->driver->owner); in phy_attach_direct()
1524 d->driver = NULL; in phy_attach_direct()
1527 if (ndev_owner != bus->owner) in phy_attach_direct()
1528 module_put(bus->owner); in phy_attach_direct()
1534 * phy_attach - attach a network device to a particular PHY device
1551 return ERR_PTR(-EINVAL); in phy_attach()
1559 return ERR_PTR(-ENODEV); in phy_attach()
1563 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_attach()
1575 struct device *d = &phydev->mdio.dev; in phy_driver_is_genphy_kind()
1578 if (!phydev->drv) in phy_driver_is_genphy_kind()
1582 ret = d->driver == driver; in phy_driver_is_genphy_kind()
1603 * phy_package_join - join a common PHY group
1606 * @priv_size: if non-zero allocate this amount of bytes for private data
1622 * allocated. If priv_size is non-zero, the given amount of bytes are
1630 struct mii_bus *bus = phydev->mdio.bus; in phy_package_join()
1635 return -EINVAL; in phy_package_join()
1637 mutex_lock(&bus->shared_lock); in phy_package_join()
1638 shared = bus->shared[addr]; in phy_package_join()
1640 ret = -ENOMEM; in phy_package_join()
1645 shared->priv = kzalloc(priv_size, GFP_KERNEL); in phy_package_join()
1646 if (!shared->priv) in phy_package_join()
1648 shared->priv_size = priv_size; in phy_package_join()
1650 shared->addr = addr; in phy_package_join()
1651 refcount_set(&shared->refcnt, 1); in phy_package_join()
1652 bus->shared[addr] = shared; in phy_package_join()
1654 ret = -EINVAL; in phy_package_join()
1655 if (priv_size && priv_size != shared->priv_size) in phy_package_join()
1657 refcount_inc(&shared->refcnt); in phy_package_join()
1659 mutex_unlock(&bus->shared_lock); in phy_package_join()
1661 phydev->shared = shared; in phy_package_join()
1668 mutex_unlock(&bus->shared_lock); in phy_package_join()
1674 * phy_package_leave - leave a common PHY group
1679 * freed. Resets the phydev->shared pointer to NULL.
1683 struct phy_package_shared *shared = phydev->shared; in phy_package_leave()
1684 struct mii_bus *bus = phydev->mdio.bus; in phy_package_leave()
1689 if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { in phy_package_leave()
1690 bus->shared[shared->addr] = NULL; in phy_package_leave()
1691 mutex_unlock(&bus->shared_lock); in phy_package_leave()
1692 kfree(shared->priv); in phy_package_leave()
1696 phydev->shared = NULL; in phy_package_leave()
1706 * devm_phy_package_join - resource managed phy_package_join()
1710 * @priv_size: if non-zero allocate this amount of bytes for private data
1725 return -ENOMEM; in devm_phy_package_join()
1741 * phy_detach - detach a PHY device from its network device
1749 struct net_device *dev = phydev->attached_dev; in phy_detach()
1753 if (phydev->sysfs_links) { in phy_detach()
1755 sysfs_remove_link(&dev->dev.kobj, "phydev"); in phy_detach()
1756 sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); in phy_detach()
1759 if (!phydev->attached_dev) in phy_detach()
1760 sysfs_remove_file(&phydev->mdio.dev.kobj, in phy_detach()
1765 phydev->attached_dev->phydev = NULL; in phy_detach()
1766 phydev->attached_dev = NULL; in phy_detach()
1768 phydev->phylink = NULL; in phy_detach()
1772 if (phydev->mdio.dev.driver) in phy_detach()
1773 module_put(phydev->mdio.dev.driver->owner); in phy_detach()
1775 /* If the device had no specific driver before (i.e. - it in phy_detach()
1782 device_release_driver(&phydev->mdio.dev); in phy_detach()
1789 * a use-after-free bug by reading the underlying bus first. in phy_detach()
1791 bus = phydev->mdio.bus; in phy_detach()
1793 put_device(&phydev->mdio.dev); in phy_detach()
1795 ndev_owner = dev->dev.parent->driver->owner; in phy_detach()
1796 if (ndev_owner != bus->owner) in phy_detach()
1797 module_put(bus->owner); in phy_detach()
1804 struct net_device *netdev = phydev->attached_dev; in phy_suspend()
1805 struct phy_driver *phydrv = phydev->drv; in phy_suspend()
1808 if (phydev->suspended) in phy_suspend()
1813 if (wol.wolopts || (netdev && netdev->wol_enabled)) in phy_suspend()
1814 return -EBUSY; in phy_suspend()
1816 if (!phydrv || !phydrv->suspend) in phy_suspend()
1819 ret = phydrv->suspend(phydev); in phy_suspend()
1821 phydev->suspended = true; in phy_suspend()
1829 struct phy_driver *phydrv = phydev->drv; in __phy_resume()
1832 lockdep_assert_held(&phydev->lock); in __phy_resume()
1834 if (!phydrv || !phydrv->resume) in __phy_resume()
1837 ret = phydrv->resume(phydev); in __phy_resume()
1839 phydev->suspended = false; in __phy_resume()
1849 mutex_lock(&phydev->lock); in phy_resume()
1851 mutex_unlock(&phydev->lock); in phy_resume()
1861 if (!phydev->drv) in phy_loopback()
1862 return -EIO; in phy_loopback()
1864 mutex_lock(&phydev->lock); in phy_loopback()
1866 if (enable && phydev->loopback_enabled) { in phy_loopback()
1867 ret = -EBUSY; in phy_loopback()
1871 if (!enable && !phydev->loopback_enabled) { in phy_loopback()
1872 ret = -EINVAL; in phy_loopback()
1876 if (phydev->drv->set_loopback) in phy_loopback()
1877 ret = phydev->drv->set_loopback(phydev, enable); in phy_loopback()
1884 phydev->loopback_enabled = enable; in phy_loopback()
1887 mutex_unlock(&phydev->lock); in phy_loopback()
1893 * phy_reset_after_clk_enable - perform a PHY reset if needed
1903 if (!phydev || !phydev->drv) in phy_reset_after_clk_enable()
1904 return -ENODEV; in phy_reset_after_clk_enable()
1906 if (phydev->drv->flags & PHY_RST_AFTER_CLK_EN) { in phy_reset_after_clk_enable()
1919 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
1933 linkmode_and(phydev->advertising, phydev->advertising, in genphy_config_advert()
1934 phydev->supported); in genphy_config_advert()
1936 adv = linkmode_adv_to_mii_adv_t(phydev->advertising); in genphy_config_advert()
1952 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all in genphy_config_advert()
1959 adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising); in genphy_config_advert()
1973 * genphy_c37_config_advert - sanitize and advertise auto-negotiation parameters
1980 * for Clause 37 1000Base-X mode.
1987 linkmode_and(phydev->advertising, phydev->advertising, in genphy_c37_config_advert()
1988 phydev->supported); in genphy_c37_config_advert()
1991 phydev->advertising)) in genphy_c37_config_advert()
1994 phydev->advertising)) in genphy_c37_config_advert()
1997 phydev->advertising)) in genphy_c37_config_advert()
2007 * genphy_config_eee_advert - disable unwanted eee mode advertisement
2011 * efficent ethernet modes. Returns 0 if the PHY's advertisement hasn't
2019 if (!phydev->eee_broken_modes) in genphy_config_eee_advert()
2023 phydev->eee_broken_modes, 0); in genphy_config_eee_advert()
2030 * genphy_setup_forced - configures/forces speed/duplex from @phydev
2041 phydev->pause = 0; in genphy_setup_forced()
2042 phydev->asym_pause = 0; in genphy_setup_forced()
2044 ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); in genphy_setup_forced()
2055 if (!phydev->is_gigabit_capable) in genphy_setup_master_slave()
2058 switch (phydev->master_slave_set) { in genphy_setup_master_slave()
2075 return -EOPNOTSUPP; in genphy_setup_master_slave()
2088 phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN; in genphy_read_master_slave()
2089 phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN; in genphy_read_master_slave()
2113 } else if (phydev->link) { in genphy_read_master_slave()
2123 phydev->master_slave_get = cfg; in genphy_read_master_slave()
2124 phydev->master_slave_state = state; in genphy_read_master_slave()
2131 * genphy_restart_aneg - Enable and Restart Autonegotiation
2143 * genphy_check_and_restart_aneg - Enable and restart auto-negotiation
2147 * Check, and restart auto-negotiation if needed.
2173 * __genphy_config_aneg - restart auto-negotiation or write BMCR
2177 * Description: If auto-negotiation is enabled, we configure the
2178 * advertising, and then restart auto-negotiation. If it is not
2194 if (AUTONEG_ENABLE != phydev->autoneg) in __genphy_config_aneg()
2208 * genphy_c37_config_aneg - restart auto-negotiation or write BMCR
2211 * Description: If auto-negotiation is enabled, we configure the
2212 * advertising, and then restart auto-negotiation. If it is not
2214 * for use with Clause 37 1000Base-X mode.
2220 if (phydev->autoneg != AUTONEG_ENABLE) in genphy_c37_config_aneg()
2256 * genphy_aneg_done - return auto-negotiation status
2260 * auto-negotiation is incomplete, or if there was an error.
2261 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
2272 * genphy_update_link - update link status in @phydev
2275 * Description: Update the value in phydev->link to reflect the
2294 * drops can be detected. Do not double-read the status in genphy_update_link()
2298 if (!phy_polling_mode(phydev) || !phydev->link) { in genphy_update_link()
2311 phydev->link = status & BMSR_LSTATUS ? 1 : 0; in genphy_update_link()
2312 phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0; in genphy_update_link()
2317 if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete) in genphy_update_link()
2318 phydev->link = 0; in genphy_update_link()
2328 if (phydev->autoneg == AUTONEG_ENABLE) { in genphy_read_lpa()
2329 if (!phydev->autoneg_complete) { in genphy_read_lpa()
2330 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2332 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0); in genphy_read_lpa()
2336 if (phydev->is_gigabit_capable) { in genphy_read_lpa()
2351 return -ENOLINK; in genphy_read_lpa()
2354 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2362 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); in genphy_read_lpa()
2364 linkmode_zero(phydev->lp_advertising); in genphy_read_lpa()
2372 * genphy_read_status_fixed - read the link parameters for !aneg mode
2386 phydev->duplex = DUPLEX_FULL; in genphy_read_status_fixed()
2388 phydev->duplex = DUPLEX_HALF; in genphy_read_status_fixed()
2391 phydev->speed = SPEED_1000; in genphy_read_status_fixed()
2393 phydev->speed = SPEED_100; in genphy_read_status_fixed()
2395 phydev->speed = SPEED_10; in genphy_read_status_fixed()
2402 * genphy_read_status - check the link status and update current link state
2412 int err, old_link = phydev->link; in genphy_read_status()
2420 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in genphy_read_status()
2423 phydev->master_slave_get = MASTER_SLAVE_CFG_UNSUPPORTED; in genphy_read_status()
2424 phydev->master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED; in genphy_read_status()
2425 phydev->speed = SPEED_UNKNOWN; in genphy_read_status()
2426 phydev->duplex = DUPLEX_UNKNOWN; in genphy_read_status()
2427 phydev->pause = 0; in genphy_read_status()
2428 phydev->asym_pause = 0; in genphy_read_status()
2430 if (phydev->is_gigabit_capable) { in genphy_read_status()
2440 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_read_status()
2442 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_read_status()
2453 * genphy_c37_read_status - check the link status and update current link state
2458 * advertises. This function is for Clause 37 1000Base-X mode.
2462 int lpa, err, old_link = phydev->link; in genphy_c37_read_status()
2470 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in genphy_c37_read_status()
2473 phydev->duplex = DUPLEX_UNKNOWN; in genphy_c37_read_status()
2474 phydev->pause = 0; in genphy_c37_read_status()
2475 phydev->asym_pause = 0; in genphy_c37_read_status()
2477 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_c37_read_status()
2483 phydev->lp_advertising, lpa & LPA_LPACK); in genphy_c37_read_status()
2485 phydev->lp_advertising, lpa & LPA_1000XFULL); in genphy_c37_read_status()
2487 phydev->lp_advertising, lpa & LPA_1000XPAUSE); in genphy_c37_read_status()
2489 phydev->lp_advertising, in genphy_c37_read_status()
2493 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_c37_read_status()
2500 phydev->duplex = DUPLEX_FULL; in genphy_c37_read_status()
2502 phydev->duplex = DUPLEX_HALF; in genphy_c37_read_status()
2510 * genphy_soft_reset - software reset the PHY via BMCR_RESET bit
2523 if (phydev->autoneg == AUTONEG_ENABLE) in genphy_soft_reset()
2534 phydev->suspended = 0; in genphy_soft_reset()
2541 if (phydev->autoneg == AUTONEG_DISABLE) in genphy_soft_reset()
2562 * genphy_read_abilities - read PHY abilities from Clause 22 registers
2566 * phydev->supported accordingly.
2576 phydev->supported); in genphy_read_abilities()
2582 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported, in genphy_read_abilities()
2585 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2587 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2589 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2591 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2600 phydev->supported, val & ESTATUS_1000_TFULL); in genphy_read_abilities()
2602 phydev->supported, val & ESTATUS_1000_THALF); in genphy_read_abilities()
2604 phydev->supported, val & ESTATUS_1000_XFULL); in genphy_read_abilities()
2617 return -EOPNOTSUPP; in genphy_read_mmd_unsupported()
2624 return -EOPNOTSUPP; in genphy_write_mmd_unsupported()
2646 ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); in genphy_loopback()
2666 * phy_remove_link_mode - Remove a supported link mode
2676 linkmode_clear_bit(link_mode, phydev->supported); in phy_remove_link_mode()
2690 * phy_advertise_supported - Advertise all supported modes
2700 linkmode_copy(new, phydev->supported); in phy_advertise_supported()
2701 phy_copy_pause_bits(new, phydev->advertising); in phy_advertise_supported()
2702 linkmode_copy(phydev->advertising, new); in phy_advertise_supported()
2707 * phy_support_sym_pause - Enable support of symmetrical pause
2715 linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported); in phy_support_sym_pause()
2716 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_sym_pause()
2721 * phy_support_asym_pause - Enable support of asym pause
2728 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_asym_pause()
2733 * phy_set_sym_pause - Configure symmetric Pause
2746 linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported); in phy_set_sym_pause()
2750 phydev->supported); in phy_set_sym_pause()
2752 linkmode_copy(phydev->advertising, phydev->supported); in phy_set_sym_pause()
2757 * phy_set_asym_pause - Configure Pause and Asym Pause
2771 linkmode_copy(oldadv, phydev->advertising); in phy_set_asym_pause()
2772 linkmode_set_pause(phydev->advertising, tx, rx); in phy_set_asym_pause()
2774 if (!linkmode_equal(oldadv, phydev->advertising) && in phy_set_asym_pause()
2775 phydev->autoneg) in phy_set_asym_pause()
2781 * phy_validate_pause - Test if the PHY/MAC support the pause configuration
2793 phydev->supported) && pp->rx_pause) in phy_validate_pause()
2797 phydev->supported) && in phy_validate_pause()
2798 pp->rx_pause != pp->tx_pause) in phy_validate_pause()
2806 * phy_get_pause - resolve negotiated pause modes
2819 if (phydev->duplex != DUPLEX_FULL) { in phy_get_pause()
2825 return linkmode_resolve_pause(phydev->advertising, in phy_get_pause()
2826 phydev->lp_advertising, in phy_get_pause()
2846 return -EINVAL; in phy_get_int_delay_property()
2851 * phy_get_internal_delay - returns the index of the internal delay
2864 * Return -EINVAL if the delay is invalid or cannot be found.
2873 delay = phy_get_int_delay_property(dev, "rx-internal-delay-ps"); in phy_get_internal_delay()
2875 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
2876 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) in phy_get_internal_delay()
2883 delay = phy_get_int_delay_property(dev, "tx-internal-delay-ps"); in phy_get_internal_delay()
2885 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
2886 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) in phy_get_internal_delay()
2899 if (delay < delay_values[0] || delay > delay_values[size - 1]) { in phy_get_internal_delay()
2901 return -EINVAL; in phy_get_internal_delay()
2912 if (delay > delay_values[i - 1] && in phy_get_internal_delay()
2914 if (delay - delay_values[i - 1] < in phy_get_internal_delay()
2915 delay_values[i] - delay) in phy_get_internal_delay()
2916 return i - 1; in phy_get_internal_delay()
2925 return -EINVAL; in phy_get_internal_delay()
2931 return phydrv->config_intr && phydrv->handle_interrupt; in phy_drv_supports_irq()
2935 * fwnode_mdio_find_device - Given a fwnode, find the mdio_device
2958 * fwnode_phy_find_device - For provided phy_fwnode, find phy_device.
2973 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) in fwnode_phy_find_device()
2974 return to_phy_device(&mdiodev->dev); in fwnode_phy_find_device()
2976 put_device(&mdiodev->dev); in fwnode_phy_find_device()
2983 * device_phy_find_device - For the given device, get the phy_device
2995 * fwnode_get_phy_node - Get the phy_node using the named reference.
2999 * For ACPI, only "phy-handle" is supported. Legacy DT properties "phy"
3000 * and "phy-device" are not supported in ACPI. DT supports all the three
3007 /* Only phy-handle is used for ACPI */ in fwnode_get_phy_node()
3008 phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); in fwnode_get_phy_node()
3013 phy_node = fwnode_find_reference(fwnode, "phy-device", 0); in fwnode_get_phy_node()
3019 * phy_probe - probe and init a PHY device
3029 struct device_driver *drv = phydev->mdio.dev.driver; in phy_probe()
3033 phydev->drv = phydrv; in phy_probe()
3039 phydev->irq = PHY_POLL; in phy_probe()
3041 if (phydrv->flags & PHY_IS_INTERNAL) in phy_probe()
3042 phydev->is_internal = true; in phy_probe()
3044 mutex_lock(&phydev->lock); in phy_probe()
3049 if (phydev->drv->probe) { in phy_probe()
3050 err = phydev->drv->probe(phydev); in phy_probe()
3059 if (phydrv->features) in phy_probe()
3060 linkmode_copy(phydev->supported, phydrv->features); in phy_probe()
3061 else if (phydrv->get_features) in phy_probe()
3062 err = phydrv->get_features(phydev); in phy_probe()
3063 else if (phydev->is_c45) in phy_probe()
3072 phydev->supported)) in phy_probe()
3073 phydev->autoneg = 0; in phy_probe()
3076 phydev->supported)) in phy_probe()
3077 phydev->is_gigabit_capable = 1; in phy_probe()
3079 phydev->supported)) in phy_probe()
3080 phydev->is_gigabit_capable = 1; in phy_probe()
3101 if (!test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported) && in phy_probe()
3102 !test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported)) { in phy_probe()
3104 phydev->supported); in phy_probe()
3106 phydev->supported); in phy_probe()
3110 phydev->state = PHY_READY; in phy_probe()
3117 mutex_unlock(&phydev->lock); in phy_probe()
3126 cancel_delayed_work_sync(&phydev->state_queue); in phy_remove()
3128 mutex_lock(&phydev->lock); in phy_remove()
3129 phydev->state = PHY_DOWN; in phy_remove()
3130 mutex_unlock(&phydev->lock); in phy_remove()
3132 sfp_bus_del_upstream(phydev->sfp_bus); in phy_remove()
3133 phydev->sfp_bus = NULL; in phy_remove()
3135 if (phydev->drv && phydev->drv->remove) in phy_remove()
3136 phydev->drv->remove(phydev); in phy_remove()
3141 phydev->drv = NULL; in phy_remove()
3150 if (phydev->state == PHY_READY || !phydev->attached_dev) in phy_shutdown()
3157 * phy_driver_register - register a phy_driver with the PHY layer
3168 if (WARN_ON(new_driver->features && new_driver->get_features)) { in phy_driver_register()
3170 new_driver->name); in phy_driver_register()
3171 return -EINVAL; in phy_driver_register()
3177 * make out-of-bounds accesses and lockup in phydev->lock. in phy_driver_register()
3179 if (WARN(new_driver->mdiodrv.driver.of_match_table, in phy_driver_register()
3181 new_driver->name)) in phy_driver_register()
3182 return -EINVAL; in phy_driver_register()
3184 new_driver->mdiodrv.flags |= MDIO_DEVICE_IS_PHY; in phy_driver_register()
3185 new_driver->mdiodrv.driver.name = new_driver->name; in phy_driver_register()
3186 new_driver->mdiodrv.driver.bus = &mdio_bus_type; in phy_driver_register()
3187 new_driver->mdiodrv.driver.probe = phy_probe; in phy_driver_register()
3188 new_driver->mdiodrv.driver.remove = phy_remove; in phy_driver_register()
3189 new_driver->mdiodrv.driver.shutdown = phy_shutdown; in phy_driver_register()
3190 new_driver->mdiodrv.driver.owner = owner; in phy_driver_register()
3191 new_driver->mdiodrv.driver.probe_type = PROBE_FORCE_SYNCHRONOUS; in phy_driver_register()
3193 retval = driver_register(&new_driver->mdiodrv.driver); in phy_driver_register()
3196 new_driver->name, retval); in phy_driver_register()
3201 pr_debug("%s: Registered new driver\n", new_driver->name); in phy_driver_register()
3215 while (i-- > 0) in phy_drivers_register()
3226 driver_unregister(&drv->mdiodrv.driver); in phy_driver_unregister()