Lines Matching full:phydev

61 static void phy_process_state_change(struct phy_device *phydev,  in phy_process_state_change()  argument
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()
73 static void phy_link_up(struct phy_device *phydev) in phy_link_up() argument
75 phydev->phy_link_change(phydev, true); in phy_link_up()
76 phy_led_trigger_change_speed(phydev); in phy_link_up()
79 static void phy_link_down(struct phy_device *phydev) in phy_link_down() argument
81 phydev->phy_link_change(phydev, false); in phy_link_down()
82 phy_led_trigger_change_speed(phydev); in phy_link_down()
83 WRITE_ONCE(phydev->link_down_events, phydev->link_down_events + 1); in phy_link_down()
86 static const char *phy_pause_str(struct phy_device *phydev) in phy_pause_str() argument
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()
114 * @phydev: the phy_device struct
116 void phy_print_status(struct phy_device *phydev) in phy_print_status() argument
118 if (phydev->link) { in phy_print_status()
119 netdev_info(phydev->attached_dev, 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()
124 phy_pause_str(phydev)); in phy_print_status()
126 netdev_info(phydev->attached_dev, "Link is Down\n"); in phy_print_status()
133 * @phydev: The phy device to return rate matching for
143 int phy_get_rate_matching(struct phy_device *phydev, in phy_get_rate_matching() argument
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()
160 * @phydev: the phy_device struct
161 * @interrupts: interrupt flags to configure for this @phydev
165 static int phy_config_interrupt(struct phy_device *phydev, bool interrupts) in phy_config_interrupt() argument
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()
176 * @phydev: target phy_device struct
178 * Restart the autonegotiation on @phydev. Returns >= 0 on success or
181 int phy_restart_aneg(struct phy_device *phydev) in phy_restart_aneg() argument
185 if (phydev->is_c45 && !(phydev->c45_ids.devices_in_package & BIT(0))) in phy_restart_aneg()
186 ret = genphy_c45_restart_aneg(phydev); in phy_restart_aneg()
188 ret = genphy_restart_aneg(phydev); in phy_restart_aneg()
196 * @phydev: target phy_device struct
198 * Description: Return the auto-negotiation status from this @phydev
202 int phy_aneg_done(struct phy_device *phydev) in phy_aneg_done() argument
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()
207 return genphy_c45_aneg_done(phydev); in phy_aneg_done()
209 return genphy_aneg_done(phydev); in phy_aneg_done()
266 * @phydev: the target phy_device struct
272 static void phy_sanitize_settings(struct phy_device *phydev) in phy_sanitize_settings() argument
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()
288 void phy_ethtool_ksettings_get(struct phy_device *phydev, in phy_ethtool_ksettings_get() argument
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()
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()
317 * @phydev: the phy_device struct
325 int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd) in phy_mii_ioctl() argument
338 mii_data->phy_id = phydev->mdio.addr; in phy_mii_ioctl()
345 ret = mdiobus_c45_read(phydev->mdio.bus, prtad, devad, in phy_mii_ioctl()
349 ret = mdiobus_read(phydev->mdio.bus, mii_data->phy_id, 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()
407 mdiobus_c45_write(phydev->mdio.bus, prtad, devad, 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()
415 return phy_init_hw(phydev); in phy_mii_ioctl()
418 return phy_start_aneg(phydev); in phy_mii_ioctl()
423 if (phydev->mii_ts && phydev->mii_ts->hwtstamp) { in phy_mii_ioctl()
428 ret = phydev->mii_ts->hwtstamp(phydev->mii_ts, &kernel_cfg, &extack); in phy_mii_ioctl()
454 if (!dev->phydev) in phy_do_ioctl()
457 return phy_mii_ioctl(dev->phydev, ifr, cmd); in phy_do_ioctl()
483 * @phydev: the PHY device structure
488 int __phy_hwtstamp_get(struct phy_device *phydev, in __phy_hwtstamp_get() argument
491 if (!phydev) in __phy_hwtstamp_get()
500 * @phydev: the PHY device structure
504 int __phy_hwtstamp_set(struct phy_device *phydev, in __phy_hwtstamp_set() argument
508 if (!phydev) 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()
520 * @phydev: the phy_device struct
523 void phy_queue_state_machine(struct phy_device *phydev, unsigned long jiffies) in phy_queue_state_machine() argument
525 mod_delayed_work(system_power_efficient_wq, &phydev->state_queue, in phy_queue_state_machine()
533 * @phydev: the phy_device struct
535 void phy_trigger_machine(struct phy_device *phydev) in phy_trigger_machine() argument
537 phy_queue_state_machine(phydev, 0); in phy_trigger_machine()
541 static void phy_abort_cable_test(struct phy_device *phydev) in phy_abort_cable_test() argument
545 ethnl_cable_test_finished(phydev); in phy_abort_cable_test()
547 err = phy_init_hw(phydev); in phy_abort_cable_test()
549 phydev_err(phydev, "Error while aborting cable test"); in phy_abort_cable_test()
555 * @phydev: the phy_device struct
558 int phy_ethtool_get_strings(struct phy_device *phydev, u8 *data) in phy_ethtool_get_strings() argument
560 if (!phydev->drv) 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()
574 * @phydev: the phy_device struct
576 int phy_ethtool_get_sset_count(struct phy_device *phydev) in phy_ethtool_get_sset_count() argument
580 if (!phydev->drv) 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()
600 * @phydev: the phy_device struct
604 int phy_ethtool_get_stats(struct phy_device *phydev, in phy_ethtool_get_stats() argument
607 if (!phydev->drv) 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()
620 * @phydev: the phy_device struct
626 int phy_ethtool_get_plca_cfg(struct phy_device *phydev, in phy_ethtool_get_plca_cfg() argument
631 if (!phydev->drv) { in phy_ethtool_get_plca_cfg()
636 if (!phydev->drv->get_plca_cfg) { 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()
651 * @phydev: the phy_device struct
659 static int plca_check_valid(struct phy_device *phydev, in plca_check_valid() argument
666 phydev->advertising)) { in plca_check_valid()
680 * @phydev: the phy_device struct
687 int phy_ethtool_set_plca_cfg(struct phy_device *phydev, in phy_ethtool_set_plca_cfg() argument
694 if (!phydev->drv) { 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()
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()
765 ret = plca_check_valid(phydev, curr_plca_cfg, extack); 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()
781 * @phydev: the phy_device struct
787 int phy_ethtool_get_plca_status(struct phy_device *phydev, in phy_ethtool_get_plca_status() argument
792 if (!phydev->drv) { in phy_ethtool_get_plca_status()
797 if (!phydev->drv->get_plca_status) { 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()
813 * @phydev: the phy_device struct
816 int phy_start_cable_test(struct phy_device *phydev, in phy_start_cable_test() argument
819 struct net_device *dev = phydev->attached_dev; 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()
830 mutex_lock(&phydev->lock); in phy_start_cable_test()
831 if (phydev->state == PHY_CABLETEST) { 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()
846 err = ethnl_cable_test_alloc(phydev, ETHTOOL_MSG_CABLE_TEST_NTF); in phy_start_cable_test()
851 phy_link_down(phydev); in phy_start_cable_test()
854 err = phydev->drv->cable_test_start(phydev); in phy_start_cable_test()
857 phy_link_up(phydev); in phy_start_cable_test()
861 phydev->state = PHY_CABLETEST; in phy_start_cable_test()
863 if (phy_polling_mode(phydev)) in phy_start_cable_test()
864 phy_trigger_machine(phydev); in phy_start_cable_test()
866 mutex_unlock(&phydev->lock); in phy_start_cable_test()
871 ethnl_cable_test_free(phydev); in phy_start_cable_test()
873 mutex_unlock(&phydev->lock); in phy_start_cable_test()
882 * @phydev: the phy_device struct
886 int phy_start_cable_test_tdr(struct phy_device *phydev, in phy_start_cable_test_tdr() argument
890 struct net_device *dev = phydev->attached_dev; 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()
901 mutex_lock(&phydev->lock); in phy_start_cable_test_tdr()
902 if (phydev->state == PHY_CABLETEST) { 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()
917 err = ethnl_cable_test_alloc(phydev, ETHTOOL_MSG_CABLE_TEST_TDR_NTF); in phy_start_cable_test_tdr()
922 phy_link_down(phydev); in phy_start_cable_test_tdr()
925 err = phydev->drv->cable_test_tdr_start(phydev, config); in phy_start_cable_test_tdr()
928 phy_link_up(phydev); in phy_start_cable_test_tdr()
932 phydev->state = PHY_CABLETEST; in phy_start_cable_test_tdr()
934 if (phy_polling_mode(phydev)) in phy_start_cable_test_tdr()
935 phy_trigger_machine(phydev); in phy_start_cable_test_tdr()
937 mutex_unlock(&phydev->lock); in phy_start_cable_test_tdr()
942 ethnl_cable_test_free(phydev); in phy_start_cable_test_tdr()
944 mutex_unlock(&phydev->lock); in phy_start_cable_test_tdr()
950 int phy_config_aneg(struct phy_device *phydev) in phy_config_aneg() argument
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()
959 return genphy_c45_config_aneg(phydev); in phy_config_aneg()
961 return genphy_config_aneg(phydev); in phy_config_aneg()
967 * @phydev: the phy_device struct
972 static int phy_check_link_status(struct phy_device *phydev) in phy_check_link_status() argument
976 lockdep_assert_held(&phydev->lock); in phy_check_link_status()
981 if (phydev->loopback_enabled) in phy_check_link_status()
984 err = phy_read_status(phydev); in phy_check_link_status()
988 if (phydev->link && phydev->state != PHY_RUNNING) { in phy_check_link_status()
989 phy_check_downshift(phydev); in phy_check_link_status()
990 phydev->state = PHY_RUNNING; in phy_check_link_status()
991 err = genphy_c45_eee_is_active(phydev, in phy_check_link_status()
994 phydev->enable_tx_lpi = false; in phy_check_link_status()
996 phydev->enable_tx_lpi = phydev->eee_cfg.tx_lpi_enabled; in phy_check_link_status()
998 phy_link_up(phydev); in phy_check_link_status()
999 } else if (!phydev->link && phydev->state != PHY_NOLINK) { in phy_check_link_status()
1000 phydev->state = PHY_NOLINK; in phy_check_link_status()
1001 phydev->enable_tx_lpi = false; in phy_check_link_status()
1002 phy_link_down(phydev); in phy_check_link_status()
1010 * @phydev: the phy_device struct
1017 int _phy_start_aneg(struct phy_device *phydev) in _phy_start_aneg() argument
1021 lockdep_assert_held(&phydev->lock); in _phy_start_aneg()
1023 if (!phydev->drv) in _phy_start_aneg()
1026 if (AUTONEG_DISABLE == phydev->autoneg) in _phy_start_aneg()
1027 phy_sanitize_settings(phydev); in _phy_start_aneg()
1029 err = phy_config_aneg(phydev); in _phy_start_aneg()
1033 if (phy_is_started(phydev)) in _phy_start_aneg()
1034 err = phy_check_link_status(phydev); in _phy_start_aneg()
1042 * @phydev: the phy_device struct
1049 int phy_start_aneg(struct phy_device *phydev) in phy_start_aneg() argument
1053 mutex_lock(&phydev->lock); in phy_start_aneg()
1054 err = _phy_start_aneg(phydev); in phy_start_aneg()
1055 mutex_unlock(&phydev->lock); in phy_start_aneg()
1061 static int phy_poll_aneg_done(struct phy_device *phydev) in phy_poll_aneg_done() argument
1068 ret = phy_aneg_done(phydev); in phy_poll_aneg_done()
1077 int phy_ethtool_ksettings_set(struct phy_device *phydev, in phy_ethtool_ksettings_set() argument
1085 if (cmd->base.phy_address != phydev->mdio.addr) in phy_ethtool_ksettings_set()
1091 linkmode_and(advertising, advertising, phydev->supported); in phy_ethtool_ksettings_set()
1100 phydev->supported))) 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()
1128 if (phy_is_started(phydev)) { in phy_ethtool_ksettings_set()
1129 phydev->state = PHY_UP; in phy_ethtool_ksettings_set()
1130 phy_trigger_machine(phydev); in phy_ethtool_ksettings_set()
1132 _phy_start_aneg(phydev); in phy_ethtool_ksettings_set()
1135 mutex_unlock(&phydev->lock); in phy_ethtool_ksettings_set()
1142 * @phydev: the phy_device struct
1153 int phy_speed_down(struct phy_device *phydev, bool sync) in phy_speed_down() argument
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()
1165 ret = phy_speed_down_core(phydev); 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()
1176 ret = phy_config_aneg(phydev); in phy_speed_down()
1180 ret = sync ? phy_poll_aneg_done(phydev) : 0; in phy_speed_down()
1182 mutex_unlock(&phydev->lock); in phy_speed_down()
1190 * @phydev: the phy_device struct
1194 int phy_speed_up(struct phy_device *phydev) in phy_speed_up() argument
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()
1214 ret = phy_config_aneg(phydev); in phy_speed_up()
1216 mutex_unlock(&phydev->lock); in phy_speed_up()
1224 * @phydev: the phy_device struct
1232 void phy_start_machine(struct phy_device *phydev) in phy_start_machine() argument
1234 phy_trigger_machine(phydev); in phy_start_machine()
1240 * @phydev: target phy_device struct
1246 void phy_stop_machine(struct phy_device *phydev) in phy_stop_machine() argument
1248 cancel_delayed_work_sync(&phydev->state_queue); in phy_stop_machine()
1250 mutex_lock(&phydev->lock); in phy_stop_machine()
1251 if (phy_is_started(phydev)) in phy_stop_machine()
1252 phydev->state = PHY_UP; in phy_stop_machine()
1253 mutex_unlock(&phydev->lock); in phy_stop_machine()
1256 static void phy_process_error(struct phy_device *phydev) in phy_process_error() argument
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()
1264 phy_trigger_machine(phydev); in phy_process_error()
1267 static void phy_error_precise(struct phy_device *phydev, in phy_error_precise() argument
1271 phy_process_error(phydev); in phy_error_precise()
1276 * @phydev: target phy_device struct
1280 * Must be called with phydev->lock held.
1282 void phy_error(struct phy_device *phydev) in phy_error() argument
1285 phy_process_error(phydev); in phy_error()
1291 * @phydev: target phy_device struct
1293 int phy_disable_interrupts(struct phy_device *phydev) in phy_disable_interrupts() argument
1296 return phy_config_interrupt(phydev, PHY_INTERRUPT_DISABLED); in phy_disable_interrupts()
1308 struct phy_device *phydev = phy_dat; in phy_interrupt() local
1314 if (IS_ENABLED(CONFIG_PM_SLEEP) && phydev->irq_suspended) { in phy_interrupt()
1315 struct net_device *netdev = phydev->attached_dev; 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()
1342 * @phydev: target phy_device struct
1344 static int phy_enable_interrupts(struct phy_device *phydev) in phy_enable_interrupts() argument
1346 return phy_config_interrupt(phydev, PHY_INTERRUPT_ENABLED); in phy_enable_interrupts()
1351 * @phydev: target phy_device struct
1357 void phy_request_interrupt(struct phy_device *phydev) in phy_request_interrupt() argument
1361 err = request_threaded_irq(phydev->irq, NULL, phy_interrupt, in phy_request_interrupt()
1363 phydev_name(phydev), phydev); in phy_request_interrupt()
1365 phydev_warn(phydev, "Error %d requesting IRQ %d, falling back to polling\n", in phy_request_interrupt()
1366 err, phydev->irq); in phy_request_interrupt()
1367 phydev->irq = PHY_POLL; in phy_request_interrupt()
1369 if (phy_enable_interrupts(phydev)) { in phy_request_interrupt()
1370 phydev_warn(phydev, "Can't enable interrupt, falling back to polling\n"); in phy_request_interrupt()
1371 phy_free_interrupt(phydev); in phy_request_interrupt()
1372 phydev->irq = PHY_POLL; in phy_request_interrupt()
1380 * @phydev: target phy_device struct
1385 void phy_free_interrupt(struct phy_device *phydev) in phy_free_interrupt() argument
1387 phy_disable_interrupts(phydev); in phy_free_interrupt()
1388 free_irq(phydev->irq, phydev); in phy_free_interrupt()
1398 static enum phy_state_work _phy_state_machine(struct phy_device *phydev) in _phy_state_machine() argument
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()
1416 err = phy_check_link_status(phydev); in _phy_state_machine()
1420 err = phydev->drv->cable_test_get_status(phydev, &finished); in _phy_state_machine()
1422 phy_abort_cable_test(phydev); in _phy_state_machine()
1425 phydev->state = PHY_UP; in _phy_state_machine()
1430 ethnl_cable_test_finished(phydev); 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()
1440 phy_link_down(phydev); in _phy_state_machine()
1447 err = _phy_start_aneg(phydev); in _phy_state_machine()
1455 phy_error_precise(phydev, func, err); in _phy_state_machine()
1457 phy_process_state_change(phydev, old_state); in _phy_state_machine()
1467 if (phy_polling_mode(phydev) && phy_is_started(phydev)) in _phy_state_machine()
1468 phy_queue_state_machine(phydev, PHY_STATE_TIME); in _phy_state_machine()
1474 static void _phy_state_machine_post_work(struct phy_device *phydev, in _phy_state_machine_post_work() argument
1478 phy_suspend(phydev); in _phy_state_machine_post_work()
1488 struct phy_device *phydev = in phy_state_machine() local
1492 mutex_lock(&phydev->lock); in phy_state_machine()
1493 state_work = _phy_state_machine(phydev); in phy_state_machine()
1494 mutex_unlock(&phydev->lock); in phy_state_machine()
1496 _phy_state_machine_post_work(phydev, state_work); in phy_state_machine()
1501 * @phydev: target phy_device struct
1503 void phy_stop(struct phy_device *phydev) in phy_stop() argument
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()
1520 phy_abort_cable_test(phydev); 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()
1528 phy_process_state_change(phydev, old_state); in phy_stop()
1530 state_work = _phy_state_machine(phydev); in phy_stop()
1531 mutex_unlock(&phydev->lock); in phy_stop()
1533 _phy_state_machine_post_work(phydev, state_work); in phy_stop()
1534 phy_stop_machine(phydev); in phy_stop()
1545 * @phydev: target phy_device struct
1553 void phy_start(struct phy_device *phydev) in phy_start() argument
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()
1567 __phy_resume(phydev); in phy_start()
1569 phydev->state = PHY_UP; in phy_start()
1571 phy_start_machine(phydev); in phy_start()
1573 mutex_unlock(&phydev->lock); in phy_start()
1579 * @phydev: phy_device struct with changed link
1584 void phy_mac_interrupt(struct phy_device *phydev) in phy_mac_interrupt() argument
1587 phy_trigger_machine(phydev); in phy_mac_interrupt()
1593 * @phydev: target phy_device struct
1601 int phy_init_eee(struct phy_device *phydev, bool clk_stop_enable) in phy_init_eee() argument
1605 if (!phydev->drv) in phy_init_eee()
1608 ret = genphy_c45_eee_is_active(phydev, NULL, NULL, NULL); in phy_init_eee()
1618 ret = phy_set_bits_mmd(phydev, MDIO_MMD_PCS, MDIO_CTRL1, in phy_init_eee()
1627 * @phydev: target phy_device struct
1632 int phy_get_eee_err(struct phy_device *phydev) in phy_get_eee_err() argument
1636 if (!phydev->drv) in phy_get_eee_err()
1639 mutex_lock(&phydev->lock); in phy_get_eee_err()
1640 ret = phy_read_mmd(phydev, MDIO_MMD_PCS, MDIO_PCS_EEE_WK_ERR); in phy_get_eee_err()
1641 mutex_unlock(&phydev->lock); in phy_get_eee_err()
1649 * @phydev: target phy_device struct
1655 int phy_ethtool_get_eee(struct phy_device *phydev, struct ethtool_keee *data) in phy_ethtool_get_eee() argument
1659 if (!phydev->drv) in phy_ethtool_get_eee()
1662 mutex_lock(&phydev->lock); in phy_ethtool_get_eee()
1663 ret = genphy_c45_ethtool_get_eee(phydev, data); 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()
1674 * @phydev: pointer to the target PHY device structure
1685 static void phy_ethtool_set_eee_noneg(struct phy_device *phydev, in phy_ethtool_set_eee_noneg() argument
1688 if (phydev->eee_cfg.tx_lpi_enabled != data->tx_lpi_enabled || in phy_ethtool_set_eee_noneg()
1689 phydev->eee_cfg.tx_lpi_timer != data->tx_lpi_timer) { in phy_ethtool_set_eee_noneg()
1690 eee_to_eeecfg(&phydev->eee_cfg, data); in phy_ethtool_set_eee_noneg()
1691 phydev->enable_tx_lpi = eeecfg_mac_can_tx_lpi(&phydev->eee_cfg); in phy_ethtool_set_eee_noneg()
1692 if (phydev->link) { in phy_ethtool_set_eee_noneg()
1693 phydev->link = false; in phy_ethtool_set_eee_noneg()
1694 phy_link_down(phydev); in phy_ethtool_set_eee_noneg()
1695 phydev->link = true; in phy_ethtool_set_eee_noneg()
1696 phy_link_up(phydev); in phy_ethtool_set_eee_noneg()
1703 * @phydev: target phy_device struct
1708 int phy_ethtool_set_eee(struct phy_device *phydev, struct ethtool_keee *data) in phy_ethtool_set_eee() argument
1712 if (!phydev->drv) in phy_ethtool_set_eee()
1715 mutex_lock(&phydev->lock); in phy_ethtool_set_eee()
1716 ret = genphy_c45_ethtool_set_eee(phydev, data); in phy_ethtool_set_eee()
1719 phy_ethtool_set_eee_noneg(phydev, data); in phy_ethtool_set_eee()
1720 eee_to_eeecfg(&phydev->eee_cfg, data); in phy_ethtool_set_eee()
1722 mutex_unlock(&phydev->lock); in phy_ethtool_set_eee()
1731 * @phydev: target phy_device struct
1734 int phy_ethtool_set_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) in phy_ethtool_set_wol() argument
1738 if (phydev->drv && phydev->drv->set_wol) { in phy_ethtool_set_wol()
1739 mutex_lock(&phydev->lock); in phy_ethtool_set_wol()
1740 ret = phydev->drv->set_wol(phydev, wol); in phy_ethtool_set_wol()
1741 mutex_unlock(&phydev->lock); in phy_ethtool_set_wol()
1753 * @phydev: target phy_device struct
1756 void phy_ethtool_get_wol(struct phy_device *phydev, struct ethtool_wolinfo *wol) in phy_ethtool_get_wol() argument
1758 if (phydev->drv && phydev->drv->get_wol) { in phy_ethtool_get_wol()
1759 mutex_lock(&phydev->lock); in phy_ethtool_get_wol()
1760 phydev->drv->get_wol(phydev, wol); in phy_ethtool_get_wol()
1761 mutex_unlock(&phydev->lock); in phy_ethtool_get_wol()
1769 struct phy_device *phydev = ndev->phydev; in phy_ethtool_get_link_ksettings() local
1771 if (!phydev) in phy_ethtool_get_link_ksettings()
1774 phy_ethtool_ksettings_get(phydev, cmd); in phy_ethtool_get_link_ksettings()
1783 struct phy_device *phydev = ndev->phydev; in phy_ethtool_set_link_ksettings() local
1785 if (!phydev) in phy_ethtool_set_link_ksettings()
1788 return phy_ethtool_ksettings_set(phydev, cmd); in phy_ethtool_set_link_ksettings()
1798 struct phy_device *phydev = ndev->phydev; in phy_ethtool_nway_reset() local
1801 if (!phydev) in phy_ethtool_nway_reset()
1804 if (!phydev->drv) in phy_ethtool_nway_reset()
1807 mutex_lock(&phydev->lock); in phy_ethtool_nway_reset()
1808 ret = phy_restart_aneg(phydev); in phy_ethtool_nway_reset()
1809 mutex_unlock(&phydev->lock); in phy_ethtool_nway_reset()