1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation, incorporated herein by reference.
11 #include <linux/delay.h>
12 #include "net_driver.h"
15 #include "falcon_hwdefs.h"
16 #include "falcon_io.h"
22 #include "workarounds.h"
24 /**************************************************************************
28 *************************************************************************/
29 static int falcon_reset_xmac(struct efx_nic *efx)
34 EFX_POPULATE_OWORD_1(reg, XM_CORE_RST, 1);
35 falcon_write(efx, ®, XM_GLB_CFG_REG);
37 for (count = 0; count < 10000; count++) { /* wait upto 100ms */
38 falcon_read(efx, ®, XM_GLB_CFG_REG);
39 if (EFX_OWORD_FIELD(reg, XM_CORE_RST) == 0)
44 EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
48 /* Configure the XAUI driver that is an output from Falcon */
49 static void falcon_setup_xaui(struct efx_nic *efx)
51 efx_oword_t sdctl, txdrv;
53 /* Move the XAUI into low power, unless there is no PHY, in
54 * which case the XAUI will have to drive a cable. */
55 if (efx->phy_type == PHY_TYPE_NONE)
58 falcon_read(efx, &sdctl, XX_SD_CTL_REG);
59 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT);
60 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVD, XX_SD_CTL_DRV_DEFAULT);
61 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT);
62 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVC, XX_SD_CTL_DRV_DEFAULT);
63 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT);
64 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVB, XX_SD_CTL_DRV_DEFAULT);
65 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT);
66 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVA, XX_SD_CTL_DRV_DEFAULT);
67 falcon_write(efx, &sdctl, XX_SD_CTL_REG);
69 EFX_POPULATE_OWORD_8(txdrv,
70 XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
71 XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
72 XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
73 XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
74 XX_DTXD, XX_TXDRV_DTX_DEFAULT,
75 XX_DTXC, XX_TXDRV_DTX_DEFAULT,
76 XX_DTXB, XX_TXDRV_DTX_DEFAULT,
77 XX_DTXA, XX_TXDRV_DTX_DEFAULT);
78 falcon_write(efx, &txdrv, XX_TXDRV_CTL_REG);
81 static void falcon_hold_xaui_in_rst(struct efx_nic *efx)
86 EFX_SET_OWORD_FIELD(reg, XX_PWRDNA_EN, 1);
87 EFX_SET_OWORD_FIELD(reg, XX_PWRDNB_EN, 1);
88 EFX_SET_OWORD_FIELD(reg, XX_PWRDNC_EN, 1);
89 EFX_SET_OWORD_FIELD(reg, XX_PWRDND_EN, 1);
90 EFX_SET_OWORD_FIELD(reg, XX_RSTPLLAB_EN, 1);
91 EFX_SET_OWORD_FIELD(reg, XX_RSTPLLCD_EN, 1);
92 EFX_SET_OWORD_FIELD(reg, XX_RESETA_EN, 1);
93 EFX_SET_OWORD_FIELD(reg, XX_RESETB_EN, 1);
94 EFX_SET_OWORD_FIELD(reg, XX_RESETC_EN, 1);
95 EFX_SET_OWORD_FIELD(reg, XX_RESETD_EN, 1);
96 EFX_SET_OWORD_FIELD(reg, XX_RSTXGXSRX_EN, 1);
97 EFX_SET_OWORD_FIELD(reg, XX_RSTXGXSTX_EN, 1);
98 falcon_write(efx, ®, XX_PWR_RST_REG);
102 static int _falcon_reset_xaui_a(struct efx_nic *efx)
106 falcon_hold_xaui_in_rst(efx);
107 falcon_read(efx, ®, XX_PWR_RST_REG);
109 /* Follow the RAMBUS XAUI data reset sequencing
110 * Channels A and B first: power down, reset PLL, reset, clear
112 EFX_SET_OWORD_FIELD(reg, XX_PWRDNA_EN, 0);
113 EFX_SET_OWORD_FIELD(reg, XX_PWRDNB_EN, 0);
114 falcon_write(efx, ®, XX_PWR_RST_REG);
117 EFX_SET_OWORD_FIELD(reg, XX_RSTPLLAB_EN, 0);
118 falcon_write(efx, ®, XX_PWR_RST_REG);
121 EFX_SET_OWORD_FIELD(reg, XX_RESETA_EN, 0);
122 EFX_SET_OWORD_FIELD(reg, XX_RESETB_EN, 0);
123 falcon_write(efx, ®, XX_PWR_RST_REG);
126 /* Channels C and D: power down, reset PLL, reset, clear */
127 EFX_SET_OWORD_FIELD(reg, XX_PWRDNC_EN, 0);
128 EFX_SET_OWORD_FIELD(reg, XX_PWRDND_EN, 0);
129 falcon_write(efx, ®, XX_PWR_RST_REG);
132 EFX_SET_OWORD_FIELD(reg, XX_RSTPLLCD_EN, 0);
133 falcon_write(efx, ®, XX_PWR_RST_REG);
136 EFX_SET_OWORD_FIELD(reg, XX_RESETC_EN, 0);
137 EFX_SET_OWORD_FIELD(reg, XX_RESETD_EN, 0);
138 falcon_write(efx, ®, XX_PWR_RST_REG);
142 falcon_setup_xaui(efx);
145 /* Take XGXS out of reset */
147 falcon_write(efx, ®, XX_PWR_RST_REG);
153 static int _falcon_reset_xaui_b(struct efx_nic *efx)
158 EFX_POPULATE_DWORD_1(reg, XX_RST_XX_EN, 1);
159 falcon_write(efx, ®, XX_PWR_RST_REG);
161 /* Give some time for the link to establish */
162 for (count = 0; count < 1000; count++) { /* wait upto 10ms */
163 falcon_read(efx, ®, XX_PWR_RST_REG);
164 if (EFX_OWORD_FIELD(reg, XX_RST_XX_EN) == 0) {
165 falcon_setup_xaui(efx);
170 EFX_ERR(efx, "timed out waiting for XAUI/XGXS reset\n");
174 int falcon_reset_xaui(struct efx_nic *efx)
178 if (EFX_WORKAROUND_9388(efx)) {
179 falcon_hold_xaui_in_rst(efx);
180 efx->phy_op->reset_xaui(efx);
181 rc = _falcon_reset_xaui_a(efx);
183 rc = _falcon_reset_xaui_b(efx);
188 static bool falcon_xgmii_status(struct efx_nic *efx)
192 if (falcon_rev(efx) < FALCON_REV_B0)
195 /* The ISR latches, so clear it and re-read */
196 falcon_read(efx, ®, XM_MGT_INT_REG_B0);
197 falcon_read(efx, ®, XM_MGT_INT_REG_B0);
199 if (EFX_OWORD_FIELD(reg, XM_LCLFLT) ||
200 EFX_OWORD_FIELD(reg, XM_RMTFLT)) {
201 EFX_INFO(efx, "MGT_INT: "EFX_DWORD_FMT"\n", EFX_DWORD_VAL(reg));
208 static void falcon_mask_status_intr(struct efx_nic *efx, bool enable)
212 if ((falcon_rev(efx) < FALCON_REV_B0) || LOOPBACK_INTERNAL(efx))
217 falcon_read(efx, ®, XM_MGT_INT_REG_B0);
219 EFX_POPULATE_OWORD_2(reg,
220 XM_MSK_RMTFLT, !enable,
221 XM_MSK_LCLFLT, !enable);
222 falcon_write(efx, ®, XM_MGT_INT_MSK_REG_B0);
225 int falcon_init_xmac(struct efx_nic *efx)
229 /* Initialize the PHY first so the clock is around */
230 rc = efx->phy_op->init(efx);
234 rc = falcon_reset_xaui(efx);
238 /* Wait again. Give the PHY and MAC time to come back */
239 schedule_timeout_uninterruptible(HZ / 10);
241 rc = falcon_reset_xmac(efx);
245 falcon_mask_status_intr(efx, true);
249 efx->phy_op->fini(efx);
254 bool falcon_xaui_link_ok(struct efx_nic *efx)
257 bool align_done, link_ok = false;
260 if (LOOPBACK_INTERNAL(efx))
263 /* Read link status */
264 falcon_read(efx, ®, XX_CORE_STAT_REG);
266 align_done = EFX_OWORD_FIELD(reg, XX_ALIGN_DONE);
267 sync_status = EFX_OWORD_FIELD(reg, XX_SYNC_STAT);
268 if (align_done && (sync_status == XX_SYNC_STAT_DECODE_SYNCED))
271 /* Clear link status ready for next read */
272 EFX_SET_OWORD_FIELD(reg, XX_COMMA_DET, XX_COMMA_DET_RESET);
273 EFX_SET_OWORD_FIELD(reg, XX_CHARERR, XX_CHARERR_RESET);
274 EFX_SET_OWORD_FIELD(reg, XX_DISPERR, XX_DISPERR_RESET);
275 falcon_write(efx, ®, XX_CORE_STAT_REG);
277 /* If the link is up, then check the phy side of the xaui link
278 * (error conditions from the wire side propoagate back through
279 * the phy to the xaui side). */
280 if (efx->link_up && link_ok) {
281 if (efx->phy_op->mmds & (1 << MDIO_MMD_PHYXS))
282 link_ok = mdio_clause45_phyxgxs_lane_sync(efx);
285 /* If the PHY and XAUI links are up, then check the mac's xgmii
287 if (efx->link_up && link_ok)
288 link_ok = falcon_xgmii_status(efx);
293 static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
295 unsigned int max_frame_len;
297 bool rx_fc = !!(efx->flow_control & EFX_FC_RX);
299 /* Configure MAC - cut-thru mode is hard wired on */
300 EFX_POPULATE_DWORD_3(reg,
304 falcon_write(efx, ®, XM_GLB_CFG_REG);
307 EFX_POPULATE_DWORD_6(reg,
314 falcon_write(efx, ®, XM_TX_CFG_REG);
317 EFX_POPULATE_DWORD_5(reg,
320 XM_ACPT_ALL_MCAST, 1,
321 XM_ACPT_ALL_UCAST, efx->promiscuous,
323 falcon_write(efx, ®, XM_RX_CFG_REG);
325 /* Set frame length */
326 max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
327 EFX_POPULATE_DWORD_1(reg, XM_MAX_RX_FRM_SIZE, max_frame_len);
328 falcon_write(efx, ®, XM_RX_PARAM_REG);
329 EFX_POPULATE_DWORD_2(reg,
330 XM_MAX_TX_FRM_SIZE, max_frame_len,
331 XM_TX_JUMBO_MODE, 1);
332 falcon_write(efx, ®, XM_TX_PARAM_REG);
334 EFX_POPULATE_DWORD_2(reg,
335 XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
336 XM_DIS_FCNTL, !rx_fc);
337 falcon_write(efx, ®, XM_FC_REG);
339 /* Set MAC address */
340 EFX_POPULATE_DWORD_4(reg,
341 XM_ADR_0, efx->net_dev->dev_addr[0],
342 XM_ADR_1, efx->net_dev->dev_addr[1],
343 XM_ADR_2, efx->net_dev->dev_addr[2],
344 XM_ADR_3, efx->net_dev->dev_addr[3]);
345 falcon_write(efx, ®, XM_ADR_LO_REG);
346 EFX_POPULATE_DWORD_2(reg,
347 XM_ADR_4, efx->net_dev->dev_addr[4],
348 XM_ADR_5, efx->net_dev->dev_addr[5]);
349 falcon_write(efx, ®, XM_ADR_HI_REG);
352 static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
355 bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS);
356 bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI);
357 bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII);
359 /* XGXS block is flaky and will need to be reset if moving
360 * into our out of XGMII, XGXS or XAUI loopbacks. */
361 if (EFX_WORKAROUND_5147(efx)) {
362 bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
365 falcon_read(efx, ®, XX_CORE_STAT_REG);
366 old_xgxs_loopback = EFX_OWORD_FIELD(reg, XX_XGXS_LB_EN);
367 old_xgmii_loopback = EFX_OWORD_FIELD(reg, XX_XGMII_LB_EN);
369 falcon_read(efx, ®, XX_SD_CTL_REG);
370 old_xaui_loopback = EFX_OWORD_FIELD(reg, XX_LPBKA);
372 /* The PHY driver may have turned XAUI off */
373 reset_xgxs = ((xgxs_loopback != old_xgxs_loopback) ||
374 (xaui_loopback != old_xaui_loopback) ||
375 (xgmii_loopback != old_xgmii_loopback));
378 falcon_reset_xaui(efx);
381 falcon_read(efx, ®, XX_CORE_STAT_REG);
382 EFX_SET_OWORD_FIELD(reg, XX_FORCE_SIG,
383 (xgxs_loopback || xaui_loopback) ?
384 XX_FORCE_SIG_DECODE_FORCED : 0);
385 EFX_SET_OWORD_FIELD(reg, XX_XGXS_LB_EN, xgxs_loopback);
386 EFX_SET_OWORD_FIELD(reg, XX_XGMII_LB_EN, xgmii_loopback);
387 falcon_write(efx, ®, XX_CORE_STAT_REG);
389 falcon_read(efx, ®, XX_SD_CTL_REG);
390 EFX_SET_OWORD_FIELD(reg, XX_LPBKD, xaui_loopback);
391 EFX_SET_OWORD_FIELD(reg, XX_LPBKC, xaui_loopback);
392 EFX_SET_OWORD_FIELD(reg, XX_LPBKB, xaui_loopback);
393 EFX_SET_OWORD_FIELD(reg, XX_LPBKA, xaui_loopback);
394 falcon_write(efx, ®, XX_SD_CTL_REG);
398 /* Try and bring the Falcon side of the Falcon-Phy XAUI link fails
399 * to come back up. Bash it until it comes back up */
400 static bool falcon_check_xaui_link_up(struct efx_nic *efx)
402 int max_tries, tries;
403 tries = EFX_WORKAROUND_5147(efx) ? 5 : 1;
406 if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
407 (efx->phy_type == PHY_TYPE_NONE) ||
408 efx_phy_mode_disabled(efx->phy_mode))
412 if (falcon_xaui_link_ok(efx))
415 EFX_LOG(efx, "%s Clobbering XAUI (%d tries left).\n",
417 falcon_reset_xaui(efx);
422 EFX_LOG(efx, "Failed to bring XAUI link back up in %d tries!\n",
427 void falcon_reconfigure_xmac(struct efx_nic *efx)
431 falcon_mask_status_intr(efx, false);
433 falcon_deconfigure_mac_wrapper(efx);
435 /* Reconfigure the PHY, disabling transmit in mac level loopback. */
436 if (LOOPBACK_INTERNAL(efx))
437 efx->phy_mode |= PHY_MODE_TX_DISABLED;
439 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
440 efx->phy_op->reconfigure(efx);
442 falcon_reconfigure_xgxs_core(efx);
443 falcon_reconfigure_xmac_core(efx);
445 falcon_reconfigure_mac_wrapper(efx);
447 /* Ensure XAUI link is up */
448 xaui_link_ok = falcon_check_xaui_link_up(efx);
450 if (xaui_link_ok && efx->link_up)
451 falcon_mask_status_intr(efx, true);
454 void falcon_fini_xmac(struct efx_nic *efx)
456 /* Isolate the MAC - PHY */
457 falcon_deconfigure_mac_wrapper(efx);
459 /* Potentially power down the PHY */
460 efx->phy_op->fini(efx);
463 void falcon_update_stats_xmac(struct efx_nic *efx)
465 struct efx_mac_stats *mac_stats = &efx->mac_stats;
468 rc = falcon_dma_stats(efx, XgDmaDone_offset);
472 /* Update MAC stats from DMAed values */
473 FALCON_STAT(efx, XgRxOctets, rx_bytes);
474 FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
475 FALCON_STAT(efx, XgRxPkts, rx_packets);
476 FALCON_STAT(efx, XgRxPktsOK, rx_good);
477 FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
478 FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
479 FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
480 FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
481 FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
482 FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
483 FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
484 FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
485 FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
486 FALCON_STAT(efx, XgRxAlignError, rx_align_error);
487 FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
488 FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
489 FALCON_STAT(efx, XgRxControlPkts, rx_control);
490 FALCON_STAT(efx, XgRxPausePkts, rx_pause);
491 FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
492 FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
493 FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
494 FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
495 FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
496 FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
497 FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
498 FALCON_STAT(efx, XgRxLengthError, rx_length_error);
499 FALCON_STAT(efx, XgTxPkts, tx_packets);
500 FALCON_STAT(efx, XgTxOctets, tx_bytes);
501 FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
502 FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
503 FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
504 FALCON_STAT(efx, XgTxControlPkts, tx_control);
505 FALCON_STAT(efx, XgTxPausePkts, tx_pause);
506 FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
507 FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
508 FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
509 FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
510 FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
511 FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
512 FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
513 FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
514 FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
515 FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
516 FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
517 FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
519 /* Update derived statistics */
520 mac_stats->tx_good_bytes =
521 (mac_stats->tx_bytes - mac_stats->tx_bad_bytes -
522 mac_stats->tx_control * 64);
523 mac_stats->rx_bad_bytes =
524 (mac_stats->rx_bytes - mac_stats->rx_good_bytes -
525 mac_stats->rx_control * 64);
528 int falcon_check_xmac(struct efx_nic *efx)
533 if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
534 efx_phy_mode_disabled(efx->phy_mode))
537 falcon_mask_status_intr(efx, false);
538 xaui_link_ok = falcon_xaui_link_ok(efx);
540 if (EFX_WORKAROUND_5147(efx) && !xaui_link_ok)
541 falcon_reset_xaui(efx);
543 /* Call the PHY check_hw routine */
544 rc = efx->phy_op->check_hw(efx);
546 /* Unmask interrupt if everything was (and still is) ok */
547 if (xaui_link_ok && efx->link_up)
548 falcon_mask_status_intr(efx, true);
553 /* Simulate a PHY event */
554 void falcon_xmac_sim_phy_event(struct efx_nic *efx)
556 efx_qword_t phy_event;
558 EFX_POPULATE_QWORD_2(phy_event,
559 EV_CODE, GLOBAL_EV_DECODE,
561 falcon_generate_event(&efx->channel[0], &phy_event);
564 int falcon_xmac_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
566 mdio_clause45_get_settings(efx, ecmd);
567 ecmd->transceiver = XCVR_INTERNAL;
568 ecmd->phy_address = efx->mii.phy_id;
569 ecmd->autoneg = AUTONEG_DISABLE;
570 ecmd->duplex = DUPLEX_FULL;
574 int falcon_xmac_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
576 if (ecmd->transceiver != XCVR_INTERNAL)
578 if (ecmd->autoneg != AUTONEG_DISABLE)
580 if (ecmd->duplex != DUPLEX_FULL)
583 return mdio_clause45_set_settings(efx, ecmd);
587 int falcon_xmac_set_pause(struct efx_nic *efx, enum efx_fc_type flow_control)
591 if (flow_control & EFX_FC_AUTO) {
592 EFX_LOG(efx, "10G does not support flow control "
593 "autonegotiation\n");
597 if ((flow_control & EFX_FC_TX) && !(flow_control & EFX_FC_RX))
600 /* TX flow control may automatically turn itself off if the
601 * link partner (intermittently) stops responding to pause
602 * frames. There isn't any indication that this has happened,
603 * so the best we do is leave it up to the user to spot this
604 * and fix it be cycling transmit flow control on this end. */
605 reset = ((flow_control & EFX_FC_TX) &&
606 !(efx->flow_control & EFX_FC_TX));
607 if (EFX_WORKAROUND_11482(efx) && reset) {
608 if (falcon_rev(efx) >= FALCON_REV_B0) {
609 /* Recover by resetting the EM block */
611 falcon_drain_tx_fifo(efx);
613 /* Schedule a reset to recover */
614 efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
618 efx->flow_control = flow_control;