kernel: backport phylink changes from mainline Linux
[openwrt/staging/jow.git] / target / linux / generic / backport-6.1 / 715-12-v6.4-net-phylink-remove-an_enabled.patch
1 From 7211ffd70941933a7825a56cf480f07ee81c321c Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 21 Mar 2023 15:58:54 +0000
4 Subject: [PATCH 11/21] net: phylink: remove an_enabled
5
6 The Autoneg bit in the advertising bitmap and state->an_enabled are
7 always identical. state->an_enabled is now no longer used by any
8 drivers, so lets kill this duplication.
9
10 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
11 Reviewed-by: Simon Horman <simon.horman@corigine.com>
12 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
13 ---
14 drivers/net/phy/phylink.c | 37 +++++++++++++++++--------------------
15 include/linux/phylink.h | 2 --
16 2 files changed, 17 insertions(+), 22 deletions(-)
17
18 --- a/drivers/net/phy/phylink.c
19 +++ b/drivers/net/phy/phylink.c
20 @@ -841,7 +841,6 @@ static int phylink_parse_mode(struct phy
21 phylink_set(pl->supported, Autoneg);
22 phylink_set(pl->supported, Asym_Pause);
23 phylink_set(pl->supported, Pause);
24 - pl->link_config.an_enabled = true;
25 pl->cfg_link_an_mode = MLO_AN_INBAND;
26
27 switch (pl->link_config.interface) {
28 @@ -944,9 +943,6 @@ static int phylink_parse_mode(struct phy
29 "failed to validate link configuration for in-band status\n");
30 return -EINVAL;
31 }
32 -
33 - /* Check if MAC/PCS also supports Autoneg. */
34 - pl->link_config.an_enabled = phylink_test(pl->supported, Autoneg);
35 }
36
37 return 0;
38 @@ -956,7 +952,8 @@ static void phylink_apply_manual_flow(st
39 struct phylink_link_state *state)
40 {
41 /* If autoneg is disabled, pause AN is also disabled */
42 - if (!state->an_enabled)
43 + if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
44 + state->advertising))
45 state->pause &= ~MLO_PAUSE_AN;
46
47 /* Manual configuration of pause modes */
48 @@ -996,21 +993,22 @@ static void phylink_mac_config(struct ph
49 const struct phylink_link_state *state)
50 {
51 phylink_dbg(pl,
52 - "%s: mode=%s/%s/%s/%s/%s adv=%*pb pause=%02x link=%u an=%u\n",
53 + "%s: mode=%s/%s/%s/%s/%s adv=%*pb pause=%02x link=%u\n",
54 __func__, phylink_an_mode_str(pl->cur_link_an_mode),
55 phy_modes(state->interface),
56 phy_speed_to_str(state->speed),
57 phy_duplex_to_str(state->duplex),
58 phy_rate_matching_to_str(state->rate_matching),
59 __ETHTOOL_LINK_MODE_MASK_NBITS, state->advertising,
60 - state->pause, state->link, state->an_enabled);
61 + state->pause, state->link);
62
63 pl->mac_ops->mac_config(pl->config, pl->cur_link_an_mode, state);
64 }
65
66 static void phylink_mac_pcs_an_restart(struct phylink *pl)
67 {
68 - if (pl->link_config.an_enabled &&
69 + if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
70 + pl->link_config.advertising) &&
71 phy_interface_mode_is_8023z(pl->link_config.interface) &&
72 phylink_autoneg_inband(pl->cur_link_an_mode)) {
73 if (pl->pcs)
74 @@ -1137,9 +1135,9 @@ static void phylink_mac_pcs_get_state(st
75 linkmode_copy(state->advertising, pl->link_config.advertising);
76 linkmode_zero(state->lp_advertising);
77 state->interface = pl->link_config.interface;
78 - state->an_enabled = pl->link_config.an_enabled;
79 state->rate_matching = pl->link_config.rate_matching;
80 - if (state->an_enabled) {
81 + if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
82 + state->advertising)) {
83 state->speed = SPEED_UNKNOWN;
84 state->duplex = DUPLEX_UNKNOWN;
85 state->pause = MLO_PAUSE_NONE;
86 @@ -1531,7 +1529,6 @@ struct phylink *phylink_create(struct ph
87 pl->link_config.pause = MLO_PAUSE_AN;
88 pl->link_config.speed = SPEED_UNKNOWN;
89 pl->link_config.duplex = DUPLEX_UNKNOWN;
90 - pl->link_config.an_enabled = true;
91 pl->mac_ops = mac_ops;
92 __set_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
93 timer_setup(&pl->link_poll, phylink_fixed_poll, 0);
94 @@ -2155,8 +2152,9 @@ static void phylink_get_ksettings(const
95 kset->base.speed = state->speed;
96 kset->base.duplex = state->duplex;
97 }
98 - kset->base.autoneg = state->an_enabled ? AUTONEG_ENABLE :
99 - AUTONEG_DISABLE;
100 + kset->base.autoneg = linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
101 + state->advertising) ?
102 + AUTONEG_ENABLE : AUTONEG_DISABLE;
103 }
104
105 /**
106 @@ -2303,9 +2301,8 @@ int phylink_ethtool_ksettings_set(struct
107 /* We have ruled out the case with a PHY attached, and the
108 * fixed-link cases. All that is left are in-band links.
109 */
110 - config.an_enabled = kset->base.autoneg == AUTONEG_ENABLE;
111 linkmode_mod_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising,
112 - config.an_enabled);
113 + kset->base.autoneg == AUTONEG_ENABLE);
114
115 /* If this link is with an SFP, ensure that changes to advertised modes
116 * also cause the associated interface to be selected such that the
117 @@ -2339,13 +2336,14 @@ int phylink_ethtool_ksettings_set(struct
118 }
119
120 /* If autonegotiation is enabled, we must have an advertisement */
121 - if (config.an_enabled && phylink_is_empty_linkmode(config.advertising))
122 + if (linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
123 + config.advertising) &&
124 + phylink_is_empty_linkmode(config.advertising))
125 return -EINVAL;
126
127 mutex_lock(&pl->state_mutex);
128 pl->link_config.speed = config.speed;
129 pl->link_config.duplex = config.duplex;
130 - pl->link_config.an_enabled = config.an_enabled;
131
132 if (pl->link_config.interface != config.interface) {
133 /* The interface changed, e.g. 1000base-X <-> 2500base-X */
134 @@ -2951,7 +2949,6 @@ static int phylink_sfp_config_phy(struct
135 config.speed = SPEED_UNKNOWN;
136 config.duplex = DUPLEX_UNKNOWN;
137 config.pause = MLO_PAUSE_AN;
138 - config.an_enabled = pl->link_config.an_enabled;
139
140 /* Ignore errors if we're expecting a PHY to attach later */
141 ret = phylink_validate(pl, support, &config);
142 @@ -3020,7 +3017,6 @@ static int phylink_sfp_config_optical(st
143 config.speed = SPEED_UNKNOWN;
144 config.duplex = DUPLEX_UNKNOWN;
145 config.pause = MLO_PAUSE_AN;
146 - config.an_enabled = true;
147
148 /* For all the interfaces that are supported, reduce the sfp_support
149 * mask to only those link modes that can be supported.
150 @@ -3354,7 +3350,8 @@ void phylink_mii_c22_pcs_decode_state(st
151 /* If there is no link or autonegotiation is disabled, the LP advertisement
152 * data is not meaningful, so don't go any further.
153 */
154 - if (!state->link || !state->an_enabled)
155 + if (!state->link || !linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT,
156 + state->advertising))
157 return;
158
159 switch (state->interface) {
160 --- a/include/linux/phylink.h
161 +++ b/include/linux/phylink.h
162 @@ -93,7 +93,6 @@ static inline bool phylink_autoneg_inban
163 * the medium link mode (@speed and @duplex) and the speed/duplex of the phy
164 * interface mode (@interface) are different.
165 * @link: true if the link is up.
166 - * @an_enabled: true if autonegotiation is enabled/desired.
167 * @an_complete: true if autonegotiation has completed.
168 */
169 struct phylink_link_state {
170 @@ -105,7 +104,6 @@ struct phylink_link_state {
171 int pause;
172 int rate_matching;
173 unsigned int link:1;
174 - unsigned int an_enabled:1;
175 unsigned int an_complete:1;
176 };
177