]>
Commit | Line | Data |
---|---|---|
afd4aea0 BH |
1 | /**************************************************************************** |
2 | * Driver for Solarflare Solarstorm network controllers and boards | |
3 | * Copyright 2009 Solarflare Communications Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License version 2 as published | |
7 | * by the Free Software Foundation, incorporated herein by reference. | |
8 | */ | |
9 | ||
10 | /* | |
11 | * Driver for PHY related operations via MCDI. | |
12 | */ | |
13 | ||
14 | #include "efx.h" | |
15 | #include "phy.h" | |
16 | #include "mcdi.h" | |
17 | #include "mcdi_pcol.h" | |
18 | #include "mdio_10g.h" | |
19 | ||
20 | struct efx_mcdi_phy_cfg { | |
21 | u32 flags; | |
22 | u32 type; | |
23 | u32 supported_cap; | |
24 | u32 channel; | |
25 | u32 port; | |
26 | u32 stats_mask; | |
27 | u8 name[20]; | |
28 | u32 media; | |
29 | u32 mmd_mask; | |
30 | u8 revision[20]; | |
31 | u32 forced_cap; | |
32 | }; | |
33 | ||
34 | static int | |
35 | efx_mcdi_get_phy_cfg(struct efx_nic *efx, struct efx_mcdi_phy_cfg *cfg) | |
36 | { | |
37 | u8 outbuf[MC_CMD_GET_PHY_CFG_OUT_LEN]; | |
38 | size_t outlen; | |
39 | int rc; | |
40 | ||
41 | BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN != 0); | |
42 | BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN != sizeof(cfg->name)); | |
43 | ||
44 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_CFG, NULL, 0, | |
45 | outbuf, sizeof(outbuf), &outlen); | |
46 | if (rc) | |
47 | goto fail; | |
48 | ||
49 | if (outlen < MC_CMD_GET_PHY_CFG_OUT_LEN) { | |
50 | rc = -EMSGSIZE; | |
51 | goto fail; | |
52 | } | |
53 | ||
54 | cfg->flags = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_FLAGS); | |
55 | cfg->type = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_TYPE); | |
56 | cfg->supported_cap = | |
57 | MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_SUPPORTED_CAP); | |
58 | cfg->channel = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_CHANNEL); | |
59 | cfg->port = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_PRT); | |
60 | cfg->stats_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_STATS_MASK); | |
61 | memcpy(cfg->name, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_NAME), | |
62 | sizeof(cfg->name)); | |
63 | cfg->media = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MEDIA_TYPE); | |
64 | cfg->mmd_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MMD_MASK); | |
65 | memcpy(cfg->revision, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_REVISION), | |
66 | sizeof(cfg->revision)); | |
67 | ||
68 | return 0; | |
69 | ||
70 | fail: | |
71 | EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc); | |
72 | return rc; | |
73 | } | |
74 | ||
75 | static int efx_mcdi_set_link(struct efx_nic *efx, u32 capabilities, | |
76 | u32 flags, u32 loopback_mode, | |
77 | u32 loopback_speed) | |
78 | { | |
79 | u8 inbuf[MC_CMD_SET_LINK_IN_LEN]; | |
80 | int rc; | |
81 | ||
82 | BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN != 0); | |
83 | ||
84 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_CAP, capabilities); | |
85 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_FLAGS, flags); | |
86 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_MODE, loopback_mode); | |
87 | MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_SPEED, loopback_speed); | |
88 | ||
89 | rc = efx_mcdi_rpc(efx, MC_CMD_SET_LINK, inbuf, sizeof(inbuf), | |
90 | NULL, 0, NULL); | |
91 | if (rc) | |
92 | goto fail; | |
93 | ||
94 | return 0; | |
95 | ||
96 | fail: | |
97 | EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc); | |
98 | return rc; | |
99 | } | |
100 | ||
101 | static int efx_mcdi_loopback_modes(struct efx_nic *efx, u64 *loopback_modes) | |
102 | { | |
103 | u8 outbuf[MC_CMD_GET_LOOPBACK_MODES_OUT_LEN]; | |
104 | size_t outlen; | |
105 | int rc; | |
106 | ||
107 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LOOPBACK_MODES, NULL, 0, | |
108 | outbuf, sizeof(outbuf), &outlen); | |
109 | if (rc) | |
110 | goto fail; | |
111 | ||
112 | if (outlen < MC_CMD_GET_LOOPBACK_MODES_OUT_LEN) { | |
113 | rc = -EMSGSIZE; | |
114 | goto fail; | |
115 | } | |
116 | ||
117 | *loopback_modes = MCDI_QWORD(outbuf, GET_LOOPBACK_MODES_SUGGESTED); | |
118 | ||
119 | return 0; | |
120 | ||
121 | fail: | |
122 | EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc); | |
123 | return rc; | |
124 | } | |
125 | ||
126 | int efx_mcdi_mdio_read(struct efx_nic *efx, unsigned int bus, | |
127 | unsigned int prtad, unsigned int devad, u16 addr, | |
128 | u16 *value_out, u32 *status_out) | |
129 | { | |
130 | u8 inbuf[MC_CMD_MDIO_READ_IN_LEN]; | |
131 | u8 outbuf[MC_CMD_MDIO_READ_OUT_LEN]; | |
132 | size_t outlen; | |
133 | int rc; | |
134 | ||
135 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, bus); | |
136 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad); | |
137 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad); | |
138 | MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr); | |
139 | ||
140 | rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf), | |
141 | outbuf, sizeof(outbuf), &outlen); | |
142 | if (rc) | |
143 | goto fail; | |
144 | ||
145 | *value_out = (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE); | |
146 | *status_out = MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS); | |
147 | return 0; | |
148 | ||
149 | fail: | |
150 | EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc); | |
151 | return rc; | |
152 | } | |
153 | ||
154 | int efx_mcdi_mdio_write(struct efx_nic *efx, unsigned int bus, | |
155 | unsigned int prtad, unsigned int devad, u16 addr, | |
156 | u16 value, u32 *status_out) | |
157 | { | |
158 | u8 inbuf[MC_CMD_MDIO_WRITE_IN_LEN]; | |
159 | u8 outbuf[MC_CMD_MDIO_WRITE_OUT_LEN]; | |
160 | size_t outlen; | |
161 | int rc; | |
162 | ||
163 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, bus); | |
164 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad); | |
165 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad); | |
166 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr); | |
167 | MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value); | |
168 | ||
169 | rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf), | |
170 | outbuf, sizeof(outbuf), &outlen); | |
171 | if (rc) | |
172 | goto fail; | |
173 | ||
174 | *status_out = MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS); | |
175 | return 0; | |
176 | ||
177 | fail: | |
178 | EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc); | |
179 | return rc; | |
180 | } | |
181 | ||
182 | static u32 mcdi_to_ethtool_cap(u32 media, u32 cap) | |
183 | { | |
184 | u32 result = 0; | |
185 | ||
186 | switch (media) { | |
187 | case MC_CMD_MEDIA_KX4: | |
188 | result |= SUPPORTED_Backplane; | |
189 | if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN)) | |
190 | result |= SUPPORTED_1000baseKX_Full; | |
191 | if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN)) | |
192 | result |= SUPPORTED_10000baseKX4_Full; | |
193 | break; | |
194 | ||
195 | case MC_CMD_MEDIA_XFP: | |
196 | case MC_CMD_MEDIA_SFP_PLUS: | |
197 | result |= SUPPORTED_FIBRE; | |
198 | break; | |
199 | ||
200 | case MC_CMD_MEDIA_BASE_T: | |
201 | result |= SUPPORTED_TP; | |
202 | if (cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN)) | |
203 | result |= SUPPORTED_10baseT_Half; | |
204 | if (cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN)) | |
205 | result |= SUPPORTED_10baseT_Full; | |
206 | if (cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN)) | |
207 | result |= SUPPORTED_100baseT_Half; | |
208 | if (cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN)) | |
209 | result |= SUPPORTED_100baseT_Full; | |
210 | if (cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN)) | |
211 | result |= SUPPORTED_1000baseT_Half; | |
212 | if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN)) | |
213 | result |= SUPPORTED_1000baseT_Full; | |
214 | if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN)) | |
215 | result |= SUPPORTED_10000baseT_Full; | |
216 | break; | |
217 | } | |
218 | ||
219 | if (cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN)) | |
220 | result |= SUPPORTED_Pause; | |
221 | if (cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN)) | |
222 | result |= SUPPORTED_Asym_Pause; | |
223 | if (cap & (1 << MC_CMD_PHY_CAP_AN_LBN)) | |
224 | result |= SUPPORTED_Autoneg; | |
225 | ||
226 | return result; | |
227 | } | |
228 | ||
229 | static u32 ethtool_to_mcdi_cap(u32 cap) | |
230 | { | |
231 | u32 result = 0; | |
232 | ||
233 | if (cap & SUPPORTED_10baseT_Half) | |
234 | result |= (1 << MC_CMD_PHY_CAP_10HDX_LBN); | |
235 | if (cap & SUPPORTED_10baseT_Full) | |
236 | result |= (1 << MC_CMD_PHY_CAP_10FDX_LBN); | |
237 | if (cap & SUPPORTED_100baseT_Half) | |
238 | result |= (1 << MC_CMD_PHY_CAP_100HDX_LBN); | |
239 | if (cap & SUPPORTED_100baseT_Full) | |
240 | result |= (1 << MC_CMD_PHY_CAP_100FDX_LBN); | |
241 | if (cap & SUPPORTED_1000baseT_Half) | |
242 | result |= (1 << MC_CMD_PHY_CAP_1000HDX_LBN); | |
243 | if (cap & (SUPPORTED_1000baseT_Full | SUPPORTED_1000baseKX_Full)) | |
244 | result |= (1 << MC_CMD_PHY_CAP_1000FDX_LBN); | |
245 | if (cap & (SUPPORTED_10000baseT_Full | SUPPORTED_10000baseKX4_Full)) | |
246 | result |= (1 << MC_CMD_PHY_CAP_10000FDX_LBN); | |
247 | if (cap & SUPPORTED_Pause) | |
248 | result |= (1 << MC_CMD_PHY_CAP_PAUSE_LBN); | |
249 | if (cap & SUPPORTED_Asym_Pause) | |
250 | result |= (1 << MC_CMD_PHY_CAP_ASYM_LBN); | |
251 | if (cap & SUPPORTED_Autoneg) | |
252 | result |= (1 << MC_CMD_PHY_CAP_AN_LBN); | |
253 | ||
254 | return result; | |
255 | } | |
256 | ||
257 | static u32 efx_get_mcdi_phy_flags(struct efx_nic *efx) | |
258 | { | |
259 | struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data; | |
260 | enum efx_phy_mode mode, supported; | |
261 | u32 flags; | |
262 | ||
263 | /* TODO: Advertise the capabilities supported by this PHY */ | |
264 | supported = 0; | |
265 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_TXDIS_LBN)) | |
266 | supported |= PHY_MODE_TX_DISABLED; | |
267 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_LOWPOWER_LBN)) | |
268 | supported |= PHY_MODE_LOW_POWER; | |
269 | if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_POWEROFF_LBN)) | |
270 | supported |= PHY_MODE_OFF; | |
271 | ||
272 | mode = efx->phy_mode & supported; | |
273 | ||
274 | flags = 0; | |
275 | if (mode & PHY_MODE_TX_DISABLED) | |
276 | flags |= (1 << MC_CMD_SET_LINK_TXDIS_LBN); | |
277 | if (mode & PHY_MODE_LOW_POWER) | |
278 | flags |= (1 << MC_CMD_SET_LINK_LOWPOWER_LBN); | |
279 | if (mode & PHY_MODE_OFF) | |
280 | flags |= (1 << MC_CMD_SET_LINK_POWEROFF_LBN); | |
281 | ||
282 | return flags; | |
283 | } | |
284 | ||
285 | static u32 mcdi_to_ethtool_media(u32 media) | |
286 | { | |
287 | switch (media) { | |
288 | case MC_CMD_MEDIA_XAUI: | |
289 | case MC_CMD_MEDIA_CX4: | |
290 | case MC_CMD_MEDIA_KX4: | |
291 | return PORT_OTHER; | |
292 | ||
293 | case MC_CMD_MEDIA_XFP: | |
294 | case MC_CMD_MEDIA_SFP_PLUS: | |
295 | return PORT_FIBRE; | |
296 | ||
297 | case MC_CMD_MEDIA_BASE_T: | |
298 | return PORT_TP; | |
299 | ||
300 | default: | |
301 | return PORT_OTHER; | |
302 | } | |
303 | } | |
304 | ||
305 | static int efx_mcdi_phy_probe(struct efx_nic *efx) | |
306 | { | |
ff3b00a0 SH |
307 | struct efx_mcdi_phy_cfg *phy_data; |
308 | u8 outbuf[MC_CMD_GET_LINK_OUT_LEN]; | |
309 | u32 caps; | |
afd4aea0 BH |
310 | int rc; |
311 | ||
ff3b00a0 SH |
312 | /* Initialise and populate phy_data */ |
313 | phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL); | |
314 | if (phy_data == NULL) | |
315 | return -ENOMEM; | |
316 | ||
317 | rc = efx_mcdi_get_phy_cfg(efx, phy_data); | |
afd4aea0 BH |
318 | if (rc != 0) |
319 | goto fail; | |
320 | ||
ff3b00a0 SH |
321 | /* Read initial link advertisement */ |
322 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); | |
323 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, | |
324 | outbuf, sizeof(outbuf), NULL); | |
325 | if (rc) | |
326 | goto fail; | |
327 | ||
328 | /* Fill out nic state */ | |
329 | efx->phy_data = phy_data; | |
330 | efx->phy_type = phy_data->type; | |
afd4aea0 | 331 | |
ff3b00a0 SH |
332 | efx->mdio_bus = phy_data->channel; |
333 | efx->mdio.prtad = phy_data->port; | |
334 | efx->mdio.mmds = phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22); | |
afd4aea0 | 335 | efx->mdio.mode_support = 0; |
ff3b00a0 | 336 | if (phy_data->mmd_mask & (1 << MC_CMD_MMD_CLAUSE22)) |
afd4aea0 | 337 | efx->mdio.mode_support |= MDIO_SUPPORTS_C22; |
ff3b00a0 | 338 | if (phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22)) |
afd4aea0 BH |
339 | efx->mdio.mode_support |= MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
340 | ||
ff3b00a0 SH |
341 | caps = MCDI_DWORD(outbuf, GET_LINK_OUT_CAP); |
342 | if (caps & (1 << MC_CMD_PHY_CAP_AN_LBN)) | |
343 | efx->link_advertising = | |
344 | mcdi_to_ethtool_cap(phy_data->media, caps); | |
345 | else | |
346 | phy_data->forced_cap = caps; | |
347 | ||
afd4aea0 BH |
348 | /* Assert that we can map efx -> mcdi loopback modes */ |
349 | BUILD_BUG_ON(LOOPBACK_NONE != MC_CMD_LOOPBACK_NONE); | |
350 | BUILD_BUG_ON(LOOPBACK_DATA != MC_CMD_LOOPBACK_DATA); | |
351 | BUILD_BUG_ON(LOOPBACK_GMAC != MC_CMD_LOOPBACK_GMAC); | |
352 | BUILD_BUG_ON(LOOPBACK_XGMII != MC_CMD_LOOPBACK_XGMII); | |
353 | BUILD_BUG_ON(LOOPBACK_XGXS != MC_CMD_LOOPBACK_XGXS); | |
354 | BUILD_BUG_ON(LOOPBACK_XAUI != MC_CMD_LOOPBACK_XAUI); | |
355 | BUILD_BUG_ON(LOOPBACK_GMII != MC_CMD_LOOPBACK_GMII); | |
356 | BUILD_BUG_ON(LOOPBACK_SGMII != MC_CMD_LOOPBACK_SGMII); | |
357 | BUILD_BUG_ON(LOOPBACK_XGBR != MC_CMD_LOOPBACK_XGBR); | |
358 | BUILD_BUG_ON(LOOPBACK_XFI != MC_CMD_LOOPBACK_XFI); | |
359 | BUILD_BUG_ON(LOOPBACK_XAUI_FAR != MC_CMD_LOOPBACK_XAUI_FAR); | |
360 | BUILD_BUG_ON(LOOPBACK_GMII_FAR != MC_CMD_LOOPBACK_GMII_FAR); | |
361 | BUILD_BUG_ON(LOOPBACK_SGMII_FAR != MC_CMD_LOOPBACK_SGMII_FAR); | |
362 | BUILD_BUG_ON(LOOPBACK_XFI_FAR != MC_CMD_LOOPBACK_XFI_FAR); | |
363 | BUILD_BUG_ON(LOOPBACK_GPHY != MC_CMD_LOOPBACK_GPHY); | |
364 | BUILD_BUG_ON(LOOPBACK_PHYXS != MC_CMD_LOOPBACK_PHYXS); | |
365 | BUILD_BUG_ON(LOOPBACK_PCS != MC_CMD_LOOPBACK_PCS); | |
366 | BUILD_BUG_ON(LOOPBACK_PMAPMD != MC_CMD_LOOPBACK_PMAPMD); | |
367 | BUILD_BUG_ON(LOOPBACK_XPORT != MC_CMD_LOOPBACK_XPORT); | |
368 | BUILD_BUG_ON(LOOPBACK_XGMII_WS != MC_CMD_LOOPBACK_XGMII_WS); | |
369 | BUILD_BUG_ON(LOOPBACK_XAUI_WS != MC_CMD_LOOPBACK_XAUI_WS); | |
370 | BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR != MC_CMD_LOOPBACK_XAUI_WS_FAR); | |
371 | BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR != MC_CMD_LOOPBACK_XAUI_WS_NEAR); | |
372 | BUILD_BUG_ON(LOOPBACK_GMII_WS != MC_CMD_LOOPBACK_GMII_WS); | |
373 | BUILD_BUG_ON(LOOPBACK_XFI_WS != MC_CMD_LOOPBACK_XFI_WS); | |
374 | BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR != MC_CMD_LOOPBACK_XFI_WS_FAR); | |
375 | BUILD_BUG_ON(LOOPBACK_PHYXS_WS != MC_CMD_LOOPBACK_PHYXS_WS); | |
376 | ||
377 | rc = efx_mcdi_loopback_modes(efx, &efx->loopback_modes); | |
378 | if (rc != 0) | |
379 | goto fail; | |
380 | /* The MC indicates that LOOPBACK_NONE is a valid loopback mode, | |
381 | * but by convention we don't */ | |
382 | efx->loopback_modes &= ~(1 << LOOPBACK_NONE); | |
383 | ||
afd4aea0 BH |
384 | return 0; |
385 | ||
386 | fail: | |
387 | kfree(phy_data); | |
388 | return rc; | |
389 | } | |
390 | ||
391 | int efx_mcdi_phy_reconfigure(struct efx_nic *efx) | |
392 | { | |
393 | struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data; | |
394 | u32 caps = (efx->link_advertising ? | |
395 | ethtool_to_mcdi_cap(efx->link_advertising) : | |
396 | phy_cfg->forced_cap); | |
397 | ||
398 | return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx), | |
399 | efx->loopback_mode, 0); | |
400 | } | |
401 | ||
402 | void efx_mcdi_phy_decode_link(struct efx_nic *efx, | |
403 | struct efx_link_state *link_state, | |
404 | u32 speed, u32 flags, u32 fcntl) | |
405 | { | |
406 | switch (fcntl) { | |
407 | case MC_CMD_FCNTL_AUTO: | |
408 | WARN_ON(1); /* This is not a link mode */ | |
409 | link_state->fc = EFX_FC_AUTO | EFX_FC_TX | EFX_FC_RX; | |
410 | break; | |
411 | case MC_CMD_FCNTL_BIDIR: | |
412 | link_state->fc = EFX_FC_TX | EFX_FC_RX; | |
413 | break; | |
414 | case MC_CMD_FCNTL_RESPOND: | |
415 | link_state->fc = EFX_FC_RX; | |
416 | break; | |
417 | default: | |
418 | WARN_ON(1); | |
419 | case MC_CMD_FCNTL_OFF: | |
420 | link_state->fc = 0; | |
421 | break; | |
422 | } | |
423 | ||
424 | link_state->up = !!(flags & (1 << MC_CMD_GET_LINK_LINK_UP_LBN)); | |
425 | link_state->fd = !!(flags & (1 << MC_CMD_GET_LINK_FULL_DUPLEX_LBN)); | |
426 | link_state->speed = speed; | |
427 | } | |
428 | ||
429 | /* Verify that the forced flow control settings (!EFX_FC_AUTO) are | |
430 | * supported by the link partner. Warn the user if this isn't the case | |
431 | */ | |
432 | void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa) | |
433 | { | |
434 | struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data; | |
435 | u32 rmtadv; | |
436 | ||
437 | /* The link partner capabilities are only relevent if the | |
438 | * link supports flow control autonegotiation */ | |
439 | if (~phy_cfg->supported_cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN)) | |
440 | return; | |
441 | ||
442 | /* If flow control autoneg is supported and enabled, then fine */ | |
443 | if (efx->wanted_fc & EFX_FC_AUTO) | |
444 | return; | |
445 | ||
446 | rmtadv = 0; | |
447 | if (lpa & (1 << MC_CMD_PHY_CAP_PAUSE_LBN)) | |
448 | rmtadv |= ADVERTISED_Pause; | |
449 | if (lpa & (1 << MC_CMD_PHY_CAP_ASYM_LBN)) | |
450 | rmtadv |= ADVERTISED_Asym_Pause; | |
451 | ||
452 | if ((efx->wanted_fc & EFX_FC_TX) && rmtadv == ADVERTISED_Asym_Pause) | |
453 | EFX_ERR(efx, "warning: link partner doesn't support " | |
454 | "pause frames"); | |
455 | } | |
456 | ||
457 | static bool efx_mcdi_phy_poll(struct efx_nic *efx) | |
458 | { | |
459 | struct efx_link_state old_state = efx->link_state; | |
460 | u8 outbuf[MC_CMD_GET_LINK_OUT_LEN]; | |
461 | int rc; | |
462 | ||
463 | WARN_ON(!mutex_is_locked(&efx->mac_lock)); | |
464 | ||
465 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); | |
466 | ||
467 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, | |
468 | outbuf, sizeof(outbuf), NULL); | |
469 | if (rc) { | |
470 | EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc); | |
471 | efx->link_state.up = false; | |
472 | } else { | |
473 | efx_mcdi_phy_decode_link( | |
474 | efx, &efx->link_state, | |
475 | MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED), | |
476 | MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS), | |
477 | MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL)); | |
478 | } | |
479 | ||
480 | return !efx_link_state_equal(&efx->link_state, &old_state); | |
481 | } | |
482 | ||
ff3b00a0 | 483 | static void efx_mcdi_phy_remove(struct efx_nic *efx) |
afd4aea0 BH |
484 | { |
485 | struct efx_mcdi_phy_data *phy_data = efx->phy_data; | |
486 | ||
487 | efx->phy_data = NULL; | |
488 | kfree(phy_data); | |
489 | } | |
490 | ||
491 | static void efx_mcdi_phy_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) | |
492 | { | |
493 | struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data; | |
494 | u8 outbuf[MC_CMD_GET_LINK_OUT_LEN]; | |
495 | int rc; | |
496 | ||
497 | ecmd->supported = | |
498 | mcdi_to_ethtool_cap(phy_cfg->media, phy_cfg->supported_cap); | |
499 | ecmd->advertising = efx->link_advertising; | |
500 | ecmd->speed = efx->link_state.speed; | |
501 | ecmd->duplex = efx->link_state.fd; | |
502 | ecmd->port = mcdi_to_ethtool_media(phy_cfg->media); | |
503 | ecmd->phy_address = phy_cfg->port; | |
504 | ecmd->transceiver = XCVR_INTERNAL; | |
505 | ecmd->autoneg = !!(efx->link_advertising & ADVERTISED_Autoneg); | |
506 | ecmd->mdio_support = (efx->mdio.mode_support & | |
507 | (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22)); | |
508 | ||
509 | BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0); | |
510 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0, | |
511 | outbuf, sizeof(outbuf), NULL); | |
512 | if (rc) { | |
513 | EFX_ERR(efx, "%s: failed rc=%d\n", __func__, rc); | |
514 | return; | |
515 | } | |
516 | ecmd->lp_advertising = | |
517 | mcdi_to_ethtool_cap(phy_cfg->media, | |
518 | MCDI_DWORD(outbuf, GET_LINK_OUT_LP_CAP)); | |
519 | } | |
520 | ||
521 | static int efx_mcdi_phy_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd) | |
522 | { | |
523 | struct efx_mcdi_phy_cfg *phy_cfg = efx->phy_data; | |
524 | u32 caps; | |
525 | int rc; | |
526 | ||
527 | if (ecmd->autoneg) { | |
528 | caps = (ethtool_to_mcdi_cap(ecmd->advertising) | | |
529 | 1 << MC_CMD_PHY_CAP_AN_LBN); | |
530 | } else if (ecmd->duplex) { | |
531 | switch (ecmd->speed) { | |
532 | case 10: caps = 1 << MC_CMD_PHY_CAP_10FDX_LBN; break; | |
533 | case 100: caps = 1 << MC_CMD_PHY_CAP_100FDX_LBN; break; | |
534 | case 1000: caps = 1 << MC_CMD_PHY_CAP_1000FDX_LBN; break; | |
535 | case 10000: caps = 1 << MC_CMD_PHY_CAP_10000FDX_LBN; break; | |
536 | default: return -EINVAL; | |
537 | } | |
538 | } else { | |
539 | switch (ecmd->speed) { | |
540 | case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break; | |
541 | case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break; | |
542 | case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break; | |
543 | default: return -EINVAL; | |
544 | } | |
545 | } | |
546 | ||
547 | rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx), | |
548 | efx->loopback_mode, 0); | |
549 | if (rc) | |
550 | return rc; | |
551 | ||
552 | if (ecmd->autoneg) { | |
553 | efx_link_set_advertising( | |
554 | efx, ecmd->advertising | ADVERTISED_Autoneg); | |
555 | phy_cfg->forced_cap = 0; | |
556 | } else { | |
557 | efx_link_set_advertising(efx, 0); | |
558 | phy_cfg->forced_cap = caps; | |
559 | } | |
560 | return 0; | |
561 | } | |
562 | ||
563 | struct efx_phy_operations efx_mcdi_phy_ops = { | |
564 | .probe = efx_mcdi_phy_probe, | |
ff3b00a0 | 565 | .init = efx_port_dummy_op_int, |
afd4aea0 BH |
566 | .reconfigure = efx_mcdi_phy_reconfigure, |
567 | .poll = efx_mcdi_phy_poll, | |
ff3b00a0 SH |
568 | .fini = efx_port_dummy_op_void, |
569 | .remove = efx_mcdi_phy_remove, | |
afd4aea0 BH |
570 | .get_settings = efx_mcdi_phy_get_settings, |
571 | .set_settings = efx_mcdi_phy_set_settings, | |
572 | .run_tests = NULL, | |
573 | .test_name = NULL, | |
574 | }; |