Lines Matching +full:wake +full:- +full:on +full:- +full:lan
1 // SPDX-License-Identifier: GPL-2.0
4 * technologies such as SFP cages where the PHY is hot-pluggable.
44 * struct phylink - internal data type for phylink
60 u8 link_port; /* The current non-phy ethtool port */
92 if ((pl)->config->type == PHYLINK_NETDEV) \
93 netdev_printk(level, (pl)->netdev, fmt, ##__VA_ARGS__); \
94 else if ((pl)->config->type == PHYLINK_DEV) \
95 dev_printk(level, (pl)->dev, fmt, ##__VA_ARGS__); \
107 if ((pl)->config->type == PHYLINK_NETDEV) \
108 netdev_dbg((pl)->netdev, fmt, ##__VA_ARGS__); \
109 else if ((pl)->config->type == PHYLINK_DEV) \
110 dev_dbg((pl)->dev, fmt, ##__VA_ARGS__); \
137 * phylink_set_port_modes() - set the port type modes in the ethtool mask
195 * phylink_interface_max_speed() - get the maximum speed of a phy interface
266 * phylink_caps_to_linkmodes() - Convert capabilities to ethtool link modes
443 * phylink_limit_mac_speed - limit the phylink_config to a maximum speed
456 config->mac_capabilities &= ~phylink_caps_params[i].mask; in phylink_limit_mac_speed()
461 * phylink_cap_from_speed_duplex - Get mac capability from speed/duplex
485 * phylink_get_capabilities() - get capabilities for a given MAC
621 * phylink_validate_mask_caps() - Restrict link modes based on caps
626 * Calculate the supported link modes based on @mac_capabilities, and restrict
627 * @supported and @state based on that. Use this function if your capabiliies
628 * aren't constant, such as if they vary depending on the interface.
639 caps = phylink_get_capabilities(state->interface, mac_capabilities, in phylink_validate_mask_caps()
640 state->rate_matching); in phylink_validate_mask_caps()
644 linkmode_and(state->advertising, state->advertising, mask); in phylink_validate_mask_caps()
656 if (pl->mac_ops->mac_select_pcs) { in phylink_validate_mac_and_pcs()
657 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); in phylink_validate_mac_and_pcs()
667 if (!pcs->ops) { in phylink_validate_mac_and_pcs()
669 phy_modes(state->interface)); in phylink_validate_mac_and_pcs()
671 return -EINVAL; in phylink_validate_mac_and_pcs()
675 if (pcs->ops->pcs_validate) { in phylink_validate_mac_and_pcs()
676 ret = pcs->ops->pcs_validate(pcs, supported, state); in phylink_validate_mac_and_pcs()
678 return -EINVAL; in phylink_validate_mac_and_pcs()
683 linkmode_and(state->advertising, state->advertising, in phylink_validate_mac_and_pcs()
689 if (pl->mac_ops->mac_get_caps) in phylink_validate_mac_and_pcs()
690 capabilities = pl->mac_ops->mac_get_caps(pl->config, in phylink_validate_mac_and_pcs()
691 state->interface); in phylink_validate_mac_and_pcs()
693 capabilities = pl->config->mac_capabilities; in phylink_validate_mac_and_pcs()
697 return phylink_is_empty_linkmode(supported) ? -EINVAL : 0; in phylink_validate_mac_and_pcs()
744 linkmode_copy(state->advertising, all_adv); in phylink_validate_mask()
746 return phylink_is_empty_linkmode(supported) ? -EINVAL : 0; in phylink_validate_mask()
752 const unsigned long *interfaces = pl->config->supported_interfaces; in phylink_validate()
754 if (state->interface == PHY_INTERFACE_MODE_NA) in phylink_validate()
758 if (!test_bit(state->interface, interfaces)) in phylink_validate()
759 return -EINVAL; in phylink_validate()
774 fixed_node = fwnode_get_named_child_node(fwnode, "fixed-link"); in phylink_parse_fixedlink()
778 pl->link_config.speed = speed; in phylink_parse_fixedlink()
779 pl->link_config.duplex = DUPLEX_HALF; in phylink_parse_fixedlink()
781 if (fwnode_property_read_bool(fixed_node, "full-duplex")) in phylink_parse_fixedlink()
782 pl->link_config.duplex = DUPLEX_FULL; in phylink_parse_fixedlink()
784 /* We treat the "pause" and "asym-pause" terminology as in phylink_parse_fixedlink()
789 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
790 if (fwnode_property_read_bool(fixed_node, "asym-pause")) in phylink_parse_fixedlink()
792 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
799 pl->link_gpio = desc; in phylink_parse_fixedlink()
800 else if (desc == ERR_PTR(-EPROBE_DEFER)) in phylink_parse_fixedlink()
801 ret = -EPROBE_DEFER; in phylink_parse_fixedlink()
810 ret = fwnode_property_read_u32_array(fwnode, "fixed-link", in phylink_parse_fixedlink()
813 phylink_err(pl, "broken fixed-link?\n"); in phylink_parse_fixedlink()
814 return -EINVAL; in phylink_parse_fixedlink()
817 ret = fwnode_property_read_u32_array(fwnode, "fixed-link", in phylink_parse_fixedlink()
820 pl->link_config.duplex = prop[1] ? in phylink_parse_fixedlink()
822 pl->link_config.speed = prop[2]; in phylink_parse_fixedlink()
825 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
828 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
832 if (pl->link_config.speed > SPEED_1000 && in phylink_parse_fixedlink()
833 pl->link_config.duplex != DUPLEX_FULL) in phylink_parse_fixedlink()
835 pl->link_config.speed); in phylink_parse_fixedlink()
837 linkmode_fill(pl->supported); in phylink_parse_fixedlink()
838 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_parse_fixedlink()
839 phylink_validate(pl, pl->supported, &pl->link_config); in phylink_parse_fixedlink()
841 s = phy_lookup_setting(pl->link_config.speed, pl->link_config.duplex, in phylink_parse_fixedlink()
842 pl->supported, true); in phylink_parse_fixedlink()
847 linkmode_and(pl->supported, pl->supported, mask); in phylink_parse_fixedlink()
849 phylink_set(pl->supported, MII); in phylink_parse_fixedlink()
852 __set_bit(s->bit, pl->supported); in phylink_parse_fixedlink()
853 __set_bit(s->bit, pl->link_config.lp_advertising); in phylink_parse_fixedlink()
856 pl->link_config.duplex == DUPLEX_FULL ? "full" : "half", in phylink_parse_fixedlink()
857 pl->link_config.speed); in phylink_parse_fixedlink()
860 linkmode_and(pl->link_config.advertising, pl->link_config.advertising, in phylink_parse_fixedlink()
861 pl->supported); in phylink_parse_fixedlink()
863 pl->link_config.link = 1; in phylink_parse_fixedlink()
864 pl->link_config.an_complete = 1; in phylink_parse_fixedlink()
876 if (pl->config->default_an_inband) in phylink_parse_mode()
877 pl->cfg_link_an_mode = MLO_AN_INBAND; in phylink_parse_mode()
879 dn = fwnode_get_named_child_node(fwnode, "fixed-link"); in phylink_parse_mode()
880 if (dn || fwnode_property_present(fwnode, "fixed-link")) in phylink_parse_mode()
881 pl->cfg_link_an_mode = MLO_AN_FIXED; in phylink_parse_mode()
885 strcmp(managed, "in-band-status") == 0)) { in phylink_parse_mode()
886 if (pl->cfg_link_an_mode == MLO_AN_FIXED) { in phylink_parse_mode()
888 "can't use both fixed-link and in-band-status\n"); in phylink_parse_mode()
889 return -EINVAL; in phylink_parse_mode()
892 pl->cfg_link_an_mode = MLO_AN_INBAND; in phylink_parse_mode()
895 if (pl->cfg_link_an_mode == MLO_AN_INBAND) { in phylink_parse_mode()
896 linkmode_zero(pl->supported); in phylink_parse_mode()
897 phylink_set(pl->supported, MII); in phylink_parse_mode()
898 phylink_set(pl->supported, Autoneg); in phylink_parse_mode()
899 phylink_set(pl->supported, Asym_Pause); in phylink_parse_mode()
900 phylink_set(pl->supported, Pause); in phylink_parse_mode()
902 switch (pl->link_config.interface) { in phylink_parse_mode()
922 caps = phylink_get_capabilities(pl->link_config.interface, caps, in phylink_parse_mode()
924 phylink_caps_to_linkmodes(pl->supported, caps); in phylink_parse_mode()
929 "incorrect link mode %s for in-band status\n", in phylink_parse_mode()
930 phy_modes(pl->link_config.interface)); in phylink_parse_mode()
931 return -EINVAL; in phylink_parse_mode()
934 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_parse_mode()
936 if (phylink_validate(pl, pl->supported, &pl->link_config)) { in phylink_parse_mode()
938 "failed to validate link configuration for in-band status\n"); in phylink_parse_mode()
939 return -EINVAL; in phylink_parse_mode()
951 state->advertising)) in phylink_apply_manual_flow()
952 state->pause &= ~MLO_PAUSE_AN; in phylink_apply_manual_flow()
955 if (!(pl->link_config.pause & MLO_PAUSE_AN)) in phylink_apply_manual_flow()
956 state->pause = pl->link_config.pause; in phylink_apply_manual_flow()
963 if (state->duplex == DUPLEX_FULL) { in phylink_resolve_an_pause()
964 linkmode_resolve_pause(state->advertising, in phylink_resolve_an_pause()
965 state->lp_advertising, in phylink_resolve_an_pause()
968 state->pause |= MLO_PAUSE_TX; in phylink_resolve_an_pause()
970 state->pause |= MLO_PAUSE_RX; in phylink_resolve_an_pause()
977 if (pcs && pcs->ops->pcs_pre_config) in phylink_pcs_pre_config()
978 pcs->ops->pcs_pre_config(pcs, interface); in phylink_pcs_pre_config()
986 if (pcs && pcs->ops->pcs_post_config) in phylink_pcs_post_config()
987 err = pcs->ops->pcs_post_config(pcs, interface); in phylink_pcs_post_config()
994 if (pcs && pcs->ops->pcs_disable) in phylink_pcs_disable()
995 pcs->ops->pcs_disable(pcs); in phylink_pcs_disable()
1002 if (pcs && pcs->ops->pcs_enable) in phylink_pcs_enable()
1003 err = pcs->ops->pcs_enable(pcs); in phylink_pcs_enable()
1015 return pcs->ops->pcs_config(pcs, neg_mode, state->interface, in phylink_pcs_config()
1016 state->advertising, permit_pause_to_mac); in phylink_pcs_config()
1023 if (pcs && pcs->ops->pcs_link_up) in phylink_pcs_link_up()
1024 pcs->ops->pcs_link_up(pcs, neg_mode, interface, speed, duplex); in phylink_pcs_link_up()
1029 if (pl->cfg_link_an_mode == MLO_AN_INBAND) in phylink_pcs_poll_stop()
1030 del_timer(&pl->link_poll); in phylink_pcs_poll_stop()
1035 if (pl->pcs && pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND) in phylink_pcs_poll_start()
1036 mod_timer(&pl->link_poll, jiffies + HZ); in phylink_pcs_poll_start()
1044 if (pl->config->mac_requires_rxc) in phylink_pcs_pre_init()
1045 pcs->rxc_always_on = true; in phylink_pcs_pre_init()
1047 if (pcs->ops->pcs_pre_init) in phylink_pcs_pre_init()
1048 ret = pcs->ops->pcs_pre_init(pcs); in phylink_pcs_pre_init()
1068 __func__, phylink_an_mode_str(pl->cur_link_an_mode), in phylink_mac_config()
1074 pl->mac_ops->mac_config(pl->config, pl->cur_link_an_mode, &st); in phylink_mac_config()
1079 if (pl->pcs && linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, in phylink_pcs_an_restart()
1080 pl->link_config.advertising) && in phylink_pcs_an_restart()
1081 phy_interface_mode_is_8023z(pl->link_config.interface) && in phylink_pcs_an_restart()
1082 phylink_autoneg_inband(pl->cur_link_an_mode)) in phylink_pcs_an_restart()
1083 pl->pcs->ops->pcs_an_restart(pl->pcs); in phylink_pcs_an_restart()
1087 * phylink_pcs_neg_mode() - helper to determine PCS inband mode
1095 * - %PHYLINK_PCS_NEG_NONE: interface mode does not support inband
1096 * - %PHYLINK_PCS_NEG_OUTBAND: an out of band mode (e.g. reading the PHY)
1098 * - %PHYLINK_PCS_NEG_INBAND_DISABLED: inband mode selected but autoneg
1100 * - %PHYLINK_PCS_NEG_INBAND_ENABLED: inband mode selected and autoneg enabled
1130 /* 1000base-X is designed for use media-side for Fibre in phylink_pcs_neg_mode()
1132 * taken into account. We also do this for 2500base-X in phylink_pcs_neg_mode()
1162 phylink_dbg(pl, "major config %s\n", phy_modes(state->interface)); in phylink_major_config()
1164 pl->pcs_neg_mode = phylink_pcs_neg_mode(pl->cur_link_an_mode, in phylink_major_config()
1165 state->interface, in phylink_major_config()
1166 state->advertising); in phylink_major_config()
1168 if (pl->mac_ops->mac_select_pcs) { in phylink_major_config()
1169 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); in phylink_major_config()
1177 pcs_changed = pl->pcs != pcs; in phylink_major_config()
1182 if (pl->mac_ops->mac_prepare) { in phylink_major_config()
1183 err = pl->mac_ops->mac_prepare(pl->config, pl->cur_link_an_mode, in phylink_major_config()
1184 state->interface); in phylink_major_config()
1196 phylink_pcs_disable(pl->pcs); in phylink_major_config()
1198 if (pl->pcs) in phylink_major_config()
1199 pl->pcs->phylink = NULL; in phylink_major_config()
1201 pcs->phylink = pl; in phylink_major_config()
1203 pl->pcs = pcs; in phylink_major_config()
1206 if (pl->pcs) in phylink_major_config()
1207 phylink_pcs_pre_config(pl->pcs, state->interface); in phylink_major_config()
1211 if (pl->pcs) in phylink_major_config()
1212 phylink_pcs_post_config(pl->pcs, state->interface); in phylink_major_config()
1214 if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed) in phylink_major_config()
1215 phylink_pcs_enable(pl->pcs); in phylink_major_config()
1217 neg_mode = pl->cur_link_an_mode; in phylink_major_config()
1218 if (pl->pcs && pl->pcs->neg_mode) in phylink_major_config()
1219 neg_mode = pl->pcs_neg_mode; in phylink_major_config()
1221 err = phylink_pcs_config(pl->pcs, neg_mode, state, in phylink_major_config()
1222 !!(pl->link_config.pause & MLO_PAUSE_AN)); in phylink_major_config()
1232 if (pl->mac_ops->mac_finish) { in phylink_major_config()
1233 err = pl->mac_ops->mac_finish(pl->config, pl->cur_link_an_mode, in phylink_major_config()
1234 state->interface); in phylink_major_config()
1240 if (pl->sfp_bus) { in phylink_major_config()
1241 rate_kbd = phylink_interface_signal_rate(state->interface); in phylink_major_config()
1243 sfp_upstream_set_signal_rate(pl->sfp_bus, rate_kbd); in phylink_major_config()
1260 if (test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) in phylink_change_inband_advert()
1264 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_change_inband_advert()
1265 phy_modes(pl->link_config.interface), in phylink_change_inband_advert()
1266 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->link_config.advertising, in phylink_change_inband_advert()
1267 pl->link_config.pause); in phylink_change_inband_advert()
1270 pl->pcs_neg_mode = phylink_pcs_neg_mode(pl->cur_link_an_mode, in phylink_change_inband_advert()
1271 pl->link_config.interface, in phylink_change_inband_advert()
1272 pl->link_config.advertising); in phylink_change_inband_advert()
1274 neg_mode = pl->cur_link_an_mode; in phylink_change_inband_advert()
1275 if (pl->pcs->neg_mode) in phylink_change_inband_advert()
1276 neg_mode = pl->pcs_neg_mode; in phylink_change_inband_advert()
1278 /* Modern PCS-based method; update the advert at the PCS, and in phylink_change_inband_advert()
1282 ret = phylink_pcs_config(pl->pcs, neg_mode, &pl->link_config, in phylink_change_inband_advert()
1283 !!(pl->link_config.pause & MLO_PAUSE_AN)); in phylink_change_inband_advert()
1296 linkmode_copy(state->advertising, pl->link_config.advertising); in phylink_mac_pcs_get_state()
1297 linkmode_zero(state->lp_advertising); in phylink_mac_pcs_get_state()
1298 state->interface = pl->link_config.interface; in phylink_mac_pcs_get_state()
1299 state->rate_matching = pl->link_config.rate_matching; in phylink_mac_pcs_get_state()
1301 state->advertising)) { in phylink_mac_pcs_get_state()
1302 state->speed = SPEED_UNKNOWN; in phylink_mac_pcs_get_state()
1303 state->duplex = DUPLEX_UNKNOWN; in phylink_mac_pcs_get_state()
1304 state->pause = MLO_PAUSE_NONE; in phylink_mac_pcs_get_state()
1306 state->speed = pl->link_config.speed; in phylink_mac_pcs_get_state()
1307 state->duplex = pl->link_config.duplex; in phylink_mac_pcs_get_state()
1308 state->pause = pl->link_config.pause; in phylink_mac_pcs_get_state()
1310 state->an_complete = 0; in phylink_mac_pcs_get_state()
1311 state->link = 1; in phylink_mac_pcs_get_state()
1313 if (pl->pcs) in phylink_mac_pcs_get_state()
1314 pl->pcs->ops->pcs_get_state(pl->pcs, state); in phylink_mac_pcs_get_state()
1316 state->link = 0; in phylink_mac_pcs_get_state()
1325 *state = pl->link_config; in phylink_get_fixed_state()
1326 if (pl->config->get_fixed_state) in phylink_get_fixed_state()
1327 pl->config->get_fixed_state(pl->config, state); in phylink_get_fixed_state()
1328 else if (pl->link_gpio) in phylink_get_fixed_state()
1329 state->link = !!gpiod_get_value_cansleep(pl->link_gpio); in phylink_get_fixed_state()
1331 state->pause = MLO_PAUSE_NONE; in phylink_get_fixed_state()
1339 switch (pl->cur_link_an_mode) { in phylink_mac_initial_config()
1341 link_state = pl->phy_state; in phylink_mac_initial_config()
1349 link_state = pl->link_config; in phylink_mac_initial_config()
1381 struct net_device *ndev = pl->netdev; in phylink_link_up()
1411 pl->cur_interface = link_state.interface; in phylink_link_up()
1413 neg_mode = pl->cur_link_an_mode; in phylink_link_up()
1414 if (pl->pcs && pl->pcs->neg_mode) in phylink_link_up()
1415 neg_mode = pl->pcs_neg_mode; in phylink_link_up()
1417 phylink_pcs_link_up(pl->pcs, neg_mode, pl->cur_interface, speed, in phylink_link_up()
1420 pl->mac_ops->mac_link_up(pl->config, pl->phydev, pl->cur_link_an_mode, in phylink_link_up()
1421 pl->cur_interface, speed, duplex, in phylink_link_up()
1428 "Link is Up - %s/%s - flow control %s\n", in phylink_link_up()
1436 struct net_device *ndev = pl->netdev; in phylink_link_down()
1440 pl->mac_ops->mac_link_down(pl->config, pl->cur_link_an_mode, in phylink_link_down()
1441 pl->cur_interface); in phylink_link_down()
1449 struct net_device *ndev = pl->netdev; in phylink_resolve()
1454 mutex_lock(&pl->state_mutex); in phylink_resolve()
1455 if (pl->netdev) in phylink_resolve()
1458 cur_link_state = pl->old_link_state; in phylink_resolve()
1460 if (pl->phylink_disable_state) { in phylink_resolve()
1461 pl->link_failed = false; in phylink_resolve()
1463 } else if (pl->link_failed) { in phylink_resolve()
1466 } else if (pl->cur_link_an_mode == MLO_AN_FIXED) { in phylink_resolve()
1469 } else if (pl->cur_link_an_mode == MLO_AN_PHY) { in phylink_resolve()
1470 link_state = pl->phy_state; in phylink_resolve()
1475 /* The PCS may have a latching link-fail indicator. If the link in phylink_resolve()
1476 * was up, bring the link down and re-trigger the resolve. in phylink_resolve()
1477 * Otherwise, re-read the PCS state to get the current status in phylink_resolve()
1490 if (pl->phydev) in phylink_resolve()
1491 link_state.link &= pl->phy_state.link; in phylink_resolve()
1494 if (pl->phydev && pl->phy_state.link) { in phylink_resolve()
1496 * event if the link isn't already down, and re-resolve. in phylink_resolve()
1498 if (link_state.interface != pl->phy_state.interface) { in phylink_resolve()
1503 link_state.interface = pl->phy_state.interface; in phylink_resolve()
1508 if (pl->phy_state.rate_matching) { in phylink_resolve()
1510 pl->phy_state.rate_matching; in phylink_resolve()
1511 link_state.speed = pl->phy_state.speed; in phylink_resolve()
1512 link_state.duplex = pl->phy_state.duplex; in phylink_resolve()
1518 link_state.pause = pl->phy_state.pause; in phylink_resolve()
1523 if (pl->cur_link_an_mode != MLO_AN_FIXED) in phylink_resolve()
1527 if (link_state.interface != pl->link_config.interface) { in phylink_resolve()
1536 pl->link_config.interface = link_state.interface; in phylink_resolve()
1541 pl->old_link_state = link_state.link; in phylink_resolve()
1548 pl->link_failed = false; in phylink_resolve()
1549 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_resolve()
1551 mutex_unlock(&pl->state_mutex); in phylink_resolve()
1556 if (!pl->phylink_disable_state) in phylink_run_resolve()
1557 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_run_resolve()
1562 unsigned long state = pl->phylink_disable_state; in phylink_run_resolve_and_disable()
1564 set_bit(bit, &pl->phylink_disable_state); in phylink_run_resolve_and_disable()
1566 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_run_resolve_and_disable()
1567 flush_work(&pl->resolve); in phylink_run_resolve_and_disable()
1573 clear_bit(bit, &pl->phylink_disable_state); in phylink_enable_and_run_resolve()
1603 pl->sfp_bus = bus; in phylink_register_sfp()
1612 * phylink_set_fixed_link() - set the fixed link
1619 * Returns: zero on success or negative error code.
1627 if (pl->cfg_link_an_mode != MLO_AN_PHY || !state || in phylink_set_fixed_link()
1628 !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) in phylink_set_fixed_link()
1629 return -EINVAL; in phylink_set_fixed_link()
1631 s = phy_lookup_setting(state->speed, state->duplex, in phylink_set_fixed_link()
1632 pl->supported, true); in phylink_set_fixed_link()
1634 return -EINVAL; in phylink_set_fixed_link()
1636 adv = pl->link_config.advertising; in phylink_set_fixed_link()
1638 linkmode_set_bit(s->bit, adv); in phylink_set_fixed_link()
1641 pl->link_config.speed = state->speed; in phylink_set_fixed_link()
1642 pl->link_config.duplex = state->duplex; in phylink_set_fixed_link()
1643 pl->link_config.link = 1; in phylink_set_fixed_link()
1644 pl->link_config.an_complete = 1; in phylink_set_fixed_link()
1646 pl->cfg_link_an_mode = MLO_AN_FIXED; in phylink_set_fixed_link()
1647 pl->cur_link_an_mode = pl->cfg_link_an_mode; in phylink_set_fixed_link()
1654 * phylink_create() - create a phylink instance
1662 * This will parse in-band modes, fixed-link or SFP configuration.
1666 * Returns a pointer to a &struct phylink, or an error-pointer value. Users
1678 if (phy_interface_empty(config->supported_interfaces)) { in phylink_create()
1679 dev_err(config->dev, in phylink_create()
1681 return ERR_PTR(-EINVAL); in phylink_create()
1686 return ERR_PTR(-ENOMEM); in phylink_create()
1688 mutex_init(&pl->state_mutex); in phylink_create()
1689 INIT_WORK(&pl->resolve, phylink_resolve); in phylink_create()
1691 pl->config = config; in phylink_create()
1692 if (config->type == PHYLINK_NETDEV) { in phylink_create()
1693 pl->netdev = to_net_dev(config->dev); in phylink_create()
1694 netif_carrier_off(pl->netdev); in phylink_create()
1695 } else if (config->type == PHYLINK_DEV) { in phylink_create()
1696 pl->dev = config->dev; in phylink_create()
1699 return ERR_PTR(-EINVAL); in phylink_create()
1702 pl->phy_state.interface = iface; in phylink_create()
1703 pl->link_interface = iface; in phylink_create()
1705 pl->link_port = PORT_BNC; in phylink_create()
1707 pl->link_port = PORT_MII; in phylink_create()
1708 pl->link_config.interface = iface; in phylink_create()
1709 pl->link_config.pause = MLO_PAUSE_AN; in phylink_create()
1710 pl->link_config.speed = SPEED_UNKNOWN; in phylink_create()
1711 pl->link_config.duplex = DUPLEX_UNKNOWN; in phylink_create()
1712 pl->pcs_state = PCS_STATE_DOWN; in phylink_create()
1713 pl->mac_ops = mac_ops; in phylink_create()
1714 __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state); in phylink_create()
1715 timer_setup(&pl->link_poll, phylink_fixed_poll, 0); in phylink_create()
1717 linkmode_fill(pl->supported); in phylink_create()
1718 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_create()
1719 phylink_validate(pl, pl->supported, &pl->link_config); in phylink_create()
1727 if (pl->cfg_link_an_mode == MLO_AN_FIXED) { in phylink_create()
1735 pl->cur_link_an_mode = pl->cfg_link_an_mode; in phylink_create()
1748 * phylink_destroy() - cleanup and destroy the phylink instance
1758 sfp_bus_del_upstream(pl->sfp_bus); in phylink_destroy()
1759 if (pl->link_gpio) in phylink_destroy()
1760 gpiod_put(pl->link_gpio); in phylink_destroy()
1762 cancel_work_sync(&pl->resolve); in phylink_destroy()
1768 * phylink_expects_phy() - Determine if phylink expects a phy to be attached
1771 * When using fixed-link mode, or in-band mode with 1000base-X or 2500base-X,
1778 if (pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_expects_phy()
1779 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_expects_phy()
1780 phy_interface_mode_is_8023z(pl->link_config.interface))) in phylink_expects_phy()
1788 struct phylink *pl = phydev->phylink; in phylink_phy_change()
1793 mutex_lock(&pl->state_mutex); in phylink_phy_change()
1794 pl->phy_state.speed = phydev->speed; in phylink_phy_change()
1795 pl->phy_state.duplex = phydev->duplex; in phylink_phy_change()
1796 pl->phy_state.rate_matching = phydev->rate_matching; in phylink_phy_change()
1797 pl->phy_state.pause = MLO_PAUSE_NONE; in phylink_phy_change()
1799 pl->phy_state.pause |= MLO_PAUSE_TX; in phylink_phy_change()
1801 pl->phy_state.pause |= MLO_PAUSE_RX; in phylink_phy_change()
1802 pl->phy_state.interface = phydev->interface; in phylink_phy_change()
1803 pl->phy_state.link = up; in phylink_phy_change()
1805 pl->link_failed = true; in phylink_phy_change()
1806 mutex_unlock(&pl->state_mutex); in phylink_phy_change()
1811 phy_modes(phydev->interface), in phylink_phy_change()
1812 phy_speed_to_str(phydev->speed), in phylink_phy_change()
1813 phy_duplex_to_str(phydev->duplex), in phylink_phy_change()
1814 phy_rate_matching_to_str(phydev->rate_matching), in phylink_phy_change()
1815 phylink_pause_to_str(pl->phy_state.pause)); in phylink_phy_change()
1825 * depending on the negotiated media speeds, use this to validate in phylink_validate_phy()
1828 if (!phy_interface_empty(phy->possible_interfaces)) { in phylink_validate_phy()
1832 phy_interface_and(interfaces, phy->possible_interfaces, in phylink_validate_phy()
1833 pl->config->supported_interfaces); in phylink_validate_phy()
1837 return -EINVAL; in phylink_validate_phy()
1841 /* If the PHY is on a SFP, limit the interfaces to in phylink_validate_phy()
1849 return -EINVAL; in phylink_validate_phy()
1856 phy->possible_interfaces, in phylink_validate_phy()
1869 state->rate_matching = phy_get_rate_matching(phy, state->interface); in phylink_validate_phy()
1871 /* Clause 45 PHYs may switch their Serdes lane between, e.g. 10GBASE-R, in phylink_validate_phy()
1872 * 5GBASE-R, 2500BASE-X and SGMII if they are not using rate matching. in phylink_validate_phy()
1878 * linkmodes can be supported. For now, as a work-around, we validate in phylink_validate_phy()
1882 if (phy->is_c45 && state->rate_matching == RATE_MATCH_NONE && in phylink_validate_phy()
1883 state->interface != PHY_INTERFACE_MODE_RXAUI && in phylink_validate_phy()
1884 state->interface != PHY_INTERFACE_MODE_XAUI && in phylink_validate_phy()
1885 state->interface != PHY_INTERFACE_MODE_USXGMII) in phylink_validate_phy()
1886 state->interface = PHY_INTERFACE_MODE_NA; in phylink_validate_phy()
1909 linkmode_copy(supported, phy->supported); in phylink_bringup_phy()
1910 linkmode_copy(config.advertising, phy->advertising); in phylink_bringup_phy()
1917 __ETHTOOL_LINK_MODE_MASK_NBITS, phy->supported, in phylink_bringup_phy()
1923 phy->phylink = pl; in phylink_bringup_phy()
1924 phy->phy_link_change = phylink_phy_change; in phylink_bringup_phy()
1929 dev_name(&phy->mdio.dev), phy->drv->name, irq_str); in phylink_bringup_phy()
1932 mutex_lock(&phy->lock); in phylink_bringup_phy()
1933 mutex_lock(&pl->state_mutex); in phylink_bringup_phy()
1934 pl->phydev = phy; in phylink_bringup_phy()
1935 pl->phy_state.interface = interface; in phylink_bringup_phy()
1936 pl->phy_state.pause = MLO_PAUSE_NONE; in phylink_bringup_phy()
1937 pl->phy_state.speed = SPEED_UNKNOWN; in phylink_bringup_phy()
1938 pl->phy_state.duplex = DUPLEX_UNKNOWN; in phylink_bringup_phy()
1939 pl->phy_state.rate_matching = RATE_MATCH_NONE; in phylink_bringup_phy()
1940 linkmode_copy(pl->supported, supported); in phylink_bringup_phy()
1941 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_bringup_phy()
1944 linkmode_copy(phy->advertising, config.advertising); in phylink_bringup_phy()
1945 mutex_unlock(&pl->state_mutex); in phylink_bringup_phy()
1946 mutex_unlock(&phy->lock); in phylink_bringup_phy()
1951 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, in phylink_bringup_phy()
1952 __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising); in phylink_bringup_phy()
1957 if (pl->config->mac_managed_pm) in phylink_bringup_phy()
1958 phy->mac_managed_pm = true; in phylink_bringup_phy()
1968 if (WARN_ON(pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_attach_phy()
1969 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_attach_phy()
1970 phy_interface_mode_is_8023z(interface) && !pl->sfp_bus))) in phylink_attach_phy()
1971 return -EINVAL; in phylink_attach_phy()
1973 if (pl->phydev) in phylink_attach_phy()
1974 return -EBUSY; in phylink_attach_phy()
1976 if (pl->config->mac_requires_rxc) in phylink_attach_phy()
1979 return phy_attach_direct(pl->netdev, phy, flags, interface); in phylink_attach_phy()
1983 * phylink_connect_phy() - connect a PHY to the phylink instance
1995 * Returns 0 on success or a negative errno.
2002 if (pl->link_interface == PHY_INTERFACE_MODE_NA) { in phylink_connect_phy()
2003 pl->link_interface = phy->interface; in phylink_connect_phy()
2004 pl->link_config.interface = pl->link_interface; in phylink_connect_phy()
2007 ret = phylink_attach_phy(pl, phy, pl->link_interface); in phylink_connect_phy()
2011 ret = phylink_bringup_phy(pl, phy, pl->link_config.interface); in phylink_connect_phy()
2020 * phylink_of_phy_connect() - connect the PHY specified in the DT mode.
2023 * @flags: PHY-specific flags to communicate to the PHY device driver
2029 * Returns 0 on success or a negative errno.
2039 * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode.
2042 * @flags: PHY-specific flags to communicate to the PHY device driver
2047 * Returns 0 on success or a negative errno.
2058 if (pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_fwnode_phy_connect()
2059 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_fwnode_phy_connect()
2060 phy_interface_mode_is_8023z(pl->link_interface))) in phylink_fwnode_phy_connect()
2065 if (pl->cfg_link_an_mode == MLO_AN_PHY) in phylink_fwnode_phy_connect()
2066 return -ENODEV; in phylink_fwnode_phy_connect()
2074 return -ENODEV; in phylink_fwnode_phy_connect()
2077 if (pl->link_interface == PHY_INTERFACE_MODE_NA) { in phylink_fwnode_phy_connect()
2078 pl->link_interface = phy_dev->interface; in phylink_fwnode_phy_connect()
2079 pl->link_config.interface = pl->link_interface; in phylink_fwnode_phy_connect()
2082 if (pl->config->mac_requires_rxc) in phylink_fwnode_phy_connect()
2085 ret = phy_attach_direct(pl->netdev, phy_dev, flags, in phylink_fwnode_phy_connect()
2086 pl->link_interface); in phylink_fwnode_phy_connect()
2091 ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface); in phylink_fwnode_phy_connect()
2100 * phylink_disconnect_phy() - disconnect any PHY attached to the phylink
2112 phy = pl->phydev; in phylink_disconnect_phy()
2114 mutex_lock(&phy->lock); in phylink_disconnect_phy()
2115 mutex_lock(&pl->state_mutex); in phylink_disconnect_phy()
2116 pl->phydev = NULL; in phylink_disconnect_phy()
2117 mutex_unlock(&pl->state_mutex); in phylink_disconnect_phy()
2118 mutex_unlock(&phy->lock); in phylink_disconnect_phy()
2119 flush_work(&pl->resolve); in phylink_disconnect_phy()
2129 pl->link_failed = true; in phylink_link_changed()
2135 * phylink_mac_change() - notify phylink of a change in MAC state
2149 * phylink_pcs_change() - notify phylink of a change to PCS link state
2157 * the latched link-down state, otherwise pass false.
2161 struct phylink *pl = pcs->phylink; in phylink_pcs_change()
2178 * phylink_start() - start a phylink instance
2192 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_start()
2193 phy_modes(pl->link_config.interface)); in phylink_start()
2196 if (pl->netdev) in phylink_start()
2197 netif_carrier_off(pl->netdev); in phylink_start()
2199 pl->pcs_state = PCS_STATE_STARTING; in phylink_start()
2202 * a fixed-link to start with the correct parameters, and also in phylink_start()
2211 pl->pcs_state = PCS_STATE_STARTED; in phylink_start()
2215 if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) { in phylink_start()
2216 int irq = gpiod_to_irq(pl->link_gpio); in phylink_start()
2223 pl->link_irq = irq; in phylink_start()
2231 if (pl->cfg_link_an_mode == MLO_AN_FIXED) in phylink_start()
2232 poll |= pl->config->poll_fixed_state; in phylink_start()
2235 mod_timer(&pl->link_poll, jiffies + HZ); in phylink_start()
2236 if (pl->phydev) in phylink_start()
2237 phy_start(pl->phydev); in phylink_start()
2238 if (pl->sfp_bus) in phylink_start()
2239 sfp_upstream_start(pl->sfp_bus); in phylink_start()
2244 * phylink_stop() - stop a phylink instance
2259 if (pl->sfp_bus) in phylink_stop()
2260 sfp_upstream_stop(pl->sfp_bus); in phylink_stop()
2261 if (pl->phydev) in phylink_stop()
2262 phy_stop(pl->phydev); in phylink_stop()
2263 del_timer_sync(&pl->link_poll); in phylink_stop()
2264 if (pl->link_irq) { in phylink_stop()
2265 free_irq(pl->link_irq, pl); in phylink_stop()
2266 pl->link_irq = 0; in phylink_stop()
2271 pl->pcs_state = PCS_STATE_DOWN; in phylink_stop()
2273 phylink_pcs_disable(pl->pcs); in phylink_stop()
2278 * phylink_suspend() - handle a network device suspend event
2280 * @mac_wol: true if the MAC needs to receive packets for Wake-on-Lan
2284 * - If Wake-on-Lan is not active, we can bring down the link between
2286 * - If Wake-on-Lan is active, and being handled only by the PHY, we
2288 * - If Wake-on-Lan is active, but being handled by the MAC, the MAC
2295 if (mac_wol && (!pl->netdev || pl->netdev->ethtool->wol_enabled)) { in phylink_suspend()
2296 /* Wake-on-Lan enabled, MAC handling */ in phylink_suspend()
2297 mutex_lock(&pl->state_mutex); in phylink_suspend()
2300 __set_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state); in phylink_suspend()
2306 if (pl->netdev) in phylink_suspend()
2307 netif_carrier_off(pl->netdev); in phylink_suspend()
2309 pl->old_link_state = false; in phylink_suspend()
2314 mutex_unlock(&pl->state_mutex); in phylink_suspend()
2322 * phylink_resume() - handle a network device resume event
2332 if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) { in phylink_resume()
2333 /* Wake-on-Lan enabled, MAC handling */ in phylink_resume()
2338 * resume, which is harmless - the true link state will be in phylink_resume()
2341 mutex_lock(&pl->state_mutex); in phylink_resume()
2343 mutex_unlock(&pl->state_mutex); in phylink_resume()
2345 /* Re-apply the link parameters so that all the settings get in phylink_resume()
2350 /* Re-enable and re-resolve the link parameters */ in phylink_resume()
2359 * phylink_ethtool_get_wol() - get the wake on lan parameters for the PHY
2363 * Read the wake on lan parameters from the PHY attached to the phylink
2365 * support for wake on lan.
2371 wol->supported = 0; in phylink_ethtool_get_wol()
2372 wol->wolopts = 0; in phylink_ethtool_get_wol()
2374 if (pl->phydev) in phylink_ethtool_get_wol()
2375 phy_ethtool_get_wol(pl->phydev, wol); in phylink_ethtool_get_wol()
2380 * phylink_ethtool_set_wol() - set wake on lan parameters
2384 * Set the wake on lan parameters for the PHY attached to the phylink
2388 * Returns zero on success or negative errno code.
2392 int ret = -EOPNOTSUPP; in phylink_ethtool_set_wol()
2396 if (pl->phydev) in phylink_ethtool_set_wol()
2397 ret = phy_ethtool_set_wol(pl->phydev, wol); in phylink_ethtool_set_wol()
2408 interface = sfp_select_interface(pl->sfp_bus, link_modes); in phylink_sfp_select_interface()
2417 if (!test_bit(interface, pl->config->supported_interfaces)) { in phylink_sfp_select_interface()
2422 pl->config->supported_interfaces); in phylink_sfp_select_interface()
2443 phylink_merge_link_mode(kset->link_modes.advertising, state->advertising); in phylink_get_ksettings()
2444 linkmode_copy(kset->link_modes.lp_advertising, state->lp_advertising); in phylink_get_ksettings()
2445 if (kset->base.rate_matching == RATE_MATCH_NONE) { in phylink_get_ksettings()
2446 kset->base.speed = state->speed; in phylink_get_ksettings()
2447 kset->base.duplex = state->duplex; in phylink_get_ksettings()
2449 kset->base.autoneg = linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, in phylink_get_ksettings()
2450 state->advertising) ? in phylink_get_ksettings()
2455 * phylink_ethtool_ksettings_get() - get the current link settings
2461 * settings depending on the current negotiation mode.
2470 if (pl->phydev) in phylink_ethtool_ksettings_get()
2471 phy_ethtool_ksettings_get(pl->phydev, kset); in phylink_ethtool_ksettings_get()
2473 kset->base.port = pl->link_port; in phylink_ethtool_ksettings_get()
2475 linkmode_copy(kset->link_modes.supported, pl->supported); in phylink_ethtool_ksettings_get()
2477 switch (pl->cur_link_an_mode) { in phylink_ethtool_ksettings_get()
2480 * current link settings - and note that these also in phylink_ethtool_ksettings_get()
2491 if (pl->phydev) in phylink_ethtool_ksettings_get()
2497 * layer via in-band status. Report these as the current in phylink_ethtool_ksettings_get()
2509 * phylink_ethtool_ksettings_set() - set the link settings
2522 if (pl->phydev) { in phylink_ethtool_ksettings_set()
2527 pl->supported); in phylink_ethtool_ksettings_set()
2529 /* We can rely on phylib for this update; we also do not need in phylink_ethtool_ksettings_set()
2530 * to update the pl->link_config settings: in phylink_ethtool_ksettings_set()
2531 * - the configuration returned via ksettings_get() will come in phylink_ethtool_ksettings_set()
2533 * - link_config.interface will be updated by the PHY calling in phylink_ethtool_ksettings_set()
2535 * - initial link configuration for PHY mode comes from the in phylink_ethtool_ksettings_set()
2537 * - other configuration changes (e.g. pause modes) are in phylink_ethtool_ksettings_set()
2539 * - if in in-band mode with a PHY, the link configuration in phylink_ethtool_ksettings_set()
2540 * is passed on the link from the PHY, and all of in phylink_ethtool_ksettings_set()
2542 * - the only possible use would be link_config.advertising in phylink_ethtool_ksettings_set()
2543 * pause modes when in 1000base-X mode with a PHY, but in in phylink_ethtool_ksettings_set()
2547 return phy_ethtool_ksettings_set(pl->phydev, &phy_kset); in phylink_ethtool_ksettings_set()
2550 config = pl->link_config; in phylink_ethtool_ksettings_set()
2552 linkmode_and(config.advertising, kset->link_modes.advertising, in phylink_ethtool_ksettings_set()
2553 pl->supported); in phylink_ethtool_ksettings_set()
2556 switch (kset->base.autoneg) { in phylink_ethtool_ksettings_set()
2561 s = phy_lookup_setting(kset->base.speed, kset->base.duplex, in phylink_ethtool_ksettings_set()
2562 pl->supported, false); in phylink_ethtool_ksettings_set()
2564 return -EINVAL; in phylink_ethtool_ksettings_set()
2569 if (pl->cur_link_an_mode == MLO_AN_FIXED) { in phylink_ethtool_ksettings_set()
2570 if (s->speed != pl->link_config.speed || in phylink_ethtool_ksettings_set()
2571 s->duplex != pl->link_config.duplex) in phylink_ethtool_ksettings_set()
2572 return -EINVAL; in phylink_ethtool_ksettings_set()
2576 config.speed = s->speed; in phylink_ethtool_ksettings_set()
2577 config.duplex = s->duplex; in phylink_ethtool_ksettings_set()
2585 if (pl->cur_link_an_mode == MLO_AN_FIXED) { in phylink_ethtool_ksettings_set()
2587 pl->link_config.advertising)) in phylink_ethtool_ksettings_set()
2588 return -EINVAL; in phylink_ethtool_ksettings_set()
2597 return -EINVAL; in phylink_ethtool_ksettings_set()
2601 * fixed-link cases. All that is left are in-band links. in phylink_ethtool_ksettings_set()
2604 kset->base.autoneg == AUTONEG_ENABLE); in phylink_ethtool_ksettings_set()
2610 if (pl->sfp_bus) { in phylink_ethtool_ksettings_set()
2614 return -EINVAL; in phylink_ethtool_ksettings_set()
2617 linkmode_copy(support, pl->supported); in phylink_ethtool_ksettings_set()
2620 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_ethtool_ksettings_set()
2623 return -EINVAL; in phylink_ethtool_ksettings_set()
2627 linkmode_copy(support, pl->supported); in phylink_ethtool_ksettings_set()
2629 return -EINVAL; in phylink_ethtool_ksettings_set()
2636 return -EINVAL; in phylink_ethtool_ksettings_set()
2638 mutex_lock(&pl->state_mutex); in phylink_ethtool_ksettings_set()
2639 pl->link_config.speed = config.speed; in phylink_ethtool_ksettings_set()
2640 pl->link_config.duplex = config.duplex; in phylink_ethtool_ksettings_set()
2642 if (pl->link_config.interface != config.interface) { in phylink_ethtool_ksettings_set()
2643 /* The interface changed, e.g. 1000base-X <-> 2500base-X */ in phylink_ethtool_ksettings_set()
2645 if (pl->old_link_state) { in phylink_ethtool_ksettings_set()
2647 pl->old_link_state = false; in phylink_ethtool_ksettings_set()
2650 &pl->phylink_disable_state)) in phylink_ethtool_ksettings_set()
2652 pl->link_config.interface = config.interface; in phylink_ethtool_ksettings_set()
2653 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_ethtool_ksettings_set()
2654 } else if (!linkmode_equal(pl->link_config.advertising, in phylink_ethtool_ksettings_set()
2656 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_ethtool_ksettings_set()
2659 mutex_unlock(&pl->state_mutex); in phylink_ethtool_ksettings_set()
2666 * phylink_ethtool_nway_reset() - restart negotiation
2674 * Returns zero on success, or negative error code.
2682 if (pl->phydev) in phylink_ethtool_nway_reset()
2683 ret = phy_restart_aneg(pl->phydev); in phylink_ethtool_nway_reset()
2691 * phylink_ethtool_get_pauseparam() - get the current pause parameters
2700 pause->autoneg = !!(pl->link_config.pause & MLO_PAUSE_AN); in phylink_ethtool_get_pauseparam()
2701 pause->rx_pause = !!(pl->link_config.pause & MLO_PAUSE_RX); in phylink_ethtool_get_pauseparam()
2702 pause->tx_pause = !!(pl->link_config.pause & MLO_PAUSE_TX); in phylink_ethtool_get_pauseparam()
2707 * phylink_ethtool_set_pauseparam() - set the current pause parameters
2714 struct phylink_link_state *config = &pl->link_config; in phylink_ethtool_set_pauseparam()
2720 if (pl->cur_link_an_mode == MLO_AN_FIXED) in phylink_ethtool_set_pauseparam()
2721 return -EOPNOTSUPP; in phylink_ethtool_set_pauseparam()
2723 if (!phylink_test(pl->supported, Pause) && in phylink_ethtool_set_pauseparam()
2724 !phylink_test(pl->supported, Asym_Pause)) in phylink_ethtool_set_pauseparam()
2725 return -EOPNOTSUPP; in phylink_ethtool_set_pauseparam()
2727 if (!phylink_test(pl->supported, Asym_Pause) && in phylink_ethtool_set_pauseparam()
2728 pause->rx_pause != pause->tx_pause) in phylink_ethtool_set_pauseparam()
2729 return -EINVAL; in phylink_ethtool_set_pauseparam()
2732 if (pause->autoneg) in phylink_ethtool_set_pauseparam()
2734 if (pause->rx_pause) in phylink_ethtool_set_pauseparam()
2736 if (pause->tx_pause) in phylink_ethtool_set_pauseparam()
2739 mutex_lock(&pl->state_mutex); in phylink_ethtool_set_pauseparam()
2753 linkmode_set_pause(config->advertising, pause->tx_pause, in phylink_ethtool_set_pauseparam()
2754 pause->rx_pause); in phylink_ethtool_set_pauseparam()
2756 manual_changed = (config->pause ^ pause_state) & MLO_PAUSE_AN || in phylink_ethtool_set_pauseparam()
2758 (config->pause ^ pause_state) & MLO_PAUSE_TXRX_MASK); in phylink_ethtool_set_pauseparam()
2760 config->pause = pause_state; in phylink_ethtool_set_pauseparam()
2762 /* Update our in-band advertisement, triggering a renegotiation if in phylink_ethtool_set_pauseparam()
2765 if (!pl->phydev) in phylink_ethtool_set_pauseparam()
2768 mutex_unlock(&pl->state_mutex); in phylink_ethtool_set_pauseparam()
2775 if (pl->phydev) in phylink_ethtool_set_pauseparam()
2776 phy_set_asym_pause(pl->phydev, pause->rx_pause, in phylink_ethtool_set_pauseparam()
2777 pause->tx_pause); in phylink_ethtool_set_pauseparam()
2784 pl->link_failed = true; in phylink_ethtool_set_pauseparam()
2793 * phylink_get_eee_err() - read the energy efficient ethernet error
2808 if (pl->phydev) in phylink_get_eee_err()
2809 ret = phy_get_eee_err(pl->phydev); in phylink_get_eee_err()
2816 * phylink_init_eee() - init and check the EEE features
2824 int ret = -EOPNOTSUPP; in phylink_init_eee()
2826 if (pl->phydev) in phylink_init_eee()
2827 ret = phy_init_eee(pl->phydev, clk_stop_enable); in phylink_init_eee()
2834 * phylink_ethtool_get_eee() - read the energy efficient ethernet parameters
2840 int ret = -EOPNOTSUPP; in phylink_ethtool_get_eee()
2844 if (pl->phydev) in phylink_ethtool_get_eee()
2845 ret = phy_ethtool_get_eee(pl->phydev, eee); in phylink_ethtool_get_eee()
2852 * phylink_ethtool_set_eee() - set the energy efficient ethernet parameters
2858 int ret = -EOPNOTSUPP; in phylink_ethtool_set_eee()
2862 if (pl->phydev) in phylink_ethtool_set_eee()
2863 ret = phy_ethtool_set_eee(pl->phydev, eee); in phylink_ethtool_set_eee()
2869 /* This emulates MII registers for a fixed-mode phy operating as per the
2878 unsigned long *lpa = state->lp_advertising; in phylink_mii_emul_read()
2881 fs.link = state->link; in phylink_mii_emul_read()
2882 fs.speed = state->speed; in phylink_mii_emul_read()
2883 fs.duplex = state->duplex; in phylink_mii_emul_read()
2889 if (!state->an_complete) in phylink_mii_emul_read()
2898 struct phy_device *phydev = pl->phydev; in phylink_phy_read()
2904 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_read()
2908 if (phydev->is_c45) { in phylink_phy_read()
2914 devad = __ffs(phydev->c45_ids.mmds_present); in phylink_phy_read()
2918 if (!(phydev->c45_ids.mmds_present & MDIO_DEVS_AN)) in phylink_phy_read()
2919 return -EINVAL; in phylink_phy_read()
2927 return -EINVAL; in phylink_phy_read()
2930 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_read()
2934 return mdiobus_read(pl->phydev->mdio.bus, phy_id, reg); in phylink_phy_read()
2940 struct phy_device *phydev = pl->phydev; in phylink_phy_write()
2946 return mdiobus_c45_write(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_write()
2950 if (phydev->is_c45) { in phylink_phy_write()
2956 devad = __ffs(phydev->c45_ids.mmds_present); in phylink_phy_write()
2960 if (!(phydev->c45_ids.mmds_present & MDIO_DEVS_AN)) in phylink_phy_write()
2961 return -EINVAL; in phylink_phy_write()
2969 return -EINVAL; in phylink_phy_write()
2971 return mdiobus_c45_write(pl->phydev->mdio.bus, phy_id, devad, in phylink_phy_write()
2975 return mdiobus_write(phydev->mdio.bus, phy_id, reg, val); in phylink_phy_write()
2984 switch (pl->cur_link_an_mode) { in phylink_mii_read()
2993 return -EOPNOTSUPP; in phylink_mii_read()
3009 switch (pl->cur_link_an_mode) { in phylink_mii_write()
3014 return -EOPNOTSUPP; in phylink_mii_write()
3024 * phylink_mii_ioctl() - generic mii ioctl interface
3029 * Perform the specified MII ioctl on the PHY attached to the phylink instance
3032 * Returns: zero on success or negative error code.
3039 * set a register on the specified PHY.
3048 if (pl->phydev) { in phylink_mii_ioctl()
3052 mii->phy_id = pl->phydev->mdio.addr; in phylink_mii_ioctl()
3056 ret = phylink_phy_read(pl, mii->phy_id, mii->reg_num); in phylink_mii_ioctl()
3058 mii->val_out = ret; in phylink_mii_ioctl()
3064 ret = phylink_phy_write(pl, mii->phy_id, mii->reg_num, in phylink_mii_ioctl()
3065 mii->val_in); in phylink_mii_ioctl()
3069 ret = phy_mii_ioctl(pl->phydev, ifr, cmd); in phylink_mii_ioctl()
3075 mii->phy_id = 0; in phylink_mii_ioctl()
3079 ret = phylink_mii_read(pl, mii->phy_id, mii->reg_num); in phylink_mii_ioctl()
3081 mii->val_out = ret; in phylink_mii_ioctl()
3087 ret = phylink_mii_write(pl, mii->phy_id, mii->reg_num, in phylink_mii_ioctl()
3088 mii->val_in); in phylink_mii_ioctl()
3092 ret = -EOPNOTSUPP; in phylink_mii_ioctl()
3102 * phylink_speed_down() - set the non-SFP PHY to lowest speed supported by both
3119 if (!pl->sfp_bus && pl->phydev) in phylink_speed_down()
3120 ret = phy_speed_down(pl->phydev, sync); in phylink_speed_down()
3127 * phylink_speed_up() - restore the advertised speeds prior to the call to
3142 if (!pl->sfp_bus && pl->phydev) in phylink_speed_up()
3143 ret = phy_speed_up(pl->phydev); in phylink_speed_up()
3153 pl->netdev->sfp_bus = bus; in phylink_sfp_attach()
3160 pl->netdev->sfp_bus = NULL; in phylink_sfp_detach()
3186 phylink_an_mode_str(mode), phy_modes(state->interface), in phylink_sfp_set_config()
3189 if (!linkmode_equal(pl->supported, supported)) { in phylink_sfp_set_config()
3190 linkmode_copy(pl->supported, supported); in phylink_sfp_set_config()
3194 if (!linkmode_equal(pl->link_config.advertising, state->advertising)) { in phylink_sfp_set_config()
3195 linkmode_copy(pl->link_config.advertising, state->advertising); in phylink_sfp_set_config()
3199 if (pl->cur_link_an_mode != mode || in phylink_sfp_set_config()
3200 pl->link_config.interface != state->interface) { in phylink_sfp_set_config()
3201 pl->cur_link_an_mode = mode; in phylink_sfp_set_config()
3202 pl->link_config.interface = state->interface; in phylink_sfp_set_config()
3208 phy_modes(state->interface)); in phylink_sfp_set_config()
3212 &pl->phylink_disable_state)) in phylink_sfp_set_config()
3223 linkmode_copy(support, phy->supported); in phylink_sfp_config_phy()
3226 linkmode_copy(config.advertising, phy->advertising); in phylink_sfp_config_phy()
3243 return -EINVAL; in phylink_sfp_config_phy()
3259 pl->link_port = pl->sfp_port; in phylink_sfp_config_phy()
3276 pl->config->supported_interfaces, in phylink_sfp_config_optical()
3278 pl->sfp_interfaces); in phylink_sfp_config_optical()
3283 phy_interface_and(interfaces, pl->config->supported_interfaces, in phylink_sfp_config_optical()
3284 pl->sfp_interfaces); in phylink_sfp_config_optical()
3287 return -EINVAL; in phylink_sfp_config_optical()
3291 linkmode_copy(support, pl->sfp_support); in phylink_sfp_config_optical()
3292 linkmode_copy(config.advertising, pl->sfp_support); in phylink_sfp_config_optical()
3300 ret = phylink_validate_mask(pl, NULL, pl->sfp_support, &config, in phylink_sfp_config_optical()
3311 return -EINVAL; in phylink_sfp_config_optical()
3328 pl->link_port = pl->sfp_port; in phylink_sfp_config_optical()
3330 phylink_sfp_set_config(pl, MLO_AN_INBAND, pl->sfp_support, &config); in phylink_sfp_config_optical()
3342 linkmode_zero(pl->sfp_support); in phylink_sfp_module_insert()
3343 phy_interface_zero(pl->sfp_interfaces); in phylink_sfp_module_insert()
3344 sfp_parse_support(pl->sfp_bus, id, pl->sfp_support, pl->sfp_interfaces); in phylink_sfp_module_insert()
3345 pl->sfp_port = sfp_parse_port(pl->sfp_bus, id, pl->sfp_support); in phylink_sfp_module_insert()
3348 pl->sfp_may_have_phy = sfp_may_have_phy(pl->sfp_bus, id); in phylink_sfp_module_insert()
3349 if (pl->sfp_may_have_phy) in phylink_sfp_module_insert()
3360 if (pl->phydev) { in phylink_sfp_module_start()
3361 phy_start(pl->phydev); in phylink_sfp_module_start()
3368 if (!pl->sfp_may_have_phy) in phylink_sfp_module_start()
3379 if (pl->phydev) in phylink_sfp_module_stop()
3380 phy_stop(pl->phydev); in phylink_sfp_module_stop()
3406 return phy->is_c45 && phy_id_compare(phy->c45_ids.device_ids[1], in phylink_phy_no_inband()
3430 phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces, in phylink_sfp_connect_phy()
3431 pl->config->supported_interfaces); in phylink_sfp_connect_phy()
3463 /* 100GBASE-KP4 and 100GBASE-CR10 not supported */
3468 /* 5GBASE-KR not supported */
3479 if (linkmode_test_bit(bit, state->advertising) && in phylink_resolve_c73()
3480 linkmode_test_bit(bit, state->lp_advertising)) in phylink_resolve_c73()
3485 state->speed = phylink_c73_priority_resolution[i].speed; in phylink_resolve_c73()
3486 state->duplex = DUPLEX_FULL; in phylink_resolve_c73()
3489 state->link = false; in phylink_resolve_c73()
3506 mii_lpa_mod_linkmode_x(state->lp_advertising, config_reg, fd_bit); in phylink_decode_c37_word()
3508 if (linkmode_test_bit(fd_bit, state->advertising) && in phylink_decode_c37_word()
3509 linkmode_test_bit(fd_bit, state->lp_advertising)) { in phylink_decode_c37_word()
3510 state->speed = speed; in phylink_decode_c37_word()
3511 state->duplex = DUPLEX_FULL; in phylink_decode_c37_word()
3514 state->link = false; in phylink_decode_c37_word()
3524 state->link = false; in phylink_decode_sgmii_word()
3530 state->speed = SPEED_10; in phylink_decode_sgmii_word()
3533 state->speed = SPEED_100; in phylink_decode_sgmii_word()
3536 state->speed = SPEED_1000; in phylink_decode_sgmii_word()
3539 state->link = false; in phylink_decode_sgmii_word()
3543 state->duplex = DUPLEX_FULL; in phylink_decode_sgmii_word()
3545 state->duplex = DUPLEX_HALF; in phylink_decode_sgmii_word()
3549 * phylink_decode_usxgmii_word() - decode the USXGMII word from a MAC PCS
3551 * @lpa: a 16 bit value which stores the USXGMII auto-negotiation word
3553 * Helper for MAC PCS supporting the USXGMII protocol and the auto-negotiation
3562 state->speed = SPEED_10; in phylink_decode_usxgmii_word()
3565 state->speed = SPEED_100; in phylink_decode_usxgmii_word()
3568 state->speed = SPEED_1000; in phylink_decode_usxgmii_word()
3571 state->speed = SPEED_2500; in phylink_decode_usxgmii_word()
3574 state->speed = SPEED_5000; in phylink_decode_usxgmii_word()
3577 state->speed = SPEED_10000; in phylink_decode_usxgmii_word()
3580 state->link = false; in phylink_decode_usxgmii_word()
3585 state->duplex = DUPLEX_FULL; in phylink_decode_usxgmii_word()
3587 state->duplex = DUPLEX_HALF; in phylink_decode_usxgmii_word()
3592 * phylink_decode_usgmii_word() - decode the USGMII word from a MAC PCS
3594 * @lpa: a 16 bit value which stores the USGMII auto-negotiation word
3596 * Helper for MAC PCS supporting the USGMII protocol and the auto-negotiation
3607 state->speed = SPEED_10; in phylink_decode_usgmii_word()
3610 state->speed = SPEED_100; in phylink_decode_usgmii_word()
3613 state->speed = SPEED_1000; in phylink_decode_usgmii_word()
3616 state->link = false; in phylink_decode_usgmii_word()
3621 state->duplex = DUPLEX_FULL; in phylink_decode_usgmii_word()
3623 state->duplex = DUPLEX_HALF; in phylink_decode_usgmii_word()
3627 * phylink_mii_c22_pcs_decode_state() - Decode MAC PCS state from MII registers
3643 state->link = !!(bmsr & BMSR_LSTATUS); in phylink_mii_c22_pcs_decode_state()
3644 state->an_complete = !!(bmsr & BMSR_ANEGCOMPLETE); in phylink_mii_c22_pcs_decode_state()
3648 if (!state->link || !linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, in phylink_mii_c22_pcs_decode_state()
3649 state->advertising)) in phylink_mii_c22_pcs_decode_state()
3652 switch (state->interface) { in phylink_mii_c22_pcs_decode_state()
3670 state->link = false; in phylink_mii_c22_pcs_decode_state()
3677 * phylink_mii_c22_pcs_get_state() - read the MAC PCS state
3698 state->link = false; in phylink_mii_c22_pcs_get_state()
3707 * phylink_mii_c22_pcs_encode_advertisement() - configure the clause 37 PCS
3718 * Return: The new value for @adv, or ``-EINVAL`` if it should not be changed.
3741 return -EINVAL; in phylink_mii_c22_pcs_encode_advertisement()
3747 * phylink_mii_c22_pcs_config() - configure clause 22 PCS
3755 * Returns negative error number on failure, zero if the advertisement
3769 ret = mdiobus_modify_changed(pcs->bus, pcs->addr, in phylink_mii_c22_pcs_config()
3791 * phylink_mii_c22_pcs_an_restart() - restart 802.3z autonegotiation
3816 struct mii_bus *bus = pcs->bus; in phylink_mii_c45_pcs_get_state()
3817 int addr = pcs->addr; in phylink_mii_c45_pcs_get_state()
3822 state->link = false; in phylink_mii_c45_pcs_get_state()
3826 state->link = !!(stat & MDIO_STAT1_LSTATUS); in phylink_mii_c45_pcs_get_state()
3827 if (!state->link) in phylink_mii_c45_pcs_get_state()
3830 switch (state->interface) { in phylink_mii_c45_pcs_get_state()
3832 state->speed = SPEED_10000; in phylink_mii_c45_pcs_get_state()
3833 state->duplex = DUPLEX_FULL; in phylink_mii_c45_pcs_get_state()