Lines Matching +full:t +full:- +full:phy

1 // SPDX-License-Identifier: GPL-2.0+
3 * Also contains generic PHY driver
29 #include <linux/phy.h>
33 #include <linux/pse-pd/pse.h>
43 MODULE_DESCRIPTION("PHY library");
252 put_device(&phydev->mdio.dev); in phy_device_free()
266 fwnode_handle_put(dev->fwnode); in phy_device_release()
294 struct device_driver *drv = phydev->mdio.dev.driver; in mdio_bus_phy_may_suspend()
296 struct net_device *netdev = phydev->attached_dev; in mdio_bus_phy_may_suspend()
298 if (!drv || !phydrv->suspend) in mdio_bus_phy_may_suspend()
301 /* If the PHY on the mido bus is not attached but has WOL enabled in mdio_bus_phy_may_suspend()
302 * we cannot suspend the PHY. in mdio_bus_phy_may_suspend()
307 /* PHY not attached? May suspend if the PHY has not already been in mdio_bus_phy_may_suspend()
308 * suspended as part of a prior call to phy_disconnect() -> in mdio_bus_phy_may_suspend()
309 * phy_detach() -> phy_suspend() because the parent netdev might be the in mdio_bus_phy_may_suspend()
315 if (netdev->ethtool->wol_enabled) in mdio_bus_phy_may_suspend()
320 * Don't suspend PHY if the attached netdev parent may wake up. in mdio_bus_phy_may_suspend()
323 if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent)) in mdio_bus_phy_may_suspend()
326 /* Also don't suspend PHY if the netdev itself may wakeup. This in mdio_bus_phy_may_suspend()
330 if (device_may_wakeup(&netdev->dev)) in mdio_bus_phy_may_suspend()
334 return !phydev->suspended; in mdio_bus_phy_may_suspend()
341 if (phydev->mac_managed_pm) in mdio_bus_phy_suspend()
345 * the PHY is inaccessible. Set flag to postpone handling until the PHY in mdio_bus_phy_suspend()
349 phydev->irq_suspended = 1; in mdio_bus_phy_suspend()
350 synchronize_irq(phydev->irq); in mdio_bus_phy_suspend()
354 * control, possibly with the phydev->lock held. Upon resume, netdev in mdio_bus_phy_suspend()
355 * may call phy routines that try to grab the same lock, and that may in mdio_bus_phy_suspend()
358 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_suspend()
364 phydev->suspended_by_mdio_bus = 1; in mdio_bus_phy_suspend()
374 if (phydev->mac_managed_pm) in mdio_bus_phy_resume()
377 if (!phydev->suspended_by_mdio_bus) in mdio_bus_phy_resume()
380 phydev->suspended_by_mdio_bus = 0; in mdio_bus_phy_resume()
382 /* If we managed to get here with the PHY state machine in a state in mdio_bus_phy_resume()
387 WARN_ON(phydev->state != PHY_HALTED && phydev->state != PHY_READY && in mdio_bus_phy_resume()
388 phydev->state != PHY_UP); in mdio_bus_phy_resume()
399 phydev->irq_suspended = 0; in mdio_bus_phy_resume()
400 synchronize_irq(phydev->irq); in mdio_bus_phy_resume()
405 if (phydev->irq_rerun) { in mdio_bus_phy_resume()
406 phydev->irq_rerun = 0; in mdio_bus_phy_resume()
407 enable_irq(phydev->irq); in mdio_bus_phy_resume()
408 irq_wake_thread(phydev->irq, phydev); in mdio_bus_phy_resume()
412 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_resume()
422 * phy_register_fixup - creates a new phy_fixup and adds it to the list
423 * @bus_id: A string which matches phydev->mdio.dev.bus_id (or PHY_ANY_ID)
424 * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY)
426 * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before
428 * @run: The actual code to be run when a matching PHY is found
436 return -ENOMEM; in phy_register_fixup()
438 strscpy(fixup->bus_id, bus_id, sizeof(fixup->bus_id)); in phy_register_fixup()
439 fixup->phy_uid = phy_uid; in phy_register_fixup()
440 fixup->phy_uid_mask = phy_uid_mask; in phy_register_fixup()
441 fixup->run = run; in phy_register_fixup()
444 list_add_tail(&fixup->list, &phy_fixup_list); in phy_register_fixup()
451 /* Registers a fixup to be run on any PHY with the UID in phy_uid */
459 /* Registers a fixup to be run on the PHY with id string bus_id */
468 * phy_unregister_fixup - remove a phy_fixup from the list
469 * @bus_id: A string matches fixup->bus_id (or PHY_ANY_ID) in phy_fixup_list
470 * @phy_uid: A phy id matches fixup->phy_id (or PHY_ANY_UID) in phy_fixup_list
471 * @phy_uid_mask: Applied to phy_uid and fixup->phy_uid before comparison
479 ret = -ENODEV; in phy_unregister_fixup()
485 if ((!strcmp(fixup->bus_id, bus_id)) && in phy_unregister_fixup()
486 phy_id_compare(fixup->phy_uid, phy_uid, phy_uid_mask)) { in phy_unregister_fixup()
487 list_del(&fixup->list); in phy_unregister_fixup()
499 /* Unregisters a fixup of any PHY with the UID in phy_uid */
506 /* Unregisters a fixup of the PHY with id string bus_id */
518 if (strcmp(fixup->bus_id, phydev_name(phydev)) != 0) in phy_needs_fixup()
519 if (strcmp(fixup->bus_id, PHY_ANY_ID) != 0) in phy_needs_fixup()
522 if (!phy_id_compare(phydev->phy_id, fixup->phy_uid, in phy_needs_fixup()
523 fixup->phy_uid_mask)) in phy_needs_fixup()
524 if (fixup->phy_uid != PHY_ANY_UID) in phy_needs_fixup()
538 int err = fixup->run(phydev); in phy_scan_fixups()
544 phydev->has_fixups = true; in phy_scan_fixups()
556 const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids); in phy_bus_match()
559 if (!(phydrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY)) in phy_bus_match()
562 if (phydrv->match_phy_device) in phy_bus_match()
563 return phydrv->match_phy_device(phydev); in phy_bus_match()
565 if (phydev->is_c45) { in phy_bus_match()
567 if (phydev->c45_ids.device_ids[i] == 0xffffffff) in phy_bus_match()
570 if (phy_id_compare(phydev->c45_ids.device_ids[i], in phy_bus_match()
571 phydrv->phy_id, phydrv->phy_id_mask)) in phy_bus_match()
576 return phy_id_compare(phydev->phy_id, phydrv->phy_id, in phy_bus_match()
577 phydrv->phy_id_mask); in phy_bus_match()
586 return sysfs_emit(buf, "0x%.8lx\n", (unsigned long)phydev->phy_id); in phy_id_show()
599 mode = phy_modes(phydev->interface); in phy_interface_show()
611 return sysfs_emit(buf, "%d\n", phydev->has_fixups); in phy_has_fixups_show()
621 return sysfs_emit(buf, "0x%08x\n", phydev->dev_flags); in phy_dev_flags_show()
635 .name = "PHY",
648 * not whether a PHY driver module exists for the PHY ID. in phy_request_driver_module()
649 * Accept -ENOENT because this may occur in case no initramfs exists, in phy_request_driver_module()
650 * then modprobe isn't available. in phy_request_driver_module()
652 if (IS_ENABLED(CONFIG_MODULES) && ret < 0 && ret != -ENOENT) { in phy_request_driver_module()
653 phydev_err(dev, "error %d loading PHY driver module for ID 0x%08lx\n", in phy_request_driver_module()
672 return ERR_PTR(-ENOMEM); in phy_device_create()
674 mdiodev = &dev->mdio; in phy_device_create()
675 mdiodev->dev.parent = &bus->dev; in phy_device_create()
676 mdiodev->dev.bus = &mdio_bus_type; in phy_device_create()
677 mdiodev->dev.type = &mdio_bus_phy_type; in phy_device_create()
678 mdiodev->bus = bus; in phy_device_create()
679 mdiodev->bus_match = phy_bus_match; in phy_device_create()
680 mdiodev->addr = addr; in phy_device_create()
681 mdiodev->flags = MDIO_DEVICE_FLAG_PHY; in phy_device_create()
682 mdiodev->device_free = phy_mdio_device_free; in phy_device_create()
683 mdiodev->device_remove = phy_mdio_device_remove; in phy_device_create()
684 mdiodev->reset_state = -1; in phy_device_create()
686 dev->speed = SPEED_UNKNOWN; in phy_device_create()
687 dev->duplex = DUPLEX_UNKNOWN; in phy_device_create()
688 dev->pause = 0; in phy_device_create()
689 dev->asym_pause = 0; in phy_device_create()
690 dev->link = 0; in phy_device_create()
691 dev->port = PORT_TP; in phy_device_create()
692 dev->interface = PHY_INTERFACE_MODE_GMII; in phy_device_create()
694 dev->autoneg = AUTONEG_ENABLE; in phy_device_create()
696 dev->pma_extable = -ENODATA; in phy_device_create()
697 dev->is_c45 = is_c45; in phy_device_create()
698 dev->phy_id = phy_id; in phy_device_create()
700 dev->c45_ids = *c45_ids; in phy_device_create()
701 dev->irq = bus->irq[addr]; in phy_device_create()
703 dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr); in phy_device_create()
704 device_initialize(&mdiodev->dev); in phy_device_create()
706 dev->state = PHY_DOWN; in phy_device_create()
707 INIT_LIST_HEAD(&dev->leds); in phy_device_create()
709 mutex_init(&dev->lock); in phy_device_create()
710 INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); in phy_device_create()
712 /* Request the appropriate module unconditionally; don't in phy_device_create()
713 * bother trying to do so only if it isn't already loaded, in phy_device_create()
716 * We don't do normal hotplug because it won't work for MDIO in phy_device_create()
717 * -- because it relies on the device staying around for long in phy_device_create()
723 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in phy_device_create()
727 if (c45_ids->device_ids[i] == 0xffffffff) in phy_device_create()
731 c45_ids->device_ids[i]); in phy_device_create()
740 put_device(&mdiodev->dev); in phy_device_create()
748 /* phy_c45_probe_present - checks to see if a MMD is present in the package
750 * @prtad: PHY package address on the MII bus
751 * @devad: PHY device (MMD) address
770 /* get_phy_c45_devs_in_pkg - reads a MMD's devices in package registers.
772 * @addr: PHY address on the MII bus
773 * @dev_addr: MMD address in the PHY.
777 * from PHY at @addr on @bus.
779 * Returns: 0 on success, -EIO on failure.
788 return -EIO; in get_phy_c45_devs_in_pkg()
793 return -EIO; in get_phy_c45_devs_in_pkg()
800 * get_phy_c45_ids - reads the specified addr for its 802.3-c45 IDs.
802 * @addr: PHY address on the MII bus
805 * Read the PHY "devices in package". If this appears to be valid, read
806 * the PHY identifiers for each device. Return the "devices in package"
809 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
815 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in get_phy_c45_ids()
819 /* Find first non-zero Devices In package. Device zero is reserved in get_phy_c45_ids()
820 * for 802.3 c45 complied PHYs, so don't probe it at first. in get_phy_c45_ids()
826 * address before reading the devices-in-package in get_phy_c45_ids()
827 * register to avoid reading garbage from the PHY. in get_phy_c45_ids()
833 /* returning -ENODEV doesn't stop bus in get_phy_c45_ids()
836 return (phy_reg == -EIO || in get_phy_c45_ids()
837 phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c45_ids()
844 return -EIO; in get_phy_c45_ids()
850 * e.g. Cortina CS4315/CS4340 PHY. in get_phy_c45_ids()
854 return -EIO; in get_phy_c45_ids()
858 return -ENODEV; in get_phy_c45_ids()
881 return -EIO; in get_phy_c45_ids()
882 c45_ids->device_ids[i] = phy_reg << 16; in get_phy_c45_ids()
886 return -EIO; in get_phy_c45_ids()
887 c45_ids->device_ids[i] |= phy_reg; in get_phy_c45_ids()
890 c45_ids->devices_in_package = devs_in_pkg; in get_phy_c45_ids()
891 /* Bit 0 doesn't represent a device, it indicates c22 regs presence */ in get_phy_c45_ids()
892 c45_ids->mmds_present = devs_in_pkg & ~BIT(0); in get_phy_c45_ids()
898 * get_phy_c22_id - reads the specified addr for its clause 22 ID.
900 * @addr: PHY address on the MII bus
903 * Read the 802.3 clause 22 PHY ID from the PHY at @addr on the @bus,
905 * valid, %-EIO on bus access error, or %-ENODEV if no device responds
915 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
916 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
924 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
925 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
932 return -ENODEV; in get_phy_c22_id()
937 /* Extract the phy ID from the compatible string of the form
938 * ethernet-phy-idAAAA.BBBB.
950 if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) != 2) in fwnode_get_phy_id()
951 return -EINVAL; in fwnode_get_phy_id()
959 * get_phy_device - reads the specified PHY device and returns its @phy_device
962 * @addr: PHY address on the MII bus
963 * @is_c45: If true the PHY uses the 802.3 clause 45 protocol
965 * Probe for a PHY at @addr on @bus.
967 * When probing for a clause 22 PHY, then read the ID registers. If we find
970 * When probing for a clause 45 PHY, read the "devices in package" registers.
974 * Returns an allocated &struct phy_device on success, %-ENODEV if there is
975 * no PHY present, or %-EIO on bus access error.
995 /* PHY device such as the Marvell Alaska 88E2110 will return a PHY ID in get_phy_device()
997 * probe with C45 to see if we're able to get a valid PHY ID in the C45 in get_phy_device()
998 * space, if successful, create the C45 PHY device. in get_phy_device()
1000 if (!is_c45 && phy_id == 0 && bus->read_c45) { in get_phy_device()
1012 * phy_device_register - Register the phy device on the MDIO bus
1019 err = mdiobus_register_device(&phydev->mdio); in phy_device_register()
1026 /* Run all of the fixups for this PHY */ in phy_device_register()
1033 err = device_add(&phydev->mdio.dev); in phy_device_register()
1045 mdiobus_unregister_device(&phydev->mdio); in phy_device_register()
1051 * phy_device_remove - Remove a previously registered phy device from the MDIO bus
1054 * This doesn't free the phy_device itself, it merely reverses the effects
1060 unregister_mii_timestamper(phydev->mii_ts); in phy_device_remove()
1061 pse_control_put(phydev->psec); in phy_device_remove()
1063 device_del(&phydev->mdio.dev); in phy_device_remove()
1068 mdiobus_unregister_device(&phydev->mdio); in phy_device_remove()
1073 * phy_get_c45_ids - Read 802.3-c45 IDs for phy device.
1074 * @phydev: phy_device structure to read 802.3-c45 IDs
1076 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
1081 return get_phy_c45_ids(phydev->mdio.bus, phydev->mdio.addr, in phy_get_c45_ids()
1082 &phydev->c45_ids); in phy_get_c45_ids()
1087 * phy_find_first - finds the first PHY device on the bus
1106 struct net_device *netdev = phydev->attached_dev; in phy_link_change()
1112 phydev->adjust_link(netdev); in phy_link_change()
1113 if (phydev->mii_ts && phydev->mii_ts->link_state) in phy_link_change()
1114 phydev->mii_ts->link_state(phydev->mii_ts, phydev); in phy_link_change()
1118 * phy_prepare_link - prepares the PHY layer to monitor link status
1122 * Description: Tells the PHY infrastructure to handle the
1126 * If you want to monitor your own link state, don't call
1132 phydev->adjust_link = handler; in phy_prepare_link()
1136 * phy_connect_direct - connect an ethernet device to a specific phy_device
1138 * @phydev: the pointer to the phy device
1140 * @interface: PHY device's interface
1149 return -EINVAL; in phy_connect_direct()
1151 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_connect_direct()
1164 * phy_connect - connect an ethernet device to a PHY device
1166 * @bus_id: the id string of the PHY device to connect
1168 * @interface: PHY device's interface
1171 * devices to PHY devices. The default behavior is for
1172 * the PHY infrastructure to handle everything, and only notify
1174 * don't want, or can't use the provided functionality, you may
1186 /* Search the list of PHY devices on the mdio bus for the in phy_connect()
1187 * PHY with the requested name in phy_connect()
1191 pr_err("PHY %s not found\n", bus_id); in phy_connect()
1192 return ERR_PTR(-ENODEV); in phy_connect()
1206 * phy_disconnect - disable interrupts, stop state machine, and detach a PHY
1218 phydev->adjust_link = NULL; in phy_disconnect()
1225 * phy_poll_reset - Safely wait until a PHY reset has properly completed
1226 * @phydev: The PHY device to poll
1229 * published in 2008, a PHY reset may take up to 0.5 seconds. The MII BMCR
1232 * Furthermore, any attempts to write to PHY registers may have no effect
1235 * Some PHYs (such as the Marvell 88E1111) don't entirely conform to the
1237 * even *REQUIRE* a soft-reset to properly restart autonegotiation. In an
1240 * and reapply all driver-specific and board-specific fixups.
1265 if (!phydev->drv) in phy_init_hw()
1268 if (phydev->drv->soft_reset) { in phy_init_hw()
1269 ret = phydev->drv->soft_reset(phydev); in phy_init_hw()
1274 phydev->suspended = 0; in phy_init_hw()
1281 phy_interface_zero(phydev->possible_interfaces); in phy_init_hw()
1283 if (phydev->drv->config_init) { in phy_init_hw()
1284 ret = phydev->drv->config_init(phydev); in phy_init_hw()
1289 if (phydev->drv->config_intr) { in phy_init_hw()
1290 ret = phydev->drv->config_intr(phydev); in phy_init_hw()
1305 #define ATTACHED_FMT "attached PHY driver %s(mii_bus:phy_addr=%s, irq=%s)"
1311 switch(phydev->irq) { in phy_attached_info_irq()
1319 snprintf(irq_num, sizeof(irq_num), "%d", phydev->irq); in phy_attached_info_irq()
1330 const char *unbound = phydev->drv ? "" : "[unbound] "; in phy_attached_print()
1352 struct net_device *dev = phydev->attached_dev; in phy_sysfs_create_links()
1358 err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, in phy_sysfs_create_links()
1363 err = sysfs_create_link_nowarn(&dev->dev.kobj, in phy_sysfs_create_links()
1364 &phydev->mdio.dev.kobj, in phy_sysfs_create_links()
1367 dev_err(&dev->dev, "could not add device link to %s err %d\n", in phy_sysfs_create_links()
1368 kobject_name(&phydev->mdio.dev.kobj), in phy_sysfs_create_links()
1370 /* non-fatal - some net drivers can use one netdevice in phy_sysfs_create_links()
1371 * with more then one phy in phy_sysfs_create_links()
1375 phydev->sysfs_links = true; in phy_sysfs_create_links()
1384 return sysfs_emit(buf, "%d\n", !phydev->attached_dev); in phy_standalone_show()
1389 * phy_sfp_connect_phy - Connect the SFP module's PHY to the upstream PHY
1390 * @upstream: pointer to the upstream phy device
1391 * @phy: pointer to the SFP module's phy device
1393 * This helper allows keeping track of PHY devices on the link. It adds the
1394 * SFP module's phy to the phy namespace of the upstream phy
1398 int phy_sfp_connect_phy(void *upstream, struct phy_device *phy) in phy_sfp_connect_phy() argument
1401 struct net_device *dev = phydev->attached_dev; in phy_sfp_connect_phy()
1404 return phy_link_topo_add_phy(dev, phy, PHY_UPSTREAM_PHY, phydev); in phy_sfp_connect_phy()
1411 * phy_sfp_disconnect_phy - Disconnect the SFP module's PHY from the upstream PHY
1412 * @upstream: pointer to the upstream phy device
1413 * @phy: pointer to the SFP module's phy device
1415 * This helper allows keeping track of PHY devices on the link. It removes the
1416 * SFP module's phy to the phy namespace of the upstream phy. As the module phy
1417 * will be destroyed, re-inserting the same module will add a new phy with a
1420 void phy_sfp_disconnect_phy(void *upstream, struct phy_device *phy) in phy_sfp_disconnect_phy() argument
1423 struct net_device *dev = phydev->attached_dev; in phy_sfp_disconnect_phy()
1426 phy_link_topo_del_phy(dev, phy); in phy_sfp_disconnect_phy()
1431 * phy_sfp_attach - attach the SFP bus to the PHY upstream network device
1432 * @upstream: pointer to the phy device
1441 if (phydev->attached_dev) in phy_sfp_attach()
1442 phydev->attached_dev->sfp_bus = bus; in phy_sfp_attach()
1443 phydev->sfp_bus_attached = true; in phy_sfp_attach()
1448 * phy_sfp_detach - detach the SFP bus from the PHY upstream network device
1449 * @upstream: pointer to the phy device
1458 if (phydev->attached_dev) in phy_sfp_detach()
1459 phydev->attached_dev->sfp_bus = NULL; in phy_sfp_detach()
1460 phydev->sfp_bus_attached = false; in phy_sfp_detach()
1465 * phy_sfp_probe - probe for a SFP cage attached to this PHY device
1475 if (phydev->mdio.dev.fwnode) { in phy_sfp_probe()
1476 bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); in phy_sfp_probe()
1480 phydev->sfp_bus = bus; in phy_sfp_probe()
1491 return phydrv->config_intr && phydrv->handle_interrupt; in phy_drv_supports_irq()
1495 * phy_attach_direct - attach a network device to a given PHY device pointer
1498 * @flags: PHY device's dev_flags
1499 * @interface: PHY device's interface
1501 * Description: Called by drivers to attach to a particular PHY
1507 * This function takes a reference on the phy device.
1512 struct mii_bus *bus = phydev->mdio.bus; in phy_attach_direct()
1513 struct device *d = &phydev->mdio.dev; in phy_attach_direct()
1519 * will have bus->owner match ndev_mod, so we do not want to increment in phy_attach_direct()
1520 * our own module->refcnt here, otherwise we would not be able to in phy_attach_direct()
1524 ndev_owner = dev->dev.parent->driver->owner; in phy_attach_direct()
1525 if (ndev_owner != bus->owner && !try_module_get(bus->owner)) { in phy_attach_direct()
1527 return -EIO; in phy_attach_direct()
1532 /* Assume that if there is no driver, that it doesn't in phy_attach_direct()
1535 if (!d->driver) { in phy_attach_direct()
1536 if (phydev->is_c45) in phy_attach_direct()
1537 d->driver = &genphy_c45_driver.mdiodrv.driver; in phy_attach_direct()
1539 d->driver = &genphy_driver.mdiodrv.driver; in phy_attach_direct()
1544 if (!try_module_get(d->driver->owner)) { in phy_attach_direct()
1546 err = -EIO; in phy_attach_direct()
1551 err = d->driver->probe(d); in phy_attach_direct()
1559 if (phydev->attached_dev) { in phy_attach_direct()
1560 dev_err(&dev->dev, "PHY already attached\n"); in phy_attach_direct()
1561 err = -EBUSY; in phy_attach_direct()
1565 phydev->phy_link_change = phy_link_change; in phy_attach_direct()
1567 phydev->attached_dev = dev; in phy_attach_direct()
1568 dev->phydev = phydev; in phy_attach_direct()
1570 if (phydev->sfp_bus_attached) in phy_attach_direct()
1571 dev->sfp_bus = phydev->sfp_bus; in phy_attach_direct()
1578 /* Some Ethernet drivers try to connect to a PHY device before in phy_attach_direct()
1579 * calling register_netdevice() -> netdev_register_kobject() and in phy_attach_direct()
1580 * does the dev->dev.kobj initialization. Here we only check for in phy_attach_direct()
1586 phydev->sysfs_links = false; in phy_attach_direct()
1590 if (!phydev->attached_dev) { in phy_attach_direct()
1591 err = sysfs_create_file(&phydev->mdio.dev.kobj, in phy_attach_direct()
1597 phydev->dev_flags |= flags; in phy_attach_direct()
1599 phydev->interface = interface; in phy_attach_direct()
1601 phydev->state = PHY_READY; in phy_attach_direct()
1603 phydev->interrupts = PHY_INTERRUPT_DISABLED; in phy_attach_direct()
1609 if (phydev->dev_flags & PHY_F_NO_IRQ) in phy_attach_direct()
1610 phydev->irq = PHY_POLL; in phy_attach_direct()
1612 if (!phy_drv_supports_irq(phydev->drv) && phy_interrupt_is_valid(phydev)) in phy_attach_direct()
1613 phydev->irq = PHY_POLL; in phy_attach_direct()
1615 /* Port is set to PORT_TP by default and the actual PHY driver will set in phy_attach_direct()
1616 * it to different value depending on the PHY configuration. If we have in phy_attach_direct()
1617 * the generic PHY driver we can't figure it out, thus set the old in phy_attach_direct()
1621 phydev->port = PORT_MII; in phy_attach_direct()
1623 /* Initial carrier state is off as the phy is about to be in phy_attach_direct()
1627 netif_carrier_off(phydev->attached_dev); in phy_attach_direct()
1638 if (!phydev->is_on_sfp_module) in phy_attach_direct()
1642 * If the external phy used by current mac interface is managed by in phy_attach_direct()
1644 * phy dev and mac dev. in phy_attach_direct()
1646 if (dev && phydev->mdio.bus->parent && dev->dev.parent != phydev->mdio.bus->parent) in phy_attach_direct()
1647 phydev->devlink = device_link_add(dev->dev.parent, &phydev->mdio.dev, in phy_attach_direct()
1658 module_put(d->driver->owner); in phy_attach_direct()
1659 d->driver = NULL; in phy_attach_direct()
1662 if (ndev_owner != bus->owner) in phy_attach_direct()
1663 module_put(bus->owner); in phy_attach_direct()
1669 * phy_attach - attach a network device to a particular PHY device
1671 * @bus_id: Bus ID of PHY device to attach
1672 * @interface: PHY device's interface
1674 * Description: Same as phy_attach_direct() except that a PHY bus_id
1685 return ERR_PTR(-EINVAL); in phy_attach()
1687 /* Search the list of PHY devices on the mdio bus for the in phy_attach()
1688 * PHY with the requested name in phy_attach()
1692 pr_err("PHY %s not found\n", bus_id); in phy_attach()
1693 return ERR_PTR(-ENODEV); in phy_attach()
1697 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_attach()
1709 struct device *d = &phydev->mdio.dev; in phy_driver_is_genphy_kind()
1712 if (!phydev->drv) in phy_driver_is_genphy_kind()
1716 ret = d->driver == driver; in phy_driver_is_genphy_kind()
1737 * phy_package_join - join a common PHY group
1739 * @base_addr: cookie and base PHY address of PHY package for offset
1741 * @priv_size: if non-zero allocate this amount of bytes for private data
1743 * This joins a PHY group and provides a shared storage for all phydevs in
1745 * more than one PHY, for example a quad PHY transceiver.
1748 * for all members of one group and as the base PHY address of the PHY package
1749 * for offset calculation to access generic registers of a PHY package.
1750 * Usually, one of the PHY addresses of the different PHYs in the package
1758 * allocated. If priv_size is non-zero, the given amount of bytes are
1766 struct mii_bus *bus = phydev->mdio.bus; in phy_package_join()
1771 return -EINVAL; in phy_package_join()
1773 mutex_lock(&bus->shared_lock); in phy_package_join()
1774 shared = bus->shared[base_addr]; in phy_package_join()
1776 ret = -ENOMEM; in phy_package_join()
1781 shared->priv = kzalloc(priv_size, GFP_KERNEL); in phy_package_join()
1782 if (!shared->priv) in phy_package_join()
1784 shared->priv_size = priv_size; in phy_package_join()
1786 shared->base_addr = base_addr; in phy_package_join()
1787 shared->np = NULL; in phy_package_join()
1788 refcount_set(&shared->refcnt, 1); in phy_package_join()
1789 bus->shared[base_addr] = shared; in phy_package_join()
1791 ret = -EINVAL; in phy_package_join()
1792 if (priv_size && priv_size != shared->priv_size) in phy_package_join()
1794 refcount_inc(&shared->refcnt); in phy_package_join()
1796 mutex_unlock(&bus->shared_lock); in phy_package_join()
1798 phydev->shared = shared; in phy_package_join()
1805 mutex_unlock(&bus->shared_lock); in phy_package_join()
1811 * of_phy_package_join - join a common PHY group in PHY package
1813 * @priv_size: if non-zero allocate this amount of bytes for private data
1815 * This is a variant of phy_package_join for PHY package defined in DT.
1817 * The parent node of the @phydev is checked as a valid PHY package node
1818 * structure (by matching the node name "ethernet-phy-package") and the
1819 * base_addr for the PHY package is passed to phy_package_join.
1822 * filled to use additional DT defined properties in PHY specific
1823 * probe_once and config_init_once PHY package OPs.
1827 * node is not detected or is not valid or doesn't match the expected node
1828 * name for PHY package.
1832 struct device_node *node = phydev->mdio.dev.of_node; in of_phy_package_join()
1838 return -EINVAL; in of_phy_package_join()
1842 return -EINVAL; in of_phy_package_join()
1844 if (!of_node_name_eq(package_node, "ethernet-phy-package")) { in of_phy_package_join()
1845 ret = -EINVAL; in of_phy_package_join()
1850 ret = -EINVAL; in of_phy_package_join()
1858 phydev->shared->np = package_node; in of_phy_package_join()
1868 * phy_package_leave - leave a common PHY group
1871 * This leaves a PHY group created by phy_package_join(). If this phydev
1873 * freed. Resets the phydev->shared pointer to NULL.
1877 struct phy_package_shared *shared = phydev->shared; in phy_package_leave()
1878 struct mii_bus *bus = phydev->mdio.bus; in phy_package_leave()
1884 if (shared->np) in phy_package_leave()
1885 of_node_put(shared->np); in phy_package_leave()
1887 if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { in phy_package_leave()
1888 bus->shared[shared->base_addr] = NULL; in phy_package_leave()
1889 mutex_unlock(&bus->shared_lock); in phy_package_leave()
1890 kfree(shared->priv); in phy_package_leave()
1894 phydev->shared = NULL; in phy_package_leave()
1904 * devm_phy_package_join - resource managed phy_package_join()
1905 * @dev: device that is registering this PHY package
1907 * @base_addr: cookie and base PHY address of PHY package for offset
1909 * @priv_size: if non-zero allocate this amount of bytes for private data
1924 return -ENOMEM; in devm_phy_package_join()
1940 * devm_of_phy_package_join - resource managed of_phy_package_join()
1941 * @dev: device that is registering this PHY package
1943 * @priv_size: if non-zero allocate this amount of bytes for private data
1958 return -ENOMEM; in devm_of_phy_package_join()
1974 * phy_detach - detach a PHY device from its network device
1977 * This detaches the phy device from its network device and the phy
1982 struct net_device *dev = phydev->attached_dev; in phy_detach()
1986 if (phydev->devlink) in phy_detach()
1987 device_link_del(phydev->devlink); in phy_detach()
1989 if (phydev->sysfs_links) { in phy_detach()
1991 sysfs_remove_link(&dev->dev.kobj, "phydev"); in phy_detach()
1992 sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); in phy_detach()
1995 if (!phydev->attached_dev) in phy_detach()
1996 sysfs_remove_file(&phydev->mdio.dev.kobj, in phy_detach()
2001 phydev->attached_dev->phydev = NULL; in phy_detach()
2002 phydev->attached_dev = NULL; in phy_detach()
2005 phydev->phylink = NULL; in phy_detach()
2007 if (!phydev->is_on_sfp_module) in phy_detach()
2010 if (phydev->mdio.dev.driver) in phy_detach()
2011 module_put(phydev->mdio.dev.driver->owner); in phy_detach()
2013 /* If the device had no specific driver before (i.e. - it in phy_detach()
2020 device_release_driver(&phydev->mdio.dev); in phy_detach()
2027 * a use-after-free bug by reading the underlying bus first. in phy_detach()
2029 bus = phydev->mdio.bus; in phy_detach()
2031 put_device(&phydev->mdio.dev); in phy_detach()
2033 ndev_owner = dev->dev.parent->driver->owner; in phy_detach()
2034 if (ndev_owner != bus->owner) in phy_detach()
2035 module_put(bus->owner); in phy_detach()
2041 struct net_device *netdev = phydev->attached_dev; in phy_suspend()
2042 const struct phy_driver *phydrv = phydev->drv; in phy_suspend()
2045 if (phydev->suspended || !phydrv) in phy_suspend()
2048 phydev->wol_enabled = phy_drv_wol_enabled(phydev) || in phy_suspend()
2049 (netdev && netdev->ethtool->wol_enabled); in phy_suspend()
2050 /* If the device has WOL enabled, we cannot suspend the PHY */ in phy_suspend()
2051 if (phydev->wol_enabled && !(phydrv->flags & PHY_ALWAYS_CALL_SUSPEND)) in phy_suspend()
2052 return -EBUSY; in phy_suspend()
2054 if (!phydrv->suspend) in phy_suspend()
2057 ret = phydrv->suspend(phydev); in phy_suspend()
2059 phydev->suspended = true; in phy_suspend()
2067 const struct phy_driver *phydrv = phydev->drv; in __phy_resume()
2070 lockdep_assert_held(&phydev->lock); in __phy_resume()
2072 if (!phydrv || !phydrv->resume) in __phy_resume()
2075 ret = phydrv->resume(phydev); in __phy_resume()
2077 phydev->suspended = false; in __phy_resume()
2087 mutex_lock(&phydev->lock); in phy_resume()
2089 mutex_unlock(&phydev->lock); in phy_resume()
2099 if (!phydev->drv) in phy_loopback()
2100 return -EIO; in phy_loopback()
2102 mutex_lock(&phydev->lock); in phy_loopback()
2104 if (enable && phydev->loopback_enabled) { in phy_loopback()
2105 ret = -EBUSY; in phy_loopback()
2109 if (!enable && !phydev->loopback_enabled) { in phy_loopback()
2110 ret = -EINVAL; in phy_loopback()
2114 if (phydev->drv->set_loopback) in phy_loopback()
2115 ret = phydev->drv->set_loopback(phydev, enable); in phy_loopback()
2122 phydev->loopback_enabled = enable; in phy_loopback()
2125 mutex_unlock(&phydev->lock); in phy_loopback()
2131 * phy_reset_after_clk_enable - perform a PHY reset if needed
2136 * needed. Returns < 0 on error, 0 if the phy wasn't reset and 1 if the phy
2141 if (!phydev || !phydev->drv) in phy_reset_after_clk_enable()
2142 return -ENODEV; in phy_reset_after_clk_enable()
2144 if (phydev->drv->flags & PHY_RST_AFTER_CLK_EN) { in phy_reset_after_clk_enable()
2154 /* Generic PHY support and helper functions */
2157 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
2159 * @advert: auto-negotiation parameters to advertise
2163 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
2164 * hasn't changed, and > 0 if it has changed.
2188 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all in genphy_config_advert()
2209 * genphy_c37_config_advert - sanitize and advertise auto-negotiation parameters
2214 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
2215 * hasn't changed, and > 0 if it has changed. This function is intended
2216 * for Clause 37 1000Base-X mode.
2222 /* Only allow advertising what this PHY supports */ in genphy_c37_config_advert()
2223 linkmode_and(phydev->advertising, phydev->advertising, in genphy_c37_config_advert()
2224 phydev->supported); in genphy_c37_config_advert()
2227 phydev->advertising)) in genphy_c37_config_advert()
2230 phydev->advertising)) in genphy_c37_config_advert()
2233 phydev->advertising)) in genphy_c37_config_advert()
2243 * genphy_config_eee_advert - disable unwanted eee mode advertisement
2247 * efficent ethernet modes. Returns 0 if the PHY's advertisement hasn't
2255 if (!phydev->eee_broken_modes) in genphy_config_eee_advert()
2259 phydev->eee_broken_modes, 0); in genphy_config_eee_advert()
2266 * genphy_setup_forced - configures/forces speed/duplex from @phydev
2277 phydev->pause = 0; in genphy_setup_forced()
2278 phydev->asym_pause = 0; in genphy_setup_forced()
2280 ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); in genphy_setup_forced()
2291 if (!phydev->is_gigabit_capable) in genphy_setup_master_slave()
2294 switch (phydev->master_slave_set) { in genphy_setup_master_slave()
2311 return -EOPNOTSUPP; in genphy_setup_master_slave()
2324 phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN; in genphy_read_master_slave()
2325 phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN; in genphy_read_master_slave()
2349 } else if (phydev->link) { in genphy_read_master_slave()
2359 phydev->master_slave_get = cfg; in genphy_read_master_slave()
2360 phydev->master_slave_state = state; in genphy_read_master_slave()
2367 * genphy_restart_aneg - Enable and Restart Autonegotiation
2372 /* Don't isolate the PHY if we're negotiating */ in genphy_restart_aneg()
2379 * genphy_check_and_restart_aneg - Enable and restart auto-negotiation
2383 * Check, and restart auto-negotiation if needed.
2390 /* Advertisement hasn't changed, but maybe aneg was never on to in genphy_check_and_restart_aneg()
2391 * begin with? Or maybe phy was isolated? in genphy_check_and_restart_aneg()
2409 * __genphy_config_aneg - restart auto-negotiation or write BMCR
2413 * Description: If auto-negotiation is enabled, we configure the
2414 * advertising, and then restart auto-negotiation. If it is not
2436 if (phydev->autoneg == AUTONEG_ENABLE) { in __genphy_config_aneg()
2437 /* Only allow advertising what this PHY supports */ in __genphy_config_aneg()
2438 linkmode_and(phydev->advertising, phydev->advertising, in __genphy_config_aneg()
2439 phydev->supported); in __genphy_config_aneg()
2440 advert = phydev->advertising; in __genphy_config_aneg()
2441 } else if (phydev->speed < SPEED_1000) { in __genphy_config_aneg()
2446 set = phy_lookup_setting(phydev->speed, phydev->duplex, in __genphy_config_aneg()
2447 phydev->supported, true); in __genphy_config_aneg()
2449 linkmode_set_bit(set->bit, fixed_advert); in __genphy_config_aneg()
2465 * genphy_c37_config_aneg - restart auto-negotiation or write BMCR
2468 * Description: If auto-negotiation is enabled, we configure the
2469 * advertising, and then restart auto-negotiation. If it is not
2471 * for use with Clause 37 1000Base-X mode.
2477 if (phydev->autoneg != AUTONEG_ENABLE) in genphy_c37_config_aneg()
2490 /* Advertisement hasn't changed, but maybe aneg was never on to in genphy_c37_config_aneg()
2491 * begin with? Or maybe phy was isolated? in genphy_c37_config_aneg()
2513 * genphy_aneg_done - return auto-negotiation status
2517 * auto-negotiation is incomplete, or if there was an error.
2518 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
2529 * genphy_update_link - update link status in @phydev
2532 * Description: Update the value in phydev->link to reflect the
2551 * drops can be detected. Do not double-read the status in genphy_update_link()
2555 if (!phy_polling_mode(phydev) || !phydev->link) { in genphy_update_link()
2568 phydev->link = status & BMSR_LSTATUS ? 1 : 0; in genphy_update_link()
2569 phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0; in genphy_update_link()
2574 if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete) in genphy_update_link()
2575 phydev->link = 0; in genphy_update_link()
2585 if (phydev->autoneg == AUTONEG_ENABLE) { in genphy_read_lpa()
2586 if (!phydev->autoneg_complete) { in genphy_read_lpa()
2587 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2589 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0); in genphy_read_lpa()
2593 if (phydev->is_gigabit_capable) { in genphy_read_lpa()
2608 return -ENOLINK; in genphy_read_lpa()
2611 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2619 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); in genphy_read_lpa()
2621 linkmode_zero(phydev->lp_advertising); in genphy_read_lpa()
2629 * genphy_read_status_fixed - read the link parameters for !aneg mode
2632 * Read the current duplex and speed state for a PHY operating with
2643 phydev->duplex = DUPLEX_FULL; in genphy_read_status_fixed()
2645 phydev->duplex = DUPLEX_HALF; in genphy_read_status_fixed()
2648 phydev->speed = SPEED_1000; in genphy_read_status_fixed()
2650 phydev->speed = SPEED_100; in genphy_read_status_fixed()
2652 phydev->speed = SPEED_10; in genphy_read_status_fixed()
2659 * genphy_read_status - check the link status and update current link state
2669 int err, old_link = phydev->link; in genphy_read_status()
2676 /* why bother the PHY if nothing can have changed */ in genphy_read_status()
2677 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in genphy_read_status()
2680 phydev->master_slave_get = MASTER_SLAVE_CFG_UNSUPPORTED; in genphy_read_status()
2681 phydev->master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED; in genphy_read_status()
2682 phydev->speed = SPEED_UNKNOWN; in genphy_read_status()
2683 phydev->duplex = DUPLEX_UNKNOWN; in genphy_read_status()
2684 phydev->pause = 0; in genphy_read_status()
2685 phydev->asym_pause = 0; in genphy_read_status()
2687 if (phydev->is_gigabit_capable) { in genphy_read_status()
2697 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_read_status()
2699 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_read_status()
2710 * genphy_c37_read_status - check the link status and update current link state
2716 * advertises. This function is for Clause 37 1000Base-X mode.
2722 int lpa, err, old_link = phydev->link; in genphy_c37_read_status()
2729 /* why bother the PHY if nothing can have changed */ in genphy_c37_read_status()
2730 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) { in genphy_c37_read_status()
2737 phydev->duplex = DUPLEX_UNKNOWN; in genphy_c37_read_status()
2738 phydev->pause = 0; in genphy_c37_read_status()
2739 phydev->asym_pause = 0; in genphy_c37_read_status()
2741 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_c37_read_status()
2747 phydev->lp_advertising, lpa & LPA_LPACK); in genphy_c37_read_status()
2749 phydev->lp_advertising, lpa & LPA_1000XFULL); in genphy_c37_read_status()
2751 phydev->lp_advertising, lpa & LPA_1000XPAUSE); in genphy_c37_read_status()
2753 phydev->lp_advertising, in genphy_c37_read_status()
2757 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_c37_read_status()
2764 phydev->duplex = DUPLEX_FULL; in genphy_c37_read_status()
2766 phydev->duplex = DUPLEX_HALF; in genphy_c37_read_status()
2774 * genphy_soft_reset - software reset the PHY via BMCR_RESET bit
2777 * Description: Perform a software PHY reset using the standard
2787 if (phydev->autoneg == AUTONEG_ENABLE) in genphy_soft_reset()
2798 phydev->suspended = 0; in genphy_soft_reset()
2805 if (phydev->autoneg == AUTONEG_DISABLE) in genphy_soft_reset()
2815 * entity (ie an IRQ controller embedded inside the PHY) and do not in genphy_handle_interrupt_no_ack()
2826 * genphy_read_abilities - read PHY abilities from Clause 22 registers
2829 * Description: Reads the PHY's abilities and populates
2830 * phydev->supported accordingly.
2840 phydev->supported); in genphy_read_abilities()
2846 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported, in genphy_read_abilities()
2849 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2851 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2853 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2855 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2864 phydev->supported, val & ESTATUS_1000_TFULL); in genphy_read_abilities()
2866 phydev->supported, val & ESTATUS_1000_THALF); in genphy_read_abilities()
2868 phydev->supported, val & ESTATUS_1000_XFULL); in genphy_read_abilities()
2880 /* This is used for the phy device which doesn't support the MMD extended
2886 return -EOPNOTSUPP; in genphy_read_mmd_unsupported()
2893 return -EOPNOTSUPP; in genphy_write_mmd_unsupported()
2915 ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); in genphy_loopback()
2935 * phy_remove_link_mode - Remove a supported link mode
2939 * Description: Some MACs don't support all link modes which the PHY
2945 linkmode_clear_bit(link_mode, phydev->supported); in phy_remove_link_mode()
2959 * phy_advertise_supported - Advertise all supported modes
2962 * Description: Called to advertise all supported modes, doesn't touch
2969 linkmode_copy(new, phydev->supported); in phy_advertise_supported()
2970 phy_copy_pause_bits(new, phydev->advertising); in phy_advertise_supported()
2971 linkmode_copy(phydev->advertising, new); in phy_advertise_supported()
2976 * phy_advertise_eee_all - Advertise all supported EEE modes
2980 * phy probing, which might be a subset of the supported EEE modes. Use this
2982 * trigger auto-negotiation, so must be called before phy_start()/
2983 * phylink_start() which will start auto-negotiation.
2987 linkmode_copy(phydev->advertising_eee, phydev->supported_eee); in phy_advertise_eee_all()
2992 * phy_support_eee - Set initial EEE policy configuration
2996 * (EEE) on the specified PHY device, influencing that EEE capabilities are
2997 * advertised before the link is established. It should be called during PHY
2998 * registration by the MAC driver and/or the PHY driver (for SmartEEE PHYs)
2999 * if MAC supports LPI or PHY is capable to compensate missing LPI functionality
3002 * The function sets default EEE policy parameters, including preparing the PHY
3006 * driver. If the PHY framework determines that both local and remote
3013 linkmode_copy(phydev->advertising_eee, phydev->supported_eee); in phy_support_eee()
3014 phydev->eee_cfg.tx_lpi_enabled = true; in phy_support_eee()
3015 phydev->eee_cfg.eee_enabled = true; in phy_support_eee()
3020 * phy_support_sym_pause - Enable support of symmetrical pause
3028 linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported); in phy_support_sym_pause()
3029 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_sym_pause()
3034 * phy_support_asym_pause - Enable support of asym pause
3041 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_asym_pause()
3046 * phy_set_sym_pause - Configure symmetric Pause
3059 linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported); in phy_set_sym_pause()
3063 phydev->supported); in phy_set_sym_pause()
3065 linkmode_copy(phydev->advertising, phydev->supported); in phy_set_sym_pause()
3070 * phy_set_asym_pause - Configure Pause and Asym Pause
3084 linkmode_copy(oldadv, phydev->advertising); in phy_set_asym_pause()
3085 linkmode_set_pause(phydev->advertising, tx, rx); in phy_set_asym_pause()
3087 if (!linkmode_equal(oldadv, phydev->advertising) && in phy_set_asym_pause()
3088 phydev->autoneg) in phy_set_asym_pause()
3094 * phy_validate_pause - Test if the PHY/MAC support the pause configuration
3098 * Description: Test if the PHY/MAC combination supports the Pause
3106 phydev->supported) && pp->rx_pause) in phy_validate_pause()
3110 phydev->supported) && in phy_validate_pause()
3111 pp->rx_pause != pp->tx_pause) in phy_validate_pause()
3119 * phy_get_pause - resolve negotiated pause modes
3132 if (phydev->duplex != DUPLEX_FULL) { in phy_get_pause()
3138 return linkmode_resolve_pause(phydev->advertising, in phy_get_pause()
3139 phydev->lp_advertising, in phy_get_pause()
3159 return -EINVAL; in phy_get_int_delay_property()
3164 * phy_get_internal_delay - returns the index of the internal delay
3167 * @delay_values: array of delays the PHY supports
3175 * The array must be in ascending order. If PHY does not have an ascending order
3177 * Return -EINVAL if the delay is invalid or cannot be found.
3186 delay = phy_get_int_delay_property(dev, "rx-internal-delay-ps"); in phy_get_internal_delay()
3188 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
3189 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) in phy_get_internal_delay()
3196 delay = phy_get_int_delay_property(dev, "tx-internal-delay-ps"); in phy_get_internal_delay()
3198 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
3199 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) in phy_get_internal_delay()
3212 if (delay < delay_values[0] || delay > delay_values[size - 1]) { in phy_get_internal_delay()
3214 return -EINVAL; in phy_get_internal_delay()
3225 if (delay > delay_values[i - 1] && in phy_get_internal_delay()
3227 if (delay - delay_values[i - 1] < in phy_get_internal_delay()
3228 delay_values[i] - delay) in phy_get_internal_delay()
3229 return i - 1; in phy_get_internal_delay()
3238 return -EINVAL; in phy_get_internal_delay()
3246 struct phy_device *phydev = phyled->phydev; in phy_led_set_brightness()
3249 mutex_lock(&phydev->lock); in phy_led_set_brightness()
3250 err = phydev->drv->led_brightness_set(phydev, phyled->index, value); in phy_led_set_brightness()
3251 mutex_unlock(&phydev->lock); in phy_led_set_brightness()
3261 struct phy_device *phydev = phyled->phydev; in phy_led_blink_set()
3264 mutex_lock(&phydev->lock); in phy_led_blink_set()
3265 err = phydev->drv->led_blink_set(phydev, phyled->index, in phy_led_blink_set()
3267 mutex_unlock(&phydev->lock); in phy_led_blink_set()
3276 struct phy_device *phydev = phyled->phydev; in phy_led_hw_control_get_device()
3278 if (phydev->attached_dev) in phy_led_hw_control_get_device()
3279 return &phydev->attached_dev->dev; in phy_led_hw_control_get_device()
3288 struct phy_device *phydev = phyled->phydev; in phy_led_hw_control_get()
3291 mutex_lock(&phydev->lock); in phy_led_hw_control_get()
3292 err = phydev->drv->led_hw_control_get(phydev, phyled->index, rules); in phy_led_hw_control_get()
3293 mutex_unlock(&phydev->lock); in phy_led_hw_control_get()
3303 struct phy_device *phydev = phyled->phydev; in phy_led_hw_control_set()
3306 mutex_lock(&phydev->lock); in phy_led_hw_control_set()
3307 err = phydev->drv->led_hw_control_set(phydev, phyled->index, rules); in phy_led_hw_control_set()
3308 mutex_unlock(&phydev->lock); in phy_led_hw_control_set()
3317 struct phy_device *phydev = phyled->phydev; in phy_led_hw_is_supported()
3320 mutex_lock(&phydev->lock); in phy_led_hw_is_supported()
3321 err = phydev->drv->led_hw_is_supported(phydev, phyled->index, rules); in phy_led_hw_is_supported()
3322 mutex_unlock(&phydev->lock); in phy_led_hw_is_supported()
3331 list_for_each_entry_safe(phyled, tmp, &phydev->leds, list) { in phy_leds_unregister()
3332 led_classdev_unregister(&phyled->led_cdev); in phy_leds_unregister()
3333 list_del(&phyled->list); in phy_leds_unregister()
3340 struct device *dev = &phydev->mdio.dev; in of_phy_led()
3350 return -ENOMEM; in of_phy_led()
3352 cdev = &phyled->led_cdev; in of_phy_led()
3353 phyled->phydev = phydev; in of_phy_led()
3359 return -EINVAL; in of_phy_led()
3361 if (of_property_read_bool(led, "active-low")) in of_phy_led()
3363 if (of_property_read_bool(led, "inactive-high-impedance")) in of_phy_led()
3368 if (!phydev->drv->led_polarity_set) in of_phy_led()
3369 return -EINVAL; in of_phy_led()
3371 err = phydev->drv->led_polarity_set(phydev, index, modes); in of_phy_led()
3376 phyled->index = index; in of_phy_led()
3377 if (phydev->drv->led_brightness_set) in of_phy_led()
3378 cdev->brightness_set_blocking = phy_led_set_brightness; in of_phy_led()
3379 if (phydev->drv->led_blink_set) in of_phy_led()
3380 cdev->blink_set = phy_led_blink_set; in of_phy_led()
3383 if (phydev->drv->led_hw_is_supported && in of_phy_led()
3384 phydev->drv->led_hw_control_set && in of_phy_led()
3385 phydev->drv->led_hw_control_get) { in of_phy_led()
3386 cdev->hw_control_is_supported = phy_led_hw_is_supported; in of_phy_led()
3387 cdev->hw_control_set = phy_led_hw_control_set; in of_phy_led()
3388 cdev->hw_control_get = phy_led_hw_control_get; in of_phy_led()
3389 cdev->hw_control_trigger = "netdev"; in of_phy_led()
3392 cdev->hw_control_get_device = phy_led_hw_control_get_device; in of_phy_led()
3394 cdev->max_brightness = 1; in of_phy_led()
3395 init_data.devicename = dev_name(&phydev->mdio.dev); in of_phy_led()
3403 list_add(&phyled->list, &phydev->leds); in of_phy_led()
3410 struct device_node *node = phydev->mdio.dev.of_node; in of_phy_leds()
3438 * fwnode_mdio_find_device - Given a fwnode, find the mdio_device
3461 * fwnode_phy_find_device - For provided phy_fwnode, find phy_device.
3463 * @phy_fwnode: Pointer to the phy's fwnode.
3476 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) in fwnode_phy_find_device()
3477 return to_phy_device(&mdiodev->dev); in fwnode_phy_find_device()
3479 put_device(&mdiodev->dev); in fwnode_phy_find_device()
3486 * device_phy_find_device - For the given device, get the phy_device
3498 * fwnode_get_phy_node - Get the phy_node using the named reference.
3502 * For ACPI, only "phy-handle" is supported. Legacy DT properties "phy"
3503 * and "phy-device" are not supported in ACPI. DT supports all the three
3504 * named references to the phy node.
3510 /* Only phy-handle is used for ACPI */ in fwnode_get_phy_node()
3511 phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); in fwnode_get_phy_node()
3514 phy_node = fwnode_find_reference(fwnode, "phy", 0); in fwnode_get_phy_node()
3516 phy_node = fwnode_find_reference(fwnode, "phy-device", 0); in fwnode_get_phy_node()
3522 * phy_probe - probe and init a PHY device
3530 struct device_driver *drv = phydev->mdio.dev.driver; in phy_probe()
3534 phydev->drv = phydrv; in phy_probe()
3536 /* Disable the interrupt if the PHY doesn't support it in phy_probe()
3540 phydev->irq = PHY_POLL; in phy_probe()
3542 if (phydrv->flags & PHY_IS_INTERNAL) in phy_probe()
3543 phydev->is_internal = true; in phy_probe()
3548 if (phydev->drv->probe) { in phy_probe()
3549 err = phydev->drv->probe(phydev); in phy_probe()
3560 if (phydrv->features) { in phy_probe()
3561 linkmode_copy(phydev->supported, phydrv->features); in phy_probe()
3564 else if (phydrv->get_features) in phy_probe()
3565 err = phydrv->get_features(phydev); in phy_probe()
3566 else if (phydev->is_c45) in phy_probe()
3575 phydev->supported)) in phy_probe()
3576 phydev->autoneg = 0; in phy_probe()
3579 phydev->supported)) in phy_probe()
3580 phydev->is_gigabit_capable = 1; in phy_probe()
3582 phydev->supported)) in phy_probe()
3583 phydev->is_gigabit_capable = 1; in phy_probe()
3588 /* Get PHY default EEE advertising modes and handle them as potentially in phy_probe()
3591 err = genphy_c45_read_eee_adv(phydev, phydev->advertising_eee); in phy_probe()
3595 /* There is no "enabled" flag. If PHY is advertising, assume it is in phy_probe()
3598 phydev->eee_enabled = !linkmode_empty(phydev->advertising_eee); in phy_probe()
3603 if (phydev->eee_enabled) in phy_probe()
3604 linkmode_and(phydev->advertising_eee, phydev->supported_eee, in phy_probe()
3605 phydev->advertising_eee); in phy_probe()
3608 * the PHY stop advertising these mode later on in phy_probe()
3612 /* The Pause Frame bits indicate that the PHY can support passing in phy_probe()
3618 * Normally, PHY drivers should not set the Pause bits, and instead in phy_probe()
3623 if (!test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported) && in phy_probe()
3624 !test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported)) { in phy_probe()
3626 phydev->supported); in phy_probe()
3628 phydev->supported); in phy_probe()
3632 phydev->state = PHY_READY; in phy_probe()
3641 /* Re-assert the reset signal on error */ in phy_probe()
3652 cancel_delayed_work_sync(&phydev->state_queue); in phy_remove()
3657 phydev->state = PHY_DOWN; in phy_remove()
3659 sfp_bus_del_upstream(phydev->sfp_bus); in phy_remove()
3660 phydev->sfp_bus = NULL; in phy_remove()
3662 if (phydev->drv && phydev->drv->remove) in phy_remove()
3663 phydev->drv->remove(phydev); in phy_remove()
3668 phydev->drv = NULL; in phy_remove()
3674 * phy_driver_register - register a phy_driver with the PHY layer
3676 * @owner: module owning this PHY
3685 if (WARN_ON(new_driver->features && new_driver->get_features)) { in phy_driver_register()
3687 new_driver->name); in phy_driver_register()
3688 return -EINVAL; in phy_driver_register()
3694 * make out-of-bounds accesses and lockup in phydev->lock. in phy_driver_register()
3696 if (WARN(new_driver->mdiodrv.driver.of_match_table, in phy_driver_register()
3698 new_driver->name)) in phy_driver_register()
3699 return -EINVAL; in phy_driver_register()
3701 new_driver->mdiodrv.flags |= MDIO_DEVICE_IS_PHY; in phy_driver_register()
3702 new_driver->mdiodrv.driver.name = new_driver->name; in phy_driver_register()
3703 new_driver->mdiodrv.driver.bus = &mdio_bus_type; in phy_driver_register()
3704 new_driver->mdiodrv.driver.probe = phy_probe; in phy_driver_register()
3705 new_driver->mdiodrv.driver.remove = phy_remove; in phy_driver_register()
3706 new_driver->mdiodrv.driver.owner = owner; in phy_driver_register()
3707 new_driver->mdiodrv.driver.probe_type = PROBE_FORCE_SYNCHRONOUS; in phy_driver_register()
3709 retval = driver_register(&new_driver->mdiodrv.driver); in phy_driver_register()
3712 new_driver->name, retval); in phy_driver_register()
3717 pr_debug("%s: Registered new driver\n", new_driver->name); in phy_driver_register()
3731 while (i-- > 0) in phy_drivers_register()
3742 driver_unregister(&drv->mdiodrv.driver); in phy_driver_unregister()
3758 .name = "Generic PHY",