1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2009 Solarflare Communications Inc.
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.
11 * Driver for PHY related operations via MCDI.
14 #include <linux/slab.h>
18 #include "mcdi_pcol.h"
23 struct efx_mcdi_phy_data
{
38 efx_mcdi_get_phy_cfg(struct efx_nic
*efx
, struct efx_mcdi_phy_data
*cfg
)
40 u8 outbuf
[MC_CMD_GET_PHY_CFG_OUT_LEN
];
44 BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN
!= 0);
45 BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN
!= sizeof(cfg
->name
));
47 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PHY_CFG
, NULL
, 0,
48 outbuf
, sizeof(outbuf
), &outlen
);
52 if (outlen
< MC_CMD_GET_PHY_CFG_OUT_LEN
) {
57 cfg
->flags
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_FLAGS
);
58 cfg
->type
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_TYPE
);
60 MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_SUPPORTED_CAP
);
61 cfg
->channel
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_CHANNEL
);
62 cfg
->port
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_PRT
);
63 cfg
->stats_mask
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_STATS_MASK
);
64 memcpy(cfg
->name
, MCDI_PTR(outbuf
, GET_PHY_CFG_OUT_NAME
),
66 cfg
->media
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_MEDIA_TYPE
);
67 cfg
->mmd_mask
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_MMD_MASK
);
68 memcpy(cfg
->revision
, MCDI_PTR(outbuf
, GET_PHY_CFG_OUT_REVISION
),
69 sizeof(cfg
->revision
));
74 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
78 static int efx_mcdi_set_link(struct efx_nic
*efx
, u32 capabilities
,
79 u32 flags
, u32 loopback_mode
,
82 u8 inbuf
[MC_CMD_SET_LINK_IN_LEN
];
85 BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN
!= 0);
87 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_CAP
, capabilities
);
88 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_FLAGS
, flags
);
89 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_LOOPBACK_MODE
, loopback_mode
);
90 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_LOOPBACK_SPEED
, loopback_speed
);
92 rc
= efx_mcdi_rpc(efx
, MC_CMD_SET_LINK
, inbuf
, sizeof(inbuf
),
100 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
104 static int efx_mcdi_loopback_modes(struct efx_nic
*efx
, u64
*loopback_modes
)
106 u8 outbuf
[MC_CMD_GET_LOOPBACK_MODES_OUT_LEN
];
110 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LOOPBACK_MODES
, NULL
, 0,
111 outbuf
, sizeof(outbuf
), &outlen
);
115 if (outlen
< MC_CMD_GET_LOOPBACK_MODES_OUT_LEN
) {
120 *loopback_modes
= MCDI_QWORD(outbuf
, GET_LOOPBACK_MODES_SUGGESTED
);
125 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
129 int efx_mcdi_mdio_read(struct efx_nic
*efx
, unsigned int bus
,
130 unsigned int prtad
, unsigned int devad
, u16 addr
,
131 u16
*value_out
, u32
*status_out
)
133 u8 inbuf
[MC_CMD_MDIO_READ_IN_LEN
];
134 u8 outbuf
[MC_CMD_MDIO_READ_OUT_LEN
];
138 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_BUS
, bus
);
139 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_PRTAD
, prtad
);
140 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_DEVAD
, devad
);
141 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_ADDR
, addr
);
143 rc
= efx_mcdi_rpc(efx
, MC_CMD_MDIO_READ
, inbuf
, sizeof(inbuf
),
144 outbuf
, sizeof(outbuf
), &outlen
);
148 *value_out
= (u16
)MCDI_DWORD(outbuf
, MDIO_READ_OUT_VALUE
);
149 *status_out
= MCDI_DWORD(outbuf
, MDIO_READ_OUT_STATUS
);
153 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
157 int efx_mcdi_mdio_write(struct efx_nic
*efx
, unsigned int bus
,
158 unsigned int prtad
, unsigned int devad
, u16 addr
,
159 u16 value
, u32
*status_out
)
161 u8 inbuf
[MC_CMD_MDIO_WRITE_IN_LEN
];
162 u8 outbuf
[MC_CMD_MDIO_WRITE_OUT_LEN
];
166 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_BUS
, bus
);
167 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_PRTAD
, prtad
);
168 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_DEVAD
, devad
);
169 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_ADDR
, addr
);
170 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_VALUE
, value
);
172 rc
= efx_mcdi_rpc(efx
, MC_CMD_MDIO_WRITE
, inbuf
, sizeof(inbuf
),
173 outbuf
, sizeof(outbuf
), &outlen
);
177 *status_out
= MCDI_DWORD(outbuf
, MDIO_WRITE_OUT_STATUS
);
181 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
185 static u32
mcdi_to_ethtool_cap(u32 media
, u32 cap
)
190 case MC_CMD_MEDIA_KX4
:
191 result
|= SUPPORTED_Backplane
;
192 if (cap
& (1 << MC_CMD_PHY_CAP_1000FDX_LBN
))
193 result
|= SUPPORTED_1000baseKX_Full
;
194 if (cap
& (1 << MC_CMD_PHY_CAP_10000FDX_LBN
))
195 result
|= SUPPORTED_10000baseKX4_Full
;
198 case MC_CMD_MEDIA_XFP
:
199 case MC_CMD_MEDIA_SFP_PLUS
:
200 result
|= SUPPORTED_FIBRE
;
203 case MC_CMD_MEDIA_BASE_T
:
204 result
|= SUPPORTED_TP
;
205 if (cap
& (1 << MC_CMD_PHY_CAP_10HDX_LBN
))
206 result
|= SUPPORTED_10baseT_Half
;
207 if (cap
& (1 << MC_CMD_PHY_CAP_10FDX_LBN
))
208 result
|= SUPPORTED_10baseT_Full
;
209 if (cap
& (1 << MC_CMD_PHY_CAP_100HDX_LBN
))
210 result
|= SUPPORTED_100baseT_Half
;
211 if (cap
& (1 << MC_CMD_PHY_CAP_100FDX_LBN
))
212 result
|= SUPPORTED_100baseT_Full
;
213 if (cap
& (1 << MC_CMD_PHY_CAP_1000HDX_LBN
))
214 result
|= SUPPORTED_1000baseT_Half
;
215 if (cap
& (1 << MC_CMD_PHY_CAP_1000FDX_LBN
))
216 result
|= SUPPORTED_1000baseT_Full
;
217 if (cap
& (1 << MC_CMD_PHY_CAP_10000FDX_LBN
))
218 result
|= SUPPORTED_10000baseT_Full
;
222 if (cap
& (1 << MC_CMD_PHY_CAP_PAUSE_LBN
))
223 result
|= SUPPORTED_Pause
;
224 if (cap
& (1 << MC_CMD_PHY_CAP_ASYM_LBN
))
225 result
|= SUPPORTED_Asym_Pause
;
226 if (cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
227 result
|= SUPPORTED_Autoneg
;
232 static u32
ethtool_to_mcdi_cap(u32 cap
)
236 if (cap
& SUPPORTED_10baseT_Half
)
237 result
|= (1 << MC_CMD_PHY_CAP_10HDX_LBN
);
238 if (cap
& SUPPORTED_10baseT_Full
)
239 result
|= (1 << MC_CMD_PHY_CAP_10FDX_LBN
);
240 if (cap
& SUPPORTED_100baseT_Half
)
241 result
|= (1 << MC_CMD_PHY_CAP_100HDX_LBN
);
242 if (cap
& SUPPORTED_100baseT_Full
)
243 result
|= (1 << MC_CMD_PHY_CAP_100FDX_LBN
);
244 if (cap
& SUPPORTED_1000baseT_Half
)
245 result
|= (1 << MC_CMD_PHY_CAP_1000HDX_LBN
);
246 if (cap
& (SUPPORTED_1000baseT_Full
| SUPPORTED_1000baseKX_Full
))
247 result
|= (1 << MC_CMD_PHY_CAP_1000FDX_LBN
);
248 if (cap
& (SUPPORTED_10000baseT_Full
| SUPPORTED_10000baseKX4_Full
))
249 result
|= (1 << MC_CMD_PHY_CAP_10000FDX_LBN
);
250 if (cap
& SUPPORTED_Pause
)
251 result
|= (1 << MC_CMD_PHY_CAP_PAUSE_LBN
);
252 if (cap
& SUPPORTED_Asym_Pause
)
253 result
|= (1 << MC_CMD_PHY_CAP_ASYM_LBN
);
254 if (cap
& SUPPORTED_Autoneg
)
255 result
|= (1 << MC_CMD_PHY_CAP_AN_LBN
);
260 static u32
efx_get_mcdi_phy_flags(struct efx_nic
*efx
)
262 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
263 enum efx_phy_mode mode
, supported
;
266 /* TODO: Advertise the capabilities supported by this PHY */
268 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_TXDIS_LBN
))
269 supported
|= PHY_MODE_TX_DISABLED
;
270 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_LOWPOWER_LBN
))
271 supported
|= PHY_MODE_LOW_POWER
;
272 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_POWEROFF_LBN
))
273 supported
|= PHY_MODE_OFF
;
275 mode
= efx
->phy_mode
& supported
;
278 if (mode
& PHY_MODE_TX_DISABLED
)
279 flags
|= (1 << MC_CMD_SET_LINK_TXDIS_LBN
);
280 if (mode
& PHY_MODE_LOW_POWER
)
281 flags
|= (1 << MC_CMD_SET_LINK_LOWPOWER_LBN
);
282 if (mode
& PHY_MODE_OFF
)
283 flags
|= (1 << MC_CMD_SET_LINK_POWEROFF_LBN
);
288 static u32
mcdi_to_ethtool_media(u32 media
)
291 case MC_CMD_MEDIA_XAUI
:
292 case MC_CMD_MEDIA_CX4
:
293 case MC_CMD_MEDIA_KX4
:
296 case MC_CMD_MEDIA_XFP
:
297 case MC_CMD_MEDIA_SFP_PLUS
:
300 case MC_CMD_MEDIA_BASE_T
:
308 static int efx_mcdi_phy_probe(struct efx_nic
*efx
)
310 struct efx_mcdi_phy_data
*phy_data
;
311 u8 outbuf
[MC_CMD_GET_LINK_OUT_LEN
];
315 /* Initialise and populate phy_data */
316 phy_data
= kzalloc(sizeof(*phy_data
), GFP_KERNEL
);
317 if (phy_data
== NULL
)
320 rc
= efx_mcdi_get_phy_cfg(efx
, phy_data
);
324 /* Read initial link advertisement */
325 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
326 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
327 outbuf
, sizeof(outbuf
), NULL
);
331 /* Fill out nic state */
332 efx
->phy_data
= phy_data
;
333 efx
->phy_type
= phy_data
->type
;
335 efx
->mdio_bus
= phy_data
->channel
;
336 efx
->mdio
.prtad
= phy_data
->port
;
337 efx
->mdio
.mmds
= phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
);
338 efx
->mdio
.mode_support
= 0;
339 if (phy_data
->mmd_mask
& (1 << MC_CMD_MMD_CLAUSE22
))
340 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C22
;
341 if (phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
))
342 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
344 caps
= MCDI_DWORD(outbuf
, GET_LINK_OUT_CAP
);
345 if (caps
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
346 efx
->link_advertising
=
347 mcdi_to_ethtool_cap(phy_data
->media
, caps
);
349 phy_data
->forced_cap
= caps
;
351 /* Assert that we can map efx -> mcdi loopback modes */
352 BUILD_BUG_ON(LOOPBACK_NONE
!= MC_CMD_LOOPBACK_NONE
);
353 BUILD_BUG_ON(LOOPBACK_DATA
!= MC_CMD_LOOPBACK_DATA
);
354 BUILD_BUG_ON(LOOPBACK_GMAC
!= MC_CMD_LOOPBACK_GMAC
);
355 BUILD_BUG_ON(LOOPBACK_XGMII
!= MC_CMD_LOOPBACK_XGMII
);
356 BUILD_BUG_ON(LOOPBACK_XGXS
!= MC_CMD_LOOPBACK_XGXS
);
357 BUILD_BUG_ON(LOOPBACK_XAUI
!= MC_CMD_LOOPBACK_XAUI
);
358 BUILD_BUG_ON(LOOPBACK_GMII
!= MC_CMD_LOOPBACK_GMII
);
359 BUILD_BUG_ON(LOOPBACK_SGMII
!= MC_CMD_LOOPBACK_SGMII
);
360 BUILD_BUG_ON(LOOPBACK_XGBR
!= MC_CMD_LOOPBACK_XGBR
);
361 BUILD_BUG_ON(LOOPBACK_XFI
!= MC_CMD_LOOPBACK_XFI
);
362 BUILD_BUG_ON(LOOPBACK_XAUI_FAR
!= MC_CMD_LOOPBACK_XAUI_FAR
);
363 BUILD_BUG_ON(LOOPBACK_GMII_FAR
!= MC_CMD_LOOPBACK_GMII_FAR
);
364 BUILD_BUG_ON(LOOPBACK_SGMII_FAR
!= MC_CMD_LOOPBACK_SGMII_FAR
);
365 BUILD_BUG_ON(LOOPBACK_XFI_FAR
!= MC_CMD_LOOPBACK_XFI_FAR
);
366 BUILD_BUG_ON(LOOPBACK_GPHY
!= MC_CMD_LOOPBACK_GPHY
);
367 BUILD_BUG_ON(LOOPBACK_PHYXS
!= MC_CMD_LOOPBACK_PHYXS
);
368 BUILD_BUG_ON(LOOPBACK_PCS
!= MC_CMD_LOOPBACK_PCS
);
369 BUILD_BUG_ON(LOOPBACK_PMAPMD
!= MC_CMD_LOOPBACK_PMAPMD
);
370 BUILD_BUG_ON(LOOPBACK_XPORT
!= MC_CMD_LOOPBACK_XPORT
);
371 BUILD_BUG_ON(LOOPBACK_XGMII_WS
!= MC_CMD_LOOPBACK_XGMII_WS
);
372 BUILD_BUG_ON(LOOPBACK_XAUI_WS
!= MC_CMD_LOOPBACK_XAUI_WS
);
373 BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR
!= MC_CMD_LOOPBACK_XAUI_WS_FAR
);
374 BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR
!= MC_CMD_LOOPBACK_XAUI_WS_NEAR
);
375 BUILD_BUG_ON(LOOPBACK_GMII_WS
!= MC_CMD_LOOPBACK_GMII_WS
);
376 BUILD_BUG_ON(LOOPBACK_XFI_WS
!= MC_CMD_LOOPBACK_XFI_WS
);
377 BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR
!= MC_CMD_LOOPBACK_XFI_WS_FAR
);
378 BUILD_BUG_ON(LOOPBACK_PHYXS_WS
!= MC_CMD_LOOPBACK_PHYXS_WS
);
380 rc
= efx_mcdi_loopback_modes(efx
, &efx
->loopback_modes
);
383 /* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
384 * but by convention we don't */
385 efx
->loopback_modes
&= ~(1 << LOOPBACK_NONE
);
387 /* Set the initial link mode */
388 efx_mcdi_phy_decode_link(
389 efx
, &efx
->link_state
,
390 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
391 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
392 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
394 /* Default to Autonegotiated flow control if the PHY supports it */
395 efx
->wanted_fc
= EFX_FC_RX
| EFX_FC_TX
;
396 if (phy_data
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
397 efx
->wanted_fc
|= EFX_FC_AUTO
;
398 efx_link_set_wanted_fc(efx
, efx
->wanted_fc
);
407 int efx_mcdi_phy_reconfigure(struct efx_nic
*efx
)
409 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
410 u32 caps
= (efx
->link_advertising
?
411 ethtool_to_mcdi_cap(efx
->link_advertising
) :
412 phy_cfg
->forced_cap
);
414 return efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
415 efx
->loopback_mode
, 0);
418 void efx_mcdi_phy_decode_link(struct efx_nic
*efx
,
419 struct efx_link_state
*link_state
,
420 u32 speed
, u32 flags
, u32 fcntl
)
423 case MC_CMD_FCNTL_AUTO
:
424 WARN_ON(1); /* This is not a link mode */
425 link_state
->fc
= EFX_FC_AUTO
| EFX_FC_TX
| EFX_FC_RX
;
427 case MC_CMD_FCNTL_BIDIR
:
428 link_state
->fc
= EFX_FC_TX
| EFX_FC_RX
;
430 case MC_CMD_FCNTL_RESPOND
:
431 link_state
->fc
= EFX_FC_RX
;
435 case MC_CMD_FCNTL_OFF
:
440 link_state
->up
= !!(flags
& (1 << MC_CMD_GET_LINK_LINK_UP_LBN
));
441 link_state
->fd
= !!(flags
& (1 << MC_CMD_GET_LINK_FULL_DUPLEX_LBN
));
442 link_state
->speed
= speed
;
445 /* Verify that the forced flow control settings (!EFX_FC_AUTO) are
446 * supported by the link partner. Warn the user if this isn't the case
448 void efx_mcdi_phy_check_fcntl(struct efx_nic
*efx
, u32 lpa
)
450 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
453 /* The link partner capabilities are only relevent if the
454 * link supports flow control autonegotiation */
455 if (~phy_cfg
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
458 /* If flow control autoneg is supported and enabled, then fine */
459 if (efx
->wanted_fc
& EFX_FC_AUTO
)
463 if (lpa
& (1 << MC_CMD_PHY_CAP_PAUSE_LBN
))
464 rmtadv
|= ADVERTISED_Pause
;
465 if (lpa
& (1 << MC_CMD_PHY_CAP_ASYM_LBN
))
466 rmtadv
|= ADVERTISED_Asym_Pause
;
468 if ((efx
->wanted_fc
& EFX_FC_TX
) && rmtadv
== ADVERTISED_Asym_Pause
)
469 netif_err(efx
, link
, efx
->net_dev
,
470 "warning: link partner doesn't support pause frames");
473 static bool efx_mcdi_phy_poll(struct efx_nic
*efx
)
475 struct efx_link_state old_state
= efx
->link_state
;
476 u8 outbuf
[MC_CMD_GET_LINK_OUT_LEN
];
479 WARN_ON(!mutex_is_locked(&efx
->mac_lock
));
481 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
483 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
484 outbuf
, sizeof(outbuf
), NULL
);
486 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n",
488 efx
->link_state
.up
= false;
490 efx_mcdi_phy_decode_link(
491 efx
, &efx
->link_state
,
492 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
493 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
494 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
497 return !efx_link_state_equal(&efx
->link_state
, &old_state
);
500 static void efx_mcdi_phy_remove(struct efx_nic
*efx
)
502 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
504 efx
->phy_data
= NULL
;
508 static void efx_mcdi_phy_get_settings(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
510 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
511 u8 outbuf
[MC_CMD_GET_LINK_OUT_LEN
];
515 mcdi_to_ethtool_cap(phy_cfg
->media
, phy_cfg
->supported_cap
);
516 ecmd
->advertising
= efx
->link_advertising
;
517 ecmd
->speed
= efx
->link_state
.speed
;
518 ecmd
->duplex
= efx
->link_state
.fd
;
519 ecmd
->port
= mcdi_to_ethtool_media(phy_cfg
->media
);
520 ecmd
->phy_address
= phy_cfg
->port
;
521 ecmd
->transceiver
= XCVR_INTERNAL
;
522 ecmd
->autoneg
= !!(efx
->link_advertising
& ADVERTISED_Autoneg
);
523 ecmd
->mdio_support
= (efx
->mdio
.mode_support
&
524 (MDIO_SUPPORTS_C45
| MDIO_SUPPORTS_C22
));
526 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
527 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
528 outbuf
, sizeof(outbuf
), NULL
);
530 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n",
534 ecmd
->lp_advertising
=
535 mcdi_to_ethtool_cap(phy_cfg
->media
,
536 MCDI_DWORD(outbuf
, GET_LINK_OUT_LP_CAP
));
539 static int efx_mcdi_phy_set_settings(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
541 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
546 caps
= (ethtool_to_mcdi_cap(ecmd
->advertising
) |
547 1 << MC_CMD_PHY_CAP_AN_LBN
);
548 } else if (ecmd
->duplex
) {
549 switch (ecmd
->speed
) {
550 case 10: caps
= 1 << MC_CMD_PHY_CAP_10FDX_LBN
; break;
551 case 100: caps
= 1 << MC_CMD_PHY_CAP_100FDX_LBN
; break;
552 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000FDX_LBN
; break;
553 case 10000: caps
= 1 << MC_CMD_PHY_CAP_10000FDX_LBN
; break;
554 default: return -EINVAL
;
557 switch (ecmd
->speed
) {
558 case 10: caps
= 1 << MC_CMD_PHY_CAP_10HDX_LBN
; break;
559 case 100: caps
= 1 << MC_CMD_PHY_CAP_100HDX_LBN
; break;
560 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000HDX_LBN
; break;
561 default: return -EINVAL
;
565 rc
= efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
566 efx
->loopback_mode
, 0);
571 efx_link_set_advertising(
572 efx
, ecmd
->advertising
| ADVERTISED_Autoneg
);
573 phy_cfg
->forced_cap
= 0;
575 efx_link_set_advertising(efx
, 0);
576 phy_cfg
->forced_cap
= caps
;
581 static int efx_mcdi_phy_test_alive(struct efx_nic
*efx
)
583 u8 outbuf
[MC_CMD_GET_PHY_STATE_OUT_LEN
];
587 BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN
!= 0);
589 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PHY_STATE
, NULL
, 0,
590 outbuf
, sizeof(outbuf
), &outlen
);
594 if (outlen
< MC_CMD_GET_PHY_STATE_OUT_LEN
)
596 if (MCDI_DWORD(outbuf
, GET_PHY_STATE_STATE
) != MC_CMD_PHY_STATE_OK
)
602 static const char *const mcdi_sft9001_cable_diag_names
[] = {
603 "cable.pairA.length",
604 "cable.pairB.length",
605 "cable.pairC.length",
606 "cable.pairD.length",
607 "cable.pairA.status",
608 "cable.pairB.status",
609 "cable.pairC.status",
610 "cable.pairD.status",
613 static int efx_mcdi_bist(struct efx_nic
*efx
, unsigned int bist_mode
,
616 unsigned int retry
, i
, count
= 0;
622 buf
= kzalloc(0x100, GFP_KERNEL
);
626 BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN
!= 0);
627 MCDI_SET_DWORD(buf
, START_BIST_IN_TYPE
, bist_mode
);
628 rc
= efx_mcdi_rpc(efx
, MC_CMD_START_BIST
, buf
, MC_CMD_START_BIST_IN_LEN
,
633 /* Wait up to 10s for BIST to finish */
634 for (retry
= 0; retry
< 100; ++retry
) {
635 BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN
!= 0);
636 rc
= efx_mcdi_rpc(efx
, MC_CMD_POLL_BIST
, NULL
, 0,
637 buf
, 0x100, &outlen
);
641 status
= MCDI_DWORD(buf
, POLL_BIST_OUT_RESULT
);
642 if (status
!= MC_CMD_POLL_BIST_RUNNING
)
652 results
[count
++] = (status
== MC_CMD_POLL_BIST_PASSED
) ? 1 : -1;
654 /* SFT9001 specific cable diagnostics output */
655 if (efx
->phy_type
== PHY_TYPE_SFT9001B
&&
656 (bist_mode
== MC_CMD_PHY_BIST_CABLE_SHORT
||
657 bist_mode
== MC_CMD_PHY_BIST_CABLE_LONG
)) {
658 ptr
= MCDI_PTR(buf
, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A
);
659 if (status
== MC_CMD_POLL_BIST_PASSED
&&
660 outlen
>= MC_CMD_POLL_BIST_OUT_SFT9001_LEN
) {
661 for (i
= 0; i
< 8; i
++) {
663 EFX_DWORD_FIELD(((efx_dword_t
*)ptr
)[i
],
677 static int efx_mcdi_phy_run_tests(struct efx_nic
*efx
, int *results
,
680 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
684 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_BIST_LBN
)) {
685 rc
= efx_mcdi_bist(efx
, MC_CMD_PHY_BIST
, results
);
692 /* If we support both LONG and SHORT, then run each in response to
693 * break or not. Otherwise, run the one we support */
695 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_BIST_CABLE_SHORT_LBN
)) {
696 if ((flags
& ETH_TEST_FL_OFFLINE
) &&
698 (1 << MC_CMD_GET_PHY_CFG_BIST_CABLE_LONG_LBN
)))
699 mode
= MC_CMD_PHY_BIST_CABLE_LONG
;
701 mode
= MC_CMD_PHY_BIST_CABLE_SHORT
;
702 } else if (phy_cfg
->flags
&
703 (1 << MC_CMD_GET_PHY_CFG_BIST_CABLE_LONG_LBN
))
704 mode
= MC_CMD_PHY_BIST_CABLE_LONG
;
707 rc
= efx_mcdi_bist(efx
, mode
, results
);
716 const char *efx_mcdi_phy_test_name(struct efx_nic
*efx
, unsigned int index
)
718 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
720 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_BIST_LBN
)) {
726 if (phy_cfg
->flags
& ((1 << MC_CMD_GET_PHY_CFG_BIST_CABLE_SHORT_LBN
) |
727 (1 << MC_CMD_GET_PHY_CFG_BIST_CABLE_LONG_LBN
))) {
732 if (efx
->phy_type
== PHY_TYPE_SFT9001B
) {
733 if (index
< ARRAY_SIZE(mcdi_sft9001_cable_diag_names
))
734 return mcdi_sft9001_cable_diag_names
[index
];
735 index
-= ARRAY_SIZE(mcdi_sft9001_cable_diag_names
);
742 struct efx_phy_operations efx_mcdi_phy_ops
= {
743 .probe
= efx_mcdi_phy_probe
,
744 .init
= efx_port_dummy_op_int
,
745 .reconfigure
= efx_mcdi_phy_reconfigure
,
746 .poll
= efx_mcdi_phy_poll
,
747 .fini
= efx_port_dummy_op_void
,
748 .remove
= efx_mcdi_phy_remove
,
749 .get_settings
= efx_mcdi_phy_get_settings
,
750 .set_settings
= efx_mcdi_phy_set_settings
,
751 .test_alive
= efx_mcdi_phy_test_alive
,
752 .run_tests
= efx_mcdi_phy_run_tests
,
753 .test_name
= efx_mcdi_phy_test_name
,