1 /****************************************************************************
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2009-2013 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>
17 #include "mcdi_pcol.h"
21 struct efx_mcdi_phy_data
{
36 efx_mcdi_get_phy_cfg(struct efx_nic
*efx
, struct efx_mcdi_phy_data
*cfg
)
38 MCDI_DECLARE_BUF(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 netif_err(efx
, hw
, efx
->net_dev
, "%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 MCDI_DECLARE_BUF(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
),
95 static int efx_mcdi_loopback_modes(struct efx_nic
*efx
, u64
*loopback_modes
)
97 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LOOPBACK_MODES_OUT_LEN
);
101 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LOOPBACK_MODES
, NULL
, 0,
102 outbuf
, sizeof(outbuf
), &outlen
);
106 if (outlen
< (MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_OFST
+
107 MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_LEN
)) {
112 *loopback_modes
= MCDI_QWORD(outbuf
, GET_LOOPBACK_MODES_OUT_SUGGESTED
);
117 netif_err(efx
, hw
, efx
->net_dev
, "%s: failed rc=%d\n", __func__
, rc
);
121 static int efx_mcdi_mdio_read(struct net_device
*net_dev
,
122 int prtad
, int devad
, u16 addr
)
124 struct efx_nic
*efx
= netdev_priv(net_dev
);
125 MCDI_DECLARE_BUF(inbuf
, MC_CMD_MDIO_READ_IN_LEN
);
126 MCDI_DECLARE_BUF(outbuf
, MC_CMD_MDIO_READ_OUT_LEN
);
130 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_BUS
, efx
->mdio_bus
);
131 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_PRTAD
, prtad
);
132 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_DEVAD
, devad
);
133 MCDI_SET_DWORD(inbuf
, MDIO_READ_IN_ADDR
, addr
);
135 rc
= efx_mcdi_rpc(efx
, MC_CMD_MDIO_READ
, inbuf
, sizeof(inbuf
),
136 outbuf
, sizeof(outbuf
), &outlen
);
140 if (MCDI_DWORD(outbuf
, MDIO_READ_OUT_STATUS
) !=
141 MC_CMD_MDIO_STATUS_GOOD
)
144 return (u16
)MCDI_DWORD(outbuf
, MDIO_READ_OUT_VALUE
);
147 static int efx_mcdi_mdio_write(struct net_device
*net_dev
,
148 int prtad
, int devad
, u16 addr
, u16 value
)
150 struct efx_nic
*efx
= netdev_priv(net_dev
);
151 MCDI_DECLARE_BUF(inbuf
, MC_CMD_MDIO_WRITE_IN_LEN
);
152 MCDI_DECLARE_BUF(outbuf
, MC_CMD_MDIO_WRITE_OUT_LEN
);
156 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_BUS
, efx
->mdio_bus
);
157 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_PRTAD
, prtad
);
158 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_DEVAD
, devad
);
159 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_ADDR
, addr
);
160 MCDI_SET_DWORD(inbuf
, MDIO_WRITE_IN_VALUE
, value
);
162 rc
= efx_mcdi_rpc(efx
, MC_CMD_MDIO_WRITE
, inbuf
, sizeof(inbuf
),
163 outbuf
, sizeof(outbuf
), &outlen
);
167 if (MCDI_DWORD(outbuf
, MDIO_WRITE_OUT_STATUS
) !=
168 MC_CMD_MDIO_STATUS_GOOD
)
174 static void mcdi_to_ethtool_linkset(u32 media
, u32 cap
, unsigned long *linkset
)
176 #define SET_BIT(name) __set_bit(ETHTOOL_LINK_MODE_ ## name ## _BIT, \
179 bitmap_zero(linkset
, __ETHTOOL_LINK_MODE_MASK_NBITS
);
181 case MC_CMD_MEDIA_KX4
:
183 if (cap
& (1 << MC_CMD_PHY_CAP_1000FDX_LBN
))
184 SET_BIT(1000baseKX_Full
);
185 if (cap
& (1 << MC_CMD_PHY_CAP_10000FDX_LBN
))
186 SET_BIT(10000baseKX4_Full
);
187 if (cap
& (1 << MC_CMD_PHY_CAP_40000FDX_LBN
))
188 SET_BIT(40000baseKR4_Full
);
191 case MC_CMD_MEDIA_XFP
:
192 case MC_CMD_MEDIA_SFP_PLUS
:
193 case MC_CMD_MEDIA_QSFP_PLUS
:
195 if (cap
& (1 << MC_CMD_PHY_CAP_1000FDX_LBN
))
196 SET_BIT(1000baseT_Full
);
197 if (cap
& (1 << MC_CMD_PHY_CAP_10000FDX_LBN
))
198 SET_BIT(10000baseT_Full
);
199 if (cap
& (1 << MC_CMD_PHY_CAP_40000FDX_LBN
))
200 SET_BIT(40000baseCR4_Full
);
201 if (cap
& (1 << MC_CMD_PHY_CAP_100000FDX_LBN
))
202 SET_BIT(100000baseCR4_Full
);
203 if (cap
& (1 << MC_CMD_PHY_CAP_25000FDX_LBN
))
204 SET_BIT(25000baseCR_Full
);
205 if (cap
& (1 << MC_CMD_PHY_CAP_50000FDX_LBN
))
206 SET_BIT(50000baseCR2_Full
);
209 case MC_CMD_MEDIA_BASE_T
:
211 if (cap
& (1 << MC_CMD_PHY_CAP_10HDX_LBN
))
212 SET_BIT(10baseT_Half
);
213 if (cap
& (1 << MC_CMD_PHY_CAP_10FDX_LBN
))
214 SET_BIT(10baseT_Full
);
215 if (cap
& (1 << MC_CMD_PHY_CAP_100HDX_LBN
))
216 SET_BIT(100baseT_Half
);
217 if (cap
& (1 << MC_CMD_PHY_CAP_100FDX_LBN
))
218 SET_BIT(100baseT_Full
);
219 if (cap
& (1 << MC_CMD_PHY_CAP_1000HDX_LBN
))
220 SET_BIT(1000baseT_Half
);
221 if (cap
& (1 << MC_CMD_PHY_CAP_1000FDX_LBN
))
222 SET_BIT(1000baseT_Full
);
223 if (cap
& (1 << MC_CMD_PHY_CAP_10000FDX_LBN
))
224 SET_BIT(10000baseT_Full
);
228 if (cap
& (1 << MC_CMD_PHY_CAP_PAUSE_LBN
))
230 if (cap
& (1 << MC_CMD_PHY_CAP_ASYM_LBN
))
232 if (cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
238 static u32
ethtool_linkset_to_mcdi_cap(const unsigned long *linkset
)
242 #define TEST_BIT(name) test_bit(ETHTOOL_LINK_MODE_ ## name ## _BIT, \
245 if (TEST_BIT(10baseT_Half
))
246 result
|= (1 << MC_CMD_PHY_CAP_10HDX_LBN
);
247 if (TEST_BIT(10baseT_Full
))
248 result
|= (1 << MC_CMD_PHY_CAP_10FDX_LBN
);
249 if (TEST_BIT(100baseT_Half
))
250 result
|= (1 << MC_CMD_PHY_CAP_100HDX_LBN
);
251 if (TEST_BIT(100baseT_Full
))
252 result
|= (1 << MC_CMD_PHY_CAP_100FDX_LBN
);
253 if (TEST_BIT(1000baseT_Half
))
254 result
|= (1 << MC_CMD_PHY_CAP_1000HDX_LBN
);
255 if (TEST_BIT(1000baseT_Full
) || TEST_BIT(1000baseKX_Full
))
256 result
|= (1 << MC_CMD_PHY_CAP_1000FDX_LBN
);
257 if (TEST_BIT(10000baseT_Full
) || TEST_BIT(10000baseKX4_Full
))
258 result
|= (1 << MC_CMD_PHY_CAP_10000FDX_LBN
);
259 if (TEST_BIT(40000baseCR4_Full
) || TEST_BIT(40000baseKR4_Full
))
260 result
|= (1 << MC_CMD_PHY_CAP_40000FDX_LBN
);
261 if (TEST_BIT(100000baseCR4_Full
))
262 result
|= (1 << MC_CMD_PHY_CAP_100000FDX_LBN
);
263 if (TEST_BIT(25000baseCR_Full
))
264 result
|= (1 << MC_CMD_PHY_CAP_25000FDX_LBN
);
265 if (TEST_BIT(50000baseCR2_Full
))
266 result
|= (1 << MC_CMD_PHY_CAP_50000FDX_LBN
);
268 result
|= (1 << MC_CMD_PHY_CAP_PAUSE_LBN
);
269 if (TEST_BIT(Asym_Pause
))
270 result
|= (1 << MC_CMD_PHY_CAP_ASYM_LBN
);
271 if (TEST_BIT(Autoneg
))
272 result
|= (1 << MC_CMD_PHY_CAP_AN_LBN
);
279 static u32
efx_get_mcdi_phy_flags(struct efx_nic
*efx
)
281 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
282 enum efx_phy_mode mode
, supported
;
285 /* TODO: Advertise the capabilities supported by this PHY */
287 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_TXDIS_LBN
))
288 supported
|= PHY_MODE_TX_DISABLED
;
289 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_LOWPOWER_LBN
))
290 supported
|= PHY_MODE_LOW_POWER
;
291 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_POWEROFF_LBN
))
292 supported
|= PHY_MODE_OFF
;
294 mode
= efx
->phy_mode
& supported
;
297 if (mode
& PHY_MODE_TX_DISABLED
)
298 flags
|= (1 << MC_CMD_SET_LINK_IN_TXDIS_LBN
);
299 if (mode
& PHY_MODE_LOW_POWER
)
300 flags
|= (1 << MC_CMD_SET_LINK_IN_LOWPOWER_LBN
);
301 if (mode
& PHY_MODE_OFF
)
302 flags
|= (1 << MC_CMD_SET_LINK_IN_POWEROFF_LBN
);
307 static u8
mcdi_to_ethtool_media(u32 media
)
310 case MC_CMD_MEDIA_XAUI
:
311 case MC_CMD_MEDIA_CX4
:
312 case MC_CMD_MEDIA_KX4
:
315 case MC_CMD_MEDIA_XFP
:
316 case MC_CMD_MEDIA_SFP_PLUS
:
317 case MC_CMD_MEDIA_QSFP_PLUS
:
320 case MC_CMD_MEDIA_BASE_T
:
328 static void efx_mcdi_phy_decode_link(struct efx_nic
*efx
,
329 struct efx_link_state
*link_state
,
330 u32 speed
, u32 flags
, u32 fcntl
)
333 case MC_CMD_FCNTL_AUTO
:
334 WARN_ON(1); /* This is not a link mode */
335 link_state
->fc
= EFX_FC_AUTO
| EFX_FC_TX
| EFX_FC_RX
;
337 case MC_CMD_FCNTL_BIDIR
:
338 link_state
->fc
= EFX_FC_TX
| EFX_FC_RX
;
340 case MC_CMD_FCNTL_RESPOND
:
341 link_state
->fc
= EFX_FC_RX
;
345 case MC_CMD_FCNTL_OFF
:
350 link_state
->up
= !!(flags
& (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN
));
351 link_state
->fd
= !!(flags
& (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN
));
352 link_state
->speed
= speed
;
355 /* The semantics of the ethtool FEC mode bitmask are not well defined,
356 * particularly the meaning of combinations of bits. Which means we get to
357 * define our own semantics, as follows:
358 * OFF overrides any other bits, and means "disable all FEC" (with the
359 * exception of 25G KR4/CR4, where it is not possible to reject it if AN
360 * partner requests it).
361 * AUTO on its own means use cable requirements and link partner autoneg with
362 * fw-default preferences for the cable type.
363 * AUTO and either RS or BASER means use the specified FEC type if cable and
364 * link partner support it, otherwise autoneg/fw-default.
365 * RS or BASER alone means use the specified FEC type if cable and link partner
366 * support it and either requests it, otherwise no FEC.
367 * Both RS and BASER (whether AUTO or not) means use FEC if cable and link
368 * partner support it, preferring RS to BASER.
370 static u32
ethtool_fec_caps_to_mcdi(u32 ethtool_cap
)
374 if (ethtool_cap
& ETHTOOL_FEC_OFF
)
377 if (ethtool_cap
& ETHTOOL_FEC_AUTO
)
378 ret
|= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN
) |
379 (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN
) |
380 (1 << MC_CMD_PHY_CAP_RS_FEC_LBN
);
381 if (ethtool_cap
& ETHTOOL_FEC_RS
)
382 ret
|= (1 << MC_CMD_PHY_CAP_RS_FEC_LBN
) |
383 (1 << MC_CMD_PHY_CAP_RS_FEC_REQUESTED_LBN
);
384 if (ethtool_cap
& ETHTOOL_FEC_BASER
)
385 ret
|= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN
) |
386 (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN
) |
387 (1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN
) |
388 (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN
);
392 /* Invert ethtool_fec_caps_to_mcdi. There are two combinations that function
393 * can never produce, (baser xor rs) and neither req; the implementation below
394 * maps both of those to AUTO. This should never matter, and it's not clear
395 * what a better mapping would be anyway.
397 static u32
mcdi_fec_caps_to_ethtool(u32 caps
, bool is_25g
)
399 bool rs
= caps
& (1 << MC_CMD_PHY_CAP_RS_FEC_LBN
),
400 rs_req
= caps
& (1 << MC_CMD_PHY_CAP_RS_FEC_REQUESTED_LBN
),
401 baser
= is_25g
? caps
& (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN
)
402 : caps
& (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN
),
403 baser_req
= is_25g
? caps
& (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN
)
404 : caps
& (1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN
);
407 return ETHTOOL_FEC_OFF
;
408 return (rs_req
? ETHTOOL_FEC_RS
: 0) |
409 (baser_req
? ETHTOOL_FEC_BASER
: 0) |
410 (baser
== baser_req
&& rs
== rs_req
? 0 : ETHTOOL_FEC_AUTO
);
413 static int efx_mcdi_phy_probe(struct efx_nic
*efx
)
415 struct efx_mcdi_phy_data
*phy_data
;
416 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
420 /* Initialise and populate phy_data */
421 phy_data
= kzalloc(sizeof(*phy_data
), GFP_KERNEL
);
422 if (phy_data
== NULL
)
425 rc
= efx_mcdi_get_phy_cfg(efx
, phy_data
);
429 /* Read initial link advertisement */
430 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
431 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
432 outbuf
, sizeof(outbuf
), NULL
);
436 /* Fill out nic state */
437 efx
->phy_data
= phy_data
;
438 efx
->phy_type
= phy_data
->type
;
440 efx
->mdio_bus
= phy_data
->channel
;
441 efx
->mdio
.prtad
= phy_data
->port
;
442 efx
->mdio
.mmds
= phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
);
443 efx
->mdio
.mode_support
= 0;
444 if (phy_data
->mmd_mask
& (1 << MC_CMD_MMD_CLAUSE22
))
445 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C22
;
446 if (phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
))
447 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
449 caps
= MCDI_DWORD(outbuf
, GET_LINK_OUT_CAP
);
450 if (caps
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
451 mcdi_to_ethtool_linkset(phy_data
->media
, caps
,
452 efx
->link_advertising
);
454 phy_data
->forced_cap
= caps
;
456 /* Assert that we can map efx -> mcdi loopback modes */
457 BUILD_BUG_ON(LOOPBACK_NONE
!= MC_CMD_LOOPBACK_NONE
);
458 BUILD_BUG_ON(LOOPBACK_DATA
!= MC_CMD_LOOPBACK_DATA
);
459 BUILD_BUG_ON(LOOPBACK_GMAC
!= MC_CMD_LOOPBACK_GMAC
);
460 BUILD_BUG_ON(LOOPBACK_XGMII
!= MC_CMD_LOOPBACK_XGMII
);
461 BUILD_BUG_ON(LOOPBACK_XGXS
!= MC_CMD_LOOPBACK_XGXS
);
462 BUILD_BUG_ON(LOOPBACK_XAUI
!= MC_CMD_LOOPBACK_XAUI
);
463 BUILD_BUG_ON(LOOPBACK_GMII
!= MC_CMD_LOOPBACK_GMII
);
464 BUILD_BUG_ON(LOOPBACK_SGMII
!= MC_CMD_LOOPBACK_SGMII
);
465 BUILD_BUG_ON(LOOPBACK_XGBR
!= MC_CMD_LOOPBACK_XGBR
);
466 BUILD_BUG_ON(LOOPBACK_XFI
!= MC_CMD_LOOPBACK_XFI
);
467 BUILD_BUG_ON(LOOPBACK_XAUI_FAR
!= MC_CMD_LOOPBACK_XAUI_FAR
);
468 BUILD_BUG_ON(LOOPBACK_GMII_FAR
!= MC_CMD_LOOPBACK_GMII_FAR
);
469 BUILD_BUG_ON(LOOPBACK_SGMII_FAR
!= MC_CMD_LOOPBACK_SGMII_FAR
);
470 BUILD_BUG_ON(LOOPBACK_XFI_FAR
!= MC_CMD_LOOPBACK_XFI_FAR
);
471 BUILD_BUG_ON(LOOPBACK_GPHY
!= MC_CMD_LOOPBACK_GPHY
);
472 BUILD_BUG_ON(LOOPBACK_PHYXS
!= MC_CMD_LOOPBACK_PHYXS
);
473 BUILD_BUG_ON(LOOPBACK_PCS
!= MC_CMD_LOOPBACK_PCS
);
474 BUILD_BUG_ON(LOOPBACK_PMAPMD
!= MC_CMD_LOOPBACK_PMAPMD
);
475 BUILD_BUG_ON(LOOPBACK_XPORT
!= MC_CMD_LOOPBACK_XPORT
);
476 BUILD_BUG_ON(LOOPBACK_XGMII_WS
!= MC_CMD_LOOPBACK_XGMII_WS
);
477 BUILD_BUG_ON(LOOPBACK_XAUI_WS
!= MC_CMD_LOOPBACK_XAUI_WS
);
478 BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR
!= MC_CMD_LOOPBACK_XAUI_WS_FAR
);
479 BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR
!= MC_CMD_LOOPBACK_XAUI_WS_NEAR
);
480 BUILD_BUG_ON(LOOPBACK_GMII_WS
!= MC_CMD_LOOPBACK_GMII_WS
);
481 BUILD_BUG_ON(LOOPBACK_XFI_WS
!= MC_CMD_LOOPBACK_XFI_WS
);
482 BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR
!= MC_CMD_LOOPBACK_XFI_WS_FAR
);
483 BUILD_BUG_ON(LOOPBACK_PHYXS_WS
!= MC_CMD_LOOPBACK_PHYXS_WS
);
485 rc
= efx_mcdi_loopback_modes(efx
, &efx
->loopback_modes
);
488 /* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
489 * but by convention we don't */
490 efx
->loopback_modes
&= ~(1 << LOOPBACK_NONE
);
492 /* Set the initial link mode */
493 efx_mcdi_phy_decode_link(
494 efx
, &efx
->link_state
,
495 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
496 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
497 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
499 /* Record the initial FEC configuration (or nearest approximation
500 * representable in the ethtool configuration space)
502 efx
->fec_config
= mcdi_fec_caps_to_ethtool(caps
,
503 efx
->link_state
.speed
== 25000 ||
504 efx
->link_state
.speed
== 50000);
506 /* Default to Autonegotiated flow control if the PHY supports it */
507 efx
->wanted_fc
= EFX_FC_RX
| EFX_FC_TX
;
508 if (phy_data
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
509 efx
->wanted_fc
|= EFX_FC_AUTO
;
510 efx_link_set_wanted_fc(efx
, efx
->wanted_fc
);
519 int efx_mcdi_port_reconfigure(struct efx_nic
*efx
)
521 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
522 u32 caps
= (efx
->link_advertising
[0] ?
523 ethtool_linkset_to_mcdi_cap(efx
->link_advertising
) :
524 phy_cfg
->forced_cap
);
526 caps
|= ethtool_fec_caps_to_mcdi(efx
->fec_config
);
528 return efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
529 efx
->loopback_mode
, 0);
532 /* Verify that the forced flow control settings (!EFX_FC_AUTO) are
533 * supported by the link partner. Warn the user if this isn't the case
535 static void efx_mcdi_phy_check_fcntl(struct efx_nic
*efx
, u32 lpa
)
537 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
540 /* The link partner capabilities are only relevant if the
541 * link supports flow control autonegotiation */
542 if (~phy_cfg
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
545 /* If flow control autoneg is supported and enabled, then fine */
546 if (efx
->wanted_fc
& EFX_FC_AUTO
)
550 if (lpa
& (1 << MC_CMD_PHY_CAP_PAUSE_LBN
))
551 rmtadv
|= ADVERTISED_Pause
;
552 if (lpa
& (1 << MC_CMD_PHY_CAP_ASYM_LBN
))
553 rmtadv
|= ADVERTISED_Asym_Pause
;
555 if ((efx
->wanted_fc
& EFX_FC_TX
) && rmtadv
== ADVERTISED_Asym_Pause
)
556 netif_err(efx
, link
, efx
->net_dev
,
557 "warning: link partner doesn't support pause frames");
560 static bool efx_mcdi_phy_poll(struct efx_nic
*efx
)
562 struct efx_link_state old_state
= efx
->link_state
;
563 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
566 WARN_ON(!mutex_is_locked(&efx
->mac_lock
));
568 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
570 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
571 outbuf
, sizeof(outbuf
), NULL
);
573 efx
->link_state
.up
= false;
575 efx_mcdi_phy_decode_link(
576 efx
, &efx
->link_state
,
577 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
578 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
579 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
581 return !efx_link_state_equal(&efx
->link_state
, &old_state
);
584 static void efx_mcdi_phy_remove(struct efx_nic
*efx
)
586 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
588 efx
->phy_data
= NULL
;
592 static void efx_mcdi_phy_get_link_ksettings(struct efx_nic
*efx
,
593 struct ethtool_link_ksettings
*cmd
)
595 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
596 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
599 cmd
->base
.speed
= efx
->link_state
.speed
;
600 cmd
->base
.duplex
= efx
->link_state
.fd
;
601 cmd
->base
.port
= mcdi_to_ethtool_media(phy_cfg
->media
);
602 cmd
->base
.phy_address
= phy_cfg
->port
;
603 cmd
->base
.autoneg
= !!(efx
->link_advertising
[0] & ADVERTISED_Autoneg
);
604 cmd
->base
.mdio_support
= (efx
->mdio
.mode_support
&
605 (MDIO_SUPPORTS_C45
| MDIO_SUPPORTS_C22
));
607 mcdi_to_ethtool_linkset(phy_cfg
->media
, phy_cfg
->supported_cap
,
608 cmd
->link_modes
.supported
);
609 memcpy(cmd
->link_modes
.advertising
, efx
->link_advertising
,
610 sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));
612 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
613 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
614 outbuf
, sizeof(outbuf
), NULL
);
617 mcdi_to_ethtool_linkset(phy_cfg
->media
,
618 MCDI_DWORD(outbuf
, GET_LINK_OUT_LP_CAP
),
619 cmd
->link_modes
.lp_advertising
);
623 efx_mcdi_phy_set_link_ksettings(struct efx_nic
*efx
,
624 const struct ethtool_link_ksettings
*cmd
)
626 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
630 if (cmd
->base
.autoneg
) {
631 caps
= (ethtool_linkset_to_mcdi_cap(cmd
->link_modes
.advertising
) |
632 1 << MC_CMD_PHY_CAP_AN_LBN
);
633 } else if (cmd
->base
.duplex
) {
634 switch (cmd
->base
.speed
) {
635 case 10: caps
= 1 << MC_CMD_PHY_CAP_10FDX_LBN
; break;
636 case 100: caps
= 1 << MC_CMD_PHY_CAP_100FDX_LBN
; break;
637 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000FDX_LBN
; break;
638 case 10000: caps
= 1 << MC_CMD_PHY_CAP_10000FDX_LBN
; break;
639 case 40000: caps
= 1 << MC_CMD_PHY_CAP_40000FDX_LBN
; break;
640 case 100000: caps
= 1 << MC_CMD_PHY_CAP_100000FDX_LBN
; break;
641 case 25000: caps
= 1 << MC_CMD_PHY_CAP_25000FDX_LBN
; break;
642 case 50000: caps
= 1 << MC_CMD_PHY_CAP_50000FDX_LBN
; break;
643 default: return -EINVAL
;
646 switch (cmd
->base
.speed
) {
647 case 10: caps
= 1 << MC_CMD_PHY_CAP_10HDX_LBN
; break;
648 case 100: caps
= 1 << MC_CMD_PHY_CAP_100HDX_LBN
; break;
649 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000HDX_LBN
; break;
650 default: return -EINVAL
;
654 caps
|= ethtool_fec_caps_to_mcdi(efx
->fec_config
);
656 rc
= efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
657 efx
->loopback_mode
, 0);
661 if (cmd
->base
.autoneg
) {
662 efx_link_set_advertising(efx
, cmd
->link_modes
.advertising
);
663 phy_cfg
->forced_cap
= 0;
665 efx_link_clear_advertising(efx
);
666 phy_cfg
->forced_cap
= caps
;
671 static int efx_mcdi_phy_get_fecparam(struct efx_nic
*efx
,
672 struct ethtool_fecparam
*fec
)
674 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_V2_LEN
);
675 u32 caps
, active
, speed
; /* MCDI format */
680 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
681 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
682 outbuf
, sizeof(outbuf
), &outlen
);
685 if (outlen
< MC_CMD_GET_LINK_OUT_V2_LEN
)
688 /* behaviour for 25G/50G links depends on 25G BASER bit */
689 speed
= MCDI_DWORD(outbuf
, GET_LINK_OUT_V2_LINK_SPEED
);
690 is_25g
= speed
== 25000 || speed
== 50000;
692 caps
= MCDI_DWORD(outbuf
, GET_LINK_OUT_V2_CAP
);
693 fec
->fec
= mcdi_fec_caps_to_ethtool(caps
, is_25g
);
694 /* BASER is never supported on 100G */
696 fec
->fec
&= ~ETHTOOL_FEC_BASER
;
698 active
= MCDI_DWORD(outbuf
, GET_LINK_OUT_V2_FEC_TYPE
);
700 case MC_CMD_FEC_NONE
:
701 fec
->active_fec
= ETHTOOL_FEC_OFF
;
703 case MC_CMD_FEC_BASER
:
704 fec
->active_fec
= ETHTOOL_FEC_BASER
;
707 fec
->active_fec
= ETHTOOL_FEC_RS
;
710 netif_warn(efx
, hw
, efx
->net_dev
,
711 "Firmware reports unrecognised FEC_TYPE %u\n",
713 /* We don't know what firmware has picked. AUTO is as good a
714 * "can't happen" value as any other.
716 fec
->active_fec
= ETHTOOL_FEC_AUTO
;
723 static int efx_mcdi_phy_set_fecparam(struct efx_nic
*efx
,
724 const struct ethtool_fecparam
*fec
)
726 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
730 /* Work out what efx_mcdi_phy_set_link_ksettings() would produce from
731 * saved advertising bits
733 if (test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT
, efx
->link_advertising
))
734 caps
= (ethtool_linkset_to_mcdi_cap(efx
->link_advertising
) |
735 1 << MC_CMD_PHY_CAP_AN_LBN
);
737 caps
= phy_cfg
->forced_cap
;
739 caps
|= ethtool_fec_caps_to_mcdi(fec
->fec
);
740 rc
= efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
741 efx
->loopback_mode
, 0);
745 /* Record the new FEC setting for subsequent set_link calls */
746 efx
->fec_config
= fec
->fec
;
750 static int efx_mcdi_phy_test_alive(struct efx_nic
*efx
)
752 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_PHY_STATE_OUT_LEN
);
756 BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN
!= 0);
758 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PHY_STATE
, NULL
, 0,
759 outbuf
, sizeof(outbuf
), &outlen
);
763 if (outlen
< MC_CMD_GET_PHY_STATE_OUT_LEN
)
765 if (MCDI_DWORD(outbuf
, GET_PHY_STATE_OUT_STATE
) != MC_CMD_PHY_STATE_OK
)
771 static const char *const mcdi_sft9001_cable_diag_names
[] = {
772 "cable.pairA.length",
773 "cable.pairB.length",
774 "cable.pairC.length",
775 "cable.pairD.length",
776 "cable.pairA.status",
777 "cable.pairB.status",
778 "cable.pairC.status",
779 "cable.pairD.status",
782 static int efx_mcdi_bist(struct efx_nic
*efx
, unsigned int bist_mode
,
785 unsigned int retry
, i
, count
= 0;
788 MCDI_DECLARE_BUF(inbuf
, MC_CMD_START_BIST_IN_LEN
);
789 MCDI_DECLARE_BUF(outbuf
, MC_CMD_POLL_BIST_OUT_SFT9001_LEN
);
793 BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN
!= 0);
794 MCDI_SET_DWORD(inbuf
, START_BIST_IN_TYPE
, bist_mode
);
795 rc
= efx_mcdi_rpc(efx
, MC_CMD_START_BIST
,
796 inbuf
, MC_CMD_START_BIST_IN_LEN
, NULL
, 0, NULL
);
800 /* Wait up to 10s for BIST to finish */
801 for (retry
= 0; retry
< 100; ++retry
) {
802 BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN
!= 0);
803 rc
= efx_mcdi_rpc(efx
, MC_CMD_POLL_BIST
, NULL
, 0,
804 outbuf
, sizeof(outbuf
), &outlen
);
808 status
= MCDI_DWORD(outbuf
, POLL_BIST_OUT_RESULT
);
809 if (status
!= MC_CMD_POLL_BIST_RUNNING
)
819 results
[count
++] = (status
== MC_CMD_POLL_BIST_PASSED
) ? 1 : -1;
821 /* SFT9001 specific cable diagnostics output */
822 if (efx
->phy_type
== PHY_TYPE_SFT9001B
&&
823 (bist_mode
== MC_CMD_PHY_BIST_CABLE_SHORT
||
824 bist_mode
== MC_CMD_PHY_BIST_CABLE_LONG
)) {
825 ptr
= MCDI_PTR(outbuf
, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A
);
826 if (status
== MC_CMD_POLL_BIST_PASSED
&&
827 outlen
>= MC_CMD_POLL_BIST_OUT_SFT9001_LEN
) {
828 for (i
= 0; i
< 8; i
++) {
830 EFX_DWORD_FIELD(((efx_dword_t
*)ptr
)[i
],
842 static int efx_mcdi_phy_run_tests(struct efx_nic
*efx
, int *results
,
845 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
849 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN
)) {
850 rc
= efx_mcdi_bist(efx
, MC_CMD_PHY_BIST
, results
);
857 /* If we support both LONG and SHORT, then run each in response to
858 * break or not. Otherwise, run the one we support */
860 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN
)) {
861 if ((flags
& ETH_TEST_FL_OFFLINE
) &&
863 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN
)))
864 mode
= MC_CMD_PHY_BIST_CABLE_LONG
;
866 mode
= MC_CMD_PHY_BIST_CABLE_SHORT
;
867 } else if (phy_cfg
->flags
&
868 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN
))
869 mode
= MC_CMD_PHY_BIST_CABLE_LONG
;
872 rc
= efx_mcdi_bist(efx
, mode
, results
);
881 static const char *efx_mcdi_phy_test_name(struct efx_nic
*efx
,
884 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
886 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN
)) {
892 if (phy_cfg
->flags
& ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN
) |
893 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN
))) {
898 if (efx
->phy_type
== PHY_TYPE_SFT9001B
) {
899 if (index
< ARRAY_SIZE(mcdi_sft9001_cable_diag_names
))
900 return mcdi_sft9001_cable_diag_names
[index
];
901 index
-= ARRAY_SIZE(mcdi_sft9001_cable_diag_names
);
908 #define SFP_PAGE_SIZE 128
909 #define SFF_DIAG_TYPE_OFFSET 92
910 #define SFF_DIAG_ADDR_CHANGE BIT(2)
911 #define SFF_8079_NUM_PAGES 2
912 #define SFF_8472_NUM_PAGES 4
913 #define SFF_8436_NUM_PAGES 5
914 #define SFF_DMT_LEVEL_OFFSET 94
916 /** efx_mcdi_phy_get_module_eeprom_page() - Get a single page of module eeprom
918 * @page: EEPROM page number
919 * @data: Destination data pointer
920 * @offset: Offset in page to copy from in to data
921 * @space: Space available in data
924 * >=0 - amount of data copied
927 static int efx_mcdi_phy_get_module_eeprom_page(struct efx_nic
*efx
,
929 u8
*data
, ssize_t offset
,
932 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX
);
933 MCDI_DECLARE_BUF(inbuf
, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN
);
935 unsigned int payload_len
;
936 unsigned int to_copy
;
939 if (offset
> SFP_PAGE_SIZE
)
942 to_copy
= min(space
, SFP_PAGE_SIZE
- offset
);
944 MCDI_SET_DWORD(inbuf
, GET_PHY_MEDIA_INFO_IN_PAGE
, page
);
945 rc
= efx_mcdi_rpc_quiet(efx
, MC_CMD_GET_PHY_MEDIA_INFO
,
946 inbuf
, sizeof(inbuf
),
947 outbuf
, sizeof(outbuf
),
953 if (outlen
< (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST
+
957 payload_len
= MCDI_DWORD(outbuf
, GET_PHY_MEDIA_INFO_OUT_DATALEN
);
958 if (payload_len
!= SFP_PAGE_SIZE
)
961 memcpy(data
, MCDI_PTR(outbuf
, GET_PHY_MEDIA_INFO_OUT_DATA
) + offset
,
967 static int efx_mcdi_phy_get_module_eeprom_byte(struct efx_nic
*efx
,
974 rc
= efx_mcdi_phy_get_module_eeprom_page(efx
, page
, &data
, byte
, 1);
981 static int efx_mcdi_phy_diag_type(struct efx_nic
*efx
)
983 /* Page zero of the EEPROM includes the diagnostic type at byte 92. */
984 return efx_mcdi_phy_get_module_eeprom_byte(efx
, 0,
985 SFF_DIAG_TYPE_OFFSET
);
988 static int efx_mcdi_phy_sff_8472_level(struct efx_nic
*efx
)
990 /* Page zero of the EEPROM includes the DMT level at byte 94. */
991 return efx_mcdi_phy_get_module_eeprom_byte(efx
, 0,
992 SFF_DMT_LEVEL_OFFSET
);
995 static u32
efx_mcdi_phy_module_type(struct efx_nic
*efx
)
997 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
999 if (phy_data
->media
!= MC_CMD_MEDIA_QSFP_PLUS
)
1000 return phy_data
->media
;
1002 /* A QSFP+ NIC may actually have an SFP+ module attached.
1003 * The ID is page 0, byte 0.
1005 switch (efx_mcdi_phy_get_module_eeprom_byte(efx
, 0, 0)) {
1007 return MC_CMD_MEDIA_SFP_PLUS
;
1010 return MC_CMD_MEDIA_QSFP_PLUS
;
1016 static int efx_mcdi_phy_get_module_eeprom(struct efx_nic
*efx
,
1017 struct ethtool_eeprom
*ee
, u8
*data
)
1020 ssize_t space_remaining
= ee
->len
;
1021 unsigned int page_off
;
1022 bool ignore_missing
;
1026 switch (efx_mcdi_phy_module_type(efx
)) {
1027 case MC_CMD_MEDIA_SFP_PLUS
:
1028 num_pages
= efx_mcdi_phy_sff_8472_level(efx
) > 0 ?
1029 SFF_8472_NUM_PAGES
: SFF_8079_NUM_PAGES
;
1031 ignore_missing
= false;
1033 case MC_CMD_MEDIA_QSFP_PLUS
:
1034 num_pages
= SFF_8436_NUM_PAGES
;
1035 page
= -1; /* We obtain the lower page by asking for -1. */
1036 ignore_missing
= true; /* Ignore missing pages after page 0. */
1042 page_off
= ee
->offset
% SFP_PAGE_SIZE
;
1043 page
+= ee
->offset
/ SFP_PAGE_SIZE
;
1045 while (space_remaining
&& (page
< num_pages
)) {
1046 rc
= efx_mcdi_phy_get_module_eeprom_page(efx
, page
,
1051 space_remaining
-= rc
;
1055 } else if (rc
== 0) {
1056 space_remaining
= 0;
1057 } else if (ignore_missing
&& (page
> 0)) {
1058 int intended_size
= SFP_PAGE_SIZE
- page_off
;
1060 space_remaining
-= intended_size
;
1061 if (space_remaining
< 0) {
1062 space_remaining
= 0;
1064 memset(data
, 0, intended_size
);
1065 data
+= intended_size
;
1078 static int efx_mcdi_phy_get_module_info(struct efx_nic
*efx
,
1079 struct ethtool_modinfo
*modinfo
)
1084 switch (efx_mcdi_phy_module_type(efx
)) {
1085 case MC_CMD_MEDIA_SFP_PLUS
:
1086 sff_8472_level
= efx_mcdi_phy_sff_8472_level(efx
);
1088 /* If we can't read the diagnostics level we have none. */
1089 if (sff_8472_level
< 0)
1092 /* Check if this module requires the (unsupported) address
1095 diag_type
= efx_mcdi_phy_diag_type(efx
);
1097 if ((sff_8472_level
== 0) ||
1098 (diag_type
& SFF_DIAG_ADDR_CHANGE
)) {
1099 modinfo
->type
= ETH_MODULE_SFF_8079
;
1100 modinfo
->eeprom_len
= ETH_MODULE_SFF_8079_LEN
;
1102 modinfo
->type
= ETH_MODULE_SFF_8472
;
1103 modinfo
->eeprom_len
= ETH_MODULE_SFF_8472_LEN
;
1107 case MC_CMD_MEDIA_QSFP_PLUS
:
1108 modinfo
->type
= ETH_MODULE_SFF_8436
;
1109 modinfo
->eeprom_len
= ETH_MODULE_SFF_8436_LEN
;
1119 static const struct efx_phy_operations efx_mcdi_phy_ops
= {
1120 .probe
= efx_mcdi_phy_probe
,
1121 .init
= efx_port_dummy_op_int
,
1122 .reconfigure
= efx_mcdi_port_reconfigure
,
1123 .poll
= efx_mcdi_phy_poll
,
1124 .fini
= efx_port_dummy_op_void
,
1125 .remove
= efx_mcdi_phy_remove
,
1126 .get_link_ksettings
= efx_mcdi_phy_get_link_ksettings
,
1127 .set_link_ksettings
= efx_mcdi_phy_set_link_ksettings
,
1128 .get_fecparam
= efx_mcdi_phy_get_fecparam
,
1129 .set_fecparam
= efx_mcdi_phy_set_fecparam
,
1130 .test_alive
= efx_mcdi_phy_test_alive
,
1131 .run_tests
= efx_mcdi_phy_run_tests
,
1132 .test_name
= efx_mcdi_phy_test_name
,
1133 .get_module_eeprom
= efx_mcdi_phy_get_module_eeprom
,
1134 .get_module_info
= efx_mcdi_phy_get_module_info
,
1137 u32
efx_mcdi_phy_get_caps(struct efx_nic
*efx
)
1139 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
1141 return phy_data
->supported_cap
;
1144 static unsigned int efx_mcdi_event_link_speed
[] = {
1145 [MCDI_EVENT_LINKCHANGE_SPEED_100M
] = 100,
1146 [MCDI_EVENT_LINKCHANGE_SPEED_1G
] = 1000,
1147 [MCDI_EVENT_LINKCHANGE_SPEED_10G
] = 10000,
1148 [MCDI_EVENT_LINKCHANGE_SPEED_40G
] = 40000,
1149 [MCDI_EVENT_LINKCHANGE_SPEED_25G
] = 25000,
1150 [MCDI_EVENT_LINKCHANGE_SPEED_50G
] = 50000,
1151 [MCDI_EVENT_LINKCHANGE_SPEED_100G
] = 100000,
1154 void efx_mcdi_process_link_change(struct efx_nic
*efx
, efx_qword_t
*ev
)
1156 u32 flags
, fcntl
, speed
, lpa
;
1158 speed
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_SPEED
);
1159 EFX_WARN_ON_PARANOID(speed
>= ARRAY_SIZE(efx_mcdi_event_link_speed
));
1160 speed
= efx_mcdi_event_link_speed
[speed
];
1162 flags
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_LINK_FLAGS
);
1163 fcntl
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_FCNTL
);
1164 lpa
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_LP_CAP
);
1166 /* efx->link_state is only modified by efx_mcdi_phy_get_link(),
1167 * which is only run after flushing the event queues. Therefore, it
1168 * is safe to modify the link state outside of the mac_lock here.
1170 efx_mcdi_phy_decode_link(efx
, &efx
->link_state
, speed
, flags
, fcntl
);
1172 efx_mcdi_phy_check_fcntl(efx
, lpa
);
1174 efx_link_status_changed(efx
);
1177 int efx_mcdi_set_mac(struct efx_nic
*efx
)
1180 MCDI_DECLARE_BUF(cmdbytes
, MC_CMD_SET_MAC_IN_LEN
);
1182 BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN
!= 0);
1184 /* This has no effect on EF10 */
1185 ether_addr_copy(MCDI_PTR(cmdbytes
, SET_MAC_IN_ADDR
),
1186 efx
->net_dev
->dev_addr
);
1188 MCDI_SET_DWORD(cmdbytes
, SET_MAC_IN_MTU
,
1189 EFX_MAX_FRAME_LEN(efx
->net_dev
->mtu
));
1190 MCDI_SET_DWORD(cmdbytes
, SET_MAC_IN_DRAIN
, 0);
1192 /* Set simple MAC filter for Siena */
1193 MCDI_POPULATE_DWORD_1(cmdbytes
, SET_MAC_IN_REJECT
,
1194 SET_MAC_IN_REJECT_UNCST
, efx
->unicast_filter
);
1196 MCDI_POPULATE_DWORD_1(cmdbytes
, SET_MAC_IN_FLAGS
,
1197 SET_MAC_IN_FLAG_INCLUDE_FCS
,
1198 !!(efx
->net_dev
->features
& NETIF_F_RXFCS
));
1200 switch (efx
->wanted_fc
) {
1201 case EFX_FC_RX
| EFX_FC_TX
:
1202 fcntl
= MC_CMD_FCNTL_BIDIR
;
1205 fcntl
= MC_CMD_FCNTL_RESPOND
;
1208 fcntl
= MC_CMD_FCNTL_OFF
;
1211 if (efx
->wanted_fc
& EFX_FC_AUTO
)
1212 fcntl
= MC_CMD_FCNTL_AUTO
;
1213 if (efx
->fc_disable
)
1214 fcntl
= MC_CMD_FCNTL_OFF
;
1216 MCDI_SET_DWORD(cmdbytes
, SET_MAC_IN_FCNTL
, fcntl
);
1218 return efx_mcdi_rpc(efx
, MC_CMD_SET_MAC
, cmdbytes
, sizeof(cmdbytes
),
1222 bool efx_mcdi_mac_check_fault(struct efx_nic
*efx
)
1224 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
1228 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
1230 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
1231 outbuf
, sizeof(outbuf
), &outlength
);
1235 return MCDI_DWORD(outbuf
, GET_LINK_OUT_MAC_FAULT
) != 0;
1238 enum efx_stats_action
{
1244 static int efx_mcdi_mac_stats(struct efx_nic
*efx
,
1245 enum efx_stats_action action
, int clear
)
1247 MCDI_DECLARE_BUF(inbuf
, MC_CMD_MAC_STATS_IN_LEN
);
1249 int change
= action
== EFX_STATS_PULL
? 0 : 1;
1250 int enable
= action
== EFX_STATS_ENABLE
? 1 : 0;
1251 int period
= action
== EFX_STATS_ENABLE
? 1000 : 0;
1252 dma_addr_t dma_addr
= efx
->stats_buffer
.dma_addr
;
1253 u32 dma_len
= action
!= EFX_STATS_DISABLE
?
1254 efx
->num_mac_stats
* sizeof(u64
) : 0;
1256 BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN
!= 0);
1258 MCDI_SET_QWORD(inbuf
, MAC_STATS_IN_DMA_ADDR
, dma_addr
);
1259 MCDI_POPULATE_DWORD_7(inbuf
, MAC_STATS_IN_CMD
,
1260 MAC_STATS_IN_DMA
, !!enable
,
1261 MAC_STATS_IN_CLEAR
, clear
,
1262 MAC_STATS_IN_PERIODIC_CHANGE
, change
,
1263 MAC_STATS_IN_PERIODIC_ENABLE
, enable
,
1264 MAC_STATS_IN_PERIODIC_CLEAR
, 0,
1265 MAC_STATS_IN_PERIODIC_NOEVENT
, 1,
1266 MAC_STATS_IN_PERIOD_MS
, period
);
1267 MCDI_SET_DWORD(inbuf
, MAC_STATS_IN_DMA_LEN
, dma_len
);
1269 if (efx_nic_rev(efx
) >= EFX_REV_HUNT_A0
) {
1270 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
1272 MCDI_SET_DWORD(inbuf
, MAC_STATS_IN_PORT_ID
, nic_data
->vport_id
);
1275 rc
= efx_mcdi_rpc_quiet(efx
, MC_CMD_MAC_STATS
, inbuf
, sizeof(inbuf
),
1277 /* Expect ENOENT if DMA queues have not been set up */
1278 if (rc
&& (rc
!= -ENOENT
|| atomic_read(&efx
->active_queues
)))
1279 efx_mcdi_display_error(efx
, MC_CMD_MAC_STATS
, sizeof(inbuf
),
1284 void efx_mcdi_mac_start_stats(struct efx_nic
*efx
)
1286 __le64
*dma_stats
= efx
->stats_buffer
.addr
;
1288 dma_stats
[efx
->num_mac_stats
- 1] = EFX_MC_STATS_GENERATION_INVALID
;
1290 efx_mcdi_mac_stats(efx
, EFX_STATS_ENABLE
, 0);
1293 void efx_mcdi_mac_stop_stats(struct efx_nic
*efx
)
1295 efx_mcdi_mac_stats(efx
, EFX_STATS_DISABLE
, 0);
1298 #define EFX_MAC_STATS_WAIT_US 100
1299 #define EFX_MAC_STATS_WAIT_ATTEMPTS 10
1301 void efx_mcdi_mac_pull_stats(struct efx_nic
*efx
)
1303 __le64
*dma_stats
= efx
->stats_buffer
.addr
;
1304 int attempts
= EFX_MAC_STATS_WAIT_ATTEMPTS
;
1306 dma_stats
[efx
->num_mac_stats
- 1] = EFX_MC_STATS_GENERATION_INVALID
;
1307 efx_mcdi_mac_stats(efx
, EFX_STATS_PULL
, 0);
1309 while (dma_stats
[efx
->num_mac_stats
- 1] ==
1310 EFX_MC_STATS_GENERATION_INVALID
&&
1312 udelay(EFX_MAC_STATS_WAIT_US
);
1315 int efx_mcdi_port_probe(struct efx_nic
*efx
)
1319 /* Hook in PHY operations table */
1320 efx
->phy_op
= &efx_mcdi_phy_ops
;
1322 /* Set up MDIO structure for PHY */
1323 efx
->mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
1324 efx
->mdio
.mdio_read
= efx_mcdi_mdio_read
;
1325 efx
->mdio
.mdio_write
= efx_mcdi_mdio_write
;
1327 /* Fill out MDIO structure, loopback modes, and initial link state */
1328 rc
= efx
->phy_op
->probe(efx
);
1332 /* Allocate buffer for stats */
1333 rc
= efx_nic_alloc_buffer(efx
, &efx
->stats_buffer
,
1334 efx
->num_mac_stats
* sizeof(u64
), GFP_KERNEL
);
1337 netif_dbg(efx
, probe
, efx
->net_dev
,
1338 "stats buffer at %llx (virt %p phys %llx)\n",
1339 (u64
)efx
->stats_buffer
.dma_addr
,
1340 efx
->stats_buffer
.addr
,
1341 (u64
)virt_to_phys(efx
->stats_buffer
.addr
));
1343 efx_mcdi_mac_stats(efx
, EFX_STATS_DISABLE
, 1);
1348 void efx_mcdi_port_remove(struct efx_nic
*efx
)
1350 efx
->phy_op
->remove(efx
);
1351 efx_nic_free_buffer(efx
, &efx
->stats_buffer
);
1354 /* Get physical port number (EF10 only; on Siena it is same as PF number) */
1355 int efx_mcdi_port_get_number(struct efx_nic
*efx
)
1357 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN
);
1360 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PORT_ASSIGNMENT
, NULL
, 0,
1361 outbuf
, sizeof(outbuf
), NULL
);
1365 return MCDI_DWORD(outbuf
, GET_PORT_ASSIGNMENT_OUT_PORT
);