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 static int efx_mcdi_phy_probe(struct efx_nic
*efx
)
357 struct efx_mcdi_phy_data
*phy_data
;
358 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
362 /* Initialise and populate phy_data */
363 phy_data
= kzalloc(sizeof(*phy_data
), GFP_KERNEL
);
364 if (phy_data
== NULL
)
367 rc
= efx_mcdi_get_phy_cfg(efx
, phy_data
);
371 /* Read initial link advertisement */
372 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
373 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
374 outbuf
, sizeof(outbuf
), NULL
);
378 /* Fill out nic state */
379 efx
->phy_data
= phy_data
;
380 efx
->phy_type
= phy_data
->type
;
382 efx
->mdio_bus
= phy_data
->channel
;
383 efx
->mdio
.prtad
= phy_data
->port
;
384 efx
->mdio
.mmds
= phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
);
385 efx
->mdio
.mode_support
= 0;
386 if (phy_data
->mmd_mask
& (1 << MC_CMD_MMD_CLAUSE22
))
387 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C22
;
388 if (phy_data
->mmd_mask
& ~(1 << MC_CMD_MMD_CLAUSE22
))
389 efx
->mdio
.mode_support
|= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
391 caps
= MCDI_DWORD(outbuf
, GET_LINK_OUT_CAP
);
392 if (caps
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
393 mcdi_to_ethtool_linkset(phy_data
->media
, caps
,
394 efx
->link_advertising
);
396 phy_data
->forced_cap
= caps
;
398 /* Assert that we can map efx -> mcdi loopback modes */
399 BUILD_BUG_ON(LOOPBACK_NONE
!= MC_CMD_LOOPBACK_NONE
);
400 BUILD_BUG_ON(LOOPBACK_DATA
!= MC_CMD_LOOPBACK_DATA
);
401 BUILD_BUG_ON(LOOPBACK_GMAC
!= MC_CMD_LOOPBACK_GMAC
);
402 BUILD_BUG_ON(LOOPBACK_XGMII
!= MC_CMD_LOOPBACK_XGMII
);
403 BUILD_BUG_ON(LOOPBACK_XGXS
!= MC_CMD_LOOPBACK_XGXS
);
404 BUILD_BUG_ON(LOOPBACK_XAUI
!= MC_CMD_LOOPBACK_XAUI
);
405 BUILD_BUG_ON(LOOPBACK_GMII
!= MC_CMD_LOOPBACK_GMII
);
406 BUILD_BUG_ON(LOOPBACK_SGMII
!= MC_CMD_LOOPBACK_SGMII
);
407 BUILD_BUG_ON(LOOPBACK_XGBR
!= MC_CMD_LOOPBACK_XGBR
);
408 BUILD_BUG_ON(LOOPBACK_XFI
!= MC_CMD_LOOPBACK_XFI
);
409 BUILD_BUG_ON(LOOPBACK_XAUI_FAR
!= MC_CMD_LOOPBACK_XAUI_FAR
);
410 BUILD_BUG_ON(LOOPBACK_GMII_FAR
!= MC_CMD_LOOPBACK_GMII_FAR
);
411 BUILD_BUG_ON(LOOPBACK_SGMII_FAR
!= MC_CMD_LOOPBACK_SGMII_FAR
);
412 BUILD_BUG_ON(LOOPBACK_XFI_FAR
!= MC_CMD_LOOPBACK_XFI_FAR
);
413 BUILD_BUG_ON(LOOPBACK_GPHY
!= MC_CMD_LOOPBACK_GPHY
);
414 BUILD_BUG_ON(LOOPBACK_PHYXS
!= MC_CMD_LOOPBACK_PHYXS
);
415 BUILD_BUG_ON(LOOPBACK_PCS
!= MC_CMD_LOOPBACK_PCS
);
416 BUILD_BUG_ON(LOOPBACK_PMAPMD
!= MC_CMD_LOOPBACK_PMAPMD
);
417 BUILD_BUG_ON(LOOPBACK_XPORT
!= MC_CMD_LOOPBACK_XPORT
);
418 BUILD_BUG_ON(LOOPBACK_XGMII_WS
!= MC_CMD_LOOPBACK_XGMII_WS
);
419 BUILD_BUG_ON(LOOPBACK_XAUI_WS
!= MC_CMD_LOOPBACK_XAUI_WS
);
420 BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR
!= MC_CMD_LOOPBACK_XAUI_WS_FAR
);
421 BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR
!= MC_CMD_LOOPBACK_XAUI_WS_NEAR
);
422 BUILD_BUG_ON(LOOPBACK_GMII_WS
!= MC_CMD_LOOPBACK_GMII_WS
);
423 BUILD_BUG_ON(LOOPBACK_XFI_WS
!= MC_CMD_LOOPBACK_XFI_WS
);
424 BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR
!= MC_CMD_LOOPBACK_XFI_WS_FAR
);
425 BUILD_BUG_ON(LOOPBACK_PHYXS_WS
!= MC_CMD_LOOPBACK_PHYXS_WS
);
427 rc
= efx_mcdi_loopback_modes(efx
, &efx
->loopback_modes
);
430 /* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
431 * but by convention we don't */
432 efx
->loopback_modes
&= ~(1 << LOOPBACK_NONE
);
434 /* Set the initial link mode */
435 efx_mcdi_phy_decode_link(
436 efx
, &efx
->link_state
,
437 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
438 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
439 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
441 /* Default to Autonegotiated flow control if the PHY supports it */
442 efx
->wanted_fc
= EFX_FC_RX
| EFX_FC_TX
;
443 if (phy_data
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
444 efx
->wanted_fc
|= EFX_FC_AUTO
;
445 efx_link_set_wanted_fc(efx
, efx
->wanted_fc
);
454 int efx_mcdi_port_reconfigure(struct efx_nic
*efx
)
456 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
457 u32 caps
= (efx
->link_advertising
[0] ?
458 ethtool_linkset_to_mcdi_cap(efx
->link_advertising
) :
459 phy_cfg
->forced_cap
);
461 return efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
462 efx
->loopback_mode
, 0);
465 /* Verify that the forced flow control settings (!EFX_FC_AUTO) are
466 * supported by the link partner. Warn the user if this isn't the case
468 static void efx_mcdi_phy_check_fcntl(struct efx_nic
*efx
, u32 lpa
)
470 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
473 /* The link partner capabilities are only relevant if the
474 * link supports flow control autonegotiation */
475 if (~phy_cfg
->supported_cap
& (1 << MC_CMD_PHY_CAP_AN_LBN
))
478 /* If flow control autoneg is supported and enabled, then fine */
479 if (efx
->wanted_fc
& EFX_FC_AUTO
)
483 if (lpa
& (1 << MC_CMD_PHY_CAP_PAUSE_LBN
))
484 rmtadv
|= ADVERTISED_Pause
;
485 if (lpa
& (1 << MC_CMD_PHY_CAP_ASYM_LBN
))
486 rmtadv
|= ADVERTISED_Asym_Pause
;
488 if ((efx
->wanted_fc
& EFX_FC_TX
) && rmtadv
== ADVERTISED_Asym_Pause
)
489 netif_err(efx
, link
, efx
->net_dev
,
490 "warning: link partner doesn't support pause frames");
493 static bool efx_mcdi_phy_poll(struct efx_nic
*efx
)
495 struct efx_link_state old_state
= efx
->link_state
;
496 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
499 WARN_ON(!mutex_is_locked(&efx
->mac_lock
));
501 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
503 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
504 outbuf
, sizeof(outbuf
), NULL
);
506 efx
->link_state
.up
= false;
508 efx_mcdi_phy_decode_link(
509 efx
, &efx
->link_state
,
510 MCDI_DWORD(outbuf
, GET_LINK_OUT_LINK_SPEED
),
511 MCDI_DWORD(outbuf
, GET_LINK_OUT_FLAGS
),
512 MCDI_DWORD(outbuf
, GET_LINK_OUT_FCNTL
));
514 return !efx_link_state_equal(&efx
->link_state
, &old_state
);
517 static void efx_mcdi_phy_remove(struct efx_nic
*efx
)
519 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
521 efx
->phy_data
= NULL
;
525 static void efx_mcdi_phy_get_link_ksettings(struct efx_nic
*efx
,
526 struct ethtool_link_ksettings
*cmd
)
528 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
529 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
532 cmd
->base
.speed
= efx
->link_state
.speed
;
533 cmd
->base
.duplex
= efx
->link_state
.fd
;
534 cmd
->base
.port
= mcdi_to_ethtool_media(phy_cfg
->media
);
535 cmd
->base
.phy_address
= phy_cfg
->port
;
536 cmd
->base
.autoneg
= !!(efx
->link_advertising
[0] & ADVERTISED_Autoneg
);
537 cmd
->base
.mdio_support
= (efx
->mdio
.mode_support
&
538 (MDIO_SUPPORTS_C45
| MDIO_SUPPORTS_C22
));
540 mcdi_to_ethtool_linkset(phy_cfg
->media
, phy_cfg
->supported_cap
,
541 cmd
->link_modes
.supported
);
542 memcpy(cmd
->link_modes
.advertising
, efx
->link_advertising
,
543 sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));
545 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
546 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
547 outbuf
, sizeof(outbuf
), NULL
);
550 mcdi_to_ethtool_linkset(phy_cfg
->media
,
551 MCDI_DWORD(outbuf
, GET_LINK_OUT_LP_CAP
),
552 cmd
->link_modes
.lp_advertising
);
556 efx_mcdi_phy_set_link_ksettings(struct efx_nic
*efx
,
557 const struct ethtool_link_ksettings
*cmd
)
559 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
563 if (cmd
->base
.autoneg
) {
564 caps
= (ethtool_linkset_to_mcdi_cap(cmd
->link_modes
.advertising
) |
565 1 << MC_CMD_PHY_CAP_AN_LBN
);
566 } else if (cmd
->base
.duplex
) {
567 switch (cmd
->base
.speed
) {
568 case 10: caps
= 1 << MC_CMD_PHY_CAP_10FDX_LBN
; break;
569 case 100: caps
= 1 << MC_CMD_PHY_CAP_100FDX_LBN
; break;
570 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000FDX_LBN
; break;
571 case 10000: caps
= 1 << MC_CMD_PHY_CAP_10000FDX_LBN
; break;
572 case 40000: caps
= 1 << MC_CMD_PHY_CAP_40000FDX_LBN
; break;
573 case 100000: caps
= 1 << MC_CMD_PHY_CAP_100000FDX_LBN
; break;
574 case 25000: caps
= 1 << MC_CMD_PHY_CAP_25000FDX_LBN
; break;
575 case 50000: caps
= 1 << MC_CMD_PHY_CAP_50000FDX_LBN
; break;
576 default: return -EINVAL
;
579 switch (cmd
->base
.speed
) {
580 case 10: caps
= 1 << MC_CMD_PHY_CAP_10HDX_LBN
; break;
581 case 100: caps
= 1 << MC_CMD_PHY_CAP_100HDX_LBN
; break;
582 case 1000: caps
= 1 << MC_CMD_PHY_CAP_1000HDX_LBN
; break;
583 default: return -EINVAL
;
587 rc
= efx_mcdi_set_link(efx
, caps
, efx_get_mcdi_phy_flags(efx
),
588 efx
->loopback_mode
, 0);
592 if (cmd
->base
.autoneg
) {
593 efx_link_set_advertising(efx
, cmd
->link_modes
.advertising
);
594 phy_cfg
->forced_cap
= 0;
596 efx_link_clear_advertising(efx
);
597 phy_cfg
->forced_cap
= caps
;
602 static int efx_mcdi_phy_test_alive(struct efx_nic
*efx
)
604 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_PHY_STATE_OUT_LEN
);
608 BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN
!= 0);
610 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PHY_STATE
, NULL
, 0,
611 outbuf
, sizeof(outbuf
), &outlen
);
615 if (outlen
< MC_CMD_GET_PHY_STATE_OUT_LEN
)
617 if (MCDI_DWORD(outbuf
, GET_PHY_STATE_OUT_STATE
) != MC_CMD_PHY_STATE_OK
)
623 static const char *const mcdi_sft9001_cable_diag_names
[] = {
624 "cable.pairA.length",
625 "cable.pairB.length",
626 "cable.pairC.length",
627 "cable.pairD.length",
628 "cable.pairA.status",
629 "cable.pairB.status",
630 "cable.pairC.status",
631 "cable.pairD.status",
634 static int efx_mcdi_bist(struct efx_nic
*efx
, unsigned int bist_mode
,
637 unsigned int retry
, i
, count
= 0;
640 MCDI_DECLARE_BUF(inbuf
, MC_CMD_START_BIST_IN_LEN
);
641 MCDI_DECLARE_BUF(outbuf
, MC_CMD_POLL_BIST_OUT_SFT9001_LEN
);
645 BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN
!= 0);
646 MCDI_SET_DWORD(inbuf
, START_BIST_IN_TYPE
, bist_mode
);
647 rc
= efx_mcdi_rpc(efx
, MC_CMD_START_BIST
,
648 inbuf
, MC_CMD_START_BIST_IN_LEN
, NULL
, 0, NULL
);
652 /* Wait up to 10s for BIST to finish */
653 for (retry
= 0; retry
< 100; ++retry
) {
654 BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN
!= 0);
655 rc
= efx_mcdi_rpc(efx
, MC_CMD_POLL_BIST
, NULL
, 0,
656 outbuf
, sizeof(outbuf
), &outlen
);
660 status
= MCDI_DWORD(outbuf
, POLL_BIST_OUT_RESULT
);
661 if (status
!= MC_CMD_POLL_BIST_RUNNING
)
671 results
[count
++] = (status
== MC_CMD_POLL_BIST_PASSED
) ? 1 : -1;
673 /* SFT9001 specific cable diagnostics output */
674 if (efx
->phy_type
== PHY_TYPE_SFT9001B
&&
675 (bist_mode
== MC_CMD_PHY_BIST_CABLE_SHORT
||
676 bist_mode
== MC_CMD_PHY_BIST_CABLE_LONG
)) {
677 ptr
= MCDI_PTR(outbuf
, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A
);
678 if (status
== MC_CMD_POLL_BIST_PASSED
&&
679 outlen
>= MC_CMD_POLL_BIST_OUT_SFT9001_LEN
) {
680 for (i
= 0; i
< 8; i
++) {
682 EFX_DWORD_FIELD(((efx_dword_t
*)ptr
)[i
],
694 static int efx_mcdi_phy_run_tests(struct efx_nic
*efx
, int *results
,
697 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
701 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN
)) {
702 rc
= efx_mcdi_bist(efx
, MC_CMD_PHY_BIST
, results
);
709 /* If we support both LONG and SHORT, then run each in response to
710 * break or not. Otherwise, run the one we support */
712 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN
)) {
713 if ((flags
& ETH_TEST_FL_OFFLINE
) &&
715 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN
)))
716 mode
= MC_CMD_PHY_BIST_CABLE_LONG
;
718 mode
= MC_CMD_PHY_BIST_CABLE_SHORT
;
719 } else if (phy_cfg
->flags
&
720 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN
))
721 mode
= MC_CMD_PHY_BIST_CABLE_LONG
;
724 rc
= efx_mcdi_bist(efx
, mode
, results
);
733 static const char *efx_mcdi_phy_test_name(struct efx_nic
*efx
,
736 struct efx_mcdi_phy_data
*phy_cfg
= efx
->phy_data
;
738 if (phy_cfg
->flags
& (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN
)) {
744 if (phy_cfg
->flags
& ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN
) |
745 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN
))) {
750 if (efx
->phy_type
== PHY_TYPE_SFT9001B
) {
751 if (index
< ARRAY_SIZE(mcdi_sft9001_cable_diag_names
))
752 return mcdi_sft9001_cable_diag_names
[index
];
753 index
-= ARRAY_SIZE(mcdi_sft9001_cable_diag_names
);
760 #define SFP_PAGE_SIZE 128
761 #define SFF_DIAG_TYPE_OFFSET 92
762 #define SFF_DIAG_ADDR_CHANGE BIT(2)
763 #define SFF_8079_NUM_PAGES 2
764 #define SFF_8472_NUM_PAGES 4
765 #define SFF_8436_NUM_PAGES 5
766 #define SFF_DMT_LEVEL_OFFSET 94
768 /** efx_mcdi_phy_get_module_eeprom_page() - Get a single page of module eeprom
770 * @page: EEPROM page number
771 * @data: Destination data pointer
772 * @offset: Offset in page to copy from in to data
773 * @space: Space available in data
776 * >=0 - amount of data copied
779 static int efx_mcdi_phy_get_module_eeprom_page(struct efx_nic
*efx
,
781 u8
*data
, ssize_t offset
,
784 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX
);
785 MCDI_DECLARE_BUF(inbuf
, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN
);
787 unsigned int payload_len
;
788 unsigned int to_copy
;
791 if (offset
> SFP_PAGE_SIZE
)
794 to_copy
= min(space
, SFP_PAGE_SIZE
- offset
);
796 MCDI_SET_DWORD(inbuf
, GET_PHY_MEDIA_INFO_IN_PAGE
, page
);
797 rc
= efx_mcdi_rpc_quiet(efx
, MC_CMD_GET_PHY_MEDIA_INFO
,
798 inbuf
, sizeof(inbuf
),
799 outbuf
, sizeof(outbuf
),
805 if (outlen
< (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST
+
809 payload_len
= MCDI_DWORD(outbuf
, GET_PHY_MEDIA_INFO_OUT_DATALEN
);
810 if (payload_len
!= SFP_PAGE_SIZE
)
813 memcpy(data
, MCDI_PTR(outbuf
, GET_PHY_MEDIA_INFO_OUT_DATA
) + offset
,
819 static int efx_mcdi_phy_get_module_eeprom_byte(struct efx_nic
*efx
,
826 rc
= efx_mcdi_phy_get_module_eeprom_page(efx
, page
, &data
, byte
, 1);
833 static int efx_mcdi_phy_diag_type(struct efx_nic
*efx
)
835 /* Page zero of the EEPROM includes the diagnostic type at byte 92. */
836 return efx_mcdi_phy_get_module_eeprom_byte(efx
, 0,
837 SFF_DIAG_TYPE_OFFSET
);
840 static int efx_mcdi_phy_sff_8472_level(struct efx_nic
*efx
)
842 /* Page zero of the EEPROM includes the DMT level at byte 94. */
843 return efx_mcdi_phy_get_module_eeprom_byte(efx
, 0,
844 SFF_DMT_LEVEL_OFFSET
);
847 static u32
efx_mcdi_phy_module_type(struct efx_nic
*efx
)
849 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
851 if (phy_data
->media
!= MC_CMD_MEDIA_QSFP_PLUS
)
852 return phy_data
->media
;
854 /* A QSFP+ NIC may actually have an SFP+ module attached.
855 * The ID is page 0, byte 0.
857 switch (efx_mcdi_phy_get_module_eeprom_byte(efx
, 0, 0)) {
859 return MC_CMD_MEDIA_SFP_PLUS
;
862 return MC_CMD_MEDIA_QSFP_PLUS
;
868 static int efx_mcdi_phy_get_module_eeprom(struct efx_nic
*efx
,
869 struct ethtool_eeprom
*ee
, u8
*data
)
872 ssize_t space_remaining
= ee
->len
;
873 unsigned int page_off
;
878 switch (efx_mcdi_phy_module_type(efx
)) {
879 case MC_CMD_MEDIA_SFP_PLUS
:
880 num_pages
= efx_mcdi_phy_sff_8472_level(efx
) > 0 ?
881 SFF_8472_NUM_PAGES
: SFF_8079_NUM_PAGES
;
883 ignore_missing
= false;
885 case MC_CMD_MEDIA_QSFP_PLUS
:
886 num_pages
= SFF_8436_NUM_PAGES
;
887 page
= -1; /* We obtain the lower page by asking for -1. */
888 ignore_missing
= true; /* Ignore missing pages after page 0. */
894 page_off
= ee
->offset
% SFP_PAGE_SIZE
;
895 page
+= ee
->offset
/ SFP_PAGE_SIZE
;
897 while (space_remaining
&& (page
< num_pages
)) {
898 rc
= efx_mcdi_phy_get_module_eeprom_page(efx
, page
,
903 space_remaining
-= rc
;
907 } else if (rc
== 0) {
909 } else if (ignore_missing
&& (page
> 0)) {
910 int intended_size
= SFP_PAGE_SIZE
- page_off
;
912 space_remaining
-= intended_size
;
913 if (space_remaining
< 0) {
916 memset(data
, 0, intended_size
);
917 data
+= intended_size
;
930 static int efx_mcdi_phy_get_module_info(struct efx_nic
*efx
,
931 struct ethtool_modinfo
*modinfo
)
936 switch (efx_mcdi_phy_module_type(efx
)) {
937 case MC_CMD_MEDIA_SFP_PLUS
:
938 sff_8472_level
= efx_mcdi_phy_sff_8472_level(efx
);
940 /* If we can't read the diagnostics level we have none. */
941 if (sff_8472_level
< 0)
944 /* Check if this module requires the (unsupported) address
947 diag_type
= efx_mcdi_phy_diag_type(efx
);
949 if ((sff_8472_level
== 0) ||
950 (diag_type
& SFF_DIAG_ADDR_CHANGE
)) {
951 modinfo
->type
= ETH_MODULE_SFF_8079
;
952 modinfo
->eeprom_len
= ETH_MODULE_SFF_8079_LEN
;
954 modinfo
->type
= ETH_MODULE_SFF_8472
;
955 modinfo
->eeprom_len
= ETH_MODULE_SFF_8472_LEN
;
959 case MC_CMD_MEDIA_QSFP_PLUS
:
960 modinfo
->type
= ETH_MODULE_SFF_8436
;
961 modinfo
->eeprom_len
= ETH_MODULE_SFF_8436_LEN
;
971 static const struct efx_phy_operations efx_mcdi_phy_ops
= {
972 .probe
= efx_mcdi_phy_probe
,
973 .init
= efx_port_dummy_op_int
,
974 .reconfigure
= efx_mcdi_port_reconfigure
,
975 .poll
= efx_mcdi_phy_poll
,
976 .fini
= efx_port_dummy_op_void
,
977 .remove
= efx_mcdi_phy_remove
,
978 .get_link_ksettings
= efx_mcdi_phy_get_link_ksettings
,
979 .set_link_ksettings
= efx_mcdi_phy_set_link_ksettings
,
980 .test_alive
= efx_mcdi_phy_test_alive
,
981 .run_tests
= efx_mcdi_phy_run_tests
,
982 .test_name
= efx_mcdi_phy_test_name
,
983 .get_module_eeprom
= efx_mcdi_phy_get_module_eeprom
,
984 .get_module_info
= efx_mcdi_phy_get_module_info
,
987 u32
efx_mcdi_phy_get_caps(struct efx_nic
*efx
)
989 struct efx_mcdi_phy_data
*phy_data
= efx
->phy_data
;
991 return phy_data
->supported_cap
;
994 static unsigned int efx_mcdi_event_link_speed
[] = {
995 [MCDI_EVENT_LINKCHANGE_SPEED_100M
] = 100,
996 [MCDI_EVENT_LINKCHANGE_SPEED_1G
] = 1000,
997 [MCDI_EVENT_LINKCHANGE_SPEED_10G
] = 10000,
998 [MCDI_EVENT_LINKCHANGE_SPEED_40G
] = 40000,
999 [MCDI_EVENT_LINKCHANGE_SPEED_25G
] = 25000,
1000 [MCDI_EVENT_LINKCHANGE_SPEED_50G
] = 50000,
1001 [MCDI_EVENT_LINKCHANGE_SPEED_100G
] = 100000,
1004 void efx_mcdi_process_link_change(struct efx_nic
*efx
, efx_qword_t
*ev
)
1006 u32 flags
, fcntl
, speed
, lpa
;
1008 speed
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_SPEED
);
1009 EFX_WARN_ON_PARANOID(speed
>= ARRAY_SIZE(efx_mcdi_event_link_speed
));
1010 speed
= efx_mcdi_event_link_speed
[speed
];
1012 flags
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_LINK_FLAGS
);
1013 fcntl
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_FCNTL
);
1014 lpa
= EFX_QWORD_FIELD(*ev
, MCDI_EVENT_LINKCHANGE_LP_CAP
);
1016 /* efx->link_state is only modified by efx_mcdi_phy_get_link(),
1017 * which is only run after flushing the event queues. Therefore, it
1018 * is safe to modify the link state outside of the mac_lock here.
1020 efx_mcdi_phy_decode_link(efx
, &efx
->link_state
, speed
, flags
, fcntl
);
1022 efx_mcdi_phy_check_fcntl(efx
, lpa
);
1024 efx_link_status_changed(efx
);
1027 int efx_mcdi_set_mac(struct efx_nic
*efx
)
1030 MCDI_DECLARE_BUF(cmdbytes
, MC_CMD_SET_MAC_IN_LEN
);
1032 BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN
!= 0);
1034 /* This has no effect on EF10 */
1035 ether_addr_copy(MCDI_PTR(cmdbytes
, SET_MAC_IN_ADDR
),
1036 efx
->net_dev
->dev_addr
);
1038 MCDI_SET_DWORD(cmdbytes
, SET_MAC_IN_MTU
,
1039 EFX_MAX_FRAME_LEN(efx
->net_dev
->mtu
));
1040 MCDI_SET_DWORD(cmdbytes
, SET_MAC_IN_DRAIN
, 0);
1042 /* Set simple MAC filter for Siena */
1043 MCDI_POPULATE_DWORD_1(cmdbytes
, SET_MAC_IN_REJECT
,
1044 SET_MAC_IN_REJECT_UNCST
, efx
->unicast_filter
);
1046 MCDI_POPULATE_DWORD_1(cmdbytes
, SET_MAC_IN_FLAGS
,
1047 SET_MAC_IN_FLAG_INCLUDE_FCS
,
1048 !!(efx
->net_dev
->features
& NETIF_F_RXFCS
));
1050 switch (efx
->wanted_fc
) {
1051 case EFX_FC_RX
| EFX_FC_TX
:
1052 fcntl
= MC_CMD_FCNTL_BIDIR
;
1055 fcntl
= MC_CMD_FCNTL_RESPOND
;
1058 fcntl
= MC_CMD_FCNTL_OFF
;
1061 if (efx
->wanted_fc
& EFX_FC_AUTO
)
1062 fcntl
= MC_CMD_FCNTL_AUTO
;
1063 if (efx
->fc_disable
)
1064 fcntl
= MC_CMD_FCNTL_OFF
;
1066 MCDI_SET_DWORD(cmdbytes
, SET_MAC_IN_FCNTL
, fcntl
);
1068 return efx_mcdi_rpc(efx
, MC_CMD_SET_MAC
, cmdbytes
, sizeof(cmdbytes
),
1072 bool efx_mcdi_mac_check_fault(struct efx_nic
*efx
)
1074 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_LINK_OUT_LEN
);
1078 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN
!= 0);
1080 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_LINK
, NULL
, 0,
1081 outbuf
, sizeof(outbuf
), &outlength
);
1085 return MCDI_DWORD(outbuf
, GET_LINK_OUT_MAC_FAULT
) != 0;
1088 enum efx_stats_action
{
1094 static int efx_mcdi_mac_stats(struct efx_nic
*efx
,
1095 enum efx_stats_action action
, int clear
)
1097 MCDI_DECLARE_BUF(inbuf
, MC_CMD_MAC_STATS_IN_LEN
);
1099 int change
= action
== EFX_STATS_PULL
? 0 : 1;
1100 int enable
= action
== EFX_STATS_ENABLE
? 1 : 0;
1101 int period
= action
== EFX_STATS_ENABLE
? 1000 : 0;
1102 dma_addr_t dma_addr
= efx
->stats_buffer
.dma_addr
;
1103 u32 dma_len
= action
!= EFX_STATS_DISABLE
?
1104 efx
->num_mac_stats
* sizeof(u64
) : 0;
1106 BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN
!= 0);
1108 MCDI_SET_QWORD(inbuf
, MAC_STATS_IN_DMA_ADDR
, dma_addr
);
1109 MCDI_POPULATE_DWORD_7(inbuf
, MAC_STATS_IN_CMD
,
1110 MAC_STATS_IN_DMA
, !!enable
,
1111 MAC_STATS_IN_CLEAR
, clear
,
1112 MAC_STATS_IN_PERIODIC_CHANGE
, change
,
1113 MAC_STATS_IN_PERIODIC_ENABLE
, enable
,
1114 MAC_STATS_IN_PERIODIC_CLEAR
, 0,
1115 MAC_STATS_IN_PERIODIC_NOEVENT
, 1,
1116 MAC_STATS_IN_PERIOD_MS
, period
);
1117 MCDI_SET_DWORD(inbuf
, MAC_STATS_IN_DMA_LEN
, dma_len
);
1119 if (efx_nic_rev(efx
) >= EFX_REV_HUNT_A0
) {
1120 struct efx_ef10_nic_data
*nic_data
= efx
->nic_data
;
1122 MCDI_SET_DWORD(inbuf
, MAC_STATS_IN_PORT_ID
, nic_data
->vport_id
);
1125 rc
= efx_mcdi_rpc_quiet(efx
, MC_CMD_MAC_STATS
, inbuf
, sizeof(inbuf
),
1127 /* Expect ENOENT if DMA queues have not been set up */
1128 if (rc
&& (rc
!= -ENOENT
|| atomic_read(&efx
->active_queues
)))
1129 efx_mcdi_display_error(efx
, MC_CMD_MAC_STATS
, sizeof(inbuf
),
1134 void efx_mcdi_mac_start_stats(struct efx_nic
*efx
)
1136 __le64
*dma_stats
= efx
->stats_buffer
.addr
;
1138 dma_stats
[efx
->num_mac_stats
- 1] = EFX_MC_STATS_GENERATION_INVALID
;
1140 efx_mcdi_mac_stats(efx
, EFX_STATS_ENABLE
, 0);
1143 void efx_mcdi_mac_stop_stats(struct efx_nic
*efx
)
1145 efx_mcdi_mac_stats(efx
, EFX_STATS_DISABLE
, 0);
1148 #define EFX_MAC_STATS_WAIT_US 100
1149 #define EFX_MAC_STATS_WAIT_ATTEMPTS 10
1151 void efx_mcdi_mac_pull_stats(struct efx_nic
*efx
)
1153 __le64
*dma_stats
= efx
->stats_buffer
.addr
;
1154 int attempts
= EFX_MAC_STATS_WAIT_ATTEMPTS
;
1156 dma_stats
[efx
->num_mac_stats
- 1] = EFX_MC_STATS_GENERATION_INVALID
;
1157 efx_mcdi_mac_stats(efx
, EFX_STATS_PULL
, 0);
1159 while (dma_stats
[efx
->num_mac_stats
- 1] ==
1160 EFX_MC_STATS_GENERATION_INVALID
&&
1162 udelay(EFX_MAC_STATS_WAIT_US
);
1165 int efx_mcdi_port_probe(struct efx_nic
*efx
)
1169 /* Hook in PHY operations table */
1170 efx
->phy_op
= &efx_mcdi_phy_ops
;
1172 /* Set up MDIO structure for PHY */
1173 efx
->mdio
.mode_support
= MDIO_SUPPORTS_C45
| MDIO_EMULATE_C22
;
1174 efx
->mdio
.mdio_read
= efx_mcdi_mdio_read
;
1175 efx
->mdio
.mdio_write
= efx_mcdi_mdio_write
;
1177 /* Fill out MDIO structure, loopback modes, and initial link state */
1178 rc
= efx
->phy_op
->probe(efx
);
1182 /* Allocate buffer for stats */
1183 rc
= efx_nic_alloc_buffer(efx
, &efx
->stats_buffer
,
1184 efx
->num_mac_stats
* sizeof(u64
), GFP_KERNEL
);
1187 netif_dbg(efx
, probe
, efx
->net_dev
,
1188 "stats buffer at %llx (virt %p phys %llx)\n",
1189 (u64
)efx
->stats_buffer
.dma_addr
,
1190 efx
->stats_buffer
.addr
,
1191 (u64
)virt_to_phys(efx
->stats_buffer
.addr
));
1193 efx_mcdi_mac_stats(efx
, EFX_STATS_DISABLE
, 1);
1198 void efx_mcdi_port_remove(struct efx_nic
*efx
)
1200 efx
->phy_op
->remove(efx
);
1201 efx_nic_free_buffer(efx
, &efx
->stats_buffer
);
1204 /* Get physical port number (EF10 only; on Siena it is same as PF number) */
1205 int efx_mcdi_port_get_number(struct efx_nic
*efx
)
1207 MCDI_DECLARE_BUF(outbuf
, MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN
);
1210 rc
= efx_mcdi_rpc(efx
, MC_CMD_GET_PORT_ASSIGNMENT
, NULL
, 0,
1211 outbuf
, sizeof(outbuf
), NULL
);
1215 return MCDI_DWORD(outbuf
, GET_PORT_ASSIGNMENT_OUT_PORT
);