Lines Matching +full:eee +full:- +full:broken +full:- +full:100 +full:tx
1 // SPDX-License-Identifier: GPL-2.0+
126 /* 10/100 half/full*/ in features_init()
134 /* 100 full, TP */ in features_init()
139 /* 10/100 half/full + 1000 half/full */ in features_init()
150 /* 10/100 half/full + 1000 half/full + fibre*/ in features_init()
164 /* 10/100 half/full + 1000 half/full + TP/MII/FIBRE/AUI/BNC/Backplane*/ in features_init()
175 /* 10/100 half/full + 1000 half/full + 10G full*/ in features_init()
189 /* 10/100/1000/10G full */ in features_init()
204 put_device(&phydev->mdio.dev); in phy_device_free()
236 struct device_driver *drv = phydev->mdio.dev.driver; in mdio_bus_phy_may_suspend()
238 struct net_device *netdev = phydev->attached_dev; in mdio_bus_phy_may_suspend()
240 if (!drv || !phydrv->suspend) in mdio_bus_phy_may_suspend()
244 * suspended as part of a prior call to phy_disconnect() -> in mdio_bus_phy_may_suspend()
245 * phy_detach() -> phy_suspend() because the parent netdev might be the in mdio_bus_phy_may_suspend()
251 if (netdev->wol_enabled) in mdio_bus_phy_may_suspend()
259 if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent)) in mdio_bus_phy_may_suspend()
266 if (device_may_wakeup(&netdev->dev)) in mdio_bus_phy_may_suspend()
270 return !phydev->suspended; in mdio_bus_phy_may_suspend()
277 if (phydev->mac_managed_pm) in mdio_bus_phy_suspend()
281 * control, possibly with the phydev->lock held. Upon resume, netdev in mdio_bus_phy_suspend()
285 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_suspend()
291 phydev->suspended_by_mdio_bus = 1; in mdio_bus_phy_suspend()
301 if (phydev->mac_managed_pm) in mdio_bus_phy_resume()
304 if (!phydev->suspended_by_mdio_bus) in mdio_bus_phy_resume()
307 phydev->suspended_by_mdio_bus = 0; in mdio_bus_phy_resume()
317 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_resume()
327 * phy_register_fixup - creates a new phy_fixup and adds it to the list
328 * @bus_id: A string which matches phydev->mdio.dev.bus_id (or PHY_ANY_ID)
329 * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY)
331 * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before
341 return -ENOMEM; in phy_register_fixup()
343 strlcpy(fixup->bus_id, bus_id, sizeof(fixup->bus_id)); in phy_register_fixup()
344 fixup->phy_uid = phy_uid; in phy_register_fixup()
345 fixup->phy_uid_mask = phy_uid_mask; in phy_register_fixup()
346 fixup->run = run; in phy_register_fixup()
349 list_add_tail(&fixup->list, &phy_fixup_list); in phy_register_fixup()
373 * phy_unregister_fixup - remove a phy_fixup from the list
374 * @bus_id: A string matches fixup->bus_id (or PHY_ANY_ID) in phy_fixup_list
375 * @phy_uid: A phy id matches fixup->phy_id (or PHY_ANY_UID) in phy_fixup_list
376 * @phy_uid_mask: Applied to phy_uid and fixup->phy_uid before comparison
384 ret = -ENODEV; in phy_unregister_fixup()
390 if ((!strcmp(fixup->bus_id, bus_id)) && in phy_unregister_fixup()
391 ((fixup->phy_uid & phy_uid_mask) == in phy_unregister_fixup()
393 list_del(&fixup->list); in phy_unregister_fixup()
424 if (strcmp(fixup->bus_id, phydev_name(phydev)) != 0) in phy_needs_fixup()
425 if (strcmp(fixup->bus_id, PHY_ANY_ID) != 0) in phy_needs_fixup()
428 if ((fixup->phy_uid & fixup->phy_uid_mask) != in phy_needs_fixup()
429 (phydev->phy_id & fixup->phy_uid_mask)) in phy_needs_fixup()
430 if (fixup->phy_uid != PHY_ANY_UID) in phy_needs_fixup()
444 int err = fixup->run(phydev); in phy_scan_fixups()
450 phydev->has_fixups = true; in phy_scan_fixups()
462 const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids); in phy_bus_match()
465 if (!(phydrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY)) in phy_bus_match()
468 if (phydrv->match_phy_device) in phy_bus_match()
469 return phydrv->match_phy_device(phydev); in phy_bus_match()
471 if (phydev->is_c45) { in phy_bus_match()
473 if (phydev->c45_ids.device_ids[i] == 0xffffffff) in phy_bus_match()
476 if ((phydrv->phy_id & phydrv->phy_id_mask) == in phy_bus_match()
477 (phydev->c45_ids.device_ids[i] & in phy_bus_match()
478 phydrv->phy_id_mask)) in phy_bus_match()
483 return (phydrv->phy_id & phydrv->phy_id_mask) == in phy_bus_match()
484 (phydev->phy_id & phydrv->phy_id_mask); in phy_bus_match()
493 return sprintf(buf, "0x%.8lx\n", (unsigned long)phydev->phy_id); in phy_id_show()
506 mode = phy_modes(phydev->interface); in phy_interface_show()
518 return sprintf(buf, "%d\n", phydev->has_fixups); in phy_has_fixups_show()
528 return sprintf(buf, "0x%08x\n", phydev->dev_flags); in phy_dev_flags_show()
556 * Accept -ENOENT because this may occur in case no initramfs exists, in phy_request_driver_module()
559 if (IS_ENABLED(CONFIG_MODULES) && ret < 0 && ret != -ENOENT) { in phy_request_driver_module()
579 return ERR_PTR(-ENOMEM); in phy_device_create()
581 mdiodev = &dev->mdio; in phy_device_create()
582 mdiodev->dev.parent = &bus->dev; in phy_device_create()
583 mdiodev->dev.bus = &mdio_bus_type; in phy_device_create()
584 mdiodev->dev.type = &mdio_bus_phy_type; in phy_device_create()
585 mdiodev->bus = bus; in phy_device_create()
586 mdiodev->bus_match = phy_bus_match; in phy_device_create()
587 mdiodev->addr = addr; in phy_device_create()
588 mdiodev->flags = MDIO_DEVICE_FLAG_PHY; in phy_device_create()
589 mdiodev->device_free = phy_mdio_device_free; in phy_device_create()
590 mdiodev->device_remove = phy_mdio_device_remove; in phy_device_create()
592 dev->speed = SPEED_UNKNOWN; in phy_device_create()
593 dev->duplex = DUPLEX_UNKNOWN; in phy_device_create()
594 dev->pause = 0; in phy_device_create()
595 dev->asym_pause = 0; in phy_device_create()
596 dev->link = 0; in phy_device_create()
597 dev->port = PORT_TP; in phy_device_create()
598 dev->interface = PHY_INTERFACE_MODE_GMII; in phy_device_create()
600 dev->autoneg = AUTONEG_ENABLE; in phy_device_create()
602 dev->is_c45 = is_c45; in phy_device_create()
603 dev->phy_id = phy_id; in phy_device_create()
605 dev->c45_ids = *c45_ids; in phy_device_create()
606 dev->irq = bus->irq[addr]; in phy_device_create()
608 dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr); in phy_device_create()
609 device_initialize(&mdiodev->dev); in phy_device_create()
611 dev->state = PHY_DOWN; in phy_device_create()
613 mutex_init(&dev->lock); in phy_device_create()
614 INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); in phy_device_create()
621 * -- because it relies on the device staying around for long in phy_device_create()
627 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in phy_device_create()
631 if (c45_ids->device_ids[i] == 0xffffffff) in phy_device_create()
635 c45_ids->device_ids[i]); in phy_device_create()
644 put_device(&mdiodev->dev); in phy_device_create()
652 /* phy_c45_probe_present - checks to see if a MMD is present in the package
674 /* get_phy_c45_devs_in_pkg - reads a MMD's devices in package registers.
683 * Returns: 0 on success, -EIO on failure.
692 return -EIO; in get_phy_c45_devs_in_pkg()
697 return -EIO; in get_phy_c45_devs_in_pkg()
704 * get_phy_c45_ids - reads the specified addr for its 802.3-c45 IDs.
713 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
719 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in get_phy_c45_ids()
723 /* Find first non-zero Devices In package. Device zero is reserved in get_phy_c45_ids()
730 * address before reading the devices-in-package in get_phy_c45_ids()
737 return -EIO; in get_phy_c45_ids()
744 return -EIO; in get_phy_c45_ids()
754 return -EIO; in get_phy_c45_ids()
758 return -ENODEV; in get_phy_c45_ids()
781 return -EIO; in get_phy_c45_ids()
782 c45_ids->device_ids[i] = phy_reg << 16; in get_phy_c45_ids()
786 return -EIO; in get_phy_c45_ids()
787 c45_ids->device_ids[i] |= phy_reg; in get_phy_c45_ids()
790 c45_ids->devices_in_package = devs_in_pkg; in get_phy_c45_ids()
792 c45_ids->mmds_present = devs_in_pkg & ~BIT(0); in get_phy_c45_ids()
798 * get_phy_c22_id - reads the specified addr for its clause 22 ID.
805 * valid, %-EIO on bus access error, or %-ENODEV if no device responds
815 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
816 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
824 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
825 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
832 return -ENODEV; in get_phy_c22_id()
838 * ethernet-phy-idAAAA.BBBB.
850 if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) != 2) in fwnode_get_phy_id()
851 return -EINVAL; in fwnode_get_phy_id()
859 * get_phy_device - reads the specified PHY device and returns its @phy_device
874 * Returns an allocated &struct phy_device on success, %-ENODEV if there is
875 * no PHY present, or %-EIO on bus access error.
900 if (!is_c45 && phy_id == 0 && bus->probe_capabilities >= MDIOBUS_C45) { in get_phy_device()
912 * phy_device_register - Register the phy device on the MDIO bus
919 err = mdiobus_register_device(&phydev->mdio); in phy_device_register()
933 err = device_add(&phydev->mdio.dev); in phy_device_register()
945 mdiobus_unregister_device(&phydev->mdio); in phy_device_register()
951 * phy_device_remove - Remove a previously registered phy device from the MDIO bus
960 unregister_mii_timestamper(phydev->mii_ts); in phy_device_remove()
962 device_del(&phydev->mdio.dev); in phy_device_remove()
967 mdiobus_unregister_device(&phydev->mdio); in phy_device_remove()
972 * phy_get_c45_ids - Read 802.3-c45 IDs for phy device.
973 * @phydev: phy_device structure to read 802.3-c45 IDs
975 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
980 return get_phy_c45_ids(phydev->mdio.bus, phydev->mdio.addr, in phy_get_c45_ids()
981 &phydev->c45_ids); in phy_get_c45_ids()
986 * phy_find_first - finds the first PHY device on the bus
1005 struct net_device *netdev = phydev->attached_dev; in phy_link_change()
1011 phydev->adjust_link(netdev); in phy_link_change()
1012 if (phydev->mii_ts && phydev->mii_ts->link_state) in phy_link_change()
1013 phydev->mii_ts->link_state(phydev->mii_ts, phydev); in phy_link_change()
1017 * phy_prepare_link - prepares the PHY layer to monitor link status
1031 phydev->adjust_link = handler; in phy_prepare_link()
1035 * phy_connect_direct - connect an ethernet device to a specific phy_device
1048 return -EINVAL; in phy_connect_direct()
1050 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_connect_direct()
1063 * phy_connect - connect an ethernet device to a PHY device
1091 return ERR_PTR(-ENODEV); in phy_connect()
1105 * phy_disconnect - disable interrupts, stop state machine, and detach a PHY
1117 phydev->adjust_link = NULL; in phy_disconnect()
1124 * phy_poll_reset - Safely wait until a PHY reset has properly completed
1136 * even *REQUIRE* a soft-reset to properly restart autonegotiation. In an
1137 * effort to support such broken PHYs, this function is separate from the
1139 * and reapply all driver-specific and board-specific fixups.
1164 if (!phydev->drv) in phy_init_hw()
1167 if (phydev->drv->soft_reset) { in phy_init_hw()
1168 ret = phydev->drv->soft_reset(phydev); in phy_init_hw()
1171 phydev->suspended = 0; in phy_init_hw()
1181 if (phydev->drv->config_init) { in phy_init_hw()
1182 ret = phydev->drv->config_init(phydev); in phy_init_hw()
1187 if (phydev->drv->config_intr) { in phy_init_hw()
1188 ret = phydev->drv->config_intr(phydev); in phy_init_hw()
1209 switch(phydev->irq) { in phy_attached_info_irq()
1217 snprintf(irq_num, sizeof(irq_num), "%d", phydev->irq); in phy_attached_info_irq()
1228 const char *unbound = phydev->drv ? "" : "[unbound] "; in phy_attached_print()
1250 struct net_device *dev = phydev->attached_dev; in phy_sysfs_create_links()
1256 err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, in phy_sysfs_create_links()
1261 err = sysfs_create_link_nowarn(&dev->dev.kobj, in phy_sysfs_create_links()
1262 &phydev->mdio.dev.kobj, in phy_sysfs_create_links()
1265 dev_err(&dev->dev, "could not add device link to %s err %d\n", in phy_sysfs_create_links()
1266 kobject_name(&phydev->mdio.dev.kobj), in phy_sysfs_create_links()
1268 /* non-fatal - some net drivers can use one netdevice in phy_sysfs_create_links()
1273 phydev->sysfs_links = true; in phy_sysfs_create_links()
1282 return sprintf(buf, "%d\n", !phydev->attached_dev); in phy_standalone_show()
1287 * phy_sfp_attach - attach the SFP bus to the PHY upstream network device
1297 if (phydev->attached_dev) in phy_sfp_attach()
1298 phydev->attached_dev->sfp_bus = bus; in phy_sfp_attach()
1299 phydev->sfp_bus_attached = true; in phy_sfp_attach()
1304 * phy_sfp_detach - detach the SFP bus from the PHY upstream network device
1314 if (phydev->attached_dev) in phy_sfp_detach()
1315 phydev->attached_dev->sfp_bus = NULL; in phy_sfp_detach()
1316 phydev->sfp_bus_attached = false; in phy_sfp_detach()
1321 * phy_sfp_probe - probe for a SFP cage attached to this PHY device
1331 if (phydev->mdio.dev.fwnode) { in phy_sfp_probe()
1332 bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); in phy_sfp_probe()
1336 phydev->sfp_bus = bus; in phy_sfp_probe()
1346 * phy_attach_direct - attach a network device to a given PHY device pointer
1363 struct mii_bus *bus = phydev->mdio.bus; in phy_attach_direct()
1364 struct device *d = &phydev->mdio.dev; in phy_attach_direct()
1370 * will have bus->owner match ndev_mod, so we do not want to increment in phy_attach_direct()
1371 * our own module->refcnt here, otherwise we would not be able to in phy_attach_direct()
1375 ndev_owner = dev->dev.parent->driver->owner; in phy_attach_direct()
1376 if (ndev_owner != bus->owner && !try_module_get(bus->owner)) { in phy_attach_direct()
1378 return -EIO; in phy_attach_direct()
1386 if (!d->driver) { in phy_attach_direct()
1387 if (phydev->is_c45) in phy_attach_direct()
1388 d->driver = &genphy_c45_driver.mdiodrv.driver; in phy_attach_direct()
1390 d->driver = &genphy_driver.mdiodrv.driver; in phy_attach_direct()
1395 if (!try_module_get(d->driver->owner)) { in phy_attach_direct()
1397 err = -EIO; in phy_attach_direct()
1402 err = d->driver->probe(d); in phy_attach_direct()
1410 if (phydev->attached_dev) { in phy_attach_direct()
1411 dev_err(&dev->dev, "PHY already attached\n"); in phy_attach_direct()
1412 err = -EBUSY; in phy_attach_direct()
1416 phydev->phy_link_change = phy_link_change; in phy_attach_direct()
1418 phydev->attached_dev = dev; in phy_attach_direct()
1419 dev->phydev = phydev; in phy_attach_direct()
1421 if (phydev->sfp_bus_attached) in phy_attach_direct()
1422 dev->sfp_bus = phydev->sfp_bus; in phy_attach_direct()
1423 else if (dev->sfp_bus) in phy_attach_direct()
1424 phydev->is_on_sfp_module = true; in phy_attach_direct()
1428 * calling register_netdevice() -> netdev_register_kobject() and in phy_attach_direct()
1429 * does the dev->dev.kobj initialization. Here we only check for in phy_attach_direct()
1435 phydev->sysfs_links = false; in phy_attach_direct()
1439 if (!phydev->attached_dev) { in phy_attach_direct()
1440 err = sysfs_create_file(&phydev->mdio.dev.kobj, in phy_attach_direct()
1446 phydev->dev_flags |= flags; in phy_attach_direct()
1448 phydev->interface = interface; in phy_attach_direct()
1450 phydev->state = PHY_READY; in phy_attach_direct()
1458 phydev->port = PORT_MII; in phy_attach_direct()
1464 netif_carrier_off(phydev->attached_dev); in phy_attach_direct()
1489 module_put(d->driver->owner); in phy_attach_direct()
1492 if (ndev_owner != bus->owner) in phy_attach_direct()
1493 module_put(bus->owner); in phy_attach_direct()
1499 * phy_attach - attach a network device to a particular PHY device
1516 return ERR_PTR(-EINVAL); in phy_attach()
1524 return ERR_PTR(-ENODEV); in phy_attach()
1528 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_attach()
1540 struct device *d = &phydev->mdio.dev; in phy_driver_is_genphy_kind()
1543 if (!phydev->drv) in phy_driver_is_genphy_kind()
1547 ret = d->driver == driver; in phy_driver_is_genphy_kind()
1568 * phy_package_join - join a common PHY group
1571 * @priv_size: if non-zero allocate this amount of bytes for private data
1587 * allocated. If priv_size is non-zero, the given amount of bytes are
1595 struct mii_bus *bus = phydev->mdio.bus; in phy_package_join()
1600 return -EINVAL; in phy_package_join()
1602 mutex_lock(&bus->shared_lock); in phy_package_join()
1603 shared = bus->shared[addr]; in phy_package_join()
1605 ret = -ENOMEM; in phy_package_join()
1610 shared->priv = kzalloc(priv_size, GFP_KERNEL); in phy_package_join()
1611 if (!shared->priv) in phy_package_join()
1613 shared->priv_size = priv_size; in phy_package_join()
1615 shared->addr = addr; in phy_package_join()
1616 refcount_set(&shared->refcnt, 1); in phy_package_join()
1617 bus->shared[addr] = shared; in phy_package_join()
1619 ret = -EINVAL; in phy_package_join()
1620 if (priv_size && priv_size != shared->priv_size) in phy_package_join()
1622 refcount_inc(&shared->refcnt); in phy_package_join()
1624 mutex_unlock(&bus->shared_lock); in phy_package_join()
1626 phydev->shared = shared; in phy_package_join()
1633 mutex_unlock(&bus->shared_lock); in phy_package_join()
1639 * phy_package_leave - leave a common PHY group
1644 * freed. Resets the phydev->shared pointer to NULL.
1648 struct phy_package_shared *shared = phydev->shared; in phy_package_leave()
1649 struct mii_bus *bus = phydev->mdio.bus; in phy_package_leave()
1654 if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { in phy_package_leave()
1655 bus->shared[shared->addr] = NULL; in phy_package_leave()
1656 mutex_unlock(&bus->shared_lock); in phy_package_leave()
1657 kfree(shared->priv); in phy_package_leave()
1661 phydev->shared = NULL; in phy_package_leave()
1671 * devm_phy_package_join - resource managed phy_package_join()
1675 * @priv_size: if non-zero allocate this amount of bytes for private data
1690 return -ENOMEM; in devm_phy_package_join()
1706 * phy_detach - detach a PHY device from its network device
1714 struct net_device *dev = phydev->attached_dev; in phy_detach()
1718 if (phydev->sysfs_links) { in phy_detach()
1720 sysfs_remove_link(&dev->dev.kobj, "phydev"); in phy_detach()
1721 sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); in phy_detach()
1724 if (!phydev->attached_dev) in phy_detach()
1725 sysfs_remove_file(&phydev->mdio.dev.kobj, in phy_detach()
1730 phydev->attached_dev->phydev = NULL; in phy_detach()
1731 phydev->attached_dev = NULL; in phy_detach()
1733 phydev->phylink = NULL; in phy_detach()
1737 if (phydev->mdio.dev.driver) in phy_detach()
1738 module_put(phydev->mdio.dev.driver->owner); in phy_detach()
1740 /* If the device had no specific driver before (i.e. - it in phy_detach()
1747 device_release_driver(&phydev->mdio.dev); in phy_detach()
1751 * a use-after-free bug by reading the underlying bus first. in phy_detach()
1753 bus = phydev->mdio.bus; in phy_detach()
1755 put_device(&phydev->mdio.dev); in phy_detach()
1757 ndev_owner = dev->dev.parent->driver->owner; in phy_detach()
1758 if (ndev_owner != bus->owner) in phy_detach()
1759 module_put(bus->owner); in phy_detach()
1769 struct net_device *netdev = phydev->attached_dev; in phy_suspend()
1770 struct phy_driver *phydrv = phydev->drv; in phy_suspend()
1773 if (phydev->suspended) in phy_suspend()
1778 if (wol.wolopts || (netdev && netdev->wol_enabled)) in phy_suspend()
1779 return -EBUSY; in phy_suspend()
1781 if (!phydrv || !phydrv->suspend) in phy_suspend()
1784 ret = phydrv->suspend(phydev); in phy_suspend()
1786 phydev->suspended = true; in phy_suspend()
1794 struct phy_driver *phydrv = phydev->drv; in __phy_resume()
1797 lockdep_assert_held(&phydev->lock); in __phy_resume()
1799 if (!phydrv || !phydrv->resume) in __phy_resume()
1802 ret = phydrv->resume(phydev); in __phy_resume()
1804 phydev->suspended = false; in __phy_resume()
1814 mutex_lock(&phydev->lock); in phy_resume()
1816 mutex_unlock(&phydev->lock); in phy_resume()
1826 if (!phydev->drv) in phy_loopback()
1827 return -EIO; in phy_loopback()
1829 mutex_lock(&phydev->lock); in phy_loopback()
1831 if (enable && phydev->loopback_enabled) { in phy_loopback()
1832 ret = -EBUSY; in phy_loopback()
1836 if (!enable && !phydev->loopback_enabled) { in phy_loopback()
1837 ret = -EINVAL; in phy_loopback()
1841 if (phydev->drv->set_loopback) in phy_loopback()
1842 ret = phydev->drv->set_loopback(phydev, enable); in phy_loopback()
1849 phydev->loopback_enabled = enable; in phy_loopback()
1852 mutex_unlock(&phydev->lock); in phy_loopback()
1858 * phy_reset_after_clk_enable - perform a PHY reset if needed
1868 if (!phydev || !phydev->drv) in phy_reset_after_clk_enable()
1869 return -ENODEV; in phy_reset_after_clk_enable()
1871 if (phydev->drv->flags & PHY_RST_AFTER_CLK_EN) { in phy_reset_after_clk_enable()
1884 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
1898 linkmode_and(phydev->advertising, phydev->advertising, in genphy_config_advert()
1899 phydev->supported); in genphy_config_advert()
1901 adv = linkmode_adv_to_mii_adv_t(phydev->advertising); in genphy_config_advert()
1917 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all in genphy_config_advert()
1924 adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising); in genphy_config_advert()
1938 * genphy_c37_config_advert - sanitize and advertise auto-negotiation parameters
1945 * for Clause 37 1000Base-X mode.
1952 linkmode_and(phydev->advertising, phydev->advertising, in genphy_c37_config_advert()
1953 phydev->supported); in genphy_c37_config_advert()
1956 phydev->advertising)) in genphy_c37_config_advert()
1959 phydev->advertising)) in genphy_c37_config_advert()
1962 phydev->advertising)) in genphy_c37_config_advert()
1972 * genphy_config_eee_advert - disable unwanted eee mode advertisement
1984 if (!phydev->eee_broken_modes) in genphy_config_eee_advert()
1988 phydev->eee_broken_modes, 0); in genphy_config_eee_advert()
1989 /* If the call failed, we assume that EEE is not supported */ in genphy_config_eee_advert()
1995 * genphy_setup_forced - configures/forces speed/duplex from @phydev
2006 phydev->pause = 0; in genphy_setup_forced()
2007 phydev->asym_pause = 0; in genphy_setup_forced()
2009 if (SPEED_1000 == phydev->speed) in genphy_setup_forced()
2011 else if (SPEED_100 == phydev->speed) in genphy_setup_forced()
2014 if (DUPLEX_FULL == phydev->duplex) in genphy_setup_forced()
2026 if (!phydev->is_gigabit_capable) in genphy_setup_master_slave()
2029 switch (phydev->master_slave_set) { in genphy_setup_master_slave()
2046 return -EOPNOTSUPP; in genphy_setup_master_slave()
2059 if (!phydev->is_gigabit_capable) { in genphy_read_master_slave()
2060 phydev->master_slave_get = MASTER_SLAVE_CFG_UNSUPPORTED; in genphy_read_master_slave()
2061 phydev->master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED; in genphy_read_master_slave()
2065 phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN; in genphy_read_master_slave()
2066 phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN; in genphy_read_master_slave()
2090 } else if (phydev->link) { in genphy_read_master_slave()
2100 phydev->master_slave_get = cfg; in genphy_read_master_slave()
2101 phydev->master_slave_state = state; in genphy_read_master_slave()
2107 * genphy_restart_aneg - Enable and Restart Autonegotiation
2119 * genphy_check_and_restart_aneg - Enable and restart auto-negotiation
2123 * Check, and restart auto-negotiation if needed.
2149 * __genphy_config_aneg - restart auto-negotiation or write BMCR
2153 * Description: If auto-negotiation is enabled, we configure the
2154 * advertising, and then restart auto-negotiation. If it is not
2170 if (AUTONEG_ENABLE != phydev->autoneg) in __genphy_config_aneg()
2184 * genphy_c37_config_aneg - restart auto-negotiation or write BMCR
2187 * Description: If auto-negotiation is enabled, we configure the
2188 * advertising, and then restart auto-negotiation. If it is not
2190 * for use with Clause 37 1000Base-X mode.
2196 if (phydev->autoneg != AUTONEG_ENABLE) in genphy_c37_config_aneg()
2232 * genphy_aneg_done - return auto-negotiation status
2236 * auto-negotiation is incomplete, or if there was an error.
2237 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
2248 * genphy_update_link - update link status in @phydev
2251 * Description: Update the value in phydev->link to reflect the
2270 * drops can be detected. Do not double-read the status in genphy_update_link()
2274 if (!phy_polling_mode(phydev) || !phydev->link) { in genphy_update_link()
2287 phydev->link = status & BMSR_LSTATUS ? 1 : 0; in genphy_update_link()
2288 phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0; in genphy_update_link()
2293 if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete) in genphy_update_link()
2294 phydev->link = 0; in genphy_update_link()
2304 if (phydev->autoneg == AUTONEG_ENABLE) { in genphy_read_lpa()
2305 if (!phydev->autoneg_complete) { in genphy_read_lpa()
2306 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2308 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0); in genphy_read_lpa()
2312 if (phydev->is_gigabit_capable) { in genphy_read_lpa()
2327 return -ENOLINK; in genphy_read_lpa()
2330 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2338 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); in genphy_read_lpa()
2340 linkmode_zero(phydev->lp_advertising); in genphy_read_lpa()
2348 * genphy_read_status_fixed - read the link parameters for !aneg mode
2362 phydev->duplex = DUPLEX_FULL; in genphy_read_status_fixed()
2364 phydev->duplex = DUPLEX_HALF; in genphy_read_status_fixed()
2367 phydev->speed = SPEED_1000; in genphy_read_status_fixed()
2369 phydev->speed = SPEED_100; in genphy_read_status_fixed()
2371 phydev->speed = SPEED_10; in genphy_read_status_fixed()
2378 * genphy_read_status - check the link status and update current link state
2384 * then move on to 10/100.
2388 int err, old_link = phydev->link; in genphy_read_status()
2396 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in genphy_read_status()
2399 phydev->speed = SPEED_UNKNOWN; in genphy_read_status()
2400 phydev->duplex = DUPLEX_UNKNOWN; in genphy_read_status()
2401 phydev->pause = 0; in genphy_read_status()
2402 phydev->asym_pause = 0; in genphy_read_status()
2412 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_read_status()
2414 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_read_status()
2425 * genphy_c37_read_status - check the link status and update current link state
2430 * advertises. This function is for Clause 37 1000Base-X mode.
2434 int lpa, err, old_link = phydev->link; in genphy_c37_read_status()
2442 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in genphy_c37_read_status()
2445 phydev->duplex = DUPLEX_UNKNOWN; in genphy_c37_read_status()
2446 phydev->pause = 0; in genphy_c37_read_status()
2447 phydev->asym_pause = 0; in genphy_c37_read_status()
2449 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_c37_read_status()
2455 phydev->lp_advertising, lpa & LPA_LPACK); in genphy_c37_read_status()
2457 phydev->lp_advertising, lpa & LPA_1000XFULL); in genphy_c37_read_status()
2459 phydev->lp_advertising, lpa & LPA_1000XPAUSE); in genphy_c37_read_status()
2461 phydev->lp_advertising, in genphy_c37_read_status()
2465 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_c37_read_status()
2472 phydev->duplex = DUPLEX_FULL; in genphy_c37_read_status()
2474 phydev->duplex = DUPLEX_HALF; in genphy_c37_read_status()
2482 * genphy_soft_reset - software reset the PHY via BMCR_RESET bit
2495 if (phydev->autoneg == AUTONEG_ENABLE) in genphy_soft_reset()
2506 phydev->suspended = 0; in genphy_soft_reset()
2513 if (phydev->autoneg == AUTONEG_DISABLE) in genphy_soft_reset()
2534 * genphy_read_abilities - read PHY abilities from Clause 22 registers
2538 * phydev->supported accordingly.
2548 phydev->supported); in genphy_read_abilities()
2554 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported, in genphy_read_abilities()
2557 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2559 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2561 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2563 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2572 phydev->supported, val & ESTATUS_1000_TFULL); in genphy_read_abilities()
2574 phydev->supported, val & ESTATUS_1000_THALF); in genphy_read_abilities()
2576 phydev->supported, val & ESTATUS_1000_XFULL); in genphy_read_abilities()
2589 return -EOPNOTSUPP; in genphy_read_mmd_unsupported()
2596 return -EOPNOTSUPP; in genphy_write_mmd_unsupported()
2618 if (phydev->speed == SPEED_1000) in genphy_loopback()
2620 else if (phydev->speed == SPEED_100) in genphy_loopback()
2623 if (phydev->duplex == DUPLEX_FULL) in genphy_loopback()
2644 * phy_remove_link_mode - Remove a supported link mode
2654 linkmode_clear_bit(link_mode, phydev->supported); in phy_remove_link_mode()
2668 * phy_advertise_supported - Advertise all supported modes
2678 linkmode_copy(new, phydev->supported); in phy_advertise_supported()
2679 phy_copy_pause_bits(new, phydev->advertising); in phy_advertise_supported()
2680 linkmode_copy(phydev->advertising, new); in phy_advertise_supported()
2685 * phy_support_sym_pause - Enable support of symmetrical pause
2693 linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported); in phy_support_sym_pause()
2694 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_sym_pause()
2699 * phy_support_asym_pause - Enable support of asym pause
2706 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_asym_pause()
2711 * phy_set_sym_pause - Configure symmetric Pause
2714 * @tx: Transmit Pause is supported
2721 void phy_set_sym_pause(struct phy_device *phydev, bool rx, bool tx, in phy_set_sym_pause() argument
2724 linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported); in phy_set_sym_pause()
2726 if (rx && tx && autoneg) in phy_set_sym_pause()
2728 phydev->supported); in phy_set_sym_pause()
2730 linkmode_copy(phydev->advertising, phydev->supported); in phy_set_sym_pause()
2735 * phy_set_asym_pause - Configure Pause and Asym Pause
2738 * @tx: Transmit Pause is supported
2745 void phy_set_asym_pause(struct phy_device *phydev, bool rx, bool tx) in phy_set_asym_pause() argument
2749 linkmode_copy(oldadv, phydev->advertising); in phy_set_asym_pause()
2750 linkmode_set_pause(phydev->advertising, tx, rx); in phy_set_asym_pause()
2752 if (!linkmode_equal(oldadv, phydev->advertising) && in phy_set_asym_pause()
2753 phydev->autoneg) in phy_set_asym_pause()
2759 * phy_validate_pause - Test if the PHY/MAC support the pause configuration
2771 phydev->supported) && pp->rx_pause) in phy_validate_pause()
2775 phydev->supported) && in phy_validate_pause()
2776 pp->rx_pause != pp->tx_pause) in phy_validate_pause()
2784 * phy_get_pause - resolve negotiated pause modes
2797 if (phydev->duplex != DUPLEX_FULL) { in phy_get_pause()
2803 return linkmode_resolve_pause(phydev->advertising, in phy_get_pause()
2804 phydev->lp_advertising, in phy_get_pause()
2824 return -EINVAL; in phy_get_int_delay_property()
2829 * phy_get_internal_delay - returns the index of the internal delay
2842 * Return -EINVAL if the delay is invalid or cannot be found.
2851 delay = phy_get_int_delay_property(dev, "rx-internal-delay-ps"); in phy_get_internal_delay()
2853 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
2854 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) in phy_get_internal_delay()
2861 delay = phy_get_int_delay_property(dev, "tx-internal-delay-ps"); in phy_get_internal_delay()
2863 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
2864 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) in phy_get_internal_delay()
2877 if (delay < delay_values[0] || delay > delay_values[size - 1]) { in phy_get_internal_delay()
2879 return -EINVAL; in phy_get_internal_delay()
2890 if (delay > delay_values[i - 1] && in phy_get_internal_delay()
2892 if (delay - delay_values[i - 1] < in phy_get_internal_delay()
2893 delay_values[i] - delay) in phy_get_internal_delay()
2894 return i - 1; in phy_get_internal_delay()
2903 return -EINVAL; in phy_get_internal_delay()
2909 return phydrv->config_intr && phydrv->handle_interrupt; in phy_drv_supports_irq()
2913 * fwnode_mdio_find_device - Given a fwnode, find the mdio_device
2936 * fwnode_phy_find_device - For provided phy_fwnode, find phy_device.
2951 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) in fwnode_phy_find_device()
2952 return to_phy_device(&mdiodev->dev); in fwnode_phy_find_device()
2954 put_device(&mdiodev->dev); in fwnode_phy_find_device()
2961 * device_phy_find_device - For the given device, get the phy_device
2973 * fwnode_get_phy_node - Get the phy_node using the named reference.
2977 * For ACPI, only "phy-handle" is supported. Legacy DT properties "phy"
2978 * and "phy-device" are not supported in ACPI. DT supports all the three
2985 /* Only phy-handle is used for ACPI */ in fwnode_get_phy_node()
2986 phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); in fwnode_get_phy_node()
2991 phy_node = fwnode_find_reference(fwnode, "phy-device", 0); in fwnode_get_phy_node()
2997 * phy_probe - probe and init a PHY device
3007 struct device_driver *drv = phydev->mdio.dev.driver; in phy_probe()
3011 phydev->drv = phydrv; in phy_probe()
3017 phydev->irq = PHY_POLL; in phy_probe()
3019 if (phydrv->flags & PHY_IS_INTERNAL) in phy_probe()
3020 phydev->is_internal = true; in phy_probe()
3022 mutex_lock(&phydev->lock); in phy_probe()
3027 if (phydev->drv->probe) { in phy_probe()
3028 err = phydev->drv->probe(phydev); in phy_probe()
3037 if (phydrv->features) in phy_probe()
3038 linkmode_copy(phydev->supported, phydrv->features); in phy_probe()
3039 else if (phydrv->get_features) in phy_probe()
3040 err = phydrv->get_features(phydev); in phy_probe()
3041 else if (phydev->is_c45) in phy_probe()
3050 phydev->supported)) in phy_probe()
3051 phydev->autoneg = 0; in phy_probe()
3054 phydev->supported)) in phy_probe()
3055 phydev->is_gigabit_capable = 1; in phy_probe()
3057 phydev->supported)) in phy_probe()
3058 phydev->is_gigabit_capable = 1; in phy_probe()
3063 /* Get the EEE modes we want to prohibit. We will ask in phy_probe()
3079 if (!test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported) && in phy_probe()
3080 !test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported)) { in phy_probe()
3082 phydev->supported); in phy_probe()
3084 phydev->supported); in phy_probe()
3088 phydev->state = PHY_READY; in phy_probe()
3095 mutex_unlock(&phydev->lock); in phy_probe()
3104 cancel_delayed_work_sync(&phydev->state_queue); in phy_remove()
3106 mutex_lock(&phydev->lock); in phy_remove()
3107 phydev->state = PHY_DOWN; in phy_remove()
3108 mutex_unlock(&phydev->lock); in phy_remove()
3110 sfp_bus_del_upstream(phydev->sfp_bus); in phy_remove()
3111 phydev->sfp_bus = NULL; in phy_remove()
3113 if (phydev->drv && phydev->drv->remove) in phy_remove()
3114 phydev->drv->remove(phydev); in phy_remove()
3119 phydev->drv = NULL; in phy_remove()
3128 if (phydev->state == PHY_READY || !phydev->attached_dev) in phy_shutdown()
3135 * phy_driver_register - register a phy_driver with the PHY layer
3146 if (WARN_ON(new_driver->features && new_driver->get_features)) { in phy_driver_register()
3148 new_driver->name); in phy_driver_register()
3149 return -EINVAL; in phy_driver_register()
3152 new_driver->mdiodrv.flags |= MDIO_DEVICE_IS_PHY; in phy_driver_register()
3153 new_driver->mdiodrv.driver.name = new_driver->name; in phy_driver_register()
3154 new_driver->mdiodrv.driver.bus = &mdio_bus_type; in phy_driver_register()
3155 new_driver->mdiodrv.driver.probe = phy_probe; in phy_driver_register()
3156 new_driver->mdiodrv.driver.remove = phy_remove; in phy_driver_register()
3157 new_driver->mdiodrv.driver.shutdown = phy_shutdown; in phy_driver_register()
3158 new_driver->mdiodrv.driver.owner = owner; in phy_driver_register()
3159 new_driver->mdiodrv.driver.probe_type = PROBE_FORCE_SYNCHRONOUS; in phy_driver_register()
3161 retval = driver_register(&new_driver->mdiodrv.driver); in phy_driver_register()
3164 new_driver->name, retval); in phy_driver_register()
3169 pr_debug("%s: Registered new driver\n", new_driver->name); in phy_driver_register()
3183 while (i-- > 0) in phy_drivers_register()
3194 driver_unregister(&drv->mdiodrv.driver); in phy_driver_unregister()