Lines Matching +full:link +full:- +full:trigger +full:- +full:order +full:- +full:stop
1 // SPDX-License-Identifier: GPL-2.0+
64 if (old_state != phydev->state) { in phy_process_state_change()
65 phydev_dbg(phydev, "PHY state change %s -> %s\n", in phy_process_state_change()
67 phy_state_to_str(phydev->state)); in phy_process_state_change()
68 if (phydev->drv && phydev->drv->link_change_notify) in phy_process_state_change()
69 phydev->drv->link_change_notify(phydev); in phy_process_state_change()
75 phydev->phy_link_change(phydev, true); in phy_link_up()
81 phydev->phy_link_change(phydev, false); in phy_link_down()
83 WRITE_ONCE(phydev->link_down_events, phydev->link_down_events + 1); in phy_link_down()
90 if (phydev->autoneg == AUTONEG_DISABLE) in phy_pause_str()
94 phydev->advertising); in phy_pause_str()
96 phydev->advertising); in phy_pause_str()
98 if (local_pause && phydev->pause) in phy_pause_str()
101 if (local_asym_pause && phydev->asym_pause) { in phy_pause_str()
104 if (phydev->pause) in phy_pause_str()
113 * phy_print_status - Convenience function to print out the current phy status
118 if (phydev->link) { in phy_print_status()
119 netdev_info(phydev->attached_dev, in phy_print_status()
120 "Link is Up - %s/%s %s- flow control %s\n", in phy_print_status()
121 phy_speed_to_str(phydev->speed), in phy_print_status()
122 phy_duplex_to_str(phydev->duplex), in phy_print_status()
123 phydev->downshifted_rate ? "(downshifted) " : "", in phy_print_status()
126 netdev_info(phydev->attached_dev, "Link is Down\n"); in phy_print_status()
132 * phy_get_rate_matching - determine if rate matching is supported
148 if (phydev->drv->get_rate_matching) { in phy_get_rate_matching()
149 mutex_lock(&phydev->lock); in phy_get_rate_matching()
150 ret = phydev->drv->get_rate_matching(phydev, iface); in phy_get_rate_matching()
151 mutex_unlock(&phydev->lock); in phy_get_rate_matching()
159 * phy_config_interrupt - configure the PHY device for the requested interrupts
167 phydev->interrupts = interrupts ? 1 : 0; in phy_config_interrupt()
168 if (phydev->drv->config_intr) in phy_config_interrupt()
169 return phydev->drv->config_intr(phydev); in phy_config_interrupt()
175 * phy_restart_aneg - restart auto-negotiation
185 if (phydev->is_c45 && !(phydev->c45_ids.devices_in_package & BIT(0))) in phy_restart_aneg()
195 * phy_aneg_done - return auto-negotiation status
198 * Description: Return the auto-negotiation status from this @phydev
199 * Returns > 0 on success or < 0 on error. 0 means that auto-negotiation
204 if (phydev->drv && phydev->drv->aneg_done) in phy_aneg_done()
205 return phydev->drv->aneg_done(phydev); in phy_aneg_done()
206 else if (phydev->is_c45) in phy_aneg_done()
214 * phy_find_valid - find a PHY setting that matches the requested parameters
217 * @supported: mask of supported link modes
219 * Locate a supported phy setting that is, in priority order:
220 * - an exact match for the specified speed and duplex mode
221 * - a match for the specified speed, or slower speed
222 * - the slowest supported speed
233 * phy_supported_speeds - return all speeds currently supported by a phy device
246 return phy_speeds(speeds, size, phy->supported); in phy_supported_speeds()
250 * phy_check_valid - check if there is a valid PHY setting which matches
265 * phy_sanitize_settings - make sure the PHY is set to supported speed and duplex
269 * duplexes. Drop down by one in this order: 1000/FULL,
276 setting = phy_find_valid(phydev->speed, phydev->duplex, in phy_sanitize_settings()
277 phydev->supported); in phy_sanitize_settings()
279 phydev->speed = setting->speed; in phy_sanitize_settings()
280 phydev->duplex = setting->duplex; in phy_sanitize_settings()
283 phydev->speed = SPEED_UNKNOWN; in phy_sanitize_settings()
284 phydev->duplex = DUPLEX_UNKNOWN; in phy_sanitize_settings()
291 mutex_lock(&phydev->lock); in phy_ethtool_ksettings_get()
292 linkmode_copy(cmd->link_modes.supported, phydev->supported); in phy_ethtool_ksettings_get()
293 linkmode_copy(cmd->link_modes.advertising, phydev->advertising); in phy_ethtool_ksettings_get()
294 linkmode_copy(cmd->link_modes.lp_advertising, phydev->lp_advertising); in phy_ethtool_ksettings_get()
296 cmd->base.speed = phydev->speed; in phy_ethtool_ksettings_get()
297 cmd->base.duplex = phydev->duplex; in phy_ethtool_ksettings_get()
298 cmd->base.master_slave_cfg = phydev->master_slave_get; in phy_ethtool_ksettings_get()
299 cmd->base.master_slave_state = phydev->master_slave_state; in phy_ethtool_ksettings_get()
300 cmd->base.rate_matching = phydev->rate_matching; in phy_ethtool_ksettings_get()
301 if (phydev->interface == PHY_INTERFACE_MODE_MOCA) in phy_ethtool_ksettings_get()
302 cmd->base.port = PORT_BNC; in phy_ethtool_ksettings_get()
304 cmd->base.port = phydev->port; in phy_ethtool_ksettings_get()
305 cmd->base.transceiver = phy_is_internal(phydev) ? in phy_ethtool_ksettings_get()
307 cmd->base.phy_address = phydev->mdio.addr; in phy_ethtool_ksettings_get()
308 cmd->base.autoneg = phydev->autoneg; in phy_ethtool_ksettings_get()
309 cmd->base.eth_tp_mdix_ctrl = phydev->mdix_ctrl; in phy_ethtool_ksettings_get()
310 cmd->base.eth_tp_mdix = phydev->mdix; in phy_ethtool_ksettings_get()
311 mutex_unlock(&phydev->lock); in phy_ethtool_ksettings_get()
316 * phy_mii_ioctl - generic PHY MII ioctl interface
330 u16 val = mii_data->val_in; in phy_mii_ioctl()
338 mii_data->phy_id = phydev->mdio.addr; in phy_mii_ioctl()
342 if (mdio_phy_id_is_c45(mii_data->phy_id)) { in phy_mii_ioctl()
343 prtad = mdio_phy_id_prtad(mii_data->phy_id); in phy_mii_ioctl()
344 devad = mdio_phy_id_devad(mii_data->phy_id); in phy_mii_ioctl()
345 ret = mdiobus_c45_read(phydev->mdio.bus, prtad, devad, in phy_mii_ioctl()
346 mii_data->reg_num); in phy_mii_ioctl()
349 ret = mdiobus_read(phydev->mdio.bus, mii_data->phy_id, in phy_mii_ioctl()
350 mii_data->reg_num); in phy_mii_ioctl()
356 mii_data->val_out = ret; in phy_mii_ioctl()
361 if (mdio_phy_id_is_c45(mii_data->phy_id)) { in phy_mii_ioctl()
362 prtad = mdio_phy_id_prtad(mii_data->phy_id); in phy_mii_ioctl()
363 devad = mdio_phy_id_devad(mii_data->phy_id); in phy_mii_ioctl()
365 prtad = mii_data->phy_id; in phy_mii_ioctl()
366 devad = mii_data->reg_num; in phy_mii_ioctl()
368 if (prtad == phydev->mdio.addr) { in phy_mii_ioctl()
372 if (phydev->autoneg == AUTONEG_ENABLE) in phy_mii_ioctl()
374 phydev->autoneg = AUTONEG_DISABLE; in phy_mii_ioctl()
376 phydev->duplex = DUPLEX_FULL; in phy_mii_ioctl()
378 phydev->duplex = DUPLEX_HALF; in phy_mii_ioctl()
380 phydev->speed = SPEED_1000; in phy_mii_ioctl()
382 phydev->speed = SPEED_100; in phy_mii_ioctl()
383 else phydev->speed = SPEED_10; in phy_mii_ioctl()
385 if (phydev->autoneg == AUTONEG_DISABLE) in phy_mii_ioctl()
387 phydev->autoneg = AUTONEG_ENABLE; in phy_mii_ioctl()
391 mii_adv_mod_linkmode_adv_t(phydev->advertising, in phy_mii_ioctl()
396 mii_ctrl1000_mod_linkmode_adv_t(phydev->advertising, in phy_mii_ioctl()
406 if (mdio_phy_id_is_c45(mii_data->phy_id)) in phy_mii_ioctl()
407 mdiobus_c45_write(phydev->mdio.bus, prtad, devad, in phy_mii_ioctl()
408 mii_data->reg_num, val); in phy_mii_ioctl()
410 mdiobus_write(phydev->mdio.bus, prtad, devad, val); in phy_mii_ioctl()
412 if (prtad == phydev->mdio.addr && in phy_mii_ioctl()
423 if (phydev->mii_ts && phydev->mii_ts->hwtstamp) { in phy_mii_ioctl()
424 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg))) in phy_mii_ioctl()
425 return -EFAULT; in phy_mii_ioctl()
428 ret = phydev->mii_ts->hwtstamp(phydev->mii_ts, &kernel_cfg, &extack); in phy_mii_ioctl()
433 if (copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg))) in phy_mii_ioctl()
434 return -EFAULT; in phy_mii_ioctl()
441 return -EOPNOTSUPP; in phy_mii_ioctl()
447 * phy_do_ioctl - generic ndo_eth_ioctl implementation
454 if (!dev->phydev) in phy_do_ioctl()
455 return -ENODEV; in phy_do_ioctl()
457 return phy_mii_ioctl(dev->phydev, ifr, cmd); in phy_do_ioctl()
462 * phy_do_ioctl_running - generic ndo_eth_ioctl implementation but test first
474 return -ENODEV; in phy_do_ioctl_running()
481 * __phy_hwtstamp_get - Get hardware timestamping configuration from PHY
492 return -ENODEV; in __phy_hwtstamp_get()
494 return -EOPNOTSUPP; in __phy_hwtstamp_get()
498 * __phy_hwtstamp_set - Modify PHY hardware timestamping configuration
509 return -ENODEV; in __phy_hwtstamp_set()
511 if (phydev->mii_ts && phydev->mii_ts->hwtstamp) in __phy_hwtstamp_set()
512 return phydev->mii_ts->hwtstamp(phydev->mii_ts, config, extack); in __phy_hwtstamp_set()
514 return -EOPNOTSUPP; in __phy_hwtstamp_set()
518 * phy_queue_state_machine - Trigger the state machine to run soon
525 mod_delayed_work(system_power_efficient_wq, &phydev->state_queue, in phy_queue_state_machine()
531 * phy_trigger_machine - Trigger the state machine to run now
553 * phy_ethtool_get_strings - Get the statistic counter names
560 if (!phydev->drv) in phy_ethtool_get_strings()
561 return -EIO; in phy_ethtool_get_strings()
563 mutex_lock(&phydev->lock); in phy_ethtool_get_strings()
564 phydev->drv->get_strings(phydev, data); in phy_ethtool_get_strings()
565 mutex_unlock(&phydev->lock); in phy_ethtool_get_strings()
572 * phy_ethtool_get_sset_count - Get the number of statistic counters
580 if (!phydev->drv) in phy_ethtool_get_sset_count()
581 return -EIO; in phy_ethtool_get_sset_count()
583 if (phydev->drv->get_sset_count && in phy_ethtool_get_sset_count()
584 phydev->drv->get_strings && in phy_ethtool_get_sset_count()
585 phydev->drv->get_stats) { in phy_ethtool_get_sset_count()
586 mutex_lock(&phydev->lock); in phy_ethtool_get_sset_count()
587 ret = phydev->drv->get_sset_count(phydev); in phy_ethtool_get_sset_count()
588 mutex_unlock(&phydev->lock); in phy_ethtool_get_sset_count()
593 return -EOPNOTSUPP; in phy_ethtool_get_sset_count()
598 * phy_ethtool_get_stats - Get the statistic counters
607 if (!phydev->drv) in phy_ethtool_get_stats()
608 return -EIO; in phy_ethtool_get_stats()
610 mutex_lock(&phydev->lock); in phy_ethtool_get_stats()
611 phydev->drv->get_stats(phydev, stats, data); in phy_ethtool_get_stats()
612 mutex_unlock(&phydev->lock); in phy_ethtool_get_stats()
619 * phy_ethtool_get_plca_cfg - Get PLCA RS configuration
631 if (!phydev->drv) { in phy_ethtool_get_plca_cfg()
632 ret = -EIO; in phy_ethtool_get_plca_cfg()
636 if (!phydev->drv->get_plca_cfg) { in phy_ethtool_get_plca_cfg()
637 ret = -EOPNOTSUPP; in phy_ethtool_get_plca_cfg()
641 mutex_lock(&phydev->lock); in phy_ethtool_get_plca_cfg()
642 ret = phydev->drv->get_plca_cfg(phydev, plca_cfg); in phy_ethtool_get_plca_cfg()
644 mutex_unlock(&phydev->lock); in phy_ethtool_get_plca_cfg()
650 * plca_check_valid - Check PLCA configuration before enabling
666 phydev->advertising)) { in plca_check_valid()
667 ret = -EOPNOTSUPP; in plca_check_valid()
669 "Point to Multi-Point mode is not enabled"); in plca_check_valid()
670 } else if (plca_cfg->node_id >= 255) { in plca_check_valid()
672 ret = -EINVAL; in plca_check_valid()
679 * phy_ethtool_set_plca_cfg - Set PLCA RS configuration
694 if (!phydev->drv) { in phy_ethtool_set_plca_cfg()
695 ret = -EIO; in phy_ethtool_set_plca_cfg()
699 if (!phydev->drv->set_plca_cfg || in phy_ethtool_set_plca_cfg()
700 !phydev->drv->get_plca_cfg) { in phy_ethtool_set_plca_cfg()
701 ret = -EOPNOTSUPP; in phy_ethtool_set_plca_cfg()
707 ret = -ENOMEM; in phy_ethtool_set_plca_cfg()
711 mutex_lock(&phydev->lock); in phy_ethtool_set_plca_cfg()
713 ret = phydev->drv->get_plca_cfg(phydev, curr_plca_cfg); in phy_ethtool_set_plca_cfg()
717 if (curr_plca_cfg->enabled < 0 && plca_cfg->enabled >= 0) { in phy_ethtool_set_plca_cfg()
720 ret = -EINVAL; in phy_ethtool_set_plca_cfg()
724 if (curr_plca_cfg->node_id < 0 && plca_cfg->node_id >= 0) { in phy_ethtool_set_plca_cfg()
727 ret = -EINVAL; in phy_ethtool_set_plca_cfg()
731 if (curr_plca_cfg->node_cnt < 0 && plca_cfg->node_cnt >= 0) { in phy_ethtool_set_plca_cfg()
734 ret = -EINVAL; in phy_ethtool_set_plca_cfg()
738 if (curr_plca_cfg->to_tmr < 0 && plca_cfg->to_tmr >= 0) { in phy_ethtool_set_plca_cfg()
741 ret = -EINVAL; in phy_ethtool_set_plca_cfg()
745 if (curr_plca_cfg->burst_cnt < 0 && plca_cfg->burst_cnt >= 0) { in phy_ethtool_set_plca_cfg()
748 ret = -EINVAL; in phy_ethtool_set_plca_cfg()
752 if (curr_plca_cfg->burst_tmr < 0 && plca_cfg->burst_tmr >= 0) { in phy_ethtool_set_plca_cfg()
755 ret = -EINVAL; in phy_ethtool_set_plca_cfg()
760 if (plca_cfg->enabled > 0) { in phy_ethtool_set_plca_cfg()
762 if (plca_cfg->node_id >= 0) in phy_ethtool_set_plca_cfg()
763 curr_plca_cfg->node_id = plca_cfg->node_id; in phy_ethtool_set_plca_cfg()
770 ret = phydev->drv->set_plca_cfg(phydev, plca_cfg); in phy_ethtool_set_plca_cfg()
774 mutex_unlock(&phydev->lock); in phy_ethtool_set_plca_cfg()
780 * phy_ethtool_get_plca_status - Get PLCA RS status information
792 if (!phydev->drv) { in phy_ethtool_get_plca_status()
793 ret = -EIO; in phy_ethtool_get_plca_status()
797 if (!phydev->drv->get_plca_status) { in phy_ethtool_get_plca_status()
798 ret = -EOPNOTSUPP; in phy_ethtool_get_plca_status()
802 mutex_lock(&phydev->lock); in phy_ethtool_get_plca_status()
803 ret = phydev->drv->get_plca_status(phydev, plca_st); in phy_ethtool_get_plca_status()
805 mutex_unlock(&phydev->lock); in phy_ethtool_get_plca_status()
811 * phy_start_cable_test - Start a cable test
819 struct net_device *dev = phydev->attached_dev; in phy_start_cable_test()
820 int err = -ENOMEM; in phy_start_cable_test()
822 if (!(phydev->drv && in phy_start_cable_test()
823 phydev->drv->cable_test_start && in phy_start_cable_test()
824 phydev->drv->cable_test_get_status)) { in phy_start_cable_test()
827 return -EOPNOTSUPP; in phy_start_cable_test()
830 mutex_lock(&phydev->lock); in phy_start_cable_test()
831 if (phydev->state == PHY_CABLETEST) { in phy_start_cable_test()
834 err = -EBUSY; in phy_start_cable_test()
838 if (phydev->state < PHY_UP || in phy_start_cable_test()
839 phydev->state > PHY_CABLETEST) { in phy_start_cable_test()
842 err = -EBUSY; in phy_start_cable_test()
854 err = phydev->drv->cable_test_start(phydev); in phy_start_cable_test()
861 phydev->state = PHY_CABLETEST; in phy_start_cable_test()
866 mutex_unlock(&phydev->lock); in phy_start_cable_test()
873 mutex_unlock(&phydev->lock); in phy_start_cable_test()
880 * phy_start_cable_test_tdr - Start a raw TDR cable test
890 struct net_device *dev = phydev->attached_dev; in phy_start_cable_test_tdr()
891 int err = -ENOMEM; in phy_start_cable_test_tdr()
893 if (!(phydev->drv && in phy_start_cable_test_tdr()
894 phydev->drv->cable_test_tdr_start && in phy_start_cable_test_tdr()
895 phydev->drv->cable_test_get_status)) { in phy_start_cable_test_tdr()
898 return -EOPNOTSUPP; in phy_start_cable_test_tdr()
901 mutex_lock(&phydev->lock); in phy_start_cable_test_tdr()
902 if (phydev->state == PHY_CABLETEST) { in phy_start_cable_test_tdr()
905 err = -EBUSY; in phy_start_cable_test_tdr()
909 if (phydev->state < PHY_UP || in phy_start_cable_test_tdr()
910 phydev->state > PHY_CABLETEST) { in phy_start_cable_test_tdr()
913 err = -EBUSY; in phy_start_cable_test_tdr()
925 err = phydev->drv->cable_test_tdr_start(phydev, config); in phy_start_cable_test_tdr()
932 phydev->state = PHY_CABLETEST; in phy_start_cable_test_tdr()
937 mutex_unlock(&phydev->lock); in phy_start_cable_test_tdr()
944 mutex_unlock(&phydev->lock); in phy_start_cable_test_tdr()
952 if (phydev->drv->config_aneg) in phy_config_aneg()
953 return phydev->drv->config_aneg(phydev); in phy_config_aneg()
958 if (phydev->is_c45 && !(phydev->c45_ids.devices_in_package & BIT(0))) in phy_config_aneg()
966 * phy_check_link_status - check link status and set state accordingly
969 * Description: Check for link and whether autoneg was triggered / is running
976 lockdep_assert_held(&phydev->lock); in phy_check_link_status()
979 * report that Link is Down when loopback is enabled. in phy_check_link_status()
981 if (phydev->loopback_enabled) in phy_check_link_status()
988 if (phydev->link && phydev->state != PHY_RUNNING) { in phy_check_link_status()
990 phydev->state = PHY_RUNNING; in phy_check_link_status()
993 phydev->eee_active = err > 0; in phy_check_link_status()
994 phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && in phy_check_link_status()
995 phydev->eee_active; in phy_check_link_status()
998 } else if (!phydev->link && phydev->state != PHY_NOLINK) { in phy_check_link_status()
999 phydev->state = PHY_NOLINK; in phy_check_link_status()
1000 phydev->eee_active = false; in phy_check_link_status()
1001 phydev->enable_tx_lpi = false; in phy_check_link_status()
1009 * _phy_start_aneg - start auto-negotiation for this PHY device
1015 * reflect the beginning of Auto-negotiation or forcing.
1021 lockdep_assert_held(&phydev->lock); in _phy_start_aneg()
1023 if (!phydev->drv) in _phy_start_aneg()
1024 return -EIO; in _phy_start_aneg()
1026 if (AUTONEG_DISABLE == phydev->autoneg) in _phy_start_aneg()
1041 * phy_start_aneg - start auto-negotiation for this PHY device
1047 * reflect the beginning of Auto-negotiation or forcing.
1053 mutex_lock(&phydev->lock); in phy_start_aneg()
1055 mutex_unlock(&phydev->lock); in phy_start_aneg()
1069 } while (!ret && --retries); in phy_poll_aneg_done()
1072 return -ETIMEDOUT; in phy_poll_aneg_done()
1081 u8 autoneg = cmd->base.autoneg; in phy_ethtool_ksettings_set()
1082 u8 duplex = cmd->base.duplex; in phy_ethtool_ksettings_set()
1083 u32 speed = cmd->base.speed; in phy_ethtool_ksettings_set()
1085 if (cmd->base.phy_address != phydev->mdio.addr) in phy_ethtool_ksettings_set()
1086 return -EINVAL; in phy_ethtool_ksettings_set()
1088 linkmode_copy(advertising, cmd->link_modes.advertising); in phy_ethtool_ksettings_set()
1091 linkmode_and(advertising, advertising, phydev->supported); in phy_ethtool_ksettings_set()
1095 return -EINVAL; in phy_ethtool_ksettings_set()
1100 phydev->supported))) in phy_ethtool_ksettings_set()
1101 return -EINVAL; in phy_ethtool_ksettings_set()
1109 return -EINVAL; in phy_ethtool_ksettings_set()
1111 mutex_lock(&phydev->lock); in phy_ethtool_ksettings_set()
1112 phydev->autoneg = autoneg; in phy_ethtool_ksettings_set()
1115 phydev->speed = speed; in phy_ethtool_ksettings_set()
1116 phydev->duplex = duplex; in phy_ethtool_ksettings_set()
1119 linkmode_copy(phydev->advertising, advertising); in phy_ethtool_ksettings_set()
1122 phydev->advertising, autoneg == AUTONEG_ENABLE); in phy_ethtool_ksettings_set()
1124 phydev->master_slave_set = cmd->base.master_slave_cfg; in phy_ethtool_ksettings_set()
1125 phydev->mdix_ctrl = cmd->base.eth_tp_mdix_ctrl; in phy_ethtool_ksettings_set()
1129 phydev->state = PHY_UP; in phy_ethtool_ksettings_set()
1135 mutex_unlock(&phydev->lock); in phy_ethtool_ksettings_set()
1141 * phy_speed_down - set speed to lowest speed supported by both link partners
1158 mutex_lock(&phydev->lock); in phy_speed_down()
1160 if (phydev->autoneg != AUTONEG_ENABLE) in phy_speed_down()
1163 linkmode_copy(adv_tmp, phydev->advertising); in phy_speed_down()
1169 linkmode_copy(phydev->adv_old, adv_tmp); in phy_speed_down()
1171 if (linkmode_equal(phydev->advertising, adv_tmp)) { in phy_speed_down()
1182 mutex_unlock(&phydev->lock); in phy_speed_down()
1189 * phy_speed_up - (re)set advertised speeds to all supported speeds
1199 mutex_lock(&phydev->lock); in phy_speed_up()
1201 if (phydev->autoneg != AUTONEG_ENABLE) in phy_speed_up()
1204 if (linkmode_empty(phydev->adv_old)) in phy_speed_up()
1207 linkmode_copy(adv_tmp, phydev->advertising); in phy_speed_up()
1208 linkmode_copy(phydev->advertising, phydev->adv_old); in phy_speed_up()
1209 linkmode_zero(phydev->adv_old); in phy_speed_up()
1211 if (linkmode_equal(phydev->advertising, adv_tmp)) in phy_speed_up()
1216 mutex_unlock(&phydev->lock); in phy_speed_up()
1223 * phy_start_machine - start PHY state machine tracking
1239 * phy_stop_machine - stop the PHY state machine tracking
1248 cancel_delayed_work_sync(&phydev->state_queue); in phy_stop_machine()
1250 mutex_lock(&phydev->lock); in phy_stop_machine()
1252 phydev->state = PHY_UP; in phy_stop_machine()
1253 mutex_unlock(&phydev->lock); in phy_stop_machine()
1258 /* phydev->lock must be held for the state change to be safe */ in phy_process_error()
1259 if (!mutex_is_locked(&phydev->lock)) in phy_process_error()
1260 phydev_err(phydev, "PHY-device data unsafe context\n"); in phy_process_error()
1262 phydev->state = PHY_ERROR; in phy_process_error()
1275 * phy_error - enter ERROR state for this PHY device
1279 * or write error, and tells the controller the link is down.
1280 * Must be called with phydev->lock held.
1290 * phy_disable_interrupts - Disable the PHY interrupts from the PHY side
1300 * phy_interrupt - PHY interrupt handler
1314 if (IS_ENABLED(CONFIG_PM_SLEEP) && phydev->irq_suspended) { in phy_interrupt()
1315 struct net_device *netdev = phydev->attached_dev; in phy_interrupt()
1318 struct device *parent = netdev->dev.parent; in phy_interrupt()
1320 if (netdev->ethtool->wol_enabled) in phy_interrupt()
1322 else if (device_may_wakeup(&netdev->dev)) in phy_interrupt()
1323 pm_wakeup_dev_event(&netdev->dev, 0, true); in phy_interrupt()
1328 phydev->irq_rerun = 1; in phy_interrupt()
1333 mutex_lock(&phydev->lock); in phy_interrupt()
1334 ret = phydev->drv->handle_interrupt(phydev); in phy_interrupt()
1335 mutex_unlock(&phydev->lock); in phy_interrupt()
1341 * phy_enable_interrupts - Enable the interrupts from the PHY side
1350 * phy_request_interrupt - request and enable interrupt for a PHY device
1361 err = request_threaded_irq(phydev->irq, NULL, phy_interrupt, in phy_request_interrupt()
1366 err, phydev->irq); in phy_request_interrupt()
1367 phydev->irq = PHY_POLL; in phy_request_interrupt()
1372 phydev->irq = PHY_POLL; in phy_request_interrupt()
1379 * phy_free_interrupt - disable and free interrupt for a PHY device
1388 free_irq(phydev->irq, phydev); in phy_free_interrupt()
1401 struct net_device *dev = phydev->attached_dev; in _phy_state_machine()
1402 enum phy_state old_state = phydev->state; in _phy_state_machine()
1407 switch (phydev->state) { in _phy_state_machine()
1420 err = phydev->drv->cable_test_get_status(phydev, &finished); in _phy_state_machine()
1425 phydev->state = PHY_UP; in _phy_state_machine()
1433 phydev->state = PHY_UP; in _phy_state_machine()
1438 if (phydev->link) { in _phy_state_machine()
1439 phydev->link = 0; in _phy_state_machine()
1451 if (err == -ENODEV) in _phy_state_machine()
1459 /* Only re-schedule a PHY state machine change if we are polling the in _phy_state_machine()
1482 * phy_state_machine - Handle the state machine
1492 mutex_lock(&phydev->lock); in phy_state_machine()
1494 mutex_unlock(&phydev->lock); in phy_state_machine()
1500 * phy_stop - Bring down the PHY link, and stop checking the status
1505 struct net_device *dev = phydev->attached_dev; in phy_stop()
1509 if (!phy_is_started(phydev) && phydev->state != PHY_DOWN && in phy_stop()
1510 phydev->state != PHY_ERROR) { in phy_stop()
1512 phy_state_to_str(phydev->state)); in phy_stop()
1516 mutex_lock(&phydev->lock); in phy_stop()
1517 old_state = phydev->state; in phy_stop()
1519 if (phydev->state == PHY_CABLETEST) { in phy_stop()
1524 if (phydev->sfp_bus) in phy_stop()
1525 sfp_upstream_stop(phydev->sfp_bus); in phy_stop()
1527 phydev->state = PHY_HALTED; in phy_stop()
1531 mutex_unlock(&phydev->lock); in phy_stop()
1544 * phy_start - start or restart a PHY device
1548 * handle PHY-related work. Used during startup to start the
1555 mutex_lock(&phydev->lock); in phy_start()
1557 if (phydev->state != PHY_READY && phydev->state != PHY_HALTED) { in phy_start()
1559 phy_state_to_str(phydev->state)); in phy_start()
1563 if (phydev->sfp_bus) in phy_start()
1564 sfp_upstream_start(phydev->sfp_bus); in phy_start()
1566 /* if phy was suspended, bring the physical link up again */ in phy_start()
1569 phydev->state = PHY_UP; in phy_start()
1573 mutex_unlock(&phydev->lock); in phy_start()
1578 * phy_mac_interrupt - MAC says the link has changed
1579 * @phydev: phy_device struct with changed link
1581 * The MAC layer is able to indicate there has been a change in the PHY link
1582 * status. Trigger the state machine and work a work queue.
1586 /* Trigger a state machine change */ in phy_mac_interrupt()
1592 * phy_init_eee - init and check the EEE feature
1594 * @clk_stop_enable: PHY may stop the clock during LPI
1596 * Description: it checks if the Energy-Efficient Ethernet (EEE)
1598 * and it programs the MMD register 3.0 setting the "Clock stop enable"
1605 if (!phydev->drv) in phy_init_eee()
1606 return -EIO; in phy_init_eee()
1612 return -EPROTONOSUPPORT; in phy_init_eee()
1615 /* Configure the PHY to stop receiving xMII in phy_init_eee()
1626 * phy_get_eee_err - report the EEE wake error count
1636 if (!phydev->drv) in phy_get_eee_err()
1637 return -EIO; in phy_get_eee_err()
1639 mutex_lock(&phydev->lock); in phy_get_eee_err()
1641 mutex_unlock(&phydev->lock); in phy_get_eee_err()
1648 * phy_ethtool_get_eee - get EEE supported and status
1659 if (!phydev->drv) in phy_ethtool_get_eee()
1660 return -EIO; in phy_ethtool_get_eee()
1662 mutex_lock(&phydev->lock); in phy_ethtool_get_eee()
1664 eeecfg_to_eee(data, &phydev->eee_cfg); in phy_ethtool_get_eee()
1665 mutex_unlock(&phydev->lock); in phy_ethtool_get_eee()
1672 * phy_ethtool_set_eee_noneg - Adjusts MAC LPI configuration without PHY
1680 * informed of the new LPI settings by cycling the link down and up, which
1690 if (!phydev->link) in phy_ethtool_set_eee_noneg()
1693 enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled && phydev->eee_active; in phy_ethtool_set_eee_noneg()
1695 if (phydev->enable_tx_lpi != enable_tx_lpi || in phy_ethtool_set_eee_noneg()
1696 phydev->eee_cfg.tx_lpi_timer != old_cfg->tx_lpi_timer) { in phy_ethtool_set_eee_noneg()
1697 phydev->enable_tx_lpi = false; in phy_ethtool_set_eee_noneg()
1698 phydev->link = false; in phy_ethtool_set_eee_noneg()
1700 phydev->enable_tx_lpi = enable_tx_lpi; in phy_ethtool_set_eee_noneg()
1701 phydev->link = true; in phy_ethtool_set_eee_noneg()
1707 * phy_ethtool_set_eee - set EEE supported and status
1718 if (!phydev->drv) in phy_ethtool_set_eee()
1719 return -EIO; in phy_ethtool_set_eee()
1721 mutex_lock(&phydev->lock); in phy_ethtool_set_eee()
1723 old_cfg = phydev->eee_cfg; in phy_ethtool_set_eee()
1724 eee_to_eeecfg(&phydev->eee_cfg, data); in phy_ethtool_set_eee()
1730 phydev->eee_cfg = old_cfg; in phy_ethtool_set_eee()
1732 mutex_unlock(&phydev->lock); in phy_ethtool_set_eee()
1739 * phy_ethtool_set_wol - Configure Wake On LAN
1748 if (phydev->drv && phydev->drv->set_wol) { in phy_ethtool_set_wol()
1749 mutex_lock(&phydev->lock); in phy_ethtool_set_wol()
1750 ret = phydev->drv->set_wol(phydev, wol); in phy_ethtool_set_wol()
1751 mutex_unlock(&phydev->lock); in phy_ethtool_set_wol()
1756 return -EOPNOTSUPP; in phy_ethtool_set_wol()
1761 * phy_ethtool_get_wol - Get the current Wake On LAN configuration
1768 if (phydev->drv && phydev->drv->get_wol) { in phy_ethtool_get_wol()
1769 mutex_lock(&phydev->lock); in phy_ethtool_get_wol()
1770 phydev->drv->get_wol(phydev, wol); in phy_ethtool_get_wol()
1771 mutex_unlock(&phydev->lock); in phy_ethtool_get_wol()
1779 struct phy_device *phydev = ndev->phydev; in phy_ethtool_get_link_ksettings()
1782 return -ENODEV; in phy_ethtool_get_link_ksettings()
1793 struct phy_device *phydev = ndev->phydev; in phy_ethtool_set_link_ksettings()
1796 return -ENODEV; in phy_ethtool_set_link_ksettings()
1803 * phy_ethtool_nway_reset - Restart auto negotiation
1808 struct phy_device *phydev = ndev->phydev; in phy_ethtool_nway_reset()
1812 return -ENODEV; in phy_ethtool_nway_reset()
1814 if (!phydev->drv) in phy_ethtool_nway_reset()
1815 return -EIO; in phy_ethtool_nway_reset()
1817 mutex_lock(&phydev->lock); in phy_ethtool_nway_reset()
1819 mutex_unlock(&phydev->lock); in phy_ethtool_nway_reset()