]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/net/sfc/falcon_xmac.c
sfc: Use explicit bool for boolean variables, parameters and return values
[linux-2.6-omap-h63xx.git] / drivers / net / sfc / falcon_xmac.c
1 /****************************************************************************
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"
18 #include "gmii.h"
19 #include "mdio_10g.h"
20 #include "phy.h"
21 #include "boards.h"
22 #include "workarounds.h"
23
24 /**************************************************************************
25  *
26  * MAC register access
27  *
28  **************************************************************************/
29
30 /* Offset of an XMAC register within Falcon */
31 #define FALCON_XMAC_REG(mac_reg)                                        \
32         (FALCON_XMAC_REGBANK + ((mac_reg) * FALCON_XMAC_REG_SIZE))
33
34 void falcon_xmac_writel(struct efx_nic *efx,
35                          efx_dword_t *value, unsigned int mac_reg)
36 {
37         efx_oword_t temp;
38
39         EFX_POPULATE_OWORD_1(temp, MAC_DATA, EFX_DWORD_FIELD(*value, MAC_DATA));
40         falcon_write(efx, &temp, FALCON_XMAC_REG(mac_reg));
41 }
42
43 void falcon_xmac_readl(struct efx_nic *efx,
44                        efx_dword_t *value, unsigned int mac_reg)
45 {
46         efx_oword_t temp;
47
48         falcon_read(efx, &temp, FALCON_XMAC_REG(mac_reg));
49         EFX_POPULATE_DWORD_1(*value, MAC_DATA, EFX_OWORD_FIELD(temp, MAC_DATA));
50 }
51
52 /**************************************************************************
53  *
54  * MAC operations
55  *
56  *************************************************************************/
57 static int falcon_reset_xmac(struct efx_nic *efx)
58 {
59         efx_dword_t reg;
60         int count;
61
62         EFX_POPULATE_DWORD_1(reg, XM_CORE_RST, 1);
63         falcon_xmac_writel(efx, &reg, XM_GLB_CFG_REG_MAC);
64
65         for (count = 0; count < 10000; count++) {       /* wait upto 100ms */
66                 falcon_xmac_readl(efx, &reg, XM_GLB_CFG_REG_MAC);
67                 if (EFX_DWORD_FIELD(reg, XM_CORE_RST) == 0)
68                         return 0;
69                 udelay(10);
70         }
71
72         /* This often fails when DSP is disabled, ignore it */
73         if (sfe4001_phy_flash_cfg)
74                 return 0;
75
76         EFX_ERR(efx, "timed out waiting for XMAC core reset\n");
77         return -ETIMEDOUT;
78 }
79
80 /* Configure the XAUI driver that is an output from Falcon */
81 static void falcon_setup_xaui(struct efx_nic *efx)
82 {
83         efx_dword_t sdctl, txdrv;
84
85         /* Move the XAUI into low power, unless there is no PHY, in
86          * which case the XAUI will have to drive a cable. */
87         if (efx->phy_type == PHY_TYPE_NONE)
88                 return;
89
90         falcon_xmac_readl(efx, &sdctl, XX_SD_CTL_REG_MAC);
91         EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVD, XX_SD_CTL_DRV_DEFAULT);
92         EFX_SET_DWORD_FIELD(sdctl, XX_LODRVD, XX_SD_CTL_DRV_DEFAULT);
93         EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVC, XX_SD_CTL_DRV_DEFAULT);
94         EFX_SET_DWORD_FIELD(sdctl, XX_LODRVC, XX_SD_CTL_DRV_DEFAULT);
95         EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVB, XX_SD_CTL_DRV_DEFAULT);
96         EFX_SET_DWORD_FIELD(sdctl, XX_LODRVB, XX_SD_CTL_DRV_DEFAULT);
97         EFX_SET_DWORD_FIELD(sdctl, XX_HIDRVA, XX_SD_CTL_DRV_DEFAULT);
98         EFX_SET_DWORD_FIELD(sdctl, XX_LODRVA, XX_SD_CTL_DRV_DEFAULT);
99         falcon_xmac_writel(efx, &sdctl, XX_SD_CTL_REG_MAC);
100
101         EFX_POPULATE_DWORD_8(txdrv,
102                              XX_DEQD, XX_TXDRV_DEQ_DEFAULT,
103                              XX_DEQC, XX_TXDRV_DEQ_DEFAULT,
104                              XX_DEQB, XX_TXDRV_DEQ_DEFAULT,
105                              XX_DEQA, XX_TXDRV_DEQ_DEFAULT,
106                              XX_DTXD, XX_TXDRV_DTX_DEFAULT,
107                              XX_DTXC, XX_TXDRV_DTX_DEFAULT,
108                              XX_DTXB, XX_TXDRV_DTX_DEFAULT,
109                              XX_DTXA, XX_TXDRV_DTX_DEFAULT);
110         falcon_xmac_writel(efx, &txdrv, XX_TXDRV_CTL_REG_MAC);
111 }
112
113 static void falcon_hold_xaui_in_rst(struct efx_nic *efx)
114 {
115         efx_dword_t reg;
116
117         EFX_ZERO_DWORD(reg);
118         EFX_SET_DWORD_FIELD(reg, XX_PWRDNA_EN, 1);
119         EFX_SET_DWORD_FIELD(reg, XX_PWRDNB_EN, 1);
120         EFX_SET_DWORD_FIELD(reg, XX_PWRDNC_EN, 1);
121         EFX_SET_DWORD_FIELD(reg, XX_PWRDND_EN, 1);
122         EFX_SET_DWORD_FIELD(reg, XX_RSTPLLAB_EN, 1);
123         EFX_SET_DWORD_FIELD(reg, XX_RSTPLLCD_EN, 1);
124         EFX_SET_DWORD_FIELD(reg, XX_RESETA_EN, 1);
125         EFX_SET_DWORD_FIELD(reg, XX_RESETB_EN, 1);
126         EFX_SET_DWORD_FIELD(reg, XX_RESETC_EN, 1);
127         EFX_SET_DWORD_FIELD(reg, XX_RESETD_EN, 1);
128         EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSRX_EN, 1);
129         EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSTX_EN, 1);
130         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
131         udelay(10);
132 }
133
134 static int _falcon_reset_xaui_a(struct efx_nic *efx)
135 {
136         efx_dword_t reg;
137
138         falcon_hold_xaui_in_rst(efx);
139         falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
140
141         /* Follow the RAMBUS XAUI data reset sequencing
142          * Channels A and B first: power down, reset PLL, reset, clear
143          */
144         EFX_SET_DWORD_FIELD(reg, XX_PWRDNA_EN, 0);
145         EFX_SET_DWORD_FIELD(reg, XX_PWRDNB_EN, 0);
146         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
147         udelay(10);
148
149         EFX_SET_DWORD_FIELD(reg, XX_RSTPLLAB_EN, 0);
150         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
151         udelay(10);
152
153         EFX_SET_DWORD_FIELD(reg, XX_RESETA_EN, 0);
154         EFX_SET_DWORD_FIELD(reg, XX_RESETB_EN, 0);
155         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
156         udelay(10);
157
158         /* Channels C and D: power down, reset PLL, reset, clear */
159         EFX_SET_DWORD_FIELD(reg, XX_PWRDNC_EN, 0);
160         EFX_SET_DWORD_FIELD(reg, XX_PWRDND_EN, 0);
161         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
162         udelay(10);
163
164         EFX_SET_DWORD_FIELD(reg, XX_RSTPLLCD_EN, 0);
165         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
166         udelay(10);
167
168         EFX_SET_DWORD_FIELD(reg, XX_RESETC_EN, 0);
169         EFX_SET_DWORD_FIELD(reg, XX_RESETD_EN, 0);
170         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
171         udelay(10);
172
173         /* Setup XAUI */
174         falcon_setup_xaui(efx);
175         udelay(10);
176
177         /* Take XGXS out of reset */
178         EFX_ZERO_DWORD(reg);
179         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
180         udelay(10);
181
182         return 0;
183 }
184
185 static int _falcon_reset_xaui_b(struct efx_nic *efx)
186 {
187         efx_dword_t reg;
188         int count;
189
190         EFX_POPULATE_DWORD_1(reg, XX_RST_XX_EN, 1);
191         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
192
193         /* Give some time for the link to establish */
194         for (count = 0; count < 1000; count++) { /* wait upto 10ms */
195                 falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
196                 if (EFX_DWORD_FIELD(reg, XX_RST_XX_EN) == 0) {
197                         falcon_setup_xaui(efx);
198                         return 0;
199                 }
200                 udelay(10);
201         }
202         EFX_ERR(efx, "timed out waiting for XAUI/XGXS reset\n");
203         return -ETIMEDOUT;
204 }
205
206 int falcon_reset_xaui(struct efx_nic *efx)
207 {
208         int rc;
209
210         if (EFX_WORKAROUND_9388(efx)) {
211                 falcon_hold_xaui_in_rst(efx);
212                 efx->phy_op->reset_xaui(efx);
213                 rc = _falcon_reset_xaui_a(efx);
214         } else {
215                 rc = _falcon_reset_xaui_b(efx);
216         }
217         return rc;
218 }
219
220 static bool falcon_xgmii_status(struct efx_nic *efx)
221 {
222         efx_dword_t reg;
223
224         if (falcon_rev(efx) < FALCON_REV_B0)
225                 return true;
226
227         /* The ISR latches, so clear it and re-read */
228         falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
229         falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
230
231         if (EFX_DWORD_FIELD(reg, XM_LCLFLT) ||
232             EFX_DWORD_FIELD(reg, XM_RMTFLT)) {
233                 EFX_INFO(efx, "MGT_INT: "EFX_DWORD_FMT"\n", EFX_DWORD_VAL(reg));
234                 return false;
235         }
236
237         return true;
238 }
239
240 static void falcon_mask_status_intr(struct efx_nic *efx, bool enable)
241 {
242         efx_dword_t reg;
243
244         if ((falcon_rev(efx) < FALCON_REV_B0) || LOOPBACK_INTERNAL(efx))
245                 return;
246
247         /* Flush the ISR */
248         if (enable)
249                 falcon_xmac_readl(efx, &reg, XM_MGT_INT_REG_MAC_B0);
250
251         EFX_POPULATE_DWORD_2(reg,
252                              XM_MSK_RMTFLT, !enable,
253                              XM_MSK_LCLFLT, !enable);
254         falcon_xmac_writel(efx, &reg, XM_MGT_INT_MSK_REG_MAC_B0);
255 }
256
257 int falcon_init_xmac(struct efx_nic *efx)
258 {
259         int rc;
260
261         /* Initialize the PHY first so the clock is around */
262         rc = efx->phy_op->init(efx);
263         if (rc)
264                 goto fail1;
265
266         rc = falcon_reset_xaui(efx);
267         if (rc)
268                 goto fail2;
269
270         /* Wait again. Give the PHY and MAC time to come back */
271         schedule_timeout_uninterruptible(HZ / 10);
272
273         rc = falcon_reset_xmac(efx);
274         if (rc)
275                 goto fail2;
276
277         falcon_mask_status_intr(efx, true);
278         return 0;
279
280  fail2:
281         efx->phy_op->fini(efx);
282  fail1:
283         return rc;
284 }
285
286 bool falcon_xaui_link_ok(struct efx_nic *efx)
287 {
288         efx_dword_t reg;
289         bool align_done, link_ok = false;
290         int sync_status;
291
292         if (LOOPBACK_INTERNAL(efx))
293                 return true;
294
295         /* Read link status */
296         falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
297
298         align_done = EFX_DWORD_FIELD(reg, XX_ALIGN_DONE);
299         sync_status = EFX_DWORD_FIELD(reg, XX_SYNC_STAT);
300         if (align_done && (sync_status == XX_SYNC_STAT_DECODE_SYNCED))
301                 link_ok = true;
302
303         /* Clear link status ready for next read */
304         EFX_SET_DWORD_FIELD(reg, XX_COMMA_DET, XX_COMMA_DET_RESET);
305         EFX_SET_DWORD_FIELD(reg, XX_CHARERR, XX_CHARERR_RESET);
306         EFX_SET_DWORD_FIELD(reg, XX_DISPERR, XX_DISPERR_RESET);
307         falcon_xmac_writel(efx, &reg, XX_CORE_STAT_REG_MAC);
308
309         /* If the link is up, then check the phy side of the xaui link
310          * (error conditions from the wire side propoagate back through
311          * the phy to the xaui side). */
312         if (efx->link_up && link_ok) {
313                 if (efx->phy_op->mmds & (1 << MDIO_MMD_PHYXS))
314                         link_ok = mdio_clause45_phyxgxs_lane_sync(efx);
315         }
316
317         /* If the PHY and XAUI links are up, then check the mac's xgmii
318          * fault state */
319         if (efx->link_up && link_ok)
320                 link_ok = falcon_xgmii_status(efx);
321
322         return link_ok;
323 }
324
325 static void falcon_reconfigure_xmac_core(struct efx_nic *efx)
326 {
327         unsigned int max_frame_len;
328         efx_dword_t reg;
329         bool rx_fc = !!(efx->flow_control & EFX_FC_RX);
330
331         /* Configure MAC  - cut-thru mode is hard wired on */
332         EFX_POPULATE_DWORD_3(reg,
333                              XM_RX_JUMBO_MODE, 1,
334                              XM_TX_STAT_EN, 1,
335                              XM_RX_STAT_EN, 1);
336         falcon_xmac_writel(efx, &reg, XM_GLB_CFG_REG_MAC);
337
338         /* Configure TX */
339         EFX_POPULATE_DWORD_6(reg,
340                              XM_TXEN, 1,
341                              XM_TX_PRMBL, 1,
342                              XM_AUTO_PAD, 1,
343                              XM_TXCRC, 1,
344                              XM_FCNTL, 1,
345                              XM_IPG, 0x3);
346         falcon_xmac_writel(efx, &reg, XM_TX_CFG_REG_MAC);
347
348         /* Configure RX */
349         EFX_POPULATE_DWORD_5(reg,
350                              XM_RXEN, 1,
351                              XM_AUTO_DEPAD, 0,
352                              XM_ACPT_ALL_MCAST, 1,
353                              XM_ACPT_ALL_UCAST, efx->promiscuous,
354                              XM_PASS_CRC_ERR, 1);
355         falcon_xmac_writel(efx, &reg, XM_RX_CFG_REG_MAC);
356
357         /* Set frame length */
358         max_frame_len = EFX_MAX_FRAME_LEN(efx->net_dev->mtu);
359         EFX_POPULATE_DWORD_1(reg, XM_MAX_RX_FRM_SIZE, max_frame_len);
360         falcon_xmac_writel(efx, &reg, XM_RX_PARAM_REG_MAC);
361         EFX_POPULATE_DWORD_2(reg,
362                              XM_MAX_TX_FRM_SIZE, max_frame_len,
363                              XM_TX_JUMBO_MODE, 1);
364         falcon_xmac_writel(efx, &reg, XM_TX_PARAM_REG_MAC);
365
366         EFX_POPULATE_DWORD_2(reg,
367                              XM_PAUSE_TIME, 0xfffe, /* MAX PAUSE TIME */
368                              XM_DIS_FCNTL, !rx_fc);
369         falcon_xmac_writel(efx, &reg, XM_FC_REG_MAC);
370
371         /* Set MAC address */
372         EFX_POPULATE_DWORD_4(reg,
373                              XM_ADR_0, efx->net_dev->dev_addr[0],
374                              XM_ADR_1, efx->net_dev->dev_addr[1],
375                              XM_ADR_2, efx->net_dev->dev_addr[2],
376                              XM_ADR_3, efx->net_dev->dev_addr[3]);
377         falcon_xmac_writel(efx, &reg, XM_ADR_LO_REG_MAC);
378         EFX_POPULATE_DWORD_2(reg,
379                              XM_ADR_4, efx->net_dev->dev_addr[4],
380                              XM_ADR_5, efx->net_dev->dev_addr[5]);
381         falcon_xmac_writel(efx, &reg, XM_ADR_HI_REG_MAC);
382 }
383
384 static void falcon_reconfigure_xgxs_core(struct efx_nic *efx)
385 {
386         efx_dword_t reg;
387         bool xgxs_loopback = (efx->loopback_mode == LOOPBACK_XGXS);
388         bool xaui_loopback = (efx->loopback_mode == LOOPBACK_XAUI);
389         bool xgmii_loopback = (efx->loopback_mode == LOOPBACK_XGMII);
390
391         /* XGXS block is flaky and will need to be reset if moving
392          * into our out of XGMII, XGXS or XAUI loopbacks. */
393         if (EFX_WORKAROUND_5147(efx)) {
394                 bool old_xgmii_loopback, old_xgxs_loopback, old_xaui_loopback;
395                 bool reset_xgxs;
396
397                 falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
398                 old_xgxs_loopback = EFX_DWORD_FIELD(reg, XX_XGXS_LB_EN);
399                 old_xgmii_loopback = EFX_DWORD_FIELD(reg, XX_XGMII_LB_EN);
400
401                 falcon_xmac_readl(efx, &reg, XX_SD_CTL_REG_MAC);
402                 old_xaui_loopback = EFX_DWORD_FIELD(reg, XX_LPBKA);
403
404                 /* The PHY driver may have turned XAUI off */
405                 reset_xgxs = ((xgxs_loopback != old_xgxs_loopback) ||
406                               (xaui_loopback != old_xaui_loopback) ||
407                               (xgmii_loopback != old_xgmii_loopback));
408                 if (reset_xgxs) {
409                         falcon_xmac_readl(efx, &reg, XX_PWR_RST_REG_MAC);
410                         EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSTX_EN, 1);
411                         EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSRX_EN, 1);
412                         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
413                         udelay(1);
414                         EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSTX_EN, 0);
415                         EFX_SET_DWORD_FIELD(reg, XX_RSTXGXSRX_EN, 0);
416                         falcon_xmac_writel(efx, &reg, XX_PWR_RST_REG_MAC);
417                         udelay(1);
418                 }
419         }
420
421         falcon_xmac_readl(efx, &reg, XX_CORE_STAT_REG_MAC);
422         EFX_SET_DWORD_FIELD(reg, XX_FORCE_SIG,
423                             (xgxs_loopback || xaui_loopback) ?
424                             XX_FORCE_SIG_DECODE_FORCED : 0);
425         EFX_SET_DWORD_FIELD(reg, XX_XGXS_LB_EN, xgxs_loopback);
426         EFX_SET_DWORD_FIELD(reg, XX_XGMII_LB_EN, xgmii_loopback);
427         falcon_xmac_writel(efx, &reg, XX_CORE_STAT_REG_MAC);
428
429         falcon_xmac_readl(efx, &reg, XX_SD_CTL_REG_MAC);
430         EFX_SET_DWORD_FIELD(reg, XX_LPBKD, xaui_loopback);
431         EFX_SET_DWORD_FIELD(reg, XX_LPBKC, xaui_loopback);
432         EFX_SET_DWORD_FIELD(reg, XX_LPBKB, xaui_loopback);
433         EFX_SET_DWORD_FIELD(reg, XX_LPBKA, xaui_loopback);
434         falcon_xmac_writel(efx, &reg, XX_SD_CTL_REG_MAC);
435 }
436
437
438 /* Try and bring the Falcon side of the Falcon-Phy XAUI link fails
439  * to come back up. Bash it until it comes back up */
440 static bool falcon_check_xaui_link_up(struct efx_nic *efx)
441 {
442         int max_tries, tries;
443         tries = EFX_WORKAROUND_5147(efx) ? 5 : 1;
444         max_tries = tries;
445
446         if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
447             (efx->phy_type == PHY_TYPE_NONE))
448                 return false;
449
450         while (tries) {
451                 if (falcon_xaui_link_ok(efx))
452                         return true;
453
454                 EFX_LOG(efx, "%s Clobbering XAUI (%d tries left).\n",
455                         __func__, tries);
456                 falcon_reset_xaui(efx);
457                 udelay(200);
458                 tries--;
459         }
460
461         EFX_LOG(efx, "Failed to bring XAUI link back up in %d tries!\n",
462                 max_tries);
463         return false;
464 }
465
466 void falcon_reconfigure_xmac(struct efx_nic *efx)
467 {
468         bool xaui_link_ok;
469
470         falcon_mask_status_intr(efx, false);
471
472         falcon_deconfigure_mac_wrapper(efx);
473
474         efx->tx_disabled = LOOPBACK_INTERNAL(efx);
475         efx->phy_op->reconfigure(efx);
476
477         falcon_reconfigure_xgxs_core(efx);
478         falcon_reconfigure_xmac_core(efx);
479
480         falcon_reconfigure_mac_wrapper(efx);
481
482         /* Ensure XAUI link is up */
483         xaui_link_ok = falcon_check_xaui_link_up(efx);
484
485         if (xaui_link_ok && efx->link_up)
486                 falcon_mask_status_intr(efx, true);
487 }
488
489 void falcon_fini_xmac(struct efx_nic *efx)
490 {
491         /* Isolate the MAC - PHY */
492         falcon_deconfigure_mac_wrapper(efx);
493
494         /* Potentially power down the PHY */
495         efx->phy_op->fini(efx);
496 }
497
498 void falcon_update_stats_xmac(struct efx_nic *efx)
499 {
500         struct efx_mac_stats *mac_stats = &efx->mac_stats;
501         int rc;
502
503         rc = falcon_dma_stats(efx, XgDmaDone_offset);
504         if (rc)
505                 return;
506
507         /* Update MAC stats from DMAed values */
508         FALCON_STAT(efx, XgRxOctets, rx_bytes);
509         FALCON_STAT(efx, XgRxOctetsOK, rx_good_bytes);
510         FALCON_STAT(efx, XgRxPkts, rx_packets);
511         FALCON_STAT(efx, XgRxPktsOK, rx_good);
512         FALCON_STAT(efx, XgRxBroadcastPkts, rx_broadcast);
513         FALCON_STAT(efx, XgRxMulticastPkts, rx_multicast);
514         FALCON_STAT(efx, XgRxUnicastPkts, rx_unicast);
515         FALCON_STAT(efx, XgRxUndersizePkts, rx_lt64);
516         FALCON_STAT(efx, XgRxOversizePkts, rx_gtjumbo);
517         FALCON_STAT(efx, XgRxJabberPkts, rx_bad_gtjumbo);
518         FALCON_STAT(efx, XgRxUndersizeFCSerrorPkts, rx_bad_lt64);
519         FALCON_STAT(efx, XgRxDropEvents, rx_overflow);
520         FALCON_STAT(efx, XgRxFCSerrorPkts, rx_bad);
521         FALCON_STAT(efx, XgRxAlignError, rx_align_error);
522         FALCON_STAT(efx, XgRxSymbolError, rx_symbol_error);
523         FALCON_STAT(efx, XgRxInternalMACError, rx_internal_error);
524         FALCON_STAT(efx, XgRxControlPkts, rx_control);
525         FALCON_STAT(efx, XgRxPausePkts, rx_pause);
526         FALCON_STAT(efx, XgRxPkts64Octets, rx_64);
527         FALCON_STAT(efx, XgRxPkts65to127Octets, rx_65_to_127);
528         FALCON_STAT(efx, XgRxPkts128to255Octets, rx_128_to_255);
529         FALCON_STAT(efx, XgRxPkts256to511Octets, rx_256_to_511);
530         FALCON_STAT(efx, XgRxPkts512to1023Octets, rx_512_to_1023);
531         FALCON_STAT(efx, XgRxPkts1024to15xxOctets, rx_1024_to_15xx);
532         FALCON_STAT(efx, XgRxPkts15xxtoMaxOctets, rx_15xx_to_jumbo);
533         FALCON_STAT(efx, XgRxLengthError, rx_length_error);
534         FALCON_STAT(efx, XgTxPkts, tx_packets);
535         FALCON_STAT(efx, XgTxOctets, tx_bytes);
536         FALCON_STAT(efx, XgTxMulticastPkts, tx_multicast);
537         FALCON_STAT(efx, XgTxBroadcastPkts, tx_broadcast);
538         FALCON_STAT(efx, XgTxUnicastPkts, tx_unicast);
539         FALCON_STAT(efx, XgTxControlPkts, tx_control);
540         FALCON_STAT(efx, XgTxPausePkts, tx_pause);
541         FALCON_STAT(efx, XgTxPkts64Octets, tx_64);
542         FALCON_STAT(efx, XgTxPkts65to127Octets, tx_65_to_127);
543         FALCON_STAT(efx, XgTxPkts128to255Octets, tx_128_to_255);
544         FALCON_STAT(efx, XgTxPkts256to511Octets, tx_256_to_511);
545         FALCON_STAT(efx, XgTxPkts512to1023Octets, tx_512_to_1023);
546         FALCON_STAT(efx, XgTxPkts1024to15xxOctets, tx_1024_to_15xx);
547         FALCON_STAT(efx, XgTxPkts1519toMaxOctets, tx_15xx_to_jumbo);
548         FALCON_STAT(efx, XgTxUndersizePkts, tx_lt64);
549         FALCON_STAT(efx, XgTxOversizePkts, tx_gtjumbo);
550         FALCON_STAT(efx, XgTxNonTcpUdpPkt, tx_non_tcpudp);
551         FALCON_STAT(efx, XgTxMacSrcErrPkt, tx_mac_src_error);
552         FALCON_STAT(efx, XgTxIpSrcErrPkt, tx_ip_src_error);
553
554         /* Update derived statistics */
555         mac_stats->tx_good_bytes =
556                 (mac_stats->tx_bytes - mac_stats->tx_bad_bytes -
557                  mac_stats->tx_control * 64);
558         mac_stats->rx_bad_bytes =
559                 (mac_stats->rx_bytes - mac_stats->rx_good_bytes -
560                  mac_stats->rx_control * 64);
561 }
562
563 int falcon_check_xmac(struct efx_nic *efx)
564 {
565         bool xaui_link_ok;
566         int rc;
567
568         if ((efx->loopback_mode == LOOPBACK_NETWORK) ||
569             (efx->phy_type == PHY_TYPE_NONE))
570                 return 0;
571
572         falcon_mask_status_intr(efx, false);
573         xaui_link_ok = falcon_xaui_link_ok(efx);
574
575         if (EFX_WORKAROUND_5147(efx) && !xaui_link_ok)
576                 falcon_reset_xaui(efx);
577
578         /* Call the PHY check_hw routine */
579         rc = efx->phy_op->check_hw(efx);
580
581         /* Unmask interrupt if everything was (and still is) ok */
582         if (xaui_link_ok && efx->link_up)
583                 falcon_mask_status_intr(efx, true);
584
585         return rc;
586 }
587
588 /* Simulate a PHY event */
589 void falcon_xmac_sim_phy_event(struct efx_nic *efx)
590 {
591         efx_qword_t phy_event;
592
593         EFX_POPULATE_QWORD_2(phy_event,
594                              EV_CODE, GLOBAL_EV_DECODE,
595                              XG_PHY_INTR, 1);
596         falcon_generate_event(&efx->channel[0], &phy_event);
597 }
598
599 int falcon_xmac_get_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
600 {
601         mdio_clause45_get_settings(efx, ecmd);
602         ecmd->transceiver = XCVR_INTERNAL;
603         ecmd->phy_address = efx->mii.phy_id;
604         ecmd->autoneg = AUTONEG_DISABLE;
605         ecmd->duplex = DUPLEX_FULL;
606         return 0;
607 }
608
609 int falcon_xmac_set_settings(struct efx_nic *efx, struct ethtool_cmd *ecmd)
610 {
611         if (ecmd->transceiver != XCVR_INTERNAL)
612                 return -EINVAL;
613         if (ecmd->autoneg != AUTONEG_DISABLE)
614                 return -EINVAL;
615         if (ecmd->duplex != DUPLEX_FULL)
616                 return -EINVAL;
617
618         return mdio_clause45_set_settings(efx, ecmd);
619 }
620
621
622 int falcon_xmac_set_pause(struct efx_nic *efx, enum efx_fc_type flow_control)
623 {
624         bool reset;
625
626         if (flow_control & EFX_FC_AUTO) {
627                 EFX_LOG(efx, "10G does not support flow control "
628                         "autonegotiation\n");
629                 return -EINVAL;
630         }
631
632         if ((flow_control & EFX_FC_TX) && !(flow_control & EFX_FC_RX))
633                 return -EINVAL;
634
635         /* TX flow control may automatically turn itself off if the
636          * link partner (intermittently) stops responding to pause
637          * frames. There isn't any indication that this has happened,
638          * so the best we do is leave it up to the user to spot this
639          * and fix it be cycling transmit flow control on this end. */
640         reset = ((flow_control & EFX_FC_TX) &&
641                  !(efx->flow_control & EFX_FC_TX));
642         if (EFX_WORKAROUND_11482(efx) && reset) {
643                 if (falcon_rev(efx) >= FALCON_REV_B0) {
644                         /* Recover by resetting the EM block */
645                         if (efx->link_up)
646                                 falcon_drain_tx_fifo(efx);
647                 } else {
648                         /* Schedule a reset to recover */
649                         efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
650                 }
651         }
652
653         efx->flow_control = flow_control;
654
655         return 0;
656 }