Lines Matching +full:link +full:- +full:trigger +full:- +full:order +full:- +full:stop

1 // SPDX-License-Identifier: GPL-2.0
4 * technologies such as SFP cages where the PHY is hot-pluggable.
23 #include "phy-caps.h"
38 * struct phylink - internal data type for phylink
55 u8 link_port; /* The current non-phy ethtool port */
59 /* The link configuration settings */
70 /* Serialize updates to pl->phydev with phylink_resolve() */
103 if ((pl)->config->type == PHYLINK_NETDEV) \
104 netdev_printk(level, (pl)->netdev, fmt, ##__VA_ARGS__); \
105 else if ((pl)->config->type == PHYLINK_DEV) \
106 dev_printk(level, (pl)->dev, fmt, ##__VA_ARGS__); \
118 if ((pl)->config->type == PHYLINK_NETDEV) \
119 netdev_dbg((pl)->netdev, fmt, ##__VA_ARGS__); \
120 else if ((pl)->config->type == PHYLINK_DEV) \
121 dev_dbg((pl)->dev, fmt, ##__VA_ARGS__); \
151 * phylink_set_port_modes() - set the port type modes in the ethtool mask
152 * @mask: ethtool link mode mask
201 return "inband,an-enabled";
203 return "inband,an-disabled";
227 * phylink_interface_max_speed() - get the maximum speed of a phy interface
331 * phylink_caps_to_link_caps() - Convert a set of MAC capabilities LINK caps
334 * Returns: The corresponding set of LINK_CAPA as defined in phy-caps.h
361 * phylink_caps_to_linkmodes() - Convert capabilities to ethtool link modes
383 * phylink_limit_mac_speed - limit the phylink_config to a maximum speed
396 config->mac_capabilities &= ~phylink_caps_params[i].mask;
401 * phylink_cap_from_speed_duplex - Get mac capability from speed/duplex
425 * phylink_get_capabilities() - get capabilities for a given MAC
454 * then we might have to renegotiate if the link partner
487 * phylink_validate_mask_caps() - Restrict link modes based on caps
488 * @supported: ethtool bitmask for supported link modes.
492 * Calculate the supported link modes based on @mac_capabilities, and restrict
505 caps = phylink_get_capabilities(state->interface, mac_capabilities,
506 state->rate_matching);
510 linkmode_and(state->advertising, state->advertising, mask);
522 if (pl->mac_ops->mac_select_pcs) {
523 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
533 if (!pcs->ops) {
535 phy_modes(state->interface));
537 return -EINVAL;
544 if (!phy_interface_empty(pcs->supported_interfaces) &&
545 !test_bit(state->interface, pcs->supported_interfaces)) {
547 phy_modes(state->interface));
548 return -EINVAL;
551 /* Validate the link parameters with the PCS */
552 if (pcs->ops->pcs_validate) {
553 ret = pcs->ops->pcs_validate(pcs, supported, state);
555 return -EINVAL;
560 linkmode_and(state->advertising, state->advertising,
565 /* Then validate the link parameters with the MAC */
566 if (pl->mac_ops->mac_get_caps)
567 capabilities = pl->mac_ops->mac_get_caps(pl->config,
568 state->interface);
570 capabilities = pl->config->mac_capabilities;
574 return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
621 linkmode_copy(state->advertising, all_adv);
623 return phylink_is_empty_linkmode(supported) ? -EINVAL : 0;
629 const unsigned long *interfaces = pl->config->supported_interfaces;
631 if (state->interface == PHY_INTERFACE_MODE_NA)
635 if (!test_bit(state->interface, interfaces))
636 return -EINVAL;
668 fixed_node = fwnode_get_named_child_node(fwnode, "fixed-link");
672 pl->link_config.speed = speed;
673 pl->link_config.duplex = DUPLEX_HALF;
675 if (fwnode_property_read_bool(fixed_node, "full-duplex"))
676 pl->link_config.duplex = DUPLEX_FULL;
678 /* We treat the "pause" and "asym-pause" terminology as
679 * defining the link partner's ability.
683 pl->link_config.lp_advertising);
684 if (fwnode_property_read_bool(fixed_node, "asym-pause"))
686 pl->link_config.lp_advertising);
689 desc = fwnode_gpiod_get_index(fixed_node, "link", 0,
693 pl->link_gpio = desc;
694 else if (desc == ERR_PTR(-EPROBE_DEFER))
695 ret = -EPROBE_DEFER;
704 ret = fwnode_property_read_u32_array(fwnode, "fixed-link",
707 phylink_err(pl, "broken fixed-link?\n");
708 return -EINVAL;
711 phylink_warn(pl, "%pfw uses deprecated array-style fixed-link binding!\n",
714 ret = fwnode_property_read_u32_array(fwnode, "fixed-link",
717 pl->link_config.duplex = prop[1] ?
719 pl->link_config.speed = prop[2];
722 pl->link_config.lp_advertising);
725 pl->link_config.lp_advertising);
729 if (pl->link_config.speed > SPEED_1000 &&
730 pl->link_config.duplex != DUPLEX_FULL)
731 phylink_warn(pl, "fixed link specifies half duplex for %dMbps link?\n",
732 pl->link_config.speed);
734 linkmode_zero(pl->supported);
735 phylink_fill_fixedlink_supported(pl->supported);
737 linkmode_copy(pl->link_config.advertising, pl->supported);
738 phylink_validate(pl, pl->supported, &pl->link_config);
740 c = phy_caps_lookup(pl->link_config.speed, pl->link_config.duplex,
741 pl->supported, true);
743 linkmode_and(match, pl->supported, c->linkmodes);
748 linkmode_and(pl->supported, pl->supported, mask);
750 phylink_set(pl->supported, MII);
753 linkmode_or(pl->supported, pl->supported, match);
754 linkmode_or(pl->link_config.lp_advertising,
755 pl->link_config.lp_advertising, match);
757 phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n",
758 pl->link_config.duplex == DUPLEX_FULL ? "full" : "half",
759 pl->link_config.speed);
762 linkmode_and(pl->link_config.advertising, pl->link_config.advertising,
763 pl->supported);
765 pl->link_config.link = 1;
766 pl->link_config.an_complete = 1;
778 if (pl->config->default_an_inband)
779 pl->cfg_link_an_mode = MLO_AN_INBAND;
781 dn = fwnode_get_named_child_node(fwnode, "fixed-link");
782 if (dn || fwnode_property_present(fwnode, "fixed-link"))
783 pl->cfg_link_an_mode = MLO_AN_FIXED;
787 strcmp(managed, "in-band-status") == 0)) {
788 if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
790 "can't use both fixed-link and in-band-status\n");
791 return -EINVAL;
794 pl->cfg_link_an_mode = MLO_AN_INBAND;
797 if (pl->cfg_link_an_mode == MLO_AN_INBAND) {
798 linkmode_zero(pl->supported);
799 phylink_set(pl->supported, MII);
800 phylink_set(pl->supported, Autoneg);
801 phylink_set(pl->supported, Asym_Pause);
802 phylink_set(pl->supported, Pause);
804 switch (pl->link_config.interface) {
827 caps = phylink_get_capabilities(pl->link_config.interface, caps,
829 phylink_caps_to_linkmodes(pl->supported, caps);
834 "incorrect link mode %s for in-band status\n",
835 phy_modes(pl->link_config.interface));
836 return -EINVAL;
839 linkmode_copy(pl->link_config.advertising, pl->supported);
841 if (phylink_validate(pl, pl->supported, &pl->link_config)) {
843 "failed to validate link configuration for in-band status\n");
844 return -EINVAL;
856 state->advertising))
857 state->pause &= ~MLO_PAUSE_AN;
860 if (!(pl->link_config.pause & MLO_PAUSE_AN))
861 state->pause = pl->link_config.pause;
868 if (state->duplex == DUPLEX_FULL) {
869 linkmode_resolve_pause(state->advertising,
870 state->lp_advertising,
873 state->pause |= MLO_PAUSE_TX;
875 state->pause |= MLO_PAUSE_RX;
882 if (pcs && pcs->ops->pcs_inband_caps)
883 return pcs->ops->pcs_inband_caps(pcs, interface);
891 if (pcs && pcs->ops->pcs_pre_config)
892 pcs->ops->pcs_pre_config(pcs, interface);
900 if (pcs && pcs->ops->pcs_post_config)
901 err = pcs->ops->pcs_post_config(pcs, interface);
908 if (pcs && pcs->ops->pcs_disable)
909 pcs->ops->pcs_disable(pcs);
916 if (pcs && pcs->ops->pcs_enable)
917 err = pcs->ops->pcs_enable(pcs);
929 return pcs->ops->pcs_config(pcs, neg_mode, state->interface,
930 state->advertising, permit_pause_to_mac);
937 if (pcs && pcs->ops->pcs_link_up)
938 pcs->ops->pcs_link_up(pcs, neg_mode, interface, speed, duplex);
943 if (pcs && pcs->ops->pcs_disable_eee)
944 pcs->ops->pcs_disable_eee(pcs);
949 if (pcs && pcs->ops->pcs_enable_eee)
950 pcs->ops->pcs_enable_eee(pcs);
961 if (!pl->mac_ops->mac_select_pcs)
964 pcs = pl->mac_ops->mac_select_pcs(pl->config, interface);
973 if (pl->cfg_link_an_mode == MLO_AN_INBAND)
974 timer_delete(&pl->link_poll);
979 if (pl->pcs && pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND)
980 mod_timer(&pl->link_poll, jiffies + HZ);
988 if (pl->config->mac_requires_rxc)
989 pcs->rxc_always_on = true;
991 if (pcs->ops->pcs_pre_init)
992 ret = pcs->ops->pcs_pre_init(pcs);
1003 /* Stop drivers incorrectly using these */
1008 st.link = false;
1012 __func__, phylink_an_mode_str(pl->act_link_an_mode),
1018 pl->mac_ops->mac_config(pl->config, pl->act_link_an_mode, &st);
1023 if (pl->pcs && linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
1024 pl->link_config.advertising) &&
1025 phy_interface_mode_is_8023z(pl->link_config.interface) &&
1026 phylink_autoneg_inband(pl->act_link_an_mode))
1027 pl->pcs->ops->pcs_an_restart(pl->pcs);
1053 /* 1000base-X is designed for use media-side for Fibre
1055 * taken into account. We also do this for 2500base-X
1067 * phylink_pcs_neg_mode() - helper to determine PCS inband mode
1071 * @advertising: adertisement ethtool link mode mask
1076 * - %PHYLINK_PCS_NEG_NONE: interface mode does not support inband
1077 * - %PHYLINK_PCS_NEG_OUTBAND: an out of band mode (e.g. reading the PHY)
1079 * - %PHYLINK_PCS_NEG_INBAND_DISABLED: inband mode selected but autoneg
1081 * - %PHYLINK_PCS_NEG_INBAND_ENABLED: inband mode selected and autoneg enabled
1097 pl->pcs_neg_mode = PHYLINK_PCS_NEG_NONE;
1098 pl->act_link_an_mode = pl->req_link_an_mode;
1102 mode = pl->req_link_an_mode;
1104 pl->phy_ib_mode = 0;
1109 if (pl->phydev)
1110 phy_ib_caps = phy_inband_caps(pl->phydev, interface);
1120 /* PCS supports reporting in-band capabilities, and
1130 /* PHY supports in-band capabilities, and supports
1134 pl->phy_ib_mode = LINK_INBAND_DISABLE;
1136 pl->phy_ib_mode = LINK_INBAND_BYPASS;
1154 } else if (type == INBAND_CISCO_SGMII || pl->phydev) {
1156 * Base-X with a PHY, we try to use in-band mode where-ever
1158 * do not support in-band.
1185 /* In-band supported or unknown at both ends. Enable
1186 * in-band mode with or without bypass at the PHY.
1189 pl->phy_ib_mode = LINK_INBAND_ENABLE;
1191 pl->phy_ib_mode = LINK_INBAND_BYPASS;
1196 /* Either in-band not supported at at least one end.
1197 * In-band bypass at the other end is possible.
1200 pl->phy_ib_mode = LINK_INBAND_DISABLE;
1202 pl->phy_ib_mode = LINK_INBAND_BYPASS;
1205 if (pl->phydev)
1209 phylink_warn(pl, "%s: incompatible in-band capabilities, trying in-band",
1214 /* For Base-X without a PHY */
1232 pl->pcs_neg_mode = neg_mode;
1233 pl->act_link_an_mode = mode;
1245 phylink_an_mode_str(pl->req_link_an_mode),
1246 phy_modes(state->interface));
1248 pl->major_config_failed = false;
1250 if (pl->mac_ops->mac_select_pcs) {
1251 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface);
1257 pl->major_config_failed = true;
1261 pcs_changed = pl->pcs != pcs;
1264 phylink_pcs_neg_mode(pl, pcs, state->interface, state->advertising);
1267 phylink_an_mode_str(pl->act_link_an_mode),
1268 phylink_pcs_mode_str(pl->pcs_neg_mode),
1269 phy_modes(state->interface));
1273 if (pl->mac_ops->mac_prepare) {
1274 err = pl->mac_ops->mac_prepare(pl->config, pl->act_link_an_mode,
1275 state->interface);
1279 pl->major_config_failed = true;
1288 phylink_pcs_disable(pl->pcs);
1290 if (pl->pcs)
1291 pl->pcs->phylink = NULL;
1293 pcs->phylink = pl;
1295 pl->pcs = pcs;
1298 if (pl->pcs)
1299 phylink_pcs_pre_config(pl->pcs, state->interface);
1303 if (pl->pcs) {
1304 err = phylink_pcs_post_config(pl->pcs, state->interface);
1309 pl->major_config_failed = true;
1313 if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed)
1314 phylink_pcs_enable(pl->pcs);
1316 err = phylink_pcs_config(pl->pcs, pl->pcs_neg_mode, state,
1317 !!(pl->link_config.pause & MLO_PAUSE_AN));
1320 pl->major_config_failed = true;
1328 if (pl->mac_ops->mac_finish) {
1329 err = pl->mac_ops->mac_finish(pl->config, pl->act_link_an_mode,
1330 state->interface);
1335 pl->major_config_failed = true;
1339 if (pl->phydev && pl->phy_ib_mode) {
1340 err = phy_config_inband(pl->phydev, pl->phy_ib_mode);
1345 pl->major_config_failed = true;
1349 if (pl->sfp_bus) {
1350 rate_kbd = phylink_interface_signal_rate(state->interface);
1352 sfp_upstream_set_signal_rate(pl->sfp_bus, rate_kbd);
1368 if (test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state))
1372 phylink_an_mode_str(pl->req_link_an_mode),
1373 phy_modes(pl->link_config.interface),
1374 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->link_config.advertising,
1375 pl->link_config.pause);
1378 phylink_pcs_neg_mode(pl, pl->pcs, pl->link_config.interface,
1379 pl->link_config.advertising);
1381 /* Modern PCS-based method; update the advert at the PCS, and
1385 ret = phylink_pcs_config(pl->pcs, pl->pcs_neg_mode, &pl->link_config,
1386 !!(pl->link_config.pause & MLO_PAUSE_AN));
1402 linkmode_copy(state->advertising, pl->link_config.advertising);
1403 linkmode_zero(state->lp_advertising);
1404 state->interface = pl->link_config.interface;
1405 state->rate_matching = pl->link_config.rate_matching;
1406 state->an_complete = 0;
1407 state->link = 1;
1409 autoneg = pl->pcs_neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED;
1411 state->speed = SPEED_UNKNOWN;
1412 state->duplex = DUPLEX_UNKNOWN;
1413 state->pause = MLO_PAUSE_NONE;
1415 state->speed = pl->link_config.speed;
1416 state->duplex = pl->link_config.duplex;
1417 state->pause = pl->link_config.pause;
1420 pcs = pl->pcs;
1422 pcs->ops->pcs_get_state(pcs, pl->pcs_neg_mode, state);
1424 state->link = 0;
1427 /* The fixed state is... fixed except for the link state,
1433 *state = pl->link_config;
1434 if (pl->config->get_fixed_state)
1435 pl->config->get_fixed_state(pl->config, state);
1436 else if (pl->link_gpio)
1437 state->link = !!gpiod_get_value_cansleep(pl->link_gpio);
1439 state->pause = MLO_PAUSE_NONE;
1446 struct phy_device *phy = pl->phydev;
1448 switch (pl->req_link_an_mode) {
1450 link_state = pl->phy_state;
1458 link_state = pl->link_config;
1467 link_state.link = false;
1471 mutex_lock(&phy->lock);
1474 mutex_unlock(&phy->lock);
1493 if (pl->mac_enable_tx_lpi) {
1494 pl->mac_enable_tx_lpi = false;
1498 pl->mac_ops->mac_disable_tx_lpi(pl->config);
1500 phylink_pcs_disable_eee(pl->pcs);
1508 if (!test_bit(pl->cur_interface, pl->config->lpi_interfaces)) {
1510 phy_modes(pl->cur_interface));
1514 phylink_dbg(pl, "LPI timer %uus, tx clock stop %u\n",
1515 pl->mac_tx_lpi_timer, pl->mac_tx_clk_stop);
1517 phylink_pcs_enable_eee(pl->pcs);
1519 err = pl->mac_ops->mac_enable_tx_lpi(pl->config, pl->mac_tx_lpi_timer,
1520 pl->mac_tx_clk_stop);
1522 phylink_pcs_disable_eee(pl->pcs);
1524 pl->mac_ops->mac_enable_tx_lpi, ERR_PTR(err));
1528 pl->mac_enable_tx_lpi = true;
1534 struct net_device *ndev = pl->netdev;
1563 pl->cur_interface = link_state.interface;
1565 phylink_pcs_link_up(pl->pcs, pl->pcs_neg_mode, pl->cur_interface, speed,
1568 pl->mac_ops->mac_link_up(pl->config, pl->phydev, pl->act_link_an_mode,
1569 pl->cur_interface, speed, duplex,
1572 if (pl->mac_supports_eee && pl->phy_enable_tx_lpi)
1579 "Link is Up - %s/%s - flow control %s\n",
1587 struct net_device *ndev = pl->netdev;
1594 pl->mac_ops->mac_link_down(pl->config, pl->act_link_an_mode,
1595 pl->cur_interface);
1596 phylink_info(pl, "Link is Down\n");
1601 return pl->netdev ? netif_carrier_ok(pl->netdev) : pl->old_link_state;
1613 mutex_lock(&pl->phydev_mutex);
1614 phy = pl->phydev;
1616 mutex_lock(&phy->lock);
1617 mutex_lock(&pl->state_mutex);
1620 if (pl->phylink_disable_state) {
1621 pl->link_failed = false;
1622 link_state.link = false;
1623 } else if (pl->link_failed) {
1624 link_state.link = false;
1626 } else if (pl->act_link_an_mode == MLO_AN_FIXED) {
1628 mac_config = link_state.link;
1629 } else if (pl->act_link_an_mode == MLO_AN_PHY) {
1630 link_state = pl->phy_state;
1631 mac_config = link_state.link;
1635 /* The PCS may have a latching link-fail indicator. If the link
1636 * was up, bring the link down and re-trigger the resolve.
1637 * Otherwise, re-read the PCS state to get the current status
1638 * of the link.
1640 if (!link_state.link) {
1651 link_state.link &= pl->phy_state.link;
1653 /* Only update if the PHY link is up */
1654 if (phy && pl->phy_state.link) {
1655 /* If the interface has changed, force a link down
1656 * event if the link isn't already down, and re-resolve.
1658 if (link_state.interface != pl->phy_state.interface) {
1660 link_state.link = false;
1663 link_state.interface = pl->phy_state.interface;
1665 /* If we are doing rate matching, then the link
1668 if (pl->phy_state.rate_matching) {
1670 pl->phy_state.rate_matching;
1671 link_state.speed = pl->phy_state.speed;
1672 link_state.duplex = pl->phy_state.duplex;
1678 link_state.pause = pl->phy_state.pause;
1683 if (pl->act_link_an_mode != MLO_AN_FIXED)
1687 if (link_state.interface != pl->link_config.interface) {
1688 /* The interface has changed, force the link down and
1696 pl->link_config.interface = link_state.interface;
1700 /* If configuration of the interface failed, force the link down
1703 if (pl->major_config_failed)
1704 link_state.link = false;
1706 if (link_state.link != cur_link_state) {
1707 pl->old_link_state = link_state.link;
1708 if (!link_state.link)
1713 if (!link_state.link && retrigger) {
1714 pl->link_failed = false;
1715 queue_work(system_power_efficient_wq, &pl->resolve);
1717 mutex_unlock(&pl->state_mutex);
1719 mutex_unlock(&phy->lock);
1720 mutex_unlock(&pl->phydev_mutex);
1725 if (!pl->phylink_disable_state)
1726 queue_work(system_power_efficient_wq, &pl->resolve);
1731 unsigned long state = pl->phylink_disable_state;
1733 set_bit(bit, &pl->phylink_disable_state);
1735 queue_work(system_power_efficient_wq, &pl->resolve);
1736 flush_work(&pl->resolve);
1742 clear_bit(bit, &pl->phylink_disable_state);
1772 pl->sfp_bus = bus;
1781 * phylink_set_fixed_link() - set the fixed link
1785 * This function is used when the link parameters are known and do not change,
1796 if (pl->cfg_link_an_mode != MLO_AN_PHY || !state ||
1797 !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state))
1798 return -EINVAL;
1800 c = phy_caps_lookup(state->speed, state->duplex,
1801 pl->supported, true);
1803 return -EINVAL;
1805 adv = pl->link_config.advertising;
1806 linkmode_and(adv, pl->supported, c->linkmodes);
1809 pl->link_config.speed = state->speed;
1810 pl->link_config.duplex = state->duplex;
1811 pl->link_config.link = 1;
1812 pl->link_config.an_complete = 1;
1814 pl->cfg_link_an_mode = MLO_AN_FIXED;
1815 pl->req_link_an_mode = pl->cfg_link_an_mode;
1822 * phylink_create() - create a phylink instance
1826 * @iface: the desired link mode defined by &typedef phy_interface_t
1829 * Create a new phylink instance, and parse the link parameters found in @np.
1830 * This will parse in-band modes, fixed-link or SFP configuration.
1834 * Returns a pointer to a &struct phylink, or an error-pointer value. Users
1846 if (phy_interface_empty(config->supported_interfaces)) {
1847 dev_err(config->dev,
1849 return ERR_PTR(-EINVAL);
1854 return ERR_PTR(-ENOMEM);
1856 mutex_init(&pl->phydev_mutex);
1857 mutex_init(&pl->state_mutex);
1858 INIT_WORK(&pl->resolve, phylink_resolve);
1860 pl->config = config;
1861 if (config->type == PHYLINK_NETDEV) {
1862 pl->netdev = to_net_dev(config->dev);
1863 netif_carrier_off(pl->netdev);
1864 } else if (config->type == PHYLINK_DEV) {
1865 pl->dev = config->dev;
1868 return ERR_PTR(-EINVAL);
1871 pl->mac_supports_eee_ops = phylink_mac_implements_lpi(mac_ops);
1872 pl->mac_supports_eee = pl->mac_supports_eee_ops &&
1873 pl->config->lpi_capabilities &&
1874 !phy_interface_empty(pl->config->lpi_interfaces);
1877 pl->eee_cfg.eee_enabled = pl->config->eee_enabled_default;
1878 pl->eee_cfg.tx_lpi_enabled = pl->eee_cfg.eee_enabled;
1879 pl->eee_cfg.tx_lpi_timer = pl->config->lpi_timer_default;
1881 pl->phy_state.interface = iface;
1882 pl->link_interface = iface;
1884 pl->link_port = PORT_BNC;
1886 pl->link_port = PORT_MII;
1887 pl->link_config.interface = iface;
1888 pl->link_config.pause = MLO_PAUSE_AN;
1889 pl->link_config.speed = SPEED_UNKNOWN;
1890 pl->link_config.duplex = DUPLEX_UNKNOWN;
1891 pl->pcs_state = PCS_STATE_DOWN;
1892 pl->mac_ops = mac_ops;
1893 __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
1894 timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
1896 linkmode_fill(pl->supported);
1897 linkmode_copy(pl->link_config.advertising, pl->supported);
1898 phylink_validate(pl, pl->supported, &pl->link_config);
1906 if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
1914 pl->req_link_an_mode = pl->cfg_link_an_mode;
1927 * phylink_destroy() - cleanup and destroy the phylink instance
1937 sfp_bus_del_upstream(pl->sfp_bus);
1938 if (pl->link_gpio)
1939 gpiod_put(pl->link_gpio);
1941 cancel_work_sync(&pl->resolve);
1947 * phylink_expects_phy() - Determine if phylink expects a phy to be attached
1950 * When using fixed-link mode, or in-band mode with 1000base-X or 2500base-X,
1957 if (pl->cfg_link_an_mode == MLO_AN_FIXED ||
1958 (pl->cfg_link_an_mode == MLO_AN_INBAND &&
1959 phy_interface_mode_is_8023z(pl->link_interface)))
1967 struct phylink *pl = phydev->phylink;
1972 mutex_lock(&pl->state_mutex);
1973 pl->phy_state.speed = phydev->speed;
1974 pl->phy_state.duplex = phydev->duplex;
1975 pl->phy_state.rate_matching = phydev->rate_matching;
1976 pl->phy_state.pause = MLO_PAUSE_NONE;
1978 pl->phy_state.pause |= MLO_PAUSE_TX;
1980 pl->phy_state.pause |= MLO_PAUSE_RX;
1981 pl->phy_state.interface = phydev->interface;
1982 pl->phy_state.link = up;
1984 pl->link_failed = true;
1987 pl->phy_enable_tx_lpi = phydev->enable_tx_lpi;
1988 pl->mac_tx_lpi_timer = phydev->eee_cfg.tx_lpi_timer;
1989 mutex_unlock(&pl->state_mutex);
1993 phylink_dbg(pl, "phy link %s %s/%s/%s/%s/%s/%slpi\n",
1995 phy_modes(phydev->interface),
1996 phy_speed_to_str(phydev->speed),
1997 phy_duplex_to_str(phydev->duplex),
1998 phy_rate_matching_to_str(phydev->rate_matching),
1999 phylink_pause_to_str(pl->phy_state.pause),
2000 phydev->enable_tx_lpi ? "" : "no");
2011 * which ethtool link modes can be used.
2013 if (!phy_interface_empty(phy->possible_interfaces)) {
2017 phy_interface_and(interfaces, phy->possible_interfaces,
2018 pl->config->supported_interfaces);
2022 return -EINVAL;
2034 return -EINVAL;
2041 phy->possible_interfaces,
2054 state->rate_matching = phy_get_rate_matching(phy, state->interface);
2056 /* Clause 45 PHYs may switch their Serdes lane between, e.g. 10GBASE-R,
2057 * 5GBASE-R, 2500BASE-X and SGMII if they are not using rate matching.
2063 * linkmodes can be supported. For now, as a work-around, we validate
2064 * against all interface modes, which may lead to more ethtool link
2067 if (phy->is_c45 && state->rate_matching == RATE_MATCH_NONE &&
2068 state->interface != PHY_INTERFACE_MODE_RXAUI &&
2069 state->interface != PHY_INTERFACE_MODE_XAUI &&
2070 state->interface != PHY_INTERFACE_MODE_USXGMII)
2071 state->interface = PHY_INTERFACE_MODE_NA;
2094 linkmode_copy(supported, phy->supported);
2095 linkmode_copy(config.advertising, phy->advertising);
2102 __ETHTOOL_LINK_MODE_MASK_NBITS, phy->supported,
2108 phy->phylink = pl;
2109 phy->phy_link_change = phylink_phy_change;
2114 dev_name(&phy->mdio.dev), phy->drv->name, irq_str);
2117 mutex_lock(&pl->phydev_mutex);
2118 mutex_lock(&phy->lock);
2119 mutex_lock(&pl->state_mutex);
2120 pl->phydev = phy;
2121 pl->phy_state.interface = interface;
2122 pl->phy_state.pause = MLO_PAUSE_NONE;
2123 pl->phy_state.speed = SPEED_UNKNOWN;
2124 pl->phy_state.duplex = DUPLEX_UNKNOWN;
2125 pl->phy_state.rate_matching = RATE_MATCH_NONE;
2126 linkmode_copy(pl->supported, supported);
2127 linkmode_copy(pl->link_config.advertising, config.advertising);
2130 linkmode_copy(phy->advertising, config.advertising);
2135 if (pl->mac_supports_eee) {
2140 if (pl->eee_cfg.eee_enabled)
2143 phy->eee_cfg.tx_lpi_enabled = pl->eee_cfg.tx_lpi_enabled;
2144 phy->eee_cfg.tx_lpi_timer = pl->eee_cfg.tx_lpi_timer;
2147 linkmode_zero(pl->supported_lpi);
2148 phylink_caps_to_linkmodes(pl->supported_lpi,
2149 pl->config->lpi_capabilities);
2154 linkmode_and(phy->advertising_eee, phy->advertising_eee,
2155 pl->supported_lpi);
2156 } else if (pl->mac_supports_eee_ops) {
2161 mutex_unlock(&pl->state_mutex);
2162 mutex_unlock(&phy->lock);
2163 mutex_unlock(&pl->phydev_mutex);
2168 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported,
2169 __ETHTOOL_LINK_MODE_MASK_NBITS, phy->advertising);
2171 if (pl->config->mac_managed_pm)
2172 phy->mac_managed_pm = true;
2174 /* Allow the MAC to stop its clock if the PHY has the capability */
2175 pl->mac_tx_clk_stop = phy_eee_tx_clock_stop_capable(phy) > 0;
2177 if (pl->mac_supports_eee_ops) {
2178 /* Explicitly configure whether the PHY is allowed to stop it's
2182 pl->config->eee_rx_clk_stop_enable);
2183 if (ret == -EOPNOTSUPP)
2198 if (WARN_ON(pl->cfg_link_an_mode == MLO_AN_FIXED ||
2199 (pl->cfg_link_an_mode == MLO_AN_INBAND &&
2200 phy_interface_mode_is_8023z(interface) && !pl->sfp_bus)))
2201 return -EINVAL;
2203 if (pl->phydev)
2204 return -EBUSY;
2206 if (pl->config->mac_requires_rxc)
2209 return phy_attach_direct(pl->netdev, phy, flags, interface);
2213 * phylink_connect_phy() - connect a PHY to the phylink instance
2222 * This updates the phylink's ethtool supported and advertising link mode
2232 if (pl->link_interface == PHY_INTERFACE_MODE_NA) {
2233 pl->link_interface = phy->interface;
2234 pl->link_config.interface = pl->link_interface;
2237 ret = phylink_attach_phy(pl, phy, pl->link_interface);
2241 ret = phylink_bringup_phy(pl, phy, pl->link_config.interface);
2250 * phylink_of_phy_connect() - connect the PHY specified in the DT mode.
2253 * @flags: PHY-specific flags to communicate to the PHY device driver
2269 * phylink_fwnode_phy_connect() - connect the PHY specified in the fwnode.
2272 * @flags: PHY-specific flags to communicate to the PHY device driver
2288 if (pl->cfg_link_an_mode == MLO_AN_FIXED ||
2289 (pl->cfg_link_an_mode == MLO_AN_INBAND &&
2290 phy_interface_mode_is_8023z(pl->link_interface)))
2295 if (pl->cfg_link_an_mode == MLO_AN_PHY)
2296 return -ENODEV;
2304 return -ENODEV;
2307 if (pl->link_interface == PHY_INTERFACE_MODE_NA) {
2308 pl->link_interface = phy_dev->interface;
2309 pl->link_config.interface = pl->link_interface;
2312 if (pl->config->mac_requires_rxc)
2315 ret = phy_attach_direct(pl->netdev, phy_dev, flags,
2316 pl->link_interface);
2321 ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface);
2330 * phylink_disconnect_phy() - disconnect any PHY attached to the phylink
2342 mutex_lock(&pl->phydev_mutex);
2343 phy = pl->phydev;
2345 mutex_lock(&phy->lock);
2346 mutex_lock(&pl->state_mutex);
2347 pl->phydev = NULL;
2348 pl->phy_enable_tx_lpi = false;
2349 pl->mac_tx_clk_stop = false;
2350 mutex_unlock(&pl->state_mutex);
2351 mutex_unlock(&phy->lock);
2353 mutex_unlock(&pl->phydev_mutex);
2356 flush_work(&pl->resolve);
2365 pl->link_failed = true;
2367 phylink_dbg(pl, "%s link %s\n", what, up ? "up" : "down");
2371 * phylink_mac_change() - notify phylink of a change in MAC state
2373 * @up: indicates whether the link is currently up.
2375 * The MAC driver should call this driver when the state of its link
2376 * changes (eg, link failure, new negotiation results, etc.)
2385 * phylink_pcs_change() - notify phylink of a change to PCS link state
2387 * @up: indicates whether the link is currently up.
2389 * The PCS driver should call this when the state of its link changes
2390 * (e.g. link failure, new negotiation results, etc.) Note: it should
2391 * not determine "up" by reading the BMSR. If in doubt about the link
2393 * the latched link-down state, otherwise pass false.
2397 struct phylink *pl = pcs->phylink;
2414 * phylink_start() - start a phylink instance
2418 * desired link mode(s) and negotiation style. This should be called from the
2427 phylink_info(pl, "configuring for %s/%s link mode\n",
2428 phylink_an_mode_str(pl->req_link_an_mode),
2429 phy_modes(pl->link_config.interface));
2432 if (pl->netdev)
2433 netif_carrier_off(pl->netdev);
2435 pl->pcs_state = PCS_STATE_STARTING;
2437 /* Apply the link configuration to the MAC when starting. This allows
2438 * a fixed-link to start with the correct parameters, and also
2441 * Restart autonegotiation if using 802.3z to ensure that the link
2447 pl->pcs_state = PCS_STATE_STARTED;
2451 if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
2452 int irq = gpiod_to_irq(pl->link_gpio);
2458 "netdev link", pl))
2459 pl->link_irq = irq;
2467 if (pl->cfg_link_an_mode == MLO_AN_FIXED)
2468 poll |= pl->config->poll_fixed_state;
2471 mod_timer(&pl->link_poll, jiffies + HZ);
2472 if (pl->phydev)
2473 phy_start(pl->phydev);
2474 if (pl->sfp_bus)
2475 sfp_upstream_start(pl->sfp_bus);
2480 * phylink_stop() - stop a phylink instance
2483 * Stop the phylink instance specified by @pl. This should be called from the
2488 * This will synchronously bring down the link if the link is not already
2489 * down (in other words, it will trigger a mac_link_down() method call.)
2495 if (pl->sfp_bus)
2496 sfp_upstream_stop(pl->sfp_bus);
2497 if (pl->phydev)
2498 phy_stop(pl->phydev);
2499 timer_delete_sync(&pl->link_poll);
2500 if (pl->link_irq) {
2501 free_irq(pl->link_irq, pl);
2502 pl->link_irq = 0;
2507 pl->pcs_state = PCS_STATE_DOWN;
2509 phylink_pcs_disable(pl->pcs);
2514 * phylink_rx_clk_stop_block() - block PHY ability to stop receive clock in LPI
2517 * Disable the PHY's ability to stop the receive clock while the receive path
2525 if (pl->mac_rx_clk_stop_blocked == U8_MAX) {
2526 phylink_warn(pl, "%s called too many times - ignoring\n",
2532 /* Disable PHY receive clock stop if this is the first time this
2533 * function has been called and clock-stop was previously enabled.
2535 if (pl->mac_rx_clk_stop_blocked++ == 0 &&
2536 pl->mac_supports_eee_ops && pl->phydev &&
2537 pl->config->eee_rx_clk_stop_enable)
2538 phy_eee_rx_clock_stop(pl->phydev, false);
2543 * phylink_rx_clk_stop_unblock() - unblock PHY ability to stop receive clock
2548 * ability to stop the receive clock when the receive path is in EEE LPI mode.
2554 if (pl->mac_rx_clk_stop_blocked == 0) {
2555 phylink_warn(pl, "%s called too many times - ignoring\n",
2561 /* Re-enable PHY receive clock stop if the number of unblocks matches
2564 if (--pl->mac_rx_clk_stop_blocked == 0 &&
2565 pl->mac_supports_eee_ops && pl->phydev &&
2566 pl->config->eee_rx_clk_stop_enable)
2567 phy_eee_rx_clock_stop(pl->phydev, true);
2573 return !!pl->mac_ops->mac_wol_set;
2579 return phydev && (pl->config->wol_phy_legacy || phy_can_wakeup(phydev));
2584 return pl->config->wol_phy_speed_ctrl && !pl->wolopts_mac &&
2585 pl->phydev && phy_may_wakeup(pl->phydev);
2589 * phylink_suspend() - handle a network device suspend event
2591 * @mac_wol: true if the MAC needs to receive packets for Wake-on-Lan
2595 * - If Wake-on-Lan is not active, we can bring down the link between
2597 * - If Wake-on-Lan is active, and being handled only by the PHY, we
2598 * can also bring down the link between the MAC and PHY.
2599 * - If Wake-on-Lan is active, but being handled by the MAC, the MAC
2600 * still needs to receive packets, so we can not bring the link down.
2602 * Note: when phylink managed Wake-on-Lan is in use, @mac_wol is ignored.
2610 mac_wol = !!pl->wolopts_mac;
2612 if (mac_wol && (!pl->netdev || pl->netdev->ethtool->wol_enabled)) {
2613 /* Wake-on-Lan enabled, MAC handling */
2614 mutex_lock(&pl->state_mutex);
2616 /* Stop the resolver bringing the link up */
2617 __set_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state);
2619 pl->suspend_link_up = phylink_link_is_up(pl);
2620 if (pl->suspend_link_up) {
2625 if (pl->netdev)
2626 netif_carrier_off(pl->netdev);
2627 pl->old_link_state = false;
2631 * link to remain up to receive the WoL packets.
2633 mutex_unlock(&pl->state_mutex);
2644 * phylink_prepare_resume() - prepare to resume a network device
2653 struct phy_device *phydev = pl->phydev;
2657 /* IEEE 802.3 22.2.4.1.5 allows PHYs to stop their receive clock
2659 * in order to resume. If the MAC requires RXC, and we have a PHY,
2663 if (pl->config->mac_requires_rxc && phydev && phydev->suspended)
2669 * phylink_resume() - handle a network device resume event
2672 * Undo the effects of phylink_suspend(), returning the link to an
2682 if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) {
2683 /* Wake-on-Lan enabled, MAC handling */
2685 if (pl->suspend_link_up) {
2688 * consistency. This will cause a "Link Down" message
2689 * to be printed during resume, which is harmless -
2690 * the true link state will be printed when we run a
2693 mutex_lock(&pl->state_mutex);
2695 mutex_unlock(&pl->state_mutex);
2698 /* Re-apply the link parameters so that all the settings get
2703 /* Re-enable and re-resolve the link parameters */
2712 * phylink_ethtool_get_wol() - get the wake on lan parameters for the PHY
2724 wol->supported = 0;
2725 wol->wolopts = 0;
2728 if (phylink_phy_supports_wol(pl, pl->phydev))
2729 phy_ethtool_get_wol(pl->phydev, wol);
2734 if (~wol->wolopts & pl->wolopts_mac & WAKE_MAGICSECURE)
2735 memcpy(wol->sopass, pl->wol_sopass,
2736 sizeof(wol->sopass));
2738 wol->supported |= pl->config->wol_mac_support;
2739 wol->wolopts |= pl->wolopts_mac;
2742 if (pl->phydev)
2743 phy_ethtool_get_wol(pl->phydev, wol);
2749 * phylink_ethtool_set_wol() - set wake on lan parameters
2762 int ret = -EOPNOTSUPP;
2769 wolopts = wol->wolopts;
2771 if (phylink_phy_supports_wol(pl, pl->phydev)) {
2772 ret = phy_ethtool_set_wol(pl->phydev, wol);
2773 if (ret != 0 && ret != -EOPNOTSUPP)
2776 phy_ethtool_get_wol(pl->phydev, &w);
2778 /* Any Wake-on-Lan modes which the PHY is handling
2784 wolopts &= pl->config->wol_mac_support;
2785 changed = pl->wolopts_mac != wolopts;
2787 changed |= !!memcmp(wol->sopass, pl->wol_sopass,
2788 sizeof(wol->sopass));
2789 memcpy(pl->wol_sopass, wol->sopass, sizeof(pl->wol_sopass));
2792 ret = pl->mac_ops->mac_wol_set(pl->config, wolopts,
2793 wol->sopass);
2795 pl->wolopts_mac = wolopts;
2800 if (pl->phydev)
2801 ret = phy_ethtool_set_wol(pl->phydev, wol);
2813 interface = sfp_select_interface(pl->sfp_bus, link_modes);
2822 if (!test_bit(interface, pl->config->supported_interfaces)) {
2827 pl->config->supported_interfaces);
2844 if (!test_bit(interface, pl->sfp_interfaces))
2881 phylink_merge_link_mode(kset->link_modes.advertising, state->advertising);
2882 linkmode_copy(kset->link_modes.lp_advertising, state->lp_advertising);
2883 if (kset->base.rate_matching == RATE_MATCH_NONE) {
2884 kset->base.speed = state->speed;
2885 kset->base.duplex = state->duplex;
2887 kset->base.autoneg = linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
2888 state->advertising) ?
2893 * phylink_ethtool_ksettings_get() - get the current link settings
2895 * @kset: a pointer to a &struct ethtool_link_ksettings to hold link settings
2897 * Read the current link settings for the phylink instance specified by @pl.
2898 * This will be the link settings read from the MAC, PHY or fixed link
2908 if (pl->phydev)
2909 phy_ethtool_ksettings_get(pl->phydev, kset);
2911 kset->base.port = pl->link_port;
2913 linkmode_copy(kset->link_modes.supported, pl->supported);
2915 switch (pl->act_link_an_mode) {
2918 * current link settings - and note that these also
2929 if (pl->phydev)
2934 /* The MAC is reporting the link results from its own PCS
2935 * layer via in-band status. Report these as the current
2936 * link settings.
2967 * phylink_ethtool_ksettings_set() - set the link settings
2980 if (pl->phydev) {
2985 pl->supported);
2988 * to update the pl->link_config settings:
2989 * - the configuration returned via ksettings_get() will come
2991 * - link_config.interface will be updated by the PHY calling
2993 * - initial link configuration for PHY mode comes from the
2995 * - other configuration changes (e.g. pause modes) are
2997 * - if in in-band mode with a PHY, the link configuration
2998 * is passed on the link from the PHY, and all of
3000 * - the only possible use would be link_config.advertising
3001 * pause modes when in 1000base-X mode with a PHY, but in
3005 return phy_ethtool_ksettings_set(pl->phydev, &phy_kset);
3008 config = pl->link_config;
3010 linkmode_and(config.advertising, kset->link_modes.advertising,
3011 pl->supported);
3014 switch (kset->base.autoneg) {
3019 c = phy_caps_lookup(kset->base.speed, kset->base.duplex,
3020 pl->supported, false);
3022 return -EINVAL;
3024 /* If we have a fixed link, refuse to change link parameters.
3025 * If the link parameters match, accept them but do nothing.
3027 if (pl->req_link_an_mode == MLO_AN_FIXED) {
3028 if (c->speed != pl->link_config.speed ||
3029 c->duplex != pl->link_config.duplex)
3030 return -EINVAL;
3034 config.speed = c->speed;
3035 config.duplex = c->duplex;
3039 /* If we have a fixed link, allow autonegotiation (since that
3043 if (pl->req_link_an_mode == MLO_AN_FIXED) {
3045 pl->link_config.advertising))
3046 return -EINVAL;
3055 return -EINVAL;
3059 * fixed-link cases. All that is left are in-band links.
3062 kset->base.autoneg == AUTONEG_ENABLE);
3064 /* If this link is with an SFP, ensure that changes to advertised modes
3066 * link can be configured correctly.
3068 if (pl->sfp_bus) {
3069 if (kset->base.autoneg == AUTONEG_ENABLE)
3078 return -EINVAL;
3081 linkmode_copy(support, pl->supported);
3084 phylink_an_mode_str(pl->req_link_an_mode),
3087 return -EINVAL;
3091 linkmode_copy(support, pl->supported);
3093 return -EINVAL;
3100 return -EINVAL;
3103 * situation, so the PCS is the media-facing entity.
3107 return -EINVAL;
3109 mutex_lock(&pl->state_mutex);
3110 pl->link_config.speed = config.speed;
3111 pl->link_config.duplex = config.duplex;
3113 if (pl->link_config.interface != config.interface) {
3114 /* The interface changed, e.g. 1000base-X <-> 2500base-X */
3115 /* We need to force the link down, then change the interface */
3116 if (pl->old_link_state) {
3118 pl->old_link_state = false;
3121 &pl->phylink_disable_state))
3123 pl->link_config.interface = config.interface;
3124 linkmode_copy(pl->link_config.advertising, config.advertising);
3125 } else if (!linkmode_equal(pl->link_config.advertising,
3127 linkmode_copy(pl->link_config.advertising, config.advertising);
3130 mutex_unlock(&pl->state_mutex);
3137 * phylink_ethtool_nway_reset() - restart negotiation
3141 * cause any attached phy to restart negotiation with the link partner, and
3153 if (pl->phydev)
3154 ret = phy_restart_aneg(pl->phydev);
3162 * phylink_ethtool_get_pauseparam() - get the current pause parameters
3171 pause->autoneg = !!(pl->link_config.pause & MLO_PAUSE_AN);
3172 pause->rx_pause = !!(pl->link_config.pause & MLO_PAUSE_RX);
3173 pause->tx_pause = !!(pl->link_config.pause & MLO_PAUSE_TX);
3178 * phylink_ethtool_set_pauseparam() - set the current pause parameters
3185 struct phylink_link_state *config = &pl->link_config;
3191 if (pl->req_link_an_mode == MLO_AN_FIXED)
3192 return -EOPNOTSUPP;
3194 if (!phylink_test(pl->supported, Pause) &&
3195 !phylink_test(pl->supported, Asym_Pause))
3196 return -EOPNOTSUPP;
3198 if (!phylink_test(pl->supported, Asym_Pause) &&
3199 pause->rx_pause != pause->tx_pause)
3200 return -EINVAL;
3203 if (pause->autoneg)
3205 if (pause->rx_pause)
3207 if (pause->tx_pause)
3210 mutex_lock(&pl->state_mutex);
3224 linkmode_set_pause(config->advertising, pause->tx_pause,
3225 pause->rx_pause);
3227 manual_changed = (config->pause ^ pause_state) & MLO_PAUSE_AN ||
3229 (config->pause ^ pause_state) & MLO_PAUSE_TXRX_MASK);
3231 config->pause = pause_state;
3233 /* Update our in-band advertisement, triggering a renegotiation if
3236 if (!pl->phydev)
3239 mutex_unlock(&pl->state_mutex);
3243 * call our phylink_phy_change() and trigger a resolve. Note that
3246 if (pl->phydev)
3247 phy_set_asym_pause(pl->phydev, pause->rx_pause,
3248 pause->tx_pause);
3250 /* If the manual pause settings changed, make sure we trigger a
3252 * link will cycle.
3255 pl->link_failed = true;
3264 * phylink_get_eee_err() - read the energy efficient ethernet error
3279 if (pl->phydev)
3280 ret = phy_get_eee_err(pl->phydev);
3287 * phylink_ethtool_get_eee() - read the energy efficient ethernet parameters
3293 int ret = -EOPNOTSUPP;
3297 if (pl->mac_supports_eee_ops && !pl->mac_supports_eee)
3300 if (pl->phydev) {
3301 ret = phy_ethtool_get_eee(pl->phydev, eee);
3303 if (ret == 0 && pl->mac_supports_eee_ops)
3304 linkmode_and(eee->supported, eee->supported,
3305 pl->supported_lpi);
3313 * phylink_ethtool_set_eee() - set the energy efficient ethernet parameters
3319 bool mac_eee = pl->mac_supports_eee;
3320 int ret = -EOPNOTSUPP;
3326 eee->eee_enabled ? ", enabled" : "",
3327 __ETHTOOL_LINK_MODE_MASK_NBITS, eee->advertised,
3328 eee->tx_lpi_enabled ? " enabled" : "", eee->tx_lpi_timer);
3330 if (pl->mac_supports_eee_ops && !mac_eee)
3333 if (pl->phydev) {
3335 if (pl->mac_supports_eee_ops)
3336 linkmode_and(eee->advertised, eee->advertised,
3337 pl->supported_lpi);
3338 ret = phy_ethtool_set_eee(pl->phydev, eee);
3340 eee_to_eeecfg(&pl->eee_cfg, eee);
3347 /* This emulates MII registers for a fixed-mode phy operating as per the
3356 unsigned long *lpa = state->lp_advertising;
3359 fs.link = state->link;
3360 fs.speed = state->speed;
3361 fs.duplex = state->duplex;
3367 if (!state->an_complete)
3376 struct phy_device *phydev = pl->phydev;
3382 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad,
3386 if (phydev->is_c45) {
3392 devad = __ffs(phydev->c45_ids.mmds_present);
3396 if (!(phydev->c45_ids.mmds_present & MDIO_DEVS_AN))
3397 return -EINVAL;
3405 return -EINVAL;
3408 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad,
3412 return mdiobus_read(pl->phydev->mdio.bus, phy_id, reg);
3418 struct phy_device *phydev = pl->phydev;
3424 return mdiobus_c45_write(pl->phydev->mdio.bus, prtad, devad,
3428 if (phydev->is_c45) {
3434 devad = __ffs(phydev->c45_ids.mmds_present);
3438 if (!(phydev->c45_ids.mmds_present & MDIO_DEVS_AN))
3439 return -EINVAL;
3447 return -EINVAL;
3449 return mdiobus_c45_write(pl->phydev->mdio.bus, phy_id, devad,
3453 return mdiobus_write(phydev->mdio.bus, phy_id, reg, val);
3462 switch (pl->act_link_an_mode) {
3471 return -EOPNOTSUPP;
3487 switch (pl->act_link_an_mode) {
3492 return -EOPNOTSUPP;
3502 * phylink_mii_ioctl() - generic mii ioctl interface
3526 if (pl->phydev) {
3530 mii->phy_id = pl->phydev->mdio.addr;
3534 ret = phylink_phy_read(pl, mii->phy_id, mii->reg_num);
3536 mii->val_out = ret;
3542 ret = phylink_phy_write(pl, mii->phy_id, mii->reg_num,
3543 mii->val_in);
3547 ret = phy_mii_ioctl(pl->phydev, ifr, cmd);
3553 mii->phy_id = 0;
3557 ret = phylink_mii_read(pl, mii->phy_id, mii->reg_num);
3559 mii->val_out = ret;
3565 ret = phylink_mii_write(pl, mii->phy_id, mii->reg_num,
3566 mii->val_in);
3570 ret = -EOPNOTSUPP;
3580 * phylink_speed_down() - set the non-SFP PHY to lowest speed supported by both
3581 * link partners
3597 if (!pl->sfp_bus && pl->phydev)
3598 ret = phy_speed_down(pl->phydev, sync);
3605 * phylink_speed_up() - restore the advertised speeds prior to the call to
3620 if (!pl->sfp_bus && pl->phydev)
3621 ret = phy_speed_up(pl->phydev);
3631 pl->netdev->sfp_bus = bus;
3638 pl->netdev->sfp_bus = NULL;
3663 phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n",
3664 phylink_an_mode_str(mode), phy_modes(state->interface),
3667 if (!linkmode_equal(pl->supported, supported)) {
3668 linkmode_copy(pl->supported, supported);
3672 if (!linkmode_equal(pl->link_config.advertising, state->advertising)) {
3673 linkmode_copy(pl->link_config.advertising, state->advertising);
3677 if (pl->req_link_an_mode != mode ||
3678 pl->link_config.interface != state->interface) {
3679 pl->req_link_an_mode = mode;
3680 pl->link_config.interface = state->interface;
3684 phylink_info(pl, "switched to %s/%s link mode\n",
3686 phy_modes(state->interface));
3690 &pl->phylink_disable_state))
3700 /* We're not using pl->sfp_interfaces, so clear it. */
3701 phy_interface_zero(pl->sfp_interfaces);
3702 linkmode_copy(support, phy->supported);
3705 linkmode_copy(config.advertising, phy->advertising);
3722 return -EINVAL;
3738 pl->link_port = pl->sfp_port;
3755 pl->config->supported_interfaces,
3757 pl->sfp_interfaces);
3762 phy_interface_and(pl->sfp_interfaces, pl->config->supported_interfaces,
3763 pl->sfp_interfaces);
3764 if (phy_interface_empty(pl->sfp_interfaces)) {
3766 return -EINVAL;
3770 linkmode_copy(support, pl->sfp_support);
3771 linkmode_copy(config.advertising, pl->sfp_support);
3777 * mask to only those link modes that can be supported.
3779 ret = phylink_validate_mask(pl, NULL, pl->sfp_support, &config,
3780 pl->sfp_interfaces);
3787 interface = phylink_choose_sfp_interface(pl, pl->sfp_interfaces);
3790 return -EINVAL;
3803 if (phy_interface_weight(pl->sfp_interfaces) == 1) {
3805 pl->sfp_support);
3816 return -EINVAL;
3830 pl->link_port = pl->sfp_port;
3832 phylink_sfp_set_config(pl, pl->sfp_support, &config, false);
3845 caps = sfp_get_module_caps(pl->sfp_bus);
3846 phy_interface_copy(pl->sfp_interfaces, caps->interfaces);
3847 linkmode_copy(pl->sfp_support, caps->link_modes);
3848 pl->sfp_may_have_phy = caps->may_have_phy;
3849 pl->sfp_port = caps->port;
3852 if (pl->sfp_may_have_phy)
3862 phy_interface_zero(pl->sfp_interfaces);
3870 if (pl->phydev) {
3871 phy_start(pl->phydev);
3878 if (!pl->sfp_may_have_phy)
3888 /* If this SFP module has a PHY, stop it. */
3889 if (pl->phydev)
3890 phy_stop(pl->phydev);
3915 if (!phy->drv) {
3917 phydev_name(phy), (unsigned long)phy->phy_id);
3919 return -EINVAL;
3932 phy_interface_and(phy->host_interfaces, phylink_sfp_interfaces,
3933 pl->config->supported_interfaces);
3966 /* 100GBASE-KP4 and 100GBASE-CR10 not supported */
3971 /* 5GBASE-KR not supported */
3982 if (linkmode_test_bit(bit, state->advertising) &&
3983 linkmode_test_bit(bit, state->lp_advertising))
3988 state->speed = phylink_c73_priority_resolution[i].speed;
3989 state->duplex = DUPLEX_FULL;
3992 state->link = false;
4009 mii_lpa_mod_linkmode_x(state->lp_advertising, config_reg, fd_bit);
4011 if (linkmode_test_bit(fd_bit, state->advertising) &&
4012 linkmode_test_bit(fd_bit, state->lp_advertising)) {
4013 state->speed = speed;
4014 state->duplex = DUPLEX_FULL;
4017 state->link = false;
4027 state->link = false;
4033 state->speed = SPEED_10;
4036 state->speed = SPEED_100;
4039 state->speed = SPEED_1000;
4042 state->link = false;
4046 state->duplex = DUPLEX_FULL;
4048 state->duplex = DUPLEX_HALF;
4052 * phylink_decode_usxgmii_word() - decode the USXGMII word from a MAC PCS
4054 * @lpa: a 16 bit value which stores the USXGMII auto-negotiation word
4056 * Helper for MAC PCS supporting the USXGMII protocol and the auto-negotiation
4065 state->speed = SPEED_10;
4068 state->speed = SPEED_100;
4071 state->speed = SPEED_1000;
4074 state->speed = SPEED_2500;
4077 state->speed = SPEED_5000;
4080 state->speed = SPEED_10000;
4083 state->link = false;
4088 state->duplex = DUPLEX_FULL;
4090 state->duplex = DUPLEX_HALF;
4095 * phylink_decode_usgmii_word() - decode the USGMII word from a MAC PCS
4097 * @lpa: a 16 bit value which stores the USGMII auto-negotiation word
4099 * Helper for MAC PCS supporting the USGMII protocol and the auto-negotiation
4110 state->speed = SPEED_10;
4113 state->speed = SPEED_100;
4116 state->speed = SPEED_1000;
4119 state->link = false;
4124 state->duplex = DUPLEX_FULL;
4126 state->duplex = DUPLEX_HALF;
4130 * phylink_mii_c22_pcs_decode_state() - Decode MAC PCS state from MII registers
4132 * @neg_mode: link negotiation mode (PHYLINK_PCS_NEG_xxx)
4139 * Parse the Clause 37 or Cisco SGMII link partner negotiation word into
4147 state->link = !!(bmsr & BMSR_LSTATUS);
4148 state->an_complete = !!(bmsr & BMSR_ANEGCOMPLETE);
4150 /* If the link is down, the advertisement data is undefined. */
4151 if (!state->link)
4154 switch (state->interface) {
4159 state->speed = SPEED_1000;
4160 state->duplex = DUPLEX_FULL;
4161 state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;
4169 state->speed = SPEED_2500;
4170 state->duplex = DUPLEX_FULL;
4171 state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX;
4187 state->link = false;
4194 * phylink_mii_c22_pcs_get_state() - read the MAC PCS state
4196 * @neg_mode: link negotiation mode (PHYLINK_PCS_NEG_xxx)
4203 * parse the Clause 37 or Cisco SGMII link partner negotiation word into
4217 state->link = false;
4226 * phylink_mii_c22_pcs_encode_advertisement() - configure the clause 37 PCS
4237 * Return: The new value for @adv, or ``-EINVAL`` if it should not be changed.
4260 return -EINVAL;
4266 * phylink_mii_c22_pcs_config() - configure clause 22 PCS
4288 ret = mdiobus_modify_changed(pcs->bus, pcs->addr,
4310 * phylink_mii_c22_pcs_an_restart() - restart 802.3z autonegotiation
4316 * Restart the clause 37 negotiation with the link partner. This is
4335 struct mii_bus *bus = pcs->bus;
4336 int addr = pcs->addr;
4341 state->link = false;
4345 state->link = !!(stat & MDIO_STAT1_LSTATUS);
4346 if (!state->link)
4349 switch (state->interface) {
4351 state->speed = SPEED_10000;
4352 state->duplex = DUPLEX_FULL;