octeon: disable edgerouter image
[openwrt/openwrt.git] / target / linux / generic / pending-4.19 / 748-net-phylink-split-link_an_mode-configured-and-curren.patch
1 From d1339d6956f0255b6ce2412328a98945be8cc3ca Mon Sep 17 00:00:00 2001
2 From: Russell King <rmk+kernel@armlinux.org.uk>
3 Date: Sat, 16 Nov 2019 11:30:18 +0000
4 Subject: [PATCH 651/660] net: phylink: split link_an_mode configured and
5 current settings
6
7 Split link_an_mode between the configured setting and the current
8 operating setting. This is an important distinction to make when we
9 need to configure PHY mode for a plugged SFP+ module that does not
10 use in-band signalling.
11
12 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
13 ---
14 drivers/net/phy/phylink.c | 59 ++++++++++++++++++++-------------------
15 1 file changed, 31 insertions(+), 28 deletions(-)
16
17 --- a/drivers/net/phy/phylink.c
18 +++ b/drivers/net/phy/phylink.c
19 @@ -48,7 +48,8 @@ struct phylink {
20 unsigned long phylink_disable_state; /* bitmask of disables */
21 struct phy_device *phydev;
22 phy_interface_t link_interface; /* PHY_INTERFACE_xxx */
23 - u8 link_an_mode; /* MLO_AN_xxx */
24 + u8 cfg_link_an_mode; /* MLO_AN_xxx */
25 + u8 cur_link_an_mode;
26 u8 link_port; /* The current non-phy ethtool port */
27 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
28
29 @@ -253,12 +254,12 @@ static int phylink_parse_mode(struct phy
30
31 dn = fwnode_get_named_child_node(fwnode, "fixed-link");
32 if (dn || fwnode_property_present(fwnode, "fixed-link"))
33 - pl->link_an_mode = MLO_AN_FIXED;
34 + pl->cfg_link_an_mode = MLO_AN_FIXED;
35 fwnode_handle_put(dn);
36
37 if (fwnode_property_read_string(fwnode, "managed", &managed) == 0 &&
38 strcmp(managed, "in-band-status") == 0) {
39 - if (pl->link_an_mode == MLO_AN_FIXED) {
40 + if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
41 netdev_err(pl->netdev,
42 "can't use both fixed-link and in-band-status\n");
43 return -EINVAL;
44 @@ -270,7 +271,7 @@ static int phylink_parse_mode(struct phy
45 phylink_set(pl->supported, Asym_Pause);
46 phylink_set(pl->supported, Pause);
47 pl->link_config.an_enabled = true;
48 - pl->link_an_mode = MLO_AN_INBAND;
49 + pl->cfg_link_an_mode = MLO_AN_INBAND;
50
51 switch (pl->link_config.interface) {
52 case PHY_INTERFACE_MODE_SGMII:
53 @@ -330,14 +331,14 @@ static void phylink_mac_config(struct ph
54 {
55 netdev_dbg(pl->netdev,
56 "%s: mode=%s/%s/%s/%s adv=%*pb pause=%02x link=%u an=%u\n",
57 - __func__, phylink_an_mode_str(pl->link_an_mode),
58 + __func__, phylink_an_mode_str(pl->cur_link_an_mode),
59 phy_modes(state->interface),
60 phy_speed_to_str(state->speed),
61 phy_duplex_to_str(state->duplex),
62 __ETHTOOL_LINK_MODE_MASK_NBITS, state->advertising,
63 state->pause, state->link, state->an_enabled);
64
65 - pl->ops->mac_config(pl->netdev, pl->link_an_mode, state);
66 + pl->ops->mac_config(pl->netdev, pl->cur_link_an_mode, state);
67 }
68
69 static void phylink_mac_config_up(struct phylink *pl,
70 @@ -446,7 +447,7 @@ static void phylink_resolve(struct work_
71 } else if (pl->mac_link_dropped) {
72 link_state.link = false;
73 } else {
74 - switch (pl->link_an_mode) {
75 + switch (pl->cur_link_an_mode) {
76 case MLO_AN_PHY:
77 link_state = pl->phy_state;
78 phylink_resolve_flow(pl, &link_state);
79 @@ -483,12 +484,12 @@ static void phylink_resolve(struct work_
80 if (link_state.link != netif_carrier_ok(ndev)) {
81 if (!link_state.link) {
82 netif_carrier_off(ndev);
83 - pl->ops->mac_link_down(ndev, pl->link_an_mode,
84 + pl->ops->mac_link_down(ndev, pl->cur_link_an_mode,
85 pl->cur_interface);
86 netdev_info(ndev, "Link is Down\n");
87 } else {
88 pl->cur_interface = link_state.interface;
89 - pl->ops->mac_link_up(ndev, pl->link_an_mode,
90 + pl->ops->mac_link_up(ndev, pl->cur_link_an_mode,
91 pl->cur_interface, pl->phydev);
92
93 netif_carrier_on(ndev);
94 @@ -610,7 +611,7 @@ struct phylink *phylink_create(struct ne
95 return ERR_PTR(ret);
96 }
97
98 - if (pl->link_an_mode == MLO_AN_FIXED) {
99 + if (pl->cfg_link_an_mode == MLO_AN_FIXED) {
100 ret = phylink_parse_fixedlink(pl, fwnode);
101 if (ret < 0) {
102 kfree(pl);
103 @@ -618,6 +619,8 @@ struct phylink *phylink_create(struct ne
104 }
105 }
106
107 + pl->cur_link_an_mode = pl->cfg_link_an_mode;
108 +
109 ret = phylink_register_sfp(pl, fwnode);
110 if (ret < 0) {
111 kfree(pl);
112 @@ -733,8 +736,8 @@ static int phylink_bringup_phy(struct ph
113 static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy,
114 phy_interface_t interface)
115 {
116 - if (WARN_ON(pl->link_an_mode == MLO_AN_FIXED ||
117 - (pl->link_an_mode == MLO_AN_INBAND &&
118 + if (WARN_ON(pl->cfg_link_an_mode == MLO_AN_FIXED ||
119 + (pl->cfg_link_an_mode == MLO_AN_INBAND &&
120 phy_interface_mode_is_8023z(interface))))
121 return -EINVAL;
122
123 @@ -801,8 +804,8 @@ int phylink_of_phy_connect(struct phylin
124 int ret;
125
126 /* Fixed links and 802.3z are handled without needing a PHY */
127 - if (pl->link_an_mode == MLO_AN_FIXED ||
128 - (pl->link_an_mode == MLO_AN_INBAND &&
129 + if (pl->cfg_link_an_mode == MLO_AN_FIXED ||
130 + (pl->cfg_link_an_mode == MLO_AN_INBAND &&
131 phy_interface_mode_is_8023z(pl->link_interface)))
132 return 0;
133
134 @@ -813,7 +816,7 @@ int phylink_of_phy_connect(struct phylin
135 phy_node = of_parse_phandle(dn, "phy-device", 0);
136
137 if (!phy_node) {
138 - if (pl->link_an_mode == MLO_AN_PHY)
139 + if (pl->cfg_link_an_mode == MLO_AN_PHY)
140 return -ENODEV;
141 return 0;
142 }
143 @@ -876,7 +879,7 @@ int phylink_fixed_state_cb(struct phylin
144 /* It does not make sense to let the link be overriden unless we use
145 * MLO_AN_FIXED
146 */
147 - if (pl->link_an_mode != MLO_AN_FIXED)
148 + if (pl->cfg_link_an_mode != MLO_AN_FIXED)
149 return -EINVAL;
150
151 mutex_lock(&pl->state_mutex);
152 @@ -926,7 +929,7 @@ void phylink_start(struct phylink *pl)
153 ASSERT_RTNL();
154
155 netdev_info(pl->netdev, "configuring for %s/%s link mode\n",
156 - phylink_an_mode_str(pl->link_an_mode),
157 + phylink_an_mode_str(pl->cur_link_an_mode),
158 phy_modes(pl->link_config.interface));
159
160 /* Always set the carrier off */
161 @@ -948,7 +951,7 @@ void phylink_start(struct phylink *pl)
162 clear_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state);
163 phylink_run_resolve(pl);
164
165 - if (pl->link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
166 + if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->link_gpio) {
167 int irq = gpiod_to_irq(pl->link_gpio);
168
169 if (irq > 0) {
170 @@ -963,7 +966,7 @@ void phylink_start(struct phylink *pl)
171 if (irq <= 0)
172 mod_timer(&pl->link_poll, jiffies + HZ);
173 }
174 - if (pl->link_an_mode == MLO_AN_FIXED && pl->get_fixed_state)
175 + if (pl->cfg_link_an_mode == MLO_AN_FIXED && pl->get_fixed_state)
176 mod_timer(&pl->link_poll, jiffies + HZ);
177 if (pl->phydev)
178 phy_start(pl->phydev);
179 @@ -1090,7 +1093,7 @@ int phylink_ethtool_ksettings_get(struct
180
181 linkmode_copy(kset->link_modes.supported, pl->supported);
182
183 - switch (pl->link_an_mode) {
184 + switch (pl->cur_link_an_mode) {
185 case MLO_AN_FIXED:
186 /* We are using fixed settings. Report these as the
187 * current link settings - and note that these also
188 @@ -1163,7 +1166,7 @@ int phylink_ethtool_ksettings_set(struct
189 /* If we have a fixed link (as specified by firmware), refuse
190 * to change link parameters.
191 */
192 - if (pl->link_an_mode == MLO_AN_FIXED &&
193 + if (pl->cur_link_an_mode == MLO_AN_FIXED &&
194 (s->speed != pl->link_config.speed ||
195 s->duplex != pl->link_config.duplex))
196 return -EINVAL;
197 @@ -1175,7 +1178,7 @@ int phylink_ethtool_ksettings_set(struct
198 __clear_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, config.advertising);
199 } else {
200 /* If we have a fixed link, refuse to enable autonegotiation */
201 - if (pl->link_an_mode == MLO_AN_FIXED)
202 + if (pl->cur_link_an_mode == MLO_AN_FIXED)
203 return -EINVAL;
204
205 config.speed = SPEED_UNKNOWN;
206 @@ -1217,7 +1220,7 @@ int phylink_ethtool_ksettings_set(struct
207 * configuration. For a fixed link, this isn't able to change any
208 * parameters, which just leaves inband mode.
209 */
210 - if (pl->link_an_mode == MLO_AN_INBAND &&
211 + if (pl->cur_link_an_mode == MLO_AN_INBAND &&
212 !test_bit(PHYLINK_DISABLE_STOPPED, &pl->phylink_disable_state)) {
213 phylink_mac_config(pl, &pl->link_config);
214 phylink_mac_an_restart(pl);
215 @@ -1307,7 +1310,7 @@ int phylink_ethtool_set_pauseparam(struc
216 pause->tx_pause);
217 } else if (!test_bit(PHYLINK_DISABLE_STOPPED,
218 &pl->phylink_disable_state)) {
219 - switch (pl->link_an_mode) {
220 + switch (pl->cur_link_an_mode) {
221 case MLO_AN_FIXED:
222 /* Should we allow fixed links to change against the config? */
223 phylink_resolve_flow(pl, config);
224 @@ -1496,7 +1499,7 @@ static int phylink_mii_read(struct phyli
225 struct phylink_link_state state;
226 int val = 0xffff;
227
228 - switch (pl->link_an_mode) {
229 + switch (pl->cur_link_an_mode) {
230 case MLO_AN_FIXED:
231 if (phy_id == 0) {
232 phylink_get_fixed_state(pl, &state);
233 @@ -1524,7 +1527,7 @@ static int phylink_mii_read(struct phyli
234 static int phylink_mii_write(struct phylink *pl, unsigned int phy_id,
235 unsigned int reg, unsigned int val)
236 {
237 - switch (pl->link_an_mode) {
238 + switch (pl->cur_link_an_mode) {
239 case MLO_AN_FIXED:
240 break;
241
242 @@ -1698,10 +1701,10 @@ static int phylink_sfp_module_insert(voi
243 linkmode_copy(pl->link_config.advertising, config.advertising);
244 }
245
246 - if (pl->link_an_mode != MLO_AN_INBAND ||
247 + if (pl->cur_link_an_mode != MLO_AN_INBAND ||
248 pl->link_config.interface != config.interface) {
249 pl->link_config.interface = config.interface;
250 - pl->link_an_mode = MLO_AN_INBAND;
251 + pl->cur_link_an_mode = MLO_AN_INBAND;
252
253 changed = true;
254