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"
21 struct efx_mcdi_phy_cfg
{
36 efx_mcdi_get_phy_cfg(struct efx_nic
*efx
, struct efx_mcdi_phy_cfg
*cfg
)
38 u8 outbuf
[MC_CMD_GET_PHY_CFG_OUT_LEN
];
42 BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN
!= 0);
43 BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN
!= sizeof(cfg
->name
));
45 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PHY_CFG
, NULL
, 0,
46 outbuf
, sizeof(outbuf
), &outlen
);
50 if (outlen
< MC_CMD_GET_PHY_CFG_OUT_LEN
) {
55 cfg
->flags
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_FLAGS
);
56 cfg
->type
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_TYPE
);
58 MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_SUPPORTED_CAP
);
59 cfg
->channel
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_CHANNEL
);
60 cfg
->port
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_PRT
);
61 cfg
->stats_mask
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_STATS_MASK
);
62 memcpy(cfg
->name
, MCDI_PTR(outbuf
, GET_PHY_CFG_OUT_NAME
),
64 cfg
->media
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_MEDIA_TYPE
);
65 cfg
->mmd_mask
= MCDI_DWORD(outbuf
, GET_PHY_CFG_OUT_MMD_MASK
);
66 memcpy(cfg
->revision
, MCDI_PTR(outbuf
, GET_PHY_CFG_OUT_REVISION
),
67 sizeof(cfg
->revision
));
72 EFX_ERR(efx
, "%s: failed rc=%d\n", __func__
, rc
);
76 static int efx_mcdi_set_link(struct efx_nic
*efx
, u32 capabilities
,
77 u32 flags
, u32 loopback_mode
,
80 u8 inbuf
[MC_CMD_SET_LINK_IN_LEN
];
83 BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN
!= 0);
85 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_CAP
, capabilities
);
86 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_FLAGS
, flags
);
87 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_LOOPBACK_MODE
, loopback_mode
);
88 MCDI_SET_DWORD(inbuf
, SET_LINK_IN_LOOPBACK_SPEED
, loopback_speed
);
90 rc
= efx_mcdi_rpc(efx
, MC_CMD_SET_LINK
, inbuf
, sizeof(inbuf
),
98 EFX_ERR(efx
, "%s: failed rc=%d\n", __func__
, rc
);
102 static int efx_mcdi_loopback_modes(struct efx_nic
*efx
, u64
*loopback_modes
)
104 u8 outbuf
[MC_CMD_GET_LOOPBACK_MODES_OUT_LEN
];
108 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LOOPBACK_MODES
, NULL
, 0,
109 outbuf
, sizeof(outbuf
), &outlen
);
113 if (outlen
< MC_CMD_GET_LOOPBACK_MODES_OUT_LEN
) {
118 *loopback_modes
= MCDI_QWORD(outbuf
, GET_LOOPBACK_MODES_SUGGESTED
);
123 EFX_ERR(efx
, "%s: failed rc=%d\n", __func__
, rc
);
127 int efx_mcdi_mdio_read(struct efx_nic
*efx
, unsigned int bus
,
128 unsigned int prtad
, unsigned int devad
, u16 addr
,
129 u16
*value_out
, u32
*status_out
)
131 u8 inbuf
[MC_CMD_MDIO_READ_IN_LEN
];
132 u8 outbuf
[MC_CMD_MDIO_READ_OUT_LEN
];
136 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_BUS
, bus
);
137 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_PRTAD
, prtad
);
138 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_DEVAD
, devad
);
139 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_ADDR
, addr
);
141 rc
= efx_mcdi_rpc(efx
, MC_CMD_MDIO_READ
, inbuf
, sizeof(inbuf
),
142 outbuf
, sizeof(outbuf
), &outlen
);
146 *value_out
= (u16
)MCDI_DWORD(outbuf
, MDIO_READ_OUT_VALUE
);
147 *status_out
= MCDI_DWORD(outbuf
, MDIO_READ_OUT_STATUS
);
151 EFX_ERR(efx
, "%s: failed rc=%d\n", __func__
, rc
);
155 int efx_mcdi_mdio_write(struct efx_nic
*efx
, unsigned int bus
,
156 unsigned int prtad
, unsigned int devad
, u16 addr
,
157 u16 value
, u32
*status_out
)
159 u8 inbuf
[MC_CMD_MDIO_WRITE_IN_LEN
];
160 u8 outbuf
[MC_CMD_MDIO_WRITE_OUT_LEN
];
164 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_BUS
, bus
);
165 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_PRTAD
, prtad
);
166 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_DEVAD
, devad
);
167 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_ADDR
, addr
);
168 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_VALUE
, value
);
170 rc
= efx_mcdi_rpc(efx
, MC_CMD_MDIO_WRITE
, inbuf
, sizeof(inbuf
),
171 outbuf
, sizeof(outbuf
), &outlen
);
175 *status_out
= MCDI_DWORD(outbuf
, MDIO_WRITE_OUT_STATUS
);
179 EFX_ERR(efx
, "%s: failed rc=%d\n", __func__
, rc
);
183 static u32
mcdi_to_ethtool_cap(u32 media
, u32 cap
)
188 case MC_CMD_MEDIA_KX4
:
189 result
|= SUPPORTED_Backplane
;
190 if (cap
& (1 << MC_CMD_PHY_CAP_1000FDX_LBN
))
191 result
|= SUPPORTED_1000baseKX_Full
;
192 if (cap
& (1 << MC_CMD_PHY_CAP_10000FDX_LBN
))
193 result
|= SUPPORTED_10000baseKX4_Full
;
196 case MC_CMD_MEDIA_XFP
:
197 case MC_CMD_MEDIA_SFP_PLUS
:
198 result
|= SUPPORTED_FIBRE
;
201 case MC_CMD_MEDIA_BASE_T
:
202 result
|= SUPPORTED_TP
;
203 if (cap
& (1 << MC_CMD_PHY_CAP_10HDX_LBN
))
204 result
|= SUPPORTED_10baseT_Half
;
205 if (cap
& (1 << MC_CMD_PHY_CAP_10FDX_LBN
))
206 result
|= SUPPORTED_10baseT_Full
;
207 if (cap
& (1 << MC_CMD_PHY_CAP_100HDX_LBN
))
208 result
|= SUPPORTED_100baseT_Half
;
209 if (cap
& (1 << MC_CMD_PHY_CAP_100FDX_LBN
))
210 result
|= SUPPORTED_100baseT_Full
;
211 if (cap
& (1 << MC_CMD_PHY_CAP_1000HDX_LBN
))
212 result
|= SUPPORTED_1000baseT_Half
;
213 if (cap
& (1 << MC_CMD_PHY_CAP_1000FDX_LBN
))
214 result
|= SUPPORTED_1000baseT_Full
;
215 if (cap
& (1 << MC_CMD_PHY_CAP_10000FDX_LBN
))
216 result
|= SUPPORTED_10000baseT_Full
;
220 if (cap
& (1 << MC_CMD_PHY_CAP_PAUSE_LBN
))
221 result
|= SUPPORTED_Pause
;
222 if (cap
& (1 << MC_CMD_PHY_CAP_ASYM_LBN
))
223 result
|= SUPPORTED_Asym_Pause
;
224 if (cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
225 result
|= SUPPORTED_Autoneg
;
230 static u32
ethtool_to_mcdi_cap(u32 cap
)
234 if (cap
& SUPPORTED_10baseT_Half
)
235 result
|= (1 << MC_CMD_PHY_CAP_10HDX_LBN
);
236 if (cap
& SUPPORTED_10baseT_Full
)
237 result
|= (1 << MC_CMD_PHY_CAP_10FDX_LBN
);
238 if (cap
& SUPPORTED_100baseT_Half
)
239 result
|= (1 << MC_CMD_PHY_CAP_100HDX_LBN
);
240 if (cap
& SUPPORTED_100baseT_Full
)
241 result
|= (1 << MC_CMD_PHY_CAP_100FDX_LBN
);
242 if (cap
& SUPPORTED_1000baseT_Half
)
243 result
|= (1 << MC_CMD_PHY_CAP_1000HDX_LBN
);
244 if (cap
& (SUPPORTED_1000baseT_Full
| SUPPORTED_1000baseKX_Full
))
245 result
|= (1 << MC_CMD_PHY_CAP_1000FDX_LBN
);
246 if (cap
& (SUPPORTED_10000baseT_Full
| SUPPORTED_10000baseKX4_Full
))
247 result
|= (1 << MC_CMD_PHY_CAP_10000FDX_LBN
);
248 if (cap
& SUPPORTED_Pause
)
249 result
|= (1 << MC_CMD_PHY_CAP_PAUSE_LBN
);
250 if (cap
& SUPPORTED_Asym_Pause
)
251 result
|= (1 << MC_CMD_PHY_CAP_ASYM_LBN
);
252 if (cap
& SUPPORTED_Autoneg
)
253 result
|= (1 << MC_CMD_PHY_CAP_AN_LBN
);
258 static u32
efx_get_mcdi_phy_flags(struct efx_nic
*efx
)
260 struct efx_mcdi_phy_cfg
*phy_cfg
= efx
->phy_data
;
261 enum efx_phy_mode mode
, supported
;
264 /* TODO: Advertise the capabilities supported by this PHY */
266 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_TXDIS_LBN
))
267 supported
|= PHY_MODE_TX_DISABLED
;
268 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_LOWPOWER_LBN
))
269 supported
|= PHY_MODE_LOW_POWER
;
270 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_POWEROFF_LBN
))
271 supported
|= PHY_MODE_OFF
;
273 mode
= efx
->phy_mode
& supported
;
276 if (mode
& PHY_MODE_TX_DISABLED
)
277 flags
|= (1 << MC_CMD_SET_LINK_TXDIS_LBN
);
278 if (mode
& PHY_MODE_LOW_POWER
)
279 flags
|= (1 << MC_CMD_SET_LINK_LOWPOWER_LBN
);
280 if (mode
& PHY_MODE_OFF
)
281 flags
|= (1 << MC_CMD_SET_LINK_POWEROFF_LBN
);
286 static u32
mcdi_to_ethtool_media(u32 media
)
289 case MC_CMD_MEDIA_XAUI
:
290 case MC_CMD_MEDIA_CX4
:
291 case MC_CMD_MEDIA_KX4
:
294 case MC_CMD_MEDIA_XFP
:
295 case MC_CMD_MEDIA_SFP_PLUS
:
298 case MC_CMD_MEDIA_BASE_T
:
306 static int efx_mcdi_phy_probe(struct efx_nic
*efx
)
308 struct efx_mcdi_phy_cfg
*phy_data
;
309 u8 outbuf
[MC_CMD_GET_LINK_OUT_LEN
];
313 /* Initialise and populate phy_data */
314 phy_data
= kzalloc(sizeof(*phy_data
), GFP_KERNEL
);
315 if (phy_data
== NULL
)
318 rc
= efx_mcdi_get_phy_cfg(efx
, phy_data
);
322 /* Read initial link advertisement */
323 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
324 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
325 outbuf
, sizeof(outbuf
), NULL
);
329 /* Fill out nic state */
330 efx
->phy_data
= phy_data
;
331 efx
->phy_type
= phy_data
->type
;
333 efx
->mdio_bus
= phy_data
->channel
;
334 efx
->mdio
.prtad
= phy_data
->port
;
335 efx
->mdio
.mmds
= phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
);
336 efx
->mdio
.mode_support
= 0;
337 if (phy_data
->mmd_mask
& (1 << MC_CMD_MMD_CLAUSE22
))
338 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C22
;
339 if (phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
))
340 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
342 caps
= MCDI_DWORD(outbuf
, GET_LINK_OUT_CAP
);
343 if (caps
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
344 efx
->link_advertising
=
345 mcdi_to_ethtool_cap(phy_data
->media
, caps
);
347 phy_data
->forced_cap
= caps
;
349 /* Assert that we can map efx -> mcdi loopback modes */
350 BUILD_BUG_ON(LOOPBACK_NONE
!= MC_CMD_LOOPBACK_NONE
);
351 BUILD_BUG_ON(LOOPBACK_DATA
!= MC_CMD_LOOPBACK_DATA
);
352 BUILD_BUG_ON(LOOPBACK_GMAC
!= MC_CMD_LOOPBACK_GMAC
);
353 BUILD_BUG_ON(LOOPBACK_XGMII
!= MC_CMD_LOOPBACK_XGMII
);
354 BUILD_BUG_ON(LOOPBACK_XGXS
!= MC_CMD_LOOPBACK_XGXS
);
355 BUILD_BUG_ON(LOOPBACK_XAUI
!= MC_CMD_LOOPBACK_XAUI
);
356 BUILD_BUG_ON(LOOPBACK_GMII
!= MC_CMD_LOOPBACK_GMII
);
357 BUILD_BUG_ON(LOOPBACK_SGMII
!= MC_CMD_LOOPBACK_SGMII
);
358 BUILD_BUG_ON(LOOPBACK_XGBR
!= MC_CMD_LOOPBACK_XGBR
);
359 BUILD_BUG_ON(LOOPBACK_XFI
!= MC_CMD_LOOPBACK_XFI
);
360 BUILD_BUG_ON(LOOPBACK_XAUI_FAR
!= MC_CMD_LOOPBACK_XAUI_FAR
);
361 BUILD_BUG_ON(LOOPBACK_GMII_FAR
!= MC_CMD_LOOPBACK_GMII_FAR
);
362 BUILD_BUG_ON(LOOPBACK_SGMII_FAR
!= MC_CMD_LOOPBACK_SGMII_FAR
);
363 BUILD_BUG_ON(LOOPBACK_XFI_FAR
!= MC_CMD_LOOPBACK_XFI_FAR
);
364 BUILD_BUG_ON(LOOPBACK_GPHY
!= MC_CMD_LOOPBACK_GPHY
);
365 BUILD_BUG_ON(LOOPBACK_PHYXS
!= MC_CMD_LOOPBACK_PHYXS
);
366 BUILD_BUG_ON(LOOPBACK_PCS
!= MC_CMD_LOOPBACK_PCS
);
367 BUILD_BUG_ON(LOOPBACK_PMAPMD
!= MC_CMD_LOOPBACK_PMAPMD
);
368 BUILD_BUG_ON(LOOPBACK_XPORT
!= MC_CMD_LOOPBACK_XPORT
);
369 BUILD_BUG_ON(LOOPBACK_XGMII_WS
!= MC_CMD_LOOPBACK_XGMII_WS
);
370 BUILD_BUG_ON(LOOPBACK_XAUI_WS
!= MC_CMD_LOOPBACK_XAUI_WS
);
371 BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR
!= MC_CMD_LOOPBACK_XAUI_WS_FAR
);
372 BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR
!= MC_CMD_LOOPBACK_XAUI_WS_NEAR
);
373 BUILD_BUG_ON(LOOPBACK_GMII_WS
!= MC_CMD_LOOPBACK_GMII_WS
);
374 BUILD_BUG_ON(LOOPBACK_XFI_WS
!= MC_CMD_LOOPBACK_XFI_WS
);
375 BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR
!= MC_CMD_LOOPBACK_XFI_WS_FAR
);
376 BUILD_BUG_ON(LOOPBACK_PHYXS_WS
!= MC_CMD_LOOPBACK_PHYXS_WS
);
378 rc
= efx_mcdi_loopback_modes(efx
, &efx
->loopback_modes
);
381 /* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
382 * but by convention we don't */
383 efx
->loopback_modes
&= ~(1 << LOOPBACK_NONE
);
385 /* Set the initial link mode */
386 efx_mcdi_phy_decode_link(
387 efx
, &efx
->link_state
,
388 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
389 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
390 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
392 /* Default to Autonegotiated flow control if the PHY supports it */
393 efx
->wanted_fc
= EFX_FC_RX
| EFX_FC_TX
;
394 if (phy_data
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
395 efx
->wanted_fc
|= EFX_FC_AUTO
;
404 int efx_mcdi_phy_reconfigure(struct efx_nic
*efx
)
406 struct efx_mcdi_phy_cfg
*phy_cfg
= efx
->phy_data
;
407 u32 caps
= (efx
->link_advertising
?
408 ethtool_to_mcdi_cap(efx
->link_advertising
) :
409 phy_cfg
->forced_cap
);
411 return efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
412 efx
->loopback_mode
, 0);
415 void efx_mcdi_phy_decode_link(struct efx_nic
*efx
,
416 struct efx_link_state
*link_state
,
417 u32 speed
, u32 flags
, u32 fcntl
)
420 case MC_CMD_FCNTL_AUTO
:
421 WARN_ON(1); /* This is not a link mode */
422 link_state
->fc
= EFX_FC_AUTO
| EFX_FC_TX
| EFX_FC_RX
;
424 case MC_CMD_FCNTL_BIDIR
:
425 link_state
->fc
= EFX_FC_TX
| EFX_FC_RX
;
427 case MC_CMD_FCNTL_RESPOND
:
428 link_state
->fc
= EFX_FC_RX
;
432 case MC_CMD_FCNTL_OFF
:
437 link_state
->up
= !!(flags
& (1 << MC_CMD_GET_LINK_LINK_UP_LBN
));
438 link_state
->fd
= !!(flags
& (1 << MC_CMD_GET_LINK_FULL_DUPLEX_LBN
));
439 link_state
->speed
= speed
;
442 /* Verify that the forced flow control settings (!EFX_FC_AUTO) are
443 * supported by the link partner. Warn the user if this isn't the case
445 void efx_mcdi_phy_check_fcntl(struct efx_nic
*efx
, u32 lpa
)
447 struct efx_mcdi_phy_cfg
*phy_cfg
= efx
->phy_data
;
450 /* The link partner capabilities are only relevent if the
451 * link supports flow control autonegotiation */
452 if (~phy_cfg
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
455 /* If flow control autoneg is supported and enabled, then fine */
456 if (efx
->wanted_fc
& EFX_FC_AUTO
)
460 if (lpa
& (1 << MC_CMD_PHY_CAP_PAUSE_LBN
))
461 rmtadv
|= ADVERTISED_Pause
;
462 if (lpa
& (1 << MC_CMD_PHY_CAP_ASYM_LBN
))
463 rmtadv
|= ADVERTISED_Asym_Pause
;
465 if ((efx
->wanted_fc
& EFX_FC_TX
) && rmtadv
== ADVERTISED_Asym_Pause
)
466 EFX_ERR(efx
, "warning: link partner doesn't support "
470 static bool efx_mcdi_phy_poll(struct efx_nic
*efx
)
472 struct efx_link_state old_state
= efx
->link_state
;
473 u8 outbuf
[MC_CMD_GET_LINK_OUT_LEN
];
476 WARN_ON(!mutex_is_locked(&efx
->mac_lock
));
478 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
480 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
481 outbuf
, sizeof(outbuf
), NULL
);
483 EFX_ERR(efx
, "%s: failed rc=%d\n", __func__
, rc
);
484 efx
->link_state
.up
= false;
486 efx_mcdi_phy_decode_link(
487 efx
, &efx
->link_state
,
488 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
489 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
490 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
493 return !efx_link_state_equal(&efx
->link_state
, &old_state
);
496 static void efx_mcdi_phy_remove(struct efx_nic
*efx
)
498 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
500 efx
->phy_data
= NULL
;
504 static void efx_mcdi_phy_get_settings(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
506 struct efx_mcdi_phy_cfg
*phy_cfg
= efx
->phy_data
;
507 u8 outbuf
[MC_CMD_GET_LINK_OUT_LEN
];
511 mcdi_to_ethtool_cap(phy_cfg
->media
, phy_cfg
->supported_cap
);
512 ecmd
->advertising
= efx
->link_advertising
;
513 ecmd
->speed
= efx
->link_state
.speed
;
514 ecmd
->duplex
= efx
->link_state
.fd
;
515 ecmd
->port
= mcdi_to_ethtool_media(phy_cfg
->media
);
516 ecmd
->phy_address
= phy_cfg
->port
;
517 ecmd
->transceiver
= XCVR_INTERNAL
;
518 ecmd
->autoneg
= !!(efx
->link_advertising
& ADVERTISED_Autoneg
);
519 ecmd
->mdio_support
= (efx
->mdio
.mode_support
&
520 (MDIO_SUPPORTS_C45
| MDIO_SUPPORTS_C22
));
522 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
523 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
524 outbuf
, sizeof(outbuf
), NULL
);
526 EFX_ERR(efx
, "%s: failed rc=%d\n", __func__
, rc
);
529 ecmd
->lp_advertising
=
530 mcdi_to_ethtool_cap(phy_cfg
->media
,
531 MCDI_DWORD(outbuf
, GET_LINK_OUT_LP_CAP
));
534 static int efx_mcdi_phy_set_settings(struct efx_nic
*efx
, struct ethtool_cmd
*ecmd
)
536 struct efx_mcdi_phy_cfg
*phy_cfg
= efx
->phy_data
;
541 caps
= (ethtool_to_mcdi_cap(ecmd
->advertising
) |
542 1 << MC_CMD_PHY_CAP_AN_LBN
);
543 } else if (ecmd
->duplex
) {
544 switch (ecmd
->speed
) {
545 case 10: caps
= 1 << MC_CMD_PHY_CAP_10FDX_LBN
; break;
546 case 100: caps
= 1 << MC_CMD_PHY_CAP_100FDX_LBN
; break;
547 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000FDX_LBN
; break;
548 case 10000: caps
= 1 << MC_CMD_PHY_CAP_10000FDX_LBN
; break;
549 default: return -EINVAL
;
552 switch (ecmd
->speed
) {
553 case 10: caps
= 1 << MC_CMD_PHY_CAP_10HDX_LBN
; break;
554 case 100: caps
= 1 << MC_CMD_PHY_CAP_100HDX_LBN
; break;
555 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000HDX_LBN
; break;
556 default: return -EINVAL
;
560 rc
= efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
561 efx
->loopback_mode
, 0);
566 efx_link_set_advertising(
567 efx
, ecmd
->advertising
| ADVERTISED_Autoneg
);
568 phy_cfg
->forced_cap
= 0;
570 efx_link_set_advertising(efx
, 0);
571 phy_cfg
->forced_cap
= caps
;
576 static int efx_mcdi_phy_test_alive(struct efx_nic
*efx
)
578 u8 outbuf
[MC_CMD_GET_PHY_STATE_OUT_LEN
];
582 BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN
!= 0);
584 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PHY_STATE
, NULL
, 0,
585 outbuf
, sizeof(outbuf
), &outlen
);
589 if (outlen
< MC_CMD_GET_PHY_STATE_OUT_LEN
)
591 if (MCDI_DWORD(outbuf
, GET_PHY_STATE_STATE
) != MC_CMD_PHY_STATE_OK
)
597 struct efx_phy_operations efx_mcdi_phy_ops
= {
598 .probe
= efx_mcdi_phy_probe
,
599 .init
= efx_port_dummy_op_int
,
600 .reconfigure
= efx_mcdi_phy_reconfigure
,
601 .poll
= efx_mcdi_phy_poll
,
602 .fini
= efx_port_dummy_op_void
,
603 .remove
= efx_mcdi_phy_remove
,
604 .get_settings
= efx_mcdi_phy_get_settings
,
605 .set_settings
= efx_mcdi_phy_set_settings
,
606 .test_alive
= efx_mcdi_phy_test_alive
,