Lines Matching +full:phy +full:- +full:device
1 // SPDX-License-Identifier: GPL-2.0+
3 * Also contains generic PHY driver
29 #include <linux/phy.h>
32 #include <linux/pse-pd/pse.h>
42 MODULE_DESCRIPTION("PHY library");
240 put_device(&phydev->mdio.dev); in phy_device_free()
252 static void phy_device_release(struct device *dev) in phy_device_release()
254 fwnode_handle_put(dev->fwnode); in phy_device_release()
273 struct device_driver *drv = phydev->mdio.dev.driver; in mdio_bus_phy_may_suspend()
275 struct net_device *netdev = phydev->attached_dev; in mdio_bus_phy_may_suspend()
277 if (!drv || !phydrv->suspend) in mdio_bus_phy_may_suspend()
280 /* PHY not attached? May suspend if the PHY has not already been in mdio_bus_phy_may_suspend()
281 * suspended as part of a prior call to phy_disconnect() -> in mdio_bus_phy_may_suspend()
282 * phy_detach() -> phy_suspend() because the parent netdev might be the in mdio_bus_phy_may_suspend()
288 if (netdev->wol_enabled) in mdio_bus_phy_may_suspend()
293 * Don't suspend PHY if the attached netdev parent may wake up. in mdio_bus_phy_may_suspend()
294 * The parent may point to a PCI device, as in tg3 driver. in mdio_bus_phy_may_suspend()
296 if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent)) in mdio_bus_phy_may_suspend()
299 /* Also don't suspend PHY if the netdev itself may wakeup. This in mdio_bus_phy_may_suspend()
303 if (device_may_wakeup(&netdev->dev)) in mdio_bus_phy_may_suspend()
307 return !phydev->suspended; in mdio_bus_phy_may_suspend()
310 static __maybe_unused int mdio_bus_phy_suspend(struct device *dev) in mdio_bus_phy_suspend()
314 if (phydev->mac_managed_pm) in mdio_bus_phy_suspend()
318 * the PHY is inaccessible. Set flag to postpone handling until the PHY in mdio_bus_phy_suspend()
322 phydev->irq_suspended = 1; in mdio_bus_phy_suspend()
323 synchronize_irq(phydev->irq); in mdio_bus_phy_suspend()
327 * control, possibly with the phydev->lock held. Upon resume, netdev in mdio_bus_phy_suspend()
328 * may call phy routines that try to grab the same lock, and that may in mdio_bus_phy_suspend()
331 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_suspend()
337 phydev->suspended_by_mdio_bus = 1; in mdio_bus_phy_suspend()
342 static __maybe_unused int mdio_bus_phy_resume(struct device *dev) in mdio_bus_phy_resume()
347 if (phydev->mac_managed_pm) in mdio_bus_phy_resume()
350 if (!phydev->suspended_by_mdio_bus) in mdio_bus_phy_resume()
353 phydev->suspended_by_mdio_bus = 0; in mdio_bus_phy_resume()
355 /* If we managed to get here with the PHY state machine in a state in mdio_bus_phy_resume()
360 WARN_ON(phydev->state != PHY_HALTED && phydev->state != PHY_READY && in mdio_bus_phy_resume()
361 phydev->state != PHY_UP); in mdio_bus_phy_resume()
372 phydev->irq_suspended = 0; in mdio_bus_phy_resume()
373 synchronize_irq(phydev->irq); in mdio_bus_phy_resume()
378 if (phydev->irq_rerun) { in mdio_bus_phy_resume()
379 phydev->irq_rerun = 0; in mdio_bus_phy_resume()
380 enable_irq(phydev->irq); in mdio_bus_phy_resume()
381 irq_wake_thread(phydev->irq, phydev); in mdio_bus_phy_resume()
385 if (phydev->attached_dev && phydev->adjust_link) in mdio_bus_phy_resume()
395 * phy_register_fixup - creates a new phy_fixup and adds it to the list
396 * @bus_id: A string which matches phydev->mdio.dev.bus_id (or PHY_ANY_ID)
397 * @phy_uid: Used to match against phydev->phy_id (the UID of the PHY)
399 * @phy_uid_mask: Applied to phydev->phy_id and fixup->phy_uid before
401 * @run: The actual code to be run when a matching PHY is found
409 return -ENOMEM; in phy_register_fixup()
411 strscpy(fixup->bus_id, bus_id, sizeof(fixup->bus_id)); in phy_register_fixup()
412 fixup->phy_uid = phy_uid; in phy_register_fixup()
413 fixup->phy_uid_mask = phy_uid_mask; in phy_register_fixup()
414 fixup->run = run; in phy_register_fixup()
417 list_add_tail(&fixup->list, &phy_fixup_list); in phy_register_fixup()
424 /* Registers a fixup to be run on any PHY with the UID in phy_uid */
432 /* Registers a fixup to be run on the PHY with id string bus_id */
441 * phy_unregister_fixup - remove a phy_fixup from the list
442 * @bus_id: A string matches fixup->bus_id (or PHY_ANY_ID) in phy_fixup_list
443 * @phy_uid: A phy id matches fixup->phy_id (or PHY_ANY_UID) in phy_fixup_list
444 * @phy_uid_mask: Applied to phy_uid and fixup->phy_uid before comparison
452 ret = -ENODEV; in phy_unregister_fixup()
458 if ((!strcmp(fixup->bus_id, bus_id)) && in phy_unregister_fixup()
459 phy_id_compare(fixup->phy_uid, phy_uid, phy_uid_mask)) { in phy_unregister_fixup()
460 list_del(&fixup->list); in phy_unregister_fixup()
472 /* Unregisters a fixup of any PHY with the UID in phy_uid */
479 /* Unregisters a fixup of the PHY with id string bus_id */
491 if (strcmp(fixup->bus_id, phydev_name(phydev)) != 0) in phy_needs_fixup()
492 if (strcmp(fixup->bus_id, PHY_ANY_ID) != 0) in phy_needs_fixup()
495 if (!phy_id_compare(phydev->phy_id, fixup->phy_uid, in phy_needs_fixup()
496 fixup->phy_uid_mask)) in phy_needs_fixup()
497 if (fixup->phy_uid != PHY_ANY_UID) in phy_needs_fixup()
511 int err = fixup->run(phydev); in phy_scan_fixups()
517 phydev->has_fixups = true; in phy_scan_fixups()
525 static int phy_bus_match(struct device *dev, struct device_driver *drv) in phy_bus_match()
529 const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids); in phy_bus_match()
532 if (!(phydrv->mdiodrv.flags & MDIO_DEVICE_IS_PHY)) in phy_bus_match()
535 if (phydrv->match_phy_device) in phy_bus_match()
536 return phydrv->match_phy_device(phydev); in phy_bus_match()
538 if (phydev->is_c45) { in phy_bus_match()
540 if (phydev->c45_ids.device_ids[i] == 0xffffffff) in phy_bus_match()
543 if (phy_id_compare(phydev->c45_ids.device_ids[i], in phy_bus_match()
544 phydrv->phy_id, phydrv->phy_id_mask)) in phy_bus_match()
549 return phy_id_compare(phydev->phy_id, phydrv->phy_id, in phy_bus_match()
550 phydrv->phy_id_mask); in phy_bus_match()
555 phy_id_show(struct device *dev, struct device_attribute *attr, char *buf) in phy_id_show()
559 return sysfs_emit(buf, "0x%.8lx\n", (unsigned long)phydev->phy_id); in phy_id_show()
564 phy_interface_show(struct device *dev, struct device_attribute *attr, char *buf) in phy_interface_show()
572 mode = phy_modes(phydev->interface); in phy_interface_show()
579 phy_has_fixups_show(struct device *dev, struct device_attribute *attr, in phy_has_fixups_show()
584 return sysfs_emit(buf, "%d\n", phydev->has_fixups); in phy_has_fixups_show()
588 static ssize_t phy_dev_flags_show(struct device *dev, in phy_dev_flags_show()
594 return sysfs_emit(buf, "0x%08x\n", phydev->dev_flags); in phy_dev_flags_show()
608 .name = "PHY",
621 * not whether a PHY driver module exists for the PHY ID. in phy_request_driver_module()
622 * Accept -ENOENT because this may occur in case no initramfs exists, in phy_request_driver_module()
625 if (IS_ENABLED(CONFIG_MODULES) && ret < 0 && ret != -ENOENT) { in phy_request_driver_module()
626 phydev_err(dev, "error %d loading PHY driver module for ID 0x%08lx\n", in phy_request_driver_module()
642 /* We allocate the device, and initialize the default values */ in phy_device_create()
645 return ERR_PTR(-ENOMEM); in phy_device_create()
647 mdiodev = &dev->mdio; in phy_device_create()
648 mdiodev->dev.parent = &bus->dev; in phy_device_create()
649 mdiodev->dev.bus = &mdio_bus_type; in phy_device_create()
650 mdiodev->dev.type = &mdio_bus_phy_type; in phy_device_create()
651 mdiodev->bus = bus; in phy_device_create()
652 mdiodev->bus_match = phy_bus_match; in phy_device_create()
653 mdiodev->addr = addr; in phy_device_create()
654 mdiodev->flags = MDIO_DEVICE_FLAG_PHY; in phy_device_create()
655 mdiodev->device_free = phy_mdio_device_free; in phy_device_create()
656 mdiodev->device_remove = phy_mdio_device_remove; in phy_device_create()
658 dev->speed = SPEED_UNKNOWN; in phy_device_create()
659 dev->duplex = DUPLEX_UNKNOWN; in phy_device_create()
660 dev->pause = 0; in phy_device_create()
661 dev->asym_pause = 0; in phy_device_create()
662 dev->link = 0; in phy_device_create()
663 dev->port = PORT_TP; in phy_device_create()
664 dev->interface = PHY_INTERFACE_MODE_GMII; in phy_device_create()
666 dev->autoneg = AUTONEG_ENABLE; in phy_device_create()
668 dev->pma_extable = -ENODATA; in phy_device_create()
669 dev->is_c45 = is_c45; in phy_device_create()
670 dev->phy_id = phy_id; in phy_device_create()
672 dev->c45_ids = *c45_ids; in phy_device_create()
673 dev->irq = bus->irq[addr]; in phy_device_create()
675 dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr); in phy_device_create()
676 device_initialize(&mdiodev->dev); in phy_device_create()
678 dev->state = PHY_DOWN; in phy_device_create()
679 INIT_LIST_HEAD(&dev->leds); in phy_device_create()
681 mutex_init(&dev->lock); in phy_device_create()
682 INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); in phy_device_create()
689 * -- because it relies on the device staying around for long in phy_device_create()
695 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in phy_device_create()
699 if (c45_ids->device_ids[i] == 0xffffffff) in phy_device_create()
703 c45_ids->device_ids[i]); in phy_device_create()
712 put_device(&mdiodev->dev); in phy_device_create()
720 /* phy_c45_probe_present - checks to see if a MMD is present in the package
722 * @prtad: PHY package address on the MII bus
723 * @devad: PHY device (MMD) address
725 * Read the MDIO_STAT2 register, and check whether a device is responding
728 * Returns: negative error number on bus access error, zero if no device
729 * is responding, or positive if a device is present.
742 /* get_phy_c45_devs_in_pkg - reads a MMD's devices in package registers.
744 * @addr: PHY address on the MII bus
745 * @dev_addr: MMD address in the PHY.
749 * from PHY at @addr on @bus.
751 * Returns: 0 on success, -EIO on failure.
760 return -EIO; in get_phy_c45_devs_in_pkg()
765 return -EIO; in get_phy_c45_devs_in_pkg()
772 * get_phy_c45_ids - reads the specified addr for its 802.3-c45 IDs.
774 * @addr: PHY address on the MII bus
777 * Read the PHY "devices in package". If this appears to be valid, read
778 * the PHY identifiers for each device. Return the "devices in package"
781 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
787 const int num_ids = ARRAY_SIZE(c45_ids->device_ids); in get_phy_c45_ids()
791 /* Find first non-zero Devices In package. Device zero is reserved in get_phy_c45_ids()
797 /* Check that there is a device present at this in get_phy_c45_ids()
798 * address before reading the devices-in-package in get_phy_c45_ids()
799 * register to avoid reading garbage from the PHY. in get_phy_c45_ids()
805 return -EIO; in get_phy_c45_ids()
812 return -EIO; in get_phy_c45_ids()
816 /* If mostly Fs, there is no device there, then let's probe in get_phy_c45_ids()
818 * e.g. Cortina CS4315/CS4340 PHY. in get_phy_c45_ids()
822 return -EIO; in get_phy_c45_ids()
824 /* no device there, let's get out of here */ in get_phy_c45_ids()
826 return -ENODEV; in get_phy_c45_ids()
829 /* Now probe Device Identifiers for each device present. */ in get_phy_c45_ids()
835 /* Probe the "Device Present" bits for the vendor MMDs in get_phy_c45_ids()
849 return -EIO; in get_phy_c45_ids()
850 c45_ids->device_ids[i] = phy_reg << 16; in get_phy_c45_ids()
854 return -EIO; in get_phy_c45_ids()
855 c45_ids->device_ids[i] |= phy_reg; in get_phy_c45_ids()
858 c45_ids->devices_in_package = devs_in_pkg; in get_phy_c45_ids()
859 /* Bit 0 doesn't represent a device, it indicates c22 regs presence */ in get_phy_c45_ids()
860 c45_ids->mmds_present = devs_in_pkg & ~BIT(0); in get_phy_c45_ids()
866 * get_phy_c22_id - reads the specified addr for its clause 22 ID.
868 * @addr: PHY address on the MII bus
871 * Read the 802.3 clause 22 PHY ID from the PHY at @addr on the @bus,
873 * valid, %-EIO on bus access error, or %-ENODEV if no device responds
883 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
884 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
892 /* returning -ENODEV doesn't stop bus scanning */ in get_phy_c22_id()
893 return (phy_reg == -EIO || phy_reg == -ENODEV) ? -ENODEV : -EIO; in get_phy_c22_id()
898 /* If the phy_id is mostly Fs, there is no device there */ in get_phy_c22_id()
900 return -ENODEV; in get_phy_c22_id()
905 /* Extract the phy ID from the compatible string of the form
906 * ethernet-phy-idAAAA.BBBB.
918 if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) != 2) in fwnode_get_phy_id()
919 return -EINVAL; in fwnode_get_phy_id()
927 * get_phy_device - reads the specified PHY device and returns its @phy_device
930 * @addr: PHY address on the MII bus
931 * @is_c45: If true the PHY uses the 802.3 clause 45 protocol
933 * Probe for a PHY at @addr on @bus.
935 * When probing for a clause 22 PHY, then read the ID registers. If we find
938 * When probing for a clause 45 PHY, read the "devices in package" registers.
942 * Returns an allocated &struct phy_device on success, %-ENODEV if there is
943 * no PHY present, or %-EIO on bus access error.
963 /* PHY device such as the Marvell Alaska 88E2110 will return a PHY ID in get_phy_device()
965 * probe with C45 to see if we're able to get a valid PHY ID in the C45 in get_phy_device()
966 * space, if successful, create the C45 PHY device. in get_phy_device()
968 if (!is_c45 && phy_id == 0 && bus->read_c45) { in get_phy_device()
980 * phy_device_register - Register the phy device on the MDIO bus
987 err = mdiobus_register_device(&phydev->mdio); in phy_device_register()
994 /* Run all of the fixups for this PHY */ in phy_device_register()
1001 err = device_add(&phydev->mdio.dev); in phy_device_register()
1013 mdiobus_unregister_device(&phydev->mdio); in phy_device_register()
1019 * phy_device_remove - Remove a previously registered phy device from the MDIO bus
1023 * of phy_device_register(). Use phy_device_free() to free the device
1028 unregister_mii_timestamper(phydev->mii_ts); in phy_device_remove()
1029 pse_control_put(phydev->psec); in phy_device_remove()
1031 device_del(&phydev->mdio.dev); in phy_device_remove()
1036 mdiobus_unregister_device(&phydev->mdio); in phy_device_remove()
1041 * phy_get_c45_ids - Read 802.3-c45 IDs for phy device.
1042 * @phydev: phy_device structure to read 802.3-c45 IDs
1044 * Returns zero on success, %-EIO on bus access error, or %-ENODEV if
1049 return get_phy_c45_ids(phydev->mdio.bus, phydev->mdio.addr, in phy_get_c45_ids()
1050 &phydev->c45_ids); in phy_get_c45_ids()
1055 * phy_find_first - finds the first PHY device on the bus
1074 struct net_device *netdev = phydev->attached_dev; in phy_link_change()
1080 phydev->adjust_link(netdev); in phy_link_change()
1081 if (phydev->mii_ts && phydev->mii_ts->link_state) in phy_link_change()
1082 phydev->mii_ts->link_state(phydev->mii_ts, phydev); in phy_link_change()
1086 * phy_prepare_link - prepares the PHY layer to monitor link status
1090 * Description: Tells the PHY infrastructure to handle the
1093 * connected device driver when the link status changes.
1100 phydev->adjust_link = handler; in phy_prepare_link()
1104 * phy_connect_direct - connect an ethernet device to a specific phy_device
1105 * @dev: the network device to connect
1106 * @phydev: the pointer to the phy device
1108 * @interface: PHY device's interface
1117 return -EINVAL; in phy_connect_direct()
1119 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_connect_direct()
1132 * phy_connect - connect an ethernet device to a PHY device
1133 * @dev: the network device to connect
1134 * @bus_id: the id string of the PHY device to connect
1136 * @interface: PHY device's interface
1139 * devices to PHY devices. The default behavior is for
1140 * the PHY infrastructure to handle everything, and only notify
1151 struct device *d; in phy_connect()
1154 /* Search the list of PHY devices on the mdio bus for the in phy_connect()
1155 * PHY with the requested name in phy_connect()
1159 pr_err("PHY %s not found\n", bus_id); in phy_connect()
1160 return ERR_PTR(-ENODEV); in phy_connect()
1174 * phy_disconnect - disable interrupts, stop state machine, and detach a PHY
1175 * device
1186 phydev->adjust_link = NULL; in phy_disconnect()
1193 * phy_poll_reset - Safely wait until a PHY reset has properly completed
1194 * @phydev: The PHY device to poll
1197 * published in 2008, a PHY reset may take up to 0.5 seconds. The MII BMCR
1200 * Furthermore, any attempts to write to PHY registers may have no effect
1205 * even *REQUIRE* a soft-reset to properly restart autonegotiation. In an
1208 * and reapply all driver-specific and board-specific fixups.
1233 if (!phydev->drv) in phy_init_hw()
1236 if (phydev->drv->soft_reset) { in phy_init_hw()
1237 ret = phydev->drv->soft_reset(phydev); in phy_init_hw()
1240 phydev->suspended = 0; in phy_init_hw()
1250 if (phydev->drv->config_init) { in phy_init_hw()
1251 ret = phydev->drv->config_init(phydev); in phy_init_hw()
1256 if (phydev->drv->config_intr) { in phy_init_hw()
1257 ret = phydev->drv->config_intr(phydev); in phy_init_hw()
1272 #define ATTACHED_FMT "attached PHY driver %s(mii_bus:phy_addr=%s, irq=%s)"
1278 switch(phydev->irq) { in phy_attached_info_irq()
1286 snprintf(irq_num, sizeof(irq_num), "%d", phydev->irq); in phy_attached_info_irq()
1297 const char *unbound = phydev->drv ? "" : "[unbound] "; in phy_attached_print()
1319 struct net_device *dev = phydev->attached_dev; in phy_sysfs_create_links()
1325 err = sysfs_create_link(&phydev->mdio.dev.kobj, &dev->dev.kobj, in phy_sysfs_create_links()
1330 err = sysfs_create_link_nowarn(&dev->dev.kobj, in phy_sysfs_create_links()
1331 &phydev->mdio.dev.kobj, in phy_sysfs_create_links()
1334 dev_err(&dev->dev, "could not add device link to %s err %d\n", in phy_sysfs_create_links()
1335 kobject_name(&phydev->mdio.dev.kobj), in phy_sysfs_create_links()
1337 /* non-fatal - some net drivers can use one netdevice in phy_sysfs_create_links()
1338 * with more then one phy in phy_sysfs_create_links()
1342 phydev->sysfs_links = true; in phy_sysfs_create_links()
1346 phy_standalone_show(struct device *dev, struct device_attribute *attr, in phy_standalone_show()
1351 return sysfs_emit(buf, "%d\n", !phydev->attached_dev); in phy_standalone_show()
1356 * phy_sfp_attach - attach the SFP bus to the PHY upstream network device
1357 * @upstream: pointer to the phy device
1366 if (phydev->attached_dev) in phy_sfp_attach()
1367 phydev->attached_dev->sfp_bus = bus; in phy_sfp_attach()
1368 phydev->sfp_bus_attached = true; in phy_sfp_attach()
1373 * phy_sfp_detach - detach the SFP bus from the PHY upstream network device
1374 * @upstream: pointer to the phy device
1383 if (phydev->attached_dev) in phy_sfp_detach()
1384 phydev->attached_dev->sfp_bus = NULL; in phy_sfp_detach()
1385 phydev->sfp_bus_attached = false; in phy_sfp_detach()
1390 * phy_sfp_probe - probe for a SFP cage attached to this PHY device
1400 if (phydev->mdio.dev.fwnode) { in phy_sfp_probe()
1401 bus = sfp_bus_find_fwnode(phydev->mdio.dev.fwnode); in phy_sfp_probe()
1405 phydev->sfp_bus = bus; in phy_sfp_probe()
1415 * phy_attach_direct - attach a network device to a given PHY device pointer
1416 * @dev: network device to attach
1418 * @flags: PHY device's dev_flags
1419 * @interface: PHY device's interface
1421 * Description: Called by drivers to attach to a particular PHY
1422 * device. The phy_device is found, and properly hooked up
1425 * the attaching device, and given a callback for link status
1427 * This function takes a reference on the phy device.
1432 struct mii_bus *bus = phydev->mdio.bus; in phy_attach_direct()
1433 struct device *d = &phydev->mdio.dev; in phy_attach_direct()
1438 /* For Ethernet device drivers that register their own MDIO bus, we in phy_attach_direct()
1439 * will have bus->owner match ndev_mod, so we do not want to increment in phy_attach_direct()
1440 * our own module->refcnt here, otherwise we would not be able to in phy_attach_direct()
1444 ndev_owner = dev->dev.parent->driver->owner; in phy_attach_direct()
1445 if (ndev_owner != bus->owner && !try_module_get(bus->owner)) { in phy_attach_direct()
1447 return -EIO; in phy_attach_direct()
1455 if (!d->driver) { in phy_attach_direct()
1456 if (phydev->is_c45) in phy_attach_direct()
1457 d->driver = &genphy_c45_driver.mdiodrv.driver; in phy_attach_direct()
1459 d->driver = &genphy_driver.mdiodrv.driver; in phy_attach_direct()
1464 if (!try_module_get(d->driver->owner)) { in phy_attach_direct()
1465 phydev_err(phydev, "failed to get the device driver module\n"); in phy_attach_direct()
1466 err = -EIO; in phy_attach_direct()
1471 err = d->driver->probe(d); in phy_attach_direct()
1479 if (phydev->attached_dev) { in phy_attach_direct()
1480 dev_err(&dev->dev, "PHY already attached\n"); in phy_attach_direct()
1481 err = -EBUSY; in phy_attach_direct()
1485 phydev->phy_link_change = phy_link_change; in phy_attach_direct()
1487 phydev->attached_dev = dev; in phy_attach_direct()
1488 dev->phydev = phydev; in phy_attach_direct()
1490 if (phydev->sfp_bus_attached) in phy_attach_direct()
1491 dev->sfp_bus = phydev->sfp_bus; in phy_attach_direct()
1494 /* Some Ethernet drivers try to connect to a PHY device before in phy_attach_direct()
1495 * calling register_netdevice() -> netdev_register_kobject() and in phy_attach_direct()
1496 * does the dev->dev.kobj initialization. Here we only check for in phy_attach_direct()
1497 * success which indicates that the network device kobject is in phy_attach_direct()
1502 phydev->sysfs_links = false; in phy_attach_direct()
1506 if (!phydev->attached_dev) { in phy_attach_direct()
1507 err = sysfs_create_file(&phydev->mdio.dev.kobj, in phy_attach_direct()
1513 phydev->dev_flags |= flags; in phy_attach_direct()
1515 phydev->interface = interface; in phy_attach_direct()
1517 phydev->state = PHY_READY; in phy_attach_direct()
1519 phydev->interrupts = PHY_INTERRUPT_DISABLED; in phy_attach_direct()
1525 if (phydev->dev_flags & PHY_F_NO_IRQ) in phy_attach_direct()
1526 phydev->irq = PHY_POLL; in phy_attach_direct()
1528 /* Port is set to PORT_TP by default and the actual PHY driver will set in phy_attach_direct()
1529 * it to different value depending on the PHY configuration. If we have in phy_attach_direct()
1530 * the generic PHY driver we can't figure it out, thus set the old in phy_attach_direct()
1534 phydev->port = PORT_MII; in phy_attach_direct()
1536 /* Initial carrier state is off as the phy is about to be in phy_attach_direct()
1540 netif_carrier_off(phydev->attached_dev); in phy_attach_direct()
1554 * If the external phy used by current mac interface is managed by in phy_attach_direct()
1555 * another mac interface, so we should create a device link between in phy_attach_direct()
1556 * phy dev and mac dev. in phy_attach_direct()
1558 if (dev && phydev->mdio.bus->parent && dev->dev.parent != phydev->mdio.bus->parent) in phy_attach_direct()
1559 phydev->devlink = device_link_add(dev->dev.parent, &phydev->mdio.dev, in phy_attach_direct()
1570 module_put(d->driver->owner); in phy_attach_direct()
1571 d->driver = NULL; in phy_attach_direct()
1574 if (ndev_owner != bus->owner) in phy_attach_direct()
1575 module_put(bus->owner); in phy_attach_direct()
1581 * phy_attach - attach a network device to a particular PHY device
1582 * @dev: network device to attach
1583 * @bus_id: Bus ID of PHY device to attach
1584 * @interface: PHY device's interface
1586 * Description: Same as phy_attach_direct() except that a PHY bus_id
1594 struct device *d; in phy_attach()
1598 return ERR_PTR(-EINVAL); in phy_attach()
1600 /* Search the list of PHY devices on the mdio bus for the in phy_attach()
1601 * PHY with the requested name in phy_attach()
1605 pr_err("PHY %s not found\n", bus_id); in phy_attach()
1606 return ERR_PTR(-ENODEV); in phy_attach()
1610 rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface); in phy_attach()
1622 struct device *d = &phydev->mdio.dev; in phy_driver_is_genphy_kind()
1625 if (!phydev->drv) in phy_driver_is_genphy_kind()
1629 ret = d->driver == driver; in phy_driver_is_genphy_kind()
1650 * phy_package_join - join a common PHY group
1652 * @addr: cookie and PHY address for global register access
1653 * @priv_size: if non-zero allocate this amount of bytes for private data
1655 * This joins a PHY group and provides a shared storage for all phydevs in
1657 * more than one PHY, for example a quad PHY transceiver.
1660 * for all members of one group and as a PHY address to access generic
1661 * registers of a PHY package. Usually, one of the PHY addresses of the
1664 * and phy_package_write() convenience functions. If your PHY doesn't have
1665 * global registers you can just pick any of the PHY addresses.
1669 * allocated. If priv_size is non-zero, the given amount of bytes are
1677 struct mii_bus *bus = phydev->mdio.bus; in phy_package_join()
1682 return -EINVAL; in phy_package_join()
1684 mutex_lock(&bus->shared_lock); in phy_package_join()
1685 shared = bus->shared[addr]; in phy_package_join()
1687 ret = -ENOMEM; in phy_package_join()
1692 shared->priv = kzalloc(priv_size, GFP_KERNEL); in phy_package_join()
1693 if (!shared->priv) in phy_package_join()
1695 shared->priv_size = priv_size; in phy_package_join()
1697 shared->addr = addr; in phy_package_join()
1698 refcount_set(&shared->refcnt, 1); in phy_package_join()
1699 bus->shared[addr] = shared; in phy_package_join()
1701 ret = -EINVAL; in phy_package_join()
1702 if (priv_size && priv_size != shared->priv_size) in phy_package_join()
1704 refcount_inc(&shared->refcnt); in phy_package_join()
1706 mutex_unlock(&bus->shared_lock); in phy_package_join()
1708 phydev->shared = shared; in phy_package_join()
1715 mutex_unlock(&bus->shared_lock); in phy_package_join()
1721 * phy_package_leave - leave a common PHY group
1724 * This leaves a PHY group created by phy_package_join(). If this phydev
1726 * freed. Resets the phydev->shared pointer to NULL.
1730 struct phy_package_shared *shared = phydev->shared; in phy_package_leave()
1731 struct mii_bus *bus = phydev->mdio.bus; in phy_package_leave()
1736 if (refcount_dec_and_mutex_lock(&shared->refcnt, &bus->shared_lock)) { in phy_package_leave()
1737 bus->shared[shared->addr] = NULL; in phy_package_leave()
1738 mutex_unlock(&bus->shared_lock); in phy_package_leave()
1739 kfree(shared->priv); in phy_package_leave()
1743 phydev->shared = NULL; in phy_package_leave()
1747 static void devm_phy_package_leave(struct device *dev, void *res) in devm_phy_package_leave()
1753 * devm_phy_package_join - resource managed phy_package_join()
1754 * @dev: device that is registering this PHY package
1756 * @addr: cookie and PHY address for global register access
1757 * @priv_size: if non-zero allocate this amount of bytes for private data
1763 int devm_phy_package_join(struct device *dev, struct phy_device *phydev, in devm_phy_package_join()
1772 return -ENOMEM; in devm_phy_package_join()
1788 * phy_detach - detach a PHY device from its network device
1791 * This detaches the phy device from its network device and the phy
1796 struct net_device *dev = phydev->attached_dev; in phy_detach()
1800 if (phydev->devlink) in phy_detach()
1801 device_link_del(phydev->devlink); in phy_detach()
1803 if (phydev->sysfs_links) { in phy_detach()
1805 sysfs_remove_link(&dev->dev.kobj, "phydev"); in phy_detach()
1806 sysfs_remove_link(&phydev->mdio.dev.kobj, "attached_dev"); in phy_detach()
1809 if (!phydev->attached_dev) in phy_detach()
1810 sysfs_remove_file(&phydev->mdio.dev.kobj, in phy_detach()
1815 phydev->attached_dev->phydev = NULL; in phy_detach()
1816 phydev->attached_dev = NULL; in phy_detach()
1818 phydev->phylink = NULL; in phy_detach()
1822 if (phydev->mdio.dev.driver) in phy_detach()
1823 module_put(phydev->mdio.dev.driver->owner); in phy_detach()
1825 /* If the device had no specific driver before (i.e. - it in phy_detach()
1826 * was using the generic driver), we unbind the device in phy_detach()
1832 device_release_driver(&phydev->mdio.dev); in phy_detach()
1839 * a use-after-free bug by reading the underlying bus first. in phy_detach()
1841 bus = phydev->mdio.bus; in phy_detach()
1843 put_device(&phydev->mdio.dev); in phy_detach()
1845 ndev_owner = dev->dev.parent->driver->owner; in phy_detach()
1846 if (ndev_owner != bus->owner) in phy_detach()
1847 module_put(bus->owner); in phy_detach()
1854 struct net_device *netdev = phydev->attached_dev; in phy_suspend()
1855 struct phy_driver *phydrv = phydev->drv; in phy_suspend()
1858 if (phydev->suspended) in phy_suspend()
1862 phydev->wol_enabled = wol.wolopts || (netdev && netdev->wol_enabled); in phy_suspend()
1863 /* If the device has WOL enabled, we cannot suspend the PHY */ in phy_suspend()
1864 if (phydev->wol_enabled && !(phydrv->flags & PHY_ALWAYS_CALL_SUSPEND)) in phy_suspend()
1865 return -EBUSY; in phy_suspend()
1867 if (!phydrv || !phydrv->suspend) in phy_suspend()
1870 ret = phydrv->suspend(phydev); in phy_suspend()
1872 phydev->suspended = true; in phy_suspend()
1880 struct phy_driver *phydrv = phydev->drv; in __phy_resume()
1883 lockdep_assert_held(&phydev->lock); in __phy_resume()
1885 if (!phydrv || !phydrv->resume) in __phy_resume()
1888 ret = phydrv->resume(phydev); in __phy_resume()
1890 phydev->suspended = false; in __phy_resume()
1900 mutex_lock(&phydev->lock); in phy_resume()
1902 mutex_unlock(&phydev->lock); in phy_resume()
1912 if (!phydev->drv) in phy_loopback()
1913 return -EIO; in phy_loopback()
1915 mutex_lock(&phydev->lock); in phy_loopback()
1917 if (enable && phydev->loopback_enabled) { in phy_loopback()
1918 ret = -EBUSY; in phy_loopback()
1922 if (!enable && !phydev->loopback_enabled) { in phy_loopback()
1923 ret = -EINVAL; in phy_loopback()
1927 if (phydev->drv->set_loopback) in phy_loopback()
1928 ret = phydev->drv->set_loopback(phydev, enable); in phy_loopback()
1935 phydev->loopback_enabled = enable; in phy_loopback()
1938 mutex_unlock(&phydev->lock); in phy_loopback()
1944 * phy_reset_after_clk_enable - perform a PHY reset if needed
1949 * needed. Returns < 0 on error, 0 if the phy wasn't reset and 1 if the phy
1954 if (!phydev || !phydev->drv) in phy_reset_after_clk_enable()
1955 return -ENODEV; in phy_reset_after_clk_enable()
1957 if (phydev->drv->flags & PHY_RST_AFTER_CLK_EN) { in phy_reset_after_clk_enable()
1967 /* Generic PHY support and helper functions */
1970 * genphy_config_advert - sanitize and advertise auto-negotiation parameters
1975 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
1983 /* Only allow advertising what this PHY supports */ in genphy_config_advert()
1984 linkmode_and(phydev->advertising, phydev->advertising, in genphy_config_advert()
1985 phydev->supported); in genphy_config_advert()
1987 adv = linkmode_adv_to_mii_adv_t(phydev->advertising); in genphy_config_advert()
2003 /* Per 802.3-2008, Section 22.2.4.2.16 Extended status all in genphy_config_advert()
2010 adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising); in genphy_config_advert()
2024 * genphy_c37_config_advert - sanitize and advertise auto-negotiation parameters
2029 * what is supported. Returns < 0 on error, 0 if the PHY's advertisement
2031 * for Clause 37 1000Base-X mode.
2037 /* Only allow advertising what this PHY supports */ in genphy_c37_config_advert()
2038 linkmode_and(phydev->advertising, phydev->advertising, in genphy_c37_config_advert()
2039 phydev->supported); in genphy_c37_config_advert()
2042 phydev->advertising)) in genphy_c37_config_advert()
2045 phydev->advertising)) in genphy_c37_config_advert()
2048 phydev->advertising)) in genphy_c37_config_advert()
2058 * genphy_config_eee_advert - disable unwanted eee mode advertisement
2062 * efficent ethernet modes. Returns 0 if the PHY's advertisement hasn't
2070 if (!phydev->eee_broken_modes) in genphy_config_eee_advert()
2074 phydev->eee_broken_modes, 0); in genphy_config_eee_advert()
2081 * genphy_setup_forced - configures/forces speed/duplex from @phydev
2092 phydev->pause = 0; in genphy_setup_forced()
2093 phydev->asym_pause = 0; in genphy_setup_forced()
2095 ctl = mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); in genphy_setup_forced()
2106 if (!phydev->is_gigabit_capable) in genphy_setup_master_slave()
2109 switch (phydev->master_slave_set) { in genphy_setup_master_slave()
2126 return -EOPNOTSUPP; in genphy_setup_master_slave()
2139 phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN; in genphy_read_master_slave()
2140 phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN; in genphy_read_master_slave()
2164 } else if (phydev->link) { in genphy_read_master_slave()
2174 phydev->master_slave_get = cfg; in genphy_read_master_slave()
2175 phydev->master_slave_state = state; in genphy_read_master_slave()
2182 * genphy_restart_aneg - Enable and Restart Autonegotiation
2187 /* Don't isolate the PHY if we're negotiating */ in genphy_restart_aneg()
2194 * genphy_check_and_restart_aneg - Enable and restart auto-negotiation
2198 * Check, and restart auto-negotiation if needed.
2206 * begin with? Or maybe phy was isolated? in genphy_check_and_restart_aneg()
2224 * __genphy_config_aneg - restart auto-negotiation or write BMCR
2228 * Description: If auto-negotiation is enabled, we configure the
2229 * advertising, and then restart auto-negotiation. If it is not
2248 if (AUTONEG_ENABLE != phydev->autoneg) in __genphy_config_aneg()
2262 * genphy_c37_config_aneg - restart auto-negotiation or write BMCR
2265 * Description: If auto-negotiation is enabled, we configure the
2266 * advertising, and then restart auto-negotiation. If it is not
2268 * for use with Clause 37 1000Base-X mode.
2274 if (phydev->autoneg != AUTONEG_ENABLE) in genphy_c37_config_aneg()
2288 * begin with? Or maybe phy was isolated? in genphy_c37_config_aneg()
2310 * genphy_aneg_done - return auto-negotiation status
2314 * auto-negotiation is incomplete, or if there was an error.
2315 * Returns BMSR_ANEGCOMPLETE if auto-negotiation is done.
2326 * genphy_update_link - update link status in @phydev
2329 * Description: Update the value in phydev->link to reflect the
2348 * drops can be detected. Do not double-read the status in genphy_update_link()
2352 if (!phy_polling_mode(phydev) || !phydev->link) { in genphy_update_link()
2365 phydev->link = status & BMSR_LSTATUS ? 1 : 0; in genphy_update_link()
2366 phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0; in genphy_update_link()
2371 if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete) in genphy_update_link()
2372 phydev->link = 0; in genphy_update_link()
2382 if (phydev->autoneg == AUTONEG_ENABLE) { in genphy_read_lpa()
2383 if (!phydev->autoneg_complete) { in genphy_read_lpa()
2384 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2386 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, 0); in genphy_read_lpa()
2390 if (phydev->is_gigabit_capable) { in genphy_read_lpa()
2405 return -ENOLINK; in genphy_read_lpa()
2408 mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, in genphy_read_lpa()
2416 mii_lpa_mod_linkmode_lpa_t(phydev->lp_advertising, lpa); in genphy_read_lpa()
2418 linkmode_zero(phydev->lp_advertising); in genphy_read_lpa()
2426 * genphy_read_status_fixed - read the link parameters for !aneg mode
2429 * Read the current duplex and speed state for a PHY operating with
2440 phydev->duplex = DUPLEX_FULL; in genphy_read_status_fixed()
2442 phydev->duplex = DUPLEX_HALF; in genphy_read_status_fixed()
2445 phydev->speed = SPEED_1000; in genphy_read_status_fixed()
2447 phydev->speed = SPEED_100; in genphy_read_status_fixed()
2449 phydev->speed = SPEED_10; in genphy_read_status_fixed()
2456 * genphy_read_status - check the link status and update current link state
2466 int err, old_link = phydev->link; in genphy_read_status()
2473 /* why bother the PHY if nothing can have changed */ in genphy_read_status()
2474 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in genphy_read_status()
2477 phydev->master_slave_get = MASTER_SLAVE_CFG_UNSUPPORTED; in genphy_read_status()
2478 phydev->master_slave_state = MASTER_SLAVE_STATE_UNSUPPORTED; in genphy_read_status()
2479 phydev->speed = SPEED_UNKNOWN; in genphy_read_status()
2480 phydev->duplex = DUPLEX_UNKNOWN; in genphy_read_status()
2481 phydev->pause = 0; in genphy_read_status()
2482 phydev->asym_pause = 0; in genphy_read_status()
2484 if (phydev->is_gigabit_capable) { in genphy_read_status()
2494 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_read_status()
2496 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_read_status()
2507 * genphy_c37_read_status - check the link status and update current link state
2512 * advertises. This function is for Clause 37 1000Base-X mode.
2516 int lpa, err, old_link = phydev->link; in genphy_c37_read_status()
2523 /* why bother the PHY if nothing can have changed */ in genphy_c37_read_status()
2524 if (phydev->autoneg == AUTONEG_ENABLE && old_link && phydev->link) in genphy_c37_read_status()
2527 phydev->duplex = DUPLEX_UNKNOWN; in genphy_c37_read_status()
2528 phydev->pause = 0; in genphy_c37_read_status()
2529 phydev->asym_pause = 0; in genphy_c37_read_status()
2531 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) { in genphy_c37_read_status()
2537 phydev->lp_advertising, lpa & LPA_LPACK); in genphy_c37_read_status()
2539 phydev->lp_advertising, lpa & LPA_1000XFULL); in genphy_c37_read_status()
2541 phydev->lp_advertising, lpa & LPA_1000XPAUSE); in genphy_c37_read_status()
2543 phydev->lp_advertising, in genphy_c37_read_status()
2547 } else if (phydev->autoneg == AUTONEG_DISABLE) { in genphy_c37_read_status()
2554 phydev->duplex = DUPLEX_FULL; in genphy_c37_read_status()
2556 phydev->duplex = DUPLEX_HALF; in genphy_c37_read_status()
2564 * genphy_soft_reset - software reset the PHY via BMCR_RESET bit
2567 * Description: Perform a software PHY reset using the standard
2577 if (phydev->autoneg == AUTONEG_ENABLE) in genphy_soft_reset()
2588 phydev->suspended = 0; in genphy_soft_reset()
2595 if (phydev->autoneg == AUTONEG_DISABLE) in genphy_soft_reset()
2605 * entity (ie an IRQ controller embedded inside the PHY) and do not in genphy_handle_interrupt_no_ack()
2616 * genphy_read_abilities - read PHY abilities from Clause 22 registers
2619 * Description: Reads the PHY's abilities and populates
2620 * phydev->supported accordingly.
2630 phydev->supported); in genphy_read_abilities()
2636 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported, in genphy_read_abilities()
2639 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2641 linkmode_mod_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2643 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Full_BIT, phydev->supported, in genphy_read_abilities()
2645 linkmode_mod_bit(ETHTOOL_LINK_MODE_10baseT_Half_BIT, phydev->supported, in genphy_read_abilities()
2654 phydev->supported, val & ESTATUS_1000_TFULL); in genphy_read_abilities()
2656 phydev->supported, val & ESTATUS_1000_THALF); in genphy_read_abilities()
2658 phydev->supported, val & ESTATUS_1000_XFULL); in genphy_read_abilities()
2670 /* This is used for the phy device which doesn't support the MMD extended
2676 return -EOPNOTSUPP; in genphy_read_mmd_unsupported()
2683 return -EOPNOTSUPP; in genphy_write_mmd_unsupported()
2705 ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex); in genphy_loopback()
2725 * phy_remove_link_mode - Remove a supported link mode
2729 * Description: Some MACs don't support all link modes which the PHY
2735 linkmode_clear_bit(link_mode, phydev->supported); in phy_remove_link_mode()
2749 * phy_advertise_supported - Advertise all supported modes
2759 linkmode_copy(new, phydev->supported); in phy_advertise_supported()
2760 phy_copy_pause_bits(new, phydev->advertising); in phy_advertise_supported()
2761 linkmode_copy(phydev->advertising, new); in phy_advertise_supported()
2766 * phy_support_sym_pause - Enable support of symmetrical pause
2774 linkmode_clear_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported); in phy_support_sym_pause()
2775 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_sym_pause()
2780 * phy_support_asym_pause - Enable support of asym pause
2787 phy_copy_pause_bits(phydev->advertising, phydev->supported); in phy_support_asym_pause()
2792 * phy_set_sym_pause - Configure symmetric Pause
2805 linkmode_clear_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported); in phy_set_sym_pause()
2809 phydev->supported); in phy_set_sym_pause()
2811 linkmode_copy(phydev->advertising, phydev->supported); in phy_set_sym_pause()
2816 * phy_set_asym_pause - Configure Pause and Asym Pause
2830 linkmode_copy(oldadv, phydev->advertising); in phy_set_asym_pause()
2831 linkmode_set_pause(phydev->advertising, tx, rx); in phy_set_asym_pause()
2833 if (!linkmode_equal(oldadv, phydev->advertising) && in phy_set_asym_pause()
2834 phydev->autoneg) in phy_set_asym_pause()
2840 * phy_validate_pause - Test if the PHY/MAC support the pause configuration
2844 * Description: Test if the PHY/MAC combination supports the Pause
2852 phydev->supported) && pp->rx_pause) in phy_validate_pause()
2856 phydev->supported) && in phy_validate_pause()
2857 pp->rx_pause != pp->tx_pause) in phy_validate_pause()
2865 * phy_get_pause - resolve negotiated pause modes
2878 if (phydev->duplex != DUPLEX_FULL) { in phy_get_pause()
2884 return linkmode_resolve_pause(phydev->advertising, in phy_get_pause()
2885 phydev->lp_advertising, in phy_get_pause()
2891 static int phy_get_int_delay_property(struct device *dev, const char *name) in phy_get_int_delay_property()
2903 static int phy_get_int_delay_property(struct device *dev, const char *name) in phy_get_int_delay_property()
2905 return -EINVAL; in phy_get_int_delay_property()
2910 * phy_get_internal_delay - returns the index of the internal delay
2912 * @dev: pointer to the devices device struct
2913 * @delay_values: array of delays the PHY supports
2918 * If the device property is not present then the interface type is checked
2921 * The array must be in ascending order. If PHY does not have an ascending order
2923 * Return -EINVAL if the delay is invalid or cannot be found.
2925 s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev, in phy_get_internal_delay()
2932 delay = phy_get_int_delay_property(dev, "rx-internal-delay-ps"); in phy_get_internal_delay()
2934 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
2935 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) in phy_get_internal_delay()
2942 delay = phy_get_int_delay_property(dev, "tx-internal-delay-ps"); in phy_get_internal_delay()
2944 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in phy_get_internal_delay()
2945 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) in phy_get_internal_delay()
2958 if (delay < delay_values[0] || delay > delay_values[size - 1]) { in phy_get_internal_delay()
2960 return -EINVAL; in phy_get_internal_delay()
2971 if (delay > delay_values[i - 1] && in phy_get_internal_delay()
2973 if (delay - delay_values[i - 1] < in phy_get_internal_delay()
2974 delay_values[i] - delay) in phy_get_internal_delay()
2975 return i - 1; in phy_get_internal_delay()
2984 return -EINVAL; in phy_get_internal_delay()
2990 return phydrv->config_intr && phydrv->handle_interrupt; in phy_drv_supports_irq()
2997 struct phy_device *phydev = phyled->phydev; in phy_led_set_brightness()
3000 mutex_lock(&phydev->lock); in phy_led_set_brightness()
3001 err = phydev->drv->led_brightness_set(phydev, phyled->index, value); in phy_led_set_brightness()
3002 mutex_unlock(&phydev->lock); in phy_led_set_brightness()
3012 struct phy_device *phydev = phyled->phydev; in phy_led_blink_set()
3015 mutex_lock(&phydev->lock); in phy_led_blink_set()
3016 err = phydev->drv->led_blink_set(phydev, phyled->index, in phy_led_blink_set()
3018 mutex_unlock(&phydev->lock); in phy_led_blink_set()
3023 static __maybe_unused struct device *
3027 struct phy_device *phydev = phyled->phydev; in phy_led_hw_control_get_device()
3029 if (phydev->attached_dev) in phy_led_hw_control_get_device()
3030 return &phydev->attached_dev->dev; in phy_led_hw_control_get_device()
3039 struct phy_device *phydev = phyled->phydev; in phy_led_hw_control_get()
3042 mutex_lock(&phydev->lock); in phy_led_hw_control_get()
3043 err = phydev->drv->led_hw_control_get(phydev, phyled->index, rules); in phy_led_hw_control_get()
3044 mutex_unlock(&phydev->lock); in phy_led_hw_control_get()
3054 struct phy_device *phydev = phyled->phydev; in phy_led_hw_control_set()
3057 mutex_lock(&phydev->lock); in phy_led_hw_control_set()
3058 err = phydev->drv->led_hw_control_set(phydev, phyled->index, rules); in phy_led_hw_control_set()
3059 mutex_unlock(&phydev->lock); in phy_led_hw_control_set()
3068 struct phy_device *phydev = phyled->phydev; in phy_led_hw_is_supported()
3071 mutex_lock(&phydev->lock); in phy_led_hw_is_supported()
3072 err = phydev->drv->led_hw_is_supported(phydev, phyled->index, rules); in phy_led_hw_is_supported()
3073 mutex_unlock(&phydev->lock); in phy_led_hw_is_supported()
3082 list_for_each_entry(phyled, &phydev->leds, list) { in phy_leds_unregister()
3083 led_classdev_unregister(&phyled->led_cdev); in phy_leds_unregister()
3090 struct device *dev = &phydev->mdio.dev; in of_phy_led()
3099 return -ENOMEM; in of_phy_led()
3101 cdev = &phyled->led_cdev; in of_phy_led()
3102 phyled->phydev = phydev; in of_phy_led()
3108 return -EINVAL; in of_phy_led()
3110 phyled->index = index; in of_phy_led()
3111 if (phydev->drv->led_brightness_set) in of_phy_led()
3112 cdev->brightness_set_blocking = phy_led_set_brightness; in of_phy_led()
3113 if (phydev->drv->led_blink_set) in of_phy_led()
3114 cdev->blink_set = phy_led_blink_set; in of_phy_led()
3117 if (phydev->drv->led_hw_is_supported && in of_phy_led()
3118 phydev->drv->led_hw_control_set && in of_phy_led()
3119 phydev->drv->led_hw_control_get) { in of_phy_led()
3120 cdev->hw_control_is_supported = phy_led_hw_is_supported; in of_phy_led()
3121 cdev->hw_control_set = phy_led_hw_control_set; in of_phy_led()
3122 cdev->hw_control_get = phy_led_hw_control_get; in of_phy_led()
3123 cdev->hw_control_trigger = "netdev"; in of_phy_led()
3126 cdev->hw_control_get_device = phy_led_hw_control_get_device; in of_phy_led()
3128 cdev->max_brightness = 1; in of_phy_led()
3129 init_data.devicename = dev_name(&phydev->mdio.dev); in of_phy_led()
3137 list_add(&phyled->list, &phydev->leds); in of_phy_led()
3144 struct device_node *node = phydev->mdio.dev.of_node; in of_phy_leds()
3171 * fwnode_mdio_find_device - Given a fwnode, find the mdio_device
3175 * struct device refcount incremented by one, or NULL on failure.
3180 struct device *d; in fwnode_mdio_find_device()
3194 * fwnode_phy_find_device - For provided phy_fwnode, find phy_device.
3196 * @phy_fwnode: Pointer to the phy's fwnode.
3199 * struct device refcount incremented by one, or NULL on failure.
3209 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) in fwnode_phy_find_device()
3210 return to_phy_device(&mdiodev->dev); in fwnode_phy_find_device()
3212 put_device(&mdiodev->dev); in fwnode_phy_find_device()
3219 * device_phy_find_device - For the given device, get the phy_device
3220 * @dev: Pointer to the given device
3224 struct phy_device *device_phy_find_device(struct device *dev) in device_phy_find_device()
3231 * fwnode_get_phy_node - Get the phy_node using the named reference.
3235 * For ACPI, only "phy-handle" is supported. Legacy DT properties "phy"
3236 * and "phy-device" are not supported in ACPI. DT supports all the three
3237 * named references to the phy node.
3243 /* Only phy-handle is used for ACPI */ in fwnode_get_phy_node()
3244 phy_node = fwnode_find_reference(fwnode, "phy-handle", 0); in fwnode_get_phy_node()
3247 phy_node = fwnode_find_reference(fwnode, "phy", 0); in fwnode_get_phy_node()
3249 phy_node = fwnode_find_reference(fwnode, "phy-device", 0); in fwnode_get_phy_node()
3255 * phy_probe - probe and init a PHY device
3256 * @dev: device to probe and init
3260 static int phy_probe(struct device *dev) in phy_probe()
3263 struct device_driver *drv = phydev->mdio.dev.driver; in phy_probe()
3267 phydev->drv = phydrv; in phy_probe()
3269 /* Disable the interrupt if the PHY doesn't support it in phy_probe()
3273 phydev->irq = PHY_POLL; in phy_probe()
3275 if (phydrv->flags & PHY_IS_INTERNAL) in phy_probe()
3276 phydev->is_internal = true; in phy_probe()
3281 if (phydev->drv->probe) { in phy_probe()
3282 err = phydev->drv->probe(phydev); in phy_probe()
3293 if (phydrv->features) { in phy_probe()
3294 linkmode_copy(phydev->supported, phydrv->features); in phy_probe()
3297 else if (phydrv->get_features) in phy_probe()
3298 err = phydrv->get_features(phydev); in phy_probe()
3299 else if (phydev->is_c45) in phy_probe()
3308 phydev->supported)) in phy_probe()
3309 phydev->autoneg = 0; in phy_probe()
3312 phydev->supported)) in phy_probe()
3313 phydev->is_gigabit_capable = 1; in phy_probe()
3315 phydev->supported)) in phy_probe()
3316 phydev->is_gigabit_capable = 1; in phy_probe()
3321 /* Get PHY default EEE advertising modes and handle them as potentially in phy_probe()
3324 err = genphy_c45_read_eee_adv(phydev, phydev->advertising_eee); in phy_probe()
3328 /* There is no "enabled" flag. If PHY is advertising, assume it is in phy_probe()
3331 phydev->eee_enabled = !linkmode_empty(phydev->advertising_eee); in phy_probe()
3336 if (phydev->eee_enabled) in phy_probe()
3337 linkmode_and(phydev->advertising_eee, phydev->supported_eee, in phy_probe()
3338 phydev->advertising_eee); in phy_probe()
3341 * the PHY stop advertising these mode later on in phy_probe()
3345 /* The Pause Frame bits indicate that the PHY can support passing in phy_probe()
3351 * Normally, PHY drivers should not set the Pause bits, and instead in phy_probe()
3356 if (!test_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->supported) && in phy_probe()
3357 !test_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->supported)) { in phy_probe()
3359 phydev->supported); in phy_probe()
3361 phydev->supported); in phy_probe()
3365 phydev->state = PHY_READY; in phy_probe()
3367 /* Get the LEDs from the device tree, and instantiate standard in phy_probe()
3374 /* Re-assert the reset signal on error */ in phy_probe()
3381 static int phy_remove(struct device *dev) in phy_remove()
3385 cancel_delayed_work_sync(&phydev->state_queue); in phy_remove()
3390 phydev->state = PHY_DOWN; in phy_remove()
3392 sfp_bus_del_upstream(phydev->sfp_bus); in phy_remove()
3393 phydev->sfp_bus = NULL; in phy_remove()
3395 if (phydev->drv && phydev->drv->remove) in phy_remove()
3396 phydev->drv->remove(phydev); in phy_remove()
3401 phydev->drv = NULL; in phy_remove()
3407 * phy_driver_register - register a phy_driver with the PHY layer
3409 * @owner: module owning this PHY
3418 if (WARN_ON(new_driver->features && new_driver->get_features)) { in phy_driver_register()
3420 new_driver->name); in phy_driver_register()
3421 return -EINVAL; in phy_driver_register()
3424 /* PHYLIB device drivers must not match using a DT compatible table in phy_driver_register()
3427 * make out-of-bounds accesses and lockup in phydev->lock. in phy_driver_register()
3429 if (WARN(new_driver->mdiodrv.driver.of_match_table, in phy_driver_register()
3431 new_driver->name)) in phy_driver_register()
3432 return -EINVAL; in phy_driver_register()
3434 new_driver->mdiodrv.flags |= MDIO_DEVICE_IS_PHY; in phy_driver_register()
3435 new_driver->mdiodrv.driver.name = new_driver->name; in phy_driver_register()
3436 new_driver->mdiodrv.driver.bus = &mdio_bus_type; in phy_driver_register()
3437 new_driver->mdiodrv.driver.probe = phy_probe; in phy_driver_register()
3438 new_driver->mdiodrv.driver.remove = phy_remove; in phy_driver_register()
3439 new_driver->mdiodrv.driver.owner = owner; in phy_driver_register()
3440 new_driver->mdiodrv.driver.probe_type = PROBE_FORCE_SYNCHRONOUS; in phy_driver_register()
3442 retval = driver_register(&new_driver->mdiodrv.driver); in phy_driver_register()
3445 new_driver->name, retval); in phy_driver_register()
3450 pr_debug("%s: Registered new driver\n", new_driver->name); in phy_driver_register()
3464 while (i-- > 0) in phy_drivers_register()
3475 driver_unregister(&drv->mdiodrv.driver); in phy_driver_unregister()
3491 .name = "Generic PHY",