12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <linux/module.h>
18 #include <linux/kernel.h>
20 #include <linux/errno.h>
22 #include <linux/slab.h>
25 #include <linux/pci.h>
27 #include <linux/netdevice.h>
31 #include <linux/bitops.h>
35 #include <asm/byteorder.h>
37 #include <linux/time.h>
38 #include <linux/ethtool.h>
39 #include <linux/mii.h>
41 #include <linux/if_vlan.h>
47 #include <linux/prefetch.h>
53 #if defined(CONFIG_CNIC) || defined(CONFIG_CNIC_MODULE)
60 #define DRV_MODULE_NAME "bnx2"
61 #define DRV_MODULE_VERSION "2.2.3"
62 #define DRV_MODULE_RELDATE "June 27, 2012"
63 #define FW_MIPS_FILE_06 "bnx2/bnx2-mips-06-6.2.3.fw"
64 #define FW_RV2P_FILE_06 "bnx2/bnx2-rv2p-06-6.0.15.fw"
65 #define FW_MIPS_FILE_09 "bnx2/bnx2-mips-09-6.2.1b.fw"
66 #define FW_RV2P_FILE_09_Ax "bnx2/bnx2-rv2p-09ax-6.0.17.fw"
67 #define FW_RV2P_FILE_09 "bnx2/bnx2-rv2p-09-6.0.17.fw"
69 #define RUN_AT(x) (jiffies + (x))
72 #define TX_TIMEOUT (5*HZ)
87 static int disable_msi = 0;
110 {
"Broadcom NetXtreme II BCM5706 1000Base-T" },
111 {
"HP NC370T Multifunction Gigabit Server Adapter" },
112 {
"HP NC370i Multifunction Gigabit Server Adapter" },
113 {
"Broadcom NetXtreme II BCM5706 1000Base-SX" },
114 {
"HP NC370F Multifunction Gigabit Server Adapter" },
115 {
"Broadcom NetXtreme II BCM5708 1000Base-T" },
116 {
"Broadcom NetXtreme II BCM5708 1000Base-SX" },
117 {
"Broadcom NetXtreme II BCM5709 1000Base-T" },
118 {
"Broadcom NetXtreme II BCM5709 1000Base-SX" },
119 {
"Broadcom NetXtreme II BCM5716 1000Base-T" },
120 {
"Broadcom NetXtreme II BCM5716 1000Base-SX" },
149 static const struct flash_spec flash_table[] =
151 #define BUFFERED_FLAGS (BNX2_NV_BUFFERED | BNX2_NV_TRANSLATE)
152 #define NONBUFFERED_FLAGS (BNX2_NV_WREN)
154 {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
159 {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
165 {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
168 "Non-buffered flash (128kB)"},
171 {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
174 "Non-buffered flash (256kB)"},
176 {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
181 {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
184 "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
186 {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
189 "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
192 {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
195 "Non-buffered flash (64kB)"},
197 {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
202 {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
207 {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
212 {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
215 "Buffered flash (128kB)"},
217 {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
222 {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
227 {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
230 "Entry 1110 (Atmel)"},
232 {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
235 "Buffered flash (256kB)"},
244 .name =
"5709 Buffered flash (256kB)",
249 static void bnx2_init_napi(
struct bnx2 *bp);
250 static void bnx2_del_napi(
struct bnx2 *bp);
295 bnx2_reg_wr_ind(bp, bp->
shmem_base + offset, val);
301 return bnx2_reg_rd_ind(bp, bp->
shmem_base + offset);
315 for (i = 0; i < 5; i++) {
332 struct bnx2 *bp = netdev_priv(dev);
351 static void bnx2_setup_cnic_irq_info(
struct bnx2 *bp)
359 bnapi->cnic_present = 0;
365 bnapi->cnic_present = 1;
371 cp->
irq_arr[0].status_blk = (
void *)
374 cp->
irq_arr[0].status_blk_num = sb_id;
381 struct bnx2 *bp = netdev_priv(dev);
393 bp->cnic_data =
data;
399 bnx2_setup_cnic_irq_info(bp);
404 static int bnx2_unregister_cnic(
struct net_device *dev)
406 struct bnx2 *bp = netdev_priv(dev);
412 bnapi->cnic_present = 0;
421 struct bnx2 *bp = netdev_priv(dev);
440 bnx2_cnic_stop(
struct bnx2 *bp)
447 lockdep_is_held(&bp->cnic_lock));
450 c_ops->
cnic_ctl(bp->cnic_data, &info);
456 bnx2_cnic_start(
struct bnx2 *bp)
463 lockdep_is_held(&bp->cnic_lock));
471 c_ops->
cnic_ctl(bp->cnic_data, &info);
479 bnx2_cnic_stop(
struct bnx2 *bp)
484 bnx2_cnic_start(
struct bnx2 *bp)
506 val1 = (bp->
phy_addr << 21) | (reg << 16) |
511 for (i = 0; i < 50; i++) {
548 bnx2_write_phy(
struct bnx2 *bp,
u32 reg,
u32 val)
563 val1 = (bp->
phy_addr << 21) | (reg << 16) | val |
568 for (i = 0; i < 50; i++) {
572 if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
578 if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
597 bnx2_disable_int(
struct bnx2 *bp)
611 bnx2_enable_int(
struct bnx2 *bp)
632 bnx2_disable_int_sync(
struct bnx2 *bp)
637 if (!netif_running(bp->
dev))
640 bnx2_disable_int(bp);
646 bnx2_napi_disable(
struct bnx2 *bp)
655 bnx2_napi_enable(
struct bnx2 *bp)
664 bnx2_netif_stop(
struct bnx2 *bp,
bool stop_cnic)
668 if (netif_running(bp->
dev)) {
669 bnx2_napi_disable(bp);
670 netif_tx_disable(bp->
dev);
672 bnx2_disable_int_sync(bp);
677 bnx2_netif_start(
struct bnx2 *bp,
bool start_cnic)
680 if (netif_running(bp->
dev)) {
681 netif_tx_wake_all_queues(bp->
dev);
686 bnx2_napi_enable(bp);
695 bnx2_free_tx_mem(
struct bnx2 *bp)
715 bnx2_free_rx_mem(
struct bnx2 *bp)
747 bnx2_alloc_tx_mem(
struct bnx2 *bp)
769 bnx2_alloc_rx_mem(
struct bnx2 *bp)
817 bnx2_free_mem(
struct bnx2 *bp)
822 bnx2_free_tx_mem(bp);
823 bnx2_free_rx_mem(bp);
843 bnx2_alloc_mem(
struct bnx2 *bp)
845 int i, status_blk_size,
err;
859 if (status_blk ==
NULL)
879 &sblk->status_tx_quick_consumer_index;
881 &sblk->status_rx_quick_consumer_index;
886 bp->
stats_blk = status_blk + status_blk_size;
904 err = bnx2_alloc_rx_mem(bp);
908 err = bnx2_alloc_tx_mem(bp);
920 bnx2_report_fw_link(
struct bnx2 *bp)
922 u32 fw_link_status = 0;
962 bnx2_read_phy(bp, bp->
mii_bmsr, &bmsr);
963 bnx2_read_phy(bp, bp->
mii_bmsr, &bmsr);
979 bnx2_xceiver_str(
struct bnx2 *bp)
987 bnx2_report_link(
struct bnx2 *bp)
991 netdev_info(bp->
dev,
"NIC %s Link is Up, %d Mbps %s duplex",
992 bnx2_xceiver_str(bp),
1010 netdev_err(bp->
dev,
"NIC %s Link is Down\n",
1011 bnx2_xceiver_str(bp));
1014 bnx2_report_fw_link(bp);
1018 bnx2_resolve_flow_ctrl(
struct bnx2 *bp)
1020 u32 local_adv, remote_adv;
1048 bnx2_read_phy(bp, bp->
mii_adv, &local_adv);
1049 bnx2_read_phy(bp, bp->
mii_lpa, &remote_adv);
1052 u32 new_local_adv = 0;
1053 u32 new_remote_adv = 0;
1059 if (remote_adv & ADVERTISE_1000XPAUSE)
1061 if (remote_adv & ADVERTISE_1000XPSE_ASYM)
1064 local_adv = new_local_adv;
1065 remote_adv = new_remote_adv;
1071 if (remote_adv & ADVERTISE_PAUSE_CAP) {
1074 else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
1079 if (remote_adv & ADVERTISE_PAUSE_CAP) {
1084 else if (local_adv & ADVERTISE_PAUSE_ASYM) {
1085 if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
1086 (remote_adv & ADVERTISE_PAUSE_ASYM)) {
1094 bnx2_5709s_linkup(
struct bnx2 *bp)
1133 bnx2_5708s_linkup(
struct bnx2 *bp)
1162 bnx2_5706s_linkup(
struct bnx2 *bp)
1164 u32 bmcr, local_adv, remote_adv,
common;
1169 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1181 bnx2_read_phy(bp, bp->
mii_adv, &local_adv);
1182 bnx2_read_phy(bp, bp->
mii_lpa, &remote_adv);
1184 common = local_adv & remote_adv;
1199 bnx2_copper_linkup(
struct bnx2 *bp)
1203 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1204 if (bmcr & BMCR_ANENABLE) {
1210 common = local_adv & (remote_adv >> 2);
1220 bnx2_read_phy(bp, bp->
mii_adv, &local_adv);
1221 bnx2_read_phy(bp, bp->
mii_lpa, &remote_adv);
1223 common = local_adv & remote_adv;
1253 if (bmcr & BMCR_FULLDPLX) {
1265 bnx2_init_rx_context(
struct bnx2 *bp,
u32 cid)
1280 bnx2_init_all_rx_contexts(
struct bnx2 *bp)
1288 bnx2_init_rx_context(bp, cid);
1293 bnx2_set_mac_link(
struct bnx2 *bp)
1356 bnx2_init_all_rx_contexts(bp);
1360 bnx2_enable_bmsr1(
struct bnx2 *bp)
1369 bnx2_disable_bmsr1(
struct bnx2 *bp)
1378 bnx2_test_and_enable_2g5(
struct bnx2 *bp)
1392 bnx2_read_phy(bp, bp->
mii_up1, &up1);
1395 bnx2_write_phy(bp, bp->
mii_up1, up1);
1407 bnx2_test_and_disable_2g5(
struct bnx2 *bp)
1418 bnx2_read_phy(bp, bp->
mii_up1, &up1);
1419 if (up1 & BCM5708S_UP1_2G5) {
1420 up1 &= ~BCM5708S_UP1_2G5;
1421 bnx2_write_phy(bp, bp->
mii_up1, up1);
1433 bnx2_enable_forced_2g5(
struct bnx2 *bp)
1455 err = bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1458 err = bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1469 bmcr &= ~BMCR_ANENABLE;
1473 bnx2_write_phy(bp, bp->
mii_bmcr, bmcr);
1477 bnx2_disable_forced_2g5(
struct bnx2 *bp)
1497 err = bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1500 err = bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1512 bnx2_write_phy(bp, bp->
mii_bmcr, bmcr);
1516 bnx2_5706s_force_link_dn(
struct bnx2 *bp,
int start)
1529 bnx2_set_link(
struct bnx2 *bp)
1544 bnx2_enable_bmsr1(bp);
1545 bnx2_read_phy(bp, bp->
mii_bmsr1, &bmsr);
1546 bnx2_read_phy(bp, bp->
mii_bmsr1, &bmsr);
1547 bnx2_disable_bmsr1(bp);
1554 bnx2_5706s_force_link_dn(bp, 0);
1575 bnx2_5706s_linkup(bp);
1577 bnx2_5708s_linkup(bp);
1579 bnx2_5709s_linkup(bp);
1582 bnx2_copper_linkup(bp);
1584 bnx2_resolve_flow_ctrl(bp);
1589 bnx2_disable_forced_2g5(bp);
1594 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1596 bnx2_write_phy(bp, bp->
mii_bmcr, bmcr);
1604 bnx2_report_link(bp);
1607 bnx2_set_mac_link(bp);
1613 bnx2_reset_phy(
struct bnx2 *bp)
1620 #define PHY_RESET_MAX_WAIT 100
1624 bnx2_read_phy(bp, bp->
mii_bmcr, ®);
1630 if (i == PHY_RESET_MAX_WAIT) {
1637 bnx2_phy_get_pause_adv(
struct bnx2 *bp)
1670 static int bnx2_fw_sync(
struct bnx2 *,
u32,
int,
int);
1673 bnx2_setup_remote_phy(
struct bnx2 *bp,
u8 port)
1677 u32 speed_arg = 0, pause_adv;
1679 pause_adv = bnx2_phy_get_pause_adv(bp);
1713 if (pause_adv & (ADVERTISE_1000XPAUSE | ADVERTISE_PAUSE_CAP))
1715 if (pause_adv & (ADVERTISE_1000XPSE_ASYM | ADVERTISE_PAUSE_ASYM))
1732 bnx2_setup_serdes_phy(
struct bnx2 *bp,
u8 port)
1740 return bnx2_setup_remote_phy(bp,
port);
1744 int force_link_down = 0;
1747 if (!bnx2_test_and_enable_2g5(bp))
1748 force_link_down = 1;
1750 if (bnx2_test_and_disable_2g5(bp))
1751 force_link_down = 1;
1753 bnx2_read_phy(bp, bp->
mii_adv, &adv);
1756 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1757 new_bmcr = bmcr & ~BMCR_ANENABLE;
1762 bnx2_enable_forced_2g5(bp);
1764 bnx2_disable_forced_2g5(bp);
1765 new_bmcr &= ~0x2000;
1781 new_bmcr &= ~BMCR_FULLDPLX;
1783 if ((new_bmcr != bmcr) || (force_link_down)) {
1786 bnx2_write_phy(bp, bp->
mii_adv, adv &
1789 bnx2_write_phy(bp, bp->
mii_bmcr, bmcr |
1794 bnx2_write_phy(bp, bp->
mii_bmcr, new_bmcr);
1795 bnx2_report_link(bp);
1797 bnx2_write_phy(bp, bp->
mii_adv, adv);
1798 bnx2_write_phy(bp, bp->
mii_bmcr, new_bmcr);
1800 bnx2_resolve_flow_ctrl(bp);
1801 bnx2_set_mac_link(bp);
1806 bnx2_test_and_enable_2g5(bp);
1811 new_adv |= bnx2_phy_get_pause_adv(bp);
1813 bnx2_read_phy(bp, bp->
mii_adv, &adv);
1814 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
1817 if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
1826 bnx2_write_phy(bp, bp->
mii_adv, new_adv);
1841 bnx2_resolve_flow_ctrl(bp);
1842 bnx2_set_mac_link(bp);
1848 #define ETHTOOL_ALL_FIBRE_SPEED \
1849 (bp->phy_flags & BNX2_PHY_FLAG_2_5G_CAPABLE) ? \
1850 (ADVERTISED_2500baseX_Full | ADVERTISED_1000baseT_Full) :\
1851 (ADVERTISED_1000baseT_Full)
1853 #define ETHTOOL_ALL_COPPER_SPEED \
1854 (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
1855 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
1856 ADVERTISED_1000baseT_Full)
1858 #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
1859 ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
1861 #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
1864 bnx2_set_default_remote_link(
struct bnx2 *bp)
1911 bnx2_set_default_link(
struct bnx2 *bp)
1914 bnx2_set_default_remote_link(bp);
1937 bnx2_send_heart_beat(
struct bnx2 *bp)
1951 bnx2_remote_phy_event(
struct bnx2 *bp)
1960 bnx2_send_heart_beat(bp);
1962 msg &= ~BNX2_LINK_STATUS_HEART_BEAT_EXPIRED;
2022 bnx2_set_default_link(bp);
2026 bnx2_report_link(bp);
2028 bnx2_set_mac_link(bp);
2032 bnx2_set_remote_link(
struct bnx2 *bp)
2039 bnx2_remote_phy_event(bp);
2043 bnx2_send_heart_beat(bp);
2050 bnx2_setup_copper_phy(
struct bnx2 *bp)
2057 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
2060 u32 adv_reg, adv1000_reg;
2062 u32 new_adv1000 = 0;
2064 bnx2_read_phy(bp, bp->
mii_adv, &adv_reg);
2071 new_adv = ethtool_adv_to_mii_adv_t(bp->
advertising);
2073 new_adv |= bnx2_phy_get_pause_adv(bp);
2075 new_adv1000 |= ethtool_adv_to_mii_ctrl1000_t(bp->
advertising);
2077 if ((adv1000_reg != new_adv1000) ||
2078 (adv_reg != new_adv) ||
2079 ((bmcr & BMCR_ANENABLE) == 0)) {
2081 bnx2_write_phy(bp, bp->
mii_adv, new_adv);
2090 bnx2_resolve_flow_ctrl(bp);
2091 bnx2_set_mac_link(bp);
2103 if (new_bmcr != bmcr) {
2106 bnx2_read_phy(bp, bp->
mii_bmsr, &bmsr);
2107 bnx2_read_phy(bp, bp->
mii_bmsr, &bmsr);
2109 if (bmsr & BMSR_LSTATUS) {
2116 bnx2_read_phy(bp, bp->
mii_bmsr, &bmsr);
2117 bnx2_read_phy(bp, bp->
mii_bmsr, &bmsr);
2120 bnx2_write_phy(bp, bp->
mii_bmcr, new_bmcr);
2126 if (bmsr & BMSR_LSTATUS) {
2129 bnx2_resolve_flow_ctrl(bp);
2130 bnx2_set_mac_link(bp);
2133 bnx2_resolve_flow_ctrl(bp);
2134 bnx2_set_mac_link(bp);
2148 return bnx2_setup_serdes_phy(bp,
port);
2151 return bnx2_setup_copper_phy(bp);
2156 bnx2_init_5709s_phy(
struct bnx2 *bp,
int reset_phy)
2186 val &= ~BCM5708S_UP1_2G5;
2206 bnx2_init_5708s_phy(
struct bnx2 *bp,
int reset_phy)
2264 bnx2_init_5706s_phy(
struct bnx2 *bp,
int reset_phy)
2274 if (bp->
dev->mtu > 1500) {
2278 bnx2_write_phy(bp, 0x18, 0x7);
2279 bnx2_read_phy(bp, 0x18, &val);
2280 bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
2282 bnx2_write_phy(bp, 0x1c, 0x6c00);
2283 bnx2_read_phy(bp, 0x1c, &val);
2284 bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
2289 bnx2_write_phy(bp, 0x18, 0x7);
2290 bnx2_read_phy(bp, 0x18, &val);
2291 bnx2_write_phy(bp, 0x18, val & ~0x4007);
2293 bnx2_write_phy(bp, 0x1c, 0x6c00);
2294 bnx2_read_phy(bp, 0x1c, &val);
2295 bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
2302 bnx2_init_copper_phy(
struct bnx2 *bp,
int reset_phy)
2310 bnx2_write_phy(bp, 0x18, 0x0c00);
2311 bnx2_write_phy(bp, 0x17, 0x000a);
2312 bnx2_write_phy(bp, 0x15, 0x310b);
2313 bnx2_write_phy(bp, 0x17, 0x201f);
2314 bnx2_write_phy(bp, 0x15, 0x9506);
2315 bnx2_write_phy(bp, 0x17, 0x401f);
2316 bnx2_write_phy(bp, 0x15, 0x14e2);
2317 bnx2_write_phy(bp, 0x18, 0x0400);
2328 if (bp->
dev->mtu > 1500) {
2330 bnx2_write_phy(bp, 0x18, 0x7);
2331 bnx2_read_phy(bp, 0x18, &val);
2332 bnx2_write_phy(bp, 0x18, val | 0x4000);
2334 bnx2_read_phy(bp, 0x10, &val);
2335 bnx2_write_phy(bp, 0x10, val | 0x1);
2338 bnx2_write_phy(bp, 0x18, 0x7);
2339 bnx2_read_phy(bp, 0x18, &val);
2340 bnx2_write_phy(bp, 0x18, val & ~0x4007);
2342 bnx2_read_phy(bp, 0x10, &val);
2343 bnx2_write_phy(bp, 0x10, val & ~0x1);
2347 bnx2_write_phy(bp, 0x18, 0x7007);
2348 bnx2_read_phy(bp, 0x18, &val);
2349 bnx2_write_phy(bp, 0x18, val | (1 << 15) | (1 << 4));
2355 bnx2_init_phy(
struct bnx2 *bp,
int reset_phy)
2379 bp->
phy_id |= val & 0xffff;
2383 rc = bnx2_init_5706s_phy(bp, reset_phy);
2385 rc = bnx2_init_5708s_phy(bp, reset_phy);
2387 rc = bnx2_init_5709s_phy(bp, reset_phy);
2390 rc = bnx2_init_copper_phy(bp, reset_phy);
2395 rc = bnx2_setup_phy(bp, bp->
phy_port);
2401 bnx2_set_mac_loopback(
struct bnx2 *bp)
2413 static int bnx2_test_link(
struct bnx2 *);
2416 bnx2_set_phy_loopback(
struct bnx2 *bp)
2428 for (i = 0; i < 10; i++) {
2429 if (bnx2_test_link(bp) == 0)
2446 bnx2_dump_mcp_state(
struct bnx2 *bp)
2451 netdev_err(dev,
"<--- start MCP states dump --->\n");
2459 netdev_err(dev,
"DEBUG: MCP_STATE_P0[%08x] MCP_STATE_P1[%08x]\n",
2460 bnx2_reg_rd_ind(bp, mcp_p0), bnx2_reg_rd_ind(bp, mcp_p1));
2461 netdev_err(dev,
"DEBUG: MCP mode[%08x] state[%08x] evt_mask[%08x]\n",
2465 netdev_err(dev,
"DEBUG: pc[%08x] pc[%08x] instr[%08x]\n",
2469 netdev_err(dev,
"DEBUG: shmem states:\n");
2470 netdev_err(dev,
"DEBUG: drv_mb[%08x] fw_mb[%08x] link_status[%08x]",
2475 netdev_err(dev,
"DEBUG: dev_info_signature[%08x] reset_type[%08x]",
2484 netdev_err(dev,
"DEBUG: 0x3fc[%08x]\n", bnx2_shmem_rd(bp, 0x3fc));
2485 netdev_err(dev,
"<--- end MCP states dump --->\n");
2489 bnx2_fw_sync(
struct bnx2 *bp,
u32 msg_data,
int ack,
int silent)
2521 pr_err(
"fw sync timeout, reset code = %x\n", msg_data);
2522 bnx2_dump_mcp_state(bp);
2535 bnx2_init_5709_context(
struct bnx2 *bp)
2543 for (i = 0; i < 10; i++) {
2567 for (j = 0; j < 10; j++) {
2583 bnx2_init_context(
struct bnx2 *bp)
2599 new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
2608 pcid_addr = vcid_addr;
2620 bnx2_ctx_wr(bp, vcid_addr, offset, 0);
2626 bnx2_alloc_bad_rbuf(
struct bnx2 *bp)
2633 if (good_mbuf ==
NULL)
2652 if (!(val & (1 << 9))) {
2653 good_mbuf[good_mbuf_cnt] = (
u16) val;
2662 while (good_mbuf_cnt) {
2665 val = good_mbuf[good_mbuf_cnt];
2666 val = (val << 9) | val | 1;
2679 val = (mac_addr[0] << 8) | mac_addr[1];
2683 val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
2684 (mac_addr[4] << 8) | mac_addr[5];
2694 struct rx_bd *rxbd =
2718 struct page *page = rx_pg->
page;
2766 u32 new_link_state, old_link_state;
2771 if (new_link_state != old_link_state) {
2790 bnx2_set_remote_link(bp);
2797 bnx2_get_hw_tx_cons(
struct bnx2_napi *bnapi)
2814 u16 hw_cons, sw_cons, sw_ring_cons;
2815 int tx_pkt = 0,
index;
2820 txq = netdev_get_tx_queue(bp->
dev, index);
2822 hw_cons = bnx2_get_hw_tx_cons(bnapi);
2825 while (sw_cons != hw_cons) {
2840 u16 last_idx, last_ring_idx;
2842 last_idx = sw_cons + tx_buf->
nr_frags + 1;
2843 last_ring_idx = sw_ring_cons + tx_buf->
nr_frags + 1;
2847 if (((
s16) ((
s16) last_idx - (
s16) hw_cons)) > 0) {
2858 for (i = 0; i < last; i++) {
2865 skb_frag_size(&skb_shinfo(skb)->frags[i]),
2871 tx_bytes += skb->
len;
2874 if (tx_pkt == budget)
2877 if (hw_cons == sw_cons)
2878 hw_cons = bnx2_get_hw_tx_cons(bnapi);
2881 netdev_tx_completed_queue(txq, tx_pkt, tx_bytes);
2892 if (
unlikely(netif_tx_queue_stopped(txq)) &&
2895 if ((netif_tx_queue_stopped(txq)) &&
2897 netif_tx_wake_queue(txq);
2898 __netif_tx_unlock(txq);
2908 struct sw_pg *cons_rx_pg, *prod_rx_pg;
2909 struct rx_bd *cons_bd, *prod_bd;
2924 shinfo = skb_shinfo(skb);
2935 for (i = 0; i <
count; i++) {
2944 prod_rx_pg->
page = cons_rx_pg->
page;
2964 struct sw_bd *cons_rx_buf, *prod_rx_buf;
2965 struct rx_bd *cons_bd, *prod_bd;
2996 u16 prod = ring_idx & 0xffff;
2999 err = bnx2_alloc_rx_data(bp, rxr, prod,
GFP_ATOMIC);
3001 bnx2_reuse_rx_data(bp, rxr, data, (
u16) (ring_idx >> 16), prod);
3004 unsigned int raw_len = len + 4;
3007 bnx2_reuse_rx_skb_pages(bp, rxr,
NULL, pages);
3024 unsigned int i, frag_len, frag_size,
pages;
3025 struct sw_pg *rx_pg;
3029 frag_size = len + 4 -
hdr_len;
3033 for (i = 0; i <
pages; i++) {
3038 unsigned int tail = 4 - frag_len;
3042 bnx2_reuse_rx_skb_pages(bp, rxr,
NULL,
3049 &skb_shinfo(skb)->frags[i - 1];
3050 skb_frag_size_sub(frag, tail);
3064 skb_fill_page_desc(skb, i, rx_pg->
page, 0, frag_len);
3067 err = bnx2_alloc_rx_page(bp, rxr,
3073 bnx2_reuse_rx_skb_pages(bp, rxr, skb,
3081 frag_size -= frag_len;
3084 skb->
len += frag_len;
3096 bnx2_get_hw_rx_cons(
struct bnx2_napi *bnapi)
3110 bnx2_rx_int(
struct bnx2 *bp,
struct bnx2_napi *bnapi,
int budget)
3113 u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
3115 int rx_pkt = 0, pg_ring_used = 0;
3117 hw_cons = bnx2_get_hw_rx_cons(bnapi);
3125 while (sw_cons != hw_cons) {
3128 struct sw_bd *rx_buf, *next_rx_buf;
3137 data = rx_buf->
data;
3140 rx_hdr = get_l2_fhdr(data);
3153 len = rx_hdr->l2_fhdr_pkt_len;
3158 hdr_len = rx_hdr->l2_fhdr_ip_xsum;
3171 bnx2_reuse_rx_data(bp, rxr, data, sw_ring_cons,
3178 bnx2_reuse_rx_skb_pages(bp, rxr,
NULL, pages);
3185 if (len <= bp->rx_copy_thresh) {
3186 skb = netdev_alloc_skb(bp->
dev, len + 6);
3188 bnx2_reuse_rx_data(bp, rxr, data, sw_ring_cons,
3197 skb_reserve(skb, 6);
3200 bnx2_reuse_rx_data(bp, rxr, data,
3201 sw_ring_cons, sw_ring_prod);
3204 skb = bnx2_rx_skb(bp, rxr, data, len, hdr_len, dma_addr,
3205 (sw_ring_cons << 16) | sw_ring_prod);
3211 __vlan_hwaccel_put_tag(skb, rx_hdr->l2_fhdr_vlan_tag);
3223 skb_checksum_none_assert(skb);
3234 L2_FHDR_STATUS_USE_RXHASH))
3237 skb_record_rx_queue(skb, bnapi - &bp->
bnx2_napi[0]);
3245 if ((rx_pkt == budget))
3249 if (sw_cons == hw_cons) {
3250 hw_cons = bnx2_get_hw_rx_cons(bnapi);
3274 bnx2_msi(
int irq,
void *dev_instance)
3277 struct bnx2 *bp = bnapi->
bp;
3288 napi_schedule(&bnapi->napi);
3294 bnx2_msi_1shot(
int irq,
void *dev_instance)
3297 struct bnx2 *bp = bnapi->
bp;
3305 napi_schedule(&bnapi->napi);
3311 bnx2_interrupt(
int irq,
void *dev_instance)
3314 struct bnx2 *bp = bnapi->
bp;
3341 if (napi_schedule_prep(&bnapi->napi)) {
3350 bnx2_has_fast_work(
struct bnx2_napi *bnapi)
3355 if ((bnx2_get_hw_rx_cons(bnapi) != rxr->
rx_cons) ||
3356 (bnx2_get_hw_tx_cons(bnapi) != txr->
hw_tx_cons))
3361 #define STATUS_ATTN_EVENTS (STATUS_ATTN_BITS_LINK_STATE | \
3362 STATUS_ATTN_BITS_TIMER_ABORT)
3369 if (bnx2_has_fast_work(bnapi))
3373 if (bnapi->cnic_present && (bnapi->cnic_tag != sblk->status_idx))
3385 bnx2_chk_missed_msi(
struct bnx2 *bp)
3390 if (bnx2_has_work(bnapi)) {
3397 ~BNX2_PCICFG_MSI_CONTROL_ENABLE);
3399 bnx2_msi(bp->
irq_tbl[0].vector, bnapi);
3407 static void bnx2_poll_cnic(
struct bnx2 *bp,
struct bnx2_napi *bnapi)
3411 if (!bnapi->cnic_present)
3423 static void bnx2_poll_link(
struct bnx2 *bp,
struct bnx2_napi *bnapi)
3430 (status_attn_bits_ack & STATUS_ATTN_EVENTS)) {
3432 bnx2_phy_int(bp, bnapi);
3443 static int bnx2_poll_work(
struct bnx2 *bp,
struct bnx2_napi *bnapi,
3444 int work_done,
int budget)
3449 if (bnx2_get_hw_tx_cons(bnapi) != txr->
hw_tx_cons)
3450 bnx2_tx_int(bp, bnapi, 0);
3452 if (bnx2_get_hw_rx_cons(bnapi) != rxr->
rx_cons)
3453 work_done += bnx2_rx_int(bp, bnapi, budget - work_done);
3461 struct bnx2 *bp = bnapi->
bp;
3466 work_done = bnx2_poll_work(bp, bnapi, work_done, budget);
3473 if (
likely(!bnx2_has_fast_work(bnapi))) {
3485 static int bnx2_poll(
struct napi_struct *napi,
int budget)
3488 struct bnx2 *bp = bnapi->
bp;
3493 bnx2_poll_link(bp, bnapi);
3495 work_done = bnx2_poll_work(bp, bnapi, work_done, budget);
3498 bnx2_poll_cnic(bp, bnapi);
3511 if (
likely(!bnx2_has_work(bnapi))) {
3540 struct bnx2 *bp = netdev_priv(dev);
3545 if (!netif_running(dev))
3576 memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
3581 regidx = (bit & 0xe0) >> 5;
3583 mc_filter[regidx] |= (1 <<
bit);
3602 bnx2_set_mac_addr(bp, ha->
addr,
3631 if ((offset == 0 && len != 0) || offset >= fw->
size || offset & 3)
3633 if ((non_empty && len == 0) || len > fw->
size - offset ||
3634 len & (alignment - 1))
3640 check_mips_fw_entry(
const struct firmware *fw,
3643 if (check_fw_section(fw, &entry->
text, 4,
true) ||
3644 check_fw_section(fw, &entry->
data, 4,
false) ||
3645 check_fw_section(fw, &entry->
rodata, 4,
false))
3650 static void bnx2_release_firmware(
struct bnx2 *bp)
3659 static int bnx2_request_uncached_firmware(
struct bnx2 *bp)
3661 const char *mips_fw_file, *rv2p_fw_file;
3680 pr_err(
"Can't load firmware file \"%s\"\n", mips_fw_file);
3686 pr_err(
"Can't load firmware file \"%s\"\n", rv2p_fw_file);
3687 goto err_release_mips_firmware;
3697 pr_err(
"Firmware file \"%s\" is invalid\n", mips_fw_file);
3699 goto err_release_firmware;
3704 pr_err(
"Firmware file \"%s\" is invalid\n", rv2p_fw_file);
3706 goto err_release_firmware;
3711 err_release_firmware:
3714 err_release_mips_firmware:
3719 static int bnx2_request_firmware(
struct bnx2 *bp)
3721 return bp->
rv2p_firmware ? 0 : bnx2_request_uncached_firmware(bp);
3737 load_rv2p_fw(
struct bnx2 *bp,
u32 rv2p_proc,
3758 for (i = 0; i < rv2p_code_len; i += 8) {
3764 val = (i / 8) | cmd;
3769 for (i = 0; i < 8; i++) {
3773 if (loc && ((loc * 4) < rv2p_code_len)) {
3777 code = rv2p_fw_fixup(rv2p_proc, i, loc, code);
3780 val = (loc / 2) | cmd;
3806 val = bnx2_reg_rd_ind(bp, cpu_reg->
mode);
3808 bnx2_reg_wr_ind(bp, cpu_reg->
mode, val);
3821 for (j = 0; j < (len / 4); j++, offset += 4)
3822 bnx2_reg_wr_ind(bp, offset,
be32_to_cpu(data[j]));
3835 for (j = 0; j < (len / 4); j++, offset += 4)
3836 bnx2_reg_wr_ind(bp, offset,
be32_to_cpu(data[j]));
3849 for (j = 0; j < (len / 4); j++, offset += 4)
3850 bnx2_reg_wr_ind(bp, offset,
be32_to_cpu(data[j]));
3854 bnx2_reg_wr_ind(bp, cpu_reg->
inst, 0);
3857 bnx2_reg_wr_ind(bp, cpu_reg->
pc, val);
3860 val = bnx2_reg_rd_ind(bp, cpu_reg->
mode);
3863 bnx2_reg_wr_ind(bp, cpu_reg->
mode, val);
3869 bnx2_init_cpus(
struct bnx2 *bp)
3882 rc = load_cpu_fw(bp, &cpu_reg_rxp, &mips_fw->
rxp);
3887 rc = load_cpu_fw(bp, &cpu_reg_txp, &mips_fw->
txp);
3892 rc = load_cpu_fw(bp, &cpu_reg_tpat, &mips_fw->
tpat);
3897 rc = load_cpu_fw(bp, &cpu_reg_com, &mips_fw->
com);
3902 rc = load_cpu_fw(bp, &cpu_reg_cp, &mips_fw->
cp);
3964 bnx2_set_mac_addr(bp, bp->
dev->dev_addr, 0);
4047 bnx2_acquire_nvram_lock(
struct bnx2 *bp)
4062 if (j >= NVRAM_TIMEOUT_COUNT)
4069 bnx2_release_nvram_lock(
struct bnx2 *bp)
4085 if (j >= NVRAM_TIMEOUT_COUNT)
4093 bnx2_enable_nvram_write(
struct bnx2 *bp)
4115 if (j >= NVRAM_TIMEOUT_COUNT)
4122 bnx2_disable_nvram_write(
struct bnx2 *bp)
4132 bnx2_enable_nvram_access(
struct bnx2 *bp)
4143 bnx2_disable_nvram_access(
struct bnx2 *bp)
4155 bnx2_nvram_erase_page(
struct bnx2 *bp,
u32 offset)
4188 if (j >= NVRAM_TIMEOUT_COUNT)
4195 bnx2_nvram_read_dword(
struct bnx2 *bp,
u32 offset,
u8 *ret_val,
u32 cmd_flags)
4205 offset = ((offset / bp->
flash_info->page_size) <<
4232 if (j >= NVRAM_TIMEOUT_COUNT)
4240 bnx2_nvram_write_dword(
struct bnx2 *bp,
u32 offset,
u8 *val,
u32 cmd_flags)
4251 offset = ((offset / bp->
flash_info->page_size) <<
4277 if (j >= NVRAM_TIMEOUT_COUNT)
4284 bnx2_init_nvram(
struct bnx2 *bp)
4292 goto get_flash_size;
4300 if (val & 0x40000000) {
4303 for (j = 0, flash = &flash_table[0]; j <
entry_count;
4306 (flash->
config1 & FLASH_BACKUP_STRAP_MASK)) {
4316 if (val & (1 << 23))
4321 for (j = 0, flash = &flash_table[0]; j <
entry_count;
4324 if ((val & mask) == (flash->
strapping & mask)) {
4328 if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
4332 bnx2_enable_nvram_access(bp);
4341 bnx2_disable_nvram_access(bp);
4342 bnx2_release_nvram_lock(bp);
4349 if (j == entry_count) {
4351 pr_alert(
"Unknown flash/EEPROM type\n");
4367 bnx2_nvram_read(
struct bnx2 *bp,
u32 offset,
u8 *ret_buf,
4377 if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
4381 bnx2_enable_nvram_access(bp);
4394 pre_len = 4 - (offset & 3);
4396 if (pre_len >= len32) {
4405 rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
4410 memcpy(ret_buf, buf + (offset & 3), pre_len);
4417 extra = 4 - (len32 & 3);
4418 len32 = (len32 + 4) & ~3;
4430 rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
4432 memcpy(ret_buf, buf, 4 - extra);
4434 else if (len32 > 0) {
4443 rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
4450 while (len32 > 4 && rc == 0) {
4451 rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
4463 rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
4465 memcpy(ret_buf, buf, 4 - extra);
4469 bnx2_disable_nvram_access(bp);
4471 bnx2_release_nvram_lock(bp);
4483 int align_start, align_end;
4488 align_start = align_end = 0;
4490 if ((align_start = (offset32 & 3))) {
4492 len32 += align_start;
4495 if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
4500 align_end = 4 - (len32 & 3);
4502 if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4, end, 4)))
4506 if (align_start || align_end) {
4508 if (align_buf ==
NULL)
4511 memcpy(align_buf, start, 4);
4514 memcpy(align_buf + len32 - 4, end, 4);
4516 memcpy(align_buf + align_start, data_buf, buf_size);
4522 if (flash_buffer ==
NULL) {
4524 goto nvram_write_end;
4529 while ((written < len32) && (rc == 0)) {
4535 page_start = offset32 + written;
4536 page_start -= (page_start % bp->
flash_info->page_size);
4538 page_end = page_start + bp->
flash_info->page_size;
4540 data_start = (written == 0) ? offset32 : page_start;
4542 data_end = (page_end > offset32 + len32) ?
4543 (offset32 + len32) : page_end;
4546 if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
4547 goto nvram_write_end;
4550 bnx2_enable_nvram_access(bp);
4558 for (j = 0; j < bp->
flash_info->page_size; j += 4) {
4562 rc = bnx2_nvram_read_dword(bp,
4568 goto nvram_write_end;
4575 if ((rc = bnx2_enable_nvram_write(bp)) != 0)
4576 goto nvram_write_end;
4583 if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
4584 goto nvram_write_end;
4587 bnx2_enable_nvram_write(bp);
4589 for (addr = page_start; addr < data_start;
4590 addr += 4, i += 4) {
4592 rc = bnx2_nvram_write_dword(bp, addr,
4593 &flash_buffer[i], cmd_flags);
4596 goto nvram_write_end;
4603 for (addr = data_start; addr < data_end; addr += 4, i += 4) {
4604 if ((addr == page_end - 4) ||
4606 (addr == data_end - 4))) {
4610 rc = bnx2_nvram_write_dword(bp, addr, buf,
4614 goto nvram_write_end;
4623 for (addr = data_end; addr < page_end;
4624 addr += 4, i += 4) {
4626 if (addr == page_end-4) {
4629 rc = bnx2_nvram_write_dword(bp, addr,
4630 &flash_buffer[i], cmd_flags);
4633 goto nvram_write_end;
4640 bnx2_disable_nvram_write(bp);
4643 bnx2_disable_nvram_access(bp);
4644 bnx2_release_nvram_lock(bp);
4647 written += data_end - data_start;
4651 kfree(flash_buffer);
4657 bnx2_init_fw_cap(
struct bnx2 *bp)
4683 if (link & BNX2_LINK_STATUS_SERDES_LINK)
4692 if (netif_running(bp->
dev) && sig)
4697 bnx2_setup_msix_tbl(
struct bnx2 *bp)
4706 bnx2_reset_chip(
struct bnx2 *bp,
u32 reset_code)
4729 for (i = 0; i < 100; i++) {
4776 for (i = 0; i < 10; i++) {
4786 pr_err(
"Chip reset did not complete\n");
4793 if (val != 0x01020304) {
4794 pr_err(
"Chip not in correct endian mode\n");
4805 bnx2_init_fw_cap(bp);
4808 bnx2_set_default_remote_link(bp);
4817 rc = bnx2_alloc_bad_rbuf(bp);
4821 bnx2_setup_msix_tbl(bp);
4831 bnx2_init_chip(
struct bnx2 *bp)
4848 val |= (0x2 << 20) | (1 << 11);
4882 rc = bnx2_init_5709_context(bp);
4886 bnx2_init_context(bp);
4888 if ((rc = bnx2_init_cpus(bp)) != 0)
4891 bnx2_init_nvram(bp);
4893 bnx2_set_mac_addr(bp, bp->
dev->dev_addr, 0);
5040 bnx2_set_rx_mode(bp->
dev);
5061 bnx2_clear_ring_states(
struct bnx2 *bp)
5101 bnx2_ctx_wr(bp, cid_addr, offset0, val);
5104 bnx2_ctx_wr(bp, cid_addr, offset1, val);
5107 bnx2_ctx_wr(bp, cid_addr, offset2, val);
5110 bnx2_ctx_wr(bp, cid_addr, offset3, val);
5114 bnx2_init_tx_ring(
struct bnx2 *bp,
int ring_num)
5142 bnx2_init_tx_context(bp, cid, txr);
5152 for (i = 0; i < num_rings; i++) {
5155 rxbd = &rx_ring[
i][0];
5160 if (i == (num_rings - 1))
5170 bnx2_init_rx_ring(
struct bnx2 *bp,
int ring_num)
5173 u16 prod, ring_prod;
5188 bnx2_init_rx_context(bp, cid);
5223 if (bnx2_alloc_rx_page(bp, rxr, ring_prod,
GFP_KERNEL) < 0) {
5224 netdev_warn(bp->
dev,
"init'ed rx page ring %d with %d/%d pages only\n",
5233 ring_prod = prod = rxr->
rx_prod;
5235 if (bnx2_alloc_rx_data(bp, rxr, ring_prod,
GFP_KERNEL) < 0) {
5236 netdev_warn(bp->
dev,
"init'ed rx ring %d with %d/%d skbs only\n",
5256 bnx2_init_all_rings(
struct bnx2 *bp)
5261 bnx2_clear_ring_states(bp);
5265 bnx2_init_tx_ring(bp, i);
5275 bnx2_init_rx_ring(bp, i);
5281 int shift = (i % 8) << 2;
5306 while (ring_size > MAX_RX_DESC_CNT) {
5312 while ((max & num_rings) == 0)
5315 if (num_rings != max)
5324 u32 rx_size, rx_space, jumbo_size;
5339 jumbo_size = size *
pages;
5362 bnx2_free_tx_skbs(
struct bnx2 *bp)
5393 for (k = 0; k < last; k++, j =
NEXT_TX_BD(j)) {
5397 skb_frag_size(&skb_shinfo(skb)->frags[k]),
5402 netdev_tx_reset_queue(netdev_get_tx_queue(bp->
dev, i));
5407 bnx2_free_rx_skbs(
struct bnx2 *bp)
5436 bnx2_free_rx_page(bp, rxr, j);
5441 bnx2_free_skbs(
struct bnx2 *bp)
5443 bnx2_free_tx_skbs(bp);
5444 bnx2_free_rx_skbs(bp);
5448 bnx2_reset_nic(
struct bnx2 *bp,
u32 reset_code)
5452 rc = bnx2_reset_chip(bp, reset_code);
5457 if ((rc = bnx2_init_chip(bp)) != 0)
5460 bnx2_init_all_rings(bp);
5465 bnx2_init_nic(
struct bnx2 *bp,
int reset_phy)
5473 bnx2_init_phy(bp, reset_phy);
5476 bnx2_remote_phy_event(bp);
5482 bnx2_shutdown_chip(
struct bnx2 *bp)
5493 return bnx2_reset_chip(bp, reset_code);
5497 bnx2_test_registers(
struct bnx2 *bp)
5501 static const struct {
5504 #define BNX2_FL_NOT_5709 1
5508 { 0x006c, 0, 0x00000000, 0x0000003f },
5509 { 0x0090, 0, 0xffffffff, 0x00000000 },
5510 { 0x0094, 0, 0x00000000, 0x00000000 },
5533 { 0x1000, 0, 0x00000000, 0x00000001 },
5536 { 0x1408, 0, 0x01c00800, 0x00000000 },
5537 { 0x149c, 0, 0x8000ffff, 0x00000000 },
5538 { 0x14a8, 0, 0x00000000, 0x000001ff },
5539 { 0x14ac, 0, 0x0fffffff, 0x10000000 },
5540 { 0x14b0, 0, 0x00000002, 0x00000001 },
5541 { 0x14b8, 0, 0x00000000, 0x00000000 },
5542 { 0x14c0, 0, 0x00000000, 0x00000009 },
5543 { 0x14c4, 0, 0x00003fff, 0x00000000 },
5544 { 0x14cc, 0, 0x00000000, 0x00000001 },
5545 { 0x14d0, 0, 0xffffffff, 0x00000000 },
5547 { 0x1800, 0, 0x00000000, 0x00000001 },
5548 { 0x1804, 0, 0x00000000, 0x00000003 },
5550 { 0x2800, 0, 0x00000000, 0x00000001 },
5551 { 0x2804, 0, 0x00000000, 0x00003f01 },
5552 { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
5553 { 0x2810, 0, 0xffff0000, 0x00000000 },
5554 { 0x2814, 0, 0xffff0000, 0x00000000 },
5555 { 0x2818, 0, 0xffff0000, 0x00000000 },
5556 { 0x281c, 0, 0xffff0000, 0x00000000 },
5557 { 0x2834, 0, 0xffffffff, 0x00000000 },
5558 { 0x2840, 0, 0x00000000, 0xffffffff },
5559 { 0x2844, 0, 0x00000000, 0xffffffff },
5560 { 0x2848, 0, 0xffffffff, 0x00000000 },
5561 { 0x284c, 0, 0xf800f800, 0x07ff07ff },
5563 { 0x2c00, 0, 0x00000000, 0x00000011 },
5564 { 0x2c04, 0, 0x00000000, 0x00030007 },
5566 { 0x3c00, 0, 0x00000000, 0x00000001 },
5567 { 0x3c04, 0, 0x00000000, 0x00070000 },
5568 { 0x3c08, 0, 0x00007f71, 0x07f00000 },
5569 { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
5570 { 0x3c10, 0, 0xffffffff, 0x00000000 },
5571 { 0x3c14, 0, 0x00000000, 0xffffffff },
5572 { 0x3c18, 0, 0x00000000, 0xffffffff },
5573 { 0x3c1c, 0, 0xfffff000, 0x00000000 },
5574 { 0x3c20, 0, 0xffffff00, 0x00000000 },
5576 { 0x5004, 0, 0x00000000, 0x0000007f },
5577 { 0x5008, 0, 0x0f0007ff, 0x00000000 },
5579 { 0x5c00, 0, 0x00000000, 0x00000001 },
5580 { 0x5c04, 0, 0x00000000, 0x0003000f },
5581 { 0x5c08, 0, 0x00000003, 0x00000000 },
5582 { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
5583 { 0x5c10, 0, 0x00000000, 0xffffffff },
5584 { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
5585 { 0x5c84, 0, 0x00000000, 0x0000f333 },
5586 { 0x5c88, 0, 0x00000000, 0x00077373 },
5587 { 0x5c8c, 0, 0x00000000, 0x0007f737 },
5589 { 0x6808, 0, 0x0000ff7f, 0x00000000 },
5590 { 0x680c, 0, 0xffffffff, 0x00000000 },
5591 { 0x6810, 0, 0xffffffff, 0x00000000 },
5592 { 0x6814, 0, 0xffffffff, 0x00000000 },
5593 { 0x6818, 0, 0xffffffff, 0x00000000 },
5594 { 0x681c, 0, 0xffffffff, 0x00000000 },
5595 { 0x6820, 0, 0x00ff00ff, 0x00000000 },
5596 { 0x6824, 0, 0x00ff00ff, 0x00000000 },
5597 { 0x6828, 0, 0x00ff00ff, 0x00000000 },
5598 { 0x682c, 0, 0x03ff03ff, 0x00000000 },
5599 { 0x6830, 0, 0x03ff03ff, 0x00000000 },
5600 { 0x6834, 0, 0x03ff03ff, 0x00000000 },
5601 { 0x6838, 0, 0x03ff03ff, 0x00000000 },
5602 { 0x683c, 0, 0x0000ffff, 0x00000000 },
5603 { 0x6840, 0, 0x00000ff0, 0x00000000 },
5604 { 0x6844, 0, 0x00ffff00, 0x00000000 },
5605 { 0x684c, 0, 0xffffffff, 0x00000000 },
5606 { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
5607 { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
5608 { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
5609 { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
5610 { 0x6908, 0, 0x00000000, 0x0001ff0f },
5611 { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
5613 { 0xffff, 0, 0x00000000, 0x00000000 },
5621 for (i = 0; reg_tbl[
i].offset != 0xffff; i++) {
5625 if (is_5709 && (flags & BNX2_FL_NOT_5709))
5628 offset = (
u32) reg_tbl[i].offset;
5629 rw_mask = reg_tbl[
i].rw_mask;
5630 ro_mask = reg_tbl[
i].ro_mask;
5637 if ((val & rw_mask) != 0) {
5641 if ((val & ro_mask) != (save_val & ro_mask)) {
5648 if ((val & rw_mask) != rw_mask) {
5652 if ((val & ro_mask) != (save_val & ro_mask)) {
5668 bnx2_do_mem_test(
struct bnx2 *bp,
u32 start,
u32 size)
5670 static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
5671 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
5674 for (i = 0; i <
sizeof(test_pattern) / 4; i++) {
5677 for (offset = 0; offset <
size; offset += 4) {
5679 bnx2_reg_wr_ind(bp, start + offset, test_pattern[i]);
5681 if (bnx2_reg_rd_ind(bp, start + offset) !=
5691 bnx2_test_memory(
struct bnx2 *bp)
5695 static struct mem_entry {
5698 } mem_tbl_5706[] = {
5699 { 0x60000, 0x4000 },
5700 { 0xa0000, 0x3000 },
5701 { 0xe0000, 0x4000 },
5702 { 0x120000, 0x4000 },
5703 { 0x1a0000, 0x4000 },
5704 { 0x160000, 0x4000 },
5708 { 0x60000, 0x4000 },
5709 { 0xa0000, 0x3000 },
5710 { 0xe0000, 0x4000 },
5711 { 0x120000, 0x4000 },
5712 { 0x1a0000, 0x4000 },
5715 struct mem_entry *mem_tbl;
5718 mem_tbl = mem_tbl_5709;
5720 mem_tbl = mem_tbl_5706;
5722 for (i = 0; mem_tbl[
i].offset != 0xffffffff; i++) {
5723 if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
5724 mem_tbl[i].len)) != 0) {
5732 #define BNX2_MAC_LOOPBACK 0
5733 #define BNX2_PHY_LOOPBACK 1
5736 bnx2_run_loopback(
struct bnx2 *bp,
int loopback_mode)
5738 unsigned int pkt_size, num_pkts,
i;
5742 u16 rx_start_idx, rx_idx;
5745 struct sw_bd *rx_buf;
5754 txr = &tx_napi->tx_ring;
5758 bnx2_set_mac_loopback(bp);
5765 bnx2_set_phy_loopback(bp);
5771 skb = netdev_alloc_skb(bp->
dev, pkt_size);
5774 packet =
skb_put(skb, pkt_size);
5776 memset(packet + 6, 0x0, 8);
5777 for (i = 14; i < pkt_size; i++)
5778 packet[i] = (
unsigned char) (i & 0xff);
5793 rx_start_idx = bnx2_get_hw_rx_cons(bnapi);
5823 if (bnx2_get_hw_tx_cons(tx_napi) != txr->
tx_prod)
5824 goto loopback_test_done;
5826 rx_idx = bnx2_get_hw_rx_cons(bnapi);
5827 if (rx_idx != rx_start_idx + num_pkts) {
5828 goto loopback_test_done;
5832 data = rx_buf->
data;
5834 rx_hdr = get_l2_fhdr(data);
5835 data = (
u8 *)rx_hdr + BNX2_RX_OFFSET;
5848 goto loopback_test_done;
5851 if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
5852 goto loopback_test_done;
5855 for (i = 14; i < pkt_size; i++) {
5856 if (*(data + i) != (
unsigned char) (i & 0xff)) {
5857 goto loopback_test_done;
5868 #define BNX2_MAC_LOOPBACK_FAILED 1
5869 #define BNX2_PHY_LOOPBACK_FAILED 2
5870 #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
5871 BNX2_PHY_LOOPBACK_FAILED)
5874 bnx2_test_loopback(
struct bnx2 *bp)
5878 if (!netif_running(bp->
dev))
5883 bnx2_init_phy(bp, 1);
5892 #define NVRAM_SIZE 0x200
5893 #define CRC32_RESIDUAL 0xdebb20e3
5896 bnx2_test_nvram(
struct bnx2 *bp)
5899 u8 *data = (
u8 *) buf;
5903 if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
5904 goto test_nvram_done;
5907 if (magic != 0x669955aa) {
5909 goto test_nvram_done;
5912 if ((rc = bnx2_nvram_read(bp, 0x100, data,
NVRAM_SIZE)) != 0)
5913 goto test_nvram_done;
5918 goto test_nvram_done;
5931 bnx2_test_link(
struct bnx2 *bp)
5935 if (!netif_running(bp->
dev))
5944 bnx2_enable_bmsr1(bp);
5945 bnx2_read_phy(bp, bp->
mii_bmsr1, &bmsr);
5946 bnx2_read_phy(bp, bp->
mii_bmsr1, &bmsr);
5947 bnx2_disable_bmsr1(bp);
5950 if (bmsr & BMSR_LSTATUS) {
5957 bnx2_test_intr(
struct bnx2 *bp)
5962 if (!netif_running(bp->
dev))
5971 for (i = 0; i < 10; i++) {
5988 bnx2_5706_serdes_has_link(
struct bnx2 *bp)
5990 u32 mode_ctl, an_dbg,
exp;
6019 bnx2_5706_serdes_timer(
struct bnx2 *bp)
6032 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
6034 if (bmcr & BMCR_ANENABLE) {
6035 if (bnx2_5706_serdes_has_link(bp)) {
6036 bmcr &= ~BMCR_ANENABLE;
6038 bnx2_write_phy(bp, bp->
mii_bmcr, bmcr);
6047 bnx2_write_phy(bp, 0x17, 0x0f01);
6048 bnx2_read_phy(bp, 0x15, &phy2);
6052 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
6054 bnx2_write_phy(bp, bp->
mii_bmcr, bmcr);
6070 bnx2_5706s_force_link_dn(bp, 1);
6074 }
else if (!bp->
link_up && !(val & MISC_SHDW_AN_DBG_NOSYNC))
6081 bnx2_5708_serdes_timer(
struct bnx2 *bp)
6097 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
6098 if (bmcr & BMCR_ANENABLE) {
6099 bnx2_enable_forced_2g5(bp);
6102 bnx2_disable_forced_2g5(bp);
6114 bnx2_timer(
unsigned long data)
6116 struct bnx2 *bp = (
struct bnx2 *) data;
6118 if (!netif_running(bp->
dev))
6122 goto bnx2_restart_timer;
6126 bnx2_chk_missed_msi(bp);
6128 bnx2_send_heart_beat(bp);
6140 bnx2_5706_serdes_timer(bp);
6142 bnx2_5708_serdes_timer(bp);
6150 bnx2_request_irq(
struct bnx2 *bp)
6152 unsigned long flags;
6173 __bnx2_free_irq(
struct bnx2 *bp)
6187 bnx2_free_irq(
struct bnx2 *bp)
6190 __bnx2_free_irq(bp);
6200 bnx2_enable_msix(
struct bnx2 *bp,
int msix_vecs)
6202 int i, total_vecs,
rc;
6203 struct msix_entry msix_ent[BNX2_MAX_MSIX_VEC];
6205 const int len =
sizeof(bp->
irq_tbl[0].name);
6207 bnx2_setup_msix_tbl(bp);
6217 msix_ent[
i].entry =
i;
6218 msix_ent[
i].vector = 0;
6221 total_vecs = msix_vecs;
6237 msix_vecs = total_vecs;
6243 for (i = 0; i < total_vecs; i++) {
6244 bp->
irq_tbl[
i].vector = msix_ent[
i].vector;
6246 bp->
irq_tbl[
i].handler = bnx2_msi_1shot;
6251 bnx2_setup_int_mode(
struct bnx2 *bp,
int dis_msi)
6265 bp->
irq_tbl[0].handler = bnx2_interrupt;
6271 bnx2_enable_msix(bp, msix_vecs);
6275 if (pci_enable_msi(bp->
pdev) == 0) {
6279 bp->
irq_tbl[0].handler = bnx2_msi_1shot;
6281 bp->
irq_tbl[0].handler = bnx2_msi;
6306 struct bnx2 *bp = netdev_priv(dev);
6309 rc = bnx2_request_firmware(bp);
6315 bnx2_set_power_state(bp,
PCI_D0);
6316 bnx2_disable_int(bp);
6318 rc = bnx2_setup_int_mode(bp, disable_msi);
6322 bnx2_napi_enable(bp);
6323 rc = bnx2_alloc_mem(bp);
6327 rc = bnx2_request_irq(bp);
6331 rc = bnx2_init_nic(bp, 1);
6341 bnx2_enable_int(bp);
6347 if (bnx2_test_intr(bp) != 0) {
6348 netdev_warn(bp->
dev,
"No interrupt was generated using MSI, switching to INTx mode. Please report this failure to the PCI maintainer and include system chipset information.\n");
6350 bnx2_disable_int(bp);
6353 bnx2_setup_int_mode(bp, 1);
6355 rc = bnx2_init_nic(bp, 0);
6358 rc = bnx2_request_irq(bp);
6364 bnx2_enable_int(bp);
6368 netdev_info(dev,
"using MSI\n");
6370 netdev_info(dev,
"using MSIX\n");
6372 netif_tx_start_all_queues(dev);
6377 bnx2_napi_disable(bp);
6382 bnx2_release_firmware(bp);
6394 if (!netif_running(bp->
dev)) {
6399 bnx2_netif_stop(bp,
true);
6407 rc = bnx2_init_nic(bp, 1);
6409 netdev_err(bp->
dev,
"failed to reset NIC, closing\n");
6410 bnx2_napi_enable(bp);
6417 bnx2_netif_start(bp,
true);
6421 #define BNX2_FTQ_ENTRY(ftq) { __stringify(ftq##FTQ_CTL), BNX2_##ftq##FTQ_CTL }
6424 bnx2_dump_ftq(
struct bnx2 *bp)
6429 static const struct ftq_reg {
6449 netdev_err(dev,
"<--- start FTQ dump --->\n");
6451 netdev_err(dev,
"%s %08x\n", ftq_arr[i].
name,
6452 bnx2_reg_rd_ind(bp, ftq_arr[i].off));
6454 netdev_err(dev,
"CPU states:\n");
6456 netdev_err(dev,
"%06x mode %x state %x evt_mask %x pc %x pc %x instr %x\n",
6457 reg, bnx2_reg_rd_ind(bp, reg),
6458 bnx2_reg_rd_ind(bp, reg + 4),
6459 bnx2_reg_rd_ind(bp, reg + 8),
6460 bnx2_reg_rd_ind(bp, reg + 0x1c),
6461 bnx2_reg_rd_ind(bp, reg + 0x1c),
6462 bnx2_reg_rd_ind(bp, reg + 0x20));
6464 netdev_err(dev,
"<--- end FTQ dump --->\n");
6465 netdev_err(dev,
"<--- start TBDC dump --->\n");
6466 netdev_err(dev,
"TBDC free cnt: %ld\n",
6468 netdev_err(dev,
"LINE CID BIDX CMD VALIDS\n");
6469 for (i = 0; i < 0x20; i++) {
6483 netdev_err(dev,
"%02x %06x %04lx %02x [%x]\n",
6485 bdidx >> 24, (valid >> 8) & 0x0ff);
6487 netdev_err(dev,
"<--- end TBDC dump --->\n");
6491 bnx2_dump_state(
struct bnx2 *bp)
6497 netdev_err(dev,
"DEBUG: intr_sem[%x] PCI_CMD[%08x]\n",
6501 netdev_err(dev,
"DEBUG: PCI_PM[%08x] PCI_MISC_CFG[%08x]\n", val1, val2);
6502 netdev_err(dev,
"DEBUG: EMAC_TX_STATUS[%08x] EMAC_RX_STATUS[%08x]\n",
6505 netdev_err(dev,
"DEBUG: RPM_MGMT_PKT_CTRL[%08x]\n",
6507 netdev_err(dev,
"DEBUG: HC_STATS_INTERRUPT_STATUS[%08x]\n",
6510 netdev_err(dev,
"DEBUG: PBA[%08x]\n",
6517 struct bnx2 *bp = netdev_priv(dev);
6520 bnx2_dump_state(bp);
6521 bnx2_dump_mcp_state(bp);
6534 struct bnx2 *bp = netdev_priv(dev);
6538 u32 len, vlan_tag_flags, last_frag,
mss;
6539 u16 prod, ring_prod;
6546 i = skb_get_queue_mapping(skb);
6549 txq = netdev_get_tx_queue(dev, i);
6551 if (
unlikely(bnx2_tx_avail(bp, txr) <
6552 (skb_shinfo(skb)->nr_frags + 1))) {
6553 netif_tx_stop_queue(txq);
6554 netdev_err(dev,
"BUG! Tx ring full when queue awake!\n");
6558 len = skb_headlen(skb);
6572 if ((mss = skb_shinfo(skb)->gso_size)) {
6578 tcp_opt_len = tcp_optlen(skb);
6581 u32 tcp_off = skb_transport_offset(skb) -
6584 vlan_tag_flags |= ((tcp_opt_len >> 2) << 8) |
6586 if (
likely(tcp_off == 0))
6590 vlan_tag_flags |= ((tcp_off & 0x3) <<
6592 ((tcp_off & 0x10) <<
6598 if (tcp_opt_len || (iph->ihl > 5)) {
6599 vlan_tag_flags |= ((iph->ihl - 5) +
6600 (tcp_opt_len >> 2)) << 8;
6623 last_frag = skb_shinfo(skb)->nr_frags;
6625 tx_buf->
is_gso = skb_is_gso(skb);
6627 for (i = 0; i < last_frag; i++) {
6634 len = skb_frag_size(frag);
6635 mapping = skb_frag_dma_map(&bp->
pdev->dev, frag, 0, len,
6653 netdev_tx_sent_queue(txq, skb->
len);
6666 netif_tx_stop_queue(txq);
6675 netif_tx_wake_queue(txq);
6692 for (i = 0; i < last_frag; i++) {
6697 skb_frag_size(&skb_shinfo(skb)->frags[i]),
6709 struct bnx2 *bp = netdev_priv(dev);
6711 bnx2_disable_int_sync(bp);
6712 bnx2_napi_disable(bp);
6713 netif_tx_disable(dev);
6715 bnx2_shutdown_chip(bp);
6727 bnx2_save_stats(
struct bnx2 *bp)
6734 for (i = 0; i < 20; i += 2) {
6738 hi = temp_stats[
i] + hw_stats[
i];
6739 lo = (
u64) temp_stats[i + 1] + (
u64) hw_stats[i + 1];
6740 if (lo > 0xffffffff)
6743 temp_stats[i + 1] = lo & 0xffffffff;
6747 temp_stats[i] += hw_stats[i];
6750 #define GET_64BIT_NET_STATS64(ctr) \
6751 (((u64) (ctr##_hi) << 32) + (u64) (ctr##_lo))
6753 #define GET_64BIT_NET_STATS(ctr) \
6754 GET_64BIT_NET_STATS64(bp->stats_blk->ctr) + \
6755 GET_64BIT_NET_STATS64(bp->temp_stats_blk->ctr)
6757 #define GET_32BIT_NET_STATS(ctr) \
6758 (unsigned long) (bp->stats_blk->ctr + \
6759 bp->temp_stats_blk->ctr)
6764 struct bnx2 *bp = netdev_priv(dev);
6839 struct bnx2 *bp = netdev_priv(dev);
6840 int support_serdes = 0, support_copper = 0;
6851 if (support_serdes) {
6858 if (support_copper) {
6878 if (netif_carrier_ok(dev)) {
6883 ethtool_cmd_speed_set(cmd, -1);
6897 struct bnx2 *bp = netdev_priv(dev);
6907 goto err_out_unlock;
6911 goto err_out_unlock;
6917 goto err_out_unlock;
6935 u32 speed = ethtool_cmd_speed(cmd);
6940 goto err_out_unlock;
6944 goto err_out_unlock;
6946 goto err_out_unlock;
6949 req_line_speed = speed;
6950 req_duplex = cmd->
duplex;
6963 if (netif_running(dev))
6964 err = bnx2_setup_phy(bp, cmd->
port);
6975 struct bnx2 *bp = netdev_priv(dev);
6983 #define BNX2_REGDUMP_LEN (32 * 1024)
6996 struct bnx2 *bp = netdev_priv(dev);
6997 static const u32 reg_boundaries[] = {
6998 0x0000, 0x0098, 0x0400, 0x045c,
6999 0x0800, 0x0880, 0x0c00, 0x0c10,
7000 0x0c30, 0x0d08, 0x1000, 0x101c,
7001 0x1040, 0x1048, 0x1080, 0x10a4,
7002 0x1400, 0x1490, 0x1498, 0x14f0,
7003 0x1500, 0x155c, 0x1580, 0x15dc,
7004 0x1600, 0x1658, 0x1680, 0x16d8,
7005 0x1800, 0x1820, 0x1840, 0x1854,
7006 0x1880, 0x1894, 0x1900, 0x1984,
7007 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
7008 0x1c80, 0x1c94, 0x1d00, 0x1d84,
7009 0x2000, 0x2030, 0x23c0, 0x2400,
7010 0x2800, 0x2820, 0x2830, 0x2850,
7011 0x2b40, 0x2c10, 0x2fc0, 0x3058,
7012 0x3c00, 0x3c94, 0x4000, 0x4010,
7013 0x4080, 0x4090, 0x43c0, 0x4458,
7014 0x4c00, 0x4c18, 0x4c40, 0x4c54,
7015 0x4fc0, 0x5010, 0x53c0, 0x5444,
7016 0x5c00, 0x5c18, 0x5c80, 0x5c90,
7017 0x5fc0, 0x6000, 0x6400, 0x6428,
7018 0x6800, 0x6848, 0x684c, 0x6860,
7019 0x6888, 0x6910, 0x8000
7026 if (!netif_running(bp->
dev))
7030 offset = reg_boundaries[0];
7033 *p++ =
REG_RD(bp, offset);
7035 if (offset == reg_boundaries[i + 1]) {
7036 offset = reg_boundaries[i + 2];
7037 p = (
u32 *) (orig_p + offset);
7046 struct bnx2 *bp = netdev_priv(dev);
7065 struct bnx2 *bp = netdev_priv(dev);
7085 struct bnx2 *bp = netdev_priv(dev);
7088 if (!netif_running(dev))
7100 rc = bnx2_setup_remote_phy(bp, bp->
phy_port);
7119 bnx2_read_phy(bp, bp->
mii_bmcr, &bmcr);
7131 struct bnx2 *bp = netdev_priv(dev);
7139 struct bnx2 *bp = netdev_priv(dev);
7151 struct bnx2 *bp = netdev_priv(dev);
7154 if (!netif_running(dev))
7159 rc = bnx2_nvram_read(bp, eeprom->
offset, eebuf, eeprom->
len);
7168 struct bnx2 *bp = netdev_priv(dev);
7171 if (!netif_running(dev))
7176 rc = bnx2_nvram_write(bp, eeprom->
offset, eebuf, eeprom->
len);
7184 struct bnx2 *bp = netdev_priv(dev);
7206 struct bnx2 *bp = netdev_priv(dev);
7243 if (netif_running(bp->
dev)) {
7244 bnx2_netif_stop(bp,
true);
7245 bnx2_init_nic(bp, 0);
7246 bnx2_netif_start(bp,
true);
7255 struct bnx2 *bp = netdev_priv(dev);
7268 bnx2_change_ring_size(
struct bnx2 *bp,
u32 rx,
u32 tx,
bool reset_irq)
7270 if (netif_running(bp->
dev)) {
7272 bnx2_save_stats(bp);
7274 bnx2_netif_stop(bp,
true);
7280 __bnx2_free_irq(bp);
7286 bnx2_set_rx_ring_size(bp, rx);
7289 if (netif_running(bp->
dev)) {
7293 rc = bnx2_setup_int_mode(bp, disable_msi);
7298 rc = bnx2_alloc_mem(bp);
7301 rc = bnx2_request_irq(bp);
7304 rc = bnx2_init_nic(bp, 0);
7307 bnx2_napi_enable(bp);
7315 bnx2_setup_cnic_irq_info(bp);
7318 bnx2_netif_start(bp,
true);
7326 struct bnx2 *bp = netdev_priv(dev);
7343 struct bnx2 *bp = netdev_priv(dev);
7353 struct bnx2 *bp = netdev_priv(dev);
7368 if (netif_running(dev)) {
7379 } bnx2_stats_str_arr[] = {
7381 {
"rx_error_bytes" },
7383 {
"tx_error_bytes" },
7384 {
"rx_ucast_packets" },
7385 {
"rx_mcast_packets" },
7386 {
"rx_bcast_packets" },
7387 {
"tx_ucast_packets" },
7388 {
"tx_mcast_packets" },
7389 {
"tx_bcast_packets" },
7390 {
"tx_mac_errors" },
7391 {
"tx_carrier_errors" },
7392 {
"rx_crc_errors" },
7393 {
"rx_align_errors" },
7394 {
"tx_single_collisions" },
7395 {
"tx_multi_collisions" },
7397 {
"tx_excess_collisions" },
7398 {
"tx_late_collisions" },
7399 {
"tx_total_collisions" },
7402 {
"rx_undersize_packets" },
7403 {
"rx_oversize_packets" },
7404 {
"rx_64_byte_packets" },
7405 {
"rx_65_to_127_byte_packets" },
7406 {
"rx_128_to_255_byte_packets" },
7407 {
"rx_256_to_511_byte_packets" },
7408 {
"rx_512_to_1023_byte_packets" },
7409 {
"rx_1024_to_1522_byte_packets" },
7410 {
"rx_1523_to_9022_byte_packets" },
7411 {
"tx_64_byte_packets" },
7412 {
"tx_65_to_127_byte_packets" },
7413 {
"tx_128_to_255_byte_packets" },
7414 {
"tx_256_to_511_byte_packets" },
7415 {
"tx_512_to_1023_byte_packets" },
7416 {
"tx_1024_to_1522_byte_packets" },
7417 {
"tx_1523_to_9022_byte_packets" },
7418 {
"rx_xon_frames" },
7419 {
"rx_xoff_frames" },
7420 {
"tx_xon_frames" },
7421 {
"tx_xoff_frames" },
7422 {
"rx_mac_ctrl_frames" },
7423 {
"rx_filtered_packets" },
7424 {
"rx_ftq_discards" },
7426 {
"rx_fw_discards" },
7429 #define BNX2_NUM_STATS ARRAY_SIZE(bnx2_stats_str_arr)
7431 #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
7433 static const unsigned long bnx2_stats_offset_arr[
BNX2_NUM_STATS] = {
7444 STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
7487 8,0,8,8,8,8,8,8,8,8,
7488 4,0,4,4,4,4,4,4,4,4,
7489 4,4,4,4,4,4,4,4,4,4,
7490 4,4,4,4,4,4,4,4,4,4,
7495 8,0,8,8,8,8,8,8,8,8,
7496 4,4,4,4,4,4,4,4,4,4,
7497 4,4,4,4,4,4,4,4,4,4,
7498 4,4,4,4,4,4,4,4,4,4,
7502 #define BNX2_NUM_TESTS 6
7507 {
"register_test (offline)" },
7508 {
"memory_test (offline)" },
7509 {
"loopback_test (offline)" },
7510 {
"nvram_test (online)" },
7511 {
"interrupt_test (online)" },
7512 {
"link_test (online)" },
7516 bnx2_get_sset_count(
struct net_device *dev,
int sset)
7531 struct bnx2 *bp = netdev_priv(dev);
7533 bnx2_set_power_state(bp,
PCI_D0);
7539 bnx2_netif_stop(bp,
true);
7543 if (bnx2_test_registers(bp) != 0) {
7547 if (bnx2_test_memory(bp) != 0) {
7551 if ((buf[2] = bnx2_test_loopback(bp)) != 0)
7554 if (!netif_running(bp->
dev))
7555 bnx2_shutdown_chip(bp);
7557 bnx2_init_nic(bp, 1);
7558 bnx2_netif_start(bp,
true);
7562 for (i = 0; i < 7; i++) {
7569 if (bnx2_test_nvram(bp) != 0) {
7573 if (bnx2_test_intr(bp) != 0) {
7578 if (bnx2_test_link(bp) != 0) {
7583 if (!netif_running(bp->
dev))
7590 switch (stringset) {
7592 memcpy(buf, bnx2_stats_str_arr,
7593 sizeof(bnx2_stats_str_arr));
7596 memcpy(buf, bnx2_tests_str_arr,
7597 sizeof(bnx2_tests_str_arr));
7603 bnx2_get_ethtool_stats(
struct net_device *dev,
7606 struct bnx2 *bp = netdev_priv(dev);
7610 u8 *stats_len_arr =
NULL;
7612 if (hw_stats ==
NULL) {
7621 stats_len_arr = bnx2_5706_stats_len_arr;
7623 stats_len_arr = bnx2_5708_stats_len_arr;
7628 if (stats_len_arr[i] == 0) {
7634 offset = bnx2_stats_offset_arr[
i];
7635 if (stats_len_arr[i] == 4) {
7637 buf[
i] = (
u64) *(hw_stats + offset) +
7642 buf[
i] = (((
u64) *(hw_stats + offset)) << 32) +
7643 *(hw_stats + offset + 1) +
7644 (((
u64) *(temp_stats +
offset)) << 32) +
7645 *(temp_stats + offset + 1);
7652 struct bnx2 *bp = netdev_priv(dev);
7656 bnx2_set_power_state(bp,
PCI_D0);
7679 if (!netif_running(dev))
7690 struct bnx2 *bp = netdev_priv(dev);
7701 struct bnx2 *bp = netdev_priv(dev);
7711 netif_running(dev)) {
7712 bnx2_netif_stop(bp,
false);
7714 bnx2_set_rx_mode(dev);
7716 bnx2_netif_start(bp,
false);
7723 static void bnx2_get_channels(
struct net_device *dev,
7726 struct bnx2 *bp = netdev_priv(dev);
7727 u32 max_rx_rings = 1;
7728 u32 max_tx_rings = 1;
7735 channels->
max_rx = max_rx_rings;
7736 channels->
max_tx = max_tx_rings;
7745 static int bnx2_set_channels(
struct net_device *dev,
7748 struct bnx2 *bp = netdev_priv(dev);
7749 u32 max_rx_rings = 1;
7750 u32 max_tx_rings = 1;
7757 if (channels->
rx_count > max_rx_rings ||
7764 if (netif_running(dev))
7771 static const struct ethtool_ops bnx2_ethtool_ops = {
7772 .get_settings = bnx2_get_settings,
7773 .set_settings = bnx2_set_settings,
7774 .get_drvinfo = bnx2_get_drvinfo,
7775 .get_regs_len = bnx2_get_regs_len,
7776 .get_regs = bnx2_get_regs,
7777 .get_wol = bnx2_get_wol,
7778 .set_wol = bnx2_set_wol,
7779 .nway_reset = bnx2_nway_reset,
7780 .get_link = bnx2_get_link,
7781 .get_eeprom_len = bnx2_get_eeprom_len,
7782 .get_eeprom = bnx2_get_eeprom,
7783 .set_eeprom = bnx2_set_eeprom,
7784 .get_coalesce = bnx2_get_coalesce,
7785 .set_coalesce = bnx2_set_coalesce,
7786 .get_ringparam = bnx2_get_ringparam,
7787 .set_ringparam = bnx2_set_ringparam,
7788 .get_pauseparam = bnx2_get_pauseparam,
7789 .set_pauseparam = bnx2_set_pauseparam,
7790 .self_test = bnx2_self_test,
7791 .get_strings = bnx2_get_strings,
7792 .set_phys_id = bnx2_set_phys_id,
7793 .get_ethtool_stats = bnx2_get_ethtool_stats,
7794 .get_sset_count = bnx2_get_sset_count,
7795 .get_channels = bnx2_get_channels,
7796 .set_channels = bnx2_set_channels,
7804 struct bnx2 *bp = netdev_priv(dev);
7818 if (!netif_running(dev))
7822 err = bnx2_read_phy(bp, data->
reg_num & 0x1f, &mii_regval);
7834 if (!netif_running(dev))
7838 err = bnx2_write_phy(bp, data->
reg_num & 0x1f, data->
val_in);
7852 bnx2_change_mac_addr(
struct net_device *dev,
void *p)
7855 struct bnx2 *bp = netdev_priv(dev);
7857 if (!is_valid_ether_addr(addr->
sa_data))
7861 if (netif_running(dev))
7862 bnx2_set_mac_addr(bp, bp->
dev->dev_addr, 0);
7869 bnx2_change_mtu(
struct net_device *dev,
int new_mtu)
7871 struct bnx2 *bp = netdev_priv(dev);
7882 #ifdef CONFIG_NET_POLL_CONTROLLER
7886 struct bnx2 *bp = netdev_priv(dev);
7900 bnx2_get_5709_media(
struct bnx2 *bp)
7918 if (bp->
func == 0) {
7938 bnx2_get_pci_speed(
struct bnx2 *bp)
7990 bnx2_read_vpd_fw_ver(
struct bnx2 *bp)
7994 unsigned int block_end, rosize, len;
7996 #define BNX2_VPD_NVRAM_OFFSET 0x300
7997 #define BNX2_VPD_LEN 128
7998 #define BNX2_MAX_VER_SLEN 30
8004 rc = bnx2_nvram_read(bp, BNX2_VPD_NVRAM_OFFSET, data + BNX2_VPD_LEN,
8010 data[
i] = data[i + BNX2_VPD_LEN + 3];
8011 data[i + 1] = data[i + BNX2_VPD_LEN + 2];
8012 data[i + 2] = data[i + BNX2_VPD_LEN + 1];
8013 data[i + 3] = data[i + BNX2_VPD_LEN];
8020 rosize = pci_vpd_lrdt_size(&data[i]);
8022 block_end = i + rosize;
8024 if (block_end > BNX2_VPD_LEN)
8032 len = pci_vpd_info_field_size(&data[j]);
8035 if (j + len > block_end || len != 4 ||
8036 memcmp(&data[j],
"1028", 4))
8044 len = pci_vpd_info_field_size(&data[j]);
8047 if (j + len > block_end || len > BNX2_MAX_VER_SLEN)
8063 u64 dma_mask, persist_dma_mask;
8067 bp = netdev_priv(dev);
8083 dev_err(&pdev->
dev,
"Cannot enable PCI device, aborting\n");
8089 "Cannot find PCI device base address, aborting\n");
8091 goto err_out_disable;
8096 dev_err(&pdev->
dev,
"Cannot obtain PCI resources, aborting\n");
8097 goto err_out_disable;
8105 "Cannot find power management capability, aborting\n");
8107 goto err_out_release;
8123 dev_err(&pdev->
dev,
"Cannot map register space, aborting\n");
8125 goto err_out_release;
8128 bnx2_set_power_state(bp,
PCI_D0);
8141 if (!pci_is_pcie(pdev)) {
8159 "Cannot find PCIX capability, aborting\n");
8183 if (pci_set_dma_mask(pdev, dma_mask) == 0) {
8185 rc = pci_set_consistent_dma_mask(pdev, persist_dma_mask);
8188 "pci_set_consistent_dma_mask failed, aborting\n");
8191 }
else if ((rc = pci_set_dma_mask(pdev,
DMA_BIT_MASK(32))) != 0) {
8192 dev_err(&pdev->
dev,
"System does not support DMA, aborting\n");
8197 bnx2_get_pci_speed(bp);
8209 "5706 A1 can only be used in a PCIX bus, aborting\n");
8213 bnx2_init_nvram(bp);
8235 dev_err(&pdev->
dev,
"Firmware not running, aborting\n");
8240 bnx2_read_vpd_fw_ver(bp);
8244 for (i = 0; i < 3 && j < 24; i++) {
8252 num = (
u8) (reg >> (24 - (i * 8)));
8253 for (k = 100, skip0 = 1; k >= 1; num %=
k, k /= 10) {
8254 if (num >= k || !skip0 || k == 1) {
8269 for (i = 0; i < 30; i++) {
8284 for (i = 0; i < 3 && j < 28; i++) {
8285 reg = bnx2_reg_rd_ind(bp, addr + i * 4);
8303 bnx2_set_rx_ring_size(bp, 255);
8323 bnx2_get_5709_media(bp);
8356 bnx2_init_fw_cap(bp);
8404 bnx2_set_default_link(bp);
8410 bp->
timer.function = bnx2_timer;
8414 bp->cnic_eth_dev.max_iscsi_conn =
8436 pci_set_drvdata(pdev,
NULL);
8443 bnx2_bus_string(
struct bnx2 *bp,
char *
str)
8448 s +=
sprintf(s,
"PCI Express");
8463 bnx2_del_napi(
struct bnx2 *bp)
8472 bnx2_init_napi(
struct bnx2 *bp)
8483 poll = bnx2_poll_msix;
8491 .ndo_open = bnx2_open,
8492 .ndo_start_xmit = bnx2_start_xmit,
8493 .ndo_stop = bnx2_close,
8494 .ndo_get_stats64 = bnx2_get_stats64,
8495 .ndo_set_rx_mode = bnx2_set_rx_mode,
8496 .ndo_do_ioctl = bnx2_ioctl,
8498 .ndo_set_mac_address = bnx2_change_mac_addr,
8499 .ndo_change_mtu = bnx2_change_mtu,
8500 .ndo_fix_features = bnx2_fix_features,
8501 .ndo_set_features = bnx2_set_features,
8502 .ndo_tx_timeout = bnx2_tx_timeout,
8503 #ifdef CONFIG_NET_POLL_CONTROLLER
8504 .ndo_poll_controller = poll_bnx2,
8511 static int version_printed = 0;
8517 if (version_printed++ == 0)
8525 rc = bnx2_init_board(pdev, dev);
8533 bp = netdev_priv(dev);
8535 pci_set_drvdata(pdev, dev);
8553 dev_err(&pdev->
dev,
"Cannot register net device\n");
8557 netdev_info(dev,
"%s (%c%d) %s found at mem %lx, IRQ %d, "
8559 ((
CHIP_ID(bp) & 0xf000) >> 12) +
'A',
8560 ((
CHIP_ID(bp) & 0x0ff0) >> 4),
8570 pci_set_drvdata(pdev,
NULL);
8577 bnx2_remove_one(
struct pci_dev *pdev)
8579 struct net_device *dev = pci_get_drvdata(pdev);
8580 struct bnx2 *bp = netdev_priv(dev);
8596 bnx2_release_firmware(bp);
8602 pci_set_drvdata(pdev,
NULL);
8608 struct net_device *dev = pci_get_drvdata(pdev);
8609 struct bnx2 *bp = netdev_priv(dev);
8616 if (!netif_running(dev))
8620 bnx2_netif_stop(bp,
true);
8623 bnx2_shutdown_chip(bp);
8630 bnx2_resume(
struct pci_dev *pdev)
8632 struct net_device *dev = pci_get_drvdata(pdev);
8633 struct bnx2 *bp = netdev_priv(dev);
8636 if (!netif_running(dev))
8639 bnx2_set_power_state(bp,
PCI_D0);
8641 bnx2_init_nic(bp, 1);
8642 bnx2_netif_start(bp,
true);
8657 struct net_device *dev = pci_get_drvdata(pdev);
8658 struct bnx2 *bp = netdev_priv(dev);
8668 if (netif_running(dev)) {
8669 bnx2_netif_stop(bp,
true);
8689 struct net_device *dev = pci_get_drvdata(pdev);
8690 struct bnx2 *bp = netdev_priv(dev);
8697 "Cannot re-enable PCI device after reset\n");
8704 if (netif_running(dev)) {
8705 bnx2_set_power_state(bp,
PCI_D0);
8706 bnx2_init_nic(bp, 1);
8718 "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
8732 static void bnx2_io_resume(
struct pci_dev *pdev)
8734 struct net_device *dev = pci_get_drvdata(pdev);
8735 struct bnx2 *bp = netdev_priv(dev);
8738 if (netif_running(dev))
8739 bnx2_netif_start(bp,
true);
8746 .error_detected = bnx2_io_error_detected,
8747 .slot_reset = bnx2_io_slot_reset,
8748 .resume = bnx2_io_resume,
8753 .id_table = bnx2_pci_tbl,
8754 .probe = bnx2_init_one,
8756 .suspend = bnx2_suspend,
8757 .resume = bnx2_resume,
8758 .err_handler = &bnx2_err_handler,
8761 static int __init bnx2_init(
void)
8763 return pci_register_driver(&bnx2_pci_driver);
8766 static void __exit bnx2_cleanup(
void)