Lines Matching refs:pl
85 #define phylink_printk(level, pl, fmt, ...) \ argument
87 if ((pl)->config->type == PHYLINK_NETDEV) \
88 netdev_printk(level, (pl)->netdev, fmt, ##__VA_ARGS__); \
89 else if ((pl)->config->type == PHYLINK_DEV) \
90 dev_printk(level, (pl)->dev, fmt, ##__VA_ARGS__); \
93 #define phylink_err(pl, fmt, ...) \ argument
94 phylink_printk(KERN_ERR, pl, fmt, ##__VA_ARGS__)
95 #define phylink_warn(pl, fmt, ...) \ argument
96 phylink_printk(KERN_WARNING, pl, fmt, ##__VA_ARGS__)
97 #define phylink_info(pl, fmt, ...) \ argument
98 phylink_printk(KERN_INFO, pl, fmt, ##__VA_ARGS__)
100 #define phylink_dbg(pl, fmt, ...) \ argument
102 if ((pl)->config->type == PHYLINK_NETDEV) \
103 netdev_dbg((pl)->netdev, fmt, ##__VA_ARGS__); \
104 else if ((pl)->config->type == PHYLINK_DEV) \
105 dev_dbg((pl)->dev, fmt, ##__VA_ARGS__); \
108 #define phylink_dbg(pl, fmt, ...) \ argument
109 phylink_printk(KERN_DEBUG, pl, fmt, ##__VA_ARGS__)
111 #define phylink_dbg(pl, fmt, ...) \ argument
114 phylink_printk(KERN_DEBUG, pl, fmt, ##__VA_ARGS__); \
593 static int phylink_validate_mac_and_pcs(struct phylink *pl, in phylink_validate_mac_and_pcs() argument
601 if (pl->using_mac_select_pcs) { in phylink_validate_mac_and_pcs()
602 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); in phylink_validate_mac_and_pcs()
606 pcs = pl->pcs; in phylink_validate_mac_and_pcs()
615 phylink_err(pl, "interface %s: uninitialised PCS\n", in phylink_validate_mac_and_pcs()
636 pl->mac_ops->validate(pl->config, supported, state); in phylink_validate_mac_and_pcs()
641 static int phylink_validate_mask(struct phylink *pl, unsigned long *supported, in phylink_validate_mask() argument
657 if (!phylink_validate_mac_and_pcs(pl, s, &t)) { in phylink_validate_mask()
670 static int phylink_validate(struct phylink *pl, unsigned long *supported, in phylink_validate() argument
673 const unsigned long *interfaces = pl->config->supported_interfaces; in phylink_validate()
677 return phylink_validate_mask(pl, supported, state, in phylink_validate()
684 return phylink_validate_mac_and_pcs(pl, supported, state); in phylink_validate()
687 static int phylink_parse_fixedlink(struct phylink *pl, in phylink_parse_fixedlink() argument
700 pl->link_config.speed = speed; in phylink_parse_fixedlink()
701 pl->link_config.duplex = DUPLEX_HALF; in phylink_parse_fixedlink()
704 pl->link_config.duplex = DUPLEX_FULL; in phylink_parse_fixedlink()
711 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
714 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
721 pl->link_gpio = desc; in phylink_parse_fixedlink()
735 phylink_err(pl, "broken fixed-link?\n"); in phylink_parse_fixedlink()
742 pl->link_config.duplex = prop[1] ? in phylink_parse_fixedlink()
744 pl->link_config.speed = prop[2]; in phylink_parse_fixedlink()
747 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
750 pl->link_config.lp_advertising); in phylink_parse_fixedlink()
754 if (pl->link_config.speed > SPEED_1000 && in phylink_parse_fixedlink()
755 pl->link_config.duplex != DUPLEX_FULL) in phylink_parse_fixedlink()
756 phylink_warn(pl, "fixed link specifies half duplex for %dMbps link?\n", in phylink_parse_fixedlink()
757 pl->link_config.speed); in phylink_parse_fixedlink()
759 bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS); in phylink_parse_fixedlink()
760 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_parse_fixedlink()
761 phylink_validate(pl, pl->supported, &pl->link_config); in phylink_parse_fixedlink()
763 s = phy_lookup_setting(pl->link_config.speed, pl->link_config.duplex, in phylink_parse_fixedlink()
764 pl->supported, true); in phylink_parse_fixedlink()
765 linkmode_zero(pl->supported); in phylink_parse_fixedlink()
766 phylink_set(pl->supported, MII); in phylink_parse_fixedlink()
767 phylink_set(pl->supported, Pause); in phylink_parse_fixedlink()
768 phylink_set(pl->supported, Asym_Pause); in phylink_parse_fixedlink()
769 phylink_set(pl->supported, Autoneg); in phylink_parse_fixedlink()
771 __set_bit(s->bit, pl->supported); in phylink_parse_fixedlink()
772 __set_bit(s->bit, pl->link_config.lp_advertising); in phylink_parse_fixedlink()
774 phylink_warn(pl, "fixed link %s duplex %dMbps not recognised\n", in phylink_parse_fixedlink()
775 pl->link_config.duplex == DUPLEX_FULL ? "full" : "half", in phylink_parse_fixedlink()
776 pl->link_config.speed); in phylink_parse_fixedlink()
779 linkmode_and(pl->link_config.advertising, pl->link_config.advertising, in phylink_parse_fixedlink()
780 pl->supported); in phylink_parse_fixedlink()
782 pl->link_config.link = 1; in phylink_parse_fixedlink()
783 pl->link_config.an_complete = 1; in phylink_parse_fixedlink()
788 static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) in phylink_parse_mode() argument
795 pl->cfg_link_an_mode = MLO_AN_FIXED; in phylink_parse_mode()
800 pl->config->ovr_an_inband) { in phylink_parse_mode()
801 if (pl->cfg_link_an_mode == MLO_AN_FIXED) { in phylink_parse_mode()
802 phylink_err(pl, in phylink_parse_mode()
807 linkmode_zero(pl->supported); in phylink_parse_mode()
808 phylink_set(pl->supported, MII); in phylink_parse_mode()
809 phylink_set(pl->supported, Autoneg); in phylink_parse_mode()
810 phylink_set(pl->supported, Asym_Pause); in phylink_parse_mode()
811 phylink_set(pl->supported, Pause); in phylink_parse_mode()
812 pl->link_config.an_enabled = true; in phylink_parse_mode()
813 pl->cfg_link_an_mode = MLO_AN_INBAND; in phylink_parse_mode()
815 switch (pl->link_config.interface) { in phylink_parse_mode()
824 phylink_set(pl->supported, 10baseT_Half); in phylink_parse_mode()
825 phylink_set(pl->supported, 10baseT_Full); in phylink_parse_mode()
826 phylink_set(pl->supported, 100baseT_Half); in phylink_parse_mode()
827 phylink_set(pl->supported, 100baseT_Full); in phylink_parse_mode()
828 phylink_set(pl->supported, 1000baseT_Half); in phylink_parse_mode()
829 phylink_set(pl->supported, 1000baseT_Full); in phylink_parse_mode()
833 phylink_set(pl->supported, 1000baseX_Full); in phylink_parse_mode()
837 phylink_set(pl->supported, 2500baseX_Full); in phylink_parse_mode()
841 phylink_set(pl->supported, 5000baseT_Full); in phylink_parse_mode()
845 phylink_set(pl->supported, 25000baseCR_Full); in phylink_parse_mode()
846 phylink_set(pl->supported, 25000baseKR_Full); in phylink_parse_mode()
847 phylink_set(pl->supported, 25000baseSR_Full); in phylink_parse_mode()
852 phylink_set(pl->supported, 10baseT_Half); in phylink_parse_mode()
853 phylink_set(pl->supported, 10baseT_Full); in phylink_parse_mode()
854 phylink_set(pl->supported, 100baseT_Half); in phylink_parse_mode()
855 phylink_set(pl->supported, 100baseT_Full); in phylink_parse_mode()
856 phylink_set(pl->supported, 1000baseT_Half); in phylink_parse_mode()
857 phylink_set(pl->supported, 1000baseT_Full); in phylink_parse_mode()
858 phylink_set(pl->supported, 1000baseX_Full); in phylink_parse_mode()
859 phylink_set(pl->supported, 1000baseKX_Full); in phylink_parse_mode()
860 phylink_set(pl->supported, 2500baseT_Full); in phylink_parse_mode()
861 phylink_set(pl->supported, 2500baseX_Full); in phylink_parse_mode()
862 phylink_set(pl->supported, 5000baseT_Full); in phylink_parse_mode()
863 phylink_set(pl->supported, 10000baseT_Full); in phylink_parse_mode()
864 phylink_set(pl->supported, 10000baseKR_Full); in phylink_parse_mode()
865 phylink_set(pl->supported, 10000baseKX4_Full); in phylink_parse_mode()
866 phylink_set(pl->supported, 10000baseCR_Full); in phylink_parse_mode()
867 phylink_set(pl->supported, 10000baseSR_Full); in phylink_parse_mode()
868 phylink_set(pl->supported, 10000baseLR_Full); in phylink_parse_mode()
869 phylink_set(pl->supported, 10000baseLRM_Full); in phylink_parse_mode()
870 phylink_set(pl->supported, 10000baseER_Full); in phylink_parse_mode()
874 phylink_set(pl->supported, 25000baseCR_Full); in phylink_parse_mode()
875 phylink_set(pl->supported, 25000baseKR_Full); in phylink_parse_mode()
876 phylink_set(pl->supported, 25000baseSR_Full); in phylink_parse_mode()
877 phylink_set(pl->supported, 40000baseKR4_Full); in phylink_parse_mode()
878 phylink_set(pl->supported, 40000baseCR4_Full); in phylink_parse_mode()
879 phylink_set(pl->supported, 40000baseSR4_Full); in phylink_parse_mode()
880 phylink_set(pl->supported, 40000baseLR4_Full); in phylink_parse_mode()
881 phylink_set(pl->supported, 50000baseCR2_Full); in phylink_parse_mode()
882 phylink_set(pl->supported, 50000baseKR2_Full); in phylink_parse_mode()
883 phylink_set(pl->supported, 50000baseSR2_Full); in phylink_parse_mode()
884 phylink_set(pl->supported, 50000baseKR_Full); in phylink_parse_mode()
885 phylink_set(pl->supported, 50000baseSR_Full); in phylink_parse_mode()
886 phylink_set(pl->supported, 50000baseCR_Full); in phylink_parse_mode()
887 phylink_set(pl->supported, 50000baseLR_ER_FR_Full); in phylink_parse_mode()
888 phylink_set(pl->supported, 50000baseDR_Full); in phylink_parse_mode()
889 phylink_set(pl->supported, 100000baseKR4_Full); in phylink_parse_mode()
890 phylink_set(pl->supported, 100000baseSR4_Full); in phylink_parse_mode()
891 phylink_set(pl->supported, 100000baseCR4_Full); in phylink_parse_mode()
892 phylink_set(pl->supported, 100000baseLR4_ER4_Full); in phylink_parse_mode()
893 phylink_set(pl->supported, 100000baseKR2_Full); in phylink_parse_mode()
894 phylink_set(pl->supported, 100000baseSR2_Full); in phylink_parse_mode()
895 phylink_set(pl->supported, 100000baseCR2_Full); in phylink_parse_mode()
896 phylink_set(pl->supported, 100000baseLR2_ER2_FR2_Full); in phylink_parse_mode()
897 phylink_set(pl->supported, 100000baseDR2_Full); in phylink_parse_mode()
901 phylink_err(pl, in phylink_parse_mode()
903 phy_modes(pl->link_config.interface)); in phylink_parse_mode()
907 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_parse_mode()
909 if (phylink_validate(pl, pl->supported, &pl->link_config)) { in phylink_parse_mode()
910 phylink_err(pl, in phylink_parse_mode()
916 pl->link_config.an_enabled = phylink_test(pl->supported, Autoneg); in phylink_parse_mode()
922 static void phylink_apply_manual_flow(struct phylink *pl, in phylink_apply_manual_flow() argument
930 if (!(pl->link_config.pause & MLO_PAUSE_AN)) in phylink_apply_manual_flow()
931 state->pause = pl->link_config.pause; in phylink_apply_manual_flow()
950 static void phylink_pcs_poll_stop(struct phylink *pl) in phylink_pcs_poll_stop() argument
952 if (pl->cfg_link_an_mode == MLO_AN_INBAND) in phylink_pcs_poll_stop()
953 del_timer(&pl->link_poll); in phylink_pcs_poll_stop()
956 static void phylink_pcs_poll_start(struct phylink *pl) in phylink_pcs_poll_start() argument
958 if (pl->pcs && pl->pcs->poll && pl->cfg_link_an_mode == MLO_AN_INBAND) in phylink_pcs_poll_start()
959 mod_timer(&pl->link_poll, jiffies + HZ); in phylink_pcs_poll_start()
962 static void phylink_mac_config(struct phylink *pl, in phylink_mac_config() argument
965 phylink_dbg(pl, in phylink_mac_config()
967 __func__, phylink_an_mode_str(pl->cur_link_an_mode), in phylink_mac_config()
975 pl->mac_ops->mac_config(pl->config, pl->cur_link_an_mode, state); in phylink_mac_config()
978 static void phylink_mac_pcs_an_restart(struct phylink *pl) in phylink_mac_pcs_an_restart() argument
980 if (pl->link_config.an_enabled && in phylink_mac_pcs_an_restart()
981 phy_interface_mode_is_8023z(pl->link_config.interface) && in phylink_mac_pcs_an_restart()
982 phylink_autoneg_inband(pl->cur_link_an_mode)) { in phylink_mac_pcs_an_restart()
983 if (pl->pcs) in phylink_mac_pcs_an_restart()
984 pl->pcs->ops->pcs_an_restart(pl->pcs); in phylink_mac_pcs_an_restart()
985 else if (pl->config->legacy_pre_march2020) in phylink_mac_pcs_an_restart()
986 pl->mac_ops->mac_an_restart(pl->config); in phylink_mac_pcs_an_restart()
990 static void phylink_major_config(struct phylink *pl, bool restart, in phylink_major_config() argument
997 phylink_dbg(pl, "major config %s\n", phy_modes(state->interface)); in phylink_major_config()
999 if (pl->using_mac_select_pcs) { in phylink_major_config()
1000 pcs = pl->mac_ops->mac_select_pcs(pl->config, state->interface); in phylink_major_config()
1002 phylink_err(pl, in phylink_major_config()
1008 pcs_changed = pcs && pl->pcs != pcs; in phylink_major_config()
1011 phylink_pcs_poll_stop(pl); in phylink_major_config()
1013 if (pl->mac_ops->mac_prepare) { in phylink_major_config()
1014 err = pl->mac_ops->mac_prepare(pl->config, pl->cur_link_an_mode, in phylink_major_config()
1017 phylink_err(pl, "mac_prepare failed: %pe\n", in phylink_major_config()
1027 pl->pcs = pcs; in phylink_major_config()
1029 phylink_mac_config(pl, state); in phylink_major_config()
1031 if (pl->pcs) { in phylink_major_config()
1032 err = pl->pcs->ops->pcs_config(pl->pcs, pl->cur_link_an_mode, in phylink_major_config()
1035 !!(pl->link_config.pause & in phylink_major_config()
1038 phylink_err(pl, "pcs_config failed: %pe\n", in phylink_major_config()
1044 phylink_mac_pcs_an_restart(pl); in phylink_major_config()
1046 if (pl->mac_ops->mac_finish) { in phylink_major_config()
1047 err = pl->mac_ops->mac_finish(pl->config, pl->cur_link_an_mode, in phylink_major_config()
1050 phylink_err(pl, "mac_finish failed: %pe\n", in phylink_major_config()
1054 phylink_pcs_poll_start(pl); in phylink_major_config()
1063 static int phylink_change_inband_advert(struct phylink *pl) in phylink_change_inband_advert() argument
1067 if (test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) in phylink_change_inband_advert()
1070 if (!pl->pcs && pl->config->legacy_pre_march2020) { in phylink_change_inband_advert()
1072 phylink_mac_config(pl, &pl->link_config); in phylink_change_inband_advert()
1073 phylink_mac_pcs_an_restart(pl); in phylink_change_inband_advert()
1077 phylink_dbg(pl, "%s: mode=%s/%s adv=%*pb pause=%02x\n", __func__, in phylink_change_inband_advert()
1078 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_change_inband_advert()
1079 phy_modes(pl->link_config.interface), in phylink_change_inband_advert()
1080 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->link_config.advertising, in phylink_change_inband_advert()
1081 pl->link_config.pause); in phylink_change_inband_advert()
1087 ret = pl->pcs->ops->pcs_config(pl->pcs, pl->cur_link_an_mode, in phylink_change_inband_advert()
1088 pl->link_config.interface, in phylink_change_inband_advert()
1089 pl->link_config.advertising, in phylink_change_inband_advert()
1090 !!(pl->link_config.pause & in phylink_change_inband_advert()
1096 phylink_mac_pcs_an_restart(pl); in phylink_change_inband_advert()
1101 static void phylink_mac_pcs_get_state(struct phylink *pl, in phylink_mac_pcs_get_state() argument
1104 linkmode_copy(state->advertising, pl->link_config.advertising); in phylink_mac_pcs_get_state()
1106 state->interface = pl->link_config.interface; in phylink_mac_pcs_get_state()
1107 state->an_enabled = pl->link_config.an_enabled; in phylink_mac_pcs_get_state()
1108 state->rate_matching = pl->link_config.rate_matching; in phylink_mac_pcs_get_state()
1114 state->speed = pl->link_config.speed; in phylink_mac_pcs_get_state()
1115 state->duplex = pl->link_config.duplex; in phylink_mac_pcs_get_state()
1116 state->pause = pl->link_config.pause; in phylink_mac_pcs_get_state()
1121 if (pl->pcs) in phylink_mac_pcs_get_state()
1122 pl->pcs->ops->pcs_get_state(pl->pcs, state); in phylink_mac_pcs_get_state()
1123 else if (pl->mac_ops->mac_pcs_get_state && in phylink_mac_pcs_get_state()
1124 pl->config->legacy_pre_march2020) in phylink_mac_pcs_get_state()
1125 pl->mac_ops->mac_pcs_get_state(pl->config, state); in phylink_mac_pcs_get_state()
1133 static void phylink_get_fixed_state(struct phylink *pl, in phylink_get_fixed_state() argument
1136 *state = pl->link_config; in phylink_get_fixed_state()
1137 if (pl->config->get_fixed_state) in phylink_get_fixed_state()
1138 pl->config->get_fixed_state(pl->config, state); in phylink_get_fixed_state()
1139 else if (pl->link_gpio) in phylink_get_fixed_state()
1140 state->link = !!gpiod_get_value_cansleep(pl->link_gpio); in phylink_get_fixed_state()
1145 static void phylink_mac_initial_config(struct phylink *pl, bool force_restart) in phylink_mac_initial_config() argument
1149 switch (pl->cur_link_an_mode) { in phylink_mac_initial_config()
1151 link_state = pl->phy_state; in phylink_mac_initial_config()
1155 phylink_get_fixed_state(pl, &link_state); in phylink_mac_initial_config()
1159 link_state = pl->link_config; in phylink_mac_initial_config()
1170 phylink_apply_manual_flow(pl, &link_state); in phylink_mac_initial_config()
1171 phylink_major_config(pl, force_restart, &link_state); in phylink_mac_initial_config()
1188 static void phylink_link_up(struct phylink *pl, in phylink_link_up() argument
1191 struct net_device *ndev = pl->netdev; in phylink_link_up()
1220 pl->cur_interface = link_state.interface; in phylink_link_up()
1222 if (pl->pcs && pl->pcs->ops->pcs_link_up) in phylink_link_up()
1223 pl->pcs->ops->pcs_link_up(pl->pcs, pl->cur_link_an_mode, in phylink_link_up()
1224 pl->cur_interface, speed, duplex); in phylink_link_up()
1226 pl->mac_ops->mac_link_up(pl->config, pl->phydev, pl->cur_link_an_mode, in phylink_link_up()
1227 pl->cur_interface, speed, duplex, in phylink_link_up()
1233 phylink_info(pl, in phylink_link_up()
1240 static void phylink_link_down(struct phylink *pl) in phylink_link_down() argument
1242 struct net_device *ndev = pl->netdev; in phylink_link_down()
1246 pl->mac_ops->mac_link_down(pl->config, pl->cur_link_an_mode, in phylink_link_down()
1247 pl->cur_interface); in phylink_link_down()
1248 phylink_info(pl, "Link is Down\n"); in phylink_link_down()
1253 struct phylink *pl = container_of(w, struct phylink, resolve); in phylink_resolve() local
1255 struct net_device *ndev = pl->netdev; in phylink_resolve()
1260 mutex_lock(&pl->state_mutex); in phylink_resolve()
1261 if (pl->netdev) in phylink_resolve()
1264 cur_link_state = pl->old_link_state; in phylink_resolve()
1266 if (pl->phylink_disable_state) { in phylink_resolve()
1267 pl->mac_link_dropped = false; in phylink_resolve()
1269 } else if (pl->mac_link_dropped) { in phylink_resolve()
1273 switch (pl->cur_link_an_mode) { in phylink_resolve()
1275 link_state = pl->phy_state; in phylink_resolve()
1276 phylink_apply_manual_flow(pl, &link_state); in phylink_resolve()
1281 phylink_get_fixed_state(pl, &link_state); in phylink_resolve()
1286 phylink_mac_pcs_get_state(pl, &link_state); in phylink_resolve()
1297 phylink_mac_pcs_get_state(pl, in phylink_resolve()
1304 if (pl->phydev) in phylink_resolve()
1305 link_state.link &= pl->phy_state.link; in phylink_resolve()
1308 if (pl->phydev && pl->phy_state.link) { in phylink_resolve()
1314 pl->phy_state.interface) { in phylink_resolve()
1318 link_state.interface = pl->phy_state.interface; in phylink_resolve()
1323 if (pl->phy_state.rate_matching) { in phylink_resolve()
1325 pl->phy_state.rate_matching; in phylink_resolve()
1326 link_state.speed = pl->phy_state.speed; in phylink_resolve()
1328 pl->phy_state.duplex; in phylink_resolve()
1334 link_state.pause = pl->phy_state.pause; in phylink_resolve()
1337 phylink_apply_manual_flow(pl, &link_state); in phylink_resolve()
1343 if (link_state.interface != pl->link_config.interface) { in phylink_resolve()
1348 phylink_link_down(pl); in phylink_resolve()
1351 phylink_major_config(pl, false, &link_state); in phylink_resolve()
1352 pl->link_config.interface = link_state.interface; in phylink_resolve()
1353 } else if (!pl->pcs && pl->config->legacy_pre_march2020) { in phylink_resolve()
1359 phylink_mac_config(pl, &link_state); in phylink_resolve()
1364 pl->old_link_state = link_state.link; in phylink_resolve()
1366 phylink_link_down(pl); in phylink_resolve()
1368 phylink_link_up(pl, link_state); in phylink_resolve()
1371 pl->mac_link_dropped = false; in phylink_resolve()
1372 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_resolve()
1374 mutex_unlock(&pl->state_mutex); in phylink_resolve()
1377 static void phylink_run_resolve(struct phylink *pl) in phylink_run_resolve() argument
1379 if (!pl->phylink_disable_state) in phylink_run_resolve()
1380 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_run_resolve()
1383 static void phylink_run_resolve_and_disable(struct phylink *pl, int bit) in phylink_run_resolve_and_disable() argument
1385 unsigned long state = pl->phylink_disable_state; in phylink_run_resolve_and_disable()
1387 set_bit(bit, &pl->phylink_disable_state); in phylink_run_resolve_and_disable()
1389 queue_work(system_power_efficient_wq, &pl->resolve); in phylink_run_resolve_and_disable()
1390 flush_work(&pl->resolve); in phylink_run_resolve_and_disable()
1394 static void phylink_enable_and_run_resolve(struct phylink *pl, int bit) in phylink_enable_and_run_resolve() argument
1396 clear_bit(bit, &pl->phylink_disable_state); in phylink_enable_and_run_resolve()
1397 phylink_run_resolve(pl); in phylink_enable_and_run_resolve()
1402 struct phylink *pl = container_of(t, struct phylink, link_poll); in phylink_fixed_poll() local
1406 phylink_run_resolve(pl); in phylink_fixed_poll()
1411 static int phylink_register_sfp(struct phylink *pl, in phylink_register_sfp() argument
1422 phylink_err(pl, "unable to attach SFP bus: %pe\n", bus); in phylink_register_sfp()
1426 pl->sfp_bus = bus; in phylink_register_sfp()
1428 ret = sfp_bus_add_upstream(bus, pl, &sfp_phylink_ops); in phylink_register_sfp()
1456 struct phylink *pl; in phylink_create() local
1472 pl = kzalloc(sizeof(*pl), GFP_KERNEL); in phylink_create()
1473 if (!pl) in phylink_create()
1476 mutex_init(&pl->state_mutex); in phylink_create()
1477 INIT_WORK(&pl->resolve, phylink_resolve); in phylink_create()
1479 pl->config = config; in phylink_create()
1481 pl->netdev = to_net_dev(config->dev); in phylink_create()
1483 pl->dev = config->dev; in phylink_create()
1485 kfree(pl); in phylink_create()
1489 pl->using_mac_select_pcs = using_mac_select_pcs; in phylink_create()
1490 pl->phy_state.interface = iface; in phylink_create()
1491 pl->link_interface = iface; in phylink_create()
1493 pl->link_port = PORT_BNC; in phylink_create()
1495 pl->link_port = PORT_MII; in phylink_create()
1496 pl->link_config.interface = iface; in phylink_create()
1497 pl->link_config.pause = MLO_PAUSE_AN; in phylink_create()
1498 pl->link_config.speed = SPEED_UNKNOWN; in phylink_create()
1499 pl->link_config.duplex = DUPLEX_UNKNOWN; in phylink_create()
1500 pl->link_config.an_enabled = true; in phylink_create()
1501 pl->mac_ops = mac_ops; in phylink_create()
1502 __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state); in phylink_create()
1503 timer_setup(&pl->link_poll, phylink_fixed_poll, 0); in phylink_create()
1505 bitmap_fill(pl->supported, __ETHTOOL_LINK_MODE_MASK_NBITS); in phylink_create()
1506 linkmode_copy(pl->link_config.advertising, pl->supported); in phylink_create()
1507 phylink_validate(pl, pl->supported, &pl->link_config); in phylink_create()
1509 ret = phylink_parse_mode(pl, fwnode); in phylink_create()
1511 kfree(pl); in phylink_create()
1515 if (pl->cfg_link_an_mode == MLO_AN_FIXED) { in phylink_create()
1516 ret = phylink_parse_fixedlink(pl, fwnode); in phylink_create()
1518 kfree(pl); in phylink_create()
1523 pl->cur_link_an_mode = pl->cfg_link_an_mode; in phylink_create()
1525 ret = phylink_register_sfp(pl, fwnode); in phylink_create()
1527 kfree(pl); in phylink_create()
1531 return pl; in phylink_create()
1544 void phylink_destroy(struct phylink *pl) in phylink_destroy() argument
1546 sfp_bus_del_upstream(pl->sfp_bus); in phylink_destroy()
1547 if (pl->link_gpio) in phylink_destroy()
1548 gpiod_put(pl->link_gpio); in phylink_destroy()
1550 cancel_work_sync(&pl->resolve); in phylink_destroy()
1551 kfree(pl); in phylink_destroy()
1557 struct phylink *pl = phydev->phylink; in phylink_phy_change() local
1562 mutex_lock(&pl->state_mutex); in phylink_phy_change()
1563 pl->phy_state.speed = phydev->speed; in phylink_phy_change()
1564 pl->phy_state.duplex = phydev->duplex; in phylink_phy_change()
1565 pl->phy_state.rate_matching = phydev->rate_matching; in phylink_phy_change()
1566 pl->phy_state.pause = MLO_PAUSE_NONE; in phylink_phy_change()
1568 pl->phy_state.pause |= MLO_PAUSE_TX; in phylink_phy_change()
1570 pl->phy_state.pause |= MLO_PAUSE_RX; in phylink_phy_change()
1571 pl->phy_state.interface = phydev->interface; in phylink_phy_change()
1572 pl->phy_state.link = up; in phylink_phy_change()
1573 mutex_unlock(&pl->state_mutex); in phylink_phy_change()
1575 phylink_run_resolve(pl); in phylink_phy_change()
1577 phylink_dbg(pl, "phy link %s %s/%s/%s/%s/%s\n", up ? "up" : "down", in phylink_phy_change()
1582 phylink_pause_to_str(pl->phy_state.pause)); in phylink_phy_change()
1585 static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy, in phylink_bringup_phy() argument
1630 ret = phylink_validate(pl, supported, &config); in phylink_bringup_phy()
1632 phylink_warn(pl, "validation of %s with support %*pb and advertisement %*pb failed: %pe\n", in phylink_bringup_phy()
1640 phy->phylink = pl; in phylink_bringup_phy()
1644 phylink_info(pl, in phylink_bringup_phy()
1650 mutex_lock(&pl->state_mutex); in phylink_bringup_phy()
1651 pl->phydev = phy; in phylink_bringup_phy()
1652 pl->phy_state.interface = interface; in phylink_bringup_phy()
1653 pl->phy_state.pause = MLO_PAUSE_NONE; in phylink_bringup_phy()
1654 pl->phy_state.speed = SPEED_UNKNOWN; in phylink_bringup_phy()
1655 pl->phy_state.duplex = DUPLEX_UNKNOWN; in phylink_bringup_phy()
1656 pl->phy_state.rate_matching = RATE_MATCH_NONE; in phylink_bringup_phy()
1657 linkmode_copy(pl->supported, supported); in phylink_bringup_phy()
1658 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_bringup_phy()
1662 mutex_unlock(&pl->state_mutex); in phylink_bringup_phy()
1665 phylink_dbg(pl, in phylink_bringup_phy()
1668 __ETHTOOL_LINK_MODE_MASK_NBITS, pl->supported, in phylink_bringup_phy()
1674 if (pl->config->mac_managed_pm) in phylink_bringup_phy()
1680 static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy, in phylink_attach_phy() argument
1683 if (WARN_ON(pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_attach_phy()
1684 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_attach_phy()
1685 phy_interface_mode_is_8023z(interface) && !pl->sfp_bus))) in phylink_attach_phy()
1688 if (pl->phydev) in phylink_attach_phy()
1691 return phy_attach_direct(pl->netdev, phy, 0, interface); in phylink_attach_phy()
1709 int phylink_connect_phy(struct phylink *pl, struct phy_device *phy) in phylink_connect_phy() argument
1714 if (pl->link_interface == PHY_INTERFACE_MODE_NA) { in phylink_connect_phy()
1715 pl->link_interface = phy->interface; in phylink_connect_phy()
1716 pl->link_config.interface = pl->link_interface; in phylink_connect_phy()
1719 ret = phylink_attach_phy(pl, phy, pl->link_interface); in phylink_connect_phy()
1723 ret = phylink_bringup_phy(pl, phy, pl->link_config.interface); in phylink_connect_phy()
1743 int phylink_of_phy_connect(struct phylink *pl, struct device_node *dn, in phylink_of_phy_connect() argument
1746 return phylink_fwnode_phy_connect(pl, of_fwnode_handle(dn), flags); in phylink_of_phy_connect()
1761 int phylink_fwnode_phy_connect(struct phylink *pl, in phylink_fwnode_phy_connect() argument
1770 if (pl->cfg_link_an_mode == MLO_AN_FIXED || in phylink_fwnode_phy_connect()
1771 (pl->cfg_link_an_mode == MLO_AN_INBAND && in phylink_fwnode_phy_connect()
1772 phy_interface_mode_is_8023z(pl->link_interface))) in phylink_fwnode_phy_connect()
1777 if (pl->cfg_link_an_mode == MLO_AN_PHY) in phylink_fwnode_phy_connect()
1789 if (pl->link_interface == PHY_INTERFACE_MODE_NA) { in phylink_fwnode_phy_connect()
1790 pl->link_interface = phy_dev->interface; in phylink_fwnode_phy_connect()
1791 pl->link_config.interface = pl->link_interface; in phylink_fwnode_phy_connect()
1794 ret = phy_attach_direct(pl->netdev, phy_dev, flags, in phylink_fwnode_phy_connect()
1795 pl->link_interface); in phylink_fwnode_phy_connect()
1801 ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface); in phylink_fwnode_phy_connect()
1816 void phylink_disconnect_phy(struct phylink *pl) in phylink_disconnect_phy() argument
1822 phy = pl->phydev; in phylink_disconnect_phy()
1825 mutex_lock(&pl->state_mutex); in phylink_disconnect_phy()
1826 pl->phydev = NULL; in phylink_disconnect_phy()
1827 mutex_unlock(&pl->state_mutex); in phylink_disconnect_phy()
1829 flush_work(&pl->resolve); in phylink_disconnect_phy()
1844 void phylink_mac_change(struct phylink *pl, bool up) in phylink_mac_change() argument
1847 pl->mac_link_dropped = true; in phylink_mac_change()
1848 phylink_run_resolve(pl); in phylink_mac_change()
1849 phylink_dbg(pl, "mac link %s\n", up ? "up" : "down"); in phylink_mac_change()
1855 struct phylink *pl = data; in phylink_link_handler() local
1857 phylink_run_resolve(pl); in phylink_link_handler()
1870 void phylink_start(struct phylink *pl) in phylink_start() argument
1876 phylink_info(pl, "configuring for %s/%s link mode\n", in phylink_start()
1877 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_start()
1878 phy_modes(pl->link_config.interface)); in phylink_start()
1881 if (pl->netdev) in phylink_start()
1882 netif_carrier_off(pl->netdev); in phylink_start()
1892 phylink_mac_initial_config(pl, true); in phylink_start()
1894 phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_STOPPED); in phylink_start()
1896 if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) { in phylink_start()
1897 int irq = gpiod_to_irq(pl->link_gpio); in phylink_start()
1903 "netdev link", pl)) in phylink_start()
1904 pl->link_irq = irq; in phylink_start()
1912 switch (pl->cfg_link_an_mode) { in phylink_start()
1914 poll |= pl->config->poll_fixed_state; in phylink_start()
1917 if (pl->pcs) in phylink_start()
1918 poll |= pl->pcs->poll; in phylink_start()
1922 mod_timer(&pl->link_poll, jiffies + HZ); in phylink_start()
1923 if (pl->phydev) in phylink_start()
1924 phy_start(pl->phydev); in phylink_start()
1925 if (pl->sfp_bus) in phylink_start()
1926 sfp_upstream_start(pl->sfp_bus); in phylink_start()
1942 void phylink_stop(struct phylink *pl) in phylink_stop() argument
1946 if (pl->sfp_bus) in phylink_stop()
1947 sfp_upstream_stop(pl->sfp_bus); in phylink_stop()
1948 if (pl->phydev) in phylink_stop()
1949 phy_stop(pl->phydev); in phylink_stop()
1950 del_timer_sync(&pl->link_poll); in phylink_stop()
1951 if (pl->link_irq) { in phylink_stop()
1952 free_irq(pl->link_irq, pl); in phylink_stop()
1953 pl->link_irq = 0; in phylink_stop()
1956 phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_STOPPED); in phylink_stop()
1974 void phylink_suspend(struct phylink *pl, bool mac_wol) in phylink_suspend() argument
1978 if (mac_wol && (!pl->netdev || pl->netdev->wol_enabled)) { in phylink_suspend()
1980 mutex_lock(&pl->state_mutex); in phylink_suspend()
1983 __set_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state); in phylink_suspend()
1989 if (pl->netdev) in phylink_suspend()
1990 netif_carrier_off(pl->netdev); in phylink_suspend()
1992 pl->old_link_state = false; in phylink_suspend()
1997 mutex_unlock(&pl->state_mutex); in phylink_suspend()
1999 phylink_stop(pl); in phylink_suspend()
2011 void phylink_resume(struct phylink *pl) in phylink_resume() argument
2015 if (test_bit(PHYLINK_DISABLE_MAC_WOL, &pl->phylink_disable_state)) { in phylink_resume()
2024 mutex_lock(&pl->state_mutex); in phylink_resume()
2025 phylink_link_down(pl); in phylink_resume()
2026 mutex_unlock(&pl->state_mutex); in phylink_resume()
2031 phylink_mac_initial_config(pl, true); in phylink_resume()
2034 phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_MAC_WOL); in phylink_resume()
2036 phylink_start(pl); in phylink_resume()
2050 void phylink_ethtool_get_wol(struct phylink *pl, struct ethtool_wolinfo *wol) in phylink_ethtool_get_wol() argument
2057 if (pl->phydev) in phylink_ethtool_get_wol()
2058 phy_ethtool_get_wol(pl->phydev, wol); in phylink_ethtool_get_wol()
2073 int phylink_ethtool_set_wol(struct phylink *pl, struct ethtool_wolinfo *wol) in phylink_ethtool_set_wol() argument
2079 if (pl->phydev) in phylink_ethtool_set_wol()
2080 ret = phy_ethtool_set_wol(pl->phydev, wol); in phylink_ethtool_set_wol()
2119 int phylink_ethtool_ksettings_get(struct phylink *pl, in phylink_ethtool_ksettings_get() argument
2126 if (pl->phydev) in phylink_ethtool_ksettings_get()
2127 phy_ethtool_ksettings_get(pl->phydev, kset); in phylink_ethtool_ksettings_get()
2129 kset->base.port = pl->link_port; in phylink_ethtool_ksettings_get()
2131 linkmode_copy(kset->link_modes.supported, pl->supported); in phylink_ethtool_ksettings_get()
2133 switch (pl->cur_link_an_mode) { in phylink_ethtool_ksettings_get()
2139 phylink_get_fixed_state(pl, &link_state); in phylink_ethtool_ksettings_get()
2147 if (pl->phydev) in phylink_ethtool_ksettings_get()
2150 phylink_mac_pcs_get_state(pl, &link_state); in phylink_ethtool_ksettings_get()
2169 int phylink_ethtool_ksettings_set(struct phylink *pl, in phylink_ethtool_ksettings_set() argument
2178 if (pl->phydev) { in phylink_ethtool_ksettings_set()
2197 return phy_ethtool_ksettings_set(pl->phydev, kset); in phylink_ethtool_ksettings_set()
2200 config = pl->link_config; in phylink_ethtool_ksettings_set()
2204 pl->supported); in phylink_ethtool_ksettings_set()
2213 pl->supported, false); in phylink_ethtool_ksettings_set()
2220 if (pl->cur_link_an_mode == MLO_AN_FIXED) { in phylink_ethtool_ksettings_set()
2221 if (s->speed != pl->link_config.speed || in phylink_ethtool_ksettings_set()
2222 s->duplex != pl->link_config.duplex) in phylink_ethtool_ksettings_set()
2236 if (pl->cur_link_an_mode == MLO_AN_FIXED) { in phylink_ethtool_ksettings_set()
2238 pl->link_config.advertising)) in phylink_ethtool_ksettings_set()
2262 if (pl->sfp_bus) { in phylink_ethtool_ksettings_set()
2263 config.interface = sfp_select_interface(pl->sfp_bus, in phylink_ethtool_ksettings_set()
2266 phylink_err(pl, in phylink_ethtool_ksettings_set()
2274 linkmode_copy(support, pl->supported); in phylink_ethtool_ksettings_set()
2275 if (phylink_validate(pl, support, &config)) { in phylink_ethtool_ksettings_set()
2276 phylink_err(pl, "validation of %s/%s with support %*pb failed\n", in phylink_ethtool_ksettings_set()
2277 phylink_an_mode_str(pl->cur_link_an_mode), in phylink_ethtool_ksettings_set()
2284 linkmode_copy(support, pl->supported); in phylink_ethtool_ksettings_set()
2285 if (phylink_validate(pl, support, &config)) in phylink_ethtool_ksettings_set()
2293 mutex_lock(&pl->state_mutex); in phylink_ethtool_ksettings_set()
2294 pl->link_config.speed = config.speed; in phylink_ethtool_ksettings_set()
2295 pl->link_config.duplex = config.duplex; in phylink_ethtool_ksettings_set()
2296 pl->link_config.an_enabled = config.an_enabled; in phylink_ethtool_ksettings_set()
2298 if (pl->link_config.interface != config.interface) { in phylink_ethtool_ksettings_set()
2301 if (pl->old_link_state) { in phylink_ethtool_ksettings_set()
2302 phylink_link_down(pl); in phylink_ethtool_ksettings_set()
2303 pl->old_link_state = false; in phylink_ethtool_ksettings_set()
2306 &pl->phylink_disable_state)) in phylink_ethtool_ksettings_set()
2307 phylink_major_config(pl, false, &config); in phylink_ethtool_ksettings_set()
2308 pl->link_config.interface = config.interface; in phylink_ethtool_ksettings_set()
2309 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_ethtool_ksettings_set()
2310 } else if (!linkmode_equal(pl->link_config.advertising, in phylink_ethtool_ksettings_set()
2312 linkmode_copy(pl->link_config.advertising, config.advertising); in phylink_ethtool_ksettings_set()
2313 phylink_change_inband_advert(pl); in phylink_ethtool_ksettings_set()
2315 mutex_unlock(&pl->state_mutex); in phylink_ethtool_ksettings_set()
2332 int phylink_ethtool_nway_reset(struct phylink *pl) in phylink_ethtool_nway_reset() argument
2338 if (pl->phydev) in phylink_ethtool_nway_reset()
2339 ret = phy_restart_aneg(pl->phydev); in phylink_ethtool_nway_reset()
2340 phylink_mac_pcs_an_restart(pl); in phylink_ethtool_nway_reset()
2351 void phylink_ethtool_get_pauseparam(struct phylink *pl, in phylink_ethtool_get_pauseparam() argument
2356 pause->autoneg = !!(pl->link_config.pause & MLO_PAUSE_AN); in phylink_ethtool_get_pauseparam()
2357 pause->rx_pause = !!(pl->link_config.pause & MLO_PAUSE_RX); in phylink_ethtool_get_pauseparam()
2358 pause->tx_pause = !!(pl->link_config.pause & MLO_PAUSE_TX); in phylink_ethtool_get_pauseparam()
2367 int phylink_ethtool_set_pauseparam(struct phylink *pl, in phylink_ethtool_set_pauseparam() argument
2370 struct phylink_link_state *config = &pl->link_config; in phylink_ethtool_set_pauseparam()
2376 if (pl->cur_link_an_mode == MLO_AN_FIXED) in phylink_ethtool_set_pauseparam()
2379 if (!phylink_test(pl->supported, Pause) && in phylink_ethtool_set_pauseparam()
2380 !phylink_test(pl->supported, Asym_Pause)) in phylink_ethtool_set_pauseparam()
2383 if (!phylink_test(pl->supported, Asym_Pause) && in phylink_ethtool_set_pauseparam()
2395 mutex_lock(&pl->state_mutex); in phylink_ethtool_set_pauseparam()
2421 if (!pl->phydev) in phylink_ethtool_set_pauseparam()
2422 phylink_change_inband_advert(pl); in phylink_ethtool_set_pauseparam()
2424 mutex_unlock(&pl->state_mutex); in phylink_ethtool_set_pauseparam()
2431 if (pl->phydev) in phylink_ethtool_set_pauseparam()
2432 phy_set_asym_pause(pl->phydev, pause->rx_pause, in phylink_ethtool_set_pauseparam()
2440 pl->mac_link_dropped = true; in phylink_ethtool_set_pauseparam()
2441 phylink_run_resolve(pl); in phylink_ethtool_set_pauseparam()
2458 int phylink_get_eee_err(struct phylink *pl) in phylink_get_eee_err() argument
2464 if (pl->phydev) in phylink_get_eee_err()
2465 ret = phy_get_eee_err(pl->phydev); in phylink_get_eee_err()
2478 int phylink_init_eee(struct phylink *pl, bool clk_stop_enable) in phylink_init_eee() argument
2482 if (pl->phydev) in phylink_init_eee()
2483 ret = phy_init_eee(pl->phydev, clk_stop_enable); in phylink_init_eee()
2494 int phylink_ethtool_get_eee(struct phylink *pl, struct ethtool_eee *eee) in phylink_ethtool_get_eee() argument
2500 if (pl->phydev) in phylink_ethtool_get_eee()
2501 ret = phy_ethtool_get_eee(pl->phydev, eee); in phylink_ethtool_get_eee()
2512 int phylink_ethtool_set_eee(struct phylink *pl, struct ethtool_eee *eee) in phylink_ethtool_set_eee() argument
2518 if (pl->phydev) in phylink_ethtool_set_eee()
2519 ret = phy_ethtool_set_eee(pl->phydev, eee); in phylink_ethtool_set_eee()
2551 static int phylink_phy_read(struct phylink *pl, unsigned int phy_id, in phylink_phy_read() argument
2554 struct phy_device *phydev = pl->phydev; in phylink_phy_read()
2560 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_read()
2586 return mdiobus_c45_read(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_read()
2590 return mdiobus_read(pl->phydev->mdio.bus, phy_id, reg); in phylink_phy_read()
2593 static int phylink_phy_write(struct phylink *pl, unsigned int phy_id, in phylink_phy_write() argument
2596 struct phy_device *phydev = pl->phydev; in phylink_phy_write()
2602 return mdiobus_c45_write(pl->phydev->mdio.bus, prtad, devad, in phylink_phy_write()
2627 return mdiobus_c45_write(pl->phydev->mdio.bus, phy_id, devad, in phylink_phy_write()
2634 static int phylink_mii_read(struct phylink *pl, unsigned int phy_id, in phylink_mii_read() argument
2640 switch (pl->cur_link_an_mode) { in phylink_mii_read()
2643 phylink_get_fixed_state(pl, &state); in phylink_mii_read()
2653 phylink_mac_pcs_get_state(pl, &state); in phylink_mii_read()
2662 static int phylink_mii_write(struct phylink *pl, unsigned int phy_id, in phylink_mii_write() argument
2665 switch (pl->cur_link_an_mode) { in phylink_mii_write()
2697 int phylink_mii_ioctl(struct phylink *pl, struct ifreq *ifr, int cmd) in phylink_mii_ioctl() argument
2704 if (pl->phydev) { in phylink_mii_ioctl()
2708 mii->phy_id = pl->phydev->mdio.addr; in phylink_mii_ioctl()
2712 ret = phylink_phy_read(pl, mii->phy_id, mii->reg_num); in phylink_mii_ioctl()
2720 ret = phylink_phy_write(pl, mii->phy_id, mii->reg_num, in phylink_mii_ioctl()
2725 ret = phy_mii_ioctl(pl->phydev, ifr, cmd); in phylink_mii_ioctl()
2735 ret = phylink_mii_read(pl, mii->phy_id, mii->reg_num); in phylink_mii_ioctl()
2743 ret = phylink_mii_write(pl, mii->phy_id, mii->reg_num, in phylink_mii_ioctl()
2769 int phylink_speed_down(struct phylink *pl, bool sync) in phylink_speed_down() argument
2775 if (!pl->sfp_bus && pl->phydev) in phylink_speed_down()
2776 ret = phy_speed_down(pl->phydev, sync); in phylink_speed_down()
2792 int phylink_speed_up(struct phylink *pl) in phylink_speed_up() argument
2798 if (!pl->sfp_bus && pl->phydev) in phylink_speed_up()
2799 ret = phy_speed_up(pl->phydev); in phylink_speed_up()
2807 struct phylink *pl = upstream; in phylink_sfp_attach() local
2809 pl->netdev->sfp_bus = bus; in phylink_sfp_attach()
2814 struct phylink *pl = upstream; in phylink_sfp_detach() local
2816 pl->netdev->sfp_bus = NULL; in phylink_sfp_detach()
2832 static phy_interface_t phylink_choose_sfp_interface(struct phylink *pl, in phylink_choose_sfp_interface() argument
2848 static void phylink_sfp_set_config(struct phylink *pl, u8 mode, in phylink_sfp_set_config() argument
2854 phylink_dbg(pl, "requesting link mode %s/%s with support %*pb\n", in phylink_sfp_set_config()
2858 if (!linkmode_equal(pl->supported, supported)) { in phylink_sfp_set_config()
2859 linkmode_copy(pl->supported, supported); in phylink_sfp_set_config()
2863 if (!linkmode_equal(pl->link_config.advertising, state->advertising)) { in phylink_sfp_set_config()
2864 linkmode_copy(pl->link_config.advertising, state->advertising); in phylink_sfp_set_config()
2868 if (pl->cur_link_an_mode != mode || in phylink_sfp_set_config()
2869 pl->link_config.interface != state->interface) { in phylink_sfp_set_config()
2870 pl->cur_link_an_mode = mode; in phylink_sfp_set_config()
2871 pl->link_config.interface = state->interface; in phylink_sfp_set_config()
2875 phylink_info(pl, "switched to %s/%s link mode\n", in phylink_sfp_set_config()
2881 &pl->phylink_disable_state)) in phylink_sfp_set_config()
2882 phylink_mac_initial_config(pl, false); in phylink_sfp_set_config()
2885 static int phylink_sfp_config_phy(struct phylink *pl, u8 mode, in phylink_sfp_config_phy() argument
2902 config.an_enabled = pl->link_config.an_enabled; in phylink_sfp_config_phy()
2905 ret = phylink_validate(pl, support, &config); in phylink_sfp_config_phy()
2907 phylink_err(pl, "validation with support %*pb failed: %pe\n", in phylink_sfp_config_phy()
2913 iface = sfp_select_interface(pl->sfp_bus, config.advertising); in phylink_sfp_config_phy()
2915 phylink_err(pl, in phylink_sfp_config_phy()
2923 ret = phylink_validate(pl, support1, &config); in phylink_sfp_config_phy()
2925 phylink_err(pl, in phylink_sfp_config_phy()
2934 pl->link_port = pl->sfp_port; in phylink_sfp_config_phy()
2936 phylink_sfp_set_config(pl, mode, support, &config); in phylink_sfp_config_phy()
2941 static int phylink_sfp_config_optical(struct phylink *pl) in phylink_sfp_config_optical() argument
2949 phylink_dbg(pl, "optical SFP: interfaces=[mac=%*pbl, sfp=%*pbl]\n", in phylink_sfp_config_optical()
2951 pl->config->supported_interfaces, in phylink_sfp_config_optical()
2953 pl->sfp_interfaces); in phylink_sfp_config_optical()
2958 phy_interface_and(interfaces, pl->config->supported_interfaces, in phylink_sfp_config_optical()
2959 pl->sfp_interfaces); in phylink_sfp_config_optical()
2961 phylink_err(pl, "unsupported SFP module: no common interface modes\n"); in phylink_sfp_config_optical()
2966 linkmode_copy(support, pl->sfp_support); in phylink_sfp_config_optical()
2967 linkmode_copy(config.advertising, pl->sfp_support); in phylink_sfp_config_optical()
2976 ret = phylink_validate_mask(pl, pl->sfp_support, &config, interfaces); in phylink_sfp_config_optical()
2978 phylink_err(pl, "unsupported SFP module: validation with support %*pb failed\n", in phylink_sfp_config_optical()
2983 interface = phylink_choose_sfp_interface(pl, interfaces); in phylink_sfp_config_optical()
2985 phylink_err(pl, "failed to select SFP interface\n"); in phylink_sfp_config_optical()
2989 phylink_dbg(pl, "optical SFP: chosen %s interface\n", in phylink_sfp_config_optical()
2995 ret = phylink_validate(pl, support, &config); in phylink_sfp_config_optical()
2997 phylink_err(pl, "validation with support %*pb failed: %pe\n", in phylink_sfp_config_optical()
3003 pl->link_port = pl->sfp_port; in phylink_sfp_config_optical()
3005 phylink_sfp_set_config(pl, MLO_AN_INBAND, pl->sfp_support, &config); in phylink_sfp_config_optical()
3013 struct phylink *pl = upstream; in phylink_sfp_module_insert() local
3017 linkmode_zero(pl->sfp_support); in phylink_sfp_module_insert()
3018 phy_interface_zero(pl->sfp_interfaces); in phylink_sfp_module_insert()
3019 sfp_parse_support(pl->sfp_bus, id, pl->sfp_support, pl->sfp_interfaces); in phylink_sfp_module_insert()
3020 pl->sfp_port = sfp_parse_port(pl->sfp_bus, id, pl->sfp_support); in phylink_sfp_module_insert()
3023 pl->sfp_may_have_phy = sfp_may_have_phy(pl->sfp_bus, id); in phylink_sfp_module_insert()
3024 if (pl->sfp_may_have_phy) in phylink_sfp_module_insert()
3027 return phylink_sfp_config_optical(pl); in phylink_sfp_module_insert()
3032 struct phylink *pl = upstream; in phylink_sfp_module_start() local
3035 if (pl->phydev) { in phylink_sfp_module_start()
3036 phy_start(pl->phydev); in phylink_sfp_module_start()
3043 if (!pl->sfp_may_have_phy) in phylink_sfp_module_start()
3046 return phylink_sfp_config_optical(pl); in phylink_sfp_module_start()
3051 struct phylink *pl = upstream; in phylink_sfp_module_stop() local
3054 if (pl->phydev) in phylink_sfp_module_stop()
3055 phy_stop(pl->phydev); in phylink_sfp_module_stop()
3060 struct phylink *pl = upstream; in phylink_sfp_link_down() local
3064 phylink_run_resolve_and_disable(pl, PHYLINK_DISABLE_LINK); in phylink_sfp_link_down()
3069 struct phylink *pl = upstream; in phylink_sfp_link_up() local
3073 phylink_enable_and_run_resolve(pl, PHYLINK_DISABLE_LINK); in phylink_sfp_link_up()
3087 struct phylink *pl = upstream; in phylink_sfp_connect_phy() local
3108 pl->config->supported_interfaces); in phylink_sfp_connect_phy()
3111 ret = phylink_sfp_config_phy(pl, mode, phy); in phylink_sfp_connect_phy()
3115 interface = pl->link_config.interface; in phylink_sfp_connect_phy()
3116 ret = phylink_attach_phy(pl, phy, interface); in phylink_sfp_connect_phy()
3120 ret = phylink_bringup_phy(pl, phy, interface); in phylink_sfp_connect_phy()