Lines Matching full:pl
91 #define phylink_printk(level, pl, fmt, ...) \ argument
93 if ((pl)->config->type == PHYLINK_NETDEV) \
94 netdev_printk(level, (pl)->netdev, fmt, ##__VA_ARGS__); \
95 else if ((pl)->config->type == PHYLINK_DEV) \
96 dev_printk(level, (pl)->dev, fmt, ##__VA_ARGS__); \
99 #define phylink_err(pl, fmt, ...) \ argument
100 phylink_printk(KERN_ERR, pl, fmt, ##__VA_ARGS__)
101 #define phylink_warn(pl, fmt, ...) \ argument
102 phylink_printk(KERN_WARNING, pl, fmt, ##__VA_ARGS__)
103 #define phylink_info(pl, fmt, ...) \ argument
104 phylink_printk(KERN_INFO, pl, fmt, ##__VA_ARGS__)
106 #define phylink_dbg(pl, fmt, ...) \ argument
108 if ((pl)->config->type == PHYLINK_NETDEV) \
109 netdev_dbg((pl)->netdev, fmt, ##__VA_ARGS__); \
110 else if ((pl)->config->type == PHYLINK_DEV) \
111 dev_dbg((pl)->dev, fmt, ##__VA_ARGS__); \
114 #define phylink_dbg(pl, fmt, ...) \ argument
115 phylink_printk(KERN_DEBUG, pl, fmt, ##__VA_ARGS__)
117 #define phylink_dbg(pl, fmt, ...) \ argument
120 phylink_printk(KERN_DEBUG, pl, fmt, ##__VA_ARGS__); \
655 static int phylink_validate_mac_and_pcs(struct phylink *pl, in phylink_validate_mac_and_pcs() argument
664 if (pl->using_mac_select_pcs) { in phylink_validate_mac_and_pcs()
665 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); in phylink_validate_mac_and_pcs()
669 pcs = pl->pcs; in phylink_validate_mac_and_pcs()
678 phylink_err(pl, "interface %s: uninitialised PCS\n", in phylink_validate_mac_and_pcs()
699 if (pl->mac_ops->mac_get_caps) in phylink_validate_mac_and_pcs()
700 capabilities = pl->mac_ops->mac_get_caps(pl->config, in phylink_validate_mac_and_pcs()
703 capabilities = pl->config->mac_capabilities; in phylink_validate_mac_and_pcs()
710 static void phylink_validate_one(struct phylink *pl, struct phy_device *phy, in phylink_validate_one() argument
728 if (!phylink_validate_mac_and_pcs(pl, tmp_supported, &tmp_state)) { in phylink_validate_one()
729 phylink_dbg(pl, " interface %u (%s) rate match %s supports %*pbl\n", in phylink_validate_one()
740 static int phylink_validate_mask(struct phylink *pl, struct phy_device *phy, in phylink_validate_mask() argument
750 phylink_validate_one(pl, phy, supported, state, interface, in phylink_validate_mask()
759 static int phylink_validate(struct phylink *pl, unsigned long *supported, in phylink_validate() argument
762 const unsigned long *interfaces = pl->config->supported_interfaces; in phylink_validate()
765 return phylink_validate_mask(pl, NULL, supported, state, in phylink_validate()
771 return phylink_validate_mac_and_pcs(pl, supported, state); in phylink_validate()
774 static int phylink_parse_fixedlink(struct phylink *pl, in phylink_parse_fixedlink() argument
788 pl->link_config.speed = speed; in phylink_parse_fixedlink()
789 pl->link_config.duplex = DUPLEX_HALF; in phylink_parse_fixedlink()
792 pl->link_config.duplex = DUPLEX_FULL; in phylink_parse_fixedlink()
799 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
802 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
809 pl->link_gpio = desc; in phylink_parse_fixedlink()
823 phylink_err(pl, "broken fixed-link?\n"); in phylink_parse_fixedlink()
830 pl->link_config.duplex = prop[1] ? in phylink_parse_fixedlink()
832 pl->link_config.speed = prop[2]; in phylink_parse_fixedlink()
835 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
838 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
842 if (pl->link_config.speed > SPEED_1000 && in phylink_parse_fixedlink()
843 pl->link_config.duplex != DUPLEX_FULL) in phylink_parse_fixedlink()
844 phylink_warn(pl, "fixed link specifies half duplex for %dMbps link?\n", in phylink_parse_fixedlink()
845 pl->link_config.speed); in phylink_parse_fixedlink()
847 linkmode_fill(pl->supported); in phylink_parse_fixedlink()
848 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_parse_fixedlink()
849 phylink_validate(pl, pl->supported, &pl->link_config); in phylink_parse_fixedlink()
851 pause = phylink_test(pl->supported, Pause); in phylink_parse_fixedlink()
852 asym_pause = phylink_test(pl->supported, Asym_Pause); in phylink_parse_fixedlink()
853 autoneg = phylink_test(pl->supported, Autoneg); in phylink_parse_fixedlink()
854 s = phy_lookup_setting(pl->link_config.speed, pl->link_config.duplex, in phylink_parse_fixedlink()
855 pl->supported, true); in phylink_parse_fixedlink()
856 linkmode_zero(pl->supported); in phylink_parse_fixedlink()
857 phylink_set(pl->supported, MII); in phylink_parse_fixedlink()
860 phylink_set(pl->supported, Pause); in phylink_parse_fixedlink()
863 phylink_set(pl->supported, Asym_Pause); in phylink_parse_fixedlink()
866 phylink_set(pl->supported, Autoneg); in phylink_parse_fixedlink()
869 __set_bit(s->bit, pl->supported); in phylink_parse_fixedlink()
870 __set_bit(s->bit, pl->link_config.lp_advertising); in phylink_parse_fixedlink()
872 phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n", in phylink_parse_fixedlink()
873 pl->link_config.duplex == DUPLEX_FULL ? "full" : "half", in phylink_parse_fixedlink()
874 pl->link_config.speed); in phylink_parse_fixedlink()
877 linkmode_and(pl->link_config.advertising, pl->link_config.advertising, in phylink_parse_fixedlink()
878 pl->supported); in phylink_parse_fixedlink()
880 pl->link_config.link = 1; in phylink_parse_fixedlink()
881 pl->link_config.an_complete = 1; in phylink_parse_fixedlink()
886 static int phylink_parse_mode(struct phylink *pl, in phylink_parse_mode() argument
893 if (pl->config->default_an_inband) in phylink_parse_mode()
894 pl->cfg_link_an_mode = MLO_AN_INBAND; in phylink_parse_mode()
898 pl->cfg_link_an_mode = MLO_AN_FIXED; in phylink_parse_mode()
903 if (pl->cfg_link_an_mode == MLO_AN_FIXED) { in phylink_parse_mode()
904 phylink_err(pl, in phylink_parse_mode()
909 pl->cfg_link_an_mode = MLO_AN_INBAND; in phylink_parse_mode()
912 if (pl->cfg_link_an_mode == MLO_AN_INBAND) { in phylink_parse_mode()
913 linkmode_zero(pl->supported); in phylink_parse_mode()
914 phylink_set(pl->supported, MII); in phylink_parse_mode()
915 phylink_set(pl->supported, Autoneg); in phylink_parse_mode()
916 phylink_set(pl->supported, Asym_Pause); in phylink_parse_mode()
917 phylink_set(pl->supported, Pause); in phylink_parse_mode()
919 switch (pl->link_config.interface) { in phylink_parse_mode()
939 caps = phylink_get_capabilities(pl->link_config.interface, caps, in phylink_parse_mode()
941 phylink_caps_to_linkmodes(pl->supported, caps); in phylink_parse_mode()
945 phylink_err(pl, in phylink_parse_mode()
947 phy_modes(pl->link_config.interface)); in phylink_parse_mode()
951 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_parse_mode()
953 if (phylink_validate(pl, pl->supported, &pl->link_config)) { in phylink_parse_mode()
954 phylink_err(pl, in phylink_parse_mode()
963 static void phylink_apply_manual_flow(struct phylink *pl, in phylink_apply_manual_flow() argument
972 if (!(pl->link_config.pause & MLO_PAUSE_AN)) in phylink_apply_manual_flow()
973 state->pause = pl->link_config.pause; in phylink_apply_manual_flow()
1044 static void phylink_pcs_poll_stop(struct phylink *pl) in phylink_pcs_poll_stop() argument
1046 if (pl->cfg_link_an_mode == MLO_AN_INBAND) in phylink_pcs_poll_stop()
1047 del_timer(&pl->link_poll); in phylink_pcs_poll_stop()
1050 static void phylink_pcs_poll_start(struct phylink *pl) in phylink_pcs_poll_start() argument
1052 if (pl->pcs && pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND) in phylink_pcs_poll_start()
1053 mod_timer(&pl->link_poll, jiffies + HZ); in phylink_pcs_poll_start()
1056 int phylink_pcs_pre_init(struct phylink *pl, struct phylink_pcs *pcs) in phylink_pcs_pre_init() argument
1061 if (pl->config->mac_requires_rxc) in phylink_pcs_pre_init()
1071 static void phylink_mac_config(struct phylink *pl, in phylink_mac_config() argument
1083 phylink_dbg(pl, in phylink_mac_config()
1085 __func__, phylink_an_mode_str(pl->cur_link_an_mode), in phylink_mac_config()
1091 pl->mac_ops->mac_config(pl->config, pl->cur_link_an_mode, &st); in phylink_mac_config()
1094 static void phylink_pcs_an_restart(struct phylink *pl) in phylink_pcs_an_restart() argument
1096 if (pl->pcs && linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, in phylink_pcs_an_restart()
1097 pl->link_config.advertising) && in phylink_pcs_an_restart()
1098 phy_interface_mode_is_8023z(pl->link_config.interface) && in phylink_pcs_an_restart()
1099 phylink_autoneg_inband(pl->cur_link_an_mode)) in phylink_pcs_an_restart()
1100 pl->pcs->ops->pcs_an_restart(pl->pcs); in phylink_pcs_an_restart()
1170 static void phylink_major_config(struct phylink *pl, bool restart, in phylink_major_config() argument
1179 phylink_dbg(pl, "major config %s\n", phy_modes(state->interface)); in phylink_major_config()
1181 pl->pcs_neg_mode = phylink_pcs_neg_mode(pl->cur_link_an_mode, in phylink_major_config()
1185 if (pl->using_mac_select_pcs) { in phylink_major_config()
1186 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); in phylink_major_config()
1188 phylink_err(pl, in phylink_major_config()
1194 pcs_changed = pcs && pl->pcs != pcs; in phylink_major_config()
1197 phylink_pcs_poll_stop(pl); in phylink_major_config()
1199 if (pl->mac_ops->mac_prepare) { in phylink_major_config()
1200 err = pl->mac_ops->mac_prepare(pl->config, pl->cur_link_an_mode, in phylink_major_config()
1203 phylink_err(pl, "mac_prepare failed: %pe\n", in phylink_major_config()
1213 phylink_pcs_disable(pl->pcs); in phylink_major_config()
1215 if (pl->pcs) in phylink_major_config()
1216 pl->pcs->phylink = NULL; in phylink_major_config()
1218 pcs->phylink = pl; in phylink_major_config()
1220 pl->pcs = pcs; in phylink_major_config()
1223 if (pl->pcs) in phylink_major_config()
1224 phylink_pcs_pre_config(pl->pcs, state->interface); in phylink_major_config()
1226 phylink_mac_config(pl, state); in phylink_major_config()
1228 if (pl->pcs) in phylink_major_config()
1229 phylink_pcs_post_config(pl->pcs, state->interface); in phylink_major_config()
1231 if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed) in phylink_major_config()
1232 phylink_pcs_enable(pl->pcs); in phylink_major_config()
1234 neg_mode = pl->cur_link_an_mode; in phylink_major_config()
1235 if (pl->pcs && pl->pcs->neg_mode) in phylink_major_config()
1236 neg_mode = pl->pcs_neg_mode; in phylink_major_config()
1238 err = phylink_pcs_config(pl->pcs, neg_mode, state, in phylink_major_config()
1239 !!(pl->link_config.pause & MLO_PAUSE_AN)); in phylink_major_config()
1241 phylink_err(pl, "pcs_config failed: %pe\n", in phylink_major_config()
1247 phylink_pcs_an_restart(pl); in phylink_major_config()
1249 if (pl->mac_ops->mac_finish) { in phylink_major_config()
1250 err = pl->mac_ops->mac_finish(pl->config, pl->cur_link_an_mode, in phylink_major_config()
1253 phylink_err(pl, "mac_finish failed: %pe\n", in phylink_major_config()
1257 if (pl->sfp_bus) { in phylink_major_config()
1260 sfp_upstream_set_signal_rate(pl->sfp_bus, rate_kbd); in phylink_major_config()
1263 phylink_pcs_poll_start(pl); in phylink_major_config()
1272 static int phylink_change_inband_advert(struct phylink *pl) in phylink_change_inband_advert() argument
1277 if (test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) in phylink_change_inband_advert()
1280 phylink_dbg(pl, "%s: mode=%s/%s adv=%*pb pause=%02x\n", __func__, in phylink_change_inband_advert()
1281 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_change_inband_advert()
1282 phy_modes(pl->link_config.interface), in phylink_change_inband_advert()
1283 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->link_config.advertising, in phylink_change_inband_advert()
1284 pl->link_config.pause); in phylink_change_inband_advert()
1287 pl->pcs_neg_mode = phylink_pcs_neg_mode(pl->cur_link_an_mode, in phylink_change_inband_advert()
1288 pl->link_config.interface, in phylink_change_inband_advert()
1289 pl->link_config.advertising); in phylink_change_inband_advert()
1291 neg_mode = pl->cur_link_an_mode; in phylink_change_inband_advert()
1292 if (pl->pcs->neg_mode) in phylink_change_inband_advert()
1293 neg_mode = pl->pcs_neg_mode; in phylink_change_inband_advert()
1299 ret = phylink_pcs_config(pl->pcs, neg_mode, &pl->link_config, in phylink_change_inband_advert()
1300 !!(pl->link_config.pause & MLO_PAUSE_AN)); in phylink_change_inband_advert()
1305 phylink_pcs_an_restart(pl); in phylink_change_inband_advert()
1310 static void phylink_mac_pcs_get_state(struct phylink *pl, in phylink_mac_pcs_get_state() argument
1313 linkmode_copy(state->advertising, pl->link_config.advertising); in phylink_mac_pcs_get_state()
1315 state->interface = pl->link_config.interface; in phylink_mac_pcs_get_state()
1316 state->rate_matching = pl->link_config.rate_matching; in phylink_mac_pcs_get_state()
1323 state->speed = pl->link_config.speed; in phylink_mac_pcs_get_state()
1324 state->duplex = pl->link_config.duplex; in phylink_mac_pcs_get_state()
1325 state->pause = pl->link_config.pause; in phylink_mac_pcs_get_state()
1330 if (pl->pcs) in phylink_mac_pcs_get_state()
1331 pl->pcs->ops->pcs_get_state(pl->pcs, state); in phylink_mac_pcs_get_state()
1339 static void phylink_get_fixed_state(struct phylink *pl, in phylink_get_fixed_state() argument
1342 *state = pl->link_config; in phylink_get_fixed_state()
1343 if (pl->config->get_fixed_state) in phylink_get_fixed_state()
1344 pl->config->get_fixed_state(pl->config, state); in phylink_get_fixed_state()
1345 else if (pl->link_gpio) in phylink_get_fixed_state()
1346 state->link = !!gpiod_get_value_cansleep(pl->link_gpio); in phylink_get_fixed_state()
1352 static void phylink_mac_initial_config(struct phylink *pl, bool force_restart) in phylink_mac_initial_config() argument
1356 switch (pl->cur_link_an_mode) { in phylink_mac_initial_config()
1358 link_state = pl->phy_state; in phylink_mac_initial_config()
1362 phylink_get_fixed_state(pl, &link_state); in phylink_mac_initial_config()
1366 link_state = pl->link_config; in phylink_mac_initial_config()
1377 phylink_apply_manual_flow(pl, &link_state); in phylink_mac_initial_config()
1378 phylink_major_config(pl, force_restart, &link_state); in phylink_mac_initial_config()
1395 static void phylink_link_up(struct phylink *pl, in phylink_link_up() argument
1398 struct net_device *ndev = pl->netdev; in phylink_link_up()
1428 pl->cur_interface = link_state.interface; in phylink_link_up()
1430 neg_mode = pl->cur_link_an_mode; in phylink_link_up()
1431 if (pl->pcs && pl->pcs->neg_mode) in phylink_link_up()
1432 neg_mode = pl->pcs_neg_mode; in phylink_link_up()
1434 phylink_pcs_link_up(pl->pcs, neg_mode, pl->cur_interface, speed, in phylink_link_up()
1437 pl->mac_ops->mac_link_up(pl->config, pl->phydev, pl->cur_link_an_mode, in phylink_link_up()
1438 pl->cur_interface, speed, duplex, in phylink_link_up()
1444 phylink_info(pl, in phylink_link_up()
1451 static void phylink_link_down(struct phylink *pl) in phylink_link_down() argument
1453 struct net_device *ndev = pl->netdev; in phylink_link_down()
1457 pl->mac_ops->mac_link_down(pl->config, pl->cur_link_an_mode, in phylink_link_down()
1458 pl->cur_interface); in phylink_link_down()
1459 phylink_info(pl, "Link is Down\n"); in phylink_link_down()
1464 struct phylink *pl = container_of(w, struct phylink, resolve); in phylink_resolve() local
1466 struct net_device *ndev = pl->netdev; in phylink_resolve()
1471 mutex_lock(&pl->state_mutex); in phylink_resolve()
1472 if (pl->netdev) in phylink_resolve()
1475 cur_link_state = pl->old_link_state; in phylink_resolve()
1477 if (pl->phylink_disable_state) { in phylink_resolve()
1478 pl->link_failed = false; in phylink_resolve()
1480 } else if (pl->link_failed) { in phylink_resolve()
1484 switch (pl->cur_link_an_mode) { in phylink_resolve()
1486 link_state = pl->phy_state; in phylink_resolve()
1487 phylink_apply_manual_flow(pl, &link_state); in phylink_resolve()
1492 phylink_get_fixed_state(pl, &link_state); in phylink_resolve()
1497 phylink_mac_pcs_get_state(pl, &link_state); in phylink_resolve()
1508 phylink_mac_pcs_get_state(pl, in phylink_resolve()
1515 if (pl->phydev) in phylink_resolve()
1516 link_state.link &= pl->phy_state.link; in phylink_resolve()
1519 if (pl->phydev && pl->phy_state.link) { in phylink_resolve()
1525 pl->phy_state.interface) { in phylink_resolve()
1529 link_state.interface = pl->phy_state.interface; in phylink_resolve()
1534 if (pl->phy_state.rate_matching) { in phylink_resolve()
1536 pl->phy_state.rate_matching; in phylink_resolve()
1537 link_state.speed = pl->phy_state.speed; in phylink_resolve()
1539 pl->phy_state.duplex; in phylink_resolve()
1545 link_state.pause = pl->phy_state.pause; in phylink_resolve()
1548 phylink_apply_manual_flow(pl, &link_state); in phylink_resolve()
1554 if (link_state.interface != pl->link_config.interface) { in phylink_resolve()
1559 phylink_link_down(pl); in phylink_resolve()
1562 phylink_major_config(pl, false, &link_state); in phylink_resolve()
1563 pl->link_config.interface = link_state.interface; in phylink_resolve()
1568 pl->old_link_state = link_state.link; in phylink_resolve()
1570 phylink_link_down(pl); in phylink_resolve()
1572 phylink_link_up(pl, link_state); in phylink_resolve()
1575 pl->link_failed = false; in phylink_resolve()
1576 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_resolve()
1578 mutex_unlock(&pl->state_mutex); in phylink_resolve()
1581 static void phylink_run_resolve(struct phylink *pl) in phylink_run_resolve() argument
1583 if (!pl->phylink_disable_state) in phylink_run_resolve()
1584 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_run_resolve()
1587 static void phylink_run_resolve_and_disable(struct phylink *pl, int bit) in phylink_run_resolve_and_disable() argument
1589 unsigned long state = pl->phylink_disable_state; in phylink_run_resolve_and_disable()
1591 set_bit(bit, &pl->phylink_disable_state); in phylink_run_resolve_and_disable()
1593 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_run_resolve_and_disable()
1594 flush_work(&pl->resolve); in phylink_run_resolve_and_disable()
1598 static void phylink_enable_and_run_resolve(struct phylink *pl, int bit) in phylink_enable_and_run_resolve() argument
1600 clear_bit(bit, &pl->phylink_disable_state); in phylink_enable_and_run_resolve()
1601 phylink_run_resolve(pl); in phylink_enable_and_run_resolve()
1606 struct phylink *pl = container_of(t, struct phylink, link_poll); in phylink_fixed_poll() local
1610 phylink_run_resolve(pl); in phylink_fixed_poll()
1615 static int phylink_register_sfp(struct phylink *pl, in phylink_register_sfp() argument
1626 phylink_err(pl, "unable to attach SFP bus: %pe\n", bus); in phylink_register_sfp()
1630 pl->sfp_bus = bus; in phylink_register_sfp()
1632 ret = sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops); in phylink_register_sfp()
1640 * @pl: a pointer to a &struct phylink returned from phylink_create()
1648 int phylink_set_fixed_link(struct phylink *pl, in phylink_set_fixed_link() argument
1654 if (pl->cfg_link_an_mode != MLO_AN_PHY || !state || in phylink_set_fixed_link()
1655 !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) in phylink_set_fixed_link()
1659 pl->supported, true); in phylink_set_fixed_link()
1663 adv = pl->link_config.advertising; in phylink_set_fixed_link()
1668 pl->link_config.speed = state->speed; in phylink_set_fixed_link()
1669 pl->link_config.duplex = state->duplex; in phylink_set_fixed_link()
1670 pl->link_config.link = 1; in phylink_set_fixed_link()
1671 pl->link_config.an_complete = 1; in phylink_set_fixed_link()
1673 pl->cfg_link_an_mode = MLO_AN_FIXED; in phylink_set_fixed_link()
1674 pl->cur_link_an_mode = pl->cfg_link_an_mode; in phylink_set_fixed_link()
1702 struct phylink *pl; in phylink_create() local
1717 pl = kzalloc(sizeof(*pl), GFP_KERNEL); in phylink_create()
1718 if (!pl) in phylink_create()
1721 mutex_init(&pl->state_mutex); in phylink_create()
1722 INIT_WORK(&pl->resolve, phylink_resolve); in phylink_create()
1724 pl->config = config; in phylink_create()
1726 pl->netdev = to_net_dev(config->dev); in phylink_create()
1727 netif_carrier_off(pl->netdev); in phylink_create()
1729 pl->dev = config->dev; in phylink_create()
1731 kfree(pl); in phylink_create()
1735 pl->using_mac_select_pcs = using_mac_select_pcs; in phylink_create()
1736 pl->phy_state.interface = iface; in phylink_create()
1737 pl->link_interface = iface; in phylink_create()
1739 pl->link_port = PORT_BNC; in phylink_create()
1741 pl->link_port = PORT_MII; in phylink_create()
1742 pl->link_config.interface = iface; in phylink_create()
1743 pl->link_config.pause = MLO_PAUSE_AN; in phylink_create()
1744 pl->link_config.speed = SPEED_UNKNOWN; in phylink_create()
1745 pl->link_config.duplex = DUPLEX_UNKNOWN; in phylink_create()
1746 pl->pcs_state = PCS_STATE_DOWN; in phylink_create()
1747 pl->mac_ops = mac_ops; in phylink_create()
1748 __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state); in phylink_create()
1749 timer_setup(&pl->link_poll, phylink_fixed_poll, 0); in phylink_create()
1751 linkmode_fill(pl->supported); in phylink_create()
1752 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_create()
1753 phylink_validate(pl, pl->supported, &pl->link_config); in phylink_create()
1755 ret = phylink_parse_mode(pl, fwnode); in phylink_create()
1757 kfree(pl); in phylink_create()
1761 if (pl->cfg_link_an_mode == MLO_AN_FIXED) { in phylink_create()
1762 ret = phylink_parse_fixedlink(pl, fwnode); in phylink_create()
1764 kfree(pl); in phylink_create()
1769 pl->cur_link_an_mode = pl->cfg_link_an_mode; in phylink_create()
1771 ret = phylink_register_sfp(pl, fwnode); in phylink_create()
1773 kfree(pl); in phylink_create()
1777 return pl; in phylink_create()
1783 * @pl: a pointer to a &struct phylink returned from phylink_create()
1790 void phylink_destroy(struct phylink *pl) in phylink_destroy() argument
1792 sfp_bus_del_upstream(pl->sfp_bus); in phylink_destroy()
1793 if (pl->link_gpio) in phylink_destroy()
1794 gpiod_put(pl->link_gpio); in phylink_destroy()
1796 cancel_work_sync(&pl->resolve); in phylink_destroy()
1797 kfree(pl); in phylink_destroy()
1803 * @pl: a pointer to a &struct phylink returned from phylink_create()
1810 bool phylink_expects_phy(struct phylink *pl) in phylink_expects_phy() argument
1812 if (pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_expects_phy()
1813 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_expects_phy()
1814 phy_interface_mode_is_8023z(pl->link_config.interface))) in phylink_expects_phy()
1822 struct phylink *pl = phydev->phylink; in phylink_phy_change() local
1827 mutex_lock(&pl->state_mutex); in phylink_phy_change()
1828 pl->phy_state.speed = phydev->speed; in phylink_phy_change()
1829 pl->phy_state.duplex = phydev->duplex; in phylink_phy_change()
1830 pl->phy_state.rate_matching = phydev->rate_matching; in phylink_phy_change()
1831 pl->phy_state.pause = MLO_PAUSE_NONE; in phylink_phy_change()
1833 pl->phy_state.pause |= MLO_PAUSE_TX; in phylink_phy_change()
1835 pl->phy_state.pause |= MLO_PAUSE_RX; in phylink_phy_change()
1836 pl->phy_state.interface = phydev->interface; in phylink_phy_change()
1837 pl->phy_state.link = up; in phylink_phy_change()
1839 pl->link_failed = true; in phylink_phy_change()
1840 mutex_unlock(&pl->state_mutex); in phylink_phy_change()
1842 phylink_run_resolve(pl); in phylink_phy_change()
1844 phylink_dbg(pl, "phy link %s %s/%s/%s/%s/%s\n", up ? "up" : "down", in phylink_phy_change()
1849 phylink_pause_to_str(pl->phy_state.pause)); in phylink_phy_change()
1852 static int phylink_validate_phy(struct phylink *pl, struct phy_device *phy, in phylink_validate_phy() argument
1867 pl->config->supported_interfaces); in phylink_validate_phy()
1870 phylink_err(pl, "PHY has no common interfaces\n"); in phylink_validate_phy()
1882 phylink_err(pl, "SFP PHY's possible interfaces becomes empty\n"); in phylink_validate_phy()
1887 phylink_dbg(pl, "PHY %s uses interfaces %*pbl, validating %*pbl\n", in phylink_validate_phy()
1893 return phylink_validate_mask(pl, phy, supported, state, in phylink_validate_phy()
1897 phylink_dbg(pl, "PHY %s doesn't supply possible interfaces\n", in phylink_validate_phy()
1922 return phylink_validate(pl, supported, state); in phylink_validate_phy()
1925 static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, in phylink_bringup_phy() argument
1947 ret = phylink_validate_phy(pl, phy, supported, &config); in phylink_bringup_phy()
1949 phylink_warn(pl, "validation of %s with support %*pb and advertisement %*pb failed: %pe\n", in phylink_bringup_phy()
1957 phy->phylink = pl; in phylink_bringup_phy()
1961 phylink_info(pl, in phylink_bringup_phy()
1967 mutex_lock(&pl->state_mutex); in phylink_bringup_phy()
1968 pl->phydev = phy; in phylink_bringup_phy()
1969 pl->phy_state.interface = interface; in phylink_bringup_phy()
1970 pl->phy_state.pause = MLO_PAUSE_NONE; in phylink_bringup_phy()
1971 pl->phy_state.speed = SPEED_UNKNOWN; in phylink_bringup_phy()
1972 pl->phy_state.duplex = DUPLEX_UNKNOWN; in phylink_bringup_phy()
1973 pl->phy_state.rate_matching = RATE_MATCH_NONE; in phylink_bringup_phy()
1974 linkmode_copy(pl->supported, supported); in phylink_bringup_phy()
1975 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_bringup_phy()
1979 mutex_unlock(&pl->state_mutex); in phylink_bringup_phy()
1982 phylink_dbg(pl, in phylink_bringup_phy()
1985 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, in phylink_bringup_phy()
1991 if (pl->config->mac_managed_pm) in phylink_bringup_phy()
1997 static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy, in phylink_attach_phy() argument
2002 if (WARN_ON(pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_attach_phy()
2003 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_attach_phy()
2004 phy_interface_mode_is_8023z(interface) && !pl->sfp_bus))) in phylink_attach_phy()
2007 if (pl->phydev) in phylink_attach_phy()
2010 if (pl->config->mac_requires_rxc) in phylink_attach_phy()
2013 return phy_attach_direct(pl->netdev, phy, flags, interface); in phylink_attach_phy()
2018 * @pl: a pointer to a &struct phylink returned from phylink_create()
2021 * Connect @phy to the phylink instance specified by @pl by calling
2031 int phylink_connect_phy(struct phylink *pl, struct phy_device *phy) in phylink_connect_phy() argument
2036 if (pl->link_interface == PHY_INTERFACE_MODE_NA) { in phylink_connect_phy()
2037 pl->link_interface = phy->interface; in phylink_connect_phy()
2038 pl->link_config.interface = pl->link_interface; in phylink_connect_phy()
2041 ret = phylink_attach_phy(pl, phy, pl->link_interface); in phylink_connect_phy()
2045 ret = phylink_bringup_phy(pl, phy, pl->link_config.interface); in phylink_connect_phy()
2055 * @pl: a pointer to a &struct phylink returned from phylink_create()
2060 * specified by @pl. Actions specified in phylink_connect_phy() will be
2065 int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn, in phylink_of_phy_connect() argument
2068 return phylink_fwnode_phy_connect(pl, of_fwnode_handle(dn), flags); in phylink_of_phy_connect()
2074 * @pl: a pointer to a &struct phylink returned from phylink_create()
2079 * by @pl.
2083 int phylink_fwnode_phy_connect(struct phylink *pl, in phylink_fwnode_phy_connect() argument
2092 if (pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_fwnode_phy_connect()
2093 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_fwnode_phy_connect()
2094 phy_interface_mode_is_8023z(pl->link_interface))) in phylink_fwnode_phy_connect()
2099 if (pl->cfg_link_an_mode == MLO_AN_PHY) in phylink_fwnode_phy_connect()
2111 if (pl->link_interface == PHY_INTERFACE_MODE_NA) { in phylink_fwnode_phy_connect()
2112 pl->link_interface = phy_dev->interface; in phylink_fwnode_phy_connect()
2113 pl->link_config.interface = pl->link_interface; in phylink_fwnode_phy_connect()
2116 if (pl->config->mac_requires_rxc) in phylink_fwnode_phy_connect()
2119 ret = phy_attach_direct(pl->netdev, phy_dev, flags, in phylink_fwnode_phy_connect()
2120 pl->link_interface); in phylink_fwnode_phy_connect()
2125 ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface); in phylink_fwnode_phy_connect()
2136 * @pl: a pointer to a &struct phylink returned from phylink_create()
2138 * Disconnect any current PHY from the phylink instance described by @pl.
2140 void phylink_disconnect_phy(struct phylink *pl) in phylink_disconnect_phy() argument
2146 phy = pl->phydev; in phylink_disconnect_phy()
2149 mutex_lock(&pl->state_mutex); in phylink_disconnect_phy()
2150 pl->phydev = NULL; in phylink_disconnect_phy()
2151 mutex_unlock(&pl->state_mutex); in phylink_disconnect_phy()
2153 flush_work(&pl->resolve); in phylink_disconnect_phy()
2160 static void phylink_link_changed(struct phylink *pl, bool up, const char *what) in phylink_link_changed() argument
2163 pl->link_failed = true; in phylink_link_changed()
2164 phylink_run_resolve(pl); in phylink_link_changed()
2165 phylink_dbg(pl, "%s link %s\n", what, up ? "up" : "down"); in phylink_link_changed()
2170 * @pl: a pointer to a &struct phylink returned from phylink_create()
2176 void phylink_mac_change(struct phylink *pl, bool up) in phylink_mac_change() argument
2178 phylink_link_changed(pl, up, "mac"); in phylink_mac_change()
2195 struct phylink *pl = pcs->phylink; in phylink_pcs_change() local
2197 if (pl) in phylink_pcs_change()
2198 phylink_link_changed(pl, up, "pcs"); in phylink_pcs_change()
2204 struct phylink *pl = data; in phylink_link_handler() local
2206 phylink_run_resolve(pl); in phylink_link_handler()
2213 * @pl: a pointer to a &struct phylink returned from phylink_create()
2215 * Start the phylink instance specified by @pl, configuring the MAC for the
2219 void phylink_start(struct phylink *pl) in phylink_start() argument
2225 phylink_info(pl, "configuring for %s/%s link mode\n", in phylink_start()
2226 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_start()
2227 phy_modes(pl->link_config.interface)); in phylink_start()
2230 if (pl->netdev) in phylink_start()
2231 netif_carrier_off(pl->netdev); in phylink_start()
2233 pl->pcs_state = PCS_STATE_STARTING; in phylink_start()
2243 phylink_mac_initial_config(pl, true); in phylink_start()
2245 pl->pcs_state = PCS_STATE_STARTED; in phylink_start()
2247 phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED); in phylink_start()
2249 if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) { in phylink_start()
2250 int irq = gpiod_to_irq(pl->link_gpio); in phylink_start()
2256 "netdev link", pl)) in phylink_start()
2257 pl->link_irq = irq; in phylink_start()
2265 if (pl->cfg_link_an_mode == MLO_AN_FIXED) in phylink_start()
2266 poll |= pl->config->poll_fixed_state; in phylink_start()
2269 mod_timer(&pl->link_poll, jiffies + HZ); in phylink_start()
2270 if (pl->phydev) in phylink_start()
2271 phy_start(pl->phydev); in phylink_start()
2272 if (pl->sfp_bus) in phylink_start()
2273 sfp_upstream_start(pl->sfp_bus); in phylink_start()
2279 * @pl: a pointer to a &struct phylink returned from phylink_create()
2281 * Stop the phylink instance specified by @pl. This should be called from the
2289 void phylink_stop(struct phylink *pl) in phylink_stop() argument
2293 if (pl->sfp_bus) in phylink_stop()
2294 sfp_upstream_stop(pl->sfp_bus); in phylink_stop()
2295 if (pl->phydev) in phylink_stop()
2296 phy_stop(pl->phydev); in phylink_stop()
2297 del_timer_sync(&pl->link_poll); in phylink_stop()
2298 if (pl->link_irq) { in phylink_stop()
2299 free_irq(pl->link_irq, pl); in phylink_stop()
2300 pl->link_irq = 0; in phylink_stop()
2303 phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED); in phylink_stop()
2305 pl->pcs_state = PCS_STATE_DOWN; in phylink_stop()
2307 phylink_pcs_disable(pl->pcs); in phylink_stop()
2313 * @pl: a pointer to a &struct phylink returned from phylink_create()
2325 void phylink_suspend(struct phylink *pl, bool mac_wol) in phylink_suspend() argument
2329 if (mac_wol && (!pl->netdev || pl->netdev->ethtool->wol_enabled)) { in phylink_suspend()
2331 mutex_lock(&pl->state_mutex); in phylink_suspend()
2334 __set_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state); in phylink_suspend()
2340 if (pl->netdev) in phylink_suspend()
2341 netif_carrier_off(pl->netdev); in phylink_suspend()
2343 pl->old_link_state = false; in phylink_suspend()
2348 mutex_unlock(&pl->state_mutex); in phylink_suspend()
2350 phylink_stop(pl); in phylink_suspend()
2357 * @pl: a pointer to a &struct phylink returned from phylink_create()
2362 void phylink_resume(struct phylink *pl) in phylink_resume() argument
2366 if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) { in phylink_resume()
2375 mutex_lock(&pl->state_mutex); in phylink_resume()
2376 phylink_link_down(pl); in phylink_resume()
2377 mutex_unlock(&pl->state_mutex); in phylink_resume()
2382 phylink_mac_initial_config(pl, true); in phylink_resume()
2385 phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_MAC_WOL); in phylink_resume()
2387 phylink_start(pl); in phylink_resume()
2394 * @pl: a pointer to a &struct phylink returned from phylink_create()
2398 * instance specified by @pl. If no PHY is currently attached, report no
2401 void phylink_ethtool_get_wol(struct phylink *pl, struct ethtool_wolinfo *wol) in phylink_ethtool_get_wol() argument
2408 if (pl->phydev) in phylink_ethtool_get_wol()
2409 phy_ethtool_get_wol(pl->phydev, wol); in phylink_ethtool_get_wol()
2415 * @pl: a pointer to a &struct phylink returned from phylink_create()
2419 * instance specified by @pl. If no PHY is attached, returns %EOPNOTSUPP
2424 int phylink_ethtool_set_wol(struct phylink *pl, struct ethtool_wolinfo *wol) in phylink_ethtool_set_wol() argument
2430 if (pl->phydev) in phylink_ethtool_set_wol()
2431 ret = phy_ethtool_set_wol(pl->phydev, wol); in phylink_ethtool_set_wol()
2464 * @pl: a pointer to a &struct phylink returned from phylink_create()
2467 * Read the current link settings for the phylink instance specified by @pl.
2471 int phylink_ethtool_ksettings_get(struct phylink *pl, in phylink_ethtool_ksettings_get() argument
2478 if (pl->phydev) in phylink_ethtool_ksettings_get()
2479 phy_ethtool_ksettings_get(pl->phydev, kset); in phylink_ethtool_ksettings_get()
2481 kset->base.port = pl->link_port; in phylink_ethtool_ksettings_get()
2483 linkmode_copy(kset->link_modes.supported, pl->supported); in phylink_ethtool_ksettings_get()
2485 switch (pl->cur_link_an_mode) { in phylink_ethtool_ksettings_get()
2491 phylink_get_fixed_state(pl, &link_state); in phylink_ethtool_ksettings_get()
2499 if (pl->phydev) in phylink_ethtool_ksettings_get()
2502 phylink_mac_pcs_get_state(pl, &link_state); in phylink_ethtool_ksettings_get()
2518 * @pl: a pointer to a &struct phylink returned from phylink_create()
2521 int phylink_ethtool_ksettings_set(struct phylink *pl, in phylink_ethtool_ksettings_set() argument
2530 if (pl->phydev) { in phylink_ethtool_ksettings_set()
2535 pl->supported); in phylink_ethtool_ksettings_set()
2538 * to update the pl->link_config settings: in phylink_ethtool_ksettings_set()
2555 return phy_ethtool_ksettings_set(pl->phydev, &phy_kset); in phylink_ethtool_ksettings_set()
2558 config = pl->link_config; in phylink_ethtool_ksettings_set()
2561 pl->supported); in phylink_ethtool_ksettings_set()
2570 pl->supported, false); in phylink_ethtool_ksettings_set()
2577 if (pl->cur_link_an_mode == MLO_AN_FIXED) { in phylink_ethtool_ksettings_set()
2578 if (s->speed != pl->link_config.speed || in phylink_ethtool_ksettings_set()
2579 s->duplex != pl->link_config.duplex) in phylink_ethtool_ksettings_set()
2593 if (pl->cur_link_an_mode == MLO_AN_FIXED) { in phylink_ethtool_ksettings_set()
2595 pl->link_config.advertising)) in phylink_ethtool_ksettings_set()
2618 if (pl->sfp_bus) { in phylink_ethtool_ksettings_set()
2619 config.interface = sfp_select_interface(pl->sfp_bus, in phylink_ethtool_ksettings_set()
2622 phylink_err(pl, in phylink_ethtool_ksettings_set()
2630 linkmode_copy(support, pl->supported); in phylink_ethtool_ksettings_set()
2631 if (phylink_validate(pl, support, &config)) { in phylink_ethtool_ksettings_set()
2632 phylink_err(pl, "validation of %s/%s with support %*pb failed\n", in phylink_ethtool_ksettings_set()
2633 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_ethtool_ksettings_set()
2640 linkmode_copy(support, pl->supported); in phylink_ethtool_ksettings_set()
2641 if (phylink_validate(pl, support, &config)) in phylink_ethtool_ksettings_set()
2651 mutex_lock(&pl->state_mutex); in phylink_ethtool_ksettings_set()
2652 pl->link_config.speed = config.speed; in phylink_ethtool_ksettings_set()
2653 pl->link_config.duplex = config.duplex; in phylink_ethtool_ksettings_set()
2655 if (pl->link_config.interface != config.interface) { in phylink_ethtool_ksettings_set()
2658 if (pl->old_link_state) { in phylink_ethtool_ksettings_set()
2659 phylink_link_down(pl); in phylink_ethtool_ksettings_set()
2660 pl->old_link_state = false; in phylink_ethtool_ksettings_set()
2663 &pl->phylink_disable_state)) in phylink_ethtool_ksettings_set()
2664 phylink_major_config(pl, false, &config); in phylink_ethtool_ksettings_set()
2665 pl->link_config.interface = config.interface; in phylink_ethtool_ksettings_set()
2666 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_ethtool_ksettings_set()
2667 } else if (!linkmode_equal(pl->link_config.advertising, in phylink_ethtool_ksettings_set()
2669 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_ethtool_ksettings_set()
2670 phylink_change_inband_advert(pl); in phylink_ethtool_ksettings_set()
2672 mutex_unlock(&pl->state_mutex); in phylink_ethtool_ksettings_set()
2680 * @pl: a pointer to a &struct phylink returned from phylink_create()
2682 * Restart negotiation for the phylink instance specified by @pl. This will
2689 int phylink_ethtool_nway_reset(struct phylink *pl) in phylink_ethtool_nway_reset() argument
2695 if (pl->phydev) in phylink_ethtool_nway_reset()
2696 ret = phy_restart_aneg(pl->phydev); in phylink_ethtool_nway_reset()
2697 phylink_pcs_an_restart(pl); in phylink_ethtool_nway_reset()
2705 * @pl: a pointer to a &struct phylink returned from phylink_create()
2708 void phylink_ethtool_get_pauseparam(struct phylink *pl, in phylink_ethtool_get_pauseparam() argument
2713 pause->autoneg = !!(pl->link_config.pause & MLO_PAUSE_AN); in phylink_ethtool_get_pauseparam()
2714 pause->rx_pause = !!(pl->link_config.pause & MLO_PAUSE_RX); in phylink_ethtool_get_pauseparam()
2715 pause->tx_pause = !!(pl->link_config.pause & MLO_PAUSE_TX); in phylink_ethtool_get_pauseparam()
2721 * @pl: a pointer to a &struct phylink returned from phylink_create()
2724 int phylink_ethtool_set_pauseparam(struct phylink *pl, in phylink_ethtool_set_pauseparam() argument
2727 struct phylink_link_state *config = &pl->link_config; in phylink_ethtool_set_pauseparam()
2733 if (pl->cur_link_an_mode == MLO_AN_FIXED) in phylink_ethtool_set_pauseparam()
2736 if (!phylink_test(pl->supported, Pause) && in phylink_ethtool_set_pauseparam()
2737 !phylink_test(pl->supported, Asym_Pause)) in phylink_ethtool_set_pauseparam()
2740 if (!phylink_test(pl->supported, Asym_Pause) && in phylink_ethtool_set_pauseparam()
2752 mutex_lock(&pl->state_mutex); in phylink_ethtool_set_pauseparam()
2778 if (!pl->phydev) in phylink_ethtool_set_pauseparam()
2779 phylink_change_inband_advert(pl); in phylink_ethtool_set_pauseparam()
2781 mutex_unlock(&pl->state_mutex); in phylink_ethtool_set_pauseparam()
2788 if (pl->phydev) in phylink_ethtool_set_pauseparam()
2789 phy_set_asym_pause(pl->phydev, pause->rx_pause, in phylink_ethtool_set_pauseparam()
2797 pl->link_failed = true; in phylink_ethtool_set_pauseparam()
2798 phylink_run_resolve(pl); in phylink_ethtool_set_pauseparam()
2808 * @pl: a pointer to a &struct phylink returned from phylink_create().
2811 * with the phylink instance specified by @pl.
2815 int phylink_get_eee_err(struct phylink *pl) in phylink_get_eee_err() argument
2821 if (pl->phydev) in phylink_get_eee_err()
2822 ret = phy_get_eee_err(pl->phydev); in phylink_get_eee_err()
2830 * @pl: a pointer to a &struct phylink returned from phylink_create()
2835 int phylink_init_eee(struct phylink *pl, bool clk_stop_enable) in phylink_init_eee() argument
2839 if (pl->phydev) in phylink_init_eee()
2840 ret = phy_init_eee(pl->phydev, clk_stop_enable); in phylink_init_eee()
2848 * @pl: a pointer to a &struct phylink returned from phylink_create()
2851 int phylink_ethtool_get_eee(struct phylink *pl, struct ethtool_keee *eee) in phylink_ethtool_get_eee() argument
2857 if (pl->phydev) in phylink_ethtool_get_eee()
2858 ret = phy_ethtool_get_eee(pl->phydev, eee); in phylink_ethtool_get_eee()
2866 * @pl: a pointer to a &struct phylink returned from phylink_create()
2869 int phylink_ethtool_set_eee(struct phylink *pl, struct ethtool_keee *eee) in phylink_ethtool_set_eee() argument
2875 if (pl->phydev) in phylink_ethtool_set_eee()
2876 ret = phy_ethtool_set_eee(pl->phydev, eee); in phylink_ethtool_set_eee()
2908 static int phylink_phy_read(struct phylink *pl, unsigned int phy_id, in phylink_phy_read() argument
2911 struct phy_device *phydev = pl->phydev; in phylink_phy_read()
2917 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_read()
2943 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_read()
2947 return mdiobus_read(pl->phydev->mdio.bus, phy_id, reg); in phylink_phy_read()
2950 static int phylink_phy_write(struct phylink *pl, unsigned int phy_id, in phylink_phy_write() argument
2953 struct phy_device *phydev = pl->phydev; in phylink_phy_write()
2959 return mdiobus_c45_write(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_write()
2984 return mdiobus_c45_write(pl->phydev->mdio.bus, phy_id, devad, in phylink_phy_write()
2991 static int phylink_mii_read(struct phylink *pl, unsigned int phy_id, in phylink_mii_read() argument
2997 switch (pl->cur_link_an_mode) { in phylink_mii_read()
3000 phylink_get_fixed_state(pl, &state); in phylink_mii_read()
3010 phylink_mac_pcs_get_state(pl, &state); in phylink_mii_read()
3019 static int phylink_mii_write(struct phylink *pl, unsigned int phy_id, in phylink_mii_write() argument
3022 switch (pl->cur_link_an_mode) { in phylink_mii_write()
3038 * @pl: a pointer to a &struct phylink returned from phylink_create()
3043 * specified by @pl. If no PHY is attached, emulate the presence of the PHY.
3054 int phylink_mii_ioctl(struct phylink *pl, struct ifreq *ifr, int cmd) in phylink_mii_ioctl() argument
3061 if (pl->phydev) { in phylink_mii_ioctl()
3065 mii->phy_id = pl->phydev->mdio.addr; in phylink_mii_ioctl()
3069 ret = phylink_phy_read(pl, mii->phy_id, mii->reg_num); in phylink_mii_ioctl()
3077 ret = phylink_phy_write(pl, mii->phy_id, mii->reg_num, in phylink_mii_ioctl()
3082 ret = phy_mii_ioctl(pl->phydev, ifr, cmd); in phylink_mii_ioctl()
3092 ret = phylink_mii_read(pl, mii->phy_id, mii->reg_num); in phylink_mii_ioctl()
3100 ret = phylink_mii_write(pl, mii->phy_id, mii->reg_num, in phylink_mii_ioctl()
3117 * @pl: a pointer to a &struct phylink returned from phylink_create()
3126 int phylink_speed_down(struct phylink *pl, bool sync) in phylink_speed_down() argument
3132 if (!pl->sfp_bus && pl->phydev) in phylink_speed_down()
3133 ret = phy_speed_down(pl->phydev, sync); in phylink_speed_down()
3142 * @pl: a pointer to a &struct phylink returned from phylink_create()
3149 int phylink_speed_up(struct phylink *pl) in phylink_speed_up() argument
3155 if (!pl->sfp_bus && pl->phydev) in phylink_speed_up()
3156 ret = phy_speed_up(pl->phydev); in phylink_speed_up()
3164 struct phylink *pl = upstream; in phylink_sfp_attach() local
3166 pl->netdev->sfp_bus = bus; in phylink_sfp_attach()
3171 struct phylink *pl = upstream; in phylink_sfp_detach() local
3173 pl->netdev->sfp_bus = NULL; in phylink_sfp_detach()
3176 static phy_interface_t phylink_choose_sfp_interface(struct phylink *pl, in phylink_choose_sfp_interface() argument
3192 static void phylink_sfp_set_config(struct phylink *pl, u8 mode, in phylink_sfp_set_config() argument
3198 phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n", in phylink_sfp_set_config()
3202 if (!linkmode_equal(pl->supported, supported)) { in phylink_sfp_set_config()
3203 linkmode_copy(pl->supported, supported); in phylink_sfp_set_config()
3207 if (!linkmode_equal(pl->link_config.advertising, state->advertising)) { in phylink_sfp_set_config()
3208 linkmode_copy(pl->link_config.advertising, state->advertising); in phylink_sfp_set_config()
3212 if (pl->cur_link_an_mode != mode || in phylink_sfp_set_config()
3213 pl->link_config.interface != state->interface) { in phylink_sfp_set_config()
3214 pl->cur_link_an_mode = mode; in phylink_sfp_set_config()
3215 pl->link_config.interface = state->interface; in phylink_sfp_set_config()
3219 phylink_info(pl, "switched to %s/%s link mode\n", in phylink_sfp_set_config()
3225 &pl->phylink_disable_state)) in phylink_sfp_set_config()
3226 phylink_mac_initial_config(pl, false); in phylink_sfp_set_config()
3229 static int phylink_sfp_config_phy(struct phylink *pl, u8 mode, in phylink_sfp_config_phy() argument
3248 ret = phylink_validate(pl, support, &config); in phylink_sfp_config_phy()
3250 phylink_err(pl, "validation with support %*pb failed: %pe\n", in phylink_sfp_config_phy()
3256 iface = sfp_select_interface(pl->sfp_bus, config.advertising); in phylink_sfp_config_phy()
3258 phylink_err(pl, in phylink_sfp_config_phy()
3266 ret = phylink_validate(pl, support1, &config); in phylink_sfp_config_phy()
3268 phylink_err(pl, in phylink_sfp_config_phy()
3277 pl->link_port = pl->sfp_port; in phylink_sfp_config_phy()
3279 phylink_sfp_set_config(pl, mode, support, &config); in phylink_sfp_config_phy()
3284 static int phylink_sfp_config_optical(struct phylink *pl) in phylink_sfp_config_optical() argument
3292 phylink_dbg(pl, "optical SFP: interfaces=[mac=%*pbl, sfp=%*pbl]\n", in phylink_sfp_config_optical()
3294 pl->config->supported_interfaces, in phylink_sfp_config_optical()
3296 pl->sfp_interfaces); in phylink_sfp_config_optical()
3301 phy_interface_and(interfaces, pl->config->supported_interfaces, in phylink_sfp_config_optical()
3302 pl->sfp_interfaces); in phylink_sfp_config_optical()
3304 phylink_err(pl, "unsupported SFP module: no common interface modes\n"); in phylink_sfp_config_optical()
3309 linkmode_copy(support, pl->sfp_support); in phylink_sfp_config_optical()
3310 linkmode_copy(config.advertising, pl->sfp_support); in phylink_sfp_config_optical()
3318 ret = phylink_validate_mask(pl, NULL, pl->sfp_support, &config, in phylink_sfp_config_optical()
3321 phylink_err(pl, "unsupported SFP module: validation with support %*pb failed\n", in phylink_sfp_config_optical()
3326 interface = phylink_choose_sfp_interface(pl, interfaces); in phylink_sfp_config_optical()
3328 phylink_err(pl, "failed to select SFP interface\n"); in phylink_sfp_config_optical()
3332 phylink_dbg(pl, "optical SFP: chosen %s interface\n", in phylink_sfp_config_optical()
3338 ret = phylink_validate(pl, support, &config); in phylink_sfp_config_optical()
3340 phylink_err(pl, "validation with support %*pb failed: %pe\n", in phylink_sfp_config_optical()
3346 pl->link_port = pl->sfp_port; in phylink_sfp_config_optical()
3348 phylink_sfp_set_config(pl, MLO_AN_INBAND, pl->sfp_support, &config); in phylink_sfp_config_optical()
3356 struct phylink *pl = upstream; in phylink_sfp_module_insert() local
3360 linkmode_zero(pl->sfp_support); in phylink_sfp_module_insert()
3361 phy_interface_zero(pl->sfp_interfaces); in phylink_sfp_module_insert()
3362 sfp_parse_support(pl->sfp_bus, id, pl->sfp_support, pl->sfp_interfaces); in phylink_sfp_module_insert()
3363 pl->sfp_port = sfp_parse_port(pl->sfp_bus, id, pl->sfp_support); in phylink_sfp_module_insert()
3366 pl->sfp_may_have_phy = sfp_may_have_phy(pl->sfp_bus, id); in phylink_sfp_module_insert()
3367 if (pl->sfp_may_have_phy) in phylink_sfp_module_insert()
3370 return phylink_sfp_config_optical(pl); in phylink_sfp_module_insert()
3375 struct phylink *pl = upstream; in phylink_sfp_module_start() local
3378 if (pl->phydev) { in phylink_sfp_module_start()
3379 phy_start(pl->phydev); in phylink_sfp_module_start()
3386 if (!pl->sfp_may_have_phy) in phylink_sfp_module_start()
3389 return phylink_sfp_config_optical(pl); in phylink_sfp_module_start()
3394 struct phylink *pl = upstream; in phylink_sfp_module_stop() local
3397 if (pl->phydev) in phylink_sfp_module_stop()
3398 phy_stop(pl->phydev); in phylink_sfp_module_stop()
3403 struct phylink *pl = upstream; in phylink_sfp_link_down() local
3407 phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK); in phylink_sfp_link_down()
3412 struct phylink *pl = upstream; in phylink_sfp_link_up() local
3416 phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_LINK); in phylink_sfp_link_up()
3430 struct phylink *pl = upstream; in phylink_sfp_connect_phy() local
3451 pl->config->supported_interfaces); in phylink_sfp_connect_phy()
3454 ret = phylink_sfp_config_phy(pl, mode, phy); in phylink_sfp_connect_phy()
3458 interface = pl->link_config.interface; in phylink_sfp_connect_phy()
3459 ret = phylink_attach_phy(pl, phy, interface); in phylink_sfp_connect_phy()
3463 ret = phylink_bringup_phy(pl, phy, interface); in phylink_sfp_connect_phy()