blob: 2c7e0ab6ccf8eb562433bdbdfc7baf59a06fa890 [file] [log] [blame]
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +00001/* bnx2x_ethtool.c: Broadcom Everest network driver.
2 *
3 * Copyright (c) 2007-2010 Broadcom Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation.
8 *
9 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
10 * Written by: Eliezer Tamir
11 * Based on code from Michael Chan's bnx2 driver
12 * UDP CSUM errata workaround by Arik Gendelman
13 * Slowpath and fastpath rework by Vladislav Zolotarov
14 * Statistics and Link management by Yitchak Gertner
15 *
16 */
17#include <linux/ethtool.h>
18#include <linux/netdevice.h>
19#include <linux/types.h>
20#include <linux/sched.h>
21#include <linux/crc32.h>
22
23
24#include "bnx2x.h"
25#include "bnx2x_cmn.h"
26#include "bnx2x_dump.h"
27
28
29static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
30{
31 struct bnx2x *bp = netdev_priv(dev);
32
33 cmd->supported = bp->port.supported;
34 cmd->advertising = bp->port.advertising;
35
36 if ((bp->state == BNX2X_STATE_OPEN) &&
37 !(bp->flags & MF_FUNC_DIS) &&
38 (bp->link_vars.link_up)) {
39 cmd->speed = bp->link_vars.line_speed;
40 cmd->duplex = bp->link_vars.duplex;
41 if (IS_E1HMF(bp)) {
42 u16 vn_max_rate;
43
44 vn_max_rate =
45 ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
46 FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
47 if (vn_max_rate < cmd->speed)
48 cmd->speed = vn_max_rate;
49 }
50 } else {
51 cmd->speed = -1;
52 cmd->duplex = -1;
53 }
54
55 if (bp->link_params.switch_cfg == SWITCH_CFG_10G) {
56 u32 ext_phy_type =
57 XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
58
59 switch (ext_phy_type) {
60 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
61 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
62 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
63 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
64 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
65 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
66 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
67 cmd->port = PORT_FIBRE;
68 break;
69
70 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
71 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
72 cmd->port = PORT_TP;
73 break;
74
75 case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
76 BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
77 bp->link_params.ext_phy_config);
78 break;
79
80 default:
81 DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
82 bp->link_params.ext_phy_config);
83 break;
84 }
85 } else
86 cmd->port = PORT_TP;
87
88 cmd->phy_address = bp->mdio.prtad;
89 cmd->transceiver = XCVR_INTERNAL;
90
91 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
92 cmd->autoneg = AUTONEG_ENABLE;
93 else
94 cmd->autoneg = AUTONEG_DISABLE;
95
96 cmd->maxtxpkt = 0;
97 cmd->maxrxpkt = 0;
98
99 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
100 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
101 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
102 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
103 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
104 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
105 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
106
107 return 0;
108}
109
110static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
111{
112 struct bnx2x *bp = netdev_priv(dev);
113 u32 advertising;
114
115 if (IS_E1HMF(bp))
116 return 0;
117
118 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
119 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
120 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
121 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
122 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
123 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
124 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
125
126 if (cmd->autoneg == AUTONEG_ENABLE) {
127 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
128 DP(NETIF_MSG_LINK, "Autoneg not supported\n");
129 return -EINVAL;
130 }
131
132 /* advertise the requested speed and duplex if supported */
133 cmd->advertising &= bp->port.supported;
134
135 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
136 bp->link_params.req_duplex = DUPLEX_FULL;
137 bp->port.advertising |= (ADVERTISED_Autoneg |
138 cmd->advertising);
139
140 } else { /* forced speed */
141 /* advertise the requested speed and duplex if supported */
142 switch (cmd->speed) {
143 case SPEED_10:
144 if (cmd->duplex == DUPLEX_FULL) {
145 if (!(bp->port.supported &
146 SUPPORTED_10baseT_Full)) {
147 DP(NETIF_MSG_LINK,
148 "10M full not supported\n");
149 return -EINVAL;
150 }
151
152 advertising = (ADVERTISED_10baseT_Full |
153 ADVERTISED_TP);
154 } else {
155 if (!(bp->port.supported &
156 SUPPORTED_10baseT_Half)) {
157 DP(NETIF_MSG_LINK,
158 "10M half not supported\n");
159 return -EINVAL;
160 }
161
162 advertising = (ADVERTISED_10baseT_Half |
163 ADVERTISED_TP);
164 }
165 break;
166
167 case SPEED_100:
168 if (cmd->duplex == DUPLEX_FULL) {
169 if (!(bp->port.supported &
170 SUPPORTED_100baseT_Full)) {
171 DP(NETIF_MSG_LINK,
172 "100M full not supported\n");
173 return -EINVAL;
174 }
175
176 advertising = (ADVERTISED_100baseT_Full |
177 ADVERTISED_TP);
178 } else {
179 if (!(bp->port.supported &
180 SUPPORTED_100baseT_Half)) {
181 DP(NETIF_MSG_LINK,
182 "100M half not supported\n");
183 return -EINVAL;
184 }
185
186 advertising = (ADVERTISED_100baseT_Half |
187 ADVERTISED_TP);
188 }
189 break;
190
191 case SPEED_1000:
192 if (cmd->duplex != DUPLEX_FULL) {
193 DP(NETIF_MSG_LINK, "1G half not supported\n");
194 return -EINVAL;
195 }
196
197 if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) {
198 DP(NETIF_MSG_LINK, "1G full not supported\n");
199 return -EINVAL;
200 }
201
202 advertising = (ADVERTISED_1000baseT_Full |
203 ADVERTISED_TP);
204 break;
205
206 case SPEED_2500:
207 if (cmd->duplex != DUPLEX_FULL) {
208 DP(NETIF_MSG_LINK,
209 "2.5G half not supported\n");
210 return -EINVAL;
211 }
212
213 if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) {
214 DP(NETIF_MSG_LINK,
215 "2.5G full not supported\n");
216 return -EINVAL;
217 }
218
219 advertising = (ADVERTISED_2500baseX_Full |
220 ADVERTISED_TP);
221 break;
222
223 case SPEED_10000:
224 if (cmd->duplex != DUPLEX_FULL) {
225 DP(NETIF_MSG_LINK, "10G half not supported\n");
226 return -EINVAL;
227 }
228
229 if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) {
230 DP(NETIF_MSG_LINK, "10G full not supported\n");
231 return -EINVAL;
232 }
233
234 advertising = (ADVERTISED_10000baseT_Full |
235 ADVERTISED_FIBRE);
236 break;
237
238 default:
239 DP(NETIF_MSG_LINK, "Unsupported speed\n");
240 return -EINVAL;
241 }
242
243 bp->link_params.req_line_speed = cmd->speed;
244 bp->link_params.req_duplex = cmd->duplex;
245 bp->port.advertising = advertising;
246 }
247
248 DP(NETIF_MSG_LINK, "req_line_speed %d\n"
249 DP_LEVEL " req_duplex %d advertising 0x%x\n",
250 bp->link_params.req_line_speed, bp->link_params.req_duplex,
251 bp->port.advertising);
252
253 if (netif_running(dev)) {
254 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
255 bnx2x_link_set(bp);
256 }
257
258 return 0;
259}
260
261#define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
262#define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
263
264static int bnx2x_get_regs_len(struct net_device *dev)
265{
266 struct bnx2x *bp = netdev_priv(dev);
267 int regdump_len = 0;
268 int i;
269
270 if (CHIP_IS_E1(bp)) {
271 for (i = 0; i < REGS_COUNT; i++)
272 if (IS_E1_ONLINE(reg_addrs[i].info))
273 regdump_len += reg_addrs[i].size;
274
275 for (i = 0; i < WREGS_COUNT_E1; i++)
276 if (IS_E1_ONLINE(wreg_addrs_e1[i].info))
277 regdump_len += wreg_addrs_e1[i].size *
278 (1 + wreg_addrs_e1[i].read_regs_count);
279
280 } else { /* E1H */
281 for (i = 0; i < REGS_COUNT; i++)
282 if (IS_E1H_ONLINE(reg_addrs[i].info))
283 regdump_len += reg_addrs[i].size;
284
285 for (i = 0; i < WREGS_COUNT_E1H; i++)
286 if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info))
287 regdump_len += wreg_addrs_e1h[i].size *
288 (1 + wreg_addrs_e1h[i].read_regs_count);
289 }
290 regdump_len *= 4;
291 regdump_len += sizeof(struct dump_hdr);
292
293 return regdump_len;
294}
295
296static void bnx2x_get_regs(struct net_device *dev,
297 struct ethtool_regs *regs, void *_p)
298{
299 u32 *p = _p, i, j;
300 struct bnx2x *bp = netdev_priv(dev);
301 struct dump_hdr dump_hdr = {0};
302
303 regs->version = 0;
304 memset(p, 0, regs->len);
305
306 if (!netif_running(bp->dev))
307 return;
308
309 dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
310 dump_hdr.dump_sign = dump_sign_all;
311 dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
312 dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
313 dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
314 dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
315 dump_hdr.info = CHIP_IS_E1(bp) ? RI_E1_ONLINE : RI_E1H_ONLINE;
316
317 memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
318 p += dump_hdr.hdr_size + 1;
319
320 if (CHIP_IS_E1(bp)) {
321 for (i = 0; i < REGS_COUNT; i++)
322 if (IS_E1_ONLINE(reg_addrs[i].info))
323 for (j = 0; j < reg_addrs[i].size; j++)
324 *p++ = REG_RD(bp,
325 reg_addrs[i].addr + j*4);
326
327 } else { /* E1H */
328 for (i = 0; i < REGS_COUNT; i++)
329 if (IS_E1H_ONLINE(reg_addrs[i].info))
330 for (j = 0; j < reg_addrs[i].size; j++)
331 *p++ = REG_RD(bp,
332 reg_addrs[i].addr + j*4);
333 }
334}
335
336#define PHY_FW_VER_LEN 10
337
338static void bnx2x_get_drvinfo(struct net_device *dev,
339 struct ethtool_drvinfo *info)
340{
341 struct bnx2x *bp = netdev_priv(dev);
342 u8 phy_fw_ver[PHY_FW_VER_LEN];
343
344 strcpy(info->driver, DRV_MODULE_NAME);
345 strcpy(info->version, DRV_MODULE_VERSION);
346
347 phy_fw_ver[0] = '\0';
348 if (bp->port.pmf) {
349 bnx2x_acquire_phy_lock(bp);
350 bnx2x_get_ext_phy_fw_version(&bp->link_params,
351 (bp->state != BNX2X_STATE_CLOSED),
352 phy_fw_ver, PHY_FW_VER_LEN);
353 bnx2x_release_phy_lock(bp);
354 }
355
356 strncpy(info->fw_version, bp->fw_ver, 32);
357 snprintf(info->fw_version + strlen(bp->fw_ver), 32 - strlen(bp->fw_ver),
358 "bc %d.%d.%d%s%s",
359 (bp->common.bc_ver & 0xff0000) >> 16,
360 (bp->common.bc_ver & 0xff00) >> 8,
361 (bp->common.bc_ver & 0xff),
362 ((phy_fw_ver[0] != '\0') ? " phy " : ""), phy_fw_ver);
363 strcpy(info->bus_info, pci_name(bp->pdev));
364 info->n_stats = BNX2X_NUM_STATS;
365 info->testinfo_len = BNX2X_NUM_TESTS;
366 info->eedump_len = bp->common.flash_size;
367 info->regdump_len = bnx2x_get_regs_len(dev);
368}
369
370static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
371{
372 struct bnx2x *bp = netdev_priv(dev);
373
374 if (bp->flags & NO_WOL_FLAG) {
375 wol->supported = 0;
376 wol->wolopts = 0;
377 } else {
378 wol->supported = WAKE_MAGIC;
379 if (bp->wol)
380 wol->wolopts = WAKE_MAGIC;
381 else
382 wol->wolopts = 0;
383 }
384 memset(&wol->sopass, 0, sizeof(wol->sopass));
385}
386
387static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
388{
389 struct bnx2x *bp = netdev_priv(dev);
390
391 if (wol->wolopts & ~WAKE_MAGIC)
392 return -EINVAL;
393
394 if (wol->wolopts & WAKE_MAGIC) {
395 if (bp->flags & NO_WOL_FLAG)
396 return -EINVAL;
397
398 bp->wol = 1;
399 } else
400 bp->wol = 0;
401
402 return 0;
403}
404
405static u32 bnx2x_get_msglevel(struct net_device *dev)
406{
407 struct bnx2x *bp = netdev_priv(dev);
408
409 return bp->msg_enable;
410}
411
412static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
413{
414 struct bnx2x *bp = netdev_priv(dev);
415
416 if (capable(CAP_NET_ADMIN))
417 bp->msg_enable = level;
418}
419
420static int bnx2x_nway_reset(struct net_device *dev)
421{
422 struct bnx2x *bp = netdev_priv(dev);
423
424 if (!bp->port.pmf)
425 return 0;
426
427 if (netif_running(dev)) {
428 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
429 bnx2x_link_set(bp);
430 }
431
432 return 0;
433}
434
435static u32 bnx2x_get_link(struct net_device *dev)
436{
437 struct bnx2x *bp = netdev_priv(dev);
438
439 if (bp->flags & MF_FUNC_DIS)
440 return 0;
441
442 return bp->link_vars.link_up;
443}
444
445static int bnx2x_get_eeprom_len(struct net_device *dev)
446{
447 struct bnx2x *bp = netdev_priv(dev);
448
449 return bp->common.flash_size;
450}
451
452static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
453{
454 int port = BP_PORT(bp);
455 int count, i;
456 u32 val = 0;
457
458 /* adjust timeout for emulation/FPGA */
459 count = NVRAM_TIMEOUT_COUNT;
460 if (CHIP_REV_IS_SLOW(bp))
461 count *= 100;
462
463 /* request access to nvram interface */
464 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
465 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
466
467 for (i = 0; i < count*10; i++) {
468 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
469 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
470 break;
471
472 udelay(5);
473 }
474
475 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
476 DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
477 return -EBUSY;
478 }
479
480 return 0;
481}
482
483static int bnx2x_release_nvram_lock(struct bnx2x *bp)
484{
485 int port = BP_PORT(bp);
486 int count, i;
487 u32 val = 0;
488
489 /* adjust timeout for emulation/FPGA */
490 count = NVRAM_TIMEOUT_COUNT;
491 if (CHIP_REV_IS_SLOW(bp))
492 count *= 100;
493
494 /* relinquish nvram interface */
495 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
496 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
497
498 for (i = 0; i < count*10; i++) {
499 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
500 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
501 break;
502
503 udelay(5);
504 }
505
506 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
507 DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
508 return -EBUSY;
509 }
510
511 return 0;
512}
513
514static void bnx2x_enable_nvram_access(struct bnx2x *bp)
515{
516 u32 val;
517
518 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
519
520 /* enable both bits, even on read */
521 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
522 (val | MCPR_NVM_ACCESS_ENABLE_EN |
523 MCPR_NVM_ACCESS_ENABLE_WR_EN));
524}
525
526static void bnx2x_disable_nvram_access(struct bnx2x *bp)
527{
528 u32 val;
529
530 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
531
532 /* disable both bits, even after read */
533 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
534 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
535 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
536}
537
538static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
539 u32 cmd_flags)
540{
541 int count, i, rc;
542 u32 val;
543
544 /* build the command word */
545 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
546
547 /* need to clear DONE bit separately */
548 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
549
550 /* address of the NVRAM to read from */
551 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
552 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
553
554 /* issue a read command */
555 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
556
557 /* adjust timeout for emulation/FPGA */
558 count = NVRAM_TIMEOUT_COUNT;
559 if (CHIP_REV_IS_SLOW(bp))
560 count *= 100;
561
562 /* wait for completion */
563 *ret_val = 0;
564 rc = -EBUSY;
565 for (i = 0; i < count; i++) {
566 udelay(5);
567 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
568
569 if (val & MCPR_NVM_COMMAND_DONE) {
570 val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
571 /* we read nvram data in cpu order
572 * but ethtool sees it as an array of bytes
573 * converting to big-endian will do the work */
574 *ret_val = cpu_to_be32(val);
575 rc = 0;
576 break;
577 }
578 }
579
580 return rc;
581}
582
583static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
584 int buf_size)
585{
586 int rc;
587 u32 cmd_flags;
588 __be32 val;
589
590 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
591 DP(BNX2X_MSG_NVM,
592 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
593 offset, buf_size);
594 return -EINVAL;
595 }
596
597 if (offset + buf_size > bp->common.flash_size) {
598 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
599 " buf_size (0x%x) > flash_size (0x%x)\n",
600 offset, buf_size, bp->common.flash_size);
601 return -EINVAL;
602 }
603
604 /* request access to nvram interface */
605 rc = bnx2x_acquire_nvram_lock(bp);
606 if (rc)
607 return rc;
608
609 /* enable access to nvram interface */
610 bnx2x_enable_nvram_access(bp);
611
612 /* read the first word(s) */
613 cmd_flags = MCPR_NVM_COMMAND_FIRST;
614 while ((buf_size > sizeof(u32)) && (rc == 0)) {
615 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
616 memcpy(ret_buf, &val, 4);
617
618 /* advance to the next dword */
619 offset += sizeof(u32);
620 ret_buf += sizeof(u32);
621 buf_size -= sizeof(u32);
622 cmd_flags = 0;
623 }
624
625 if (rc == 0) {
626 cmd_flags |= MCPR_NVM_COMMAND_LAST;
627 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
628 memcpy(ret_buf, &val, 4);
629 }
630
631 /* disable access to nvram interface */
632 bnx2x_disable_nvram_access(bp);
633 bnx2x_release_nvram_lock(bp);
634
635 return rc;
636}
637
638static int bnx2x_get_eeprom(struct net_device *dev,
639 struct ethtool_eeprom *eeprom, u8 *eebuf)
640{
641 struct bnx2x *bp = netdev_priv(dev);
642 int rc;
643
644 if (!netif_running(dev))
645 return -EAGAIN;
646
647 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
648 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
649 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
650 eeprom->len, eeprom->len);
651
652 /* parameters already validated in ethtool_get_eeprom */
653
654 rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
655
656 return rc;
657}
658
659static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
660 u32 cmd_flags)
661{
662 int count, i, rc;
663
664 /* build the command word */
665 cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
666
667 /* need to clear DONE bit separately */
668 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
669
670 /* write the data */
671 REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
672
673 /* address of the NVRAM to write to */
674 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
675 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
676
677 /* issue the write command */
678 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
679
680 /* adjust timeout for emulation/FPGA */
681 count = NVRAM_TIMEOUT_COUNT;
682 if (CHIP_REV_IS_SLOW(bp))
683 count *= 100;
684
685 /* wait for completion */
686 rc = -EBUSY;
687 for (i = 0; i < count; i++) {
688 udelay(5);
689 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
690 if (val & MCPR_NVM_COMMAND_DONE) {
691 rc = 0;
692 break;
693 }
694 }
695
696 return rc;
697}
698
699#define BYTE_OFFSET(offset) (8 * (offset & 0x03))
700
701static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
702 int buf_size)
703{
704 int rc;
705 u32 cmd_flags;
706 u32 align_offset;
707 __be32 val;
708
709 if (offset + buf_size > bp->common.flash_size) {
710 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
711 " buf_size (0x%x) > flash_size (0x%x)\n",
712 offset, buf_size, bp->common.flash_size);
713 return -EINVAL;
714 }
715
716 /* request access to nvram interface */
717 rc = bnx2x_acquire_nvram_lock(bp);
718 if (rc)
719 return rc;
720
721 /* enable access to nvram interface */
722 bnx2x_enable_nvram_access(bp);
723
724 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
725 align_offset = (offset & ~0x03);
726 rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
727
728 if (rc == 0) {
729 val &= ~(0xff << BYTE_OFFSET(offset));
730 val |= (*data_buf << BYTE_OFFSET(offset));
731
732 /* nvram data is returned as an array of bytes
733 * convert it back to cpu order */
734 val = be32_to_cpu(val);
735
736 rc = bnx2x_nvram_write_dword(bp, align_offset, val,
737 cmd_flags);
738 }
739
740 /* disable access to nvram interface */
741 bnx2x_disable_nvram_access(bp);
742 bnx2x_release_nvram_lock(bp);
743
744 return rc;
745}
746
747static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
748 int buf_size)
749{
750 int rc;
751 u32 cmd_flags;
752 u32 val;
753 u32 written_so_far;
754
755 if (buf_size == 1) /* ethtool */
756 return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
757
758 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
759 DP(BNX2X_MSG_NVM,
760 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
761 offset, buf_size);
762 return -EINVAL;
763 }
764
765 if (offset + buf_size > bp->common.flash_size) {
766 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
767 " buf_size (0x%x) > flash_size (0x%x)\n",
768 offset, buf_size, bp->common.flash_size);
769 return -EINVAL;
770 }
771
772 /* request access to nvram interface */
773 rc = bnx2x_acquire_nvram_lock(bp);
774 if (rc)
775 return rc;
776
777 /* enable access to nvram interface */
778 bnx2x_enable_nvram_access(bp);
779
780 written_so_far = 0;
781 cmd_flags = MCPR_NVM_COMMAND_FIRST;
782 while ((written_so_far < buf_size) && (rc == 0)) {
783 if (written_so_far == (buf_size - sizeof(u32)))
784 cmd_flags |= MCPR_NVM_COMMAND_LAST;
785 else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
786 cmd_flags |= MCPR_NVM_COMMAND_LAST;
787 else if ((offset % NVRAM_PAGE_SIZE) == 0)
788 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
789
790 memcpy(&val, data_buf, 4);
791
792 rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
793
794 /* advance to the next dword */
795 offset += sizeof(u32);
796 data_buf += sizeof(u32);
797 written_so_far += sizeof(u32);
798 cmd_flags = 0;
799 }
800
801 /* disable access to nvram interface */
802 bnx2x_disable_nvram_access(bp);
803 bnx2x_release_nvram_lock(bp);
804
805 return rc;
806}
807
808static int bnx2x_set_eeprom(struct net_device *dev,
809 struct ethtool_eeprom *eeprom, u8 *eebuf)
810{
811 struct bnx2x *bp = netdev_priv(dev);
812 int port = BP_PORT(bp);
813 int rc = 0;
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000814 u32 ext_phy_config;
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000815 if (!netif_running(dev))
816 return -EAGAIN;
817
818 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
819 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
820 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
821 eeprom->len, eeprom->len);
822
823 /* parameters already validated in ethtool_set_eeprom */
824
825 /* PHY eeprom can be accessed only by the PMF */
826 if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
827 !bp->port.pmf)
828 return -EINVAL;
829
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000830 ext_phy_config =
831 SHMEM_RD(bp,
832 dev_info.port_hw_config[port].external_phy_config);
833
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000834 if (eeprom->magic == 0x50485950) {
835 /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
836 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
837
838 bnx2x_acquire_phy_lock(bp);
839 rc |= bnx2x_link_reset(&bp->link_params,
840 &bp->link_vars, 0);
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000841 if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000842 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
843 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
844 MISC_REGISTERS_GPIO_HIGH, port);
845 bnx2x_release_phy_lock(bp);
846 bnx2x_link_report(bp);
847
848 } else if (eeprom->magic == 0x50485952) {
849 /* 'PHYR' (0x50485952): re-init link after FW upgrade */
850 if (bp->state == BNX2X_STATE_OPEN) {
851 bnx2x_acquire_phy_lock(bp);
852 rc |= bnx2x_link_reset(&bp->link_params,
853 &bp->link_vars, 1);
854
855 rc |= bnx2x_phy_init(&bp->link_params,
856 &bp->link_vars);
857 bnx2x_release_phy_lock(bp);
858 bnx2x_calc_fc_adv(bp);
859 }
860 } else if (eeprom->magic == 0x53985943) {
861 /* 'PHYC' (0x53985943): PHY FW upgrade completed */
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000862 if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000863 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000864
865 /* DSP Remove Download Mode */
866 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
867 MISC_REGISTERS_GPIO_LOW, port);
868
869 bnx2x_acquire_phy_lock(bp);
870
Yaniv Rosnere10bc842010-09-07 11:40:50 +0000871 bnx2x_sfx7101_sp_sw_reset(bp,
872 &bp->link_params.phy[EXT_PHY1]);
Dmitry Kravkovde0c62d2010-07-27 12:35:24 +0000873
874 /* wait 0.5 sec to allow it to run */
875 msleep(500);
876 bnx2x_ext_phy_hw_reset(bp, port);
877 msleep(500);
878 bnx2x_release_phy_lock(bp);
879 }
880 } else
881 rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
882
883 return rc;
884}
885static int bnx2x_get_coalesce(struct net_device *dev,
886 struct ethtool_coalesce *coal)
887{
888 struct bnx2x *bp = netdev_priv(dev);
889
890 memset(coal, 0, sizeof(struct ethtool_coalesce));
891
892 coal->rx_coalesce_usecs = bp->rx_ticks;
893 coal->tx_coalesce_usecs = bp->tx_ticks;
894
895 return 0;
896}
897
898static int bnx2x_set_coalesce(struct net_device *dev,
899 struct ethtool_coalesce *coal)
900{
901 struct bnx2x *bp = netdev_priv(dev);
902
903 bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
904 if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
905 bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
906
907 bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
908 if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
909 bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
910
911 if (netif_running(dev))
912 bnx2x_update_coalesce(bp);
913
914 return 0;
915}
916
917static void bnx2x_get_ringparam(struct net_device *dev,
918 struct ethtool_ringparam *ering)
919{
920 struct bnx2x *bp = netdev_priv(dev);
921
922 ering->rx_max_pending = MAX_RX_AVAIL;
923 ering->rx_mini_max_pending = 0;
924 ering->rx_jumbo_max_pending = 0;
925
926 ering->rx_pending = bp->rx_ring_size;
927 ering->rx_mini_pending = 0;
928 ering->rx_jumbo_pending = 0;
929
930 ering->tx_max_pending = MAX_TX_AVAIL;
931 ering->tx_pending = bp->tx_ring_size;
932}
933
934static int bnx2x_set_ringparam(struct net_device *dev,
935 struct ethtool_ringparam *ering)
936{
937 struct bnx2x *bp = netdev_priv(dev);
938 int rc = 0;
939
940 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
941 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
942 return -EAGAIN;
943 }
944
945 if ((ering->rx_pending > MAX_RX_AVAIL) ||
946 (ering->tx_pending > MAX_TX_AVAIL) ||
947 (ering->tx_pending <= MAX_SKB_FRAGS + 4))
948 return -EINVAL;
949
950 bp->rx_ring_size = ering->rx_pending;
951 bp->tx_ring_size = ering->tx_pending;
952
953 if (netif_running(dev)) {
954 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
955 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
956 }
957
958 return rc;
959}
960
961static void bnx2x_get_pauseparam(struct net_device *dev,
962 struct ethtool_pauseparam *epause)
963{
964 struct bnx2x *bp = netdev_priv(dev);
965
966 epause->autoneg = (bp->link_params.req_flow_ctrl ==
967 BNX2X_FLOW_CTRL_AUTO) &&
968 (bp->link_params.req_line_speed == SPEED_AUTO_NEG);
969
970 epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
971 BNX2X_FLOW_CTRL_RX);
972 epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
973 BNX2X_FLOW_CTRL_TX);
974
975 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
976 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
977 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
978}
979
980static int bnx2x_set_pauseparam(struct net_device *dev,
981 struct ethtool_pauseparam *epause)
982{
983 struct bnx2x *bp = netdev_priv(dev);
984
985 if (IS_E1HMF(bp))
986 return 0;
987
988 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
989 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
990 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
991
992 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
993
994 if (epause->rx_pause)
995 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX;
996
997 if (epause->tx_pause)
998 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX;
999
1000 if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
1001 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
1002
1003 if (epause->autoneg) {
1004 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
1005 DP(NETIF_MSG_LINK, "autoneg not supported\n");
1006 return -EINVAL;
1007 }
1008
1009 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
1010 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
1011 }
1012
1013 DP(NETIF_MSG_LINK,
1014 "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl);
1015
1016 if (netif_running(dev)) {
1017 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
1018 bnx2x_link_set(bp);
1019 }
1020
1021 return 0;
1022}
1023
1024static int bnx2x_set_flags(struct net_device *dev, u32 data)
1025{
1026 struct bnx2x *bp = netdev_priv(dev);
1027 int changed = 0;
1028 int rc = 0;
1029
1030 if (data & ~(ETH_FLAG_LRO | ETH_FLAG_RXHASH))
1031 return -EINVAL;
1032
1033 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1034 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
1035 return -EAGAIN;
1036 }
1037
1038 /* TPA requires Rx CSUM offloading */
1039 if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
1040 if (!bp->disable_tpa) {
1041 if (!(dev->features & NETIF_F_LRO)) {
1042 dev->features |= NETIF_F_LRO;
1043 bp->flags |= TPA_ENABLE_FLAG;
1044 changed = 1;
1045 }
1046 } else
1047 rc = -EINVAL;
1048 } else if (dev->features & NETIF_F_LRO) {
1049 dev->features &= ~NETIF_F_LRO;
1050 bp->flags &= ~TPA_ENABLE_FLAG;
1051 changed = 1;
1052 }
1053
1054 if (data & ETH_FLAG_RXHASH)
1055 dev->features |= NETIF_F_RXHASH;
1056 else
1057 dev->features &= ~NETIF_F_RXHASH;
1058
1059 if (changed && netif_running(dev)) {
1060 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
1061 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
1062 }
1063
1064 return rc;
1065}
1066
1067static u32 bnx2x_get_rx_csum(struct net_device *dev)
1068{
1069 struct bnx2x *bp = netdev_priv(dev);
1070
1071 return bp->rx_csum;
1072}
1073
1074static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
1075{
1076 struct bnx2x *bp = netdev_priv(dev);
1077 int rc = 0;
1078
1079 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1080 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
1081 return -EAGAIN;
1082 }
1083
1084 bp->rx_csum = data;
1085
1086 /* Disable TPA, when Rx CSUM is disabled. Otherwise all
1087 TPA'ed packets will be discarded due to wrong TCP CSUM */
1088 if (!data) {
1089 u32 flags = ethtool_op_get_flags(dev);
1090
1091 rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
1092 }
1093
1094 return rc;
1095}
1096
1097static int bnx2x_set_tso(struct net_device *dev, u32 data)
1098{
1099 if (data) {
1100 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
1101 dev->features |= NETIF_F_TSO6;
1102 } else {
1103 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
1104 dev->features &= ~NETIF_F_TSO6;
1105 }
1106
1107 return 0;
1108}
1109
1110static const struct {
1111 char string[ETH_GSTRING_LEN];
1112} bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
1113 { "register_test (offline)" },
1114 { "memory_test (offline)" },
1115 { "loopback_test (offline)" },
1116 { "nvram_test (online)" },
1117 { "interrupt_test (online)" },
1118 { "link_test (online)" },
1119 { "idle check (online)" }
1120};
1121
1122static int bnx2x_test_registers(struct bnx2x *bp)
1123{
1124 int idx, i, rc = -ENODEV;
1125 u32 wr_val = 0;
1126 int port = BP_PORT(bp);
1127 static const struct {
1128 u32 offset0;
1129 u32 offset1;
1130 u32 mask;
1131 } reg_tbl[] = {
1132/* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
1133 { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
1134 { HC_REG_AGG_INT_0, 4, 0x000003ff },
1135 { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
1136 { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
1137 { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
1138 { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
1139 { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
1140 { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
1141 { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
1142/* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
1143 { QM_REG_CONNNUM_0, 4, 0x000fffff },
1144 { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
1145 { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
1146 { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
1147 { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
1148 { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
1149 { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
1150 { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
1151 { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
1152/* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
1153 { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
1154 { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
1155 { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
1156 { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
1157 { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
1158 { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
1159 { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
1160 { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
1161 { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
1162/* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
1163 { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
1164 { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
1165 { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
1166 { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
1167 { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
1168 { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
1169
1170 { 0xffffffff, 0, 0x00000000 }
1171 };
1172
1173 if (!netif_running(bp->dev))
1174 return rc;
1175
1176 /* Repeat the test twice:
1177 First by writing 0x00000000, second by writing 0xffffffff */
1178 for (idx = 0; idx < 2; idx++) {
1179
1180 switch (idx) {
1181 case 0:
1182 wr_val = 0;
1183 break;
1184 case 1:
1185 wr_val = 0xffffffff;
1186 break;
1187 }
1188
1189 for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
1190 u32 offset, mask, save_val, val;
1191
1192 offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
1193 mask = reg_tbl[i].mask;
1194
1195 save_val = REG_RD(bp, offset);
1196
1197 REG_WR(bp, offset, (wr_val & mask));
1198 val = REG_RD(bp, offset);
1199
1200 /* Restore the original register's value */
1201 REG_WR(bp, offset, save_val);
1202
1203 /* verify value is as expected */
1204 if ((val & mask) != (wr_val & mask)) {
1205 DP(NETIF_MSG_PROBE,
1206 "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
1207 offset, val, wr_val, mask);
1208 goto test_reg_exit;
1209 }
1210 }
1211 }
1212
1213 rc = 0;
1214
1215test_reg_exit:
1216 return rc;
1217}
1218
1219static int bnx2x_test_memory(struct bnx2x *bp)
1220{
1221 int i, j, rc = -ENODEV;
1222 u32 val;
1223 static const struct {
1224 u32 offset;
1225 int size;
1226 } mem_tbl[] = {
1227 { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
1228 { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
1229 { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
1230 { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
1231 { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
1232 { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
1233 { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
1234
1235 { 0xffffffff, 0 }
1236 };
1237 static const struct {
1238 char *name;
1239 u32 offset;
1240 u32 e1_mask;
1241 u32 e1h_mask;
1242 } prty_tbl[] = {
1243 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
1244 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
1245 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
1246 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
1247 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
1248 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
1249
1250 { NULL, 0xffffffff, 0, 0 }
1251 };
1252
1253 if (!netif_running(bp->dev))
1254 return rc;
1255
1256 /* Go through all the memories */
1257 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
1258 for (j = 0; j < mem_tbl[i].size; j++)
1259 REG_RD(bp, mem_tbl[i].offset + j*4);
1260
1261 /* Check the parity status */
1262 for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
1263 val = REG_RD(bp, prty_tbl[i].offset);
1264 if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
1265 (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
1266 DP(NETIF_MSG_HW,
1267 "%s is 0x%x\n", prty_tbl[i].name, val);
1268 goto test_mem_exit;
1269 }
1270 }
1271
1272 rc = 0;
1273
1274test_mem_exit:
1275 return rc;
1276}
1277
1278static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up)
1279{
1280 int cnt = 1000;
1281
1282 if (link_up)
1283 while (bnx2x_link_test(bp) && cnt--)
1284 msleep(10);
1285}
1286
1287static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
1288{
1289 unsigned int pkt_size, num_pkts, i;
1290 struct sk_buff *skb;
1291 unsigned char *packet;
1292 struct bnx2x_fastpath *fp_rx = &bp->fp[0];
1293 struct bnx2x_fastpath *fp_tx = &bp->fp[0];
1294 u16 tx_start_idx, tx_idx;
1295 u16 rx_start_idx, rx_idx;
1296 u16 pkt_prod, bd_prod;
1297 struct sw_tx_bd *tx_buf;
1298 struct eth_tx_start_bd *tx_start_bd;
1299 struct eth_tx_parse_bd *pbd = NULL;
1300 dma_addr_t mapping;
1301 union eth_rx_cqe *cqe;
1302 u8 cqe_fp_flags;
1303 struct sw_rx_bd *rx_buf;
1304 u16 len;
1305 int rc = -ENODEV;
1306
1307 /* check the loopback mode */
1308 switch (loopback_mode) {
1309 case BNX2X_PHY_LOOPBACK:
1310 if (bp->link_params.loopback_mode != LOOPBACK_XGXS_10)
1311 return -EINVAL;
1312 break;
1313 case BNX2X_MAC_LOOPBACK:
1314 bp->link_params.loopback_mode = LOOPBACK_BMAC;
1315 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
1316 break;
1317 default:
1318 return -EINVAL;
1319 }
1320
1321 /* prepare the loopback packet */
1322 pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
1323 bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
1324 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1325 if (!skb) {
1326 rc = -ENOMEM;
1327 goto test_loopback_exit;
1328 }
1329 packet = skb_put(skb, pkt_size);
1330 memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
1331 memset(packet + ETH_ALEN, 0, ETH_ALEN);
1332 memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
1333 for (i = ETH_HLEN; i < pkt_size; i++)
1334 packet[i] = (unsigned char) (i & 0xff);
1335
1336 /* send the loopback packet */
1337 num_pkts = 0;
1338 tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
1339 rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
1340
1341 pkt_prod = fp_tx->tx_pkt_prod++;
1342 tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)];
1343 tx_buf->first_bd = fp_tx->tx_bd_prod;
1344 tx_buf->skb = skb;
1345 tx_buf->flags = 0;
1346
1347 bd_prod = TX_BD(fp_tx->tx_bd_prod);
1348 tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd;
1349 mapping = dma_map_single(&bp->pdev->dev, skb->data,
1350 skb_headlen(skb), DMA_TO_DEVICE);
1351 tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1352 tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1353 tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
1354 tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
1355 tx_start_bd->vlan = cpu_to_le16(pkt_prod);
1356 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
1357 tx_start_bd->general_data = ((UNICAST_ADDRESS <<
1358 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT) | 1);
1359
1360 /* turn on parsing and get a BD */
1361 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
1362 pbd = &fp_tx->tx_desc_ring[bd_prod].parse_bd;
1363
1364 memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
1365
1366 wmb();
1367
1368 fp_tx->tx_db.data.prod += 2;
1369 barrier();
1370 DOORBELL(bp, fp_tx->index, fp_tx->tx_db.raw);
1371
1372 mmiowb();
1373
1374 num_pkts++;
1375 fp_tx->tx_bd_prod += 2; /* start + pbd */
1376
1377 udelay(100);
1378
1379 tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
1380 if (tx_idx != tx_start_idx + num_pkts)
1381 goto test_loopback_exit;
1382
1383 rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
1384 if (rx_idx != rx_start_idx + num_pkts)
1385 goto test_loopback_exit;
1386
1387 cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
1388 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
1389 if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
1390 goto test_loopback_rx_exit;
1391
1392 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
1393 if (len != pkt_size)
1394 goto test_loopback_rx_exit;
1395
1396 rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
1397 skb = rx_buf->skb;
1398 skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
1399 for (i = ETH_HLEN; i < pkt_size; i++)
1400 if (*(skb->data + i) != (unsigned char) (i & 0xff))
1401 goto test_loopback_rx_exit;
1402
1403 rc = 0;
1404
1405test_loopback_rx_exit:
1406
1407 fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
1408 fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
1409 fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
1410 fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
1411
1412 /* Update producers */
1413 bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
1414 fp_rx->rx_sge_prod);
1415
1416test_loopback_exit:
1417 bp->link_params.loopback_mode = LOOPBACK_NONE;
1418
1419 return rc;
1420}
1421
1422static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
1423{
1424 int rc = 0, res;
1425
1426 if (BP_NOMCP(bp))
1427 return rc;
1428
1429 if (!netif_running(bp->dev))
1430 return BNX2X_LOOPBACK_FAILED;
1431
1432 bnx2x_netif_stop(bp, 1);
1433 bnx2x_acquire_phy_lock(bp);
1434
1435 res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
1436 if (res) {
1437 DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
1438 rc |= BNX2X_PHY_LOOPBACK_FAILED;
1439 }
1440
1441 res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
1442 if (res) {
1443 DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
1444 rc |= BNX2X_MAC_LOOPBACK_FAILED;
1445 }
1446
1447 bnx2x_release_phy_lock(bp);
1448 bnx2x_netif_start(bp);
1449
1450 return rc;
1451}
1452
1453#define CRC32_RESIDUAL 0xdebb20e3
1454
1455static int bnx2x_test_nvram(struct bnx2x *bp)
1456{
1457 static const struct {
1458 int offset;
1459 int size;
1460 } nvram_tbl[] = {
1461 { 0, 0x14 }, /* bootstrap */
1462 { 0x14, 0xec }, /* dir */
1463 { 0x100, 0x350 }, /* manuf_info */
1464 { 0x450, 0xf0 }, /* feature_info */
1465 { 0x640, 0x64 }, /* upgrade_key_info */
1466 { 0x6a4, 0x64 },
1467 { 0x708, 0x70 }, /* manuf_key_info */
1468 { 0x778, 0x70 },
1469 { 0, 0 }
1470 };
1471 __be32 buf[0x350 / 4];
1472 u8 *data = (u8 *)buf;
1473 int i, rc;
1474 u32 magic, crc;
1475
1476 if (BP_NOMCP(bp))
1477 return 0;
1478
1479 rc = bnx2x_nvram_read(bp, 0, data, 4);
1480 if (rc) {
1481 DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
1482 goto test_nvram_exit;
1483 }
1484
1485 magic = be32_to_cpu(buf[0]);
1486 if (magic != 0x669955aa) {
1487 DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
1488 rc = -ENODEV;
1489 goto test_nvram_exit;
1490 }
1491
1492 for (i = 0; nvram_tbl[i].size; i++) {
1493
1494 rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
1495 nvram_tbl[i].size);
1496 if (rc) {
1497 DP(NETIF_MSG_PROBE,
1498 "nvram_tbl[%d] read data (rc %d)\n", i, rc);
1499 goto test_nvram_exit;
1500 }
1501
1502 crc = ether_crc_le(nvram_tbl[i].size, data);
1503 if (crc != CRC32_RESIDUAL) {
1504 DP(NETIF_MSG_PROBE,
1505 "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
1506 rc = -ENODEV;
1507 goto test_nvram_exit;
1508 }
1509 }
1510
1511test_nvram_exit:
1512 return rc;
1513}
1514
1515static int bnx2x_test_intr(struct bnx2x *bp)
1516{
1517 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
1518 int i, rc;
1519
1520 if (!netif_running(bp->dev))
1521 return -ENODEV;
1522
1523 config->hdr.length = 0;
1524 if (CHIP_IS_E1(bp))
1525 /* use last unicast entries */
1526 config->hdr.offset = (BP_PORT(bp) ? 63 : 31);
1527 else
1528 config->hdr.offset = BP_FUNC(bp);
1529 config->hdr.client_id = bp->fp->cl_id;
1530 config->hdr.reserved1 = 0;
1531
1532 bp->set_mac_pending++;
1533 smp_wmb();
1534 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
1535 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
1536 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
1537 if (rc == 0) {
1538 for (i = 0; i < 10; i++) {
1539 if (!bp->set_mac_pending)
1540 break;
1541 smp_rmb();
1542 msleep_interruptible(10);
1543 }
1544 if (i == 10)
1545 rc = -ENODEV;
1546 }
1547
1548 return rc;
1549}
1550
1551static void bnx2x_self_test(struct net_device *dev,
1552 struct ethtool_test *etest, u64 *buf)
1553{
1554 struct bnx2x *bp = netdev_priv(dev);
1555
1556 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1557 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
1558 etest->flags |= ETH_TEST_FL_FAILED;
1559 return;
1560 }
1561
1562 memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
1563
1564 if (!netif_running(dev))
1565 return;
1566
1567 /* offline tests are not supported in MF mode */
1568 if (IS_E1HMF(bp))
1569 etest->flags &= ~ETH_TEST_FL_OFFLINE;
1570
1571 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1572 int port = BP_PORT(bp);
1573 u32 val;
1574 u8 link_up;
1575
1576 /* save current value of input enable for TX port IF */
1577 val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
1578 /* disable input for TX port IF */
1579 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
1580
1581 link_up = (bnx2x_link_test(bp) == 0);
1582 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
1583 bnx2x_nic_load(bp, LOAD_DIAG);
1584 /* wait until link state is restored */
1585 bnx2x_wait_for_link(bp, link_up);
1586
1587 if (bnx2x_test_registers(bp) != 0) {
1588 buf[0] = 1;
1589 etest->flags |= ETH_TEST_FL_FAILED;
1590 }
1591 if (bnx2x_test_memory(bp) != 0) {
1592 buf[1] = 1;
1593 etest->flags |= ETH_TEST_FL_FAILED;
1594 }
1595 buf[2] = bnx2x_test_loopback(bp, link_up);
1596 if (buf[2] != 0)
1597 etest->flags |= ETH_TEST_FL_FAILED;
1598
1599 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
1600
1601 /* restore input for TX port IF */
1602 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
1603
1604 bnx2x_nic_load(bp, LOAD_NORMAL);
1605 /* wait until link state is restored */
1606 bnx2x_wait_for_link(bp, link_up);
1607 }
1608 if (bnx2x_test_nvram(bp) != 0) {
1609 buf[3] = 1;
1610 etest->flags |= ETH_TEST_FL_FAILED;
1611 }
1612 if (bnx2x_test_intr(bp) != 0) {
1613 buf[4] = 1;
1614 etest->flags |= ETH_TEST_FL_FAILED;
1615 }
1616 if (bp->port.pmf)
1617 if (bnx2x_link_test(bp) != 0) {
1618 buf[5] = 1;
1619 etest->flags |= ETH_TEST_FL_FAILED;
1620 }
1621
1622#ifdef BNX2X_EXTRA_DEBUG
1623 bnx2x_panic_dump(bp);
1624#endif
1625}
1626
1627static const struct {
1628 long offset;
1629 int size;
1630 u8 string[ETH_GSTRING_LEN];
1631} bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
1632/* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
1633 { Q_STATS_OFFSET32(error_bytes_received_hi),
1634 8, "[%d]: rx_error_bytes" },
1635 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
1636 8, "[%d]: rx_ucast_packets" },
1637 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
1638 8, "[%d]: rx_mcast_packets" },
1639 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
1640 8, "[%d]: rx_bcast_packets" },
1641 { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
1642 { Q_STATS_OFFSET32(rx_err_discard_pkt),
1643 4, "[%d]: rx_phy_ip_err_discards"},
1644 { Q_STATS_OFFSET32(rx_skb_alloc_failed),
1645 4, "[%d]: rx_skb_alloc_discard" },
1646 { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
1647
1648/* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
1649 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
1650 8, "[%d]: tx_ucast_packets" },
1651 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
1652 8, "[%d]: tx_mcast_packets" },
1653 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
1654 8, "[%d]: tx_bcast_packets" }
1655};
1656
1657static const struct {
1658 long offset;
1659 int size;
1660 u32 flags;
1661#define STATS_FLAGS_PORT 1
1662#define STATS_FLAGS_FUNC 2
1663#define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
1664 u8 string[ETH_GSTRING_LEN];
1665} bnx2x_stats_arr[BNX2X_NUM_STATS] = {
1666/* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
1667 8, STATS_FLAGS_BOTH, "rx_bytes" },
1668 { STATS_OFFSET32(error_bytes_received_hi),
1669 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
1670 { STATS_OFFSET32(total_unicast_packets_received_hi),
1671 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
1672 { STATS_OFFSET32(total_multicast_packets_received_hi),
1673 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
1674 { STATS_OFFSET32(total_broadcast_packets_received_hi),
1675 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
1676 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
1677 8, STATS_FLAGS_PORT, "rx_crc_errors" },
1678 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
1679 8, STATS_FLAGS_PORT, "rx_align_errors" },
1680 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
1681 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
1682 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
1683 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
1684/* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
1685 8, STATS_FLAGS_PORT, "rx_fragments" },
1686 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
1687 8, STATS_FLAGS_PORT, "rx_jabbers" },
1688 { STATS_OFFSET32(no_buff_discard_hi),
1689 8, STATS_FLAGS_BOTH, "rx_discards" },
1690 { STATS_OFFSET32(mac_filter_discard),
1691 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
1692 { STATS_OFFSET32(xxoverflow_discard),
1693 4, STATS_FLAGS_PORT, "rx_fw_discards" },
1694 { STATS_OFFSET32(brb_drop_hi),
1695 8, STATS_FLAGS_PORT, "rx_brb_discard" },
1696 { STATS_OFFSET32(brb_truncate_hi),
1697 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
1698 { STATS_OFFSET32(pause_frames_received_hi),
1699 8, STATS_FLAGS_PORT, "rx_pause_frames" },
1700 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
1701 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
1702 { STATS_OFFSET32(nig_timer_max),
1703 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
1704/* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
1705 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
1706 { STATS_OFFSET32(rx_skb_alloc_failed),
1707 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
1708 { STATS_OFFSET32(hw_csum_err),
1709 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
1710
1711 { STATS_OFFSET32(total_bytes_transmitted_hi),
1712 8, STATS_FLAGS_BOTH, "tx_bytes" },
1713 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
1714 8, STATS_FLAGS_PORT, "tx_error_bytes" },
1715 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
1716 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
1717 { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
1718 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
1719 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
1720 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
1721 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
1722 8, STATS_FLAGS_PORT, "tx_mac_errors" },
1723 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
1724 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
1725/* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
1726 8, STATS_FLAGS_PORT, "tx_single_collisions" },
1727 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
1728 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
1729 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
1730 8, STATS_FLAGS_PORT, "tx_deferred" },
1731 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
1732 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
1733 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
1734 8, STATS_FLAGS_PORT, "tx_late_collisions" },
1735 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
1736 8, STATS_FLAGS_PORT, "tx_total_collisions" },
1737 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
1738 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
1739 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
1740 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
1741 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
1742 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
1743 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
1744 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
1745/* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
1746 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
1747 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
1748 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
1749 { STATS_OFFSET32(etherstatspktsover1522octets_hi),
1750 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
1751 { STATS_OFFSET32(pause_frames_sent_hi),
1752 8, STATS_FLAGS_PORT, "tx_pause_frames" }
1753};
1754
1755#define IS_PORT_STAT(i) \
1756 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
1757#define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
1758#define IS_E1HMF_MODE_STAT(bp) \
1759 (IS_E1HMF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
1760
1761static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
1762{
1763 struct bnx2x *bp = netdev_priv(dev);
1764 int i, num_stats;
1765
1766 switch (stringset) {
1767 case ETH_SS_STATS:
1768 if (is_multi(bp)) {
1769 num_stats = BNX2X_NUM_Q_STATS * bp->num_queues;
1770 if (!IS_E1HMF_MODE_STAT(bp))
1771 num_stats += BNX2X_NUM_STATS;
1772 } else {
1773 if (IS_E1HMF_MODE_STAT(bp)) {
1774 num_stats = 0;
1775 for (i = 0; i < BNX2X_NUM_STATS; i++)
1776 if (IS_FUNC_STAT(i))
1777 num_stats++;
1778 } else
1779 num_stats = BNX2X_NUM_STATS;
1780 }
1781 return num_stats;
1782
1783 case ETH_SS_TEST:
1784 return BNX2X_NUM_TESTS;
1785
1786 default:
1787 return -EINVAL;
1788 }
1789}
1790
1791static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
1792{
1793 struct bnx2x *bp = netdev_priv(dev);
1794 int i, j, k;
1795
1796 switch (stringset) {
1797 case ETH_SS_STATS:
1798 if (is_multi(bp)) {
1799 k = 0;
1800 for_each_queue(bp, i) {
1801 for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
1802 sprintf(buf + (k + j)*ETH_GSTRING_LEN,
1803 bnx2x_q_stats_arr[j].string, i);
1804 k += BNX2X_NUM_Q_STATS;
1805 }
1806 if (IS_E1HMF_MODE_STAT(bp))
1807 break;
1808 for (j = 0; j < BNX2X_NUM_STATS; j++)
1809 strcpy(buf + (k + j)*ETH_GSTRING_LEN,
1810 bnx2x_stats_arr[j].string);
1811 } else {
1812 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
1813 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
1814 continue;
1815 strcpy(buf + j*ETH_GSTRING_LEN,
1816 bnx2x_stats_arr[i].string);
1817 j++;
1818 }
1819 }
1820 break;
1821
1822 case ETH_SS_TEST:
1823 memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
1824 break;
1825 }
1826}
1827
1828static void bnx2x_get_ethtool_stats(struct net_device *dev,
1829 struct ethtool_stats *stats, u64 *buf)
1830{
1831 struct bnx2x *bp = netdev_priv(dev);
1832 u32 *hw_stats, *offset;
1833 int i, j, k;
1834
1835 if (is_multi(bp)) {
1836 k = 0;
1837 for_each_queue(bp, i) {
1838 hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
1839 for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
1840 if (bnx2x_q_stats_arr[j].size == 0) {
1841 /* skip this counter */
1842 buf[k + j] = 0;
1843 continue;
1844 }
1845 offset = (hw_stats +
1846 bnx2x_q_stats_arr[j].offset);
1847 if (bnx2x_q_stats_arr[j].size == 4) {
1848 /* 4-byte counter */
1849 buf[k + j] = (u64) *offset;
1850 continue;
1851 }
1852 /* 8-byte counter */
1853 buf[k + j] = HILO_U64(*offset, *(offset + 1));
1854 }
1855 k += BNX2X_NUM_Q_STATS;
1856 }
1857 if (IS_E1HMF_MODE_STAT(bp))
1858 return;
1859 hw_stats = (u32 *)&bp->eth_stats;
1860 for (j = 0; j < BNX2X_NUM_STATS; j++) {
1861 if (bnx2x_stats_arr[j].size == 0) {
1862 /* skip this counter */
1863 buf[k + j] = 0;
1864 continue;
1865 }
1866 offset = (hw_stats + bnx2x_stats_arr[j].offset);
1867 if (bnx2x_stats_arr[j].size == 4) {
1868 /* 4-byte counter */
1869 buf[k + j] = (u64) *offset;
1870 continue;
1871 }
1872 /* 8-byte counter */
1873 buf[k + j] = HILO_U64(*offset, *(offset + 1));
1874 }
1875 } else {
1876 hw_stats = (u32 *)&bp->eth_stats;
1877 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
1878 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
1879 continue;
1880 if (bnx2x_stats_arr[i].size == 0) {
1881 /* skip this counter */
1882 buf[j] = 0;
1883 j++;
1884 continue;
1885 }
1886 offset = (hw_stats + bnx2x_stats_arr[i].offset);
1887 if (bnx2x_stats_arr[i].size == 4) {
1888 /* 4-byte counter */
1889 buf[j] = (u64) *offset;
1890 j++;
1891 continue;
1892 }
1893 /* 8-byte counter */
1894 buf[j] = HILO_U64(*offset, *(offset + 1));
1895 j++;
1896 }
1897 }
1898}
1899
1900static int bnx2x_phys_id(struct net_device *dev, u32 data)
1901{
1902 struct bnx2x *bp = netdev_priv(dev);
1903 int i;
1904
1905 if (!netif_running(dev))
1906 return 0;
1907
1908 if (!bp->port.pmf)
1909 return 0;
1910
1911 if (data == 0)
1912 data = 2;
1913
1914 for (i = 0; i < (data * 2); i++) {
1915 if ((i % 2) == 0)
1916 bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
1917 SPEED_1000);
1918 else
1919 bnx2x_set_led(&bp->link_params, LED_MODE_OFF, 0);
1920
1921 msleep_interruptible(500);
1922 if (signal_pending(current))
1923 break;
1924 }
1925
1926 if (bp->link_vars.link_up)
1927 bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
1928 bp->link_vars.line_speed);
1929
1930 return 0;
1931}
1932
1933static const struct ethtool_ops bnx2x_ethtool_ops = {
1934 .get_settings = bnx2x_get_settings,
1935 .set_settings = bnx2x_set_settings,
1936 .get_drvinfo = bnx2x_get_drvinfo,
1937 .get_regs_len = bnx2x_get_regs_len,
1938 .get_regs = bnx2x_get_regs,
1939 .get_wol = bnx2x_get_wol,
1940 .set_wol = bnx2x_set_wol,
1941 .get_msglevel = bnx2x_get_msglevel,
1942 .set_msglevel = bnx2x_set_msglevel,
1943 .nway_reset = bnx2x_nway_reset,
1944 .get_link = bnx2x_get_link,
1945 .get_eeprom_len = bnx2x_get_eeprom_len,
1946 .get_eeprom = bnx2x_get_eeprom,
1947 .set_eeprom = bnx2x_set_eeprom,
1948 .get_coalesce = bnx2x_get_coalesce,
1949 .set_coalesce = bnx2x_set_coalesce,
1950 .get_ringparam = bnx2x_get_ringparam,
1951 .set_ringparam = bnx2x_set_ringparam,
1952 .get_pauseparam = bnx2x_get_pauseparam,
1953 .set_pauseparam = bnx2x_set_pauseparam,
1954 .get_rx_csum = bnx2x_get_rx_csum,
1955 .set_rx_csum = bnx2x_set_rx_csum,
1956 .get_tx_csum = ethtool_op_get_tx_csum,
1957 .set_tx_csum = ethtool_op_set_tx_hw_csum,
1958 .set_flags = bnx2x_set_flags,
1959 .get_flags = ethtool_op_get_flags,
1960 .get_sg = ethtool_op_get_sg,
1961 .set_sg = ethtool_op_set_sg,
1962 .get_tso = ethtool_op_get_tso,
1963 .set_tso = bnx2x_set_tso,
1964 .self_test = bnx2x_self_test,
1965 .get_sset_count = bnx2x_get_sset_count,
1966 .get_strings = bnx2x_get_strings,
1967 .phys_id = bnx2x_phys_id,
1968 .get_ethtool_stats = bnx2x_get_ethtool_stats,
1969};
1970
1971void bnx2x_set_ethtool_ops(struct net_device *netdev)
1972{
1973 SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);
1974}