blob: 4a54d0933e725e533441f0bd18be9cd28efc0ddd [file] [log] [blame]
Ben Hutchings8ceee662008-04-27 12:55:59 +01001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2005-2006 Fen Systems Ltd.
4 * Copyright 2006-2008 Solarflare Communications Inc.
5 *
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.
9 */
10
11#include <linux/delay.h>
12#include "net_driver.h"
13#include "efx.h"
14#include "falcon.h"
15#include "falcon_hwdefs.h"
16#include "falcon_io.h"
17#include "mac.h"
Ben Hutchings8ceee662008-04-27 12:55:59 +010018#include "mdio_10g.h"
19#include "phy.h"
20#include "boards.h"
21#include "workarounds.h"
22
23/**************************************************************************
24 *
Ben Hutchings8ceee662008-04-27 12:55:59 +010025 * MAC operations
26 *
27 *************************************************************************/
28static int falcon_reset_xmac(struct efx_nic *efx)
29{
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010030 efx_oword_t reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +010031 int count;
32
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010033 EFX_POPULATE_OWORD_1(reg, XM_CORE_RST, 1);
34 falcon_write(efx, &reg, XM_GLB_CFG_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +010035
36 for (count = 0; count < 10000; count++) { /* wait upto 100ms */
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010037 falcon_read(efx, &reg, XM_GLB_CFG_REG);
38 if (EFX_OWORD_FIELD(reg, XM_CORE_RST) == 0)
Ben Hutchings8ceee662008-04-27 12:55:59 +010039 return 0;
40 udelay(10);
41 }
42
Ben Hutchings8ceee662008-04-27 12:55:59 +010043 EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
44 return -ETIMEDOUT;
45}
46
47/* Configure the XAUI driver that is an output from Falcon */
48static void falcon_setup_xaui(struct efx_nic *efx)
49{
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010050 efx_oword_t sdctl, txdrv;
Ben Hutchings8ceee662008-04-27 12:55:59 +010051
52 /* Move the XAUI into low power, unless there is no PHY, in
53 * which case the XAUI will have to drive a cable. */
54 if (efx->phy_type == PHY_TYPE_NONE)
55 return;
56
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010057 falcon_read(efx, &sdctl, XX_SD_CTL_REG);
58 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT);
59 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVD, XX_SD_CTL_DRV_DEFAULT);
60 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT);
61 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVC, XX_SD_CTL_DRV_DEFAULT);
62 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT);
63 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVB, XX_SD_CTL_DRV_DEFAULT);
64 EFX_SET_OWORD_FIELD(sdctl, XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT);
65 EFX_SET_OWORD_FIELD(sdctl, XX_LODRVA, XX_SD_CTL_DRV_DEFAULT);
66 falcon_write(efx, &sdctl, XX_SD_CTL_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +010067
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010068 EFX_POPULATE_OWORD_8(txdrv,
Ben Hutchings8ceee662008-04-27 12:55:59 +010069 XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
70 XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
71 XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
72 XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
73 XX_DTXD, XX_TXDRV_DTX_DEFAULT,
74 XX_DTXC, XX_TXDRV_DTX_DEFAULT,
75 XX_DTXB, XX_TXDRV_DTX_DEFAULT,
76 XX_DTXA, XX_TXDRV_DTX_DEFAULT);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010077 falcon_write(efx, &txdrv, XX_TXDRV_CTL_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +010078}
79
Ben Hutchingsef08af02008-09-01 12:49:20 +010080int falcon_reset_xaui(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +010081{
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010082 efx_oword_t reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +010083 int count;
84
85 EFX_POPULATE_DWORD_1(reg, XX_RST_XX_EN, 1);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010086 falcon_write(efx, &reg, XX_PWR_RST_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +010087
88 /* Give some time for the link to establish */
89 for (count = 0; count < 1000; count++) { /* wait upto 10ms */
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +010090 falcon_read(efx, &reg, XX_PWR_RST_REG);
91 if (EFX_OWORD_FIELD(reg, XX_RST_XX_EN) == 0) {
Ben Hutchings8ceee662008-04-27 12:55:59 +010092 falcon_setup_xaui(efx);
93 return 0;
94 }
95 udelay(10);
96 }
97 EFX_ERR(efx, "timed out waiting for XAUI/XGXS reset\n");
98 return -ETIMEDOUT;
99}
100
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100101static bool falcon_xgmii_status(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100102{
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100103 efx_oword_t reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100104
Ben Hutchings55668612008-05-16 21:16:10 +0100105 if (falcon_rev(efx) < FALCON_REV_B0)
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100106 return true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100107
108 /* The ISR latches, so clear it and re-read */
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100109 falcon_read(efx, &reg, XM_MGT_INT_REG_B0);
110 falcon_read(efx, &reg, XM_MGT_INT_REG_B0);
Ben Hutchingse52edda2008-05-07 12:58:41 +0100111
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100112 if (EFX_OWORD_FIELD(reg, XM_LCLFLT) ||
113 EFX_OWORD_FIELD(reg, XM_RMTFLT)) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100114 EFX_INFO(efx, "MGT_INT: "EFX_DWORD_FMT"\n", EFX_DWORD_VAL(reg));
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100115 return false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100116 }
117
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100118 return true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100119}
120
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100121static void falcon_mask_status_intr(struct efx_nic *efx, bool enable)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100122{
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100123 efx_oword_t reg;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100124
Ben Hutchings55668612008-05-16 21:16:10 +0100125 if ((falcon_rev(efx) < FALCON_REV_B0) || LOOPBACK_INTERNAL(efx))
Ben Hutchings8ceee662008-04-27 12:55:59 +0100126 return;
127
128 /* Flush the ISR */
129 if (enable)
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100130 falcon_read(efx, &reg, XM_MGT_INT_REG_B0);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100131
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100132 EFX_POPULATE_OWORD_2(reg,
Ben Hutchings8ceee662008-04-27 12:55:59 +0100133 XM_MSK_RMTFLT, !enable,
134 XM_MSK_LCLFLT, !enable);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100135 falcon_write(efx, &reg, XM_MGT_INT_MSK_REG_B0);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100136}
137
138int falcon_init_xmac(struct efx_nic *efx)
139{
140 int rc;
141
142 /* Initialize the PHY first so the clock is around */
143 rc = efx->phy_op->init(efx);
144 if (rc)
145 goto fail1;
146
147 rc = falcon_reset_xaui(efx);
148 if (rc)
149 goto fail2;
150
151 /* Wait again. Give the PHY and MAC time to come back */
152 schedule_timeout_uninterruptible(HZ / 10);
153
154 rc = falcon_reset_xmac(efx);
155 if (rc)
156 goto fail2;
157
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100158 falcon_mask_status_intr(efx, true);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100159 return 0;
160
161 fail2:
162 efx->phy_op->fini(efx);
163 fail1:
164 return rc;
165}
166
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100167bool falcon_xaui_link_ok(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100168{
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100169 efx_oword_t reg;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100170 bool align_done, link_ok = false;
171 int sync_status;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100172
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100173 if (LOOPBACK_INTERNAL(efx))
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100174 return true;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100175
Ben Hutchings8ceee662008-04-27 12:55:59 +0100176 /* Read link status */
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100177 falcon_read(efx, &reg, XX_CORE_STAT_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100178
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100179 align_done = EFX_OWORD_FIELD(reg, XX_ALIGN_DONE);
180 sync_status = EFX_OWORD_FIELD(reg, XX_SYNC_STAT);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100181 if (align_done && (sync_status == XX_SYNC_STAT_DECODE_SYNCED))
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100182 link_ok = true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100183
184 /* Clear link status ready for next read */
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100185 EFX_SET_OWORD_FIELD(reg, XX_COMMA_DET, XX_COMMA_DET_RESET);
186 EFX_SET_OWORD_FIELD(reg, XX_CHARERR, XX_CHARERR_RESET);
187 EFX_SET_OWORD_FIELD(reg, XX_DISPERR, XX_DISPERR_RESET);
188 falcon_write(efx, &reg, XX_CORE_STAT_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100189
190 /* If the link is up, then check the phy side of the xaui link
191 * (error conditions from the wire side propoagate back through
192 * the phy to the xaui side). */
193 if (efx->link_up && link_ok) {
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100194 if (efx->phy_op->mmds & (1 << MDIO_MMD_PHYXS))
Ben Hutchings8ceee662008-04-27 12:55:59 +0100195 link_ok = mdio_clause45_phyxgxs_lane_sync(efx);
196 }
197
198 /* If the PHY and XAUI links are up, then check the mac's xgmii
199 * fault state */
200 if (efx->link_up && link_ok)
201 link_ok = falcon_xgmii_status(efx);
202
203 return link_ok;
204}
205
206static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
207{
208 unsigned int max_frame_len;
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100209 efx_oword_t reg;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100210 bool rx_fc = !!(efx->flow_control & EFX_FC_RX);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100211
212 /* Configure MAC - cut-thru mode is hard wired on */
213 EFX_POPULATE_DWORD_3(reg,
214 XM_RX_JUMBO_MODE, 1,
215 XM_TX_STAT_EN, 1,
216 XM_RX_STAT_EN, 1);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100217 falcon_write(efx, &reg, XM_GLB_CFG_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100218
219 /* Configure TX */
220 EFX_POPULATE_DWORD_6(reg,
221 XM_TXEN, 1,
222 XM_TX_PRMBL, 1,
223 XM_AUTO_PAD, 1,
224 XM_TXCRC, 1,
225 XM_FCNTL, 1,
226 XM_IPG, 0x3);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100227 falcon_write(efx, &reg, XM_TX_CFG_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100228
229 /* Configure RX */
230 EFX_POPULATE_DWORD_5(reg,
231 XM_RXEN, 1,
232 XM_AUTO_DEPAD, 0,
233 XM_ACPT_ALL_MCAST, 1,
234 XM_ACPT_ALL_UCAST, efx->promiscuous,
235 XM_PASS_CRC_ERR, 1);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100236 falcon_write(efx, &reg, XM_RX_CFG_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100237
238 /* Set frame length */
239 max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
240 EFX_POPULATE_DWORD_1(reg, XM_MAX_RX_FRM_SIZE, max_frame_len);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100241 falcon_write(efx, &reg, XM_RX_PARAM_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100242 EFX_POPULATE_DWORD_2(reg,
243 XM_MAX_TX_FRM_SIZE, max_frame_len,
244 XM_TX_JUMBO_MODE, 1);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100245 falcon_write(efx, &reg, XM_TX_PARAM_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100246
247 EFX_POPULATE_DWORD_2(reg,
248 XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100249 XM_DIS_FCNTL, !rx_fc);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100250 falcon_write(efx, &reg, XM_FC_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100251
252 /* Set MAC address */
253 EFX_POPULATE_DWORD_4(reg,
254 XM_ADR_0, efx->net_dev->dev_addr[0],
255 XM_ADR_1, efx->net_dev->dev_addr[1],
256 XM_ADR_2, efx->net_dev->dev_addr[2],
257 XM_ADR_3, efx->net_dev->dev_addr[3]);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100258 falcon_write(efx, &reg, XM_ADR_LO_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100259 EFX_POPULATE_DWORD_2(reg,
260 XM_ADR_4, efx->net_dev->dev_addr[4],
261 XM_ADR_5, efx->net_dev->dev_addr[5]);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100262 falcon_write(efx, &reg, XM_ADR_HI_REG);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100263}
264
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100265static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
266{
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100267 efx_oword_t reg;
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100268 bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS);
269 bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI);
270 bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100271
272 /* XGXS block is flaky and will need to be reset if moving
273 * into our out of XGMII, XGXS or XAUI loopbacks. */
274 if (EFX_WORKAROUND_5147(efx)) {
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100275 bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
276 bool reset_xgxs;
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100277
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100278 falcon_read(efx, &reg, XX_CORE_STAT_REG);
279 old_xgxs_loopback = EFX_OWORD_FIELD(reg, XX_XGXS_LB_EN);
280 old_xgmii_loopback = EFX_OWORD_FIELD(reg, XX_XGMII_LB_EN);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100281
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100282 falcon_read(efx, &reg, XX_SD_CTL_REG);
283 old_xaui_loopback = EFX_OWORD_FIELD(reg, XX_LPBKA);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100284
285 /* The PHY driver may have turned XAUI off */
286 reset_xgxs = ((xgxs_loopback != old_xgxs_loopback) ||
287 (xaui_loopback != old_xaui_loopback) ||
288 (xgmii_loopback != old_xgmii_loopback));
Ben Hutchings8c8661e2008-09-01 12:49:02 +0100289
290 if (reset_xgxs)
291 falcon_reset_xaui(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100292 }
293
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100294 falcon_read(efx, &reg, XX_CORE_STAT_REG);
295 EFX_SET_OWORD_FIELD(reg, XX_FORCE_SIG,
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100296 (xgxs_loopback || xaui_loopback) ?
297 XX_FORCE_SIG_DECODE_FORCED : 0);
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100298 EFX_SET_OWORD_FIELD(reg, XX_XGXS_LB_EN, xgxs_loopback);
299 EFX_SET_OWORD_FIELD(reg, XX_XGMII_LB_EN, xgmii_loopback);
300 falcon_write(efx, &reg, XX_CORE_STAT_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100301
Ben Hutchingsc1e5fcc2008-09-01 12:48:41 +0100302 falcon_read(efx, &reg, XX_SD_CTL_REG);
303 EFX_SET_OWORD_FIELD(reg, XX_LPBKD, xaui_loopback);
304 EFX_SET_OWORD_FIELD(reg, XX_LPBKC, xaui_loopback);
305 EFX_SET_OWORD_FIELD(reg, XX_LPBKB, xaui_loopback);
306 EFX_SET_OWORD_FIELD(reg, XX_LPBKA, xaui_loopback);
307 falcon_write(efx, &reg, XX_SD_CTL_REG);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100308}
309
310
Ben Hutchings8ceee662008-04-27 12:55:59 +0100311/* Try and bring the Falcon side of the Falcon-Phy XAUI link fails
312 * to come back up. Bash it until it comes back up */
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100313static bool falcon_check_xaui_link_up(struct efx_nic *efx)
Ben Hutchings8ceee662008-04-27 12:55:59 +0100314{
315 int max_tries, tries;
316 tries = EFX_WORKAROUND_5147(efx) ? 5 : 1;
317 max_tries = tries;
318
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100319 if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100320 (efx->phy_type == PHY_TYPE_NONE) ||
321 efx_phy_mode_disabled(efx->phy_mode))
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100322 return false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100323
324 while (tries) {
325 if (falcon_xaui_link_ok(efx))
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100326 return true;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100327
328 EFX_LOG(efx, "%s Clobbering XAUI (%d tries left).\n",
329 __func__, tries);
Ben Hutchings91ad7572008-05-16 21:14:27 +0100330 falcon_reset_xaui(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100331 udelay(200);
332 tries--;
333 }
334
Ben Hutchingsb0556292008-05-30 22:18:35 +0100335 EFX_LOG(efx, "Failed to bring XAUI link back up in %d tries!\n",
Ben Hutchings8ceee662008-04-27 12:55:59 +0100336 max_tries);
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100337 return false;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100338}
339
340void falcon_reconfigure_xmac(struct efx_nic *efx)
341{
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100342 bool xaui_link_ok;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100343
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100344 falcon_mask_status_intr(efx, false);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100345
346 falcon_deconfigure_mac_wrapper(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100347
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100348 /* Reconfigure the PHY, disabling transmit in mac level loopback. */
349 if (LOOPBACK_INTERNAL(efx))
350 efx->phy_mode |= PHY_MODE_TX_DISABLED;
351 else
352 efx->phy_mode &= ~PHY_MODE_TX_DISABLED;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100353 efx->phy_op->reconfigure(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100354
355 falcon_reconfigure_xgxs_core(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100356 falcon_reconfigure_xmac_core(efx);
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100357
Ben Hutchings8ceee662008-04-27 12:55:59 +0100358 falcon_reconfigure_mac_wrapper(efx);
359
360 /* Ensure XAUI link is up */
361 xaui_link_ok = falcon_check_xaui_link_up(efx);
362
363 if (xaui_link_ok && efx->link_up)
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100364 falcon_mask_status_intr(efx, true);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100365}
366
367void falcon_fini_xmac(struct efx_nic *efx)
368{
369 /* Isolate the MAC - PHY */
370 falcon_deconfigure_mac_wrapper(efx);
371
372 /* Potentially power down the PHY */
373 efx->phy_op->fini(efx);
374}
375
376void falcon_update_stats_xmac(struct efx_nic *efx)
377{
378 struct efx_mac_stats *mac_stats = &efx->mac_stats;
379 int rc;
380
381 rc = falcon_dma_stats(efx, XgDmaDone_offset);
382 if (rc)
383 return;
384
385 /* Update MAC stats from DMAed values */
386 FALCON_STAT(efx, XgRxOctets, rx_bytes);
387 FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
388 FALCON_STAT(efx, XgRxPkts, rx_packets);
389 FALCON_STAT(efx, XgRxPktsOK, rx_good);
390 FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
391 FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
392 FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
393 FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
394 FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
395 FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
396 FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
397 FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
398 FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
399 FALCON_STAT(efx, XgRxAlignError, rx_align_error);
400 FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
401 FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
402 FALCON_STAT(efx, XgRxControlPkts, rx_control);
403 FALCON_STAT(efx, XgRxPausePkts, rx_pause);
404 FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
405 FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
406 FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
407 FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
408 FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
409 FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
410 FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
411 FALCON_STAT(efx, XgRxLengthError, rx_length_error);
412 FALCON_STAT(efx, XgTxPkts, tx_packets);
413 FALCON_STAT(efx, XgTxOctets, tx_bytes);
414 FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
415 FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
416 FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
417 FALCON_STAT(efx, XgTxControlPkts, tx_control);
418 FALCON_STAT(efx, XgTxPausePkts, tx_pause);
419 FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
420 FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
421 FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
422 FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
423 FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
424 FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
425 FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
426 FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
427 FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
428 FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
429 FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
430 FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
431
432 /* Update derived statistics */
433 mac_stats->tx_good_bytes =
Ben Hutchingsc2643612008-09-01 12:46:10 +0100434 (mac_stats->tx_bytes - mac_stats->tx_bad_bytes -
435 mac_stats->tx_control * 64);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100436 mac_stats->rx_bad_bytes =
Ben Hutchingsc2643612008-09-01 12:46:10 +0100437 (mac_stats->rx_bytes - mac_stats->rx_good_bytes -
438 mac_stats->rx_control * 64);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100439}
440
Ben Hutchings8ceee662008-04-27 12:55:59 +0100441int falcon_check_xmac(struct efx_nic *efx)
442{
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100443 bool xaui_link_ok;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100444 int rc;
445
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100446 if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
Ben Hutchingsf8b87c12008-09-01 12:48:17 +0100447 efx_phy_mode_disabled(efx->phy_mode))
Ben Hutchings3273c2e2008-05-07 13:36:19 +0100448 return 0;
449
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100450 falcon_mask_status_intr(efx, false);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100451 xaui_link_ok = falcon_xaui_link_ok(efx);
452
453 if (EFX_WORKAROUND_5147(efx) && !xaui_link_ok)
Ben Hutchings91ad7572008-05-16 21:14:27 +0100454 falcon_reset_xaui(efx);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100455
456 /* Call the PHY check_hw routine */
457 rc = efx->phy_op->check_hw(efx);
458
459 /* Unmask interrupt if everything was (and still is) ok */
460 if (xaui_link_ok && efx->link_up)
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100461 falcon_mask_status_intr(efx, true);
Ben Hutchings8ceee662008-04-27 12:55:59 +0100462
463 return rc;
464}
465
466/* Simulate a PHY event */
467void falcon_xmac_sim_phy_event(struct efx_nic *efx)
468{
469 efx_qword_t phy_event;
470
471 EFX_POPULATE_QWORD_2(phy_event,
472 EV_CODE, GLOBAL_EV_DECODE,
473 XG_PHY_INTR, 1);
474 falcon_generate_event(&efx->channel[0], &phy_event);
475}
476
477int falcon_xmac_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
478{
479 mdio_clause45_get_settings(efx, ecmd);
480 ecmd->transceiver = XCVR_INTERNAL;
481 ecmd->phy_address = efx->mii.phy_id;
482 ecmd->autoneg = AUTONEG_DISABLE;
483 ecmd->duplex = DUPLEX_FULL;
484 return 0;
485}
486
487int falcon_xmac_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
488{
489 if (ecmd->transceiver != XCVR_INTERNAL)
490 return -EINVAL;
491 if (ecmd->autoneg != AUTONEG_DISABLE)
492 return -EINVAL;
493 if (ecmd->duplex != DUPLEX_FULL)
494 return -EINVAL;
495
496 return mdio_clause45_set_settings(efx, ecmd);
497}
498
499
500int falcon_xmac_set_pause(struct efx_nic *efx, enum efx_fc_type flow_control)
501{
Ben Hutchingsdc8cfa52008-09-01 12:46:50 +0100502 bool reset;
Ben Hutchings8ceee662008-04-27 12:55:59 +0100503
504 if (flow_control & EFX_FC_AUTO) {
505 EFX_LOG(efx, "10G does not support flow control "
506 "autonegotiation\n");
507 return -EINVAL;
508 }
509
510 if ((flow_control & EFX_FC_TX) && !(flow_control & EFX_FC_RX))
511 return -EINVAL;
512
513 /* TX flow control may automatically turn itself off if the
514 * link partner (intermittently) stops responding to pause
515 * frames. There isn't any indication that this has happened,
516 * so the best we do is leave it up to the user to spot this
517 * and fix it be cycling transmit flow control on this end. */
518 reset = ((flow_control & EFX_FC_TX) &&
519 !(efx->flow_control & EFX_FC_TX));
520 if (EFX_WORKAROUND_11482(efx) && reset) {
Ben Hutchings55668612008-05-16 21:16:10 +0100521 if (falcon_rev(efx) >= FALCON_REV_B0) {
Ben Hutchings8ceee662008-04-27 12:55:59 +0100522 /* Recover by resetting the EM block */
523 if (efx->link_up)
524 falcon_drain_tx_fifo(efx);
525 } else {
526 /* Schedule a reset to recover */
527 efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
528 }
529 }
530
531 efx->flow_control = flow_control;
532
533 return 0;
534}