1 /* bnx2x_ethtool.c: Broadcom Everest network driver.
3 * Copyright (c) 2007-2010 Broadcom Corporation
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.
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
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>
25 #include "bnx2x_cmn.h"
26 #include "bnx2x_dump.h"
29 static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
31 struct bnx2x *bp = netdev_priv(dev);
33 cmd->supported = bp->port.supported;
34 cmd->advertising = bp->port.advertising;
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;
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;
55 if (bp->link_params.num_phys > 0) {
56 if (bp->link_params.phy[bp->link_params.num_phys - 1].
57 supported & SUPPORTED_FIBRE)
58 cmd->port = PORT_FIBRE;
62 DP(NETIF_MSG_LINK, "No media found\n");
63 cmd->phy_address = bp->mdio.prtad;
64 cmd->transceiver = XCVR_INTERNAL;
66 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
67 cmd->autoneg = AUTONEG_ENABLE;
69 cmd->autoneg = AUTONEG_DISABLE;
74 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
75 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
76 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
77 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
78 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
79 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
80 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
85 static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
87 struct bnx2x *bp = netdev_priv(dev);
93 DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
94 DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
95 DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
96 DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
97 cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
98 cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
99 cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
101 if (cmd->autoneg == AUTONEG_ENABLE) {
102 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
103 DP(NETIF_MSG_LINK, "Autoneg not supported\n");
107 /* advertise the requested speed and duplex if supported */
108 cmd->advertising &= bp->port.supported;
110 bp->link_params.req_line_speed = SPEED_AUTO_NEG;
111 bp->link_params.req_duplex = DUPLEX_FULL;
112 bp->port.advertising |= (ADVERTISED_Autoneg |
115 } else { /* forced speed */
116 /* advertise the requested speed and duplex if supported */
117 switch (cmd->speed) {
119 if (cmd->duplex == DUPLEX_FULL) {
120 if (!(bp->port.supported &
121 SUPPORTED_10baseT_Full)) {
123 "10M full not supported\n");
127 advertising = (ADVERTISED_10baseT_Full |
130 if (!(bp->port.supported &
131 SUPPORTED_10baseT_Half)) {
133 "10M half not supported\n");
137 advertising = (ADVERTISED_10baseT_Half |
143 if (cmd->duplex == DUPLEX_FULL) {
144 if (!(bp->port.supported &
145 SUPPORTED_100baseT_Full)) {
147 "100M full not supported\n");
151 advertising = (ADVERTISED_100baseT_Full |
154 if (!(bp->port.supported &
155 SUPPORTED_100baseT_Half)) {
157 "100M half not supported\n");
161 advertising = (ADVERTISED_100baseT_Half |
167 if (cmd->duplex != DUPLEX_FULL) {
168 DP(NETIF_MSG_LINK, "1G half not supported\n");
172 if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) {
173 DP(NETIF_MSG_LINK, "1G full not supported\n");
177 advertising = (ADVERTISED_1000baseT_Full |
182 if (cmd->duplex != DUPLEX_FULL) {
184 "2.5G half not supported\n");
188 if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) {
190 "2.5G full not supported\n");
194 advertising = (ADVERTISED_2500baseX_Full |
199 if (cmd->duplex != DUPLEX_FULL) {
200 DP(NETIF_MSG_LINK, "10G half not supported\n");
204 if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) {
205 DP(NETIF_MSG_LINK, "10G full not supported\n");
209 advertising = (ADVERTISED_10000baseT_Full |
214 DP(NETIF_MSG_LINK, "Unsupported speed\n");
218 bp->link_params.req_line_speed = cmd->speed;
219 bp->link_params.req_duplex = cmd->duplex;
220 bp->port.advertising = advertising;
223 DP(NETIF_MSG_LINK, "req_line_speed %d\n"
224 DP_LEVEL " req_duplex %d advertising 0x%x\n",
225 bp->link_params.req_line_speed, bp->link_params.req_duplex,
226 bp->port.advertising);
228 if (netif_running(dev)) {
229 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
236 #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
237 #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
239 static int bnx2x_get_regs_len(struct net_device *dev)
241 struct bnx2x *bp = netdev_priv(dev);
245 if (CHIP_IS_E1(bp)) {
246 for (i = 0; i < REGS_COUNT; i++)
247 if (IS_E1_ONLINE(reg_addrs[i].info))
248 regdump_len += reg_addrs[i].size;
250 for (i = 0; i < WREGS_COUNT_E1; i++)
251 if (IS_E1_ONLINE(wreg_addrs_e1[i].info))
252 regdump_len += wreg_addrs_e1[i].size *
253 (1 + wreg_addrs_e1[i].read_regs_count);
256 for (i = 0; i < REGS_COUNT; i++)
257 if (IS_E1H_ONLINE(reg_addrs[i].info))
258 regdump_len += reg_addrs[i].size;
260 for (i = 0; i < WREGS_COUNT_E1H; i++)
261 if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info))
262 regdump_len += wreg_addrs_e1h[i].size *
263 (1 + wreg_addrs_e1h[i].read_regs_count);
266 regdump_len += sizeof(struct dump_hdr);
271 static void bnx2x_get_regs(struct net_device *dev,
272 struct ethtool_regs *regs, void *_p)
275 struct bnx2x *bp = netdev_priv(dev);
276 struct dump_hdr dump_hdr = {0};
279 memset(p, 0, regs->len);
281 if (!netif_running(bp->dev))
284 dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
285 dump_hdr.dump_sign = dump_sign_all;
286 dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
287 dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
288 dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
289 dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
290 dump_hdr.info = CHIP_IS_E1(bp) ? RI_E1_ONLINE : RI_E1H_ONLINE;
292 memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
293 p += dump_hdr.hdr_size + 1;
295 if (CHIP_IS_E1(bp)) {
296 for (i = 0; i < REGS_COUNT; i++)
297 if (IS_E1_ONLINE(reg_addrs[i].info))
298 for (j = 0; j < reg_addrs[i].size; j++)
300 reg_addrs[i].addr + j*4);
303 for (i = 0; i < REGS_COUNT; i++)
304 if (IS_E1H_ONLINE(reg_addrs[i].info))
305 for (j = 0; j < reg_addrs[i].size; j++)
307 reg_addrs[i].addr + j*4);
311 #define PHY_FW_VER_LEN 10
313 static void bnx2x_get_drvinfo(struct net_device *dev,
314 struct ethtool_drvinfo *info)
316 struct bnx2x *bp = netdev_priv(dev);
317 u8 phy_fw_ver[PHY_FW_VER_LEN];
319 strcpy(info->driver, DRV_MODULE_NAME);
320 strcpy(info->version, DRV_MODULE_VERSION);
322 phy_fw_ver[0] = '\0';
324 bnx2x_acquire_phy_lock(bp);
325 bnx2x_get_ext_phy_fw_version(&bp->link_params,
326 (bp->state != BNX2X_STATE_CLOSED),
327 phy_fw_ver, PHY_FW_VER_LEN);
328 bnx2x_release_phy_lock(bp);
331 strncpy(info->fw_version, bp->fw_ver, 32);
332 snprintf(info->fw_version + strlen(bp->fw_ver), 32 - strlen(bp->fw_ver),
334 (bp->common.bc_ver & 0xff0000) >> 16,
335 (bp->common.bc_ver & 0xff00) >> 8,
336 (bp->common.bc_ver & 0xff),
337 ((phy_fw_ver[0] != '\0') ? " phy " : ""), phy_fw_ver);
338 strcpy(info->bus_info, pci_name(bp->pdev));
339 info->n_stats = BNX2X_NUM_STATS;
340 info->testinfo_len = BNX2X_NUM_TESTS;
341 info->eedump_len = bp->common.flash_size;
342 info->regdump_len = bnx2x_get_regs_len(dev);
345 static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
347 struct bnx2x *bp = netdev_priv(dev);
349 if (bp->flags & NO_WOL_FLAG) {
353 wol->supported = WAKE_MAGIC;
355 wol->wolopts = WAKE_MAGIC;
359 memset(&wol->sopass, 0, sizeof(wol->sopass));
362 static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
364 struct bnx2x *bp = netdev_priv(dev);
366 if (wol->wolopts & ~WAKE_MAGIC)
369 if (wol->wolopts & WAKE_MAGIC) {
370 if (bp->flags & NO_WOL_FLAG)
380 static u32 bnx2x_get_msglevel(struct net_device *dev)
382 struct bnx2x *bp = netdev_priv(dev);
384 return bp->msg_enable;
387 static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
389 struct bnx2x *bp = netdev_priv(dev);
391 if (capable(CAP_NET_ADMIN))
392 bp->msg_enable = level;
395 static int bnx2x_nway_reset(struct net_device *dev)
397 struct bnx2x *bp = netdev_priv(dev);
402 if (netif_running(dev)) {
403 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
410 static u32 bnx2x_get_link(struct net_device *dev)
412 struct bnx2x *bp = netdev_priv(dev);
414 if (bp->flags & MF_FUNC_DIS)
417 return bp->link_vars.link_up;
420 static int bnx2x_get_eeprom_len(struct net_device *dev)
422 struct bnx2x *bp = netdev_priv(dev);
424 return bp->common.flash_size;
427 static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
429 int port = BP_PORT(bp);
433 /* adjust timeout for emulation/FPGA */
434 count = NVRAM_TIMEOUT_COUNT;
435 if (CHIP_REV_IS_SLOW(bp))
438 /* request access to nvram interface */
439 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
440 (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
442 for (i = 0; i < count*10; i++) {
443 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
444 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
450 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
451 DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
458 static int bnx2x_release_nvram_lock(struct bnx2x *bp)
460 int port = BP_PORT(bp);
464 /* adjust timeout for emulation/FPGA */
465 count = NVRAM_TIMEOUT_COUNT;
466 if (CHIP_REV_IS_SLOW(bp))
469 /* relinquish nvram interface */
470 REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
471 (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
473 for (i = 0; i < count*10; i++) {
474 val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
475 if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
481 if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
482 DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
489 static void bnx2x_enable_nvram_access(struct bnx2x *bp)
493 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
495 /* enable both bits, even on read */
496 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
497 (val | MCPR_NVM_ACCESS_ENABLE_EN |
498 MCPR_NVM_ACCESS_ENABLE_WR_EN));
501 static void bnx2x_disable_nvram_access(struct bnx2x *bp)
505 val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
507 /* disable both bits, even after read */
508 REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
509 (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
510 MCPR_NVM_ACCESS_ENABLE_WR_EN)));
513 static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
519 /* build the command word */
520 cmd_flags |= MCPR_NVM_COMMAND_DOIT;
522 /* need to clear DONE bit separately */
523 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
525 /* address of the NVRAM to read from */
526 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
527 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
529 /* issue a read command */
530 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
532 /* adjust timeout for emulation/FPGA */
533 count = NVRAM_TIMEOUT_COUNT;
534 if (CHIP_REV_IS_SLOW(bp))
537 /* wait for completion */
540 for (i = 0; i < count; i++) {
542 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
544 if (val & MCPR_NVM_COMMAND_DONE) {
545 val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
546 /* we read nvram data in cpu order
547 * but ethtool sees it as an array of bytes
548 * converting to big-endian will do the work */
549 *ret_val = cpu_to_be32(val);
558 static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
565 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
567 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
572 if (offset + buf_size > bp->common.flash_size) {
573 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
574 " buf_size (0x%x) > flash_size (0x%x)\n",
575 offset, buf_size, bp->common.flash_size);
579 /* request access to nvram interface */
580 rc = bnx2x_acquire_nvram_lock(bp);
584 /* enable access to nvram interface */
585 bnx2x_enable_nvram_access(bp);
587 /* read the first word(s) */
588 cmd_flags = MCPR_NVM_COMMAND_FIRST;
589 while ((buf_size > sizeof(u32)) && (rc == 0)) {
590 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
591 memcpy(ret_buf, &val, 4);
593 /* advance to the next dword */
594 offset += sizeof(u32);
595 ret_buf += sizeof(u32);
596 buf_size -= sizeof(u32);
601 cmd_flags |= MCPR_NVM_COMMAND_LAST;
602 rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
603 memcpy(ret_buf, &val, 4);
606 /* disable access to nvram interface */
607 bnx2x_disable_nvram_access(bp);
608 bnx2x_release_nvram_lock(bp);
613 static int bnx2x_get_eeprom(struct net_device *dev,
614 struct ethtool_eeprom *eeprom, u8 *eebuf)
616 struct bnx2x *bp = netdev_priv(dev);
619 if (!netif_running(dev))
622 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
623 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
624 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
625 eeprom->len, eeprom->len);
627 /* parameters already validated in ethtool_get_eeprom */
629 rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
634 static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
639 /* build the command word */
640 cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
642 /* need to clear DONE bit separately */
643 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
646 REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
648 /* address of the NVRAM to write to */
649 REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
650 (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
652 /* issue the write command */
653 REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
655 /* adjust timeout for emulation/FPGA */
656 count = NVRAM_TIMEOUT_COUNT;
657 if (CHIP_REV_IS_SLOW(bp))
660 /* wait for completion */
662 for (i = 0; i < count; i++) {
664 val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
665 if (val & MCPR_NVM_COMMAND_DONE) {
674 #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
676 static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
684 if (offset + buf_size > bp->common.flash_size) {
685 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
686 " buf_size (0x%x) > flash_size (0x%x)\n",
687 offset, buf_size, bp->common.flash_size);
691 /* request access to nvram interface */
692 rc = bnx2x_acquire_nvram_lock(bp);
696 /* enable access to nvram interface */
697 bnx2x_enable_nvram_access(bp);
699 cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
700 align_offset = (offset & ~0x03);
701 rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
704 val &= ~(0xff << BYTE_OFFSET(offset));
705 val |= (*data_buf << BYTE_OFFSET(offset));
707 /* nvram data is returned as an array of bytes
708 * convert it back to cpu order */
709 val = be32_to_cpu(val);
711 rc = bnx2x_nvram_write_dword(bp, align_offset, val,
715 /* disable access to nvram interface */
716 bnx2x_disable_nvram_access(bp);
717 bnx2x_release_nvram_lock(bp);
722 static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
730 if (buf_size == 1) /* ethtool */
731 return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
733 if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
735 "Invalid parameter: offset 0x%x buf_size 0x%x\n",
740 if (offset + buf_size > bp->common.flash_size) {
741 DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
742 " buf_size (0x%x) > flash_size (0x%x)\n",
743 offset, buf_size, bp->common.flash_size);
747 /* request access to nvram interface */
748 rc = bnx2x_acquire_nvram_lock(bp);
752 /* enable access to nvram interface */
753 bnx2x_enable_nvram_access(bp);
756 cmd_flags = MCPR_NVM_COMMAND_FIRST;
757 while ((written_so_far < buf_size) && (rc == 0)) {
758 if (written_so_far == (buf_size - sizeof(u32)))
759 cmd_flags |= MCPR_NVM_COMMAND_LAST;
760 else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
761 cmd_flags |= MCPR_NVM_COMMAND_LAST;
762 else if ((offset % NVRAM_PAGE_SIZE) == 0)
763 cmd_flags |= MCPR_NVM_COMMAND_FIRST;
765 memcpy(&val, data_buf, 4);
767 rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
769 /* advance to the next dword */
770 offset += sizeof(u32);
771 data_buf += sizeof(u32);
772 written_so_far += sizeof(u32);
776 /* disable access to nvram interface */
777 bnx2x_disable_nvram_access(bp);
778 bnx2x_release_nvram_lock(bp);
783 static int bnx2x_set_eeprom(struct net_device *dev,
784 struct ethtool_eeprom *eeprom, u8 *eebuf)
786 struct bnx2x *bp = netdev_priv(dev);
787 int port = BP_PORT(bp);
790 if (!netif_running(dev))
793 DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
794 DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
795 eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
796 eeprom->len, eeprom->len);
798 /* parameters already validated in ethtool_set_eeprom */
800 /* PHY eeprom can be accessed only by the PMF */
801 if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
807 dev_info.port_hw_config[port].external_phy_config);
809 if (eeprom->magic == 0x50485950) {
810 /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
811 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
813 bnx2x_acquire_phy_lock(bp);
814 rc |= bnx2x_link_reset(&bp->link_params,
816 if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
817 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
818 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
819 MISC_REGISTERS_GPIO_HIGH, port);
820 bnx2x_release_phy_lock(bp);
821 bnx2x_link_report(bp);
823 } else if (eeprom->magic == 0x50485952) {
824 /* 'PHYR' (0x50485952): re-init link after FW upgrade */
825 if (bp->state == BNX2X_STATE_OPEN) {
826 bnx2x_acquire_phy_lock(bp);
827 rc |= bnx2x_link_reset(&bp->link_params,
830 rc |= bnx2x_phy_init(&bp->link_params,
832 bnx2x_release_phy_lock(bp);
833 bnx2x_calc_fc_adv(bp);
835 } else if (eeprom->magic == 0x53985943) {
836 /* 'PHYC' (0x53985943): PHY FW upgrade completed */
837 if (XGXS_EXT_PHY_TYPE(ext_phy_config) ==
838 PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
840 /* DSP Remove Download Mode */
841 bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
842 MISC_REGISTERS_GPIO_LOW, port);
844 bnx2x_acquire_phy_lock(bp);
846 bnx2x_sfx7101_sp_sw_reset(bp,
847 &bp->link_params.phy[EXT_PHY1]);
849 /* wait 0.5 sec to allow it to run */
851 bnx2x_ext_phy_hw_reset(bp, port);
853 bnx2x_release_phy_lock(bp);
856 rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
860 static int bnx2x_get_coalesce(struct net_device *dev,
861 struct ethtool_coalesce *coal)
863 struct bnx2x *bp = netdev_priv(dev);
865 memset(coal, 0, sizeof(struct ethtool_coalesce));
867 coal->rx_coalesce_usecs = bp->rx_ticks;
868 coal->tx_coalesce_usecs = bp->tx_ticks;
873 static int bnx2x_set_coalesce(struct net_device *dev,
874 struct ethtool_coalesce *coal)
876 struct bnx2x *bp = netdev_priv(dev);
878 bp->rx_ticks = (u16)coal->rx_coalesce_usecs;
879 if (bp->rx_ticks > BNX2X_MAX_COALESCE_TOUT)
880 bp->rx_ticks = BNX2X_MAX_COALESCE_TOUT;
882 bp->tx_ticks = (u16)coal->tx_coalesce_usecs;
883 if (bp->tx_ticks > BNX2X_MAX_COALESCE_TOUT)
884 bp->tx_ticks = BNX2X_MAX_COALESCE_TOUT;
886 if (netif_running(dev))
887 bnx2x_update_coalesce(bp);
892 static void bnx2x_get_ringparam(struct net_device *dev,
893 struct ethtool_ringparam *ering)
895 struct bnx2x *bp = netdev_priv(dev);
897 ering->rx_max_pending = MAX_RX_AVAIL;
898 ering->rx_mini_max_pending = 0;
899 ering->rx_jumbo_max_pending = 0;
901 ering->rx_pending = bp->rx_ring_size;
902 ering->rx_mini_pending = 0;
903 ering->rx_jumbo_pending = 0;
905 ering->tx_max_pending = MAX_TX_AVAIL;
906 ering->tx_pending = bp->tx_ring_size;
909 static int bnx2x_set_ringparam(struct net_device *dev,
910 struct ethtool_ringparam *ering)
912 struct bnx2x *bp = netdev_priv(dev);
915 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
916 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
920 if ((ering->rx_pending > MAX_RX_AVAIL) ||
921 (ering->tx_pending > MAX_TX_AVAIL) ||
922 (ering->tx_pending <= MAX_SKB_FRAGS + 4))
925 bp->rx_ring_size = ering->rx_pending;
926 bp->tx_ring_size = ering->tx_pending;
928 if (netif_running(dev)) {
929 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
930 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
936 static void bnx2x_get_pauseparam(struct net_device *dev,
937 struct ethtool_pauseparam *epause)
939 struct bnx2x *bp = netdev_priv(dev);
941 epause->autoneg = (bp->link_params.req_flow_ctrl ==
942 BNX2X_FLOW_CTRL_AUTO) &&
943 (bp->link_params.req_line_speed == SPEED_AUTO_NEG);
945 epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
947 epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
950 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
951 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
952 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
955 static int bnx2x_set_pauseparam(struct net_device *dev,
956 struct ethtool_pauseparam *epause)
958 struct bnx2x *bp = netdev_priv(dev);
963 DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
964 DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
965 epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
967 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
969 if (epause->rx_pause)
970 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX;
972 if (epause->tx_pause)
973 bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX;
975 if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
976 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
978 if (epause->autoneg) {
979 if (!(bp->port.supported & SUPPORTED_Autoneg)) {
980 DP(NETIF_MSG_LINK, "autoneg not supported\n");
984 if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
985 bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
989 "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl);
991 if (netif_running(dev)) {
992 bnx2x_stats_handle(bp, STATS_EVENT_STOP);
999 static int bnx2x_set_flags(struct net_device *dev, u32 data)
1001 struct bnx2x *bp = netdev_priv(dev);
1005 if (data & ~(ETH_FLAG_LRO | ETH_FLAG_RXHASH))
1008 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1009 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
1013 /* TPA requires Rx CSUM offloading */
1014 if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
1015 if (!bp->disable_tpa) {
1016 if (!(dev->features & NETIF_F_LRO)) {
1017 dev->features |= NETIF_F_LRO;
1018 bp->flags |= TPA_ENABLE_FLAG;
1023 } else if (dev->features & NETIF_F_LRO) {
1024 dev->features &= ~NETIF_F_LRO;
1025 bp->flags &= ~TPA_ENABLE_FLAG;
1029 if (data & ETH_FLAG_RXHASH)
1030 dev->features |= NETIF_F_RXHASH;
1032 dev->features &= ~NETIF_F_RXHASH;
1034 if (changed && netif_running(dev)) {
1035 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
1036 rc = bnx2x_nic_load(bp, LOAD_NORMAL);
1042 static u32 bnx2x_get_rx_csum(struct net_device *dev)
1044 struct bnx2x *bp = netdev_priv(dev);
1049 static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
1051 struct bnx2x *bp = netdev_priv(dev);
1054 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1055 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
1061 /* Disable TPA, when Rx CSUM is disabled. Otherwise all
1062 TPA'ed packets will be discarded due to wrong TCP CSUM */
1064 u32 flags = ethtool_op_get_flags(dev);
1066 rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
1072 static int bnx2x_set_tso(struct net_device *dev, u32 data)
1075 dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
1076 dev->features |= NETIF_F_TSO6;
1078 dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
1079 dev->features &= ~NETIF_F_TSO6;
1085 static const struct {
1086 char string[ETH_GSTRING_LEN];
1087 } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
1088 { "register_test (offline)" },
1089 { "memory_test (offline)" },
1090 { "loopback_test (offline)" },
1091 { "nvram_test (online)" },
1092 { "interrupt_test (online)" },
1093 { "link_test (online)" },
1094 { "idle check (online)" }
1097 static int bnx2x_test_registers(struct bnx2x *bp)
1099 int idx, i, rc = -ENODEV;
1101 int port = BP_PORT(bp);
1102 static const struct {
1107 /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
1108 { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
1109 { HC_REG_AGG_INT_0, 4, 0x000003ff },
1110 { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
1111 { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
1112 { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
1113 { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
1114 { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
1115 { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
1116 { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
1117 /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
1118 { QM_REG_CONNNUM_0, 4, 0x000fffff },
1119 { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
1120 { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
1121 { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
1122 { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
1123 { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
1124 { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
1125 { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
1126 { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
1127 /* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
1128 { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
1129 { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
1130 { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
1131 { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
1132 { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
1133 { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
1134 { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
1135 { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
1136 { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
1137 /* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
1138 { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
1139 { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
1140 { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
1141 { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
1142 { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
1143 { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
1145 { 0xffffffff, 0, 0x00000000 }
1148 if (!netif_running(bp->dev))
1151 /* Repeat the test twice:
1152 First by writing 0x00000000, second by writing 0xffffffff */
1153 for (idx = 0; idx < 2; idx++) {
1160 wr_val = 0xffffffff;
1164 for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
1165 u32 offset, mask, save_val, val;
1167 offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
1168 mask = reg_tbl[i].mask;
1170 save_val = REG_RD(bp, offset);
1172 REG_WR(bp, offset, (wr_val & mask));
1173 val = REG_RD(bp, offset);
1175 /* Restore the original register's value */
1176 REG_WR(bp, offset, save_val);
1178 /* verify value is as expected */
1179 if ((val & mask) != (wr_val & mask)) {
1181 "offset 0x%x: val 0x%x != 0x%x mask 0x%x\n",
1182 offset, val, wr_val, mask);
1194 static int bnx2x_test_memory(struct bnx2x *bp)
1196 int i, j, rc = -ENODEV;
1198 static const struct {
1202 { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
1203 { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
1204 { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
1205 { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
1206 { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
1207 { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
1208 { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
1212 static const struct {
1218 { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
1219 { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
1220 { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
1221 { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
1222 { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
1223 { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
1225 { NULL, 0xffffffff, 0, 0 }
1228 if (!netif_running(bp->dev))
1231 /* Go through all the memories */
1232 for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
1233 for (j = 0; j < mem_tbl[i].size; j++)
1234 REG_RD(bp, mem_tbl[i].offset + j*4);
1236 /* Check the parity status */
1237 for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
1238 val = REG_RD(bp, prty_tbl[i].offset);
1239 if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
1240 (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
1242 "%s is 0x%x\n", prty_tbl[i].name, val);
1253 static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up)
1258 while (bnx2x_link_test(bp) && cnt--)
1262 static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
1264 unsigned int pkt_size, num_pkts, i;
1265 struct sk_buff *skb;
1266 unsigned char *packet;
1267 struct bnx2x_fastpath *fp_rx = &bp->fp[0];
1268 struct bnx2x_fastpath *fp_tx = &bp->fp[0];
1269 u16 tx_start_idx, tx_idx;
1270 u16 rx_start_idx, rx_idx;
1271 u16 pkt_prod, bd_prod;
1272 struct sw_tx_bd *tx_buf;
1273 struct eth_tx_start_bd *tx_start_bd;
1274 struct eth_tx_parse_bd *pbd = NULL;
1276 union eth_rx_cqe *cqe;
1278 struct sw_rx_bd *rx_buf;
1282 /* check the loopback mode */
1283 switch (loopback_mode) {
1284 case BNX2X_PHY_LOOPBACK:
1285 if (bp->link_params.loopback_mode != LOOPBACK_XGXS)
1288 case BNX2X_MAC_LOOPBACK:
1289 bp->link_params.loopback_mode = LOOPBACK_BMAC;
1290 bnx2x_phy_init(&bp->link_params, &bp->link_vars);
1296 /* prepare the loopback packet */
1297 pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
1298 bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
1299 skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
1302 goto test_loopback_exit;
1304 packet = skb_put(skb, pkt_size);
1305 memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
1306 memset(packet + ETH_ALEN, 0, ETH_ALEN);
1307 memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
1308 for (i = ETH_HLEN; i < pkt_size; i++)
1309 packet[i] = (unsigned char) (i & 0xff);
1311 /* send the loopback packet */
1313 tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
1314 rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
1316 pkt_prod = fp_tx->tx_pkt_prod++;
1317 tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)];
1318 tx_buf->first_bd = fp_tx->tx_bd_prod;
1322 bd_prod = TX_BD(fp_tx->tx_bd_prod);
1323 tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd;
1324 mapping = dma_map_single(&bp->pdev->dev, skb->data,
1325 skb_headlen(skb), DMA_TO_DEVICE);
1326 tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
1327 tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
1328 tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
1329 tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
1330 tx_start_bd->vlan = cpu_to_le16(pkt_prod);
1331 tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
1332 tx_start_bd->general_data = ((UNICAST_ADDRESS <<
1333 ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT) | 1);
1335 /* turn on parsing and get a BD */
1336 bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
1337 pbd = &fp_tx->tx_desc_ring[bd_prod].parse_bd;
1339 memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
1343 fp_tx->tx_db.data.prod += 2;
1345 DOORBELL(bp, fp_tx->index, fp_tx->tx_db.raw);
1350 fp_tx->tx_bd_prod += 2; /* start + pbd */
1354 tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
1355 if (tx_idx != tx_start_idx + num_pkts)
1356 goto test_loopback_exit;
1358 rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
1359 if (rx_idx != rx_start_idx + num_pkts)
1360 goto test_loopback_exit;
1362 cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
1363 cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
1364 if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
1365 goto test_loopback_rx_exit;
1367 len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
1368 if (len != pkt_size)
1369 goto test_loopback_rx_exit;
1371 rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
1373 skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
1374 for (i = ETH_HLEN; i < pkt_size; i++)
1375 if (*(skb->data + i) != (unsigned char) (i & 0xff))
1376 goto test_loopback_rx_exit;
1380 test_loopback_rx_exit:
1382 fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
1383 fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
1384 fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
1385 fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
1387 /* Update producers */
1388 bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
1389 fp_rx->rx_sge_prod);
1392 bp->link_params.loopback_mode = LOOPBACK_NONE;
1397 static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
1404 if (!netif_running(bp->dev))
1405 return BNX2X_LOOPBACK_FAILED;
1407 bnx2x_netif_stop(bp, 1);
1408 bnx2x_acquire_phy_lock(bp);
1410 res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
1412 DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
1413 rc |= BNX2X_PHY_LOOPBACK_FAILED;
1416 res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
1418 DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
1419 rc |= BNX2X_MAC_LOOPBACK_FAILED;
1422 bnx2x_release_phy_lock(bp);
1423 bnx2x_netif_start(bp);
1428 #define CRC32_RESIDUAL 0xdebb20e3
1430 static int bnx2x_test_nvram(struct bnx2x *bp)
1432 static const struct {
1436 { 0, 0x14 }, /* bootstrap */
1437 { 0x14, 0xec }, /* dir */
1438 { 0x100, 0x350 }, /* manuf_info */
1439 { 0x450, 0xf0 }, /* feature_info */
1440 { 0x640, 0x64 }, /* upgrade_key_info */
1442 { 0x708, 0x70 }, /* manuf_key_info */
1446 __be32 buf[0x350 / 4];
1447 u8 *data = (u8 *)buf;
1454 rc = bnx2x_nvram_read(bp, 0, data, 4);
1456 DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
1457 goto test_nvram_exit;
1460 magic = be32_to_cpu(buf[0]);
1461 if (magic != 0x669955aa) {
1462 DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
1464 goto test_nvram_exit;
1467 for (i = 0; nvram_tbl[i].size; i++) {
1469 rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
1473 "nvram_tbl[%d] read data (rc %d)\n", i, rc);
1474 goto test_nvram_exit;
1477 crc = ether_crc_le(nvram_tbl[i].size, data);
1478 if (crc != CRC32_RESIDUAL) {
1480 "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
1482 goto test_nvram_exit;
1490 static int bnx2x_test_intr(struct bnx2x *bp)
1492 struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
1495 if (!netif_running(bp->dev))
1498 config->hdr.length = 0;
1500 /* use last unicast entries */
1501 config->hdr.offset = (BP_PORT(bp) ? 63 : 31);
1503 config->hdr.offset = BP_FUNC(bp);
1504 config->hdr.client_id = bp->fp->cl_id;
1505 config->hdr.reserved1 = 0;
1507 bp->set_mac_pending++;
1509 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
1510 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
1511 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
1513 for (i = 0; i < 10; i++) {
1514 if (!bp->set_mac_pending)
1517 msleep_interruptible(10);
1526 static void bnx2x_self_test(struct net_device *dev,
1527 struct ethtool_test *etest, u64 *buf)
1529 struct bnx2x *bp = netdev_priv(dev);
1531 if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
1532 printk(KERN_ERR "Handling parity error recovery. Try again later\n");
1533 etest->flags |= ETH_TEST_FL_FAILED;
1537 memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
1539 if (!netif_running(dev))
1542 /* offline tests are not supported in MF mode */
1544 etest->flags &= ~ETH_TEST_FL_OFFLINE;
1546 if (etest->flags & ETH_TEST_FL_OFFLINE) {
1547 int port = BP_PORT(bp);
1551 /* save current value of input enable for TX port IF */
1552 val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
1553 /* disable input for TX port IF */
1554 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
1556 link_up = (bnx2x_link_test(bp) == 0);
1557 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
1558 bnx2x_nic_load(bp, LOAD_DIAG);
1559 /* wait until link state is restored */
1560 bnx2x_wait_for_link(bp, link_up);
1562 if (bnx2x_test_registers(bp) != 0) {
1564 etest->flags |= ETH_TEST_FL_FAILED;
1566 if (bnx2x_test_memory(bp) != 0) {
1568 etest->flags |= ETH_TEST_FL_FAILED;
1570 buf[2] = bnx2x_test_loopback(bp, link_up);
1572 etest->flags |= ETH_TEST_FL_FAILED;
1574 bnx2x_nic_unload(bp, UNLOAD_NORMAL);
1576 /* restore input for TX port IF */
1577 REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
1579 bnx2x_nic_load(bp, LOAD_NORMAL);
1580 /* wait until link state is restored */
1581 bnx2x_wait_for_link(bp, link_up);
1583 if (bnx2x_test_nvram(bp) != 0) {
1585 etest->flags |= ETH_TEST_FL_FAILED;
1587 if (bnx2x_test_intr(bp) != 0) {
1589 etest->flags |= ETH_TEST_FL_FAILED;
1592 if (bnx2x_link_test(bp) != 0) {
1594 etest->flags |= ETH_TEST_FL_FAILED;
1597 #ifdef BNX2X_EXTRA_DEBUG
1598 bnx2x_panic_dump(bp);
1602 static const struct {
1605 u8 string[ETH_GSTRING_LEN];
1606 } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
1607 /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
1608 { Q_STATS_OFFSET32(error_bytes_received_hi),
1609 8, "[%d]: rx_error_bytes" },
1610 { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
1611 8, "[%d]: rx_ucast_packets" },
1612 { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
1613 8, "[%d]: rx_mcast_packets" },
1614 { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
1615 8, "[%d]: rx_bcast_packets" },
1616 { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
1617 { Q_STATS_OFFSET32(rx_err_discard_pkt),
1618 4, "[%d]: rx_phy_ip_err_discards"},
1619 { Q_STATS_OFFSET32(rx_skb_alloc_failed),
1620 4, "[%d]: rx_skb_alloc_discard" },
1621 { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
1623 /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
1624 { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
1625 8, "[%d]: tx_ucast_packets" },
1626 { Q_STATS_OFFSET32(total_multicast_packets_transmitted_hi),
1627 8, "[%d]: tx_mcast_packets" },
1628 { Q_STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
1629 8, "[%d]: tx_bcast_packets" }
1632 static const struct {
1636 #define STATS_FLAGS_PORT 1
1637 #define STATS_FLAGS_FUNC 2
1638 #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
1639 u8 string[ETH_GSTRING_LEN];
1640 } bnx2x_stats_arr[BNX2X_NUM_STATS] = {
1641 /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
1642 8, STATS_FLAGS_BOTH, "rx_bytes" },
1643 { STATS_OFFSET32(error_bytes_received_hi),
1644 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
1645 { STATS_OFFSET32(total_unicast_packets_received_hi),
1646 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
1647 { STATS_OFFSET32(total_multicast_packets_received_hi),
1648 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
1649 { STATS_OFFSET32(total_broadcast_packets_received_hi),
1650 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
1651 { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
1652 8, STATS_FLAGS_PORT, "rx_crc_errors" },
1653 { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
1654 8, STATS_FLAGS_PORT, "rx_align_errors" },
1655 { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
1656 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
1657 { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
1658 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
1659 /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
1660 8, STATS_FLAGS_PORT, "rx_fragments" },
1661 { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
1662 8, STATS_FLAGS_PORT, "rx_jabbers" },
1663 { STATS_OFFSET32(no_buff_discard_hi),
1664 8, STATS_FLAGS_BOTH, "rx_discards" },
1665 { STATS_OFFSET32(mac_filter_discard),
1666 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
1667 { STATS_OFFSET32(xxoverflow_discard),
1668 4, STATS_FLAGS_PORT, "rx_fw_discards" },
1669 { STATS_OFFSET32(brb_drop_hi),
1670 8, STATS_FLAGS_PORT, "rx_brb_discard" },
1671 { STATS_OFFSET32(brb_truncate_hi),
1672 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
1673 { STATS_OFFSET32(pause_frames_received_hi),
1674 8, STATS_FLAGS_PORT, "rx_pause_frames" },
1675 { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
1676 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
1677 { STATS_OFFSET32(nig_timer_max),
1678 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
1679 /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
1680 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
1681 { STATS_OFFSET32(rx_skb_alloc_failed),
1682 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
1683 { STATS_OFFSET32(hw_csum_err),
1684 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
1686 { STATS_OFFSET32(total_bytes_transmitted_hi),
1687 8, STATS_FLAGS_BOTH, "tx_bytes" },
1688 { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
1689 8, STATS_FLAGS_PORT, "tx_error_bytes" },
1690 { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
1691 8, STATS_FLAGS_BOTH, "tx_ucast_packets" },
1692 { STATS_OFFSET32(total_multicast_packets_transmitted_hi),
1693 8, STATS_FLAGS_BOTH, "tx_mcast_packets" },
1694 { STATS_OFFSET32(total_broadcast_packets_transmitted_hi),
1695 8, STATS_FLAGS_BOTH, "tx_bcast_packets" },
1696 { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
1697 8, STATS_FLAGS_PORT, "tx_mac_errors" },
1698 { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
1699 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
1700 /* 30 */{ STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
1701 8, STATS_FLAGS_PORT, "tx_single_collisions" },
1702 { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
1703 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
1704 { STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
1705 8, STATS_FLAGS_PORT, "tx_deferred" },
1706 { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
1707 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
1708 { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
1709 8, STATS_FLAGS_PORT, "tx_late_collisions" },
1710 { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
1711 8, STATS_FLAGS_PORT, "tx_total_collisions" },
1712 { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
1713 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
1714 { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
1715 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
1716 { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
1717 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
1718 { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
1719 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
1720 /* 40 */{ STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
1721 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
1722 { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
1723 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
1724 { STATS_OFFSET32(etherstatspktsover1522octets_hi),
1725 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
1726 { STATS_OFFSET32(pause_frames_sent_hi),
1727 8, STATS_FLAGS_PORT, "tx_pause_frames" }
1730 #define IS_PORT_STAT(i) \
1731 ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
1732 #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
1733 #define IS_E1HMF_MODE_STAT(bp) \
1734 (IS_E1HMF(bp) && !(bp->msg_enable & BNX2X_MSG_STATS))
1736 static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
1738 struct bnx2x *bp = netdev_priv(dev);
1741 switch (stringset) {
1744 num_stats = BNX2X_NUM_Q_STATS * bp->num_queues;
1745 if (!IS_E1HMF_MODE_STAT(bp))
1746 num_stats += BNX2X_NUM_STATS;
1748 if (IS_E1HMF_MODE_STAT(bp)) {
1750 for (i = 0; i < BNX2X_NUM_STATS; i++)
1751 if (IS_FUNC_STAT(i))
1754 num_stats = BNX2X_NUM_STATS;
1759 return BNX2X_NUM_TESTS;
1766 static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
1768 struct bnx2x *bp = netdev_priv(dev);
1771 switch (stringset) {
1775 for_each_queue(bp, i) {
1776 for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
1777 sprintf(buf + (k + j)*ETH_GSTRING_LEN,
1778 bnx2x_q_stats_arr[j].string, i);
1779 k += BNX2X_NUM_Q_STATS;
1781 if (IS_E1HMF_MODE_STAT(bp))
1783 for (j = 0; j < BNX2X_NUM_STATS; j++)
1784 strcpy(buf + (k + j)*ETH_GSTRING_LEN,
1785 bnx2x_stats_arr[j].string);
1787 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
1788 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
1790 strcpy(buf + j*ETH_GSTRING_LEN,
1791 bnx2x_stats_arr[i].string);
1798 memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
1803 static void bnx2x_get_ethtool_stats(struct net_device *dev,
1804 struct ethtool_stats *stats, u64 *buf)
1806 struct bnx2x *bp = netdev_priv(dev);
1807 u32 *hw_stats, *offset;
1812 for_each_queue(bp, i) {
1813 hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
1814 for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
1815 if (bnx2x_q_stats_arr[j].size == 0) {
1816 /* skip this counter */
1820 offset = (hw_stats +
1821 bnx2x_q_stats_arr[j].offset);
1822 if (bnx2x_q_stats_arr[j].size == 4) {
1823 /* 4-byte counter */
1824 buf[k + j] = (u64) *offset;
1827 /* 8-byte counter */
1828 buf[k + j] = HILO_U64(*offset, *(offset + 1));
1830 k += BNX2X_NUM_Q_STATS;
1832 if (IS_E1HMF_MODE_STAT(bp))
1834 hw_stats = (u32 *)&bp->eth_stats;
1835 for (j = 0; j < BNX2X_NUM_STATS; j++) {
1836 if (bnx2x_stats_arr[j].size == 0) {
1837 /* skip this counter */
1841 offset = (hw_stats + bnx2x_stats_arr[j].offset);
1842 if (bnx2x_stats_arr[j].size == 4) {
1843 /* 4-byte counter */
1844 buf[k + j] = (u64) *offset;
1847 /* 8-byte counter */
1848 buf[k + j] = HILO_U64(*offset, *(offset + 1));
1851 hw_stats = (u32 *)&bp->eth_stats;
1852 for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
1853 if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
1855 if (bnx2x_stats_arr[i].size == 0) {
1856 /* skip this counter */
1861 offset = (hw_stats + bnx2x_stats_arr[i].offset);
1862 if (bnx2x_stats_arr[i].size == 4) {
1863 /* 4-byte counter */
1864 buf[j] = (u64) *offset;
1868 /* 8-byte counter */
1869 buf[j] = HILO_U64(*offset, *(offset + 1));
1875 static int bnx2x_phys_id(struct net_device *dev, u32 data)
1877 struct bnx2x *bp = netdev_priv(dev);
1880 if (!netif_running(dev))
1889 for (i = 0; i < (data * 2); i++) {
1891 bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
1894 bnx2x_set_led(&bp->link_params, LED_MODE_OFF, 0);
1896 msleep_interruptible(500);
1897 if (signal_pending(current))
1901 if (bp->link_vars.link_up)
1902 bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
1903 bp->link_vars.line_speed);
1908 static const struct ethtool_ops bnx2x_ethtool_ops = {
1909 .get_settings = bnx2x_get_settings,
1910 .set_settings = bnx2x_set_settings,
1911 .get_drvinfo = bnx2x_get_drvinfo,
1912 .get_regs_len = bnx2x_get_regs_len,
1913 .get_regs = bnx2x_get_regs,
1914 .get_wol = bnx2x_get_wol,
1915 .set_wol = bnx2x_set_wol,
1916 .get_msglevel = bnx2x_get_msglevel,
1917 .set_msglevel = bnx2x_set_msglevel,
1918 .nway_reset = bnx2x_nway_reset,
1919 .get_link = bnx2x_get_link,
1920 .get_eeprom_len = bnx2x_get_eeprom_len,
1921 .get_eeprom = bnx2x_get_eeprom,
1922 .set_eeprom = bnx2x_set_eeprom,
1923 .get_coalesce = bnx2x_get_coalesce,
1924 .set_coalesce = bnx2x_set_coalesce,
1925 .get_ringparam = bnx2x_get_ringparam,
1926 .set_ringparam = bnx2x_set_ringparam,
1927 .get_pauseparam = bnx2x_get_pauseparam,
1928 .set_pauseparam = bnx2x_set_pauseparam,
1929 .get_rx_csum = bnx2x_get_rx_csum,
1930 .set_rx_csum = bnx2x_set_rx_csum,
1931 .get_tx_csum = ethtool_op_get_tx_csum,
1932 .set_tx_csum = ethtool_op_set_tx_hw_csum,
1933 .set_flags = bnx2x_set_flags,
1934 .get_flags = ethtool_op_get_flags,
1935 .get_sg = ethtool_op_get_sg,
1936 .set_sg = ethtool_op_set_sg,
1937 .get_tso = ethtool_op_get_tso,
1938 .set_tso = bnx2x_set_tso,
1939 .self_test = bnx2x_self_test,
1940 .get_sset_count = bnx2x_get_sset_count,
1941 .get_strings = bnx2x_get_strings,
1942 .phys_id = bnx2x_phys_id,
1943 .get_ethtool_stats = bnx2x_get_ethtool_stats,
1946 void bnx2x_set_ethtool_ops(struct net_device *netdev)
1948 SET_ETHTOOL_OPS(netdev, &bnx2x_ethtool_ops);