1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2009-2013 Solarflare Communications Inc.
8 * Driver for PHY related operations via MCDI.
11 #include <linux/slab.h>
14 #include "mcdi_pcol.h"
18 struct efx_mcdi_phy_data {
33 efx_mcdi_get_phy_cfg(struct efx_nic *efx, struct efx_mcdi_phy_data *cfg)
35 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_CFG_OUT_LEN);
39 BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_IN_LEN != 0);
40 BUILD_BUG_ON(MC_CMD_GET_PHY_CFG_OUT_NAME_LEN != sizeof(cfg->name));
42 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_CFG, NULL, 0,
43 outbuf, sizeof(outbuf), &outlen);
47 if (outlen < MC_CMD_GET_PHY_CFG_OUT_LEN) {
52 cfg->flags = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_FLAGS);
53 cfg->type = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_TYPE);
55 MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_SUPPORTED_CAP);
56 cfg->channel = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_CHANNEL);
57 cfg->port = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_PRT);
58 cfg->stats_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_STATS_MASK);
59 memcpy(cfg->name, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_NAME),
61 cfg->media = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MEDIA_TYPE);
62 cfg->mmd_mask = MCDI_DWORD(outbuf, GET_PHY_CFG_OUT_MMD_MASK);
63 memcpy(cfg->revision, MCDI_PTR(outbuf, GET_PHY_CFG_OUT_REVISION),
64 sizeof(cfg->revision));
69 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
73 static int efx_mcdi_set_link(struct efx_nic *efx, u32 capabilities,
74 u32 flags, u32 loopback_mode,
77 MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_LINK_IN_LEN);
80 BUILD_BUG_ON(MC_CMD_SET_LINK_OUT_LEN != 0);
82 MCDI_SET_DWORD(inbuf, SET_LINK_IN_CAP, capabilities);
83 MCDI_SET_DWORD(inbuf, SET_LINK_IN_FLAGS, flags);
84 MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_MODE, loopback_mode);
85 MCDI_SET_DWORD(inbuf, SET_LINK_IN_LOOPBACK_SPEED, loopback_speed);
87 rc = efx_mcdi_rpc(efx, MC_CMD_SET_LINK, inbuf, sizeof(inbuf),
92 static int efx_mcdi_loopback_modes(struct efx_nic *efx, u64 *loopback_modes)
94 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LOOPBACK_MODES_OUT_LEN);
98 rc = efx_mcdi_rpc(efx, MC_CMD_GET_LOOPBACK_MODES, NULL, 0,
99 outbuf, sizeof(outbuf), &outlen);
103 if (outlen < (MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_OFST +
104 MC_CMD_GET_LOOPBACK_MODES_OUT_SUGGESTED_LEN)) {
109 *loopback_modes = MCDI_QWORD(outbuf, GET_LOOPBACK_MODES_OUT_SUGGESTED);
114 netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
118 static int efx_mcdi_mdio_read(struct net_device *net_dev,
119 int prtad, int devad, u16 addr)
121 struct efx_nic *efx = netdev_priv(net_dev);
122 MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_READ_IN_LEN);
123 MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_READ_OUT_LEN);
127 MCDI_SET_DWORD(inbuf, MDIO_READ_IN_BUS, efx->mdio_bus);
128 MCDI_SET_DWORD(inbuf, MDIO_READ_IN_PRTAD, prtad);
129 MCDI_SET_DWORD(inbuf, MDIO_READ_IN_DEVAD, devad);
130 MCDI_SET_DWORD(inbuf, MDIO_READ_IN_ADDR, addr);
132 rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_READ, inbuf, sizeof(inbuf),
133 outbuf, sizeof(outbuf), &outlen);
137 if (MCDI_DWORD(outbuf, MDIO_READ_OUT_STATUS) !=
138 MC_CMD_MDIO_STATUS_GOOD)
141 return (u16)MCDI_DWORD(outbuf, MDIO_READ_OUT_VALUE);
144 static int efx_mcdi_mdio_write(struct net_device *net_dev,
145 int prtad, int devad, u16 addr, u16 value)
147 struct efx_nic *efx = netdev_priv(net_dev);
148 MCDI_DECLARE_BUF(inbuf, MC_CMD_MDIO_WRITE_IN_LEN);
149 MCDI_DECLARE_BUF(outbuf, MC_CMD_MDIO_WRITE_OUT_LEN);
153 MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_BUS, efx->mdio_bus);
154 MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_PRTAD, prtad);
155 MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_DEVAD, devad);
156 MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_ADDR, addr);
157 MCDI_SET_DWORD(inbuf, MDIO_WRITE_IN_VALUE, value);
159 rc = efx_mcdi_rpc(efx, MC_CMD_MDIO_WRITE, inbuf, sizeof(inbuf),
160 outbuf, sizeof(outbuf), &outlen);
164 if (MCDI_DWORD(outbuf, MDIO_WRITE_OUT_STATUS) !=
165 MC_CMD_MDIO_STATUS_GOOD)
171 static void mcdi_to_ethtool_linkset(u32 media, u32 cap, unsigned long *linkset)
173 #define SET_BIT(name) __set_bit(ETHTOOL_LINK_MODE_ ## name ## _BIT, \
176 bitmap_zero(linkset, __ETHTOOL_LINK_MODE_MASK_NBITS);
178 case MC_CMD_MEDIA_KX4:
180 if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
181 SET_BIT(1000baseKX_Full);
182 if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
183 SET_BIT(10000baseKX4_Full);
184 if (cap & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
185 SET_BIT(40000baseKR4_Full);
188 case MC_CMD_MEDIA_XFP:
189 case MC_CMD_MEDIA_SFP_PLUS:
190 case MC_CMD_MEDIA_QSFP_PLUS:
192 if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
193 SET_BIT(1000baseT_Full);
194 if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
195 SET_BIT(10000baseT_Full);
196 if (cap & (1 << MC_CMD_PHY_CAP_40000FDX_LBN))
197 SET_BIT(40000baseCR4_Full);
198 if (cap & (1 << MC_CMD_PHY_CAP_100000FDX_LBN))
199 SET_BIT(100000baseCR4_Full);
200 if (cap & (1 << MC_CMD_PHY_CAP_25000FDX_LBN))
201 SET_BIT(25000baseCR_Full);
202 if (cap & (1 << MC_CMD_PHY_CAP_50000FDX_LBN))
203 SET_BIT(50000baseCR2_Full);
206 case MC_CMD_MEDIA_BASE_T:
208 if (cap & (1 << MC_CMD_PHY_CAP_10HDX_LBN))
209 SET_BIT(10baseT_Half);
210 if (cap & (1 << MC_CMD_PHY_CAP_10FDX_LBN))
211 SET_BIT(10baseT_Full);
212 if (cap & (1 << MC_CMD_PHY_CAP_100HDX_LBN))
213 SET_BIT(100baseT_Half);
214 if (cap & (1 << MC_CMD_PHY_CAP_100FDX_LBN))
215 SET_BIT(100baseT_Full);
216 if (cap & (1 << MC_CMD_PHY_CAP_1000HDX_LBN))
217 SET_BIT(1000baseT_Half);
218 if (cap & (1 << MC_CMD_PHY_CAP_1000FDX_LBN))
219 SET_BIT(1000baseT_Full);
220 if (cap & (1 << MC_CMD_PHY_CAP_10000FDX_LBN))
221 SET_BIT(10000baseT_Full);
225 if (cap & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
227 if (cap & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
229 if (cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
235 static u32 ethtool_linkset_to_mcdi_cap(const unsigned long *linkset)
239 #define TEST_BIT(name) test_bit(ETHTOOL_LINK_MODE_ ## name ## _BIT, \
242 if (TEST_BIT(10baseT_Half))
243 result |= (1 << MC_CMD_PHY_CAP_10HDX_LBN);
244 if (TEST_BIT(10baseT_Full))
245 result |= (1 << MC_CMD_PHY_CAP_10FDX_LBN);
246 if (TEST_BIT(100baseT_Half))
247 result |= (1 << MC_CMD_PHY_CAP_100HDX_LBN);
248 if (TEST_BIT(100baseT_Full))
249 result |= (1 << MC_CMD_PHY_CAP_100FDX_LBN);
250 if (TEST_BIT(1000baseT_Half))
251 result |= (1 << MC_CMD_PHY_CAP_1000HDX_LBN);
252 if (TEST_BIT(1000baseT_Full) || TEST_BIT(1000baseKX_Full))
253 result |= (1 << MC_CMD_PHY_CAP_1000FDX_LBN);
254 if (TEST_BIT(10000baseT_Full) || TEST_BIT(10000baseKX4_Full))
255 result |= (1 << MC_CMD_PHY_CAP_10000FDX_LBN);
256 if (TEST_BIT(40000baseCR4_Full) || TEST_BIT(40000baseKR4_Full))
257 result |= (1 << MC_CMD_PHY_CAP_40000FDX_LBN);
258 if (TEST_BIT(100000baseCR4_Full))
259 result |= (1 << MC_CMD_PHY_CAP_100000FDX_LBN);
260 if (TEST_BIT(25000baseCR_Full))
261 result |= (1 << MC_CMD_PHY_CAP_25000FDX_LBN);
262 if (TEST_BIT(50000baseCR2_Full))
263 result |= (1 << MC_CMD_PHY_CAP_50000FDX_LBN);
265 result |= (1 << MC_CMD_PHY_CAP_PAUSE_LBN);
266 if (TEST_BIT(Asym_Pause))
267 result |= (1 << MC_CMD_PHY_CAP_ASYM_LBN);
268 if (TEST_BIT(Autoneg))
269 result |= (1 << MC_CMD_PHY_CAP_AN_LBN);
276 static u32 efx_get_mcdi_phy_flags(struct efx_nic *efx)
278 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
279 enum efx_phy_mode mode, supported;
282 /* TODO: Advertise the capabilities supported by this PHY */
284 if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_TXDIS_LBN))
285 supported |= PHY_MODE_TX_DISABLED;
286 if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_LOWPOWER_LBN))
287 supported |= PHY_MODE_LOW_POWER;
288 if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_POWEROFF_LBN))
289 supported |= PHY_MODE_OFF;
291 mode = efx->phy_mode & supported;
294 if (mode & PHY_MODE_TX_DISABLED)
295 flags |= (1 << MC_CMD_SET_LINK_IN_TXDIS_LBN);
296 if (mode & PHY_MODE_LOW_POWER)
297 flags |= (1 << MC_CMD_SET_LINK_IN_LOWPOWER_LBN);
298 if (mode & PHY_MODE_OFF)
299 flags |= (1 << MC_CMD_SET_LINK_IN_POWEROFF_LBN);
304 static u8 mcdi_to_ethtool_media(u32 media)
307 case MC_CMD_MEDIA_XAUI:
308 case MC_CMD_MEDIA_CX4:
309 case MC_CMD_MEDIA_KX4:
312 case MC_CMD_MEDIA_XFP:
313 case MC_CMD_MEDIA_SFP_PLUS:
314 case MC_CMD_MEDIA_QSFP_PLUS:
317 case MC_CMD_MEDIA_BASE_T:
325 static void efx_mcdi_phy_decode_link(struct efx_nic *efx,
326 struct efx_link_state *link_state,
327 u32 speed, u32 flags, u32 fcntl)
330 case MC_CMD_FCNTL_AUTO:
331 WARN_ON(1); /* This is not a link mode */
332 link_state->fc = EFX_FC_AUTO | EFX_FC_TX | EFX_FC_RX;
334 case MC_CMD_FCNTL_BIDIR:
335 link_state->fc = EFX_FC_TX | EFX_FC_RX;
337 case MC_CMD_FCNTL_RESPOND:
338 link_state->fc = EFX_FC_RX;
343 case MC_CMD_FCNTL_OFF:
348 link_state->up = !!(flags & (1 << MC_CMD_GET_LINK_OUT_LINK_UP_LBN));
349 link_state->fd = !!(flags & (1 << MC_CMD_GET_LINK_OUT_FULL_DUPLEX_LBN));
350 link_state->speed = speed;
353 /* The semantics of the ethtool FEC mode bitmask are not well defined,
354 * particularly the meaning of combinations of bits. Which means we get to
355 * define our own semantics, as follows:
356 * OFF overrides any other bits, and means "disable all FEC" (with the
357 * exception of 25G KR4/CR4, where it is not possible to reject it if AN
358 * partner requests it).
359 * AUTO on its own means use cable requirements and link partner autoneg with
360 * fw-default preferences for the cable type.
361 * AUTO and either RS or BASER means use the specified FEC type if cable and
362 * link partner support it, otherwise autoneg/fw-default.
363 * RS or BASER alone means use the specified FEC type if cable and link partner
364 * support it and either requests it, otherwise no FEC.
365 * Both RS and BASER (whether AUTO or not) means use FEC if cable and link
366 * partner support it, preferring RS to BASER.
368 static u32 ethtool_fec_caps_to_mcdi(u32 ethtool_cap)
372 if (ethtool_cap & ETHTOOL_FEC_OFF)
375 if (ethtool_cap & ETHTOOL_FEC_AUTO)
376 ret |= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
377 (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
378 (1 << MC_CMD_PHY_CAP_RS_FEC_LBN);
379 if (ethtool_cap & ETHTOOL_FEC_RS)
380 ret |= (1 << MC_CMD_PHY_CAP_RS_FEC_LBN) |
381 (1 << MC_CMD_PHY_CAP_RS_FEC_REQUESTED_LBN);
382 if (ethtool_cap & ETHTOOL_FEC_BASER)
383 ret |= (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN) |
384 (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN) |
385 (1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN) |
386 (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN);
390 /* Invert ethtool_fec_caps_to_mcdi. There are two combinations that function
391 * can never produce, (baser xor rs) and neither req; the implementation below
392 * maps both of those to AUTO. This should never matter, and it's not clear
393 * what a better mapping would be anyway.
395 static u32 mcdi_fec_caps_to_ethtool(u32 caps, bool is_25g)
397 bool rs = caps & (1 << MC_CMD_PHY_CAP_RS_FEC_LBN),
398 rs_req = caps & (1 << MC_CMD_PHY_CAP_RS_FEC_REQUESTED_LBN),
399 baser = is_25g ? caps & (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_LBN)
400 : caps & (1 << MC_CMD_PHY_CAP_BASER_FEC_LBN),
401 baser_req = is_25g ? caps & (1 << MC_CMD_PHY_CAP_25G_BASER_FEC_REQUESTED_LBN)
402 : caps & (1 << MC_CMD_PHY_CAP_BASER_FEC_REQUESTED_LBN);
405 return ETHTOOL_FEC_OFF;
406 return (rs_req ? ETHTOOL_FEC_RS : 0) |
407 (baser_req ? ETHTOOL_FEC_BASER : 0) |
408 (baser == baser_req && rs == rs_req ? 0 : ETHTOOL_FEC_AUTO);
411 static int efx_mcdi_phy_probe(struct efx_nic *efx)
413 struct efx_mcdi_phy_data *phy_data;
414 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
418 /* Initialise and populate phy_data */
419 phy_data = kzalloc(sizeof(*phy_data), GFP_KERNEL);
420 if (phy_data == NULL)
423 rc = efx_mcdi_get_phy_cfg(efx, phy_data);
427 /* Read initial link advertisement */
428 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
429 rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
430 outbuf, sizeof(outbuf), NULL);
434 /* Fill out nic state */
435 efx->phy_data = phy_data;
436 efx->phy_type = phy_data->type;
438 efx->mdio_bus = phy_data->channel;
439 efx->mdio.prtad = phy_data->port;
440 efx->mdio.mmds = phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22);
441 efx->mdio.mode_support = 0;
442 if (phy_data->mmd_mask & (1 << MC_CMD_MMD_CLAUSE22))
443 efx->mdio.mode_support |= MDIO_SUPPORTS_C22;
444 if (phy_data->mmd_mask & ~(1 << MC_CMD_MMD_CLAUSE22))
445 efx->mdio.mode_support |= MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
447 caps = MCDI_DWORD(outbuf, GET_LINK_OUT_CAP);
448 if (caps & (1 << MC_CMD_PHY_CAP_AN_LBN))
449 mcdi_to_ethtool_linkset(phy_data->media, caps,
450 efx->link_advertising);
452 phy_data->forced_cap = caps;
454 /* Assert that we can map efx -> mcdi loopback modes */
455 BUILD_BUG_ON(LOOPBACK_NONE != MC_CMD_LOOPBACK_NONE);
456 BUILD_BUG_ON(LOOPBACK_DATA != MC_CMD_LOOPBACK_DATA);
457 BUILD_BUG_ON(LOOPBACK_GMAC != MC_CMD_LOOPBACK_GMAC);
458 BUILD_BUG_ON(LOOPBACK_XGMII != MC_CMD_LOOPBACK_XGMII);
459 BUILD_BUG_ON(LOOPBACK_XGXS != MC_CMD_LOOPBACK_XGXS);
460 BUILD_BUG_ON(LOOPBACK_XAUI != MC_CMD_LOOPBACK_XAUI);
461 BUILD_BUG_ON(LOOPBACK_GMII != MC_CMD_LOOPBACK_GMII);
462 BUILD_BUG_ON(LOOPBACK_SGMII != MC_CMD_LOOPBACK_SGMII);
463 BUILD_BUG_ON(LOOPBACK_XGBR != MC_CMD_LOOPBACK_XGBR);
464 BUILD_BUG_ON(LOOPBACK_XFI != MC_CMD_LOOPBACK_XFI);
465 BUILD_BUG_ON(LOOPBACK_XAUI_FAR != MC_CMD_LOOPBACK_XAUI_FAR);
466 BUILD_BUG_ON(LOOPBACK_GMII_FAR != MC_CMD_LOOPBACK_GMII_FAR);
467 BUILD_BUG_ON(LOOPBACK_SGMII_FAR != MC_CMD_LOOPBACK_SGMII_FAR);
468 BUILD_BUG_ON(LOOPBACK_XFI_FAR != MC_CMD_LOOPBACK_XFI_FAR);
469 BUILD_BUG_ON(LOOPBACK_GPHY != MC_CMD_LOOPBACK_GPHY);
470 BUILD_BUG_ON(LOOPBACK_PHYXS != MC_CMD_LOOPBACK_PHYXS);
471 BUILD_BUG_ON(LOOPBACK_PCS != MC_CMD_LOOPBACK_PCS);
472 BUILD_BUG_ON(LOOPBACK_PMAPMD != MC_CMD_LOOPBACK_PMAPMD);
473 BUILD_BUG_ON(LOOPBACK_XPORT != MC_CMD_LOOPBACK_XPORT);
474 BUILD_BUG_ON(LOOPBACK_XGMII_WS != MC_CMD_LOOPBACK_XGMII_WS);
475 BUILD_BUG_ON(LOOPBACK_XAUI_WS != MC_CMD_LOOPBACK_XAUI_WS);
476 BUILD_BUG_ON(LOOPBACK_XAUI_WS_FAR != MC_CMD_LOOPBACK_XAUI_WS_FAR);
477 BUILD_BUG_ON(LOOPBACK_XAUI_WS_NEAR != MC_CMD_LOOPBACK_XAUI_WS_NEAR);
478 BUILD_BUG_ON(LOOPBACK_GMII_WS != MC_CMD_LOOPBACK_GMII_WS);
479 BUILD_BUG_ON(LOOPBACK_XFI_WS != MC_CMD_LOOPBACK_XFI_WS);
480 BUILD_BUG_ON(LOOPBACK_XFI_WS_FAR != MC_CMD_LOOPBACK_XFI_WS_FAR);
481 BUILD_BUG_ON(LOOPBACK_PHYXS_WS != MC_CMD_LOOPBACK_PHYXS_WS);
483 rc = efx_mcdi_loopback_modes(efx, &efx->loopback_modes);
486 /* The MC indicates that LOOPBACK_NONE is a valid loopback mode,
487 * but by convention we don't */
488 efx->loopback_modes &= ~(1 << LOOPBACK_NONE);
490 /* Set the initial link mode */
491 efx_mcdi_phy_decode_link(
492 efx, &efx->link_state,
493 MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
494 MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
495 MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
497 /* Record the initial FEC configuration (or nearest approximation
498 * representable in the ethtool configuration space)
500 efx->fec_config = mcdi_fec_caps_to_ethtool(caps,
501 efx->link_state.speed == 25000 ||
502 efx->link_state.speed == 50000);
504 /* Default to Autonegotiated flow control if the PHY supports it */
505 efx->wanted_fc = EFX_FC_RX | EFX_FC_TX;
506 if (phy_data->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
507 efx->wanted_fc |= EFX_FC_AUTO;
508 efx_link_set_wanted_fc(efx, efx->wanted_fc);
517 int efx_mcdi_port_reconfigure(struct efx_nic *efx)
519 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
520 u32 caps = (efx->link_advertising[0] ?
521 ethtool_linkset_to_mcdi_cap(efx->link_advertising) :
522 phy_cfg->forced_cap);
524 caps |= ethtool_fec_caps_to_mcdi(efx->fec_config);
526 return efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
527 efx->loopback_mode, 0);
530 /* Verify that the forced flow control settings (!EFX_FC_AUTO) are
531 * supported by the link partner. Warn the user if this isn't the case
533 static void efx_mcdi_phy_check_fcntl(struct efx_nic *efx, u32 lpa)
535 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
538 /* The link partner capabilities are only relevant if the
539 * link supports flow control autonegotiation */
540 if (~phy_cfg->supported_cap & (1 << MC_CMD_PHY_CAP_AN_LBN))
543 /* If flow control autoneg is supported and enabled, then fine */
544 if (efx->wanted_fc & EFX_FC_AUTO)
548 if (lpa & (1 << MC_CMD_PHY_CAP_PAUSE_LBN))
549 rmtadv |= ADVERTISED_Pause;
550 if (lpa & (1 << MC_CMD_PHY_CAP_ASYM_LBN))
551 rmtadv |= ADVERTISED_Asym_Pause;
553 if ((efx->wanted_fc & EFX_FC_TX) && rmtadv == ADVERTISED_Asym_Pause)
554 netif_err(efx, link, efx->net_dev,
555 "warning: link partner doesn't support pause frames");
558 static bool efx_mcdi_phy_poll(struct efx_nic *efx)
560 struct efx_link_state old_state = efx->link_state;
561 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
564 WARN_ON(!mutex_is_locked(&efx->mac_lock));
566 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
568 rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
569 outbuf, sizeof(outbuf), NULL);
571 efx->link_state.up = false;
573 efx_mcdi_phy_decode_link(
574 efx, &efx->link_state,
575 MCDI_DWORD(outbuf, GET_LINK_OUT_LINK_SPEED),
576 MCDI_DWORD(outbuf, GET_LINK_OUT_FLAGS),
577 MCDI_DWORD(outbuf, GET_LINK_OUT_FCNTL));
579 return !efx_link_state_equal(&efx->link_state, &old_state);
582 static void efx_mcdi_phy_remove(struct efx_nic *efx)
584 struct efx_mcdi_phy_data *phy_data = efx->phy_data;
586 efx->phy_data = NULL;
590 static void efx_mcdi_phy_get_link_ksettings(struct efx_nic *efx,
591 struct ethtool_link_ksettings *cmd)
593 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
594 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
597 cmd->base.speed = efx->link_state.speed;
598 cmd->base.duplex = efx->link_state.fd;
599 cmd->base.port = mcdi_to_ethtool_media(phy_cfg->media);
600 cmd->base.phy_address = phy_cfg->port;
601 cmd->base.autoneg = !!(efx->link_advertising[0] & ADVERTISED_Autoneg);
602 cmd->base.mdio_support = (efx->mdio.mode_support &
603 (MDIO_SUPPORTS_C45 | MDIO_SUPPORTS_C22));
605 mcdi_to_ethtool_linkset(phy_cfg->media, phy_cfg->supported_cap,
606 cmd->link_modes.supported);
607 memcpy(cmd->link_modes.advertising, efx->link_advertising,
608 sizeof(__ETHTOOL_DECLARE_LINK_MODE_MASK()));
610 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
611 rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
612 outbuf, sizeof(outbuf), NULL);
615 mcdi_to_ethtool_linkset(phy_cfg->media,
616 MCDI_DWORD(outbuf, GET_LINK_OUT_LP_CAP),
617 cmd->link_modes.lp_advertising);
621 efx_mcdi_phy_set_link_ksettings(struct efx_nic *efx,
622 const struct ethtool_link_ksettings *cmd)
624 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
628 if (cmd->base.autoneg) {
629 caps = (ethtool_linkset_to_mcdi_cap(cmd->link_modes.advertising) |
630 1 << MC_CMD_PHY_CAP_AN_LBN);
631 } else if (cmd->base.duplex) {
632 switch (cmd->base.speed) {
633 case 10: caps = 1 << MC_CMD_PHY_CAP_10FDX_LBN; break;
634 case 100: caps = 1 << MC_CMD_PHY_CAP_100FDX_LBN; break;
635 case 1000: caps = 1 << MC_CMD_PHY_CAP_1000FDX_LBN; break;
636 case 10000: caps = 1 << MC_CMD_PHY_CAP_10000FDX_LBN; break;
637 case 40000: caps = 1 << MC_CMD_PHY_CAP_40000FDX_LBN; break;
638 case 100000: caps = 1 << MC_CMD_PHY_CAP_100000FDX_LBN; break;
639 case 25000: caps = 1 << MC_CMD_PHY_CAP_25000FDX_LBN; break;
640 case 50000: caps = 1 << MC_CMD_PHY_CAP_50000FDX_LBN; break;
641 default: return -EINVAL;
644 switch (cmd->base.speed) {
645 case 10: caps = 1 << MC_CMD_PHY_CAP_10HDX_LBN; break;
646 case 100: caps = 1 << MC_CMD_PHY_CAP_100HDX_LBN; break;
647 case 1000: caps = 1 << MC_CMD_PHY_CAP_1000HDX_LBN; break;
648 default: return -EINVAL;
652 caps |= ethtool_fec_caps_to_mcdi(efx->fec_config);
654 rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
655 efx->loopback_mode, 0);
659 if (cmd->base.autoneg) {
660 efx_link_set_advertising(efx, cmd->link_modes.advertising);
661 phy_cfg->forced_cap = 0;
663 efx_link_clear_advertising(efx);
664 phy_cfg->forced_cap = caps;
669 static int efx_mcdi_phy_get_fecparam(struct efx_nic *efx,
670 struct ethtool_fecparam *fec)
672 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_V2_LEN);
673 u32 caps, active, speed; /* MCDI format */
678 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
679 rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
680 outbuf, sizeof(outbuf), &outlen);
683 if (outlen < MC_CMD_GET_LINK_OUT_V2_LEN)
686 /* behaviour for 25G/50G links depends on 25G BASER bit */
687 speed = MCDI_DWORD(outbuf, GET_LINK_OUT_V2_LINK_SPEED);
688 is_25g = speed == 25000 || speed == 50000;
690 caps = MCDI_DWORD(outbuf, GET_LINK_OUT_V2_CAP);
691 fec->fec = mcdi_fec_caps_to_ethtool(caps, is_25g);
692 /* BASER is never supported on 100G */
694 fec->fec &= ~ETHTOOL_FEC_BASER;
696 active = MCDI_DWORD(outbuf, GET_LINK_OUT_V2_FEC_TYPE);
698 case MC_CMD_FEC_NONE:
699 fec->active_fec = ETHTOOL_FEC_OFF;
701 case MC_CMD_FEC_BASER:
702 fec->active_fec = ETHTOOL_FEC_BASER;
705 fec->active_fec = ETHTOOL_FEC_RS;
708 netif_warn(efx, hw, efx->net_dev,
709 "Firmware reports unrecognised FEC_TYPE %u\n",
711 /* We don't know what firmware has picked. AUTO is as good a
712 * "can't happen" value as any other.
714 fec->active_fec = ETHTOOL_FEC_AUTO;
721 static int efx_mcdi_phy_set_fecparam(struct efx_nic *efx,
722 const struct ethtool_fecparam *fec)
724 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
728 /* Work out what efx_mcdi_phy_set_link_ksettings() would produce from
729 * saved advertising bits
731 if (test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, efx->link_advertising))
732 caps = (ethtool_linkset_to_mcdi_cap(efx->link_advertising) |
733 1 << MC_CMD_PHY_CAP_AN_LBN);
735 caps = phy_cfg->forced_cap;
737 caps |= ethtool_fec_caps_to_mcdi(fec->fec);
738 rc = efx_mcdi_set_link(efx, caps, efx_get_mcdi_phy_flags(efx),
739 efx->loopback_mode, 0);
743 /* Record the new FEC setting for subsequent set_link calls */
744 efx->fec_config = fec->fec;
748 static int efx_mcdi_phy_test_alive(struct efx_nic *efx)
750 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_STATE_OUT_LEN);
754 BUILD_BUG_ON(MC_CMD_GET_PHY_STATE_IN_LEN != 0);
756 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_STATE, NULL, 0,
757 outbuf, sizeof(outbuf), &outlen);
761 if (outlen < MC_CMD_GET_PHY_STATE_OUT_LEN)
763 if (MCDI_DWORD(outbuf, GET_PHY_STATE_OUT_STATE) != MC_CMD_PHY_STATE_OK)
769 static const char *const mcdi_sft9001_cable_diag_names[] = {
770 "cable.pairA.length",
771 "cable.pairB.length",
772 "cable.pairC.length",
773 "cable.pairD.length",
774 "cable.pairA.status",
775 "cable.pairB.status",
776 "cable.pairC.status",
777 "cable.pairD.status",
780 static int efx_mcdi_bist(struct efx_nic *efx, unsigned int bist_mode,
783 unsigned int retry, i, count = 0;
786 MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN);
787 MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_SFT9001_LEN);
791 BUILD_BUG_ON(MC_CMD_START_BIST_OUT_LEN != 0);
792 MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_mode);
793 rc = efx_mcdi_rpc(efx, MC_CMD_START_BIST,
794 inbuf, MC_CMD_START_BIST_IN_LEN, NULL, 0, NULL);
798 /* Wait up to 10s for BIST to finish */
799 for (retry = 0; retry < 100; ++retry) {
800 BUILD_BUG_ON(MC_CMD_POLL_BIST_IN_LEN != 0);
801 rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0,
802 outbuf, sizeof(outbuf), &outlen);
806 status = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT);
807 if (status != MC_CMD_POLL_BIST_RUNNING)
817 results[count++] = (status == MC_CMD_POLL_BIST_PASSED) ? 1 : -1;
819 /* SFT9001 specific cable diagnostics output */
820 if (efx->phy_type == PHY_TYPE_SFT9001B &&
821 (bist_mode == MC_CMD_PHY_BIST_CABLE_SHORT ||
822 bist_mode == MC_CMD_PHY_BIST_CABLE_LONG)) {
823 ptr = MCDI_PTR(outbuf, POLL_BIST_OUT_SFT9001_CABLE_LENGTH_A);
824 if (status == MC_CMD_POLL_BIST_PASSED &&
825 outlen >= MC_CMD_POLL_BIST_OUT_SFT9001_LEN) {
826 for (i = 0; i < 8; i++) {
828 EFX_DWORD_FIELD(((efx_dword_t *)ptr)[i],
840 static int efx_mcdi_phy_run_tests(struct efx_nic *efx, int *results,
843 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
847 if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
848 rc = efx_mcdi_bist(efx, MC_CMD_PHY_BIST, results);
855 /* If we support both LONG and SHORT, then run each in response to
856 * break or not. Otherwise, run the one we support */
858 if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN)) {
859 if ((flags & ETH_TEST_FL_OFFLINE) &&
861 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN)))
862 mode = MC_CMD_PHY_BIST_CABLE_LONG;
864 mode = MC_CMD_PHY_BIST_CABLE_SHORT;
865 } else if (phy_cfg->flags &
866 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))
867 mode = MC_CMD_PHY_BIST_CABLE_LONG;
870 rc = efx_mcdi_bist(efx, mode, results);
879 static const char *efx_mcdi_phy_test_name(struct efx_nic *efx,
882 struct efx_mcdi_phy_data *phy_cfg = efx->phy_data;
884 if (phy_cfg->flags & (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_LBN)) {
890 if (phy_cfg->flags & ((1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_SHORT_LBN) |
891 (1 << MC_CMD_GET_PHY_CFG_OUT_BIST_CABLE_LONG_LBN))) {
896 if (efx->phy_type == PHY_TYPE_SFT9001B) {
897 if (index < ARRAY_SIZE(mcdi_sft9001_cable_diag_names))
898 return mcdi_sft9001_cable_diag_names[index];
899 index -= ARRAY_SIZE(mcdi_sft9001_cable_diag_names);
906 #define SFP_PAGE_SIZE 128
907 #define SFF_DIAG_TYPE_OFFSET 92
908 #define SFF_DIAG_ADDR_CHANGE BIT(2)
909 #define SFF_8079_NUM_PAGES 2
910 #define SFF_8472_NUM_PAGES 4
911 #define SFF_8436_NUM_PAGES 5
912 #define SFF_DMT_LEVEL_OFFSET 94
914 /** efx_mcdi_phy_get_module_eeprom_page() - Get a single page of module eeprom
916 * @page: EEPROM page number
917 * @data: Destination data pointer
918 * @offset: Offset in page to copy from in to data
919 * @space: Space available in data
922 * >=0 - amount of data copied
925 static int efx_mcdi_phy_get_module_eeprom_page(struct efx_nic *efx,
927 u8 *data, ssize_t offset,
930 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX);
931 MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN);
933 unsigned int payload_len;
934 unsigned int to_copy;
937 if (offset > SFP_PAGE_SIZE)
940 to_copy = min(space, SFP_PAGE_SIZE - offset);
942 MCDI_SET_DWORD(inbuf, GET_PHY_MEDIA_INFO_IN_PAGE, page);
943 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_GET_PHY_MEDIA_INFO,
944 inbuf, sizeof(inbuf),
945 outbuf, sizeof(outbuf),
951 if (outlen < (MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST +
955 payload_len = MCDI_DWORD(outbuf, GET_PHY_MEDIA_INFO_OUT_DATALEN);
956 if (payload_len != SFP_PAGE_SIZE)
959 memcpy(data, MCDI_PTR(outbuf, GET_PHY_MEDIA_INFO_OUT_DATA) + offset,
965 static int efx_mcdi_phy_get_module_eeprom_byte(struct efx_nic *efx,
972 rc = efx_mcdi_phy_get_module_eeprom_page(efx, page, &data, byte, 1);
979 static int efx_mcdi_phy_diag_type(struct efx_nic *efx)
981 /* Page zero of the EEPROM includes the diagnostic type at byte 92. */
982 return efx_mcdi_phy_get_module_eeprom_byte(efx, 0,
983 SFF_DIAG_TYPE_OFFSET);
986 static int efx_mcdi_phy_sff_8472_level(struct efx_nic *efx)
988 /* Page zero of the EEPROM includes the DMT level at byte 94. */
989 return efx_mcdi_phy_get_module_eeprom_byte(efx, 0,
990 SFF_DMT_LEVEL_OFFSET);
993 static u32 efx_mcdi_phy_module_type(struct efx_nic *efx)
995 struct efx_mcdi_phy_data *phy_data = efx->phy_data;
997 if (phy_data->media != MC_CMD_MEDIA_QSFP_PLUS)
998 return phy_data->media;
1000 /* A QSFP+ NIC may actually have an SFP+ module attached.
1001 * The ID is page 0, byte 0.
1003 switch (efx_mcdi_phy_get_module_eeprom_byte(efx, 0, 0)) {
1005 return MC_CMD_MEDIA_SFP_PLUS;
1008 return MC_CMD_MEDIA_QSFP_PLUS;
1014 static int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx,
1015 struct ethtool_eeprom *ee, u8 *data)
1018 ssize_t space_remaining = ee->len;
1019 unsigned int page_off;
1020 bool ignore_missing;
1024 switch (efx_mcdi_phy_module_type(efx)) {
1025 case MC_CMD_MEDIA_SFP_PLUS:
1026 num_pages = efx_mcdi_phy_sff_8472_level(efx) > 0 ?
1027 SFF_8472_NUM_PAGES : SFF_8079_NUM_PAGES;
1029 ignore_missing = false;
1031 case MC_CMD_MEDIA_QSFP_PLUS:
1032 num_pages = SFF_8436_NUM_PAGES;
1033 page = -1; /* We obtain the lower page by asking for -1. */
1034 ignore_missing = true; /* Ignore missing pages after page 0. */
1040 page_off = ee->offset % SFP_PAGE_SIZE;
1041 page += ee->offset / SFP_PAGE_SIZE;
1043 while (space_remaining && (page < num_pages)) {
1044 rc = efx_mcdi_phy_get_module_eeprom_page(efx, page,
1049 space_remaining -= rc;
1053 } else if (rc == 0) {
1054 space_remaining = 0;
1055 } else if (ignore_missing && (page > 0)) {
1056 int intended_size = SFP_PAGE_SIZE - page_off;
1058 space_remaining -= intended_size;
1059 if (space_remaining < 0) {
1060 space_remaining = 0;
1062 memset(data, 0, intended_size);
1063 data += intended_size;
1076 static int efx_mcdi_phy_get_module_info(struct efx_nic *efx,
1077 struct ethtool_modinfo *modinfo)
1082 switch (efx_mcdi_phy_module_type(efx)) {
1083 case MC_CMD_MEDIA_SFP_PLUS:
1084 sff_8472_level = efx_mcdi_phy_sff_8472_level(efx);
1086 /* If we can't read the diagnostics level we have none. */
1087 if (sff_8472_level < 0)
1090 /* Check if this module requires the (unsupported) address
1093 diag_type = efx_mcdi_phy_diag_type(efx);
1095 if ((sff_8472_level == 0) ||
1096 (diag_type & SFF_DIAG_ADDR_CHANGE)) {
1097 modinfo->type = ETH_MODULE_SFF_8079;
1098 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
1100 modinfo->type = ETH_MODULE_SFF_8472;
1101 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1105 case MC_CMD_MEDIA_QSFP_PLUS:
1106 modinfo->type = ETH_MODULE_SFF_8436;
1107 modinfo->eeprom_len = ETH_MODULE_SFF_8436_LEN;
1117 static const struct efx_phy_operations efx_mcdi_phy_ops = {
1118 .probe = efx_mcdi_phy_probe,
1119 .init = efx_port_dummy_op_int,
1120 .reconfigure = efx_mcdi_port_reconfigure,
1121 .poll = efx_mcdi_phy_poll,
1122 .fini = efx_port_dummy_op_void,
1123 .remove = efx_mcdi_phy_remove,
1124 .get_link_ksettings = efx_mcdi_phy_get_link_ksettings,
1125 .set_link_ksettings = efx_mcdi_phy_set_link_ksettings,
1126 .get_fecparam = efx_mcdi_phy_get_fecparam,
1127 .set_fecparam = efx_mcdi_phy_set_fecparam,
1128 .test_alive = efx_mcdi_phy_test_alive,
1129 .run_tests = efx_mcdi_phy_run_tests,
1130 .test_name = efx_mcdi_phy_test_name,
1131 .get_module_eeprom = efx_mcdi_phy_get_module_eeprom,
1132 .get_module_info = efx_mcdi_phy_get_module_info,
1135 u32 efx_mcdi_phy_get_caps(struct efx_nic *efx)
1137 struct efx_mcdi_phy_data *phy_data = efx->phy_data;
1139 return phy_data->supported_cap;
1142 static unsigned int efx_mcdi_event_link_speed[] = {
1143 [MCDI_EVENT_LINKCHANGE_SPEED_100M] = 100,
1144 [MCDI_EVENT_LINKCHANGE_SPEED_1G] = 1000,
1145 [MCDI_EVENT_LINKCHANGE_SPEED_10G] = 10000,
1146 [MCDI_EVENT_LINKCHANGE_SPEED_40G] = 40000,
1147 [MCDI_EVENT_LINKCHANGE_SPEED_25G] = 25000,
1148 [MCDI_EVENT_LINKCHANGE_SPEED_50G] = 50000,
1149 [MCDI_EVENT_LINKCHANGE_SPEED_100G] = 100000,
1152 void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev)
1154 u32 flags, fcntl, speed, lpa;
1156 speed = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_SPEED);
1157 EFX_WARN_ON_PARANOID(speed >= ARRAY_SIZE(efx_mcdi_event_link_speed));
1158 speed = efx_mcdi_event_link_speed[speed];
1160 flags = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LINK_FLAGS);
1161 fcntl = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_FCNTL);
1162 lpa = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LP_CAP);
1164 /* efx->link_state is only modified by efx_mcdi_phy_get_link(),
1165 * which is only run after flushing the event queues. Therefore, it
1166 * is safe to modify the link state outside of the mac_lock here.
1168 efx_mcdi_phy_decode_link(efx, &efx->link_state, speed, flags, fcntl);
1170 efx_mcdi_phy_check_fcntl(efx, lpa);
1172 efx_link_status_changed(efx);
1175 int efx_mcdi_set_mac(struct efx_nic *efx)
1178 MCDI_DECLARE_BUF(cmdbytes, MC_CMD_SET_MAC_IN_LEN);
1180 BUILD_BUG_ON(MC_CMD_SET_MAC_OUT_LEN != 0);
1182 /* This has no effect on EF10 */
1183 ether_addr_copy(MCDI_PTR(cmdbytes, SET_MAC_IN_ADDR),
1184 efx->net_dev->dev_addr);
1186 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_MTU,
1187 EFX_MAX_FRAME_LEN(efx->net_dev->mtu));
1188 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_DRAIN, 0);
1190 /* Set simple MAC filter for Siena */
1191 MCDI_POPULATE_DWORD_1(cmdbytes, SET_MAC_IN_REJECT,
1192 SET_MAC_IN_REJECT_UNCST, efx->unicast_filter);
1194 MCDI_POPULATE_DWORD_1(cmdbytes, SET_MAC_IN_FLAGS,
1195 SET_MAC_IN_FLAG_INCLUDE_FCS,
1196 !!(efx->net_dev->features & NETIF_F_RXFCS));
1198 switch (efx->wanted_fc) {
1199 case EFX_FC_RX | EFX_FC_TX:
1200 fcntl = MC_CMD_FCNTL_BIDIR;
1203 fcntl = MC_CMD_FCNTL_RESPOND;
1206 fcntl = MC_CMD_FCNTL_OFF;
1209 if (efx->wanted_fc & EFX_FC_AUTO)
1210 fcntl = MC_CMD_FCNTL_AUTO;
1211 if (efx->fc_disable)
1212 fcntl = MC_CMD_FCNTL_OFF;
1214 MCDI_SET_DWORD(cmdbytes, SET_MAC_IN_FCNTL, fcntl);
1216 return efx_mcdi_rpc(efx, MC_CMD_SET_MAC, cmdbytes, sizeof(cmdbytes),
1220 bool efx_mcdi_mac_check_fault(struct efx_nic *efx)
1222 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_LINK_OUT_LEN);
1226 BUILD_BUG_ON(MC_CMD_GET_LINK_IN_LEN != 0);
1228 rc = efx_mcdi_rpc(efx, MC_CMD_GET_LINK, NULL, 0,
1229 outbuf, sizeof(outbuf), &outlength);
1233 return MCDI_DWORD(outbuf, GET_LINK_OUT_MAC_FAULT) != 0;
1236 enum efx_stats_action {
1242 static int efx_mcdi_mac_stats(struct efx_nic *efx,
1243 enum efx_stats_action action, int clear)
1245 MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN);
1247 int change = action == EFX_STATS_PULL ? 0 : 1;
1248 int enable = action == EFX_STATS_ENABLE ? 1 : 0;
1249 int period = action == EFX_STATS_ENABLE ? 1000 : 0;
1250 dma_addr_t dma_addr = efx->stats_buffer.dma_addr;
1251 u32 dma_len = action != EFX_STATS_DISABLE ?
1252 efx->num_mac_stats * sizeof(u64) : 0;
1254 BUILD_BUG_ON(MC_CMD_MAC_STATS_OUT_DMA_LEN != 0);
1256 MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, dma_addr);
1257 MCDI_POPULATE_DWORD_7(inbuf, MAC_STATS_IN_CMD,
1258 MAC_STATS_IN_DMA, !!enable,
1259 MAC_STATS_IN_CLEAR, clear,
1260 MAC_STATS_IN_PERIODIC_CHANGE, change,
1261 MAC_STATS_IN_PERIODIC_ENABLE, enable,
1262 MAC_STATS_IN_PERIODIC_CLEAR, 0,
1263 MAC_STATS_IN_PERIODIC_NOEVENT, 1,
1264 MAC_STATS_IN_PERIOD_MS, period);
1265 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len);
1267 if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) {
1268 struct efx_ef10_nic_data *nic_data = efx->nic_data;
1270 MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, nic_data->vport_id);
1273 rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf),
1275 /* Expect ENOENT if DMA queues have not been set up */
1276 if (rc && (rc != -ENOENT || atomic_read(&efx->active_queues)))
1277 efx_mcdi_display_error(efx, MC_CMD_MAC_STATS, sizeof(inbuf),
1282 void efx_mcdi_mac_start_stats(struct efx_nic *efx)
1284 __le64 *dma_stats = efx->stats_buffer.addr;
1286 dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
1288 efx_mcdi_mac_stats(efx, EFX_STATS_ENABLE, 0);
1291 void efx_mcdi_mac_stop_stats(struct efx_nic *efx)
1293 efx_mcdi_mac_stats(efx, EFX_STATS_DISABLE, 0);
1296 #define EFX_MAC_STATS_WAIT_US 100
1297 #define EFX_MAC_STATS_WAIT_ATTEMPTS 10
1299 void efx_mcdi_mac_pull_stats(struct efx_nic *efx)
1301 __le64 *dma_stats = efx->stats_buffer.addr;
1302 int attempts = EFX_MAC_STATS_WAIT_ATTEMPTS;
1304 dma_stats[efx->num_mac_stats - 1] = EFX_MC_STATS_GENERATION_INVALID;
1305 efx_mcdi_mac_stats(efx, EFX_STATS_PULL, 0);
1307 while (dma_stats[efx->num_mac_stats - 1] ==
1308 EFX_MC_STATS_GENERATION_INVALID &&
1310 udelay(EFX_MAC_STATS_WAIT_US);
1313 int efx_mcdi_port_probe(struct efx_nic *efx)
1317 /* Hook in PHY operations table */
1318 efx->phy_op = &efx_mcdi_phy_ops;
1320 /* Set up MDIO structure for PHY */
1321 efx->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
1322 efx->mdio.mdio_read = efx_mcdi_mdio_read;
1323 efx->mdio.mdio_write = efx_mcdi_mdio_write;
1325 /* Fill out MDIO structure, loopback modes, and initial link state */
1326 rc = efx->phy_op->probe(efx);
1330 /* Allocate buffer for stats */
1331 rc = efx_nic_alloc_buffer(efx, &efx->stats_buffer,
1332 efx->num_mac_stats * sizeof(u64), GFP_KERNEL);
1335 netif_dbg(efx, probe, efx->net_dev,
1336 "stats buffer at %llx (virt %p phys %llx)\n",
1337 (u64)efx->stats_buffer.dma_addr,
1338 efx->stats_buffer.addr,
1339 (u64)virt_to_phys(efx->stats_buffer.addr));
1341 efx_mcdi_mac_stats(efx, EFX_STATS_DISABLE, 1);
1346 void efx_mcdi_port_remove(struct efx_nic *efx)
1348 efx->phy_op->remove(efx);
1349 efx_nic_free_buffer(efx, &efx->stats_buffer);
1352 /* Get physical port number (EF10 only; on Siena it is same as PF number) */
1353 int efx_mcdi_port_get_number(struct efx_nic *efx)
1355 MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PORT_ASSIGNMENT_OUT_LEN);
1358 rc = efx_mcdi_rpc(efx, MC_CMD_GET_PORT_ASSIGNMENT, NULL, 0,
1359 outbuf, sizeof(outbuf), NULL);
1363 return MCDI_DWORD(outbuf, GET_PORT_ASSIGNMENT_OUT_PORT);