Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1 | /* bnx2x_main.c: Broadcom Everest network driver. |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2 | * |
Eilon Greenstein | d05c26c | 2009-01-17 23:26:13 -0800 | [diff] [blame] | 3 | * Copyright (c) 2007-2009 Broadcom Corporation |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
Eilon Greenstein | 24e3fce | 2008-06-12 14:30:28 -0700 | [diff] [blame] | 9 | * Maintained by: Eilon Greenstein <eilong@broadcom.com> |
| 10 | * Written by: Eliezer Tamir |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11 | * Based on code from Michael Chan's bnx2 driver |
| 12 | * UDP CSUM errata workaround by Arik Gendelman |
| 13 | * Slowpath rework by Vladislav Zolotarov |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 14 | * Statistics and Link management by Yitchak Gertner |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/device.h> /* for dev_info() */ |
| 22 | #include <linux/timer.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/ioport.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/vmalloc.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/netdevice.h> |
| 31 | #include <linux/etherdevice.h> |
| 32 | #include <linux/skbuff.h> |
| 33 | #include <linux/dma-mapping.h> |
| 34 | #include <linux/bitops.h> |
| 35 | #include <linux/irq.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <asm/byteorder.h> |
| 38 | #include <linux/time.h> |
| 39 | #include <linux/ethtool.h> |
| 40 | #include <linux/mii.h> |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 41 | #include <linux/if_vlan.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 42 | #include <net/ip.h> |
| 43 | #include <net/tcp.h> |
| 44 | #include <net/checksum.h> |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 45 | #include <net/ip6_checksum.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 46 | #include <linux/workqueue.h> |
| 47 | #include <linux/crc32.h> |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 48 | #include <linux/crc32c.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 49 | #include <linux/prefetch.h> |
| 50 | #include <linux/zlib.h> |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 51 | #include <linux/io.h> |
| 52 | |
| 53 | #include "bnx2x_reg.h" |
| 54 | #include "bnx2x_fw_defs.h" |
| 55 | #include "bnx2x_hsi.h" |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 56 | #include "bnx2x_link.h" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 57 | #include "bnx2x.h" |
| 58 | #include "bnx2x_init.h" |
| 59 | |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 60 | #define DRV_MODULE_VERSION "1.45.26" |
| 61 | #define DRV_MODULE_RELDATE "2009/01/26" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 62 | #define BNX2X_BC_VER 0x040200 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 63 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 64 | /* Time in jiffies before concluding the transmitter is hung */ |
| 65 | #define TX_TIMEOUT (5*HZ) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 66 | |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 67 | static char version[] __devinitdata = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 68 | "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 69 | DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 70 | |
Eilon Greenstein | 24e3fce | 2008-06-12 14:30:28 -0700 | [diff] [blame] | 71 | MODULE_AUTHOR("Eliezer Tamir"); |
Eilon Greenstein | e47d7e6 | 2009-01-14 06:44:28 +0000 | [diff] [blame] | 72 | MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 73 | MODULE_LICENSE("GPL"); |
| 74 | MODULE_VERSION(DRV_MODULE_VERSION); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 75 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 76 | static int multi_mode = 1; |
| 77 | module_param(multi_mode, int, 0); |
| 78 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 79 | static int disable_tpa; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 80 | static int poll; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 81 | static int debug; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 82 | static int load_count[3]; /* 0-common, 1-port0, 2-port1 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 83 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 84 | module_param(disable_tpa, int, 0); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 85 | |
| 86 | static int int_mode; |
| 87 | module_param(int_mode, int, 0); |
| 88 | MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)"); |
| 89 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 90 | module_param(poll, int, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 91 | module_param(debug, int, 0); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 92 | MODULE_PARM_DESC(disable_tpa, "disable the TPA (LRO) feature"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 93 | MODULE_PARM_DESC(poll, "use polling (for debug)"); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 94 | MODULE_PARM_DESC(debug, "default debug msglevel"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 95 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 96 | static struct workqueue_struct *bnx2x_wq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 97 | |
| 98 | enum bnx2x_board_type { |
| 99 | BCM57710 = 0, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 100 | BCM57711 = 1, |
| 101 | BCM57711E = 2, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 102 | }; |
| 103 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 104 | /* indexed by board_type, above */ |
Andrew Morton | 53a1056 | 2008-02-09 23:16:41 -0800 | [diff] [blame] | 105 | static struct { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 106 | char *name; |
| 107 | } board_info[] __devinitdata = { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 108 | { "Broadcom NetXtreme II BCM57710 XGb" }, |
| 109 | { "Broadcom NetXtreme II BCM57711 XGb" }, |
| 110 | { "Broadcom NetXtreme II BCM57711E XGb" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 113 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 114 | static const struct pci_device_id bnx2x_pci_tbl[] = { |
| 115 | { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57710, |
| 116 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57710 }, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 117 | { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711, |
| 118 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711 }, |
| 119 | { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711E, |
| 120 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711E }, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 121 | { 0 } |
| 122 | }; |
| 123 | |
| 124 | MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl); |
| 125 | |
| 126 | /**************************************************************************** |
| 127 | * General service functions |
| 128 | ****************************************************************************/ |
| 129 | |
| 130 | /* used only at init |
| 131 | * locking is done by mcp |
| 132 | */ |
| 133 | static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val) |
| 134 | { |
| 135 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 136 | pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val); |
| 137 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 138 | PCICFG_VENDOR_ID_OFFSET); |
| 139 | } |
| 140 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 141 | static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr) |
| 142 | { |
| 143 | u32 val; |
| 144 | |
| 145 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr); |
| 146 | pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val); |
| 147 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 148 | PCICFG_VENDOR_ID_OFFSET); |
| 149 | |
| 150 | return val; |
| 151 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 152 | |
| 153 | static const u32 dmae_reg_go_c[] = { |
| 154 | DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3, |
| 155 | DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7, |
| 156 | DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11, |
| 157 | DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15 |
| 158 | }; |
| 159 | |
| 160 | /* copy command into DMAE command memory and set DMAE command go */ |
| 161 | static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, |
| 162 | int idx) |
| 163 | { |
| 164 | u32 cmd_offset; |
| 165 | int i; |
| 166 | |
| 167 | cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx); |
| 168 | for (i = 0; i < (sizeof(struct dmae_command)/4); i++) { |
| 169 | REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
| 170 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 171 | DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n", |
| 172 | idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 173 | } |
| 174 | REG_WR(bp, dmae_reg_go_c[idx], 1); |
| 175 | } |
| 176 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 177 | void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr, |
| 178 | u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 179 | { |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 180 | struct dmae_command *dmae = &bp->init_dmae; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 181 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 182 | int cnt = 200; |
| 183 | |
| 184 | if (!bp->dmae_ready) { |
| 185 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 186 | |
| 187 | DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)" |
| 188 | " using indirect\n", dst_addr, len32); |
| 189 | bnx2x_init_ind_wr(bp, dst_addr, data, len32); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | mutex_lock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 194 | |
| 195 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 196 | |
| 197 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 198 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 199 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 200 | #ifdef __BIG_ENDIAN |
| 201 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 202 | #else |
| 203 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 204 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 205 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 206 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 207 | dmae->src_addr_lo = U64_LO(dma_addr); |
| 208 | dmae->src_addr_hi = U64_HI(dma_addr); |
| 209 | dmae->dst_addr_lo = dst_addr >> 2; |
| 210 | dmae->dst_addr_hi = 0; |
| 211 | dmae->len = len32; |
| 212 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); |
| 213 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 214 | dmae->comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 215 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 216 | DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 217 | DP_LEVEL "src_addr [%x:%08x] len [%d *4] " |
| 218 | "dst_addr [%x:%08x (%08x)]\n" |
| 219 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
| 220 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
| 221 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, dst_addr, |
| 222 | dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 223 | DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 224 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 225 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 226 | |
| 227 | *wb_comp = 0; |
| 228 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 229 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 230 | |
| 231 | udelay(5); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 232 | |
| 233 | while (*wb_comp != DMAE_COMP_VAL) { |
| 234 | DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp); |
| 235 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 236 | if (!cnt) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 237 | BNX2X_ERR("dmae timeout!\n"); |
| 238 | break; |
| 239 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 240 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 241 | /* adjust delay for emulation/FPGA */ |
| 242 | if (CHIP_REV_IS_SLOW(bp)) |
| 243 | msleep(100); |
| 244 | else |
| 245 | udelay(5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 246 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 247 | |
| 248 | mutex_unlock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 249 | } |
| 250 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 251 | void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 252 | { |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 253 | struct dmae_command *dmae = &bp->init_dmae; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 254 | u32 *wb_comp = bnx2x_sp(bp, wb_comp); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 255 | int cnt = 200; |
| 256 | |
| 257 | if (!bp->dmae_ready) { |
| 258 | u32 *data = bnx2x_sp(bp, wb_data[0]); |
| 259 | int i; |
| 260 | |
| 261 | DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)" |
| 262 | " using indirect\n", src_addr, len32); |
| 263 | for (i = 0; i < len32; i++) |
| 264 | data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4); |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | mutex_lock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 269 | |
| 270 | memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4); |
| 271 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 272 | |
| 273 | dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 274 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 275 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 276 | #ifdef __BIG_ENDIAN |
| 277 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 278 | #else |
| 279 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 280 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 281 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 282 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 283 | dmae->src_addr_lo = src_addr >> 2; |
| 284 | dmae->src_addr_hi = 0; |
| 285 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data)); |
| 286 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data)); |
| 287 | dmae->len = len32; |
| 288 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp)); |
| 289 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp)); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 290 | dmae->comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 291 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 292 | DP(BNX2X_MSG_OFF, "dmae: opcode 0x%08x\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 293 | DP_LEVEL "src_addr [%x:%08x] len [%d *4] " |
| 294 | "dst_addr [%x:%08x (%08x)]\n" |
| 295 | DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n", |
| 296 | dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo, |
| 297 | dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, src_addr, |
| 298 | dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 299 | |
| 300 | *wb_comp = 0; |
| 301 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 302 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 303 | |
| 304 | udelay(5); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 305 | |
| 306 | while (*wb_comp != DMAE_COMP_VAL) { |
| 307 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 308 | if (!cnt) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 309 | BNX2X_ERR("dmae timeout!\n"); |
| 310 | break; |
| 311 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 312 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 313 | /* adjust delay for emulation/FPGA */ |
| 314 | if (CHIP_REV_IS_SLOW(bp)) |
| 315 | msleep(100); |
| 316 | else |
| 317 | udelay(5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 318 | } |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 319 | DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 320 | bp->slowpath->wb_data[0], bp->slowpath->wb_data[1], |
| 321 | bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]); |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 322 | |
| 323 | mutex_unlock(&bp->dmae_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 324 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 325 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 326 | /* used only for slowpath so not inlined */ |
| 327 | static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo) |
| 328 | { |
| 329 | u32 wb_write[2]; |
| 330 | |
| 331 | wb_write[0] = val_hi; |
| 332 | wb_write[1] = val_lo; |
| 333 | REG_WR_DMAE(bp, reg, wb_write, 2); |
| 334 | } |
| 335 | |
| 336 | #ifdef USE_WB_RD |
| 337 | static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg) |
| 338 | { |
| 339 | u32 wb_data[2]; |
| 340 | |
| 341 | REG_RD_DMAE(bp, reg, wb_data, 2); |
| 342 | |
| 343 | return HILO_U64(wb_data[0], wb_data[1]); |
| 344 | } |
| 345 | #endif |
| 346 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 347 | static int bnx2x_mc_assert(struct bnx2x *bp) |
| 348 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 349 | char last_idx; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 350 | int i, rc = 0; |
| 351 | u32 row0, row1, row2, row3; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 352 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 353 | /* XSTORM */ |
| 354 | last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM + |
| 355 | XSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 356 | if (last_idx) |
| 357 | BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 358 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 359 | /* print the asserts */ |
| 360 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 361 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 362 | row0 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 363 | XSTORM_ASSERT_LIST_OFFSET(i)); |
| 364 | row1 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 365 | XSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 366 | row2 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 367 | XSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 368 | row3 = REG_RD(bp, BAR_XSTRORM_INTMEM + |
| 369 | XSTORM_ASSERT_LIST_OFFSET(i) + 12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 370 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 371 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 372 | BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 373 | " 0x%08x 0x%08x 0x%08x\n", |
| 374 | i, row3, row2, row1, row0); |
| 375 | rc++; |
| 376 | } else { |
| 377 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 378 | } |
| 379 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 380 | |
| 381 | /* TSTORM */ |
| 382 | last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM + |
| 383 | TSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 384 | if (last_idx) |
| 385 | BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 386 | |
| 387 | /* print the asserts */ |
| 388 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 389 | |
| 390 | row0 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 391 | TSTORM_ASSERT_LIST_OFFSET(i)); |
| 392 | row1 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 393 | TSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 394 | row2 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 395 | TSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 396 | row3 = REG_RD(bp, BAR_TSTRORM_INTMEM + |
| 397 | TSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 398 | |
| 399 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 400 | BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 401 | " 0x%08x 0x%08x 0x%08x\n", |
| 402 | i, row3, row2, row1, row0); |
| 403 | rc++; |
| 404 | } else { |
| 405 | break; |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | /* CSTORM */ |
| 410 | last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM + |
| 411 | CSTORM_ASSERT_LIST_INDEX_OFFSET); |
| 412 | if (last_idx) |
| 413 | BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 414 | |
| 415 | /* print the asserts */ |
| 416 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 417 | |
| 418 | row0 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 419 | CSTORM_ASSERT_LIST_OFFSET(i)); |
| 420 | row1 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 421 | CSTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 422 | row2 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 423 | CSTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 424 | row3 = REG_RD(bp, BAR_CSTRORM_INTMEM + |
| 425 | CSTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 426 | |
| 427 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 428 | BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 429 | " 0x%08x 0x%08x 0x%08x\n", |
| 430 | i, row3, row2, row1, row0); |
| 431 | rc++; |
| 432 | } else { |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | /* USTORM */ |
| 438 | last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM + |
| 439 | USTORM_ASSERT_LIST_INDEX_OFFSET); |
| 440 | if (last_idx) |
| 441 | BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx); |
| 442 | |
| 443 | /* print the asserts */ |
| 444 | for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) { |
| 445 | |
| 446 | row0 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 447 | USTORM_ASSERT_LIST_OFFSET(i)); |
| 448 | row1 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 449 | USTORM_ASSERT_LIST_OFFSET(i) + 4); |
| 450 | row2 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 451 | USTORM_ASSERT_LIST_OFFSET(i) + 8); |
| 452 | row3 = REG_RD(bp, BAR_USTRORM_INTMEM + |
| 453 | USTORM_ASSERT_LIST_OFFSET(i) + 12); |
| 454 | |
| 455 | if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) { |
| 456 | BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x" |
| 457 | " 0x%08x 0x%08x 0x%08x\n", |
| 458 | i, row3, row2, row1, row0); |
| 459 | rc++; |
| 460 | } else { |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 465 | return rc; |
| 466 | } |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 467 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 468 | static void bnx2x_fw_dump(struct bnx2x *bp) |
| 469 | { |
| 470 | u32 mark, offset; |
| 471 | u32 data[9]; |
| 472 | int word; |
| 473 | |
| 474 | mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 475 | mark = ((mark + 0x3) & ~0x3); |
| 476 | printk(KERN_ERR PFX "begin fw dump (mark 0x%x)\n" KERN_ERR, mark); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 477 | |
| 478 | for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) { |
| 479 | for (word = 0; word < 8; word++) |
| 480 | data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH + |
| 481 | offset + 4*word)); |
| 482 | data[8] = 0x0; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 483 | printk(KERN_CONT "%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 484 | } |
| 485 | for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) { |
| 486 | for (word = 0; word < 8; word++) |
| 487 | data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH + |
| 488 | offset + 4*word)); |
| 489 | data[8] = 0x0; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 490 | printk(KERN_CONT "%s", (char *)data); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 491 | } |
| 492 | printk("\n" KERN_ERR PFX "end of fw dump\n"); |
| 493 | } |
| 494 | |
| 495 | static void bnx2x_panic_dump(struct bnx2x *bp) |
| 496 | { |
| 497 | int i; |
| 498 | u16 j, start, end; |
| 499 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 500 | bp->stats_state = STATS_STATE_DISABLED; |
| 501 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
| 502 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 503 | BNX2X_ERR("begin crash dump -----------------\n"); |
| 504 | |
| 505 | for_each_queue(bp, i) { |
| 506 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 507 | struct eth_tx_db_data *hw_prods = fp->hw_tx_prods; |
| 508 | |
| 509 | BNX2X_ERR("queue[%d]: tx_pkt_prod(%x) tx_pkt_cons(%x)" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 510 | " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 511 | i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 512 | fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb)); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 513 | BNX2X_ERR(" rx_bd_prod(%x) rx_bd_cons(%x)" |
| 514 | " *rx_bd_cons_sb(%x) rx_comp_prod(%x)" |
| 515 | " rx_comp_cons(%x) *rx_cons_sb(%x)\n", |
| 516 | fp->rx_bd_prod, fp->rx_bd_cons, |
| 517 | le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod, |
| 518 | fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb)); |
| 519 | BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)" |
| 520 | " fp_c_idx(%x) *sb_c_idx(%x) fp_u_idx(%x)" |
| 521 | " *sb_u_idx(%x) bd data(%x,%x)\n", |
| 522 | fp->rx_sge_prod, fp->last_max_sge, fp->fp_c_idx, |
| 523 | fp->status_blk->c_status_block.status_block_index, |
| 524 | fp->fp_u_idx, |
| 525 | fp->status_blk->u_status_block.status_block_index, |
| 526 | hw_prods->packets_prod, hw_prods->bds_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 527 | |
| 528 | start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10); |
| 529 | end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245); |
| 530 | for (j = start; j < end; j++) { |
| 531 | struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j]; |
| 532 | |
| 533 | BNX2X_ERR("packet[%x]=[%p,%x]\n", j, |
| 534 | sw_bd->skb, sw_bd->first_bd); |
| 535 | } |
| 536 | |
| 537 | start = TX_BD(fp->tx_bd_cons - 10); |
| 538 | end = TX_BD(fp->tx_bd_cons + 254); |
| 539 | for (j = start; j < end; j++) { |
| 540 | u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j]; |
| 541 | |
| 542 | BNX2X_ERR("tx_bd[%x]=[%x:%x:%x:%x]\n", |
| 543 | j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]); |
| 544 | } |
| 545 | |
| 546 | start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10); |
| 547 | end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503); |
| 548 | for (j = start; j < end; j++) { |
| 549 | u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j]; |
| 550 | struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j]; |
| 551 | |
| 552 | BNX2X_ERR("rx_bd[%x]=[%x:%x] sw_bd=[%p]\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 553 | j, rx_bd[1], rx_bd[0], sw_bd->skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 556 | start = RX_SGE(fp->rx_sge_prod); |
| 557 | end = RX_SGE(fp->last_max_sge); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 558 | for (j = start; j < end; j++) { |
| 559 | u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j]; |
| 560 | struct sw_rx_page *sw_page = &fp->rx_page_ring[j]; |
| 561 | |
| 562 | BNX2X_ERR("rx_sge[%x]=[%x:%x] sw_page=[%p]\n", |
| 563 | j, rx_sge[1], rx_sge[0], sw_page->page); |
| 564 | } |
| 565 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 566 | start = RCQ_BD(fp->rx_comp_cons - 10); |
| 567 | end = RCQ_BD(fp->rx_comp_cons + 503); |
| 568 | for (j = start; j < end; j++) { |
| 569 | u32 *cqe = (u32 *)&fp->rx_comp_ring[j]; |
| 570 | |
| 571 | BNX2X_ERR("cqe[%x]=[%x:%x:%x:%x]\n", |
| 572 | j, cqe[0], cqe[1], cqe[2], cqe[3]); |
| 573 | } |
| 574 | } |
| 575 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 576 | BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)" |
| 577 | " def_t_idx(%u) def_att_idx(%u) attn_state(%u)" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 578 | " spq_prod_idx(%u)\n", |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 579 | bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 580 | bp->def_att_idx, bp->attn_state, bp->spq_prod_idx); |
| 581 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 582 | bnx2x_fw_dump(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 583 | bnx2x_mc_assert(bp); |
| 584 | BNX2X_ERR("end crash dump -----------------\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 585 | } |
| 586 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 587 | static void bnx2x_int_enable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 588 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 589 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 590 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 591 | u32 val = REG_RD(bp, addr); |
| 592 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 593 | int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 594 | |
| 595 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 596 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 597 | HC_CONFIG_0_REG_INT_LINE_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 598 | val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 599 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 600 | } else if (msi) { |
| 601 | val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0; |
| 602 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 603 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 604 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 605 | } else { |
| 606 | val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 607 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 608 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 609 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 610 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 611 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 612 | val, port, addr); |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 613 | |
| 614 | REG_WR(bp, addr, val); |
| 615 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 616 | val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0; |
| 617 | } |
| 618 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 619 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n", |
| 620 | val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx"))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 621 | |
| 622 | REG_WR(bp, addr, val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 623 | |
| 624 | if (CHIP_IS_E1H(bp)) { |
| 625 | /* init leading/trailing edge */ |
| 626 | if (IS_E1HMF(bp)) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 627 | val = (0xee0f | (1 << (BP_E1HVN(bp) + 4))); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 628 | if (bp->port.pmf) |
| 629 | /* enable nig attention */ |
| 630 | val |= 0x0100; |
| 631 | } else |
| 632 | val = 0xffff; |
| 633 | |
| 634 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 635 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
| 636 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 637 | } |
| 638 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 639 | static void bnx2x_int_disable(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 640 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 641 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 642 | u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0; |
| 643 | u32 val = REG_RD(bp, addr); |
| 644 | |
| 645 | val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 | |
| 646 | HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 | |
| 647 | HC_CONFIG_0_REG_INT_LINE_EN_0 | |
| 648 | HC_CONFIG_0_REG_ATTN_BIT_EN_0); |
| 649 | |
| 650 | DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n", |
| 651 | val, port, addr); |
| 652 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 653 | /* flush all outstanding writes */ |
| 654 | mmiowb(); |
| 655 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 656 | REG_WR(bp, addr, val); |
| 657 | if (REG_RD(bp, addr) != val) |
| 658 | BNX2X_ERR("BUG! proper val not read from IGU!\n"); |
| 659 | } |
| 660 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 661 | static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 662 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 663 | int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 664 | int i, offset; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 665 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 666 | /* disable interrupt handling */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 667 | atomic_inc(&bp->intr_sem); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 668 | if (disable_hw) |
| 669 | /* prevent the HW from sending interrupts */ |
| 670 | bnx2x_int_disable(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 671 | |
| 672 | /* make sure all ISRs are done */ |
| 673 | if (msix) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 674 | synchronize_irq(bp->msix_table[0].vector); |
| 675 | offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 676 | for_each_queue(bp, i) |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 677 | synchronize_irq(bp->msix_table[i + offset].vector); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 678 | } else |
| 679 | synchronize_irq(bp->pdev->irq); |
| 680 | |
| 681 | /* make sure sp_task is not running */ |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 682 | cancel_delayed_work(&bp->sp_task); |
| 683 | flush_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 684 | } |
| 685 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 686 | /* fast path */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 687 | |
| 688 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 689 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 690 | */ |
| 691 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 692 | static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 693 | u8 storm, u16 index, u8 op, u8 update) |
| 694 | { |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 695 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 696 | COMMAND_REG_INT_ACK); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 697 | struct igu_ack_register igu_ack; |
| 698 | |
| 699 | igu_ack.status_block_index = index; |
| 700 | igu_ack.sb_id_and_flags = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 701 | ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 702 | (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) | |
| 703 | (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) | |
| 704 | (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT)); |
| 705 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 706 | DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n", |
| 707 | (*(u32 *)&igu_ack), hc_addr); |
| 708 | REG_WR(bp, hc_addr, (*(u32 *)&igu_ack)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp) |
| 712 | { |
| 713 | struct host_status_block *fpsb = fp->status_blk; |
| 714 | u16 rc = 0; |
| 715 | |
| 716 | barrier(); /* status block is written to by the chip */ |
| 717 | if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) { |
| 718 | fp->fp_c_idx = fpsb->c_status_block.status_block_index; |
| 719 | rc |= 1; |
| 720 | } |
| 721 | if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) { |
| 722 | fp->fp_u_idx = fpsb->u_status_block.status_block_index; |
| 723 | rc |= 2; |
| 724 | } |
| 725 | return rc; |
| 726 | } |
| 727 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 728 | static u16 bnx2x_ack_int(struct bnx2x *bp) |
| 729 | { |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 730 | u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 + |
| 731 | COMMAND_REG_SIMD_MASK); |
| 732 | u32 result = REG_RD(bp, hc_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 733 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 734 | DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n", |
| 735 | result, hc_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 736 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 737 | return result; |
| 738 | } |
| 739 | |
| 740 | |
| 741 | /* |
| 742 | * fast path service functions |
| 743 | */ |
| 744 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 745 | static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp) |
| 746 | { |
| 747 | u16 tx_cons_sb; |
| 748 | |
| 749 | /* Tell compiler that status block fields can change */ |
| 750 | barrier(); |
| 751 | tx_cons_sb = le16_to_cpu(*fp->tx_cons_sb); |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 752 | return (fp->tx_pkt_cons != tx_cons_sb); |
| 753 | } |
| 754 | |
| 755 | static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp) |
| 756 | { |
| 757 | /* Tell compiler that consumer and producer can change */ |
| 758 | barrier(); |
| 759 | return (fp->tx_pkt_prod != fp->tx_pkt_cons); |
| 760 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 763 | /* free skb in the packet ring at pos idx |
| 764 | * return idx of last bd freed |
| 765 | */ |
| 766 | static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 767 | u16 idx) |
| 768 | { |
| 769 | struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx]; |
| 770 | struct eth_tx_bd *tx_bd; |
| 771 | struct sk_buff *skb = tx_buf->skb; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 772 | u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 773 | int nbd; |
| 774 | |
| 775 | DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n", |
| 776 | idx, tx_buf, skb); |
| 777 | |
| 778 | /* unmap first bd */ |
| 779 | DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx); |
| 780 | tx_bd = &fp->tx_desc_ring[bd_idx]; |
| 781 | pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_bd), |
| 782 | BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE); |
| 783 | |
| 784 | nbd = le16_to_cpu(tx_bd->nbd) - 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 785 | new_cons = nbd + tx_buf->first_bd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 786 | #ifdef BNX2X_STOP_ON_ERROR |
| 787 | if (nbd > (MAX_SKB_FRAGS + 2)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 788 | BNX2X_ERR("BAD nbd!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 789 | bnx2x_panic(); |
| 790 | } |
| 791 | #endif |
| 792 | |
| 793 | /* Skip a parse bd and the TSO split header bd |
| 794 | since they have no mapping */ |
| 795 | if (nbd) |
| 796 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 797 | |
| 798 | if (tx_bd->bd_flags.as_bitfield & (ETH_TX_BD_FLAGS_IP_CSUM | |
| 799 | ETH_TX_BD_FLAGS_TCP_CSUM | |
| 800 | ETH_TX_BD_FLAGS_SW_LSO)) { |
| 801 | if (--nbd) |
| 802 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 803 | tx_bd = &fp->tx_desc_ring[bd_idx]; |
| 804 | /* is this a TSO split header bd? */ |
| 805 | if (tx_bd->bd_flags.as_bitfield & ETH_TX_BD_FLAGS_SW_LSO) { |
| 806 | if (--nbd) |
| 807 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | /* now free frags */ |
| 812 | while (nbd > 0) { |
| 813 | |
| 814 | DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx); |
| 815 | tx_bd = &fp->tx_desc_ring[bd_idx]; |
| 816 | pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_bd), |
| 817 | BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE); |
| 818 | if (--nbd) |
| 819 | bd_idx = TX_BD(NEXT_TX_IDX(bd_idx)); |
| 820 | } |
| 821 | |
| 822 | /* release skb */ |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 823 | WARN_ON(!skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 824 | dev_kfree_skb(skb); |
| 825 | tx_buf->first_bd = 0; |
| 826 | tx_buf->skb = NULL; |
| 827 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 828 | return new_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 829 | } |
| 830 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 831 | static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 832 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 833 | s16 used; |
| 834 | u16 prod; |
| 835 | u16 cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 836 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 837 | barrier(); /* Tell compiler that prod and cons can change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 838 | prod = fp->tx_bd_prod; |
| 839 | cons = fp->tx_bd_cons; |
| 840 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 841 | /* NUM_TX_RINGS = number of "next-page" entries |
| 842 | It will be used as a threshold */ |
| 843 | used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 844 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 845 | #ifdef BNX2X_STOP_ON_ERROR |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 846 | WARN_ON(used < 0); |
| 847 | WARN_ON(used > fp->bp->tx_ring_size); |
| 848 | WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 849 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 850 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 851 | return (s16)(fp->bp->tx_ring_size) - used; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void bnx2x_tx_int(struct bnx2x_fastpath *fp, int work) |
| 855 | { |
| 856 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 857 | struct netdev_queue *txq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 858 | u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons; |
| 859 | int done = 0; |
| 860 | |
| 861 | #ifdef BNX2X_STOP_ON_ERROR |
| 862 | if (unlikely(bp->panic)) |
| 863 | return; |
| 864 | #endif |
| 865 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 866 | txq = netdev_get_tx_queue(bp->dev, fp->index); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 867 | hw_cons = le16_to_cpu(*fp->tx_cons_sb); |
| 868 | sw_cons = fp->tx_pkt_cons; |
| 869 | |
| 870 | while (sw_cons != hw_cons) { |
| 871 | u16 pkt_cons; |
| 872 | |
| 873 | pkt_cons = TX_BD(sw_cons); |
| 874 | |
| 875 | /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */ |
| 876 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 877 | DP(NETIF_MSG_TX_DONE, "hw_cons %u sw_cons %u pkt_cons %u\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 878 | hw_cons, sw_cons, pkt_cons); |
| 879 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 880 | /* if (NEXT_TX_IDX(sw_cons) != hw_cons) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 881 | rmb(); |
| 882 | prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb); |
| 883 | } |
| 884 | */ |
| 885 | bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons); |
| 886 | sw_cons++; |
| 887 | done++; |
| 888 | |
| 889 | if (done == work) |
| 890 | break; |
| 891 | } |
| 892 | |
| 893 | fp->tx_pkt_cons = sw_cons; |
| 894 | fp->tx_bd_cons = bd_cons; |
| 895 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 896 | /* Need to make the tx_bd_cons update visible to start_xmit() |
| 897 | * before checking for netif_tx_queue_stopped(). Without the |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 898 | * memory barrier, there is a small possibility that start_xmit() |
| 899 | * will miss it and cause the queue to be stopped forever. |
| 900 | */ |
| 901 | smp_mb(); |
| 902 | |
| 903 | /* TBD need a thresh? */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 904 | if (unlikely(netif_tx_queue_stopped(txq))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 905 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 906 | __netif_tx_lock(txq, smp_processor_id()); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 907 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 908 | if ((netif_tx_queue_stopped(txq)) && |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 909 | (bp->state == BNX2X_STATE_OPEN) && |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 910 | (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)) |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 911 | netif_tx_wake_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 912 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 913 | __netif_tx_unlock(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 917 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 918 | static void bnx2x_sp_event(struct bnx2x_fastpath *fp, |
| 919 | union eth_rx_cqe *rr_cqe) |
| 920 | { |
| 921 | struct bnx2x *bp = fp->bp; |
| 922 | int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
| 923 | int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data); |
| 924 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 925 | DP(BNX2X_MSG_SP, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 926 | "fp %d cid %d got ramrod #%d state is %x type is %d\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 927 | FP_IDX(fp), cid, command, bp->state, |
| 928 | rr_cqe->ramrod_cqe.ramrod_type); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 929 | |
| 930 | bp->spq_left++; |
| 931 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 932 | if (FP_IDX(fp)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 933 | switch (command | fp->state) { |
| 934 | case (RAMROD_CMD_ID_ETH_CLIENT_SETUP | |
| 935 | BNX2X_FP_STATE_OPENING): |
| 936 | DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n", |
| 937 | cid); |
| 938 | fp->state = BNX2X_FP_STATE_OPEN; |
| 939 | break; |
| 940 | |
| 941 | case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING): |
| 942 | DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n", |
| 943 | cid); |
| 944 | fp->state = BNX2X_FP_STATE_HALTED; |
| 945 | break; |
| 946 | |
| 947 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 948 | BNX2X_ERR("unexpected MC reply (%d) " |
| 949 | "fp->state is %x\n", command, fp->state); |
| 950 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 951 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 952 | mb(); /* force bnx2x_wait_ramrod() to see the change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 953 | return; |
| 954 | } |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 955 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 956 | switch (command | bp->state) { |
| 957 | case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT): |
| 958 | DP(NETIF_MSG_IFUP, "got setup ramrod\n"); |
| 959 | bp->state = BNX2X_STATE_OPEN; |
| 960 | break; |
| 961 | |
| 962 | case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT): |
| 963 | DP(NETIF_MSG_IFDOWN, "got halt ramrod\n"); |
| 964 | bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE; |
| 965 | fp->state = BNX2X_FP_STATE_HALTED; |
| 966 | break; |
| 967 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 968 | case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 969 | DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 970 | bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 971 | break; |
| 972 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 973 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 974 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 975 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG): |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 976 | DP(NETIF_MSG_IFUP, "got set mac ramrod\n"); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 977 | bp->set_mac_pending = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 978 | break; |
| 979 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 980 | case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT): |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 981 | DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n"); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 982 | break; |
| 983 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 984 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 985 | BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 986 | command, bp->state); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 987 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 988 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 989 | mb(); /* force bnx2x_wait_ramrod() to see the change */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 990 | } |
| 991 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 992 | static inline void bnx2x_free_rx_sge(struct bnx2x *bp, |
| 993 | struct bnx2x_fastpath *fp, u16 index) |
| 994 | { |
| 995 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 996 | struct page *page = sw_buf->page; |
| 997 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 998 | |
| 999 | /* Skip "next page" elements */ |
| 1000 | if (!page) |
| 1001 | return; |
| 1002 | |
| 1003 | pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping), |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1004 | SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1005 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 1006 | |
| 1007 | sw_buf->page = NULL; |
| 1008 | sge->addr_hi = 0; |
| 1009 | sge->addr_lo = 0; |
| 1010 | } |
| 1011 | |
| 1012 | static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp, |
| 1013 | struct bnx2x_fastpath *fp, int last) |
| 1014 | { |
| 1015 | int i; |
| 1016 | |
| 1017 | for (i = 0; i < last; i++) |
| 1018 | bnx2x_free_rx_sge(bp, fp, i); |
| 1019 | } |
| 1020 | |
| 1021 | static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp, |
| 1022 | struct bnx2x_fastpath *fp, u16 index) |
| 1023 | { |
| 1024 | struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT); |
| 1025 | struct sw_rx_page *sw_buf = &fp->rx_page_ring[index]; |
| 1026 | struct eth_rx_sge *sge = &fp->rx_sge_ring[index]; |
| 1027 | dma_addr_t mapping; |
| 1028 | |
| 1029 | if (unlikely(page == NULL)) |
| 1030 | return -ENOMEM; |
| 1031 | |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1032 | mapping = pci_map_page(bp->pdev, page, 0, SGE_PAGE_SIZE*PAGES_PER_SGE, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1033 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1034 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1035 | __free_pages(page, PAGES_PER_SGE_SHIFT); |
| 1036 | return -ENOMEM; |
| 1037 | } |
| 1038 | |
| 1039 | sw_buf->page = page; |
| 1040 | pci_unmap_addr_set(sw_buf, mapping, mapping); |
| 1041 | |
| 1042 | sge->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1043 | sge->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1048 | static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp, |
| 1049 | struct bnx2x_fastpath *fp, u16 index) |
| 1050 | { |
| 1051 | struct sk_buff *skb; |
| 1052 | struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index]; |
| 1053 | struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index]; |
| 1054 | dma_addr_t mapping; |
| 1055 | |
| 1056 | skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 1057 | if (unlikely(skb == NULL)) |
| 1058 | return -ENOMEM; |
| 1059 | |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1060 | mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1061 | PCI_DMA_FROMDEVICE); |
FUJITA Tomonori | 8d8bb39 | 2008-07-25 19:44:49 -0700 | [diff] [blame] | 1062 | if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1063 | dev_kfree_skb(skb); |
| 1064 | return -ENOMEM; |
| 1065 | } |
| 1066 | |
| 1067 | rx_buf->skb = skb; |
| 1068 | pci_unmap_addr_set(rx_buf, mapping, mapping); |
| 1069 | |
| 1070 | rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1071 | rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1072 | |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | /* note that we are not allocating a new skb, |
| 1077 | * we are just moving one from cons to prod |
| 1078 | * we are not creating a new mapping, |
| 1079 | * so there is no need to check for dma_mapping_error(). |
| 1080 | */ |
| 1081 | static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp, |
| 1082 | struct sk_buff *skb, u16 cons, u16 prod) |
| 1083 | { |
| 1084 | struct bnx2x *bp = fp->bp; |
| 1085 | struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons]; |
| 1086 | struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod]; |
| 1087 | struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons]; |
| 1088 | struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod]; |
| 1089 | |
| 1090 | pci_dma_sync_single_for_device(bp->pdev, |
| 1091 | pci_unmap_addr(cons_rx_buf, mapping), |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 1092 | RX_COPY_THRESH, PCI_DMA_FROMDEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1093 | |
| 1094 | prod_rx_buf->skb = cons_rx_buf->skb; |
| 1095 | pci_unmap_addr_set(prod_rx_buf, mapping, |
| 1096 | pci_unmap_addr(cons_rx_buf, mapping)); |
| 1097 | *prod_bd = *cons_bd; |
| 1098 | } |
| 1099 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1100 | static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp, |
| 1101 | u16 idx) |
| 1102 | { |
| 1103 | u16 last_max = fp->last_max_sge; |
| 1104 | |
| 1105 | if (SUB_S16(idx, last_max) > 0) |
| 1106 | fp->last_max_sge = idx; |
| 1107 | } |
| 1108 | |
| 1109 | static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp) |
| 1110 | { |
| 1111 | int i, j; |
| 1112 | |
| 1113 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 1114 | int idx = RX_SGE_CNT * i - 1; |
| 1115 | |
| 1116 | for (j = 0; j < 2; j++) { |
| 1117 | SGE_MASK_CLEAR_BIT(fp, idx); |
| 1118 | idx--; |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp, |
| 1124 | struct eth_fast_path_rx_cqe *fp_cqe) |
| 1125 | { |
| 1126 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1127 | u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) - |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1128 | le16_to_cpu(fp_cqe->len_on_bd)) >> |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1129 | SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1130 | u16 last_max, last_elem, first_elem; |
| 1131 | u16 delta = 0; |
| 1132 | u16 i; |
| 1133 | |
| 1134 | if (!sge_len) |
| 1135 | return; |
| 1136 | |
| 1137 | /* First mark all used pages */ |
| 1138 | for (i = 0; i < sge_len; i++) |
| 1139 | SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i]))); |
| 1140 | |
| 1141 | DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n", |
| 1142 | sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1])); |
| 1143 | |
| 1144 | /* Here we assume that the last SGE index is the biggest */ |
| 1145 | prefetch((void *)(fp->sge_mask)); |
| 1146 | bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1])); |
| 1147 | |
| 1148 | last_max = RX_SGE(fp->last_max_sge); |
| 1149 | last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT; |
| 1150 | first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT; |
| 1151 | |
| 1152 | /* If ring is not full */ |
| 1153 | if (last_elem + 1 != first_elem) |
| 1154 | last_elem++; |
| 1155 | |
| 1156 | /* Now update the prod */ |
| 1157 | for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) { |
| 1158 | if (likely(fp->sge_mask[i])) |
| 1159 | break; |
| 1160 | |
| 1161 | fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK; |
| 1162 | delta += RX_SGE_MASK_ELEM_SZ; |
| 1163 | } |
| 1164 | |
| 1165 | if (delta > 0) { |
| 1166 | fp->rx_sge_prod += delta; |
| 1167 | /* clear page-end entries */ |
| 1168 | bnx2x_clear_sge_mask_next_elems(fp); |
| 1169 | } |
| 1170 | |
| 1171 | DP(NETIF_MSG_RX_STATUS, |
| 1172 | "fp->last_max_sge = %d fp->rx_sge_prod = %d\n", |
| 1173 | fp->last_max_sge, fp->rx_sge_prod); |
| 1174 | } |
| 1175 | |
| 1176 | static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp) |
| 1177 | { |
| 1178 | /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */ |
| 1179 | memset(fp->sge_mask, 0xff, |
| 1180 | (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64)); |
| 1181 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 1182 | /* Clear the two last indices in the page to 1: |
| 1183 | these are the indices that correspond to the "next" element, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1184 | hence will never be indicated and should be removed from |
| 1185 | the calculations. */ |
| 1186 | bnx2x_clear_sge_mask_next_elems(fp); |
| 1187 | } |
| 1188 | |
| 1189 | static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue, |
| 1190 | struct sk_buff *skb, u16 cons, u16 prod) |
| 1191 | { |
| 1192 | struct bnx2x *bp = fp->bp; |
| 1193 | struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons]; |
| 1194 | struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod]; |
| 1195 | struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod]; |
| 1196 | dma_addr_t mapping; |
| 1197 | |
| 1198 | /* move empty skb from pool to prod and map it */ |
| 1199 | prod_rx_buf->skb = fp->tpa_pool[queue].skb; |
| 1200 | mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data, |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1201 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1202 | pci_unmap_addr_set(prod_rx_buf, mapping, mapping); |
| 1203 | |
| 1204 | /* move partial skb from cons to pool (don't unmap yet) */ |
| 1205 | fp->tpa_pool[queue] = *cons_rx_buf; |
| 1206 | |
| 1207 | /* mark bin state as start - print error if current state != stop */ |
| 1208 | if (fp->tpa_state[queue] != BNX2X_TPA_STOP) |
| 1209 | BNX2X_ERR("start of bin not in stop [%d]\n", queue); |
| 1210 | |
| 1211 | fp->tpa_state[queue] = BNX2X_TPA_START; |
| 1212 | |
| 1213 | /* point prod_bd to new skb */ |
| 1214 | prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 1215 | prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 1216 | |
| 1217 | #ifdef BNX2X_STOP_ON_ERROR |
| 1218 | fp->tpa_queue_used |= (1 << queue); |
| 1219 | #ifdef __powerpc64__ |
| 1220 | DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n", |
| 1221 | #else |
| 1222 | DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n", |
| 1223 | #endif |
| 1224 | fp->tpa_queue_used); |
| 1225 | #endif |
| 1226 | } |
| 1227 | |
| 1228 | static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 1229 | struct sk_buff *skb, |
| 1230 | struct eth_fast_path_rx_cqe *fp_cqe, |
| 1231 | u16 cqe_idx) |
| 1232 | { |
| 1233 | struct sw_rx_page *rx_pg, old_rx_pg; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1234 | u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd); |
| 1235 | u32 i, frag_len, frag_size, pages; |
| 1236 | int err; |
| 1237 | int j; |
| 1238 | |
| 1239 | frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd; |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1240 | pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1241 | |
| 1242 | /* This is needed in order to enable forwarding support */ |
| 1243 | if (frag_size) |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1244 | skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1245 | max(frag_size, (u32)len_on_bd)); |
| 1246 | |
| 1247 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1248 | if (pages > |
| 1249 | min((u32)8, (u32)MAX_SKB_FRAGS) * SGE_PAGE_SIZE * PAGES_PER_SGE) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1250 | BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n", |
| 1251 | pages, cqe_idx); |
| 1252 | BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n", |
| 1253 | fp_cqe->pkt_len, len_on_bd); |
| 1254 | bnx2x_panic(); |
| 1255 | return -EINVAL; |
| 1256 | } |
| 1257 | #endif |
| 1258 | |
| 1259 | /* Run through the SGL and compose the fragmented skb */ |
| 1260 | for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) { |
| 1261 | u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j])); |
| 1262 | |
| 1263 | /* FW gives the indices of the SGE as if the ring is an array |
| 1264 | (meaning that "next" element will consume 2 indices) */ |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1265 | frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1266 | rx_pg = &fp->rx_page_ring[sge_idx]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1267 | old_rx_pg = *rx_pg; |
| 1268 | |
| 1269 | /* If we fail to allocate a substitute page, we simply stop |
| 1270 | where we are and drop the whole packet */ |
| 1271 | err = bnx2x_alloc_rx_sge(bp, fp, sge_idx); |
| 1272 | if (unlikely(err)) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1273 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1274 | return err; |
| 1275 | } |
| 1276 | |
| 1277 | /* Unmap the page as we r going to pass it to the stack */ |
| 1278 | pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping), |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 1279 | SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1280 | |
| 1281 | /* Add one frag and update the appropriate fields in the skb */ |
| 1282 | skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len); |
| 1283 | |
| 1284 | skb->data_len += frag_len; |
| 1285 | skb->truesize += frag_len; |
| 1286 | skb->len += frag_len; |
| 1287 | |
| 1288 | frag_size -= frag_len; |
| 1289 | } |
| 1290 | |
| 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp, |
| 1295 | u16 queue, int pad, int len, union eth_rx_cqe *cqe, |
| 1296 | u16 cqe_idx) |
| 1297 | { |
| 1298 | struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue]; |
| 1299 | struct sk_buff *skb = rx_buf->skb; |
| 1300 | /* alloc new skb */ |
| 1301 | struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 1302 | |
| 1303 | /* Unmap skb in the pool anyway, as we are going to change |
| 1304 | pool entry status to BNX2X_TPA_STOP even if new skb allocation |
| 1305 | fails. */ |
| 1306 | pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1307 | bp->rx_buf_size, PCI_DMA_FROMDEVICE); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1308 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1309 | if (likely(new_skb)) { |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1310 | /* fix ip xsum and give it to the stack */ |
| 1311 | /* (no need to map the new skb) */ |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1312 | #ifdef BCM_VLAN |
| 1313 | int is_vlan_cqe = |
| 1314 | (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) & |
| 1315 | PARSING_FLAGS_VLAN); |
| 1316 | int is_not_hwaccel_vlan_cqe = |
| 1317 | (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG))); |
| 1318 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1319 | |
| 1320 | prefetch(skb); |
| 1321 | prefetch(((char *)(skb)) + 128); |
| 1322 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1323 | #ifdef BNX2X_STOP_ON_ERROR |
| 1324 | if (pad + len > bp->rx_buf_size) { |
| 1325 | BNX2X_ERR("skb_put is about to fail... " |
| 1326 | "pad %d len %d rx_buf_size %d\n", |
| 1327 | pad, len, bp->rx_buf_size); |
| 1328 | bnx2x_panic(); |
| 1329 | return; |
| 1330 | } |
| 1331 | #endif |
| 1332 | |
| 1333 | skb_reserve(skb, pad); |
| 1334 | skb_put(skb, len); |
| 1335 | |
| 1336 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1337 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1338 | |
| 1339 | { |
| 1340 | struct iphdr *iph; |
| 1341 | |
| 1342 | iph = (struct iphdr *)skb->data; |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1343 | #ifdef BCM_VLAN |
| 1344 | /* If there is no Rx VLAN offloading - |
| 1345 | take VLAN tag into an account */ |
| 1346 | if (unlikely(is_not_hwaccel_vlan_cqe)) |
| 1347 | iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN); |
| 1348 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1349 | iph->check = 0; |
| 1350 | iph->check = ip_fast_csum((u8 *)iph, iph->ihl); |
| 1351 | } |
| 1352 | |
| 1353 | if (!bnx2x_fill_frag_skb(bp, fp, skb, |
| 1354 | &cqe->fast_path_cqe, cqe_idx)) { |
| 1355 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1356 | if ((bp->vlgrp != NULL) && is_vlan_cqe && |
| 1357 | (!is_not_hwaccel_vlan_cqe)) |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1358 | vlan_hwaccel_receive_skb(skb, bp->vlgrp, |
| 1359 | le16_to_cpu(cqe->fast_path_cqe. |
| 1360 | vlan_tag)); |
| 1361 | else |
| 1362 | #endif |
| 1363 | netif_receive_skb(skb); |
| 1364 | } else { |
| 1365 | DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages" |
| 1366 | " - dropping packet!\n"); |
| 1367 | dev_kfree_skb(skb); |
| 1368 | } |
| 1369 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1370 | |
| 1371 | /* put new skb in bin */ |
| 1372 | fp->tpa_pool[queue].skb = new_skb; |
| 1373 | |
| 1374 | } else { |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1375 | /* else drop the packet and keep the buffer in the bin */ |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1376 | DP(NETIF_MSG_RX_STATUS, |
| 1377 | "Failed to allocate new skb - dropping packet!\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1378 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | fp->tpa_state[queue] = BNX2X_TPA_STOP; |
| 1382 | } |
| 1383 | |
| 1384 | static inline void bnx2x_update_rx_prod(struct bnx2x *bp, |
| 1385 | struct bnx2x_fastpath *fp, |
| 1386 | u16 bd_prod, u16 rx_comp_prod, |
| 1387 | u16 rx_sge_prod) |
| 1388 | { |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 1389 | struct ustorm_eth_rx_producers rx_prods = {0}; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1390 | int i; |
| 1391 | |
| 1392 | /* Update producers */ |
| 1393 | rx_prods.bd_prod = bd_prod; |
| 1394 | rx_prods.cqe_prod = rx_comp_prod; |
| 1395 | rx_prods.sge_prod = rx_sge_prod; |
| 1396 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 1397 | /* |
| 1398 | * Make sure that the BD and SGE data is updated before updating the |
| 1399 | * producers since FW might read the BD/SGE right after the producer |
| 1400 | * is updated. |
| 1401 | * This is only applicable for weak-ordered memory model archs such |
| 1402 | * as IA-64. The following barrier is also mandatory since FW will |
| 1403 | * assumes BDs must have buffers. |
| 1404 | */ |
| 1405 | wmb(); |
| 1406 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 1407 | for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++) |
| 1408 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 1409 | USTORM_RX_PRODS_OFFSET(BP_PORT(bp), FP_CL_ID(fp)) + i*4, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1410 | ((u32 *)&rx_prods)[i]); |
| 1411 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 1412 | mmiowb(); /* keep prod updates ordered */ |
| 1413 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1414 | DP(NETIF_MSG_RX_STATUS, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 1415 | "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n", |
| 1416 | fp->index, bd_prod, rx_comp_prod, rx_sge_prod); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1419 | static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget) |
| 1420 | { |
| 1421 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1422 | u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1423 | u16 hw_comp_cons, sw_comp_cons, sw_comp_prod; |
| 1424 | int rx_pkt = 0; |
| 1425 | |
| 1426 | #ifdef BNX2X_STOP_ON_ERROR |
| 1427 | if (unlikely(bp->panic)) |
| 1428 | return 0; |
| 1429 | #endif |
| 1430 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1431 | /* CQ "next element" is of the size of the regular element, |
| 1432 | that's why it's ok here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1433 | hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb); |
| 1434 | if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT) |
| 1435 | hw_comp_cons++; |
| 1436 | |
| 1437 | bd_cons = fp->rx_bd_cons; |
| 1438 | bd_prod = fp->rx_bd_prod; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1439 | bd_prod_fw = bd_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1440 | sw_comp_cons = fp->rx_comp_cons; |
| 1441 | sw_comp_prod = fp->rx_comp_prod; |
| 1442 | |
| 1443 | /* Memory barrier necessary as speculative reads of the rx |
| 1444 | * buffer can be ahead of the index in the status block |
| 1445 | */ |
| 1446 | rmb(); |
| 1447 | |
| 1448 | DP(NETIF_MSG_RX_STATUS, |
| 1449 | "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1450 | FP_IDX(fp), hw_comp_cons, sw_comp_cons); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1451 | |
| 1452 | while (sw_comp_cons != hw_comp_cons) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1453 | struct sw_rx_bd *rx_buf = NULL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1454 | struct sk_buff *skb; |
| 1455 | union eth_rx_cqe *cqe; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1456 | u8 cqe_fp_flags; |
| 1457 | u16 len, pad; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1458 | |
| 1459 | comp_ring_cons = RCQ_BD(sw_comp_cons); |
| 1460 | bd_prod = RX_BD(bd_prod); |
| 1461 | bd_cons = RX_BD(bd_cons); |
| 1462 | |
| 1463 | cqe = &fp->rx_comp_ring[comp_ring_cons]; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1464 | cqe_fp_flags = cqe->fast_path_cqe.type_error_flags; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1465 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1466 | DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1467 | " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags), |
| 1468 | cqe_fp_flags, cqe->fast_path_cqe.status_flags, |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 1469 | le32_to_cpu(cqe->fast_path_cqe.rss_hash_result), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1470 | le16_to_cpu(cqe->fast_path_cqe.vlan_tag), |
| 1471 | le16_to_cpu(cqe->fast_path_cqe.pkt_len)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1472 | |
| 1473 | /* is this a slowpath msg? */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1474 | if (unlikely(CQE_TYPE(cqe_fp_flags))) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1475 | bnx2x_sp_event(fp, cqe); |
| 1476 | goto next_cqe; |
| 1477 | |
| 1478 | /* this is an rx packet */ |
| 1479 | } else { |
| 1480 | rx_buf = &fp->rx_buf_ring[bd_cons]; |
| 1481 | skb = rx_buf->skb; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1482 | len = le16_to_cpu(cqe->fast_path_cqe.pkt_len); |
| 1483 | pad = cqe->fast_path_cqe.placement_offset; |
| 1484 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1485 | /* If CQE is marked both TPA_START and TPA_END |
| 1486 | it is a non-TPA CQE */ |
| 1487 | if ((!fp->disable_tpa) && |
| 1488 | (TPA_TYPE(cqe_fp_flags) != |
| 1489 | (TPA_TYPE_START | TPA_TYPE_END))) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1490 | u16 queue = cqe->fast_path_cqe.queue_index; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1491 | |
| 1492 | if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) { |
| 1493 | DP(NETIF_MSG_RX_STATUS, |
| 1494 | "calling tpa_start on queue %d\n", |
| 1495 | queue); |
| 1496 | |
| 1497 | bnx2x_tpa_start(fp, queue, skb, |
| 1498 | bd_cons, bd_prod); |
| 1499 | goto next_rx; |
| 1500 | } |
| 1501 | |
| 1502 | if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) { |
| 1503 | DP(NETIF_MSG_RX_STATUS, |
| 1504 | "calling tpa_stop on queue %d\n", |
| 1505 | queue); |
| 1506 | |
| 1507 | if (!BNX2X_RX_SUM_FIX(cqe)) |
| 1508 | BNX2X_ERR("STOP on none TCP " |
| 1509 | "data\n"); |
| 1510 | |
| 1511 | /* This is a size of the linear data |
| 1512 | on this skb */ |
| 1513 | len = le16_to_cpu(cqe->fast_path_cqe. |
| 1514 | len_on_bd); |
| 1515 | bnx2x_tpa_stop(bp, fp, queue, pad, |
| 1516 | len, cqe, comp_ring_cons); |
| 1517 | #ifdef BNX2X_STOP_ON_ERROR |
| 1518 | if (bp->panic) |
| 1519 | return -EINVAL; |
| 1520 | #endif |
| 1521 | |
| 1522 | bnx2x_update_sge_prod(fp, |
| 1523 | &cqe->fast_path_cqe); |
| 1524 | goto next_cqe; |
| 1525 | } |
| 1526 | } |
| 1527 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1528 | pci_dma_sync_single_for_device(bp->pdev, |
| 1529 | pci_unmap_addr(rx_buf, mapping), |
| 1530 | pad + RX_COPY_THRESH, |
| 1531 | PCI_DMA_FROMDEVICE); |
| 1532 | prefetch(skb); |
| 1533 | prefetch(((char *)(skb)) + 128); |
| 1534 | |
| 1535 | /* is this an error packet? */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1536 | if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1537 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1538 | "ERROR flags %x rx packet %u\n", |
| 1539 | cqe_fp_flags, sw_comp_cons); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1540 | fp->eth_q_stats.rx_err_discard_pkt++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1541 | goto reuse_rx; |
| 1542 | } |
| 1543 | |
| 1544 | /* Since we don't have a jumbo ring |
| 1545 | * copy small packets if mtu > 1500 |
| 1546 | */ |
| 1547 | if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) && |
| 1548 | (len <= RX_COPY_THRESH)) { |
| 1549 | struct sk_buff *new_skb; |
| 1550 | |
| 1551 | new_skb = netdev_alloc_skb(bp->dev, |
| 1552 | len + pad); |
| 1553 | if (new_skb == NULL) { |
| 1554 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1555 | "ERROR packet dropped " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1556 | "because of alloc failure\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1557 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1558 | goto reuse_rx; |
| 1559 | } |
| 1560 | |
| 1561 | /* aligned copy */ |
| 1562 | skb_copy_from_linear_data_offset(skb, pad, |
| 1563 | new_skb->data + pad, len); |
| 1564 | skb_reserve(new_skb, pad); |
| 1565 | skb_put(new_skb, len); |
| 1566 | |
| 1567 | bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod); |
| 1568 | |
| 1569 | skb = new_skb; |
| 1570 | |
| 1571 | } else if (bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0) { |
| 1572 | pci_unmap_single(bp->pdev, |
| 1573 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 1574 | bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1575 | PCI_DMA_FROMDEVICE); |
| 1576 | skb_reserve(skb, pad); |
| 1577 | skb_put(skb, len); |
| 1578 | |
| 1579 | } else { |
| 1580 | DP(NETIF_MSG_RX_ERR, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1581 | "ERROR packet dropped because " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1582 | "of alloc failure\n"); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1583 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1584 | reuse_rx: |
| 1585 | bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod); |
| 1586 | goto next_rx; |
| 1587 | } |
| 1588 | |
| 1589 | skb->protocol = eth_type_trans(skb, bp->dev); |
| 1590 | |
| 1591 | skb->ip_summed = CHECKSUM_NONE; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1592 | if (bp->rx_csum) { |
Eilon Greenstein | 1adcd8b | 2008-08-13 15:48:29 -0700 | [diff] [blame] | 1593 | if (likely(BNX2X_RX_CSUM_OK(cqe))) |
| 1594 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1595 | else |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 1596 | fp->eth_q_stats.hw_csum_err++; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 1597 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1598 | } |
| 1599 | |
Eilon Greenstein | 748e543 | 2009-02-12 08:36:37 +0000 | [diff] [blame] | 1600 | skb_record_rx_queue(skb, fp->index); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1601 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 1602 | if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) && |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1603 | (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) & |
| 1604 | PARSING_FLAGS_VLAN)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1605 | vlan_hwaccel_receive_skb(skb, bp->vlgrp, |
| 1606 | le16_to_cpu(cqe->fast_path_cqe.vlan_tag)); |
| 1607 | else |
| 1608 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1609 | netif_receive_skb(skb); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1610 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1611 | |
| 1612 | next_rx: |
| 1613 | rx_buf->skb = NULL; |
| 1614 | |
| 1615 | bd_cons = NEXT_RX_IDX(bd_cons); |
| 1616 | bd_prod = NEXT_RX_IDX(bd_prod); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1617 | bd_prod_fw = NEXT_RX_IDX(bd_prod_fw); |
| 1618 | rx_pkt++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1619 | next_cqe: |
| 1620 | sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod); |
| 1621 | sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1622 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1623 | if (rx_pkt == budget) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1624 | break; |
| 1625 | } /* while */ |
| 1626 | |
| 1627 | fp->rx_bd_cons = bd_cons; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1628 | fp->rx_bd_prod = bd_prod_fw; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1629 | fp->rx_comp_cons = sw_comp_cons; |
| 1630 | fp->rx_comp_prod = sw_comp_prod; |
| 1631 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 1632 | /* Update producers */ |
| 1633 | bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod, |
| 1634 | fp->rx_sge_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1635 | |
| 1636 | fp->rx_pkt += rx_pkt; |
| 1637 | fp->rx_calls++; |
| 1638 | |
| 1639 | return rx_pkt; |
| 1640 | } |
| 1641 | |
| 1642 | static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie) |
| 1643 | { |
| 1644 | struct bnx2x_fastpath *fp = fp_cookie; |
| 1645 | struct bnx2x *bp = fp->bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1646 | int index = FP_IDX(fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1647 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 1648 | /* Return here if interrupt is disabled */ |
| 1649 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
| 1650 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
| 1651 | return IRQ_HANDLED; |
| 1652 | } |
| 1653 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1654 | DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n", |
| 1655 | index, FP_SB_ID(fp)); |
| 1656 | bnx2x_ack_sb(bp, FP_SB_ID(fp), USTORM_ID, 0, IGU_INT_DISABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1657 | |
| 1658 | #ifdef BNX2X_STOP_ON_ERROR |
| 1659 | if (unlikely(bp->panic)) |
| 1660 | return IRQ_HANDLED; |
| 1661 | #endif |
| 1662 | |
| 1663 | prefetch(fp->rx_cons_sb); |
| 1664 | prefetch(fp->tx_cons_sb); |
| 1665 | prefetch(&fp->status_blk->c_status_block.status_block_index); |
| 1666 | prefetch(&fp->status_blk->u_status_block.status_block_index); |
| 1667 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1668 | napi_schedule(&bnx2x_fp(bp, index, napi)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1669 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1670 | return IRQ_HANDLED; |
| 1671 | } |
| 1672 | |
| 1673 | static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance) |
| 1674 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 1675 | struct bnx2x *bp = netdev_priv(dev_instance); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1676 | u16 status = bnx2x_ack_int(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1677 | u16 mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1678 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1679 | /* Return here if interrupt is shared and it's not for us */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1680 | if (unlikely(status == 0)) { |
| 1681 | DP(NETIF_MSG_INTR, "not our interrupt!\n"); |
| 1682 | return IRQ_NONE; |
| 1683 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1684 | DP(NETIF_MSG_INTR, "got an interrupt status %u\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1685 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1686 | /* Return here if interrupt is disabled */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1687 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
| 1688 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
| 1689 | return IRQ_HANDLED; |
| 1690 | } |
| 1691 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 1692 | #ifdef BNX2X_STOP_ON_ERROR |
| 1693 | if (unlikely(bp->panic)) |
| 1694 | return IRQ_HANDLED; |
| 1695 | #endif |
| 1696 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1697 | mask = 0x2 << bp->fp[0].sb_id; |
| 1698 | if (status & mask) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1699 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
| 1700 | |
| 1701 | prefetch(fp->rx_cons_sb); |
| 1702 | prefetch(fp->tx_cons_sb); |
| 1703 | prefetch(&fp->status_blk->c_status_block.status_block_index); |
| 1704 | prefetch(&fp->status_blk->u_status_block.status_block_index); |
| 1705 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1706 | napi_schedule(&bnx2x_fp(bp, 0, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1707 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1708 | status &= ~mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1709 | } |
| 1710 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1711 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1712 | if (unlikely(status & 0x1)) { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 1713 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1714 | |
| 1715 | status &= ~0x1; |
| 1716 | if (!status) |
| 1717 | return IRQ_HANDLED; |
| 1718 | } |
| 1719 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1720 | if (status) |
| 1721 | DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n", |
| 1722 | status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1723 | |
| 1724 | return IRQ_HANDLED; |
| 1725 | } |
| 1726 | |
| 1727 | /* end of fast path */ |
| 1728 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 1729 | static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1730 | |
| 1731 | /* Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1732 | |
| 1733 | /* |
| 1734 | * General service functions |
| 1735 | */ |
| 1736 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1737 | static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1738 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1739 | u32 lock_status; |
| 1740 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1741 | int func = BP_FUNC(bp); |
| 1742 | u32 hw_lock_control_reg; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1743 | int cnt; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1744 | |
| 1745 | /* Validating that the resource is within range */ |
| 1746 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1747 | DP(NETIF_MSG_HW, |
| 1748 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1749 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1750 | return -EINVAL; |
| 1751 | } |
| 1752 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1753 | if (func <= 5) { |
| 1754 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1755 | } else { |
| 1756 | hw_lock_control_reg = |
| 1757 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1758 | } |
| 1759 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1760 | /* Validating that the resource is not already taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1761 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1762 | if (lock_status & resource_bit) { |
| 1763 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1764 | lock_status, resource_bit); |
| 1765 | return -EEXIST; |
| 1766 | } |
| 1767 | |
Eilon Greenstein | 46230476b | 2008-08-25 15:23:30 -0700 | [diff] [blame] | 1768 | /* Try for 5 second every 5ms */ |
| 1769 | for (cnt = 0; cnt < 1000; cnt++) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1770 | /* Try to acquire the lock */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1771 | REG_WR(bp, hw_lock_control_reg + 4, resource_bit); |
| 1772 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1773 | if (lock_status & resource_bit) |
| 1774 | return 0; |
| 1775 | |
| 1776 | msleep(5); |
| 1777 | } |
| 1778 | DP(NETIF_MSG_HW, "Timeout\n"); |
| 1779 | return -EAGAIN; |
| 1780 | } |
| 1781 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1782 | static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1783 | { |
| 1784 | u32 lock_status; |
| 1785 | u32 resource_bit = (1 << resource); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1786 | int func = BP_FUNC(bp); |
| 1787 | u32 hw_lock_control_reg; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1788 | |
| 1789 | /* Validating that the resource is within range */ |
| 1790 | if (resource > HW_LOCK_MAX_RESOURCE_VALUE) { |
| 1791 | DP(NETIF_MSG_HW, |
| 1792 | "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n", |
| 1793 | resource, HW_LOCK_MAX_RESOURCE_VALUE); |
| 1794 | return -EINVAL; |
| 1795 | } |
| 1796 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1797 | if (func <= 5) { |
| 1798 | hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8); |
| 1799 | } else { |
| 1800 | hw_lock_control_reg = |
| 1801 | (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8); |
| 1802 | } |
| 1803 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1804 | /* Validating that the resource is currently taken */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1805 | lock_status = REG_RD(bp, hw_lock_control_reg); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1806 | if (!(lock_status & resource_bit)) { |
| 1807 | DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n", |
| 1808 | lock_status, resource_bit); |
| 1809 | return -EFAULT; |
| 1810 | } |
| 1811 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1812 | REG_WR(bp, hw_lock_control_reg, resource_bit); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1813 | return 0; |
| 1814 | } |
| 1815 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1816 | /* HW Lock for shared dual port PHYs */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1817 | static void bnx2x_acquire_phy_lock(struct bnx2x *bp) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1818 | { |
| 1819 | u32 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 1820 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1821 | mutex_lock(&bp->port.phy_mutex); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1822 | |
| 1823 | if ((ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072) || |
| 1824 | (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)) |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1825 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_8072_MDIO); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1828 | static void bnx2x_release_phy_lock(struct bnx2x *bp) |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1829 | { |
| 1830 | u32 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 1831 | |
| 1832 | if ((ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072) || |
| 1833 | (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073)) |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1834 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_8072_MDIO); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1835 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1836 | mutex_unlock(&bp->port.phy_mutex); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1839 | int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1840 | { |
| 1841 | /* The GPIO should be swapped if swap register is set and active */ |
| 1842 | int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) && |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1843 | REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1844 | int gpio_shift = gpio_num + |
| 1845 | (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0); |
| 1846 | u32 gpio_mask = (1 << gpio_shift); |
| 1847 | u32 gpio_reg; |
| 1848 | |
| 1849 | if (gpio_num > MISC_REGISTERS_GPIO_3) { |
| 1850 | BNX2X_ERR("Invalid GPIO %d\n", gpio_num); |
| 1851 | return -EINVAL; |
| 1852 | } |
| 1853 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1854 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1855 | /* read GPIO and mask except the float bits */ |
| 1856 | gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT); |
| 1857 | |
| 1858 | switch (mode) { |
| 1859 | case MISC_REGISTERS_GPIO_OUTPUT_LOW: |
| 1860 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n", |
| 1861 | gpio_num, gpio_shift); |
| 1862 | /* clear FLOAT and set CLR */ |
| 1863 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1864 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS); |
| 1865 | break; |
| 1866 | |
| 1867 | case MISC_REGISTERS_GPIO_OUTPUT_HIGH: |
| 1868 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n", |
| 1869 | gpio_num, gpio_shift); |
| 1870 | /* clear FLOAT and set SET */ |
| 1871 | gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1872 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS); |
| 1873 | break; |
| 1874 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 1875 | case MISC_REGISTERS_GPIO_INPUT_HI_Z: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1876 | DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n", |
| 1877 | gpio_num, gpio_shift); |
| 1878 | /* set FLOAT */ |
| 1879 | gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS); |
| 1880 | break; |
| 1881 | |
| 1882 | default: |
| 1883 | break; |
| 1884 | } |
| 1885 | |
| 1886 | REG_WR(bp, MISC_REG_GPIO, gpio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1887 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1888 | |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode) |
| 1893 | { |
| 1894 | u32 spio_mask = (1 << spio_num); |
| 1895 | u32 spio_reg; |
| 1896 | |
| 1897 | if ((spio_num < MISC_REGISTERS_SPIO_4) || |
| 1898 | (spio_num > MISC_REGISTERS_SPIO_7)) { |
| 1899 | BNX2X_ERR("Invalid SPIO %d\n", spio_num); |
| 1900 | return -EINVAL; |
| 1901 | } |
| 1902 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1903 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1904 | /* read SPIO and mask except the float bits */ |
| 1905 | spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT); |
| 1906 | |
| 1907 | switch (mode) { |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 1908 | case MISC_REGISTERS_SPIO_OUTPUT_LOW: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1909 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num); |
| 1910 | /* clear FLOAT and set CLR */ |
| 1911 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 1912 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS); |
| 1913 | break; |
| 1914 | |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 1915 | case MISC_REGISTERS_SPIO_OUTPUT_HIGH: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1916 | DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num); |
| 1917 | /* clear FLOAT and set SET */ |
| 1918 | spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 1919 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS); |
| 1920 | break; |
| 1921 | |
| 1922 | case MISC_REGISTERS_SPIO_INPUT_HI_Z: |
| 1923 | DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num); |
| 1924 | /* set FLOAT */ |
| 1925 | spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS); |
| 1926 | break; |
| 1927 | |
| 1928 | default: |
| 1929 | break; |
| 1930 | } |
| 1931 | |
| 1932 | REG_WR(bp, MISC_REG_SPIO, spio_reg); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 1933 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1934 | |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1938 | static void bnx2x_calc_fc_adv(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1939 | { |
Eilon Greenstein | ad33ea3 | 2009-01-14 21:24:57 -0800 | [diff] [blame] | 1940 | switch (bp->link_vars.ieee_fc & |
| 1941 | MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1942 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1943 | bp->port.advertising &= ~(ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1944 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1945 | break; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1946 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1947 | bp->port.advertising |= (ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1948 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1949 | break; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1950 | case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1951 | bp->port.advertising |= ADVERTISED_Asym_Pause; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1952 | break; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1953 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 1954 | bp->port.advertising &= ~(ADVERTISED_Asym_Pause | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1955 | ADVERTISED_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 1956 | break; |
| 1957 | } |
| 1958 | } |
| 1959 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1960 | static void bnx2x_link_report(struct bnx2x *bp) |
| 1961 | { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1962 | if (bp->link_vars.link_up) { |
| 1963 | if (bp->state == BNX2X_STATE_OPEN) |
| 1964 | netif_carrier_on(bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1965 | printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name); |
| 1966 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1967 | printk("%d Mbps ", bp->link_vars.line_speed); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1968 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1969 | if (bp->link_vars.duplex == DUPLEX_FULL) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1970 | printk("full duplex"); |
| 1971 | else |
| 1972 | printk("half duplex"); |
| 1973 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 1974 | if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) { |
| 1975 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1976 | printk(", receive "); |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 1977 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1978 | printk("& transmit "); |
| 1979 | } else { |
| 1980 | printk(", transmit "); |
| 1981 | } |
| 1982 | printk("flow control ON"); |
| 1983 | } |
| 1984 | printk("\n"); |
| 1985 | |
| 1986 | } else { /* link_down */ |
| 1987 | netif_carrier_off(bp->dev); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1988 | printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 1992 | static u8 bnx2x_initial_phy_init(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1993 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 1994 | if (!BP_NOMCP(bp)) { |
| 1995 | u8 rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 1996 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 1997 | /* Initialize link parameters structure variables */ |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 1998 | /* It is recommended to turn off RX FC for jumbo frames |
| 1999 | for better performance */ |
| 2000 | if (IS_E1HMF(bp)) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2001 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2002 | else if (bp->dev->mtu > 5000) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2003 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX; |
Yaniv Rosner | 8c99e7b | 2008-08-13 15:56:17 -0700 | [diff] [blame] | 2004 | else |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 2005 | bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2006 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2007 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2008 | rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2009 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2010 | |
Eilon Greenstein | 3c96c68 | 2009-01-14 21:25:31 -0800 | [diff] [blame] | 2011 | bnx2x_calc_fc_adv(bp); |
| 2012 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2013 | if (bp->link_vars.link_up) |
| 2014 | bnx2x_link_report(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2015 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2016 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2017 | return rc; |
| 2018 | } |
| 2019 | BNX2X_ERR("Bootcode is missing -not initializing link\n"); |
| 2020 | return -EINVAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2021 | } |
| 2022 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2023 | static void bnx2x_link_set(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2024 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2025 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2026 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2027 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2028 | bnx2x_release_phy_lock(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2029 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2030 | bnx2x_calc_fc_adv(bp); |
| 2031 | } else |
| 2032 | BNX2X_ERR("Bootcode is missing -not setting link\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2033 | } |
| 2034 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2035 | static void bnx2x__link_reset(struct bnx2x *bp) |
| 2036 | { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2037 | if (!BP_NOMCP(bp)) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2038 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2039 | bnx2x_link_reset(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2040 | bnx2x_release_phy_lock(bp); |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2041 | } else |
| 2042 | BNX2X_ERR("Bootcode is missing -not resetting link\n"); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | static u8 bnx2x_link_test(struct bnx2x *bp) |
| 2046 | { |
| 2047 | u8 rc; |
| 2048 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2049 | bnx2x_acquire_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2050 | rc = bnx2x_test_link(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2051 | bnx2x_release_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2052 | |
| 2053 | return rc; |
| 2054 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2055 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2056 | static void bnx2x_init_port_minmax(struct bnx2x *bp) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2057 | { |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2058 | u32 r_param = bp->link_vars.line_speed / 8; |
| 2059 | u32 fair_periodic_timeout_usec; |
| 2060 | u32 t_fair; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2061 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2062 | memset(&(bp->cmng.rs_vars), 0, |
| 2063 | sizeof(struct rate_shaping_vars_per_port)); |
| 2064 | memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2065 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2066 | /* 100 usec in SDM ticks = 25 since each tick is 4 usec */ |
| 2067 | bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2068 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2069 | /* this is the threshold below which no timer arming will occur |
| 2070 | 1.25 coefficient is for the threshold to be a little bigger |
| 2071 | than the real time, to compensate for timer in-accuracy */ |
| 2072 | bp->cmng.rs_vars.rs_threshold = |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2073 | (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4; |
| 2074 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2075 | /* resolution of fairness timer */ |
| 2076 | fair_periodic_timeout_usec = QM_ARB_BYTES / r_param; |
| 2077 | /* for 10G it is 1000usec. for 1G it is 10000usec. */ |
| 2078 | t_fair = T_FAIR_COEF / bp->link_vars.line_speed; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2079 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2080 | /* this is the threshold below which we won't arm the timer anymore */ |
| 2081 | bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2082 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2083 | /* we multiply by 1e3/8 to get bytes/msec. |
| 2084 | We don't want the credits to pass a credit |
| 2085 | of the t_fair*FAIR_MEM (algorithm resolution) */ |
| 2086 | bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM; |
| 2087 | /* since each tick is 4 usec */ |
| 2088 | bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2091 | static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2092 | { |
| 2093 | struct rate_shaping_vars_per_vn m_rs_vn; |
| 2094 | struct fairness_vars_per_vn m_fair_vn; |
| 2095 | u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 2096 | u16 vn_min_rate, vn_max_rate; |
| 2097 | int i; |
| 2098 | |
| 2099 | /* If function is hidden - set min and max to zeroes */ |
| 2100 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) { |
| 2101 | vn_min_rate = 0; |
| 2102 | vn_max_rate = 0; |
| 2103 | |
| 2104 | } else { |
| 2105 | vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 2106 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2107 | /* If fairness is enabled (not all min rates are zeroes) and |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2108 | if current min rate is zero - set it to 1. |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 2109 | This is a requirement of the algorithm. */ |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2110 | if (bp->vn_weight_sum && (vn_min_rate == 0)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2111 | vn_min_rate = DEF_MIN_RATE; |
| 2112 | vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >> |
| 2113 | FUNC_MF_CFG_MAX_BW_SHIFT) * 100; |
| 2114 | } |
| 2115 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2116 | DP(NETIF_MSG_IFUP, |
| 2117 | "func %d: vn_min_rate=%d vn_max_rate=%d vn_weight_sum=%d\n", |
| 2118 | func, vn_min_rate, vn_max_rate, bp->vn_weight_sum); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2119 | |
| 2120 | memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn)); |
| 2121 | memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn)); |
| 2122 | |
| 2123 | /* global vn counter - maximal Mbps for this vn */ |
| 2124 | m_rs_vn.vn_counter.rate = vn_max_rate; |
| 2125 | |
| 2126 | /* quota - number of bytes transmitted in this period */ |
| 2127 | m_rs_vn.vn_counter.quota = |
| 2128 | (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8; |
| 2129 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2130 | if (bp->vn_weight_sum) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2131 | /* credit for each period of the fairness algorithm: |
| 2132 | number of bytes in T_FAIR (the vn share the port rate). |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2133 | vn_weight_sum should not be larger than 10000, thus |
| 2134 | T_FAIR_COEF / (8 * vn_weight_sum) will always be greater |
| 2135 | than zero */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2136 | m_fair_vn.vn_credit_delta = |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2137 | max((u32)(vn_min_rate * (T_FAIR_COEF / |
| 2138 | (8 * bp->vn_weight_sum))), |
| 2139 | (u32)(bp->cmng.fair_vars.fair_threshold * 2)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2140 | DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n", |
| 2141 | m_fair_vn.vn_credit_delta); |
| 2142 | } |
| 2143 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2144 | /* Store it to internal memory */ |
| 2145 | for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++) |
| 2146 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2147 | XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2148 | ((u32 *)(&m_rs_vn))[i]); |
| 2149 | |
| 2150 | for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++) |
| 2151 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2152 | XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4, |
| 2153 | ((u32 *)(&m_fair_vn))[i]); |
| 2154 | } |
| 2155 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2156 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2157 | /* This function is called upon link interrupt */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2158 | static void bnx2x_link_attn(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2159 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2160 | /* Make sure that we are synced with the current statistics */ |
| 2161 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2162 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2163 | bnx2x_link_update(&bp->link_params, &bp->link_vars); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2164 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2165 | if (bp->link_vars.link_up) { |
| 2166 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 2167 | /* dropless flow control */ |
| 2168 | if (CHIP_IS_E1H(bp)) { |
| 2169 | int port = BP_PORT(bp); |
| 2170 | u32 pause_enabled = 0; |
| 2171 | |
| 2172 | if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) |
| 2173 | pause_enabled = 1; |
| 2174 | |
| 2175 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 2176 | USTORM_PAUSE_ENABLED_OFFSET(port), |
| 2177 | pause_enabled); |
| 2178 | } |
| 2179 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2180 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) { |
| 2181 | struct host_port_stats *pstats; |
| 2182 | |
| 2183 | pstats = bnx2x_sp(bp, port_stats); |
| 2184 | /* reset old bmac stats */ |
| 2185 | memset(&(pstats->mac_stx[0]), 0, |
| 2186 | sizeof(struct mac_stx)); |
| 2187 | } |
| 2188 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 2189 | (bp->state == BNX2X_STATE_DISABLED)) |
| 2190 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2191 | } |
| 2192 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2193 | /* indicate link status */ |
| 2194 | bnx2x_link_report(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2195 | |
| 2196 | if (IS_E1HMF(bp)) { |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2197 | int port = BP_PORT(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2198 | int func; |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2199 | int vn; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2200 | |
| 2201 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 2202 | if (vn == BP_E1HVN(bp)) |
| 2203 | continue; |
| 2204 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2205 | func = ((vn << 1) | port); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2206 | |
| 2207 | /* Set the attention towards other drivers |
| 2208 | on the same port */ |
| 2209 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 + |
| 2210 | (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1); |
| 2211 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2212 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2213 | if (bp->link_vars.link_up) { |
| 2214 | int i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2215 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2216 | /* Init rate shaping and fairness contexts */ |
| 2217 | bnx2x_init_port_minmax(bp); |
| 2218 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2219 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 2220 | bnx2x_init_vn_minmax(bp, 2*vn + port); |
| 2221 | |
| 2222 | /* Store it to internal memory */ |
| 2223 | for (i = 0; |
| 2224 | i < sizeof(struct cmng_struct_per_port) / 4; i++) |
| 2225 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 2226 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4, |
| 2227 | ((u32 *)(&bp->cmng))[i]); |
| 2228 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2229 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2230 | } |
| 2231 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2232 | static void bnx2x__link_status_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2233 | { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2234 | if (bp->state != BNX2X_STATE_OPEN) |
| 2235 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2236 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2237 | bnx2x_link_status_update(&bp->link_params, &bp->link_vars); |
| 2238 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2239 | if (bp->link_vars.link_up) |
| 2240 | bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP); |
| 2241 | else |
| 2242 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
| 2243 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2244 | /* indicate link status */ |
| 2245 | bnx2x_link_report(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2246 | } |
| 2247 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2248 | static void bnx2x_pmf_update(struct bnx2x *bp) |
| 2249 | { |
| 2250 | int port = BP_PORT(bp); |
| 2251 | u32 val; |
| 2252 | |
| 2253 | bp->port.pmf = 1; |
| 2254 | DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf); |
| 2255 | |
| 2256 | /* enable nig attention */ |
| 2257 | val = (0xff0f | (1 << (BP_E1HVN(bp) + 4))); |
| 2258 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val); |
| 2259 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2260 | |
| 2261 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2264 | /* end of Link */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2265 | |
| 2266 | /* slow path */ |
| 2267 | |
| 2268 | /* |
| 2269 | * General service functions |
| 2270 | */ |
| 2271 | |
| 2272 | /* the slow path queue is odd since completions arrive on the fastpath ring */ |
| 2273 | static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid, |
| 2274 | u32 data_hi, u32 data_lo, int common) |
| 2275 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2276 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2277 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2278 | DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/, |
| 2279 | "SPQE (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2280 | (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) + |
| 2281 | (void *)bp->spq_prod_bd - (void *)bp->spq), command, |
| 2282 | HW_CID(bp, cid), data_hi, data_lo, bp->spq_left); |
| 2283 | |
| 2284 | #ifdef BNX2X_STOP_ON_ERROR |
| 2285 | if (unlikely(bp->panic)) |
| 2286 | return -EIO; |
| 2287 | #endif |
| 2288 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2289 | spin_lock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2290 | |
| 2291 | if (!bp->spq_left) { |
| 2292 | BNX2X_ERR("BUG! SPQ ring full!\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2293 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2294 | bnx2x_panic(); |
| 2295 | return -EBUSY; |
| 2296 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 2297 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2298 | /* CID needs port number to be encoded int it */ |
| 2299 | bp->spq_prod_bd->hdr.conn_and_cmd_data = |
| 2300 | cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) | |
| 2301 | HW_CID(bp, cid))); |
| 2302 | bp->spq_prod_bd->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE); |
| 2303 | if (common) |
| 2304 | bp->spq_prod_bd->hdr.type |= |
| 2305 | cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT)); |
| 2306 | |
| 2307 | bp->spq_prod_bd->data.mac_config_addr.hi = cpu_to_le32(data_hi); |
| 2308 | bp->spq_prod_bd->data.mac_config_addr.lo = cpu_to_le32(data_lo); |
| 2309 | |
| 2310 | bp->spq_left--; |
| 2311 | |
| 2312 | if (bp->spq_prod_bd == bp->spq_last_bd) { |
| 2313 | bp->spq_prod_bd = bp->spq; |
| 2314 | bp->spq_prod_idx = 0; |
| 2315 | DP(NETIF_MSG_TIMER, "end of spq\n"); |
| 2316 | |
| 2317 | } else { |
| 2318 | bp->spq_prod_bd++; |
| 2319 | bp->spq_prod_idx++; |
| 2320 | } |
| 2321 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2322 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2323 | bp->spq_prod_idx); |
| 2324 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2325 | spin_unlock_bh(&bp->spq_lock); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2326 | return 0; |
| 2327 | } |
| 2328 | |
| 2329 | /* acquire split MCP access lock register */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2330 | static int bnx2x_acquire_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2331 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2332 | u32 i, j, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2333 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2334 | |
| 2335 | might_sleep(); |
| 2336 | i = 100; |
| 2337 | for (j = 0; j < i*10; j++) { |
| 2338 | val = (1UL << 31); |
| 2339 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 2340 | val = REG_RD(bp, GRCBASE_MCP + 0x9c); |
| 2341 | if (val & (1L << 31)) |
| 2342 | break; |
| 2343 | |
| 2344 | msleep(5); |
| 2345 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2346 | if (!(val & (1L << 31))) { |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 2347 | BNX2X_ERR("Cannot acquire MCP access lock register\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2348 | rc = -EBUSY; |
| 2349 | } |
| 2350 | |
| 2351 | return rc; |
| 2352 | } |
| 2353 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2354 | /* release split MCP access lock register */ |
| 2355 | static void bnx2x_release_alr(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2356 | { |
| 2357 | u32 val = 0; |
| 2358 | |
| 2359 | REG_WR(bp, GRCBASE_MCP + 0x9c, val); |
| 2360 | } |
| 2361 | |
| 2362 | static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp) |
| 2363 | { |
| 2364 | struct host_def_status_block *def_sb = bp->def_status_blk; |
| 2365 | u16 rc = 0; |
| 2366 | |
| 2367 | barrier(); /* status block is written to by the chip */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2368 | if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) { |
| 2369 | bp->def_att_idx = def_sb->atten_status_block.attn_bits_index; |
| 2370 | rc |= 1; |
| 2371 | } |
| 2372 | if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) { |
| 2373 | bp->def_c_idx = def_sb->c_def_status_block.status_block_index; |
| 2374 | rc |= 2; |
| 2375 | } |
| 2376 | if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) { |
| 2377 | bp->def_u_idx = def_sb->u_def_status_block.status_block_index; |
| 2378 | rc |= 4; |
| 2379 | } |
| 2380 | if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) { |
| 2381 | bp->def_x_idx = def_sb->x_def_status_block.status_block_index; |
| 2382 | rc |= 8; |
| 2383 | } |
| 2384 | if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) { |
| 2385 | bp->def_t_idx = def_sb->t_def_status_block.status_block_index; |
| 2386 | rc |= 16; |
| 2387 | } |
| 2388 | return rc; |
| 2389 | } |
| 2390 | |
| 2391 | /* |
| 2392 | * slow path service functions |
| 2393 | */ |
| 2394 | |
| 2395 | static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted) |
| 2396 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2397 | int port = BP_PORT(bp); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2398 | u32 hc_addr = (HC_REG_COMMAND_REG + port*32 + |
| 2399 | COMMAND_REG_ATTN_BITS_SET); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2400 | u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 2401 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2402 | u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 : |
| 2403 | NIG_REG_MASK_INTERRUPT_PORT0; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2404 | u32 aeu_mask; |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 2405 | u32 nig_mask = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2406 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2407 | if (bp->attn_state & asserted) |
| 2408 | BNX2X_ERR("IGU ERROR\n"); |
| 2409 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2410 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 2411 | aeu_mask = REG_RD(bp, aeu_addr); |
| 2412 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2413 | DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n", |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2414 | aeu_mask, asserted); |
| 2415 | aeu_mask &= ~(asserted & 0xff); |
| 2416 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2417 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2418 | REG_WR(bp, aeu_addr, aeu_mask); |
| 2419 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2420 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2421 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2422 | bp->attn_state |= asserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2423 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2424 | |
| 2425 | if (asserted & ATTN_HARD_WIRED_MASK) { |
| 2426 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2427 | |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2428 | bnx2x_acquire_phy_lock(bp); |
| 2429 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2430 | /* save nig interrupt mask */ |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 2431 | nig_mask = REG_RD(bp, nig_int_mask_addr); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2432 | REG_WR(bp, nig_int_mask_addr, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2433 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2434 | bnx2x_link_attn(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2435 | |
| 2436 | /* handle unicore attn? */ |
| 2437 | } |
| 2438 | if (asserted & ATTN_SW_TIMER_4_FUNC) |
| 2439 | DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n"); |
| 2440 | |
| 2441 | if (asserted & GPIO_2_FUNC) |
| 2442 | DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n"); |
| 2443 | |
| 2444 | if (asserted & GPIO_3_FUNC) |
| 2445 | DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n"); |
| 2446 | |
| 2447 | if (asserted & GPIO_4_FUNC) |
| 2448 | DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n"); |
| 2449 | |
| 2450 | if (port == 0) { |
| 2451 | if (asserted & ATTN_GENERAL_ATTN_1) { |
| 2452 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n"); |
| 2453 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0); |
| 2454 | } |
| 2455 | if (asserted & ATTN_GENERAL_ATTN_2) { |
| 2456 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n"); |
| 2457 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0); |
| 2458 | } |
| 2459 | if (asserted & ATTN_GENERAL_ATTN_3) { |
| 2460 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n"); |
| 2461 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0); |
| 2462 | } |
| 2463 | } else { |
| 2464 | if (asserted & ATTN_GENERAL_ATTN_4) { |
| 2465 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n"); |
| 2466 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0); |
| 2467 | } |
| 2468 | if (asserted & ATTN_GENERAL_ATTN_5) { |
| 2469 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n"); |
| 2470 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0); |
| 2471 | } |
| 2472 | if (asserted & ATTN_GENERAL_ATTN_6) { |
| 2473 | DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n"); |
| 2474 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0); |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | } /* if hardwired */ |
| 2479 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2480 | DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n", |
| 2481 | asserted, hc_addr); |
| 2482 | REG_WR(bp, hc_addr, asserted); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2483 | |
| 2484 | /* now set back the mask */ |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2485 | if (asserted & ATTN_NIG_FOR_FUNC) { |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 2486 | REG_WR(bp, nig_int_mask_addr, nig_mask); |
Eilon Greenstein | a5e9a7c | 2009-01-14 21:26:01 -0800 | [diff] [blame] | 2487 | bnx2x_release_phy_lock(bp); |
| 2488 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn) |
| 2492 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2493 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2494 | int reg_offset; |
| 2495 | u32 val; |
| 2496 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2497 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 2498 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2499 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2500 | if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2501 | |
| 2502 | val = REG_RD(bp, reg_offset); |
| 2503 | val &= ~AEU_INPUTS_ATTN_BITS_SPIO5; |
| 2504 | REG_WR(bp, reg_offset, val); |
| 2505 | |
| 2506 | BNX2X_ERR("SPIO5 hw attention\n"); |
| 2507 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 2508 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
| 2509 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2510 | /* Fan failure attention */ |
| 2511 | |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2512 | /* The PHY reset is controlled by GPIO 1 */ |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2513 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1, |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2514 | MISC_REGISTERS_GPIO_OUTPUT_LOW, port); |
| 2515 | /* Low power mode is controlled by GPIO 2 */ |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2516 | bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2, |
Eilon Greenstein | 17de50b | 2008-08-13 15:56:59 -0700 | [diff] [blame] | 2517 | MISC_REGISTERS_GPIO_OUTPUT_LOW, port); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2518 | /* mark the failure */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2519 | bp->link_params.ext_phy_config &= |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2520 | ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2521 | bp->link_params.ext_phy_config |= |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2522 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE; |
| 2523 | SHMEM_WR(bp, |
| 2524 | dev_info.port_hw_config[port]. |
| 2525 | external_phy_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 2526 | bp->link_params.ext_phy_config); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2527 | /* log the failure */ |
| 2528 | printk(KERN_ERR PFX "Fan Failure on Network" |
| 2529 | " Controller %s has caused the driver to" |
| 2530 | " shutdown the card to prevent permanent" |
| 2531 | " damage. Please contact Dell Support for" |
| 2532 | " assistance\n", bp->dev->name); |
| 2533 | break; |
| 2534 | |
| 2535 | default: |
| 2536 | break; |
| 2537 | } |
| 2538 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2539 | |
| 2540 | if (attn & HW_INTERRUT_ASSERT_SET_0) { |
| 2541 | |
| 2542 | val = REG_RD(bp, reg_offset); |
| 2543 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_0); |
| 2544 | REG_WR(bp, reg_offset, val); |
| 2545 | |
| 2546 | BNX2X_ERR("FATAL HW block attention set0 0x%x\n", |
| 2547 | (attn & HW_INTERRUT_ASSERT_SET_0)); |
| 2548 | bnx2x_panic(); |
| 2549 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn) |
| 2553 | { |
| 2554 | u32 val; |
| 2555 | |
| 2556 | if (attn & BNX2X_DOORQ_ASSERT) { |
| 2557 | |
| 2558 | val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR); |
| 2559 | BNX2X_ERR("DB hw attention 0x%x\n", val); |
| 2560 | /* DORQ discard attention */ |
| 2561 | if (val & 0x2) |
| 2562 | BNX2X_ERR("FATAL error from DORQ\n"); |
| 2563 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2564 | |
| 2565 | if (attn & HW_INTERRUT_ASSERT_SET_1) { |
| 2566 | |
| 2567 | int port = BP_PORT(bp); |
| 2568 | int reg_offset; |
| 2569 | |
| 2570 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 : |
| 2571 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1); |
| 2572 | |
| 2573 | val = REG_RD(bp, reg_offset); |
| 2574 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_1); |
| 2575 | REG_WR(bp, reg_offset, val); |
| 2576 | |
| 2577 | BNX2X_ERR("FATAL HW block attention set1 0x%x\n", |
| 2578 | (attn & HW_INTERRUT_ASSERT_SET_1)); |
| 2579 | bnx2x_panic(); |
| 2580 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn) |
| 2584 | { |
| 2585 | u32 val; |
| 2586 | |
| 2587 | if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) { |
| 2588 | |
| 2589 | val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR); |
| 2590 | BNX2X_ERR("CFC hw attention 0x%x\n", val); |
| 2591 | /* CFC error attention */ |
| 2592 | if (val & 0x2) |
| 2593 | BNX2X_ERR("FATAL error from CFC\n"); |
| 2594 | } |
| 2595 | |
| 2596 | if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) { |
| 2597 | |
| 2598 | val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0); |
| 2599 | BNX2X_ERR("PXP hw attention 0x%x\n", val); |
| 2600 | /* RQ_USDMDP_FIFO_OVERFLOW */ |
| 2601 | if (val & 0x18000) |
| 2602 | BNX2X_ERR("FATAL error from PXP\n"); |
| 2603 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2604 | |
| 2605 | if (attn & HW_INTERRUT_ASSERT_SET_2) { |
| 2606 | |
| 2607 | int port = BP_PORT(bp); |
| 2608 | int reg_offset; |
| 2609 | |
| 2610 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 : |
| 2611 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2); |
| 2612 | |
| 2613 | val = REG_RD(bp, reg_offset); |
| 2614 | val &= ~(attn & HW_INTERRUT_ASSERT_SET_2); |
| 2615 | REG_WR(bp, reg_offset, val); |
| 2616 | |
| 2617 | BNX2X_ERR("FATAL HW block attention set2 0x%x\n", |
| 2618 | (attn & HW_INTERRUT_ASSERT_SET_2)); |
| 2619 | bnx2x_panic(); |
| 2620 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn) |
| 2624 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2625 | u32 val; |
| 2626 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2627 | if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) { |
| 2628 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2629 | if (attn & BNX2X_PMF_LINK_ASSERT) { |
| 2630 | int func = BP_FUNC(bp); |
| 2631 | |
| 2632 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 2633 | bnx2x__link_status_update(bp); |
| 2634 | if (SHMEM_RD(bp, func_mb[func].drv_status) & |
| 2635 | DRV_STATUS_PMF) |
| 2636 | bnx2x_pmf_update(bp); |
| 2637 | |
| 2638 | } else if (attn & BNX2X_MC_ASSERT_BITS) { |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2639 | |
| 2640 | BNX2X_ERR("MC assert!\n"); |
| 2641 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0); |
| 2642 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0); |
| 2643 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0); |
| 2644 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0); |
| 2645 | bnx2x_panic(); |
| 2646 | |
| 2647 | } else if (attn & BNX2X_MCP_ASSERT) { |
| 2648 | |
| 2649 | BNX2X_ERR("MCP assert!\n"); |
| 2650 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2651 | bnx2x_fw_dump(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2652 | |
| 2653 | } else |
| 2654 | BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn); |
| 2655 | } |
| 2656 | |
| 2657 | if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2658 | BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn); |
| 2659 | if (attn & BNX2X_GRC_TIMEOUT) { |
| 2660 | val = CHIP_IS_E1H(bp) ? |
| 2661 | REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0; |
| 2662 | BNX2X_ERR("GRC time-out 0x%08x\n", val); |
| 2663 | } |
| 2664 | if (attn & BNX2X_GRC_RSV) { |
| 2665 | val = CHIP_IS_E1H(bp) ? |
| 2666 | REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0; |
| 2667 | BNX2X_ERR("GRC reserved 0x%08x\n", val); |
| 2668 | } |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2669 | REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2670 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted) |
| 2674 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2675 | struct attn_route attn; |
| 2676 | struct attn_route group_mask; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2677 | int port = BP_PORT(bp); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2678 | int index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2679 | u32 reg_addr; |
| 2680 | u32 val; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2681 | u32 aeu_mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2682 | |
| 2683 | /* need to take HW lock because MCP or other port might also |
| 2684 | try to handle this event */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2685 | bnx2x_acquire_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2686 | |
| 2687 | attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4); |
| 2688 | attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4); |
| 2689 | attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4); |
| 2690 | attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2691 | DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n", |
| 2692 | attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2693 | |
| 2694 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
| 2695 | if (deasserted & (1 << index)) { |
| 2696 | group_mask = bp->attn_group[index]; |
| 2697 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2698 | DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n", |
| 2699 | index, group_mask.sig[0], group_mask.sig[1], |
| 2700 | group_mask.sig[2], group_mask.sig[3]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2701 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2702 | bnx2x_attn_int_deasserted3(bp, |
| 2703 | attn.sig[3] & group_mask.sig[3]); |
| 2704 | bnx2x_attn_int_deasserted1(bp, |
| 2705 | attn.sig[1] & group_mask.sig[1]); |
| 2706 | bnx2x_attn_int_deasserted2(bp, |
| 2707 | attn.sig[2] & group_mask.sig[2]); |
| 2708 | bnx2x_attn_int_deasserted0(bp, |
| 2709 | attn.sig[0] & group_mask.sig[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2710 | |
| 2711 | if ((attn.sig[0] & group_mask.sig[0] & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2712 | HW_PRTY_ASSERT_SET_0) || |
| 2713 | (attn.sig[1] & group_mask.sig[1] & |
| 2714 | HW_PRTY_ASSERT_SET_1) || |
| 2715 | (attn.sig[2] & group_mask.sig[2] & |
| 2716 | HW_PRTY_ASSERT_SET_2)) |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2717 | BNX2X_ERR("FATAL HW block parity attention\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2718 | } |
| 2719 | } |
| 2720 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 2721 | bnx2x_release_alr(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2722 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2723 | reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2724 | |
| 2725 | val = ~deasserted; |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2726 | DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n", |
| 2727 | val, reg_addr); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 2728 | REG_WR(bp, reg_addr, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2729 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2730 | if (~bp->attn_state & deasserted) |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2731 | BNX2X_ERR("IGU ERROR\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2732 | |
| 2733 | reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 2734 | MISC_REG_AEU_MASK_ATTN_FUNC_0; |
| 2735 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2736 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
| 2737 | aeu_mask = REG_RD(bp, reg_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2738 | |
Eilon Greenstein | 3fcaf2e | 2008-08-13 15:50:45 -0700 | [diff] [blame] | 2739 | DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n", |
| 2740 | aeu_mask, deasserted); |
| 2741 | aeu_mask |= (deasserted & 0xff); |
| 2742 | DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask); |
| 2743 | |
| 2744 | REG_WR(bp, reg_addr, aeu_mask); |
| 2745 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2746 | |
| 2747 | DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state); |
| 2748 | bp->attn_state &= ~deasserted; |
| 2749 | DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state); |
| 2750 | } |
| 2751 | |
| 2752 | static void bnx2x_attn_int(struct bnx2x *bp) |
| 2753 | { |
| 2754 | /* read local copy of bits */ |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 2755 | u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 2756 | attn_bits); |
| 2757 | u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block. |
| 2758 | attn_bits_ack); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2759 | u32 attn_state = bp->attn_state; |
| 2760 | |
| 2761 | /* look for changed bits */ |
| 2762 | u32 asserted = attn_bits & ~attn_ack & ~attn_state; |
| 2763 | u32 deasserted = ~attn_bits & attn_ack & attn_state; |
| 2764 | |
| 2765 | DP(NETIF_MSG_HW, |
| 2766 | "attn_bits %x attn_ack %x asserted %x deasserted %x\n", |
| 2767 | attn_bits, attn_ack, asserted, deasserted); |
| 2768 | |
| 2769 | if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2770 | BNX2X_ERR("BAD attention state\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2771 | |
| 2772 | /* handle bits that were raised */ |
| 2773 | if (asserted) |
| 2774 | bnx2x_attn_int_asserted(bp, asserted); |
| 2775 | |
| 2776 | if (deasserted) |
| 2777 | bnx2x_attn_int_deasserted(bp, deasserted); |
| 2778 | } |
| 2779 | |
| 2780 | static void bnx2x_sp_task(struct work_struct *work) |
| 2781 | { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 2782 | struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2783 | u16 status; |
| 2784 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2785 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2786 | /* Return here if interrupt is disabled */ |
| 2787 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 2788 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2789 | return; |
| 2790 | } |
| 2791 | |
| 2792 | status = bnx2x_update_dsb_idx(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 2793 | /* if (status == 0) */ |
| 2794 | /* BNX2X_ERR("spurious slowpath interrupt!\n"); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2795 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 2796 | DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2797 | |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2798 | /* HW attentions */ |
| 2799 | if (status & 0x1) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2800 | bnx2x_attn_int(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2801 | |
Eilon Greenstein | 68d5948 | 2009-01-14 21:27:36 -0800 | [diff] [blame] | 2802 | bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2803 | IGU_INT_NOP, 1); |
| 2804 | bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx), |
| 2805 | IGU_INT_NOP, 1); |
| 2806 | bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx), |
| 2807 | IGU_INT_NOP, 1); |
| 2808 | bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx), |
| 2809 | IGU_INT_NOP, 1); |
| 2810 | bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx), |
| 2811 | IGU_INT_ENABLE, 1); |
Eliezer Tamir | 877e9aa | 2008-02-28 11:55:53 -0800 | [diff] [blame] | 2812 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance) |
| 2816 | { |
| 2817 | struct net_device *dev = dev_instance; |
| 2818 | struct bnx2x *bp = netdev_priv(dev); |
| 2819 | |
| 2820 | /* Return here if interrupt is disabled */ |
| 2821 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 2822 | DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2823 | return IRQ_HANDLED; |
| 2824 | } |
| 2825 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 2826 | bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2827 | |
| 2828 | #ifdef BNX2X_STOP_ON_ERROR |
| 2829 | if (unlikely(bp->panic)) |
| 2830 | return IRQ_HANDLED; |
| 2831 | #endif |
| 2832 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 2833 | queue_delayed_work(bnx2x_wq, &bp->sp_task, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2834 | |
| 2835 | return IRQ_HANDLED; |
| 2836 | } |
| 2837 | |
| 2838 | /* end of slow path */ |
| 2839 | |
| 2840 | /* Statistics */ |
| 2841 | |
| 2842 | /**************************************************************************** |
| 2843 | * Macros |
| 2844 | ****************************************************************************/ |
| 2845 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2846 | /* sum[hi:lo] += add[hi:lo] */ |
| 2847 | #define ADD_64(s_hi, a_hi, s_lo, a_lo) \ |
| 2848 | do { \ |
| 2849 | s_lo += a_lo; \ |
Eilon Greenstein | f5ba677 | 2009-01-14 21:29:18 -0800 | [diff] [blame] | 2850 | s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2851 | } while (0) |
| 2852 | |
| 2853 | /* difference = minuend - subtrahend */ |
| 2854 | #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \ |
| 2855 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2856 | if (m_lo < s_lo) { \ |
| 2857 | /* underflow */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2858 | d_hi = m_hi - s_hi; \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2859 | if (d_hi > 0) { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2860 | /* we can 'loan' 1 */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2861 | d_hi--; \ |
| 2862 | d_lo = m_lo + (UINT_MAX - s_lo) + 1; \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2863 | } else { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2864 | /* m_hi <= s_hi */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2865 | d_hi = 0; \ |
| 2866 | d_lo = 0; \ |
| 2867 | } \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2868 | } else { \ |
| 2869 | /* m_lo >= s_lo */ \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2870 | if (m_hi < s_hi) { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2871 | d_hi = 0; \ |
| 2872 | d_lo = 0; \ |
| 2873 | } else { \ |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 2874 | /* m_hi >= s_hi */ \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2875 | d_hi = m_hi - s_hi; \ |
| 2876 | d_lo = m_lo - s_lo; \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2877 | } \ |
| 2878 | } \ |
| 2879 | } while (0) |
| 2880 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2881 | #define UPDATE_STAT64(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2882 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2883 | DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \ |
| 2884 | diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \ |
| 2885 | pstats->mac_stx[0].t##_hi = new->s##_hi; \ |
| 2886 | pstats->mac_stx[0].t##_lo = new->s##_lo; \ |
| 2887 | ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \ |
| 2888 | pstats->mac_stx[1].t##_lo, diff.lo); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2889 | } while (0) |
| 2890 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2891 | #define UPDATE_STAT64_NIG(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2892 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2893 | DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \ |
| 2894 | diff.lo, new->s##_lo, old->s##_lo); \ |
| 2895 | ADD_64(estats->t##_hi, diff.hi, \ |
| 2896 | estats->t##_lo, diff.lo); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2897 | } while (0) |
| 2898 | |
| 2899 | /* sum[hi:lo] += add */ |
| 2900 | #define ADD_EXTEND_64(s_hi, s_lo, a) \ |
| 2901 | do { \ |
| 2902 | s_lo += a; \ |
| 2903 | s_hi += (s_lo < a) ? 1 : 0; \ |
| 2904 | } while (0) |
| 2905 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2906 | #define UPDATE_EXTEND_STAT(s) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2907 | do { \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2908 | ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \ |
| 2909 | pstats->mac_stx[1].s##_lo, \ |
| 2910 | new->s); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2911 | } while (0) |
| 2912 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2913 | #define UPDATE_EXTEND_TSTAT(s, t) \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2914 | do { \ |
| 2915 | diff = le32_to_cpu(tclient->s) - old_tclient->s; \ |
| 2916 | old_tclient->s = le32_to_cpu(tclient->s); \ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 2917 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
| 2918 | } while (0) |
| 2919 | |
| 2920 | #define UPDATE_EXTEND_USTAT(s, t) \ |
| 2921 | do { \ |
| 2922 | diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \ |
| 2923 | old_uclient->s = uclient->s; \ |
| 2924 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2925 | } while (0) |
| 2926 | |
| 2927 | #define UPDATE_EXTEND_XSTAT(s, t) \ |
| 2928 | do { \ |
| 2929 | diff = le32_to_cpu(xclient->s) - old_xclient->s; \ |
| 2930 | old_xclient->s = le32_to_cpu(xclient->s); \ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 2931 | ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
| 2932 | } while (0) |
| 2933 | |
| 2934 | /* minuend -= subtrahend */ |
| 2935 | #define SUB_64(m_hi, s_hi, m_lo, s_lo) \ |
| 2936 | do { \ |
| 2937 | DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \ |
| 2938 | } while (0) |
| 2939 | |
| 2940 | /* minuend[hi:lo] -= subtrahend */ |
| 2941 | #define SUB_EXTEND_64(m_hi, m_lo, s) \ |
| 2942 | do { \ |
| 2943 | SUB_64(m_hi, 0, m_lo, s); \ |
| 2944 | } while (0) |
| 2945 | |
| 2946 | #define SUB_EXTEND_USTAT(s, t) \ |
| 2947 | do { \ |
| 2948 | diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \ |
| 2949 | SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2950 | } while (0) |
| 2951 | |
| 2952 | /* |
| 2953 | * General service functions |
| 2954 | */ |
| 2955 | |
| 2956 | static inline long bnx2x_hilo(u32 *hiref) |
| 2957 | { |
| 2958 | u32 lo = *(hiref + 1); |
| 2959 | #if (BITS_PER_LONG == 64) |
| 2960 | u32 hi = *hiref; |
| 2961 | |
| 2962 | return HILO_U64(hi, lo); |
| 2963 | #else |
| 2964 | return lo; |
| 2965 | #endif |
| 2966 | } |
| 2967 | |
| 2968 | /* |
| 2969 | * Init service functions |
| 2970 | */ |
| 2971 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2972 | static void bnx2x_storm_stats_post(struct bnx2x *bp) |
| 2973 | { |
| 2974 | if (!bp->stats_pending) { |
| 2975 | struct eth_query_ramrod_data ramrod_data = {0}; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 2976 | int i, rc; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2977 | |
| 2978 | ramrod_data.drv_counter = bp->stats_counter++; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 2979 | ramrod_data.collect_port = bp->port.pmf ? 1 : 0; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 2980 | for_each_queue(bp, i) |
| 2981 | ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2982 | |
| 2983 | rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0, |
| 2984 | ((u32 *)&ramrod_data)[1], |
| 2985 | ((u32 *)&ramrod_data)[0], 0); |
| 2986 | if (rc == 0) { |
| 2987 | /* stats ramrod has it's own slot on the spq */ |
| 2988 | bp->spq_left++; |
| 2989 | bp->stats_pending = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2990 | } |
| 2991 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2992 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 2993 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2994 | static void bnx2x_stats_init(struct bnx2x *bp) |
| 2995 | { |
| 2996 | int port = BP_PORT(bp); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 2997 | int i; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 2998 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 2999 | bp->stats_pending = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3000 | bp->executer_idx = 0; |
| 3001 | bp->stats_counter = 0; |
| 3002 | |
| 3003 | /* port stats */ |
| 3004 | if (!BP_NOMCP(bp)) |
| 3005 | bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx); |
| 3006 | else |
| 3007 | bp->port.port_stx = 0; |
| 3008 | DP(BNX2X_MSG_STATS, "port_stx 0x%x\n", bp->port.port_stx); |
| 3009 | |
| 3010 | memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats)); |
| 3011 | bp->port.old_nig_stats.brb_discard = |
| 3012 | REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3013 | bp->port.old_nig_stats.brb_truncate = |
| 3014 | REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3015 | REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50, |
| 3016 | &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2); |
| 3017 | REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50, |
| 3018 | &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2); |
| 3019 | |
| 3020 | /* function stats */ |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3021 | for_each_queue(bp, i) { |
| 3022 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 3023 | |
| 3024 | memset(&fp->old_tclient, 0, |
| 3025 | sizeof(struct tstorm_per_client_stats)); |
| 3026 | memset(&fp->old_uclient, 0, |
| 3027 | sizeof(struct ustorm_per_client_stats)); |
| 3028 | memset(&fp->old_xclient, 0, |
| 3029 | sizeof(struct xstorm_per_client_stats)); |
| 3030 | memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats)); |
| 3031 | } |
| 3032 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3033 | memset(&bp->dev->stats, 0, sizeof(struct net_device_stats)); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3034 | memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats)); |
| 3035 | |
| 3036 | bp->stats_state = STATS_STATE_DISABLED; |
| 3037 | if (IS_E1HMF(bp) && bp->port.pmf && bp->port.port_stx) |
| 3038 | bnx2x_stats_handle(bp, STATS_EVENT_PMF); |
| 3039 | } |
| 3040 | |
| 3041 | static void bnx2x_hw_stats_post(struct bnx2x *bp) |
| 3042 | { |
| 3043 | struct dmae_command *dmae = &bp->stats_dmae; |
| 3044 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3045 | |
| 3046 | *stats_comp = DMAE_COMP_VAL; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3047 | if (CHIP_REV_IS_SLOW(bp)) |
| 3048 | return; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3049 | |
| 3050 | /* loader */ |
| 3051 | if (bp->executer_idx) { |
| 3052 | int loader_idx = PMF_DMAE_C(bp); |
| 3053 | |
| 3054 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 3055 | |
| 3056 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3057 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3058 | DMAE_CMD_DST_RESET | |
| 3059 | #ifdef __BIG_ENDIAN |
| 3060 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3061 | #else |
| 3062 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3063 | #endif |
| 3064 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : |
| 3065 | DMAE_CMD_PORT_0) | |
| 3066 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3067 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0])); |
| 3068 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0])); |
| 3069 | dmae->dst_addr_lo = (DMAE_REG_CMD_MEM + |
| 3070 | sizeof(struct dmae_command) * |
| 3071 | (loader_idx + 1)) >> 2; |
| 3072 | dmae->dst_addr_hi = 0; |
| 3073 | dmae->len = sizeof(struct dmae_command) >> 2; |
| 3074 | if (CHIP_IS_E1(bp)) |
| 3075 | dmae->len--; |
| 3076 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2; |
| 3077 | dmae->comp_addr_hi = 0; |
| 3078 | dmae->comp_val = 1; |
| 3079 | |
| 3080 | *stats_comp = 0; |
| 3081 | bnx2x_post_dmae(bp, dmae, loader_idx); |
| 3082 | |
| 3083 | } else if (bp->func_stx) { |
| 3084 | *stats_comp = 0; |
| 3085 | bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp)); |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | static int bnx2x_stats_comp(struct bnx2x *bp) |
| 3090 | { |
| 3091 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3092 | int cnt = 10; |
| 3093 | |
| 3094 | might_sleep(); |
| 3095 | while (*stats_comp != DMAE_COMP_VAL) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3096 | if (!cnt) { |
| 3097 | BNX2X_ERR("timeout waiting for stats finished\n"); |
| 3098 | break; |
| 3099 | } |
| 3100 | cnt--; |
Yitchak Gertner | 1246940 | 2008-08-13 15:52:08 -0700 | [diff] [blame] | 3101 | msleep(1); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3102 | } |
| 3103 | return 1; |
| 3104 | } |
| 3105 | |
| 3106 | /* |
| 3107 | * Statistics service functions |
| 3108 | */ |
| 3109 | |
| 3110 | static void bnx2x_stats_pmf_update(struct bnx2x *bp) |
| 3111 | { |
| 3112 | struct dmae_command *dmae; |
| 3113 | u32 opcode; |
| 3114 | int loader_idx = PMF_DMAE_C(bp); |
| 3115 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3116 | |
| 3117 | /* sanity */ |
| 3118 | if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) { |
| 3119 | BNX2X_ERR("BUG!\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3120 | return; |
| 3121 | } |
| 3122 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3123 | bp->executer_idx = 0; |
| 3124 | |
| 3125 | opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3126 | DMAE_CMD_C_ENABLE | |
| 3127 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3128 | #ifdef __BIG_ENDIAN |
| 3129 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3130 | #else |
| 3131 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3132 | #endif |
| 3133 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3134 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3135 | |
| 3136 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3137 | dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC); |
| 3138 | dmae->src_addr_lo = bp->port.port_stx >> 2; |
| 3139 | dmae->src_addr_hi = 0; |
| 3140 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 3141 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 3142 | dmae->len = DMAE_LEN32_RD_MAX; |
| 3143 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3144 | dmae->comp_addr_hi = 0; |
| 3145 | dmae->comp_val = 1; |
| 3146 | |
| 3147 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3148 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 3149 | dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX; |
| 3150 | dmae->src_addr_hi = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 3151 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) + |
| 3152 | DMAE_LEN32_RD_MAX * 4); |
| 3153 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) + |
| 3154 | DMAE_LEN32_RD_MAX * 4); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3155 | dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX; |
| 3156 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3157 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3158 | dmae->comp_val = DMAE_COMP_VAL; |
| 3159 | |
| 3160 | *stats_comp = 0; |
| 3161 | bnx2x_hw_stats_post(bp); |
| 3162 | bnx2x_stats_comp(bp); |
| 3163 | } |
| 3164 | |
| 3165 | static void bnx2x_port_stats_init(struct bnx2x *bp) |
| 3166 | { |
| 3167 | struct dmae_command *dmae; |
| 3168 | int port = BP_PORT(bp); |
| 3169 | int vn = BP_E1HVN(bp); |
| 3170 | u32 opcode; |
| 3171 | int loader_idx = PMF_DMAE_C(bp); |
| 3172 | u32 mac_addr; |
| 3173 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
| 3174 | |
| 3175 | /* sanity */ |
| 3176 | if (!bp->link_vars.link_up || !bp->port.pmf) { |
| 3177 | BNX2X_ERR("BUG!\n"); |
| 3178 | return; |
| 3179 | } |
| 3180 | |
| 3181 | bp->executer_idx = 0; |
| 3182 | |
| 3183 | /* MCP */ |
| 3184 | opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3185 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3186 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3187 | #ifdef __BIG_ENDIAN |
| 3188 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3189 | #else |
| 3190 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3191 | #endif |
| 3192 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3193 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
| 3194 | |
| 3195 | if (bp->port.port_stx) { |
| 3196 | |
| 3197 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3198 | dmae->opcode = opcode; |
| 3199 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 3200 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 3201 | dmae->dst_addr_lo = bp->port.port_stx >> 2; |
| 3202 | dmae->dst_addr_hi = 0; |
| 3203 | dmae->len = sizeof(struct host_port_stats) >> 2; |
| 3204 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3205 | dmae->comp_addr_hi = 0; |
| 3206 | dmae->comp_val = 1; |
| 3207 | } |
| 3208 | |
| 3209 | if (bp->func_stx) { |
| 3210 | |
| 3211 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3212 | dmae->opcode = opcode; |
| 3213 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 3214 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 3215 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 3216 | dmae->dst_addr_hi = 0; |
| 3217 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 3218 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3219 | dmae->comp_addr_hi = 0; |
| 3220 | dmae->comp_val = 1; |
| 3221 | } |
| 3222 | |
| 3223 | /* MAC */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3224 | opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3225 | DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE | |
| 3226 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3227 | #ifdef __BIG_ENDIAN |
| 3228 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3229 | #else |
| 3230 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3231 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3232 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3233 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3234 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 3235 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3236 | |
| 3237 | mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM : |
| 3238 | NIG_REG_INGRESS_BMAC0_MEM); |
| 3239 | |
| 3240 | /* BIGMAC_REGISTER_TX_STAT_GTPKT .. |
| 3241 | BIGMAC_REGISTER_TX_STAT_GTBYT */ |
| 3242 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3243 | dmae->opcode = opcode; |
| 3244 | dmae->src_addr_lo = (mac_addr + |
| 3245 | BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2; |
| 3246 | dmae->src_addr_hi = 0; |
| 3247 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats)); |
| 3248 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats)); |
| 3249 | dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT - |
| 3250 | BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2; |
| 3251 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3252 | dmae->comp_addr_hi = 0; |
| 3253 | dmae->comp_val = 1; |
| 3254 | |
| 3255 | /* BIGMAC_REGISTER_RX_STAT_GR64 .. |
| 3256 | BIGMAC_REGISTER_RX_STAT_GRIPJ */ |
| 3257 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3258 | dmae->opcode = opcode; |
| 3259 | dmae->src_addr_lo = (mac_addr + |
| 3260 | BIGMAC_REGISTER_RX_STAT_GR64) >> 2; |
| 3261 | dmae->src_addr_hi = 0; |
| 3262 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3263 | offsetof(struct bmac_stats, rx_stat_gr64_lo)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3264 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3265 | offsetof(struct bmac_stats, rx_stat_gr64_lo)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3266 | dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ - |
| 3267 | BIGMAC_REGISTER_RX_STAT_GR64) >> 2; |
| 3268 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3269 | dmae->comp_addr_hi = 0; |
| 3270 | dmae->comp_val = 1; |
| 3271 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 3272 | } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3273 | |
| 3274 | mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0); |
| 3275 | |
| 3276 | /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/ |
| 3277 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3278 | dmae->opcode = opcode; |
| 3279 | dmae->src_addr_lo = (mac_addr + |
| 3280 | EMAC_REG_EMAC_RX_STAT_AC) >> 2; |
| 3281 | dmae->src_addr_hi = 0; |
| 3282 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats)); |
| 3283 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats)); |
| 3284 | dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT; |
| 3285 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3286 | dmae->comp_addr_hi = 0; |
| 3287 | dmae->comp_val = 1; |
| 3288 | |
| 3289 | /* EMAC_REG_EMAC_RX_STAT_AC_28 */ |
| 3290 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3291 | dmae->opcode = opcode; |
| 3292 | dmae->src_addr_lo = (mac_addr + |
| 3293 | EMAC_REG_EMAC_RX_STAT_AC_28) >> 2; |
| 3294 | dmae->src_addr_hi = 0; |
| 3295 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3296 | offsetof(struct emac_stats, rx_stat_falsecarriererrors)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3297 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3298 | offsetof(struct emac_stats, rx_stat_falsecarriererrors)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3299 | dmae->len = 1; |
| 3300 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3301 | dmae->comp_addr_hi = 0; |
| 3302 | dmae->comp_val = 1; |
| 3303 | |
| 3304 | /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/ |
| 3305 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3306 | dmae->opcode = opcode; |
| 3307 | dmae->src_addr_lo = (mac_addr + |
| 3308 | EMAC_REG_EMAC_TX_STAT_AC) >> 2; |
| 3309 | dmae->src_addr_hi = 0; |
| 3310 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3311 | offsetof(struct emac_stats, tx_stat_ifhcoutoctets)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3312 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) + |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3313 | offsetof(struct emac_stats, tx_stat_ifhcoutoctets)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3314 | dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT; |
| 3315 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3316 | dmae->comp_addr_hi = 0; |
| 3317 | dmae->comp_val = 1; |
| 3318 | } |
| 3319 | |
| 3320 | /* NIG */ |
| 3321 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3322 | dmae->opcode = opcode; |
| 3323 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD : |
| 3324 | NIG_REG_STAT0_BRB_DISCARD) >> 2; |
| 3325 | dmae->src_addr_hi = 0; |
| 3326 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats)); |
| 3327 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats)); |
| 3328 | dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2; |
| 3329 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3330 | dmae->comp_addr_hi = 0; |
| 3331 | dmae->comp_val = 1; |
| 3332 | |
| 3333 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3334 | dmae->opcode = opcode; |
| 3335 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 : |
| 3336 | NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2; |
| 3337 | dmae->src_addr_hi = 0; |
| 3338 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) + |
| 3339 | offsetof(struct nig_stats, egress_mac_pkt0_lo)); |
| 3340 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) + |
| 3341 | offsetof(struct nig_stats, egress_mac_pkt0_lo)); |
| 3342 | dmae->len = (2*sizeof(u32)) >> 2; |
| 3343 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3344 | dmae->comp_addr_hi = 0; |
| 3345 | dmae->comp_val = 1; |
| 3346 | |
| 3347 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3348 | dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI | |
| 3349 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 3350 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3351 | #ifdef __BIG_ENDIAN |
| 3352 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3353 | #else |
| 3354 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3355 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3356 | (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3357 | (vn << DMAE_CMD_E1HVN_SHIFT)); |
| 3358 | dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 : |
| 3359 | NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3360 | dmae->src_addr_hi = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3361 | dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) + |
| 3362 | offsetof(struct nig_stats, egress_mac_pkt1_lo)); |
| 3363 | dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) + |
| 3364 | offsetof(struct nig_stats, egress_mac_pkt1_lo)); |
| 3365 | dmae->len = (2*sizeof(u32)) >> 2; |
| 3366 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3367 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3368 | dmae->comp_val = DMAE_COMP_VAL; |
| 3369 | |
| 3370 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3371 | } |
| 3372 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3373 | static void bnx2x_func_stats_init(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3374 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3375 | struct dmae_command *dmae = &bp->stats_dmae; |
| 3376 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3377 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3378 | /* sanity */ |
| 3379 | if (!bp->func_stx) { |
| 3380 | BNX2X_ERR("BUG!\n"); |
| 3381 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3382 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3383 | |
| 3384 | bp->executer_idx = 0; |
| 3385 | memset(dmae, 0, sizeof(struct dmae_command)); |
| 3386 | |
| 3387 | dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3388 | DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE | |
| 3389 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
| 3390 | #ifdef __BIG_ENDIAN |
| 3391 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
| 3392 | #else |
| 3393 | DMAE_CMD_ENDIANITY_DW_SWAP | |
| 3394 | #endif |
| 3395 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3396 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3397 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 3398 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 3399 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 3400 | dmae->dst_addr_hi = 0; |
| 3401 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 3402 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3403 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3404 | dmae->comp_val = DMAE_COMP_VAL; |
| 3405 | |
| 3406 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3407 | } |
| 3408 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3409 | static void bnx2x_stats_start(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3410 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3411 | if (bp->port.pmf) |
| 3412 | bnx2x_port_stats_init(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3413 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3414 | else if (bp->func_stx) |
| 3415 | bnx2x_func_stats_init(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3416 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3417 | bnx2x_hw_stats_post(bp); |
| 3418 | bnx2x_storm_stats_post(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3419 | } |
| 3420 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3421 | static void bnx2x_stats_pmf_start(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3422 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3423 | bnx2x_stats_comp(bp); |
| 3424 | bnx2x_stats_pmf_update(bp); |
| 3425 | bnx2x_stats_start(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3426 | } |
| 3427 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3428 | static void bnx2x_stats_restart(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3429 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3430 | bnx2x_stats_comp(bp); |
| 3431 | bnx2x_stats_start(bp); |
| 3432 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3433 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3434 | static void bnx2x_bmac_stats_update(struct bnx2x *bp) |
| 3435 | { |
| 3436 | struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats); |
| 3437 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3438 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3439 | struct regpair diff; |
| 3440 | |
| 3441 | UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets); |
| 3442 | UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors); |
| 3443 | UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts); |
| 3444 | UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong); |
| 3445 | UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments); |
| 3446 | UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3447 | UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3448 | UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3449 | UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3450 | UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent); |
| 3451 | UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone); |
| 3452 | UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets); |
| 3453 | UPDATE_STAT64(tx_stat_gt127, |
| 3454 | tx_stat_etherstatspkts65octetsto127octets); |
| 3455 | UPDATE_STAT64(tx_stat_gt255, |
| 3456 | tx_stat_etherstatspkts128octetsto255octets); |
| 3457 | UPDATE_STAT64(tx_stat_gt511, |
| 3458 | tx_stat_etherstatspkts256octetsto511octets); |
| 3459 | UPDATE_STAT64(tx_stat_gt1023, |
| 3460 | tx_stat_etherstatspkts512octetsto1023octets); |
| 3461 | UPDATE_STAT64(tx_stat_gt1518, |
| 3462 | tx_stat_etherstatspkts1024octetsto1522octets); |
| 3463 | UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047); |
| 3464 | UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095); |
| 3465 | UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216); |
| 3466 | UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383); |
| 3467 | UPDATE_STAT64(tx_stat_gterr, |
| 3468 | tx_stat_dot3statsinternalmactransmiterrors); |
| 3469 | UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3470 | |
| 3471 | estats->pause_frames_received_hi = |
| 3472 | pstats->mac_stx[1].rx_stat_bmac_xpf_hi; |
| 3473 | estats->pause_frames_received_lo = |
| 3474 | pstats->mac_stx[1].rx_stat_bmac_xpf_lo; |
| 3475 | |
| 3476 | estats->pause_frames_sent_hi = |
| 3477 | pstats->mac_stx[1].tx_stat_outxoffsent_hi; |
| 3478 | estats->pause_frames_sent_lo = |
| 3479 | pstats->mac_stx[1].tx_stat_outxoffsent_lo; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3480 | } |
| 3481 | |
| 3482 | static void bnx2x_emac_stats_update(struct bnx2x *bp) |
| 3483 | { |
| 3484 | struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats); |
| 3485 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3486 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3487 | |
| 3488 | UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets); |
| 3489 | UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets); |
| 3490 | UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors); |
| 3491 | UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors); |
| 3492 | UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors); |
| 3493 | UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors); |
| 3494 | UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts); |
| 3495 | UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong); |
| 3496 | UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments); |
| 3497 | UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers); |
| 3498 | UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived); |
| 3499 | UPDATE_EXTEND_STAT(rx_stat_xoffstateentered); |
| 3500 | UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived); |
| 3501 | UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived); |
| 3502 | UPDATE_EXTEND_STAT(tx_stat_outxonsent); |
| 3503 | UPDATE_EXTEND_STAT(tx_stat_outxoffsent); |
| 3504 | UPDATE_EXTEND_STAT(tx_stat_flowcontroldone); |
| 3505 | UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions); |
| 3506 | UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes); |
| 3507 | UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes); |
| 3508 | UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions); |
| 3509 | UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions); |
| 3510 | UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions); |
| 3511 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets); |
| 3512 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets); |
| 3513 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets); |
| 3514 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets); |
| 3515 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets); |
| 3516 | UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets); |
| 3517 | UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets); |
| 3518 | UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3519 | |
| 3520 | estats->pause_frames_received_hi = |
| 3521 | pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi; |
| 3522 | estats->pause_frames_received_lo = |
| 3523 | pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo; |
| 3524 | ADD_64(estats->pause_frames_received_hi, |
| 3525 | pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi, |
| 3526 | estats->pause_frames_received_lo, |
| 3527 | pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo); |
| 3528 | |
| 3529 | estats->pause_frames_sent_hi = |
| 3530 | pstats->mac_stx[1].tx_stat_outxonsent_hi; |
| 3531 | estats->pause_frames_sent_lo = |
| 3532 | pstats->mac_stx[1].tx_stat_outxonsent_lo; |
| 3533 | ADD_64(estats->pause_frames_sent_hi, |
| 3534 | pstats->mac_stx[1].tx_stat_outxoffsent_hi, |
| 3535 | estats->pause_frames_sent_lo, |
| 3536 | pstats->mac_stx[1].tx_stat_outxoffsent_lo); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | static int bnx2x_hw_stats_update(struct bnx2x *bp) |
| 3540 | { |
| 3541 | struct nig_stats *new = bnx2x_sp(bp, nig_stats); |
| 3542 | struct nig_stats *old = &(bp->port.old_nig_stats); |
| 3543 | struct host_port_stats *pstats = bnx2x_sp(bp, port_stats); |
| 3544 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
| 3545 | struct regpair diff; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3546 | u32 nig_timer_max; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3547 | |
| 3548 | if (bp->link_vars.mac_type == MAC_TYPE_BMAC) |
| 3549 | bnx2x_bmac_stats_update(bp); |
| 3550 | |
| 3551 | else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) |
| 3552 | bnx2x_emac_stats_update(bp); |
| 3553 | |
| 3554 | else { /* unreached */ |
| 3555 | BNX2X_ERR("stats updated by dmae but no MAC active\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3556 | return -1; |
| 3557 | } |
| 3558 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3559 | ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo, |
| 3560 | new->brb_discard - old->brb_discard); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 3561 | ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo, |
| 3562 | new->brb_truncate - old->brb_truncate); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3563 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3564 | UPDATE_STAT64_NIG(egress_mac_pkt0, |
| 3565 | etherstatspkts1024octetsto1522octets); |
| 3566 | UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3567 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3568 | memcpy(old, new, sizeof(struct nig_stats)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3569 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3570 | memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]), |
| 3571 | sizeof(struct mac_stx)); |
| 3572 | estats->brb_drop_hi = pstats->brb_drop_hi; |
| 3573 | estats->brb_drop_lo = pstats->brb_drop_lo; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3574 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3575 | pstats->host_port_stats_start = ++pstats->host_port_stats_end; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3576 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3577 | nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer); |
| 3578 | if (nig_timer_max != estats->nig_timer_max) { |
| 3579 | estats->nig_timer_max = nig_timer_max; |
| 3580 | BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max); |
| 3581 | } |
| 3582 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3583 | return 0; |
| 3584 | } |
| 3585 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3586 | static int bnx2x_storm_stats_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3587 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3588 | struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3589 | struct tstorm_per_port_stats *tport = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3590 | &stats->tstorm_common.port_statistics; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3591 | struct host_func_stats *fstats = bnx2x_sp(bp, func_stats); |
| 3592 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3593 | int i; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3594 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3595 | memset(&(fstats->total_bytes_received_hi), 0, |
| 3596 | sizeof(struct host_func_stats) - 2*sizeof(u32)); |
| 3597 | estats->error_bytes_received_hi = 0; |
| 3598 | estats->error_bytes_received_lo = 0; |
| 3599 | estats->etherstatsoverrsizepkts_hi = 0; |
| 3600 | estats->etherstatsoverrsizepkts_lo = 0; |
| 3601 | estats->no_buff_discard_hi = 0; |
| 3602 | estats->no_buff_discard_lo = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3603 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3604 | for_each_queue(bp, i) { |
| 3605 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 3606 | int cl_id = fp->cl_id; |
| 3607 | struct tstorm_per_client_stats *tclient = |
| 3608 | &stats->tstorm_common.client_statistics[cl_id]; |
| 3609 | struct tstorm_per_client_stats *old_tclient = &fp->old_tclient; |
| 3610 | struct ustorm_per_client_stats *uclient = |
| 3611 | &stats->ustorm_common.client_statistics[cl_id]; |
| 3612 | struct ustorm_per_client_stats *old_uclient = &fp->old_uclient; |
| 3613 | struct xstorm_per_client_stats *xclient = |
| 3614 | &stats->xstorm_common.client_statistics[cl_id]; |
| 3615 | struct xstorm_per_client_stats *old_xclient = &fp->old_xclient; |
| 3616 | struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats; |
| 3617 | u32 diff; |
| 3618 | |
| 3619 | /* are storm stats valid? */ |
| 3620 | if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) != |
| 3621 | bp->stats_counter) { |
| 3622 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm" |
| 3623 | " xstorm counter (%d) != stats_counter (%d)\n", |
| 3624 | i, xclient->stats_counter, bp->stats_counter); |
| 3625 | return -1; |
| 3626 | } |
| 3627 | if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) != |
| 3628 | bp->stats_counter) { |
| 3629 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm" |
| 3630 | " tstorm counter (%d) != stats_counter (%d)\n", |
| 3631 | i, tclient->stats_counter, bp->stats_counter); |
| 3632 | return -2; |
| 3633 | } |
| 3634 | if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) != |
| 3635 | bp->stats_counter) { |
| 3636 | DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm" |
| 3637 | " ustorm counter (%d) != stats_counter (%d)\n", |
| 3638 | i, uclient->stats_counter, bp->stats_counter); |
| 3639 | return -4; |
| 3640 | } |
| 3641 | |
| 3642 | qstats->total_bytes_received_hi = |
| 3643 | qstats->valid_bytes_received_hi = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3644 | le32_to_cpu(tclient->total_rcv_bytes.hi); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3645 | qstats->total_bytes_received_lo = |
| 3646 | qstats->valid_bytes_received_lo = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3647 | le32_to_cpu(tclient->total_rcv_bytes.lo); |
| 3648 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3649 | qstats->error_bytes_received_hi = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3650 | le32_to_cpu(tclient->rcv_error_bytes.hi); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3651 | qstats->error_bytes_received_lo = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3652 | le32_to_cpu(tclient->rcv_error_bytes.lo); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3653 | |
| 3654 | ADD_64(qstats->total_bytes_received_hi, |
| 3655 | qstats->error_bytes_received_hi, |
| 3656 | qstats->total_bytes_received_lo, |
| 3657 | qstats->error_bytes_received_lo); |
| 3658 | |
| 3659 | UPDATE_EXTEND_TSTAT(rcv_unicast_pkts, |
| 3660 | total_unicast_packets_received); |
| 3661 | UPDATE_EXTEND_TSTAT(rcv_multicast_pkts, |
| 3662 | total_multicast_packets_received); |
| 3663 | UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts, |
| 3664 | total_broadcast_packets_received); |
| 3665 | UPDATE_EXTEND_TSTAT(packets_too_big_discard, |
| 3666 | etherstatsoverrsizepkts); |
| 3667 | UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard); |
| 3668 | |
| 3669 | SUB_EXTEND_USTAT(ucast_no_buff_pkts, |
| 3670 | total_unicast_packets_received); |
| 3671 | SUB_EXTEND_USTAT(mcast_no_buff_pkts, |
| 3672 | total_multicast_packets_received); |
| 3673 | SUB_EXTEND_USTAT(bcast_no_buff_pkts, |
| 3674 | total_broadcast_packets_received); |
| 3675 | UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard); |
| 3676 | UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard); |
| 3677 | UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard); |
| 3678 | |
| 3679 | qstats->total_bytes_transmitted_hi = |
| 3680 | le32_to_cpu(xclient->total_sent_bytes.hi); |
| 3681 | qstats->total_bytes_transmitted_lo = |
| 3682 | le32_to_cpu(xclient->total_sent_bytes.lo); |
| 3683 | |
| 3684 | UPDATE_EXTEND_XSTAT(unicast_pkts_sent, |
| 3685 | total_unicast_packets_transmitted); |
| 3686 | UPDATE_EXTEND_XSTAT(multicast_pkts_sent, |
| 3687 | total_multicast_packets_transmitted); |
| 3688 | UPDATE_EXTEND_XSTAT(broadcast_pkts_sent, |
| 3689 | total_broadcast_packets_transmitted); |
| 3690 | |
| 3691 | old_tclient->checksum_discard = tclient->checksum_discard; |
| 3692 | old_tclient->ttl0_discard = tclient->ttl0_discard; |
| 3693 | |
| 3694 | ADD_64(fstats->total_bytes_received_hi, |
| 3695 | qstats->total_bytes_received_hi, |
| 3696 | fstats->total_bytes_received_lo, |
| 3697 | qstats->total_bytes_received_lo); |
| 3698 | ADD_64(fstats->total_bytes_transmitted_hi, |
| 3699 | qstats->total_bytes_transmitted_hi, |
| 3700 | fstats->total_bytes_transmitted_lo, |
| 3701 | qstats->total_bytes_transmitted_lo); |
| 3702 | ADD_64(fstats->total_unicast_packets_received_hi, |
| 3703 | qstats->total_unicast_packets_received_hi, |
| 3704 | fstats->total_unicast_packets_received_lo, |
| 3705 | qstats->total_unicast_packets_received_lo); |
| 3706 | ADD_64(fstats->total_multicast_packets_received_hi, |
| 3707 | qstats->total_multicast_packets_received_hi, |
| 3708 | fstats->total_multicast_packets_received_lo, |
| 3709 | qstats->total_multicast_packets_received_lo); |
| 3710 | ADD_64(fstats->total_broadcast_packets_received_hi, |
| 3711 | qstats->total_broadcast_packets_received_hi, |
| 3712 | fstats->total_broadcast_packets_received_lo, |
| 3713 | qstats->total_broadcast_packets_received_lo); |
| 3714 | ADD_64(fstats->total_unicast_packets_transmitted_hi, |
| 3715 | qstats->total_unicast_packets_transmitted_hi, |
| 3716 | fstats->total_unicast_packets_transmitted_lo, |
| 3717 | qstats->total_unicast_packets_transmitted_lo); |
| 3718 | ADD_64(fstats->total_multicast_packets_transmitted_hi, |
| 3719 | qstats->total_multicast_packets_transmitted_hi, |
| 3720 | fstats->total_multicast_packets_transmitted_lo, |
| 3721 | qstats->total_multicast_packets_transmitted_lo); |
| 3722 | ADD_64(fstats->total_broadcast_packets_transmitted_hi, |
| 3723 | qstats->total_broadcast_packets_transmitted_hi, |
| 3724 | fstats->total_broadcast_packets_transmitted_lo, |
| 3725 | qstats->total_broadcast_packets_transmitted_lo); |
| 3726 | ADD_64(fstats->valid_bytes_received_hi, |
| 3727 | qstats->valid_bytes_received_hi, |
| 3728 | fstats->valid_bytes_received_lo, |
| 3729 | qstats->valid_bytes_received_lo); |
| 3730 | |
| 3731 | ADD_64(estats->error_bytes_received_hi, |
| 3732 | qstats->error_bytes_received_hi, |
| 3733 | estats->error_bytes_received_lo, |
| 3734 | qstats->error_bytes_received_lo); |
| 3735 | ADD_64(estats->etherstatsoverrsizepkts_hi, |
| 3736 | qstats->etherstatsoverrsizepkts_hi, |
| 3737 | estats->etherstatsoverrsizepkts_lo, |
| 3738 | qstats->etherstatsoverrsizepkts_lo); |
| 3739 | ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi, |
| 3740 | estats->no_buff_discard_lo, qstats->no_buff_discard_lo); |
| 3741 | } |
| 3742 | |
| 3743 | ADD_64(fstats->total_bytes_received_hi, |
| 3744 | estats->rx_stat_ifhcinbadoctets_hi, |
| 3745 | fstats->total_bytes_received_lo, |
| 3746 | estats->rx_stat_ifhcinbadoctets_lo); |
| 3747 | |
| 3748 | memcpy(estats, &(fstats->total_bytes_received_hi), |
| 3749 | sizeof(struct host_func_stats) - 2*sizeof(u32)); |
| 3750 | |
| 3751 | ADD_64(estats->etherstatsoverrsizepkts_hi, |
| 3752 | estats->rx_stat_dot3statsframestoolong_hi, |
| 3753 | estats->etherstatsoverrsizepkts_lo, |
| 3754 | estats->rx_stat_dot3statsframestoolong_lo); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3755 | ADD_64(estats->error_bytes_received_hi, |
| 3756 | estats->rx_stat_ifhcinbadoctets_hi, |
| 3757 | estats->error_bytes_received_lo, |
| 3758 | estats->rx_stat_ifhcinbadoctets_lo); |
| 3759 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3760 | if (bp->port.pmf) { |
| 3761 | estats->mac_filter_discard = |
| 3762 | le32_to_cpu(tport->mac_filter_discard); |
| 3763 | estats->xxoverflow_discard = |
| 3764 | le32_to_cpu(tport->xxoverflow_discard); |
| 3765 | estats->brb_truncate_discard = |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3766 | le32_to_cpu(tport->brb_truncate_discard); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3767 | estats->mac_discard = le32_to_cpu(tport->mac_discard); |
| 3768 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3769 | |
| 3770 | fstats->host_func_stats_start = ++fstats->host_func_stats_end; |
| 3771 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3772 | bp->stats_pending = 0; |
| 3773 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3774 | return 0; |
| 3775 | } |
| 3776 | |
| 3777 | static void bnx2x_net_stats_update(struct bnx2x *bp) |
| 3778 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3779 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3780 | struct net_device_stats *nstats = &bp->dev->stats; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3781 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3782 | |
| 3783 | nstats->rx_packets = |
| 3784 | bnx2x_hilo(&estats->total_unicast_packets_received_hi) + |
| 3785 | bnx2x_hilo(&estats->total_multicast_packets_received_hi) + |
| 3786 | bnx2x_hilo(&estats->total_broadcast_packets_received_hi); |
| 3787 | |
| 3788 | nstats->tx_packets = |
| 3789 | bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) + |
| 3790 | bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) + |
| 3791 | bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi); |
| 3792 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3793 | nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3794 | |
Eliezer Tamir | 0e39e64 | 2008-02-28 11:54:03 -0800 | [diff] [blame] | 3795 | nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3796 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3797 | nstats->rx_dropped = estats->mac_discard; |
| 3798 | for_each_queue(bp, i) |
| 3799 | nstats->rx_dropped += |
| 3800 | le32_to_cpu(bp->fp[i].old_tclient.checksum_discard); |
| 3801 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3802 | nstats->tx_dropped = 0; |
| 3803 | |
| 3804 | nstats->multicast = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3805 | bnx2x_hilo(&estats->total_multicast_packets_received_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3806 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3807 | nstats->collisions = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3808 | bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3809 | |
| 3810 | nstats->rx_length_errors = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3811 | bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) + |
| 3812 | bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi); |
| 3813 | nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) + |
| 3814 | bnx2x_hilo(&estats->brb_truncate_hi); |
| 3815 | nstats->rx_crc_errors = |
| 3816 | bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi); |
| 3817 | nstats->rx_frame_errors = |
| 3818 | bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi); |
| 3819 | nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3820 | nstats->rx_missed_errors = estats->xxoverflow_discard; |
| 3821 | |
| 3822 | nstats->rx_errors = nstats->rx_length_errors + |
| 3823 | nstats->rx_over_errors + |
| 3824 | nstats->rx_crc_errors + |
| 3825 | nstats->rx_frame_errors + |
Eliezer Tamir | 0e39e64 | 2008-02-28 11:54:03 -0800 | [diff] [blame] | 3826 | nstats->rx_fifo_errors + |
| 3827 | nstats->rx_missed_errors; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3828 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3829 | nstats->tx_aborted_errors = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3830 | bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) + |
| 3831 | bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi); |
| 3832 | nstats->tx_carrier_errors = |
| 3833 | bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3834 | nstats->tx_fifo_errors = 0; |
| 3835 | nstats->tx_heartbeat_errors = 0; |
| 3836 | nstats->tx_window_errors = 0; |
| 3837 | |
| 3838 | nstats->tx_errors = nstats->tx_aborted_errors + |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3839 | nstats->tx_carrier_errors + |
| 3840 | bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi); |
| 3841 | } |
| 3842 | |
| 3843 | static void bnx2x_drv_stats_update(struct bnx2x *bp) |
| 3844 | { |
| 3845 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
| 3846 | int i; |
| 3847 | |
| 3848 | estats->driver_xoff = 0; |
| 3849 | estats->rx_err_discard_pkt = 0; |
| 3850 | estats->rx_skb_alloc_failed = 0; |
| 3851 | estats->hw_csum_err = 0; |
| 3852 | for_each_queue(bp, i) { |
| 3853 | struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats; |
| 3854 | |
| 3855 | estats->driver_xoff += qstats->driver_xoff; |
| 3856 | estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt; |
| 3857 | estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed; |
| 3858 | estats->hw_csum_err += qstats->hw_csum_err; |
| 3859 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3860 | } |
| 3861 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3862 | static void bnx2x_stats_update(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3863 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3864 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3865 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3866 | if (*stats_comp != DMAE_COMP_VAL) |
| 3867 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3868 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3869 | if (bp->port.pmf) |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3870 | bnx2x_hw_stats_update(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3871 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3872 | if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) { |
| 3873 | BNX2X_ERR("storm stats were not updated for 3 times\n"); |
| 3874 | bnx2x_panic(); |
| 3875 | return; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3876 | } |
| 3877 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3878 | bnx2x_net_stats_update(bp); |
| 3879 | bnx2x_drv_stats_update(bp); |
| 3880 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3881 | if (bp->msglevel & NETIF_MSG_TIMER) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3882 | struct tstorm_per_client_stats *old_tclient = |
| 3883 | &bp->fp->old_tclient; |
| 3884 | struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3885 | struct bnx2x_eth_stats *estats = &bp->eth_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3886 | struct net_device_stats *nstats = &bp->dev->stats; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 3887 | int i; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3888 | |
| 3889 | printk(KERN_DEBUG "%s:\n", bp->dev->name); |
| 3890 | printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)" |
| 3891 | " tx pkt (%lx)\n", |
| 3892 | bnx2x_tx_avail(bp->fp), |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 3893 | le16_to_cpu(*bp->fp->tx_cons_sb), nstats->tx_packets); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3894 | printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)" |
| 3895 | " rx pkt (%lx)\n", |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 3896 | (u16)(le16_to_cpu(*bp->fp->rx_cons_sb) - |
| 3897 | bp->fp->rx_comp_cons), |
| 3898 | le16_to_cpu(*bp->fp->rx_cons_sb), nstats->rx_packets); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3899 | printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u " |
| 3900 | "brb truncate %u\n", |
| 3901 | (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"), |
| 3902 | qstats->driver_xoff, |
| 3903 | estats->brb_drop_lo, estats->brb_truncate_lo); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3904 | printk(KERN_DEBUG "tstats: checksum_discard %u " |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3905 | "packets_too_big_discard %lu no_buff_discard %lu " |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3906 | "mac_discard %u mac_filter_discard %u " |
| 3907 | "xxovrflow_discard %u brb_truncate_discard %u " |
| 3908 | "ttl0_discard %u\n", |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3909 | old_tclient->checksum_discard, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 3910 | bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi), |
| 3911 | bnx2x_hilo(&qstats->no_buff_discard_hi), |
| 3912 | estats->mac_discard, estats->mac_filter_discard, |
| 3913 | estats->xxoverflow_discard, estats->brb_truncate_discard, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3914 | old_tclient->ttl0_discard); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3915 | |
| 3916 | for_each_queue(bp, i) { |
| 3917 | printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i, |
| 3918 | bnx2x_fp(bp, i, tx_pkt), |
| 3919 | bnx2x_fp(bp, i, rx_pkt), |
| 3920 | bnx2x_fp(bp, i, rx_calls)); |
| 3921 | } |
| 3922 | } |
| 3923 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3924 | bnx2x_hw_stats_post(bp); |
| 3925 | bnx2x_storm_stats_post(bp); |
| 3926 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3927 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3928 | static void bnx2x_port_stats_stop(struct bnx2x *bp) |
| 3929 | { |
| 3930 | struct dmae_command *dmae; |
| 3931 | u32 opcode; |
| 3932 | int loader_idx = PMF_DMAE_C(bp); |
| 3933 | u32 *stats_comp = bnx2x_sp(bp, stats_comp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3934 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3935 | bp->executer_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3936 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3937 | opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC | |
| 3938 | DMAE_CMD_C_ENABLE | |
| 3939 | DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3940 | #ifdef __BIG_ENDIAN |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3941 | DMAE_CMD_ENDIANITY_B_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3942 | #else |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3943 | DMAE_CMD_ENDIANITY_DW_SWAP | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3944 | #endif |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3945 | (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) | |
| 3946 | (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT)); |
| 3947 | |
| 3948 | if (bp->port.port_stx) { |
| 3949 | |
| 3950 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3951 | if (bp->func_stx) |
| 3952 | dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC); |
| 3953 | else |
| 3954 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 3955 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats)); |
| 3956 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats)); |
| 3957 | dmae->dst_addr_lo = bp->port.port_stx >> 2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3958 | dmae->dst_addr_hi = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3959 | dmae->len = sizeof(struct host_port_stats) >> 2; |
| 3960 | if (bp->func_stx) { |
| 3961 | dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2; |
| 3962 | dmae->comp_addr_hi = 0; |
| 3963 | dmae->comp_val = 1; |
| 3964 | } else { |
| 3965 | dmae->comp_addr_lo = |
| 3966 | U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3967 | dmae->comp_addr_hi = |
| 3968 | U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3969 | dmae->comp_val = DMAE_COMP_VAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3970 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3971 | *stats_comp = 0; |
| 3972 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3973 | } |
| 3974 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3975 | if (bp->func_stx) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3976 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3977 | dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]); |
| 3978 | dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI); |
| 3979 | dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats)); |
| 3980 | dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats)); |
| 3981 | dmae->dst_addr_lo = bp->func_stx >> 2; |
| 3982 | dmae->dst_addr_hi = 0; |
| 3983 | dmae->len = sizeof(struct host_func_stats) >> 2; |
| 3984 | dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp)); |
| 3985 | dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp)); |
| 3986 | dmae->comp_val = DMAE_COMP_VAL; |
| 3987 | |
| 3988 | *stats_comp = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 3989 | } |
| 3990 | } |
| 3991 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 3992 | static void bnx2x_stats_stop(struct bnx2x *bp) |
| 3993 | { |
| 3994 | int update = 0; |
| 3995 | |
| 3996 | bnx2x_stats_comp(bp); |
| 3997 | |
| 3998 | if (bp->port.pmf) |
| 3999 | update = (bnx2x_hw_stats_update(bp) == 0); |
| 4000 | |
| 4001 | update |= (bnx2x_storm_stats_update(bp) == 0); |
| 4002 | |
| 4003 | if (update) { |
| 4004 | bnx2x_net_stats_update(bp); |
| 4005 | |
| 4006 | if (bp->port.pmf) |
| 4007 | bnx2x_port_stats_stop(bp); |
| 4008 | |
| 4009 | bnx2x_hw_stats_post(bp); |
| 4010 | bnx2x_stats_comp(bp); |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | static void bnx2x_stats_do_nothing(struct bnx2x *bp) |
| 4015 | { |
| 4016 | } |
| 4017 | |
| 4018 | static const struct { |
| 4019 | void (*action)(struct bnx2x *bp); |
| 4020 | enum bnx2x_stats_state next_state; |
| 4021 | } bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = { |
| 4022 | /* state event */ |
| 4023 | { |
| 4024 | /* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED}, |
| 4025 | /* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED}, |
| 4026 | /* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}, |
| 4027 | /* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED} |
| 4028 | }, |
| 4029 | { |
| 4030 | /* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED}, |
| 4031 | /* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED}, |
| 4032 | /* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED}, |
| 4033 | /* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED} |
| 4034 | } |
| 4035 | }; |
| 4036 | |
| 4037 | static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event) |
| 4038 | { |
| 4039 | enum bnx2x_stats_state state = bp->stats_state; |
| 4040 | |
| 4041 | bnx2x_stats_stm[state][event].action(bp); |
| 4042 | bp->stats_state = bnx2x_stats_stm[state][event].next_state; |
| 4043 | |
| 4044 | if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER)) |
| 4045 | DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n", |
| 4046 | state, event, bp->stats_state); |
| 4047 | } |
| 4048 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4049 | static void bnx2x_timer(unsigned long data) |
| 4050 | { |
| 4051 | struct bnx2x *bp = (struct bnx2x *) data; |
| 4052 | |
| 4053 | if (!netif_running(bp->dev)) |
| 4054 | return; |
| 4055 | |
| 4056 | if (atomic_read(&bp->intr_sem) != 0) |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 4057 | goto timer_restart; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4058 | |
| 4059 | if (poll) { |
| 4060 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
| 4061 | int rc; |
| 4062 | |
| 4063 | bnx2x_tx_int(fp, 1000); |
| 4064 | rc = bnx2x_rx_int(fp, 1000); |
| 4065 | } |
| 4066 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4067 | if (!BP_NOMCP(bp)) { |
| 4068 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4069 | u32 drv_pulse; |
| 4070 | u32 mcp_pulse; |
| 4071 | |
| 4072 | ++bp->fw_drv_pulse_wr_seq; |
| 4073 | bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK; |
| 4074 | /* TBD - add SYSTEM_TIME */ |
| 4075 | drv_pulse = bp->fw_drv_pulse_wr_seq; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4076 | SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4077 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4078 | mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) & |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4079 | MCP_PULSE_SEQ_MASK); |
| 4080 | /* The delta between driver pulse and mcp response |
| 4081 | * should be 1 (before mcp response) or 0 (after mcp response) |
| 4082 | */ |
| 4083 | if ((drv_pulse != mcp_pulse) && |
| 4084 | (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) { |
| 4085 | /* someone lost a heartbeat... */ |
| 4086 | BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n", |
| 4087 | drv_pulse, mcp_pulse); |
| 4088 | } |
| 4089 | } |
| 4090 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4091 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 4092 | (bp->state == BNX2X_STATE_DISABLED)) |
| 4093 | bnx2x_stats_handle(bp, STATS_EVENT_UPDATE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4094 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 4095 | timer_restart: |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4096 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 4097 | } |
| 4098 | |
| 4099 | /* end of Statistics */ |
| 4100 | |
| 4101 | /* nic init */ |
| 4102 | |
| 4103 | /* |
| 4104 | * nic init service functions |
| 4105 | */ |
| 4106 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4107 | static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4108 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4109 | int port = BP_PORT(bp); |
| 4110 | |
| 4111 | bnx2x_init_fill(bp, BAR_USTRORM_INTMEM + |
| 4112 | USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0, |
Yitchak Gertner | 3530298 | 2008-08-13 15:53:12 -0700 | [diff] [blame] | 4113 | sizeof(struct ustorm_status_block)/4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4114 | bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM + |
| 4115 | CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0, |
Yitchak Gertner | 3530298 | 2008-08-13 15:53:12 -0700 | [diff] [blame] | 4116 | sizeof(struct cstorm_status_block)/4); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4119 | static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb, |
| 4120 | dma_addr_t mapping, int sb_id) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4121 | { |
| 4122 | int port = BP_PORT(bp); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4123 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4124 | int index; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4125 | u64 section; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4126 | |
| 4127 | /* USTORM */ |
| 4128 | section = ((u64)mapping) + offsetof(struct host_status_block, |
| 4129 | u_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4130 | sb->u_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4131 | |
| 4132 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4133 | USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4134 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4135 | ((USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4136 | U64_HI(section)); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4137 | REG_WR8(bp, BAR_USTRORM_INTMEM + FP_USB_FUNC_OFF + |
| 4138 | USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4139 | |
| 4140 | for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++) |
| 4141 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4142 | USTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4143 | |
| 4144 | /* CSTORM */ |
| 4145 | section = ((u64)mapping) + offsetof(struct host_status_block, |
| 4146 | c_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4147 | sb->c_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4148 | |
| 4149 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4150 | CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4151 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4152 | ((CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4153 | U64_HI(section)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4154 | REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF + |
| 4155 | CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4156 | |
| 4157 | for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++) |
| 4158 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4159 | CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4160 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4161 | bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
| 4162 | } |
| 4163 | |
| 4164 | static void bnx2x_zero_def_sb(struct bnx2x *bp) |
| 4165 | { |
| 4166 | int func = BP_FUNC(bp); |
| 4167 | |
| 4168 | bnx2x_init_fill(bp, BAR_USTRORM_INTMEM + |
| 4169 | USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4170 | sizeof(struct ustorm_def_status_block)/4); |
| 4171 | bnx2x_init_fill(bp, BAR_CSTRORM_INTMEM + |
| 4172 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4173 | sizeof(struct cstorm_def_status_block)/4); |
| 4174 | bnx2x_init_fill(bp, BAR_XSTRORM_INTMEM + |
| 4175 | XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4176 | sizeof(struct xstorm_def_status_block)/4); |
| 4177 | bnx2x_init_fill(bp, BAR_TSTRORM_INTMEM + |
| 4178 | TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0, |
| 4179 | sizeof(struct tstorm_def_status_block)/4); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | static void bnx2x_init_def_sb(struct bnx2x *bp, |
| 4183 | struct host_def_status_block *def_sb, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4184 | dma_addr_t mapping, int sb_id) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4185 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4186 | int port = BP_PORT(bp); |
| 4187 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4188 | int index, val, reg_offset; |
| 4189 | u64 section; |
| 4190 | |
| 4191 | /* ATTN */ |
| 4192 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4193 | atten_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4194 | def_sb->atten_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4195 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4196 | bp->attn_state = 0; |
| 4197 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4198 | reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 : |
| 4199 | MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 4200 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4201 | for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4202 | bp->attn_group[index].sig[0] = REG_RD(bp, |
| 4203 | reg_offset + 0x10*index); |
| 4204 | bp->attn_group[index].sig[1] = REG_RD(bp, |
| 4205 | reg_offset + 0x4 + 0x10*index); |
| 4206 | bp->attn_group[index].sig[2] = REG_RD(bp, |
| 4207 | reg_offset + 0x8 + 0x10*index); |
| 4208 | bp->attn_group[index].sig[3] = REG_RD(bp, |
| 4209 | reg_offset + 0xc + 0x10*index); |
| 4210 | } |
| 4211 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4212 | reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L : |
| 4213 | HC_REG_ATTN_MSG0_ADDR_L); |
| 4214 | |
| 4215 | REG_WR(bp, reg_offset, U64_LO(section)); |
| 4216 | REG_WR(bp, reg_offset + 4, U64_HI(section)); |
| 4217 | |
| 4218 | reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0); |
| 4219 | |
| 4220 | val = REG_RD(bp, reg_offset); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4221 | val |= sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4222 | REG_WR(bp, reg_offset, val); |
| 4223 | |
| 4224 | /* USTORM */ |
| 4225 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4226 | u_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4227 | def_sb->u_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4228 | |
| 4229 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4230 | USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4231 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4232 | ((USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4233 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4234 | REG_WR8(bp, BAR_USTRORM_INTMEM + DEF_USB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4235 | USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4236 | |
| 4237 | for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++) |
| 4238 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4239 | USTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4240 | |
| 4241 | /* CSTORM */ |
| 4242 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4243 | c_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4244 | def_sb->c_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4245 | |
| 4246 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4247 | CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4248 | REG_WR(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4249 | ((CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4250 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4251 | REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4252 | CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4253 | |
| 4254 | for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++) |
| 4255 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4256 | CSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4257 | |
| 4258 | /* TSTORM */ |
| 4259 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4260 | t_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4261 | def_sb->t_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4262 | |
| 4263 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4264 | TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4265 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4266 | ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4267 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4268 | REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4269 | TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4270 | |
| 4271 | for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++) |
| 4272 | REG_WR16(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4273 | TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4274 | |
| 4275 | /* XSTORM */ |
| 4276 | section = ((u64)mapping) + offsetof(struct host_def_status_block, |
| 4277 | x_def_status_block); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4278 | def_sb->x_def_status_block.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4279 | |
| 4280 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4281 | XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4282 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4283 | ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4284 | U64_HI(section)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4285 | REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4286 | XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4287 | |
| 4288 | for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++) |
| 4289 | REG_WR16(bp, BAR_XSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4290 | XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4291 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4292 | bp->stats_pending = 0; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4293 | bp->set_mac_pending = 0; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 4294 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4295 | bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | static void bnx2x_update_coalesce(struct bnx2x *bp) |
| 4299 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4300 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4301 | int i; |
| 4302 | |
| 4303 | for_each_queue(bp, i) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4304 | int sb_id = bp->fp[i].sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4305 | |
| 4306 | /* HC_INDEX_U_ETH_RX_CQ_CONS */ |
| 4307 | REG_WR8(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4308 | USTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4309 | U_SB_ETH_RX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4310 | bp->rx_ticks/12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4311 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4312 | USTORM_SB_HC_DISABLE_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4313 | U_SB_ETH_RX_CQ_INDEX), |
| 4314 | bp->rx_ticks ? 0 : 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4315 | |
| 4316 | /* HC_INDEX_C_ETH_TX_CQ_CONS */ |
| 4317 | REG_WR8(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4318 | CSTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4319 | C_SB_ETH_TX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4320 | bp->tx_ticks/12); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4321 | REG_WR16(bp, BAR_CSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4322 | CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id, |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4323 | C_SB_ETH_TX_CQ_INDEX), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4324 | bp->tx_ticks ? 0 : 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4325 | } |
| 4326 | } |
| 4327 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4328 | static inline void bnx2x_free_tpa_pool(struct bnx2x *bp, |
| 4329 | struct bnx2x_fastpath *fp, int last) |
| 4330 | { |
| 4331 | int i; |
| 4332 | |
| 4333 | for (i = 0; i < last; i++) { |
| 4334 | struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]); |
| 4335 | struct sk_buff *skb = rx_buf->skb; |
| 4336 | |
| 4337 | if (skb == NULL) { |
| 4338 | DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i); |
| 4339 | continue; |
| 4340 | } |
| 4341 | |
| 4342 | if (fp->tpa_state[i] == BNX2X_TPA_START) |
| 4343 | pci_unmap_single(bp->pdev, |
| 4344 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 4345 | bp->rx_buf_size, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4346 | PCI_DMA_FROMDEVICE); |
| 4347 | |
| 4348 | dev_kfree_skb(skb); |
| 4349 | rx_buf->skb = NULL; |
| 4350 | } |
| 4351 | } |
| 4352 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4353 | static void bnx2x_init_rx_rings(struct bnx2x *bp) |
| 4354 | { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4355 | int func = BP_FUNC(bp); |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4356 | int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 : |
| 4357 | ETH_MAX_AGGREGATION_QUEUES_E1H; |
| 4358 | u16 ring_prod, cqe_ring_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4359 | int i, j; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4360 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 4361 | bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN; |
Eilon Greenstein | 0f00846 | 2009-02-12 08:36:18 +0000 | [diff] [blame] | 4362 | DP(NETIF_MSG_IFUP, |
| 4363 | "mtu %d rx_buf_size %d\n", bp->dev->mtu, bp->rx_buf_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4364 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4365 | if (bp->flags & TPA_ENABLE_FLAG) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4366 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4367 | for_each_rx_queue(bp, j) { |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4368 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4369 | |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4370 | for (i = 0; i < max_agg_queues; i++) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4371 | fp->tpa_pool[i].skb = |
| 4372 | netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 4373 | if (!fp->tpa_pool[i].skb) { |
| 4374 | BNX2X_ERR("Failed to allocate TPA " |
| 4375 | "skb pool for queue[%d] - " |
| 4376 | "disabling TPA on this " |
| 4377 | "queue!\n", j); |
| 4378 | bnx2x_free_tpa_pool(bp, fp, i); |
| 4379 | fp->disable_tpa = 1; |
| 4380 | break; |
| 4381 | } |
| 4382 | pci_unmap_addr_set((struct sw_rx_bd *) |
| 4383 | &bp->fp->tpa_pool[i], |
| 4384 | mapping, 0); |
| 4385 | fp->tpa_state[i] = BNX2X_TPA_STOP; |
| 4386 | } |
| 4387 | } |
| 4388 | } |
| 4389 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4390 | for_each_rx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4391 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 4392 | |
| 4393 | fp->rx_bd_cons = 0; |
| 4394 | fp->rx_cons_sb = BNX2X_RX_SB_INDEX; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4395 | fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4396 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4397 | /* "next page" elements initialization */ |
| 4398 | /* SGE ring */ |
| 4399 | for (i = 1; i <= NUM_RX_SGE_PAGES; i++) { |
| 4400 | struct eth_rx_sge *sge; |
| 4401 | |
| 4402 | sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2]; |
| 4403 | sge->addr_hi = |
| 4404 | cpu_to_le32(U64_HI(fp->rx_sge_mapping + |
| 4405 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 4406 | sge->addr_lo = |
| 4407 | cpu_to_le32(U64_LO(fp->rx_sge_mapping + |
| 4408 | BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES))); |
| 4409 | } |
| 4410 | |
| 4411 | bnx2x_init_sge_ring_bit_mask(fp); |
| 4412 | |
| 4413 | /* RX BD ring */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4414 | for (i = 1; i <= NUM_RX_RINGS; i++) { |
| 4415 | struct eth_rx_bd *rx_bd; |
| 4416 | |
| 4417 | rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2]; |
| 4418 | rx_bd->addr_hi = |
| 4419 | cpu_to_le32(U64_HI(fp->rx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4420 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4421 | rx_bd->addr_lo = |
| 4422 | cpu_to_le32(U64_LO(fp->rx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4423 | BCM_PAGE_SIZE*(i % NUM_RX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4424 | } |
| 4425 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4426 | /* CQ ring */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4427 | for (i = 1; i <= NUM_RCQ_RINGS; i++) { |
| 4428 | struct eth_rx_cqe_next_page *nextpg; |
| 4429 | |
| 4430 | nextpg = (struct eth_rx_cqe_next_page *) |
| 4431 | &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1]; |
| 4432 | nextpg->addr_hi = |
| 4433 | cpu_to_le32(U64_HI(fp->rx_comp_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4434 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4435 | nextpg->addr_lo = |
| 4436 | cpu_to_le32(U64_LO(fp->rx_comp_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4437 | BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4438 | } |
| 4439 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4440 | /* Allocate SGEs and initialize the ring elements */ |
| 4441 | for (i = 0, ring_prod = 0; |
| 4442 | i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4443 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4444 | if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) { |
| 4445 | BNX2X_ERR("was only able to allocate " |
| 4446 | "%d rx sges\n", i); |
| 4447 | BNX2X_ERR("disabling TPA for queue[%d]\n", j); |
| 4448 | /* Cleanup already allocated elements */ |
| 4449 | bnx2x_free_rx_sge_range(bp, fp, ring_prod); |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 4450 | bnx2x_free_tpa_pool(bp, fp, max_agg_queues); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4451 | fp->disable_tpa = 1; |
| 4452 | ring_prod = 0; |
| 4453 | break; |
| 4454 | } |
| 4455 | ring_prod = NEXT_SGE_IDX(ring_prod); |
| 4456 | } |
| 4457 | fp->rx_sge_prod = ring_prod; |
| 4458 | |
| 4459 | /* Allocate BDs and initialize BD ring */ |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4460 | fp->rx_comp_cons = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4461 | cqe_ring_prod = ring_prod = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4462 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 4463 | if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) { |
| 4464 | BNX2X_ERR("was only able to allocate " |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4465 | "%d rx skbs on queue[%d]\n", i, j); |
| 4466 | fp->eth_q_stats.rx_skb_alloc_failed++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4467 | break; |
| 4468 | } |
| 4469 | ring_prod = NEXT_RX_IDX(ring_prod); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4470 | cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod); |
Ilpo Järvinen | 53e5e96 | 2008-07-25 21:40:45 -0700 | [diff] [blame] | 4471 | WARN_ON(ring_prod <= i); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4472 | } |
| 4473 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4474 | fp->rx_bd_prod = ring_prod; |
| 4475 | /* must not have more available CQEs than BDs */ |
| 4476 | fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT), |
| 4477 | cqe_ring_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4478 | fp->rx_pkt = fp->rx_calls = 0; |
| 4479 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4480 | /* Warning! |
| 4481 | * this will generate an interrupt (to the TSTORM) |
| 4482 | * must only be done after chip is initialized |
| 4483 | */ |
| 4484 | bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod, |
| 4485 | fp->rx_sge_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4486 | if (j != 0) |
| 4487 | continue; |
| 4488 | |
| 4489 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4490 | USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4491 | U64_LO(fp->rx_comp_mapping)); |
| 4492 | REG_WR(bp, BAR_USTRORM_INTMEM + |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4493 | USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4494 | U64_HI(fp->rx_comp_mapping)); |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | static void bnx2x_init_tx_ring(struct bnx2x *bp) |
| 4499 | { |
| 4500 | int i, j; |
| 4501 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4502 | for_each_tx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4503 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 4504 | |
| 4505 | for (i = 1; i <= NUM_TX_RINGS; i++) { |
| 4506 | struct eth_tx_bd *tx_bd = |
| 4507 | &fp->tx_desc_ring[TX_DESC_CNT * i - 1]; |
| 4508 | |
| 4509 | tx_bd->addr_hi = |
| 4510 | cpu_to_le32(U64_HI(fp->tx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4511 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4512 | tx_bd->addr_lo = |
| 4513 | cpu_to_le32(U64_LO(fp->tx_desc_mapping + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4514 | BCM_PAGE_SIZE*(i % NUM_TX_RINGS))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | fp->tx_pkt_prod = 0; |
| 4518 | fp->tx_pkt_cons = 0; |
| 4519 | fp->tx_bd_prod = 0; |
| 4520 | fp->tx_bd_cons = 0; |
| 4521 | fp->tx_cons_sb = BNX2X_TX_SB_INDEX; |
| 4522 | fp->tx_pkt = 0; |
| 4523 | } |
| 4524 | } |
| 4525 | |
| 4526 | static void bnx2x_init_sp_ring(struct bnx2x *bp) |
| 4527 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4528 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4529 | |
| 4530 | spin_lock_init(&bp->spq_lock); |
| 4531 | |
| 4532 | bp->spq_left = MAX_SPQ_PENDING; |
| 4533 | bp->spq_prod_idx = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4534 | bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX; |
| 4535 | bp->spq_prod_bd = bp->spq; |
| 4536 | bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT; |
| 4537 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4538 | REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4539 | U64_LO(bp->spq_mapping)); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4540 | REG_WR(bp, |
| 4541 | XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4542 | U64_HI(bp->spq_mapping)); |
| 4543 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4544 | REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4545 | bp->spq_prod_idx); |
| 4546 | } |
| 4547 | |
| 4548 | static void bnx2x_init_context(struct bnx2x *bp) |
| 4549 | { |
| 4550 | int i; |
| 4551 | |
| 4552 | for_each_queue(bp, i) { |
| 4553 | struct eth_context *context = bnx2x_sp(bp, context[i].eth); |
| 4554 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4555 | u8 cl_id = fp->cl_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4556 | u8 sb_id = FP_SB_ID(fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4557 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4558 | context->ustorm_st_context.common.sb_index_numbers = |
| 4559 | BNX2X_RX_SB_INDEX_NUM; |
| 4560 | context->ustorm_st_context.common.clientId = FP_CL_ID(fp); |
| 4561 | context->ustorm_st_context.common.status_block_id = sb_id; |
| 4562 | context->ustorm_st_context.common.flags = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4563 | (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT | |
| 4564 | USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS); |
| 4565 | context->ustorm_st_context.common.statistics_counter_id = |
| 4566 | cl_id; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4567 | context->ustorm_st_context.common.mc_alignment_log_size = |
Eilon Greenstein | 0f00846 | 2009-02-12 08:36:18 +0000 | [diff] [blame] | 4568 | BNX2X_RX_ALIGN_SHIFT; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4569 | context->ustorm_st_context.common.bd_buff_size = |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 4570 | bp->rx_buf_size; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4571 | context->ustorm_st_context.common.bd_page_base_hi = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4572 | U64_HI(fp->rx_desc_mapping); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4573 | context->ustorm_st_context.common.bd_page_base_lo = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4574 | U64_LO(fp->rx_desc_mapping); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4575 | if (!fp->disable_tpa) { |
| 4576 | context->ustorm_st_context.common.flags |= |
| 4577 | (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA | |
| 4578 | USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_SGE_RING); |
| 4579 | context->ustorm_st_context.common.sge_buff_size = |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4580 | (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE, |
| 4581 | (u32)0xffff); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4582 | context->ustorm_st_context.common.sge_page_base_hi = |
| 4583 | U64_HI(fp->rx_sge_mapping); |
| 4584 | context->ustorm_st_context.common.sge_page_base_lo = |
| 4585 | U64_LO(fp->rx_sge_mapping); |
| 4586 | } |
| 4587 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4588 | context->ustorm_ag_context.cdu_usage = |
| 4589 | CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i), |
| 4590 | CDU_REGION_NUMBER_UCM_AG, |
| 4591 | ETH_CONNECTION_TYPE); |
| 4592 | |
| 4593 | context->xstorm_st_context.tx_bd_page_base_hi = |
| 4594 | U64_HI(fp->tx_desc_mapping); |
| 4595 | context->xstorm_st_context.tx_bd_page_base_lo = |
| 4596 | U64_LO(fp->tx_desc_mapping); |
| 4597 | context->xstorm_st_context.db_data_addr_hi = |
| 4598 | U64_HI(fp->tx_prods_mapping); |
| 4599 | context->xstorm_st_context.db_data_addr_lo = |
| 4600 | U64_LO(fp->tx_prods_mapping); |
| 4601 | context->xstorm_st_context.statistics_data = (fp->cl_id | |
| 4602 | XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4603 | context->cstorm_st_context.sb_index_number = |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 4604 | C_SB_ETH_TX_CQ_INDEX; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4605 | context->cstorm_st_context.status_block_id = sb_id; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4606 | |
| 4607 | context->xstorm_ag_context.cdu_reserved = |
| 4608 | CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i), |
| 4609 | CDU_REGION_NUMBER_XCM_AG, |
| 4610 | ETH_CONNECTION_TYPE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4611 | } |
| 4612 | } |
| 4613 | |
| 4614 | static void bnx2x_init_ind_table(struct bnx2x *bp) |
| 4615 | { |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 4616 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4617 | int i; |
| 4618 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4619 | if (bp->multi_mode == ETH_RSS_MODE_DISABLED) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4620 | return; |
| 4621 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4622 | DP(NETIF_MSG_IFUP, |
| 4623 | "Initializing indirection table multi_mode %d\n", bp->multi_mode); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4624 | for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4625 | REG_WR8(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 4626 | TSTORM_INDIRECTION_TABLE_OFFSET(func) + i, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4627 | BP_CL_ID(bp) + (i % bp->num_rx_queues)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4628 | } |
| 4629 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4630 | static void bnx2x_set_client_config(struct bnx2x *bp) |
| 4631 | { |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4632 | struct tstorm_eth_client_config tstorm_client = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4633 | int port = BP_PORT(bp); |
| 4634 | int i; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4635 | |
Eilon Greenstein | e7799c5 | 2009-01-14 21:30:27 -0800 | [diff] [blame] | 4636 | tstorm_client.mtu = bp->dev->mtu; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4637 | tstorm_client.config_flags = |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4638 | (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE | |
| 4639 | TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4640 | #ifdef BCM_VLAN |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 4641 | if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) { |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4642 | tstorm_client.config_flags |= |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4643 | TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4644 | DP(NETIF_MSG_IFUP, "vlan removal enabled\n"); |
| 4645 | } |
| 4646 | #endif |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4647 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4648 | if (bp->flags & TPA_ENABLE_FLAG) { |
| 4649 | tstorm_client.max_sges_for_packet = |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 4650 | SGE_PAGE_ALIGN(tstorm_client.mtu) >> SGE_PAGE_SHIFT; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4651 | tstorm_client.max_sges_for_packet = |
| 4652 | ((tstorm_client.max_sges_for_packet + |
| 4653 | PAGES_PER_SGE - 1) & (~(PAGES_PER_SGE - 1))) >> |
| 4654 | PAGES_PER_SGE_SHIFT; |
| 4655 | |
| 4656 | tstorm_client.config_flags |= |
| 4657 | TSTORM_ETH_CLIENT_CONFIG_ENABLE_SGE_RING; |
| 4658 | } |
| 4659 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4660 | for_each_queue(bp, i) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4661 | tstorm_client.statistics_counter_id = bp->fp[i].cl_id; |
| 4662 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4663 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4664 | TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id), |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4665 | ((u32 *)&tstorm_client)[0]); |
| 4666 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4667 | TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4, |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4668 | ((u32 *)&tstorm_client)[1]); |
| 4669 | } |
| 4670 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4671 | DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n", |
| 4672 | ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]); |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4673 | } |
| 4674 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4675 | static void bnx2x_set_storm_rx_mode(struct bnx2x *bp) |
| 4676 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4677 | struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4678 | int mode = bp->rx_mode; |
| 4679 | int mask = (1 << BP_L_ID(bp)); |
| 4680 | int func = BP_FUNC(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4681 | int i; |
| 4682 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 4683 | DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4684 | |
| 4685 | switch (mode) { |
| 4686 | case BNX2X_RX_MODE_NONE: /* no Rx */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4687 | tstorm_mac_filter.ucast_drop_all = mask; |
| 4688 | tstorm_mac_filter.mcast_drop_all = mask; |
| 4689 | tstorm_mac_filter.bcast_drop_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4690 | break; |
| 4691 | case BNX2X_RX_MODE_NORMAL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4692 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4693 | break; |
| 4694 | case BNX2X_RX_MODE_ALLMULTI: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4695 | tstorm_mac_filter.mcast_accept_all = mask; |
| 4696 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4697 | break; |
| 4698 | case BNX2X_RX_MODE_PROMISC: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4699 | tstorm_mac_filter.ucast_accept_all = mask; |
| 4700 | tstorm_mac_filter.mcast_accept_all = mask; |
| 4701 | tstorm_mac_filter.bcast_accept_all = mask; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4702 | break; |
| 4703 | default: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4704 | BNX2X_ERR("BAD rx mode (%d)\n", mode); |
| 4705 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) { |
| 4709 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4710 | TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4711 | ((u32 *)&tstorm_mac_filter)[i]); |
| 4712 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4713 | /* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4714 | ((u32 *)&tstorm_mac_filter)[i]); */ |
| 4715 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4716 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 4717 | if (mode != BNX2X_RX_MODE_NONE) |
| 4718 | bnx2x_set_client_config(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4719 | } |
| 4720 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4721 | static void bnx2x_init_internal_common(struct bnx2x *bp) |
| 4722 | { |
| 4723 | int i; |
| 4724 | |
Yitchak Gertner | 3cdf1db | 2008-08-25 15:24:21 -0700 | [diff] [blame] | 4725 | if (bp->flags & TPA_ENABLE_FLAG) { |
| 4726 | struct tstorm_eth_tpa_exist tpa = {0}; |
| 4727 | |
| 4728 | tpa.tpa_exist = 1; |
| 4729 | |
| 4730 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET, |
| 4731 | ((u32 *)&tpa)[0]); |
| 4732 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET + 4, |
| 4733 | ((u32 *)&tpa)[1]); |
| 4734 | } |
| 4735 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4736 | /* Zero this manually as its initialization is |
| 4737 | currently missing in the initTool */ |
| 4738 | for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++) |
| 4739 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4740 | USTORM_AGG_DATA_OFFSET + i * 4, 0); |
| 4741 | } |
| 4742 | |
| 4743 | static void bnx2x_init_internal_port(struct bnx2x *bp) |
| 4744 | { |
| 4745 | int port = BP_PORT(bp); |
| 4746 | |
| 4747 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4748 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4749 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4750 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR); |
| 4751 | } |
| 4752 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 4753 | /* Calculates the sum of vn_min_rates. |
| 4754 | It's needed for further normalizing of the min_rates. |
| 4755 | Returns: |
| 4756 | sum of vn_min_rates. |
| 4757 | or |
| 4758 | 0 - if all the min_rates are 0. |
| 4759 | In the later case fainess algorithm should be deactivated. |
| 4760 | If not all min_rates are zero then those that are zeroes will be set to 1. |
| 4761 | */ |
| 4762 | static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp) |
| 4763 | { |
| 4764 | int all_zero = 1; |
| 4765 | int port = BP_PORT(bp); |
| 4766 | int vn; |
| 4767 | |
| 4768 | bp->vn_weight_sum = 0; |
| 4769 | for (vn = VN_0; vn < E1HVN_MAX; vn++) { |
| 4770 | int func = 2*vn + port; |
| 4771 | u32 vn_cfg = |
| 4772 | SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
| 4773 | u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >> |
| 4774 | FUNC_MF_CFG_MIN_BW_SHIFT) * 100; |
| 4775 | |
| 4776 | /* Skip hidden vns */ |
| 4777 | if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) |
| 4778 | continue; |
| 4779 | |
| 4780 | /* If min rate is zero - set it to 1 */ |
| 4781 | if (!vn_min_rate) |
| 4782 | vn_min_rate = DEF_MIN_RATE; |
| 4783 | else |
| 4784 | all_zero = 0; |
| 4785 | |
| 4786 | bp->vn_weight_sum += vn_min_rate; |
| 4787 | } |
| 4788 | |
| 4789 | /* ... only if all min rates are zeros - disable fairness */ |
| 4790 | if (all_zero) |
| 4791 | bp->vn_weight_sum = 0; |
| 4792 | } |
| 4793 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4794 | static void bnx2x_init_internal_func(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4795 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4796 | struct tstorm_eth_function_common_config tstorm_config = {0}; |
| 4797 | struct stats_indication_flags stats_flags = {0}; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4798 | int port = BP_PORT(bp); |
| 4799 | int func = BP_FUNC(bp); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4800 | int i, j; |
| 4801 | u32 offset; |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4802 | u16 max_agg_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4803 | |
| 4804 | if (is_multi(bp)) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4805 | tstorm_config.config_flags = MULTI_FLAGS(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4806 | tstorm_config.rss_result_mask = MULTI_MASK; |
| 4807 | } |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 4808 | if (IS_E1HMF(bp)) |
| 4809 | tstorm_config.config_flags |= |
| 4810 | TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4811 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4812 | tstorm_config.leading_client_id = BP_L_ID(bp); |
| 4813 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4814 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4815 | TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4816 | (*(u32 *)&tstorm_config)); |
| 4817 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 4818 | bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4819 | bnx2x_set_storm_rx_mode(bp); |
| 4820 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4821 | for_each_queue(bp, i) { |
| 4822 | u8 cl_id = bp->fp[i].cl_id; |
| 4823 | |
| 4824 | /* reset xstorm per client statistics */ |
| 4825 | offset = BAR_XSTRORM_INTMEM + |
| 4826 | XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 4827 | for (j = 0; |
| 4828 | j < sizeof(struct xstorm_per_client_stats) / 4; j++) |
| 4829 | REG_WR(bp, offset + j*4, 0); |
| 4830 | |
| 4831 | /* reset tstorm per client statistics */ |
| 4832 | offset = BAR_TSTRORM_INTMEM + |
| 4833 | TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 4834 | for (j = 0; |
| 4835 | j < sizeof(struct tstorm_per_client_stats) / 4; j++) |
| 4836 | REG_WR(bp, offset + j*4, 0); |
| 4837 | |
| 4838 | /* reset ustorm per client statistics */ |
| 4839 | offset = BAR_USTRORM_INTMEM + |
| 4840 | USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id); |
| 4841 | for (j = 0; |
| 4842 | j < sizeof(struct ustorm_per_client_stats) / 4; j++) |
| 4843 | REG_WR(bp, offset + j*4, 0); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | /* Init statistics related context */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4847 | stats_flags.collect_eth = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4848 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4849 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4850 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4851 | REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4852 | ((u32 *)&stats_flags)[1]); |
| 4853 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4854 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4855 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4856 | REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4857 | ((u32 *)&stats_flags)[1]); |
| 4858 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4859 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func), |
| 4860 | ((u32 *)&stats_flags)[0]); |
| 4861 | REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4, |
| 4862 | ((u32 *)&stats_flags)[1]); |
| 4863 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4864 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4865 | ((u32 *)&stats_flags)[0]); |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4866 | REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4867 | ((u32 *)&stats_flags)[1]); |
| 4868 | |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 4869 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 4870 | XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 4871 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 4872 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 4873 | XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 4874 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
| 4875 | |
| 4876 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
| 4877 | TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 4878 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 4879 | REG_WR(bp, BAR_TSTRORM_INTMEM + |
| 4880 | TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 4881 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4882 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 4883 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4884 | USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func), |
| 4885 | U64_LO(bnx2x_sp_mapping(bp, fw_stats))); |
| 4886 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4887 | USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4, |
| 4888 | U64_HI(bnx2x_sp_mapping(bp, fw_stats))); |
| 4889 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4890 | if (CHIP_IS_E1H(bp)) { |
| 4891 | REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET, |
| 4892 | IS_E1HMF(bp)); |
| 4893 | REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET, |
| 4894 | IS_E1HMF(bp)); |
| 4895 | REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET, |
| 4896 | IS_E1HMF(bp)); |
| 4897 | REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET, |
| 4898 | IS_E1HMF(bp)); |
| 4899 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4900 | REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func), |
| 4901 | bp->e1hov); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 4902 | } |
| 4903 | |
Eilon Greenstein | 4f40f2c | 2009-01-14 21:24:17 -0800 | [diff] [blame] | 4904 | /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */ |
| 4905 | max_agg_size = |
| 4906 | min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) * |
| 4907 | SGE_PAGE_SIZE * PAGES_PER_SGE), |
| 4908 | (u32)0xffff); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 4909 | for_each_rx_queue(bp, i) { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4910 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4911 | |
| 4912 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4913 | USTORM_CQE_PAGE_BASE_OFFSET(port, FP_CL_ID(fp)), |
| 4914 | U64_LO(fp->rx_comp_mapping)); |
| 4915 | REG_WR(bp, BAR_USTRORM_INTMEM + |
| 4916 | USTORM_CQE_PAGE_BASE_OFFSET(port, FP_CL_ID(fp)) + 4, |
| 4917 | U64_HI(fp->rx_comp_mapping)); |
| 4918 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 4919 | REG_WR16(bp, BAR_USTRORM_INTMEM + |
| 4920 | USTORM_MAX_AGG_SIZE_OFFSET(port, FP_CL_ID(fp)), |
| 4921 | max_agg_size); |
| 4922 | } |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 4923 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 4924 | /* dropless flow control */ |
| 4925 | if (CHIP_IS_E1H(bp)) { |
| 4926 | struct ustorm_eth_rx_pause_data_e1h rx_pause = {0}; |
| 4927 | |
| 4928 | rx_pause.bd_thr_low = 250; |
| 4929 | rx_pause.cqe_thr_low = 250; |
| 4930 | rx_pause.cos = 1; |
| 4931 | rx_pause.sge_thr_low = 0; |
| 4932 | rx_pause.bd_thr_high = 350; |
| 4933 | rx_pause.cqe_thr_high = 350; |
| 4934 | rx_pause.sge_thr_high = 0; |
| 4935 | |
| 4936 | for_each_rx_queue(bp, i) { |
| 4937 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 4938 | |
| 4939 | if (!fp->disable_tpa) { |
| 4940 | rx_pause.sge_thr_low = 150; |
| 4941 | rx_pause.sge_thr_high = 250; |
| 4942 | } |
| 4943 | |
| 4944 | |
| 4945 | offset = BAR_USTRORM_INTMEM + |
| 4946 | USTORM_ETH_RING_PAUSE_DATA_OFFSET(port, |
| 4947 | fp->cl_id); |
| 4948 | for (j = 0; |
| 4949 | j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4; |
| 4950 | j++) |
| 4951 | REG_WR(bp, offset + j*4, |
| 4952 | ((u32 *)&rx_pause)[j]); |
| 4953 | } |
| 4954 | } |
| 4955 | |
Eilon Greenstein | 8a1c38d | 2009-02-12 08:36:40 +0000 | [diff] [blame] | 4956 | memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port)); |
| 4957 | |
| 4958 | /* Init rate shaping and fairness contexts */ |
| 4959 | if (IS_E1HMF(bp)) { |
| 4960 | int vn; |
| 4961 | |
| 4962 | /* During init there is no active link |
| 4963 | Until link is up, set link rate to 10Gbps */ |
| 4964 | bp->link_vars.line_speed = SPEED_10000; |
| 4965 | bnx2x_init_port_minmax(bp); |
| 4966 | |
| 4967 | bnx2x_calc_vn_weight_sum(bp); |
| 4968 | |
| 4969 | for (vn = VN_0; vn < E1HVN_MAX; vn++) |
| 4970 | bnx2x_init_vn_minmax(bp, 2*vn + port); |
| 4971 | |
| 4972 | /* Enable rate shaping and fairness */ |
| 4973 | bp->cmng.flags.cmng_enables = |
| 4974 | CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN; |
| 4975 | if (bp->vn_weight_sum) |
| 4976 | bp->cmng.flags.cmng_enables |= |
| 4977 | CMNG_FLAGS_PER_PORT_FAIRNESS_VN; |
| 4978 | else |
| 4979 | DP(NETIF_MSG_IFUP, "All MIN values are zeroes" |
| 4980 | " fairness will be disabled\n"); |
| 4981 | } else { |
| 4982 | /* rate shaping and fairness are disabled */ |
| 4983 | DP(NETIF_MSG_IFUP, |
| 4984 | "single function mode minmax will be disabled\n"); |
| 4985 | } |
| 4986 | |
| 4987 | |
| 4988 | /* Store it to internal memory */ |
| 4989 | if (bp->port.pmf) |
| 4990 | for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++) |
| 4991 | REG_WR(bp, BAR_XSTRORM_INTMEM + |
| 4992 | XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4, |
| 4993 | ((u32 *)(&bp->cmng))[i]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 4994 | } |
| 4995 | |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 4996 | static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code) |
| 4997 | { |
| 4998 | switch (load_code) { |
| 4999 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
| 5000 | bnx2x_init_internal_common(bp); |
| 5001 | /* no break */ |
| 5002 | |
| 5003 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 5004 | bnx2x_init_internal_port(bp); |
| 5005 | /* no break */ |
| 5006 | |
| 5007 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 5008 | bnx2x_init_internal_func(bp); |
| 5009 | break; |
| 5010 | |
| 5011 | default: |
| 5012 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 5013 | break; |
| 5014 | } |
| 5015 | } |
| 5016 | |
| 5017 | static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5018 | { |
| 5019 | int i; |
| 5020 | |
| 5021 | for_each_queue(bp, i) { |
| 5022 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 5023 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5024 | fp->bp = bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5025 | fp->state = BNX2X_FP_STATE_CLOSED; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5026 | fp->index = i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5027 | fp->cl_id = BP_L_ID(bp) + i; |
| 5028 | fp->sb_id = fp->cl_id; |
| 5029 | DP(NETIF_MSG_IFUP, |
| 5030 | "bnx2x_init_sb(%p,%p) index %d cl_id %d sb %d\n", |
| 5031 | bp, fp->status_blk, i, FP_CL_ID(fp), FP_SB_ID(fp)); |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5032 | bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping, |
| 5033 | FP_SB_ID(fp)); |
| 5034 | bnx2x_update_fpsb_idx(fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5035 | } |
| 5036 | |
Eilon Greenstein | 5c86284 | 2008-08-13 15:51:48 -0700 | [diff] [blame] | 5037 | bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping, |
| 5038 | DEF_SB_ID); |
| 5039 | bnx2x_update_dsb_idx(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5040 | bnx2x_update_coalesce(bp); |
| 5041 | bnx2x_init_rx_rings(bp); |
| 5042 | bnx2x_init_tx_ring(bp); |
| 5043 | bnx2x_init_sp_ring(bp); |
| 5044 | bnx2x_init_context(bp); |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 5045 | bnx2x_init_internal(bp, load_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5046 | bnx2x_init_ind_table(bp); |
Eilon Greenstein | 0ef0045 | 2009-01-14 21:31:08 -0800 | [diff] [blame] | 5047 | bnx2x_stats_init(bp); |
| 5048 | |
| 5049 | /* At this point, we are ready for interrupts */ |
| 5050 | atomic_set(&bp->intr_sem, 0); |
| 5051 | |
| 5052 | /* flush all before enabling interrupts */ |
| 5053 | mb(); |
| 5054 | mmiowb(); |
| 5055 | |
Eliezer Tamir | 615f8fd | 2008-02-28 11:54:54 -0800 | [diff] [blame] | 5056 | bnx2x_int_enable(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | /* end of nic init */ |
| 5060 | |
| 5061 | /* |
| 5062 | * gzip service functions |
| 5063 | */ |
| 5064 | |
| 5065 | static int bnx2x_gunzip_init(struct bnx2x *bp) |
| 5066 | { |
| 5067 | bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE, |
| 5068 | &bp->gunzip_mapping); |
| 5069 | if (bp->gunzip_buf == NULL) |
| 5070 | goto gunzip_nomem1; |
| 5071 | |
| 5072 | bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL); |
| 5073 | if (bp->strm == NULL) |
| 5074 | goto gunzip_nomem2; |
| 5075 | |
| 5076 | bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), |
| 5077 | GFP_KERNEL); |
| 5078 | if (bp->strm->workspace == NULL) |
| 5079 | goto gunzip_nomem3; |
| 5080 | |
| 5081 | return 0; |
| 5082 | |
| 5083 | gunzip_nomem3: |
| 5084 | kfree(bp->strm); |
| 5085 | bp->strm = NULL; |
| 5086 | |
| 5087 | gunzip_nomem2: |
| 5088 | pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5089 | bp->gunzip_mapping); |
| 5090 | bp->gunzip_buf = NULL; |
| 5091 | |
| 5092 | gunzip_nomem1: |
| 5093 | printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for" |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5094 | " un-compression\n", bp->dev->name); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5095 | return -ENOMEM; |
| 5096 | } |
| 5097 | |
| 5098 | static void bnx2x_gunzip_end(struct bnx2x *bp) |
| 5099 | { |
| 5100 | kfree(bp->strm->workspace); |
| 5101 | |
| 5102 | kfree(bp->strm); |
| 5103 | bp->strm = NULL; |
| 5104 | |
| 5105 | if (bp->gunzip_buf) { |
| 5106 | pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf, |
| 5107 | bp->gunzip_mapping); |
| 5108 | bp->gunzip_buf = NULL; |
| 5109 | } |
| 5110 | } |
| 5111 | |
| 5112 | static int bnx2x_gunzip(struct bnx2x *bp, u8 *zbuf, int len) |
| 5113 | { |
| 5114 | int n, rc; |
| 5115 | |
| 5116 | /* check gzip header */ |
| 5117 | if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) |
| 5118 | return -EINVAL; |
| 5119 | |
| 5120 | n = 10; |
| 5121 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5122 | #define FNAME 0x8 |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5123 | |
| 5124 | if (zbuf[3] & FNAME) |
| 5125 | while ((zbuf[n++] != 0) && (n < len)); |
| 5126 | |
| 5127 | bp->strm->next_in = zbuf + n; |
| 5128 | bp->strm->avail_in = len - n; |
| 5129 | bp->strm->next_out = bp->gunzip_buf; |
| 5130 | bp->strm->avail_out = FW_BUF_SIZE; |
| 5131 | |
| 5132 | rc = zlib_inflateInit2(bp->strm, -MAX_WBITS); |
| 5133 | if (rc != Z_OK) |
| 5134 | return rc; |
| 5135 | |
| 5136 | rc = zlib_inflate(bp->strm, Z_FINISH); |
| 5137 | if ((rc != Z_OK) && (rc != Z_STREAM_END)) |
| 5138 | printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n", |
| 5139 | bp->dev->name, bp->strm->msg); |
| 5140 | |
| 5141 | bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out); |
| 5142 | if (bp->gunzip_outlen & 0x3) |
| 5143 | printk(KERN_ERR PFX "%s: Firmware decompression error:" |
| 5144 | " gunzip_outlen (%d) not aligned\n", |
| 5145 | bp->dev->name, bp->gunzip_outlen); |
| 5146 | bp->gunzip_outlen >>= 2; |
| 5147 | |
| 5148 | zlib_inflateEnd(bp->strm); |
| 5149 | |
| 5150 | if (rc == Z_STREAM_END) |
| 5151 | return 0; |
| 5152 | |
| 5153 | return rc; |
| 5154 | } |
| 5155 | |
| 5156 | /* nic load/unload */ |
| 5157 | |
| 5158 | /* |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5159 | * General service functions |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5160 | */ |
| 5161 | |
| 5162 | /* send a NIG loopback debug packet */ |
| 5163 | static void bnx2x_lb_pckt(struct bnx2x *bp) |
| 5164 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5165 | u32 wb_write[3]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5166 | |
| 5167 | /* Ethernet source and destination addresses */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5168 | wb_write[0] = 0x55555555; |
| 5169 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5170 | wb_write[2] = 0x20; /* SOP */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5171 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5172 | |
| 5173 | /* NON-IP protocol */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5174 | wb_write[0] = 0x09000000; |
| 5175 | wb_write[1] = 0x55555555; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5176 | wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5177 | REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | /* some of the internal memories |
| 5181 | * are not directly readable from the driver |
| 5182 | * to test them we send debug packets |
| 5183 | */ |
| 5184 | static int bnx2x_int_mem_test(struct bnx2x *bp) |
| 5185 | { |
| 5186 | int factor; |
| 5187 | int count, i; |
| 5188 | u32 val = 0; |
| 5189 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5190 | if (CHIP_REV_IS_FPGA(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5191 | factor = 120; |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5192 | else if (CHIP_REV_IS_EMUL(bp)) |
| 5193 | factor = 200; |
| 5194 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5195 | factor = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5196 | |
| 5197 | DP(NETIF_MSG_HW, "start part1\n"); |
| 5198 | |
| 5199 | /* Disable inputs of parser neighbor blocks */ |
| 5200 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5201 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5202 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5203 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5204 | |
| 5205 | /* Write 0 to parser credits for CFC search request */ |
| 5206 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5207 | |
| 5208 | /* send Ethernet packet */ |
| 5209 | bnx2x_lb_pckt(bp); |
| 5210 | |
| 5211 | /* TODO do i reset NIG statistic? */ |
| 5212 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5213 | count = 1000 * factor; |
| 5214 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5215 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5216 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5217 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5218 | if (val == 0x10) |
| 5219 | break; |
| 5220 | |
| 5221 | msleep(10); |
| 5222 | count--; |
| 5223 | } |
| 5224 | if (val != 0x10) { |
| 5225 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5226 | return -1; |
| 5227 | } |
| 5228 | |
| 5229 | /* Wait until PRS register shows 1 packet */ |
| 5230 | count = 1000 * factor; |
| 5231 | while (count) { |
| 5232 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5233 | if (val == 1) |
| 5234 | break; |
| 5235 | |
| 5236 | msleep(10); |
| 5237 | count--; |
| 5238 | } |
| 5239 | if (val != 0x1) { |
| 5240 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5241 | return -2; |
| 5242 | } |
| 5243 | |
| 5244 | /* Reset and init BRB, PRS */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5245 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5246 | msleep(50); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5247 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5248 | msleep(50); |
| 5249 | bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END); |
| 5250 | bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END); |
| 5251 | |
| 5252 | DP(NETIF_MSG_HW, "part2\n"); |
| 5253 | |
| 5254 | /* Disable inputs of parser neighbor blocks */ |
| 5255 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0); |
| 5256 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x0); |
| 5257 | REG_WR(bp, CFC_REG_DEBUG0, 0x1); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5258 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5259 | |
| 5260 | /* Write 0 to parser credits for CFC search request */ |
| 5261 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0); |
| 5262 | |
| 5263 | /* send 10 Ethernet packets */ |
| 5264 | for (i = 0; i < 10; i++) |
| 5265 | bnx2x_lb_pckt(bp); |
| 5266 | |
| 5267 | /* Wait until NIG register shows 10 + 1 |
| 5268 | packets of size 11*0x10 = 0xb0 */ |
| 5269 | count = 1000 * factor; |
| 5270 | while (count) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5271 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5272 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5273 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5274 | if (val == 0xb0) |
| 5275 | break; |
| 5276 | |
| 5277 | msleep(10); |
| 5278 | count--; |
| 5279 | } |
| 5280 | if (val != 0xb0) { |
| 5281 | BNX2X_ERR("NIG timeout val = 0x%x\n", val); |
| 5282 | return -3; |
| 5283 | } |
| 5284 | |
| 5285 | /* Wait until PRS register shows 2 packets */ |
| 5286 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5287 | if (val != 2) |
| 5288 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5289 | |
| 5290 | /* Write 1 to parser credits for CFC search request */ |
| 5291 | REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1); |
| 5292 | |
| 5293 | /* Wait until PRS register shows 3 packets */ |
| 5294 | msleep(10 * factor); |
| 5295 | /* Wait until NIG register shows 1 packet of size 0x10 */ |
| 5296 | val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS); |
| 5297 | if (val != 3) |
| 5298 | BNX2X_ERR("PRS timeout val = 0x%x\n", val); |
| 5299 | |
| 5300 | /* clear NIG EOP FIFO */ |
| 5301 | for (i = 0; i < 11; i++) |
| 5302 | REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO); |
| 5303 | val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY); |
| 5304 | if (val != 1) { |
| 5305 | BNX2X_ERR("clear of NIG failed\n"); |
| 5306 | return -4; |
| 5307 | } |
| 5308 | |
| 5309 | /* Reset and init BRB, PRS, NIG */ |
| 5310 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03); |
| 5311 | msleep(50); |
| 5312 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03); |
| 5313 | msleep(50); |
| 5314 | bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END); |
| 5315 | bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END); |
| 5316 | #ifndef BCM_ISCSI |
| 5317 | /* set NIC mode */ |
| 5318 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
| 5319 | #endif |
| 5320 | |
| 5321 | /* Enable inputs of parser neighbor blocks */ |
| 5322 | REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff); |
| 5323 | REG_WR(bp, TCM_REG_PRS_IFEN, 0x1); |
| 5324 | REG_WR(bp, CFC_REG_DEBUG0, 0x0); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5325 | REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5326 | |
| 5327 | DP(NETIF_MSG_HW, "done\n"); |
| 5328 | |
| 5329 | return 0; /* OK */ |
| 5330 | } |
| 5331 | |
| 5332 | static void enable_blocks_attention(struct bnx2x *bp) |
| 5333 | { |
| 5334 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
| 5335 | REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0); |
| 5336 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 5337 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 5338 | REG_WR(bp, QM_REG_QM_INT_MASK, 0); |
| 5339 | REG_WR(bp, TM_REG_TM_INT_MASK, 0); |
| 5340 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0); |
| 5341 | REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0); |
| 5342 | REG_WR(bp, XCM_REG_XCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5343 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */ |
| 5344 | /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5345 | REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0); |
| 5346 | REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0); |
| 5347 | REG_WR(bp, UCM_REG_UCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5348 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */ |
| 5349 | /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5350 | REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0); |
| 5351 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0); |
| 5352 | REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0); |
| 5353 | REG_WR(bp, CCM_REG_CCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5354 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */ |
| 5355 | /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */ |
| 5356 | if (CHIP_REV_IS_FPGA(bp)) |
| 5357 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000); |
| 5358 | else |
| 5359 | REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5360 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0); |
| 5361 | REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0); |
| 5362 | REG_WR(bp, TCM_REG_TCM_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5363 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */ |
| 5364 | /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5365 | REG_WR(bp, CDU_REG_CDU_INT_MASK, 0); |
| 5366 | REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5367 | /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */ |
| 5368 | REG_WR(bp, PBF_REG_PBF_INT_MASK, 0X18); /* bit 3,4 masked */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5369 | } |
| 5370 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5371 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5372 | static void bnx2x_reset_common(struct bnx2x *bp) |
| 5373 | { |
| 5374 | /* reset_common */ |
| 5375 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5376 | 0xd3ffff7f); |
| 5377 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403); |
| 5378 | } |
| 5379 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5380 | static int bnx2x_init_common(struct bnx2x *bp) |
| 5381 | { |
| 5382 | u32 val, i; |
| 5383 | |
| 5384 | DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp)); |
| 5385 | |
Eilon Greenstein | 81f75bb | 2009-01-22 03:37:31 +0000 | [diff] [blame] | 5386 | bnx2x_reset_common(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5387 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff); |
| 5388 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc); |
| 5389 | |
| 5390 | bnx2x_init_block(bp, MISC_COMMON_START, MISC_COMMON_END); |
| 5391 | if (CHIP_IS_E1H(bp)) |
| 5392 | REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp)); |
| 5393 | |
| 5394 | REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100); |
| 5395 | msleep(30); |
| 5396 | REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0); |
| 5397 | |
| 5398 | bnx2x_init_block(bp, PXP_COMMON_START, PXP_COMMON_END); |
| 5399 | if (CHIP_IS_E1(bp)) { |
| 5400 | /* enable HW interrupt from PXP on USDM overflow |
| 5401 | bit 16 on INT_MASK_0 */ |
| 5402 | REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5403 | } |
| 5404 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5405 | bnx2x_init_block(bp, PXP2_COMMON_START, PXP2_COMMON_END); |
| 5406 | bnx2x_init_pxp(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5407 | |
| 5408 | #ifdef __BIG_ENDIAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5409 | REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1); |
| 5410 | REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1); |
| 5411 | REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1); |
| 5412 | REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1); |
| 5413 | REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 5414 | /* make sure this value is 0 */ |
| 5415 | REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5416 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5417 | /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */ |
| 5418 | REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1); |
| 5419 | REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1); |
| 5420 | REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1); |
| 5421 | REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5422 | #endif |
| 5423 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5424 | REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5425 | #ifdef BCM_ISCSI |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5426 | REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5); |
| 5427 | REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5); |
| 5428 | REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5429 | #endif |
| 5430 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5431 | if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp)) |
| 5432 | REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5433 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5434 | /* let the HW do it's magic ... */ |
| 5435 | msleep(100); |
| 5436 | /* finish PXP init */ |
| 5437 | val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE); |
| 5438 | if (val != 1) { |
| 5439 | BNX2X_ERR("PXP2 CFG failed\n"); |
| 5440 | return -EBUSY; |
| 5441 | } |
| 5442 | val = REG_RD(bp, PXP2_REG_RD_INIT_DONE); |
| 5443 | if (val != 1) { |
| 5444 | BNX2X_ERR("PXP2 RD_INIT failed\n"); |
| 5445 | return -EBUSY; |
| 5446 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5447 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5448 | REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0); |
| 5449 | REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5450 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5451 | bnx2x_init_block(bp, DMAE_COMMON_START, DMAE_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5452 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5453 | /* clean the DMAE memory */ |
| 5454 | bp->dmae_ready = 1; |
| 5455 | bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5456 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5457 | bnx2x_init_block(bp, TCM_COMMON_START, TCM_COMMON_END); |
| 5458 | bnx2x_init_block(bp, UCM_COMMON_START, UCM_COMMON_END); |
| 5459 | bnx2x_init_block(bp, CCM_COMMON_START, CCM_COMMON_END); |
| 5460 | bnx2x_init_block(bp, XCM_COMMON_START, XCM_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5461 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5462 | bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3); |
| 5463 | bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3); |
| 5464 | bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3); |
| 5465 | bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3); |
| 5466 | |
| 5467 | bnx2x_init_block(bp, QM_COMMON_START, QM_COMMON_END); |
| 5468 | /* soft reset pulse */ |
| 5469 | REG_WR(bp, QM_REG_SOFT_RESET, 1); |
| 5470 | REG_WR(bp, QM_REG_SOFT_RESET, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5471 | |
| 5472 | #ifdef BCM_ISCSI |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5473 | bnx2x_init_block(bp, TIMERS_COMMON_START, TIMERS_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5474 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5475 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5476 | bnx2x_init_block(bp, DQ_COMMON_START, DQ_COMMON_END); |
| 5477 | REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT); |
| 5478 | if (!CHIP_REV_IS_SLOW(bp)) { |
| 5479 | /* enable hw interrupt from doorbell Q */ |
| 5480 | REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0); |
| 5481 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5482 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5483 | bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5484 | bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END); |
Eilon Greenstein | 26c8fa4 | 2009-01-14 21:29:55 -0800 | [diff] [blame] | 5485 | REG_WR(bp, PRS_REG_A_PRSU_20, 0xf); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 5486 | /* set NIC mode */ |
| 5487 | REG_WR(bp, PRS_REG_NIC_MODE, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5488 | if (CHIP_IS_E1H(bp)) |
| 5489 | REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5490 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5491 | bnx2x_init_block(bp, TSDM_COMMON_START, TSDM_COMMON_END); |
| 5492 | bnx2x_init_block(bp, CSDM_COMMON_START, CSDM_COMMON_END); |
| 5493 | bnx2x_init_block(bp, USDM_COMMON_START, USDM_COMMON_END); |
| 5494 | bnx2x_init_block(bp, XSDM_COMMON_START, XSDM_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5495 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5496 | if (CHIP_IS_E1H(bp)) { |
| 5497 | bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0, |
| 5498 | STORM_INTMEM_SIZE_E1H/2); |
| 5499 | bnx2x_init_fill(bp, |
| 5500 | TSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5501 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5502 | bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0, |
| 5503 | STORM_INTMEM_SIZE_E1H/2); |
| 5504 | bnx2x_init_fill(bp, |
| 5505 | CSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5506 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5507 | bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0, |
| 5508 | STORM_INTMEM_SIZE_E1H/2); |
| 5509 | bnx2x_init_fill(bp, |
| 5510 | XSTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5511 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5512 | bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0, |
| 5513 | STORM_INTMEM_SIZE_E1H/2); |
| 5514 | bnx2x_init_fill(bp, |
| 5515 | USTORM_INTMEM_ADDR + STORM_INTMEM_SIZE_E1H/2, |
| 5516 | 0, STORM_INTMEM_SIZE_E1H/2); |
| 5517 | } else { /* E1 */ |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5518 | bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0, |
| 5519 | STORM_INTMEM_SIZE_E1); |
| 5520 | bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0, |
| 5521 | STORM_INTMEM_SIZE_E1); |
| 5522 | bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0, |
| 5523 | STORM_INTMEM_SIZE_E1); |
| 5524 | bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0, |
| 5525 | STORM_INTMEM_SIZE_E1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5526 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5527 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5528 | bnx2x_init_block(bp, TSEM_COMMON_START, TSEM_COMMON_END); |
| 5529 | bnx2x_init_block(bp, USEM_COMMON_START, USEM_COMMON_END); |
| 5530 | bnx2x_init_block(bp, CSEM_COMMON_START, CSEM_COMMON_END); |
| 5531 | bnx2x_init_block(bp, XSEM_COMMON_START, XSEM_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5532 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5533 | /* sync semi rtc */ |
| 5534 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
| 5535 | 0x80000000); |
| 5536 | REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 5537 | 0x80000000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5538 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5539 | bnx2x_init_block(bp, UPB_COMMON_START, UPB_COMMON_END); |
| 5540 | bnx2x_init_block(bp, XPB_COMMON_START, XPB_COMMON_END); |
| 5541 | bnx2x_init_block(bp, PBF_COMMON_START, PBF_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5542 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5543 | REG_WR(bp, SRC_REG_SOFT_RST, 1); |
| 5544 | for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) { |
| 5545 | REG_WR(bp, i, 0xc0cac01a); |
| 5546 | /* TODO: replace with something meaningful */ |
| 5547 | } |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5548 | bnx2x_init_block(bp, SRCH_COMMON_START, SRCH_COMMON_END); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5549 | REG_WR(bp, SRC_REG_SOFT_RST, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5550 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5551 | if (sizeof(union cdu_context) != 1024) |
| 5552 | /* we currently assume that a context is 1024 bytes */ |
| 5553 | printk(KERN_ALERT PFX "please adjust the size of" |
| 5554 | " cdu_context(%ld)\n", (long)sizeof(union cdu_context)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5555 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5556 | bnx2x_init_block(bp, CDU_COMMON_START, CDU_COMMON_END); |
| 5557 | val = (4 << 24) + (0 << 12) + 1024; |
| 5558 | REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val); |
| 5559 | if (CHIP_IS_E1(bp)) { |
| 5560 | /* !!! fix pxp client crdit until excel update */ |
| 5561 | REG_WR(bp, CDU_REG_CDU_DEBUG, 0x264); |
| 5562 | REG_WR(bp, CDU_REG_CDU_DEBUG, 0); |
| 5563 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5564 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5565 | bnx2x_init_block(bp, CFC_COMMON_START, CFC_COMMON_END); |
| 5566 | REG_WR(bp, CFC_REG_INIT_REG, 0x7FF); |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5567 | /* enable context validation interrupt from CFC */ |
| 5568 | REG_WR(bp, CFC_REG_CFC_INT_MASK, 0); |
| 5569 | |
| 5570 | /* set the thresholds to prevent CFC/CDU race */ |
| 5571 | REG_WR(bp, CFC_REG_DEBUG0, 0x20020000); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5572 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5573 | bnx2x_init_block(bp, HC_COMMON_START, HC_COMMON_END); |
| 5574 | bnx2x_init_block(bp, MISC_AEU_COMMON_START, MISC_AEU_COMMON_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5575 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5576 | /* PXPCS COMMON comes here */ |
| 5577 | /* Reset PCIE errors for debug */ |
| 5578 | REG_WR(bp, 0x2814, 0xffffffff); |
| 5579 | REG_WR(bp, 0x3820, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5580 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5581 | /* EMAC0 COMMON comes here */ |
| 5582 | /* EMAC1 COMMON comes here */ |
| 5583 | /* DBU COMMON comes here */ |
| 5584 | /* DBG COMMON comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5585 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5586 | bnx2x_init_block(bp, NIG_COMMON_START, NIG_COMMON_END); |
| 5587 | if (CHIP_IS_E1H(bp)) { |
| 5588 | REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp)); |
| 5589 | REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp)); |
| 5590 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5591 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5592 | if (CHIP_REV_IS_SLOW(bp)) |
| 5593 | msleep(200); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5594 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5595 | /* finish CFC init */ |
| 5596 | val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10); |
| 5597 | if (val != 1) { |
| 5598 | BNX2X_ERR("CFC LL_INIT failed\n"); |
| 5599 | return -EBUSY; |
| 5600 | } |
| 5601 | val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10); |
| 5602 | if (val != 1) { |
| 5603 | BNX2X_ERR("CFC AC_INIT failed\n"); |
| 5604 | return -EBUSY; |
| 5605 | } |
| 5606 | val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10); |
| 5607 | if (val != 1) { |
| 5608 | BNX2X_ERR("CFC CAM_INIT failed\n"); |
| 5609 | return -EBUSY; |
| 5610 | } |
| 5611 | REG_WR(bp, CFC_REG_DEBUG0, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5612 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5613 | /* read NIG statistic |
| 5614 | to see if this is our first up since powerup */ |
| 5615 | bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2); |
| 5616 | val = *bnx2x_sp(bp, wb_data[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5617 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5618 | /* do internal memory self test */ |
| 5619 | if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) { |
| 5620 | BNX2X_ERR("internal mem self test failed\n"); |
| 5621 | return -EBUSY; |
| 5622 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5623 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 5624 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
| 5625 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5626 | /* Fan failure is indicated by SPIO 5 */ |
| 5627 | bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5, |
| 5628 | MISC_REGISTERS_SPIO_INPUT_HI_Z); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5629 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5630 | /* set to active low mode */ |
| 5631 | val = REG_RD(bp, MISC_REG_SPIO_INT); |
| 5632 | val |= ((1 << MISC_REGISTERS_SPIO_5) << |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5633 | MISC_REGISTERS_SPIO_INT_OLD_SET_POS); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5634 | REG_WR(bp, MISC_REG_SPIO_INT, val); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5635 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5636 | /* enable interrupt to signal the IGU */ |
| 5637 | val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN); |
| 5638 | val |= (1 << MISC_REGISTERS_SPIO_5); |
| 5639 | REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val); |
| 5640 | break; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5641 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5642 | default: |
| 5643 | break; |
| 5644 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5645 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5646 | /* clear PXP2 attentions */ |
| 5647 | REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5648 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5649 | enable_blocks_attention(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5650 | |
Yaniv Rosner | 6bbca91 | 2008-08-13 15:57:28 -0700 | [diff] [blame] | 5651 | if (!BP_NOMCP(bp)) { |
| 5652 | bnx2x_acquire_phy_lock(bp); |
| 5653 | bnx2x_common_init_phy(bp, bp->common.shmem_base); |
| 5654 | bnx2x_release_phy_lock(bp); |
| 5655 | } else |
| 5656 | BNX2X_ERR("Bootcode is missing - can not initialize link\n"); |
| 5657 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5658 | return 0; |
| 5659 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5660 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5661 | static int bnx2x_init_port(struct bnx2x *bp) |
| 5662 | { |
| 5663 | int port = BP_PORT(bp); |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5664 | u32 low, high; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5665 | u32 val; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5666 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5667 | DP(BNX2X_MSG_MCP, "starting port init port %x\n", port); |
| 5668 | |
| 5669 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5670 | |
| 5671 | /* Port PXP comes here */ |
| 5672 | /* Port PXP2 comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5673 | #ifdef BCM_ISCSI |
| 5674 | /* Port0 1 |
| 5675 | * Port1 385 */ |
| 5676 | i++; |
| 5677 | wb_write[0] = ONCHIP_ADDR1(bp->timers_mapping); |
| 5678 | wb_write[1] = ONCHIP_ADDR2(bp->timers_mapping); |
| 5679 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 5680 | REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i)); |
| 5681 | |
| 5682 | /* Port0 2 |
| 5683 | * Port1 386 */ |
| 5684 | i++; |
| 5685 | wb_write[0] = ONCHIP_ADDR1(bp->qm_mapping); |
| 5686 | wb_write[1] = ONCHIP_ADDR2(bp->qm_mapping); |
| 5687 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 5688 | REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i)); |
| 5689 | |
| 5690 | /* Port0 3 |
| 5691 | * Port1 387 */ |
| 5692 | i++; |
| 5693 | wb_write[0] = ONCHIP_ADDR1(bp->t1_mapping); |
| 5694 | wb_write[1] = ONCHIP_ADDR2(bp->t1_mapping); |
| 5695 | REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2); |
| 5696 | REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i)); |
| 5697 | #endif |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5698 | /* Port CMs come here */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 5699 | bnx2x_init_block(bp, (port ? XCM_PORT1_START : XCM_PORT0_START), |
| 5700 | (port ? XCM_PORT1_END : XCM_PORT0_END)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5701 | |
| 5702 | /* Port QM comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5703 | #ifdef BCM_ISCSI |
| 5704 | REG_WR(bp, TM_REG_LIN0_SCAN_TIME + func*4, 1024/64*20); |
| 5705 | REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + func*4, 31); |
| 5706 | |
| 5707 | bnx2x_init_block(bp, func ? TIMERS_PORT1_START : TIMERS_PORT0_START, |
| 5708 | func ? TIMERS_PORT1_END : TIMERS_PORT0_END); |
| 5709 | #endif |
| 5710 | /* Port DQ comes here */ |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5711 | |
| 5712 | bnx2x_init_block(bp, (port ? BRB1_PORT1_START : BRB1_PORT0_START), |
| 5713 | (port ? BRB1_PORT1_END : BRB1_PORT0_END)); |
| 5714 | if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) { |
| 5715 | /* no pause for emulation and FPGA */ |
| 5716 | low = 0; |
| 5717 | high = 513; |
| 5718 | } else { |
| 5719 | if (IS_E1HMF(bp)) |
| 5720 | low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246); |
| 5721 | else if (bp->dev->mtu > 4096) { |
| 5722 | if (bp->flags & ONE_PORT_FLAG) |
| 5723 | low = 160; |
| 5724 | else { |
| 5725 | val = bp->dev->mtu; |
| 5726 | /* (24*1024 + val*4)/256 */ |
| 5727 | low = 96 + (val/64) + ((val % 64) ? 1 : 0); |
| 5728 | } |
| 5729 | } else |
| 5730 | low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160); |
| 5731 | high = low + 56; /* 14*1024/256 */ |
| 5732 | } |
| 5733 | REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low); |
| 5734 | REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high); |
| 5735 | |
| 5736 | |
Eilon Greenstein | ad8d394 | 2008-06-23 20:29:02 -0700 | [diff] [blame] | 5737 | /* Port PRS comes here */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5738 | /* Port TSDM comes here */ |
| 5739 | /* Port CSDM comes here */ |
| 5740 | /* Port USDM comes here */ |
| 5741 | /* Port XSDM comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5742 | bnx2x_init_block(bp, port ? TSEM_PORT1_START : TSEM_PORT0_START, |
| 5743 | port ? TSEM_PORT1_END : TSEM_PORT0_END); |
| 5744 | bnx2x_init_block(bp, port ? USEM_PORT1_START : USEM_PORT0_START, |
| 5745 | port ? USEM_PORT1_END : USEM_PORT0_END); |
| 5746 | bnx2x_init_block(bp, port ? CSEM_PORT1_START : CSEM_PORT0_START, |
| 5747 | port ? CSEM_PORT1_END : CSEM_PORT0_END); |
| 5748 | bnx2x_init_block(bp, port ? XSEM_PORT1_START : XSEM_PORT0_START, |
| 5749 | port ? XSEM_PORT1_END : XSEM_PORT0_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5750 | /* Port UPB comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5751 | /* Port XPB comes here */ |
| 5752 | |
| 5753 | bnx2x_init_block(bp, port ? PBF_PORT1_START : PBF_PORT0_START, |
| 5754 | port ? PBF_PORT1_END : PBF_PORT0_END); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5755 | |
| 5756 | /* configure PBF to work without PAUSE mtu 9000 */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5757 | REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5758 | |
| 5759 | /* update threshold */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5760 | REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5761 | /* update init credit */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5762 | REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5763 | |
| 5764 | /* probe changes */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5765 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5766 | msleep(5); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5767 | REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5768 | |
| 5769 | #ifdef BCM_ISCSI |
| 5770 | /* tell the searcher where the T2 table is */ |
| 5771 | REG_WR(bp, SRC_REG_COUNTFREE0 + func*4, 16*1024/64); |
| 5772 | |
| 5773 | wb_write[0] = U64_LO(bp->t2_mapping); |
| 5774 | wb_write[1] = U64_HI(bp->t2_mapping); |
| 5775 | REG_WR_DMAE(bp, SRC_REG_FIRSTFREE0 + func*4, wb_write, 2); |
| 5776 | wb_write[0] = U64_LO((u64)bp->t2_mapping + 16*1024 - 64); |
| 5777 | wb_write[1] = U64_HI((u64)bp->t2_mapping + 16*1024 - 64); |
| 5778 | REG_WR_DMAE(bp, SRC_REG_LASTFREE0 + func*4, wb_write, 2); |
| 5779 | |
| 5780 | REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + func*4, 10); |
| 5781 | /* Port SRCH comes here */ |
| 5782 | #endif |
| 5783 | /* Port CDU comes here */ |
| 5784 | /* Port CFC comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5785 | |
| 5786 | if (CHIP_IS_E1(bp)) { |
| 5787 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 5788 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 5789 | } |
| 5790 | bnx2x_init_block(bp, port ? HC_PORT1_START : HC_PORT0_START, |
| 5791 | port ? HC_PORT1_END : HC_PORT0_END); |
| 5792 | |
| 5793 | bnx2x_init_block(bp, port ? MISC_AEU_PORT1_START : |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5794 | MISC_AEU_PORT0_START, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5795 | port ? MISC_AEU_PORT1_END : MISC_AEU_PORT0_END); |
| 5796 | /* init aeu_mask_attn_func_0/1: |
| 5797 | * - SF mode: bits 3-7 are masked. only bits 0-2 are in use |
| 5798 | * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF |
| 5799 | * bits 4-7 are used for "per vn group attention" */ |
| 5800 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, |
| 5801 | (IS_E1HMF(bp) ? 0xF7 : 0x7)); |
| 5802 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5803 | /* Port PXPCS comes here */ |
| 5804 | /* Port EMAC0 comes here */ |
| 5805 | /* Port EMAC1 comes here */ |
| 5806 | /* Port DBU comes here */ |
| 5807 | /* Port DBG comes here */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5808 | bnx2x_init_block(bp, port ? NIG_PORT1_START : NIG_PORT0_START, |
| 5809 | port ? NIG_PORT1_END : NIG_PORT0_END); |
| 5810 | |
| 5811 | REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1); |
| 5812 | |
| 5813 | if (CHIP_IS_E1H(bp)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5814 | /* 0x2 disable e1hov, 0x1 enable */ |
| 5815 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4, |
| 5816 | (IS_E1HMF(bp) ? 0x1 : 0x2)); |
| 5817 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 5818 | /* support pause requests from USDM, TSDM and BRB */ |
| 5819 | REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0 + port*4, 0x7); |
| 5820 | |
| 5821 | { |
| 5822 | REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0); |
| 5823 | REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0); |
| 5824 | REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1); |
| 5825 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5826 | } |
| 5827 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5828 | /* Port MCP comes here */ |
| 5829 | /* Port DMAE comes here */ |
| 5830 | |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 5831 | switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) { |
| 5832 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5833 | /* add SPIO 5 to group 0 */ |
| 5834 | val = REG_RD(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0); |
| 5835 | val |= AEU_INPUTS_ATTN_BITS_SPIO5; |
| 5836 | REG_WR(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0, val); |
| 5837 | break; |
| 5838 | |
| 5839 | default: |
| 5840 | break; |
| 5841 | } |
| 5842 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 5843 | bnx2x__link_reset(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5844 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5845 | return 0; |
| 5846 | } |
| 5847 | |
| 5848 | #define ILT_PER_FUNC (768/2) |
| 5849 | #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC) |
| 5850 | /* the phys address is shifted right 12 bits and has an added |
| 5851 | 1=valid bit added to the 53rd bit |
| 5852 | then since this is a wide register(TM) |
| 5853 | we split it into two 32 bit writes |
| 5854 | */ |
| 5855 | #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF)) |
| 5856 | #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44))) |
| 5857 | #define PXP_ONE_ILT(x) (((x) << 10) | x) |
| 5858 | #define PXP_ILT_RANGE(f, l) (((l) << 10) | f) |
| 5859 | |
| 5860 | #define CNIC_ILT_LINES 0 |
| 5861 | |
| 5862 | static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr) |
| 5863 | { |
| 5864 | int reg; |
| 5865 | |
| 5866 | if (CHIP_IS_E1H(bp)) |
| 5867 | reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8; |
| 5868 | else /* E1 */ |
| 5869 | reg = PXP2_REG_RQ_ONCHIP_AT + index*8; |
| 5870 | |
| 5871 | bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr)); |
| 5872 | } |
| 5873 | |
| 5874 | static int bnx2x_init_func(struct bnx2x *bp) |
| 5875 | { |
| 5876 | int port = BP_PORT(bp); |
| 5877 | int func = BP_FUNC(bp); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 5878 | u32 addr, val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5879 | int i; |
| 5880 | |
| 5881 | DP(BNX2X_MSG_MCP, "starting func init func %x\n", func); |
| 5882 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 5883 | /* set MSI reconfigure capability */ |
| 5884 | addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0); |
| 5885 | val = REG_RD(bp, addr); |
| 5886 | val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0; |
| 5887 | REG_WR(bp, addr, val); |
| 5888 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5889 | i = FUNC_ILT_BASE(func); |
| 5890 | |
| 5891 | bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context)); |
| 5892 | if (CHIP_IS_E1H(bp)) { |
| 5893 | REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i); |
| 5894 | REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES); |
| 5895 | } else /* E1 */ |
| 5896 | REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4, |
| 5897 | PXP_ILT_RANGE(i, i + CNIC_ILT_LINES)); |
| 5898 | |
| 5899 | |
| 5900 | if (CHIP_IS_E1H(bp)) { |
| 5901 | for (i = 0; i < 9; i++) |
| 5902 | bnx2x_init_block(bp, |
| 5903 | cm_start[func][i], cm_end[func][i]); |
| 5904 | |
| 5905 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1); |
| 5906 | REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov); |
| 5907 | } |
| 5908 | |
| 5909 | /* HC init per function */ |
| 5910 | if (CHIP_IS_E1H(bp)) { |
| 5911 | REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0); |
| 5912 | |
| 5913 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 5914 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 5915 | } |
| 5916 | bnx2x_init_block(bp, hc_limits[func][0], hc_limits[func][1]); |
| 5917 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 5918 | /* Reset PCIE errors for debug */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5919 | REG_WR(bp, 0x2114, 0xffffffff); |
| 5920 | REG_WR(bp, 0x2120, 0xffffffff); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5921 | |
| 5922 | return 0; |
| 5923 | } |
| 5924 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5925 | static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code) |
| 5926 | { |
| 5927 | int i, rc = 0; |
| 5928 | |
| 5929 | DP(BNX2X_MSG_MCP, "function %d load_code %x\n", |
| 5930 | BP_FUNC(bp), load_code); |
| 5931 | |
| 5932 | bp->dmae_ready = 0; |
| 5933 | mutex_init(&bp->dmae_mutex); |
| 5934 | bnx2x_gunzip_init(bp); |
| 5935 | |
| 5936 | switch (load_code) { |
| 5937 | case FW_MSG_CODE_DRV_LOAD_COMMON: |
| 5938 | rc = bnx2x_init_common(bp); |
| 5939 | if (rc) |
| 5940 | goto init_hw_err; |
| 5941 | /* no break */ |
| 5942 | |
| 5943 | case FW_MSG_CODE_DRV_LOAD_PORT: |
| 5944 | bp->dmae_ready = 1; |
| 5945 | rc = bnx2x_init_port(bp); |
| 5946 | if (rc) |
| 5947 | goto init_hw_err; |
| 5948 | /* no break */ |
| 5949 | |
| 5950 | case FW_MSG_CODE_DRV_LOAD_FUNCTION: |
| 5951 | bp->dmae_ready = 1; |
| 5952 | rc = bnx2x_init_func(bp); |
| 5953 | if (rc) |
| 5954 | goto init_hw_err; |
| 5955 | break; |
| 5956 | |
| 5957 | default: |
| 5958 | BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code); |
| 5959 | break; |
| 5960 | } |
| 5961 | |
| 5962 | if (!BP_NOMCP(bp)) { |
| 5963 | int func = BP_FUNC(bp); |
| 5964 | |
| 5965 | bp->fw_drv_pulse_wr_seq = |
| 5966 | (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) & |
| 5967 | DRV_PULSE_SEQ_MASK); |
| 5968 | bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param); |
| 5969 | DP(BNX2X_MSG_MCP, "drv_pulse 0x%x func_stx 0x%x\n", |
| 5970 | bp->fw_drv_pulse_wr_seq, bp->func_stx); |
| 5971 | } else |
| 5972 | bp->func_stx = 0; |
| 5973 | |
| 5974 | /* this needs to be done before gunzip end */ |
| 5975 | bnx2x_zero_def_sb(bp); |
| 5976 | for_each_queue(bp, i) |
| 5977 | bnx2x_zero_sb(bp, BP_L_ID(bp) + i); |
| 5978 | |
| 5979 | init_hw_err: |
| 5980 | bnx2x_gunzip_end(bp); |
| 5981 | |
| 5982 | return rc; |
| 5983 | } |
| 5984 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 5985 | /* send the MCP a request, block until there is a reply */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5986 | static u32 bnx2x_fw_command(struct bnx2x *bp, u32 command) |
| 5987 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5988 | int func = BP_FUNC(bp); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5989 | u32 seq = ++bp->fw_seq; |
| 5990 | u32 rc = 0; |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 5991 | u32 cnt = 1; |
| 5992 | u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5993 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 5994 | SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq)); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 5995 | DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 5996 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 5997 | do { |
| 5998 | /* let the FW do it's magic ... */ |
| 5999 | msleep(delay); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6000 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 6001 | rc = SHMEM_RD(bp, func_mb[func].fw_mb_header); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6002 | |
Eilon Greenstein | 19680c4 | 2008-08-13 15:47:33 -0700 | [diff] [blame] | 6003 | /* Give the FW up to 2 second (200*10ms) */ |
| 6004 | } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 200)); |
| 6005 | |
| 6006 | DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n", |
| 6007 | cnt*delay, rc, seq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6008 | |
| 6009 | /* is this a reply to our command? */ |
| 6010 | if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) { |
| 6011 | rc &= FW_MSG_CODE_MASK; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6012 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6013 | } else { |
| 6014 | /* FW BUG! */ |
| 6015 | BNX2X_ERR("FW failed to respond!\n"); |
| 6016 | bnx2x_fw_dump(bp); |
| 6017 | rc = 0; |
| 6018 | } |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 6019 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6020 | return rc; |
| 6021 | } |
| 6022 | |
| 6023 | static void bnx2x_free_mem(struct bnx2x *bp) |
| 6024 | { |
| 6025 | |
| 6026 | #define BNX2X_PCI_FREE(x, y, size) \ |
| 6027 | do { \ |
| 6028 | if (x) { \ |
| 6029 | pci_free_consistent(bp->pdev, size, x, y); \ |
| 6030 | x = NULL; \ |
| 6031 | y = 0; \ |
| 6032 | } \ |
| 6033 | } while (0) |
| 6034 | |
| 6035 | #define BNX2X_FREE(x) \ |
| 6036 | do { \ |
| 6037 | if (x) { \ |
| 6038 | vfree(x); \ |
| 6039 | x = NULL; \ |
| 6040 | } \ |
| 6041 | } while (0) |
| 6042 | |
| 6043 | int i; |
| 6044 | |
| 6045 | /* fastpath */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6046 | /* Common */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6047 | for_each_queue(bp, i) { |
| 6048 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6049 | /* status blocks */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6050 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk), |
| 6051 | bnx2x_fp(bp, i, status_blk_mapping), |
| 6052 | sizeof(struct host_status_block) + |
| 6053 | sizeof(struct eth_tx_db_data)); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6054 | } |
| 6055 | /* Rx */ |
| 6056 | for_each_rx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6057 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6058 | /* fastpath rx rings: rx_buf rx_desc rx_comp */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6059 | BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring)); |
| 6060 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring), |
| 6061 | bnx2x_fp(bp, i, rx_desc_mapping), |
| 6062 | sizeof(struct eth_rx_bd) * NUM_RX_BD); |
| 6063 | |
| 6064 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring), |
| 6065 | bnx2x_fp(bp, i, rx_comp_mapping), |
| 6066 | sizeof(struct eth_fast_path_rx_cqe) * |
| 6067 | NUM_RCQ_BD); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6068 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6069 | /* SGE ring */ |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 6070 | BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring)); |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6071 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring), |
| 6072 | bnx2x_fp(bp, i, rx_sge_mapping), |
| 6073 | BCM_PAGE_SIZE * NUM_RX_SGE_PAGES); |
| 6074 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6075 | /* Tx */ |
| 6076 | for_each_tx_queue(bp, i) { |
| 6077 | |
| 6078 | /* fastpath tx rings: tx_buf tx_desc */ |
| 6079 | BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring)); |
| 6080 | BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring), |
| 6081 | bnx2x_fp(bp, i, tx_desc_mapping), |
| 6082 | sizeof(struct eth_tx_bd) * NUM_TX_BD); |
| 6083 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6084 | /* end of fastpath */ |
| 6085 | |
| 6086 | BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6087 | sizeof(struct host_def_status_block)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6088 | |
| 6089 | BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6090 | sizeof(struct bnx2x_slowpath)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6091 | |
| 6092 | #ifdef BCM_ISCSI |
| 6093 | BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024); |
| 6094 | BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024); |
| 6095 | BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024); |
| 6096 | BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024); |
| 6097 | #endif |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6098 | BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6099 | |
| 6100 | #undef BNX2X_PCI_FREE |
| 6101 | #undef BNX2X_KFREE |
| 6102 | } |
| 6103 | |
| 6104 | static int bnx2x_alloc_mem(struct bnx2x *bp) |
| 6105 | { |
| 6106 | |
| 6107 | #define BNX2X_PCI_ALLOC(x, y, size) \ |
| 6108 | do { \ |
| 6109 | x = pci_alloc_consistent(bp->pdev, size, y); \ |
| 6110 | if (x == NULL) \ |
| 6111 | goto alloc_mem_err; \ |
| 6112 | memset(x, 0, size); \ |
| 6113 | } while (0) |
| 6114 | |
| 6115 | #define BNX2X_ALLOC(x, size) \ |
| 6116 | do { \ |
| 6117 | x = vmalloc(size); \ |
| 6118 | if (x == NULL) \ |
| 6119 | goto alloc_mem_err; \ |
| 6120 | memset(x, 0, size); \ |
| 6121 | } while (0) |
| 6122 | |
| 6123 | int i; |
| 6124 | |
| 6125 | /* fastpath */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6126 | /* Common */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6127 | for_each_queue(bp, i) { |
| 6128 | bnx2x_fp(bp, i, bp) = bp; |
| 6129 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6130 | /* status blocks */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6131 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk), |
| 6132 | &bnx2x_fp(bp, i, status_blk_mapping), |
| 6133 | sizeof(struct host_status_block) + |
| 6134 | sizeof(struct eth_tx_db_data)); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6135 | } |
| 6136 | /* Rx */ |
| 6137 | for_each_rx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6138 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6139 | /* fastpath rx rings: rx_buf rx_desc rx_comp */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6140 | BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring), |
| 6141 | sizeof(struct sw_rx_bd) * NUM_RX_BD); |
| 6142 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring), |
| 6143 | &bnx2x_fp(bp, i, rx_desc_mapping), |
| 6144 | sizeof(struct eth_rx_bd) * NUM_RX_BD); |
| 6145 | |
| 6146 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring), |
| 6147 | &bnx2x_fp(bp, i, rx_comp_mapping), |
| 6148 | sizeof(struct eth_fast_path_rx_cqe) * |
| 6149 | NUM_RCQ_BD); |
| 6150 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6151 | /* SGE ring */ |
| 6152 | BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring), |
| 6153 | sizeof(struct sw_rx_page) * NUM_RX_SGE); |
| 6154 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring), |
| 6155 | &bnx2x_fp(bp, i, rx_sge_mapping), |
| 6156 | BCM_PAGE_SIZE * NUM_RX_SGE_PAGES); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6157 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6158 | /* Tx */ |
| 6159 | for_each_tx_queue(bp, i) { |
| 6160 | |
| 6161 | bnx2x_fp(bp, i, hw_tx_prods) = |
| 6162 | (void *)(bnx2x_fp(bp, i, status_blk) + 1); |
| 6163 | |
| 6164 | bnx2x_fp(bp, i, tx_prods_mapping) = |
| 6165 | bnx2x_fp(bp, i, status_blk_mapping) + |
| 6166 | sizeof(struct host_status_block); |
| 6167 | |
| 6168 | /* fastpath tx rings: tx_buf tx_desc */ |
| 6169 | BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring), |
| 6170 | sizeof(struct sw_tx_bd) * NUM_TX_BD); |
| 6171 | BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring), |
| 6172 | &bnx2x_fp(bp, i, tx_desc_mapping), |
| 6173 | sizeof(struct eth_tx_bd) * NUM_TX_BD); |
| 6174 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6175 | /* end of fastpath */ |
| 6176 | |
| 6177 | BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping, |
| 6178 | sizeof(struct host_def_status_block)); |
| 6179 | |
| 6180 | BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping, |
| 6181 | sizeof(struct bnx2x_slowpath)); |
| 6182 | |
| 6183 | #ifdef BCM_ISCSI |
| 6184 | BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024); |
| 6185 | |
| 6186 | /* Initialize T1 */ |
| 6187 | for (i = 0; i < 64*1024; i += 64) { |
| 6188 | *(u64 *)((char *)bp->t1 + i + 56) = 0x0UL; |
| 6189 | *(u64 *)((char *)bp->t1 + i + 3) = 0x0UL; |
| 6190 | } |
| 6191 | |
| 6192 | /* allocate searcher T2 table |
| 6193 | we allocate 1/4 of alloc num for T2 |
| 6194 | (which is not entered into the ILT) */ |
| 6195 | BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024); |
| 6196 | |
| 6197 | /* Initialize T2 */ |
| 6198 | for (i = 0; i < 16*1024; i += 64) |
| 6199 | * (u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64; |
| 6200 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6201 | /* now fixup the last line in the block to point to the next block */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6202 | *(u64 *)((char *)bp->t2 + 1024*16-8) = bp->t2_mapping; |
| 6203 | |
| 6204 | /* Timer block array (MAX_CONN*8) phys uncached for now 1024 conns */ |
| 6205 | BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024); |
| 6206 | |
| 6207 | /* QM queues (128*MAX_CONN) */ |
| 6208 | BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024); |
| 6209 | #endif |
| 6210 | |
| 6211 | /* Slow path ring */ |
| 6212 | BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE); |
| 6213 | |
| 6214 | return 0; |
| 6215 | |
| 6216 | alloc_mem_err: |
| 6217 | bnx2x_free_mem(bp); |
| 6218 | return -ENOMEM; |
| 6219 | |
| 6220 | #undef BNX2X_PCI_ALLOC |
| 6221 | #undef BNX2X_ALLOC |
| 6222 | } |
| 6223 | |
| 6224 | static void bnx2x_free_tx_skbs(struct bnx2x *bp) |
| 6225 | { |
| 6226 | int i; |
| 6227 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6228 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6229 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6230 | |
| 6231 | u16 bd_cons = fp->tx_bd_cons; |
| 6232 | u16 sw_prod = fp->tx_pkt_prod; |
| 6233 | u16 sw_cons = fp->tx_pkt_cons; |
| 6234 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6235 | while (sw_cons != sw_prod) { |
| 6236 | bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons)); |
| 6237 | sw_cons++; |
| 6238 | } |
| 6239 | } |
| 6240 | } |
| 6241 | |
| 6242 | static void bnx2x_free_rx_skbs(struct bnx2x *bp) |
| 6243 | { |
| 6244 | int i, j; |
| 6245 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6246 | for_each_rx_queue(bp, j) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6247 | struct bnx2x_fastpath *fp = &bp->fp[j]; |
| 6248 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6249 | for (i = 0; i < NUM_RX_BD; i++) { |
| 6250 | struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i]; |
| 6251 | struct sk_buff *skb = rx_buf->skb; |
| 6252 | |
| 6253 | if (skb == NULL) |
| 6254 | continue; |
| 6255 | |
| 6256 | pci_unmap_single(bp->pdev, |
| 6257 | pci_unmap_addr(rx_buf, mapping), |
Eilon Greenstein | 437cf2f | 2008-09-03 14:38:00 -0700 | [diff] [blame] | 6258 | bp->rx_buf_size, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6259 | PCI_DMA_FROMDEVICE); |
| 6260 | |
| 6261 | rx_buf->skb = NULL; |
| 6262 | dev_kfree_skb(skb); |
| 6263 | } |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6264 | if (!fp->disable_tpa) |
Eilon Greenstein | 3262623 | 2008-08-13 15:51:07 -0700 | [diff] [blame] | 6265 | bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ? |
| 6266 | ETH_MAX_AGGREGATION_QUEUES_E1 : |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6267 | ETH_MAX_AGGREGATION_QUEUES_E1H); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6268 | } |
| 6269 | } |
| 6270 | |
| 6271 | static void bnx2x_free_skbs(struct bnx2x *bp) |
| 6272 | { |
| 6273 | bnx2x_free_tx_skbs(bp); |
| 6274 | bnx2x_free_rx_skbs(bp); |
| 6275 | } |
| 6276 | |
| 6277 | static void bnx2x_free_msix_irqs(struct bnx2x *bp) |
| 6278 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6279 | int i, offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6280 | |
| 6281 | free_irq(bp->msix_table[0].vector, bp->dev); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6282 | DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6283 | bp->msix_table[0].vector); |
| 6284 | |
| 6285 | for_each_queue(bp, i) { |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6286 | DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq " |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6287 | "state %x\n", i, bp->msix_table[i + offset].vector, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6288 | bnx2x_fp(bp, i, state)); |
| 6289 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6290 | free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6291 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | static void bnx2x_free_irq(struct bnx2x *bp) |
| 6295 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6296 | if (bp->flags & USING_MSIX_FLAG) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6297 | bnx2x_free_msix_irqs(bp); |
| 6298 | pci_disable_msix(bp->pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6299 | bp->flags &= ~USING_MSIX_FLAG; |
| 6300 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6301 | } else if (bp->flags & USING_MSI_FLAG) { |
| 6302 | free_irq(bp->pdev->irq, bp->dev); |
| 6303 | pci_disable_msi(bp->pdev); |
| 6304 | bp->flags &= ~USING_MSI_FLAG; |
| 6305 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6306 | } else |
| 6307 | free_irq(bp->pdev->irq, bp->dev); |
| 6308 | } |
| 6309 | |
| 6310 | static int bnx2x_enable_msix(struct bnx2x *bp) |
| 6311 | { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6312 | int i, rc, offset = 1; |
| 6313 | int igu_vec = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6314 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6315 | bp->msix_table[0].entry = igu_vec; |
| 6316 | DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n", igu_vec); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6317 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6318 | for_each_queue(bp, i) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6319 | igu_vec = BP_L_ID(bp) + offset + i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6320 | bp->msix_table[i + offset].entry = igu_vec; |
| 6321 | DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d " |
| 6322 | "(fastpath #%u)\n", i + offset, igu_vec, i); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6323 | } |
| 6324 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6325 | rc = pci_enable_msix(bp->pdev, &bp->msix_table[0], |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6326 | BNX2X_NUM_QUEUES(bp) + offset); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6327 | if (rc) { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6328 | DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc); |
| 6329 | return rc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6330 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6331 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6332 | bp->flags |= USING_MSIX_FLAG; |
| 6333 | |
| 6334 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6335 | } |
| 6336 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6337 | static int bnx2x_req_msix_irqs(struct bnx2x *bp) |
| 6338 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6339 | int i, rc, offset = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6340 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6341 | rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0, |
| 6342 | bp->dev->name, bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6343 | if (rc) { |
| 6344 | BNX2X_ERR("request sp irq failed\n"); |
| 6345 | return -EBUSY; |
| 6346 | } |
| 6347 | |
| 6348 | for_each_queue(bp, i) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6349 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6350 | |
| 6351 | sprintf(fp->name, "%s.fp%d", bp->dev->name, i); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6352 | rc = request_irq(bp->msix_table[i + offset].vector, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6353 | bnx2x_msix_fp_int, 0, fp->name, fp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6354 | if (rc) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6355 | BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6356 | bnx2x_free_msix_irqs(bp); |
| 6357 | return -EBUSY; |
| 6358 | } |
| 6359 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6360 | fp->state = BNX2X_FP_STATE_IRQ; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6361 | } |
| 6362 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6363 | i = BNX2X_NUM_QUEUES(bp); |
| 6364 | if (is_multi(bp)) |
| 6365 | printk(KERN_INFO PFX |
| 6366 | "%s: using MSI-X IRQs: sp %d fp %d - %d\n", |
| 6367 | bp->dev->name, bp->msix_table[0].vector, |
| 6368 | bp->msix_table[offset].vector, |
| 6369 | bp->msix_table[offset + i - 1].vector); |
| 6370 | else |
| 6371 | printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp %d\n", |
| 6372 | bp->dev->name, bp->msix_table[0].vector, |
| 6373 | bp->msix_table[offset + i - 1].vector); |
| 6374 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6375 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6376 | } |
| 6377 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6378 | static int bnx2x_enable_msi(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6379 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6380 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6381 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6382 | rc = pci_enable_msi(bp->pdev); |
| 6383 | if (rc) { |
| 6384 | DP(NETIF_MSG_IFUP, "MSI is not attainable\n"); |
| 6385 | return -1; |
| 6386 | } |
| 6387 | bp->flags |= USING_MSI_FLAG; |
| 6388 | |
| 6389 | return 0; |
| 6390 | } |
| 6391 | |
| 6392 | static int bnx2x_req_irq(struct bnx2x *bp) |
| 6393 | { |
| 6394 | unsigned long flags; |
| 6395 | int rc; |
| 6396 | |
| 6397 | if (bp->flags & USING_MSI_FLAG) |
| 6398 | flags = 0; |
| 6399 | else |
| 6400 | flags = IRQF_SHARED; |
| 6401 | |
| 6402 | rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6403 | bp->dev->name, bp->dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6404 | if (!rc) |
| 6405 | bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ; |
| 6406 | |
| 6407 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6408 | } |
| 6409 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6410 | static void bnx2x_napi_enable(struct bnx2x *bp) |
| 6411 | { |
| 6412 | int i; |
| 6413 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6414 | for_each_rx_queue(bp, i) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6415 | napi_enable(&bnx2x_fp(bp, i, napi)); |
| 6416 | } |
| 6417 | |
| 6418 | static void bnx2x_napi_disable(struct bnx2x *bp) |
| 6419 | { |
| 6420 | int i; |
| 6421 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6422 | for_each_rx_queue(bp, i) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6423 | napi_disable(&bnx2x_fp(bp, i, napi)); |
| 6424 | } |
| 6425 | |
| 6426 | static void bnx2x_netif_start(struct bnx2x *bp) |
| 6427 | { |
| 6428 | if (atomic_dec_and_test(&bp->intr_sem)) { |
| 6429 | if (netif_running(bp->dev)) { |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6430 | bnx2x_napi_enable(bp); |
| 6431 | bnx2x_int_enable(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6432 | if (bp->state == BNX2X_STATE_OPEN) |
| 6433 | netif_tx_wake_all_queues(bp->dev); |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6434 | } |
| 6435 | } |
| 6436 | } |
| 6437 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 6438 | static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6439 | { |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 6440 | bnx2x_int_disable_sync(bp, disable_hw); |
Eilon Greenstein | e94d8af | 2009-01-22 03:37:36 +0000 | [diff] [blame] | 6441 | bnx2x_napi_disable(bp); |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6442 | if (netif_running(bp->dev)) { |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 6443 | netif_tx_disable(bp->dev); |
| 6444 | bp->dev->trans_start = jiffies; /* prevent tx timeout */ |
| 6445 | } |
| 6446 | } |
| 6447 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6448 | /* |
| 6449 | * Init service functions |
| 6450 | */ |
| 6451 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6452 | static void bnx2x_set_mac_addr_e1(struct bnx2x *bp, int set) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6453 | { |
| 6454 | struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6455 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6456 | |
| 6457 | /* CAM allocation |
| 6458 | * unicasts 0-31:port0 32-63:port1 |
| 6459 | * multicast 64-127:port0 128-191:port1 |
| 6460 | */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 6461 | config->hdr.length = 2; |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 6462 | config->hdr.offset = port ? 32 : 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6463 | config->hdr.client_id = BP_CL_ID(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6464 | config->hdr.reserved1 = 0; |
| 6465 | |
| 6466 | /* primary MAC */ |
| 6467 | config->config_table[0].cam_entry.msb_mac_addr = |
| 6468 | swab16(*(u16 *)&bp->dev->dev_addr[0]); |
| 6469 | config->config_table[0].cam_entry.middle_mac_addr = |
| 6470 | swab16(*(u16 *)&bp->dev->dev_addr[2]); |
| 6471 | config->config_table[0].cam_entry.lsb_mac_addr = |
| 6472 | swab16(*(u16 *)&bp->dev->dev_addr[4]); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6473 | config->config_table[0].cam_entry.flags = cpu_to_le16(port); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6474 | if (set) |
| 6475 | config->config_table[0].target_table_entry.flags = 0; |
| 6476 | else |
| 6477 | CAM_INVALIDATE(config->config_table[0]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6478 | config->config_table[0].target_table_entry.client_id = 0; |
| 6479 | config->config_table[0].target_table_entry.vlan_id = 0; |
| 6480 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6481 | DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n", |
| 6482 | (set ? "setting" : "clearing"), |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6483 | config->config_table[0].cam_entry.msb_mac_addr, |
| 6484 | config->config_table[0].cam_entry.middle_mac_addr, |
| 6485 | config->config_table[0].cam_entry.lsb_mac_addr); |
| 6486 | |
| 6487 | /* broadcast */ |
| 6488 | config->config_table[1].cam_entry.msb_mac_addr = 0xffff; |
| 6489 | config->config_table[1].cam_entry.middle_mac_addr = 0xffff; |
| 6490 | config->config_table[1].cam_entry.lsb_mac_addr = 0xffff; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6491 | config->config_table[1].cam_entry.flags = cpu_to_le16(port); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6492 | if (set) |
| 6493 | config->config_table[1].target_table_entry.flags = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6494 | TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST; |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6495 | else |
| 6496 | CAM_INVALIDATE(config->config_table[1]); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6497 | config->config_table[1].target_table_entry.client_id = 0; |
| 6498 | config->config_table[1].target_table_entry.vlan_id = 0; |
| 6499 | |
| 6500 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 6501 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 6502 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 6503 | } |
| 6504 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6505 | static void bnx2x_set_mac_addr_e1h(struct bnx2x *bp, int set) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6506 | { |
| 6507 | struct mac_configuration_cmd_e1h *config = |
| 6508 | (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config); |
| 6509 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6510 | if (set && (bp->state != BNX2X_STATE_OPEN)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6511 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 6512 | return; |
| 6513 | } |
| 6514 | |
| 6515 | /* CAM allocation for E1H |
| 6516 | * unicasts: by func number |
| 6517 | * multicast: 20+FUNC*20, 20 each |
| 6518 | */ |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 6519 | config->hdr.length = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6520 | config->hdr.offset = BP_FUNC(bp); |
| 6521 | config->hdr.client_id = BP_CL_ID(bp); |
| 6522 | config->hdr.reserved1 = 0; |
| 6523 | |
| 6524 | /* primary MAC */ |
| 6525 | config->config_table[0].msb_mac_addr = |
| 6526 | swab16(*(u16 *)&bp->dev->dev_addr[0]); |
| 6527 | config->config_table[0].middle_mac_addr = |
| 6528 | swab16(*(u16 *)&bp->dev->dev_addr[2]); |
| 6529 | config->config_table[0].lsb_mac_addr = |
| 6530 | swab16(*(u16 *)&bp->dev->dev_addr[4]); |
| 6531 | config->config_table[0].client_id = BP_L_ID(bp); |
| 6532 | config->config_table[0].vlan_id = 0; |
| 6533 | config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov); |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6534 | if (set) |
| 6535 | config->config_table[0].flags = BP_PORT(bp); |
| 6536 | else |
| 6537 | config->config_table[0].flags = |
| 6538 | MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6539 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6540 | DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID %d\n", |
| 6541 | (set ? "setting" : "clearing"), |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6542 | config->config_table[0].msb_mac_addr, |
| 6543 | config->config_table[0].middle_mac_addr, |
| 6544 | config->config_table[0].lsb_mac_addr, bp->e1hov, BP_L_ID(bp)); |
| 6545 | |
| 6546 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 6547 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 6548 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 6549 | } |
| 6550 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6551 | static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx, |
| 6552 | int *state_p, int poll) |
| 6553 | { |
| 6554 | /* can take a while if any port is running */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6555 | int cnt = 500; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6556 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6557 | DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n", |
| 6558 | poll ? "polling" : "waiting", state, idx); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6559 | |
| 6560 | might_sleep(); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6561 | while (cnt--) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6562 | if (poll) { |
| 6563 | bnx2x_rx_int(bp->fp, 10); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6564 | /* if index is different from 0 |
| 6565 | * the reply for some commands will |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6566 | * be on the non default queue |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6567 | */ |
| 6568 | if (idx) |
| 6569 | bnx2x_rx_int(&bp->fp[idx], 10); |
| 6570 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6571 | |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6572 | mb(); /* state is changed by bnx2x_sp_event() */ |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6573 | if (*state_p == state) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6574 | return 0; |
| 6575 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6576 | msleep(1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6577 | } |
| 6578 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6579 | /* timeout! */ |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6580 | BNX2X_ERR("timeout %s for state %x on IDX [%d]\n", |
| 6581 | poll ? "polling" : "waiting", state, idx); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6582 | #ifdef BNX2X_STOP_ON_ERROR |
| 6583 | bnx2x_panic(); |
| 6584 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6585 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6586 | return -EBUSY; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6587 | } |
| 6588 | |
| 6589 | static int bnx2x_setup_leading(struct bnx2x *bp) |
| 6590 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6591 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6592 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6593 | /* reset IGU state */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6594 | bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6595 | |
| 6596 | /* SETUP ramrod */ |
| 6597 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0); |
| 6598 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6599 | /* Wait for completion */ |
| 6600 | rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6601 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6602 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | static int bnx2x_setup_multi(struct bnx2x *bp, int index) |
| 6606 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6607 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
| 6608 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6609 | /* reset IGU state */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6610 | bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6611 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6612 | /* SETUP ramrod */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6613 | fp->state = BNX2X_FP_STATE_OPENING; |
| 6614 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0, |
| 6615 | fp->cl_id, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6616 | |
| 6617 | /* Wait for completion */ |
| 6618 | return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6619 | &(fp->state), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6620 | } |
| 6621 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6622 | static int bnx2x_poll(struct napi_struct *napi, int budget); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6623 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6624 | static void bnx2x_set_int_mode(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6625 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6626 | int num_queues; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6627 | |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6628 | switch (int_mode) { |
| 6629 | case INT_MODE_INTx: |
| 6630 | case INT_MODE_MSI: |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6631 | num_queues = 1; |
| 6632 | bp->num_rx_queues = num_queues; |
| 6633 | bp->num_tx_queues = num_queues; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6634 | DP(NETIF_MSG_IFUP, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6635 | "set number of queues to %d\n", num_queues); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6636 | break; |
| 6637 | |
| 6638 | case INT_MODE_MSIX: |
| 6639 | default: |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6640 | if (bp->multi_mode == ETH_RSS_MODE_REGULAR) |
| 6641 | num_queues = min_t(u32, num_online_cpus(), |
| 6642 | BNX2X_MAX_QUEUES(bp)); |
| 6643 | else |
| 6644 | num_queues = 1; |
| 6645 | bp->num_rx_queues = num_queues; |
| 6646 | bp->num_tx_queues = num_queues; |
| 6647 | DP(NETIF_MSG_IFUP, "set number of rx queues to %d" |
| 6648 | " number of tx queues to %d\n", |
| 6649 | bp->num_rx_queues, bp->num_tx_queues); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6650 | /* if we can't use MSI-X we only need one fp, |
| 6651 | * so try to enable MSI-X with the requested number of fp's |
| 6652 | * and fallback to MSI or legacy INTx with one fp |
| 6653 | */ |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6654 | if (bnx2x_enable_msix(bp)) { |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6655 | /* failed to enable MSI-X */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6656 | num_queues = 1; |
| 6657 | bp->num_rx_queues = num_queues; |
| 6658 | bp->num_tx_queues = num_queues; |
| 6659 | if (bp->multi_mode) |
| 6660 | BNX2X_ERR("Multi requested but failed to " |
| 6661 | "enable MSI-X set number of " |
| 6662 | "queues to %d\n", num_queues); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6663 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6664 | break; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6665 | } |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6666 | bp->dev->real_num_tx_queues = bp->num_tx_queues; |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6667 | } |
| 6668 | |
| 6669 | static void bnx2x_set_rx_mode(struct net_device *dev); |
| 6670 | |
| 6671 | /* must be called with rtnl_lock */ |
| 6672 | static int bnx2x_nic_load(struct bnx2x *bp, int load_mode) |
| 6673 | { |
| 6674 | u32 load_code; |
| 6675 | int i, rc = 0; |
| 6676 | #ifdef BNX2X_STOP_ON_ERROR |
| 6677 | DP(NETIF_MSG_IFUP, "enter load_mode %d\n", load_mode); |
| 6678 | if (unlikely(bp->panic)) |
| 6679 | return -EPERM; |
| 6680 | #endif |
| 6681 | |
| 6682 | bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD; |
| 6683 | |
| 6684 | bnx2x_set_int_mode(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6685 | |
| 6686 | if (bnx2x_alloc_mem(bp)) |
| 6687 | return -ENOMEM; |
| 6688 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6689 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6690 | bnx2x_fp(bp, i, disable_tpa) = |
| 6691 | ((bp->flags & TPA_ENABLE_FLAG) == 0); |
| 6692 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6693 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6694 | netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi), |
| 6695 | bnx2x_poll, 128); |
| 6696 | |
| 6697 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6698 | for_each_rx_queue(bp, i) { |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6699 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 6700 | |
| 6701 | fp->poll_no_work = 0; |
| 6702 | fp->poll_calls = 0; |
| 6703 | fp->poll_max_calls = 0; |
| 6704 | fp->poll_complete = 0; |
| 6705 | fp->poll_exit = 0; |
| 6706 | } |
| 6707 | #endif |
| 6708 | bnx2x_napi_enable(bp); |
| 6709 | |
| 6710 | if (bp->flags & USING_MSIX_FLAG) { |
| 6711 | rc = bnx2x_req_msix_irqs(bp); |
| 6712 | if (rc) { |
| 6713 | pci_disable_msix(bp->pdev); |
| 6714 | goto load_error1; |
| 6715 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6716 | } else { |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6717 | if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx)) |
| 6718 | bnx2x_enable_msi(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6719 | bnx2x_ack_int(bp); |
| 6720 | rc = bnx2x_req_irq(bp); |
| 6721 | if (rc) { |
| 6722 | BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc); |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6723 | if (bp->flags & USING_MSI_FLAG) |
| 6724 | pci_disable_msi(bp->pdev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6725 | goto load_error1; |
| 6726 | } |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 6727 | if (bp->flags & USING_MSI_FLAG) { |
| 6728 | bp->dev->irq = bp->pdev->irq; |
| 6729 | printk(KERN_INFO PFX "%s: using MSI IRQ %d\n", |
| 6730 | bp->dev->name, bp->pdev->irq); |
| 6731 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6732 | } |
| 6733 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6734 | /* Send LOAD_REQUEST command to MCP |
| 6735 | Returns the type of LOAD command: |
| 6736 | if it is the first port to be initialized |
| 6737 | common blocks should be initialized, otherwise - not |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6738 | */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6739 | if (!BP_NOMCP(bp)) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6740 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ); |
| 6741 | if (!load_code) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6742 | BNX2X_ERR("MCP response failure, aborting\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6743 | rc = -EBUSY; |
| 6744 | goto load_error2; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6745 | } |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6746 | if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) { |
| 6747 | rc = -EBUSY; /* other port in diagnostic mode */ |
| 6748 | goto load_error2; |
| 6749 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6750 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6751 | } else { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6752 | int port = BP_PORT(bp); |
| 6753 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6754 | DP(NETIF_MSG_IFUP, "NO MCP load counts before us %d, %d, %d\n", |
| 6755 | load_count[0], load_count[1], load_count[2]); |
| 6756 | load_count[0]++; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6757 | load_count[1 + port]++; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6758 | DP(NETIF_MSG_IFUP, "NO MCP new load counts %d, %d, %d\n", |
| 6759 | load_count[0], load_count[1], load_count[2]); |
| 6760 | if (load_count[0] == 1) |
| 6761 | load_code = FW_MSG_CODE_DRV_LOAD_COMMON; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6762 | else if (load_count[1 + port] == 1) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6763 | load_code = FW_MSG_CODE_DRV_LOAD_PORT; |
| 6764 | else |
| 6765 | load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6766 | } |
| 6767 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6768 | if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) || |
| 6769 | (load_code == FW_MSG_CODE_DRV_LOAD_PORT)) |
| 6770 | bp->port.pmf = 1; |
| 6771 | else |
| 6772 | bp->port.pmf = 0; |
| 6773 | DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf); |
| 6774 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6775 | /* Initialize HW */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6776 | rc = bnx2x_init_hw(bp, load_code); |
| 6777 | if (rc) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6778 | BNX2X_ERR("HW init failed, aborting\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6779 | goto load_error2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6780 | } |
| 6781 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6782 | /* Setup NIC internals and enable interrupts */ |
Eilon Greenstein | 471de71 | 2008-08-13 15:49:35 -0700 | [diff] [blame] | 6783 | bnx2x_nic_init(bp, load_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6784 | |
| 6785 | /* Send LOAD_DONE command to MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6786 | if (!BP_NOMCP(bp)) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6787 | load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE); |
| 6788 | if (!load_code) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6789 | BNX2X_ERR("MCP response failure, aborting\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6790 | rc = -EBUSY; |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6791 | goto load_error3; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6792 | } |
| 6793 | } |
| 6794 | |
| 6795 | bp->state = BNX2X_STATE_OPENING_WAIT4_PORT; |
| 6796 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6797 | rc = bnx2x_setup_leading(bp); |
| 6798 | if (rc) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6799 | BNX2X_ERR("Setup leading failed!\n"); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6800 | goto load_error3; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6801 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6802 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6803 | if (CHIP_IS_E1H(bp)) |
| 6804 | if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) { |
| 6805 | BNX2X_ERR("!!! mf_cfg function disabled\n"); |
| 6806 | bp->state = BNX2X_STATE_DISABLED; |
| 6807 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6808 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6809 | if (bp->state == BNX2X_STATE_OPEN) |
| 6810 | for_each_nondefault_queue(bp, i) { |
| 6811 | rc = bnx2x_setup_multi(bp, i); |
| 6812 | if (rc) |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6813 | goto load_error3; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6814 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6815 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6816 | if (CHIP_IS_E1(bp)) |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6817 | bnx2x_set_mac_addr_e1(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6818 | else |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 6819 | bnx2x_set_mac_addr_e1h(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6820 | |
| 6821 | if (bp->port.pmf) |
| 6822 | bnx2x_initial_phy_init(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6823 | |
| 6824 | /* Start fast path */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6825 | switch (load_mode) { |
| 6826 | case LOAD_NORMAL: |
| 6827 | /* Tx queue should be only reenabled */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6828 | netif_tx_wake_all_queues(bp->dev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6829 | /* Initialize the receive filter. */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6830 | bnx2x_set_rx_mode(bp->dev); |
| 6831 | break; |
| 6832 | |
| 6833 | case LOAD_OPEN: |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6834 | netif_tx_start_all_queues(bp->dev); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6835 | /* Initialize the receive filter. */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6836 | bnx2x_set_rx_mode(bp->dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6837 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6838 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6839 | case LOAD_DIAG: |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6840 | /* Initialize the receive filter. */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6841 | bnx2x_set_rx_mode(bp->dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6842 | bp->state = BNX2X_STATE_DIAG; |
| 6843 | break; |
| 6844 | |
| 6845 | default: |
| 6846 | break; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6847 | } |
| 6848 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6849 | if (!bp->port.pmf) |
| 6850 | bnx2x__link_status_update(bp); |
| 6851 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6852 | /* start the timer */ |
| 6853 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 6854 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6855 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6856 | return 0; |
| 6857 | |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6858 | load_error3: |
| 6859 | bnx2x_int_disable_sync(bp, 1); |
| 6860 | if (!BP_NOMCP(bp)) { |
| 6861 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP); |
| 6862 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 6863 | } |
| 6864 | bp->port.pmf = 0; |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 6865 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 6866 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6867 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 6868 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6869 | load_error2: |
Yitchak Gertner | d101463 | 2008-08-25 15:25:45 -0700 | [diff] [blame] | 6870 | /* Release IRQs */ |
| 6871 | bnx2x_free_irq(bp); |
Eilon Greenstein | 2dfe0e1 | 2009-01-22 03:37:44 +0000 | [diff] [blame] | 6872 | load_error1: |
| 6873 | bnx2x_napi_disable(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6874 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 6875 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6876 | bnx2x_free_mem(bp); |
| 6877 | |
| 6878 | /* TBD we really need to reset the chip |
| 6879 | if we want to recover from this */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6880 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6881 | } |
| 6882 | |
| 6883 | static int bnx2x_stop_multi(struct bnx2x *bp, int index) |
| 6884 | { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6885 | struct bnx2x_fastpath *fp = &bp->fp[index]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6886 | int rc; |
| 6887 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6888 | /* halt the connection */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6889 | fp->state = BNX2X_FP_STATE_HALTING; |
| 6890 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6891 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6892 | /* Wait for completion */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6893 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6894 | &(fp->state), 1); |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6895 | if (rc) /* timeout */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6896 | return rc; |
| 6897 | |
| 6898 | /* delete cfc entry */ |
| 6899 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1); |
| 6900 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6901 | /* Wait for completion */ |
| 6902 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 6903 | &(fp->state), 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6904 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6905 | } |
| 6906 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6907 | static int bnx2x_stop_leading(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6908 | { |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6909 | u16 dsb_sp_prod_idx; |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 6910 | /* if the other port is handling traffic, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6911 | this can take a lot of time */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6912 | int cnt = 500; |
| 6913 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6914 | |
| 6915 | might_sleep(); |
| 6916 | |
| 6917 | /* Send HALT ramrod */ |
| 6918 | bp->fp[0].state = BNX2X_FP_STATE_HALTING; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6919 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, BP_CL_ID(bp), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6920 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6921 | /* Wait for completion */ |
| 6922 | rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0, |
| 6923 | &(bp->fp[0].state), 1); |
| 6924 | if (rc) /* timeout */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6925 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6926 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6927 | dsb_sp_prod_idx = *bp->dsb_sp_prod; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6928 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 6929 | /* Send PORT_DELETE ramrod */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6930 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1); |
| 6931 | |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6932 | /* Wait for completion to arrive on default status block |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6933 | we are going to reset the chip anyway |
| 6934 | so there is not much to do if this times out |
| 6935 | */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6936 | while (dsb_sp_prod_idx == *bp->dsb_sp_prod) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6937 | if (!cnt) { |
| 6938 | DP(NETIF_MSG_IFDOWN, "timeout waiting for port del " |
| 6939 | "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n", |
| 6940 | *bp->dsb_sp_prod, dsb_sp_prod_idx); |
| 6941 | #ifdef BNX2X_STOP_ON_ERROR |
| 6942 | bnx2x_panic(); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6943 | #else |
| 6944 | rc = -EBUSY; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6945 | #endif |
| 6946 | break; |
| 6947 | } |
| 6948 | cnt--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6949 | msleep(1); |
Eilon Greenstein | 5650d9d | 2009-01-22 06:01:29 +0000 | [diff] [blame] | 6950 | rmb(); /* Refresh the dsb_sp_prod */ |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6951 | } |
| 6952 | bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD; |
| 6953 | bp->fp[0].state = BNX2X_FP_STATE_CLOSED; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 6954 | |
| 6955 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 6956 | } |
| 6957 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6958 | static void bnx2x_reset_func(struct bnx2x *bp) |
| 6959 | { |
| 6960 | int port = BP_PORT(bp); |
| 6961 | int func = BP_FUNC(bp); |
| 6962 | int base, i; |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 6963 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6964 | /* Configure IGU */ |
| 6965 | REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0); |
| 6966 | REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0); |
| 6967 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6968 | /* Clear ILT */ |
| 6969 | base = FUNC_ILT_BASE(func); |
| 6970 | for (i = base; i < base + ILT_PER_FUNC; i++) |
| 6971 | bnx2x_ilt_wr(bp, i, 0); |
| 6972 | } |
| 6973 | |
| 6974 | static void bnx2x_reset_port(struct bnx2x *bp) |
| 6975 | { |
| 6976 | int port = BP_PORT(bp); |
| 6977 | u32 val; |
| 6978 | |
| 6979 | REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0); |
| 6980 | |
| 6981 | /* Do not rcv packets to BRB */ |
| 6982 | REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0); |
| 6983 | /* Do not direct rcv packets that are not for MCP to the BRB */ |
| 6984 | REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 6985 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 6986 | |
| 6987 | /* Configure AEU */ |
| 6988 | REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0); |
| 6989 | |
| 6990 | msleep(100); |
| 6991 | /* Check for BRB port occupancy */ |
| 6992 | val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4); |
| 6993 | if (val) |
| 6994 | DP(NETIF_MSG_IFDOWN, |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 6995 | "BRB1 is not empty %d blocks are occupied\n", val); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 6996 | |
| 6997 | /* TODO: Close Doorbell port? */ |
| 6998 | } |
| 6999 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7000 | static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code) |
| 7001 | { |
| 7002 | DP(BNX2X_MSG_MCP, "function %d reset_code %x\n", |
| 7003 | BP_FUNC(bp), reset_code); |
| 7004 | |
| 7005 | switch (reset_code) { |
| 7006 | case FW_MSG_CODE_DRV_UNLOAD_COMMON: |
| 7007 | bnx2x_reset_port(bp); |
| 7008 | bnx2x_reset_func(bp); |
| 7009 | bnx2x_reset_common(bp); |
| 7010 | break; |
| 7011 | |
| 7012 | case FW_MSG_CODE_DRV_UNLOAD_PORT: |
| 7013 | bnx2x_reset_port(bp); |
| 7014 | bnx2x_reset_func(bp); |
| 7015 | break; |
| 7016 | |
| 7017 | case FW_MSG_CODE_DRV_UNLOAD_FUNCTION: |
| 7018 | bnx2x_reset_func(bp); |
| 7019 | break; |
| 7020 | |
| 7021 | default: |
| 7022 | BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code); |
| 7023 | break; |
| 7024 | } |
| 7025 | } |
| 7026 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7027 | /* must be called with rtnl_lock */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7028 | static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7029 | { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7030 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7031 | u32 reset_code = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7032 | int i, cnt, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7033 | |
| 7034 | bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT; |
| 7035 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7036 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 7037 | bnx2x_set_storm_rx_mode(bp); |
| 7038 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 7039 | bnx2x_netif_stop(bp, 1); |
Eilon Greenstein | e94d8af | 2009-01-22 03:37:36 +0000 | [diff] [blame] | 7040 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7041 | del_timer_sync(&bp->timer); |
| 7042 | SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb, |
| 7043 | (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq)); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 7044 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7045 | |
Eilon Greenstein | 70b9986 | 2009-01-14 06:43:48 +0000 | [diff] [blame] | 7046 | /* Release IRQs */ |
| 7047 | bnx2x_free_irq(bp); |
| 7048 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7049 | /* Wait until tx fastpath tasks complete */ |
| 7050 | for_each_tx_queue(bp, i) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7051 | struct bnx2x_fastpath *fp = &bp->fp[i]; |
| 7052 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7053 | cnt = 1000; |
| 7054 | smp_rmb(); |
Vladislav Zolotarov | e8b5fc5 | 2009-01-26 12:36:42 -0800 | [diff] [blame] | 7055 | while (bnx2x_has_tx_work_unload(fp)) { |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7056 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7057 | bnx2x_tx_int(fp, 1000); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7058 | if (!cnt) { |
| 7059 | BNX2X_ERR("timeout waiting for queue[%d]\n", |
| 7060 | i); |
| 7061 | #ifdef BNX2X_STOP_ON_ERROR |
| 7062 | bnx2x_panic(); |
| 7063 | return -EBUSY; |
| 7064 | #else |
| 7065 | break; |
| 7066 | #endif |
| 7067 | } |
| 7068 | cnt--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7069 | msleep(1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7070 | smp_rmb(); |
| 7071 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7072 | } |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7073 | /* Give HW time to discard old tx messages */ |
| 7074 | msleep(1); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7075 | |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7076 | if (CHIP_IS_E1(bp)) { |
| 7077 | struct mac_configuration_cmd *config = |
| 7078 | bnx2x_sp(bp, mcast_config); |
| 7079 | |
| 7080 | bnx2x_set_mac_addr_e1(bp, 0); |
| 7081 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7082 | for (i = 0; i < config->hdr.length; i++) |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7083 | CAM_INVALIDATE(config->config_table[i]); |
| 7084 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 7085 | config->hdr.length = i; |
Yitchak Gertner | 65abd74 | 2008-08-25 15:26:24 -0700 | [diff] [blame] | 7086 | if (CHIP_REV_IS_SLOW(bp)) |
| 7087 | config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port); |
| 7088 | else |
| 7089 | config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port); |
| 7090 | config->hdr.client_id = BP_CL_ID(bp); |
| 7091 | config->hdr.reserved1 = 0; |
| 7092 | |
| 7093 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 7094 | U64_HI(bnx2x_sp_mapping(bp, mcast_config)), |
| 7095 | U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0); |
| 7096 | |
| 7097 | } else { /* E1H */ |
| 7098 | REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0); |
| 7099 | |
| 7100 | bnx2x_set_mac_addr_e1h(bp, 0); |
| 7101 | |
| 7102 | for (i = 0; i < MC_HASH_SIZE; i++) |
| 7103 | REG_WR(bp, MC_HASH_OFFSET(bp, i), 0); |
| 7104 | } |
| 7105 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7106 | if (unload_mode == UNLOAD_NORMAL) |
| 7107 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7108 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7109 | else if (bp->flags & NO_WOL_FLAG) { |
| 7110 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP; |
| 7111 | if (CHIP_IS_E1H(bp)) |
| 7112 | REG_WR(bp, MISC_REG_E1HMF_MODE, 0); |
| 7113 | |
| 7114 | } else if (bp->wol) { |
| 7115 | u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7116 | u8 *mac_addr = bp->dev->dev_addr; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7117 | u32 val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7118 | /* The mac address is written to entries 1-4 to |
| 7119 | preserve entry 0 which is used by the PMF */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7120 | u8 entry = (BP_E1HVN(bp) + 1)*8; |
| 7121 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7122 | val = (mac_addr[0] << 8) | mac_addr[1]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7123 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7124 | |
| 7125 | val = (mac_addr[2] << 24) | (mac_addr[3] << 16) | |
| 7126 | (mac_addr[4] << 8) | mac_addr[5]; |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7127 | EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7128 | |
| 7129 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7130 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7131 | } else |
| 7132 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
| 7133 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7134 | /* Close multi and leading connections |
| 7135 | Completions for ramrods are collected in a synchronous way */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7136 | for_each_nondefault_queue(bp, i) |
| 7137 | if (bnx2x_stop_multi(bp, i)) |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7138 | goto unload_error; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7139 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7140 | rc = bnx2x_stop_leading(bp); |
| 7141 | if (rc) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7142 | BNX2X_ERR("Stop leading failed!\n"); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7143 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7144 | return -EBUSY; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7145 | #else |
| 7146 | goto unload_error; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7147 | #endif |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7148 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7149 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7150 | unload_error: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7151 | if (!BP_NOMCP(bp)) |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7152 | reset_code = bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7153 | else { |
| 7154 | DP(NETIF_MSG_IFDOWN, "NO MCP load counts %d, %d, %d\n", |
| 7155 | load_count[0], load_count[1], load_count[2]); |
| 7156 | load_count[0]--; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7157 | load_count[1 + port]--; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7158 | DP(NETIF_MSG_IFDOWN, "NO MCP new load counts %d, %d, %d\n", |
| 7159 | load_count[0], load_count[1], load_count[2]); |
| 7160 | if (load_count[0] == 0) |
| 7161 | reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7162 | else if (load_count[1 + port] == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7163 | reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT; |
| 7164 | else |
| 7165 | reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION; |
| 7166 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7167 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7168 | if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) || |
| 7169 | (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT)) |
| 7170 | bnx2x__link_reset(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7171 | |
| 7172 | /* Reset the chip */ |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7173 | bnx2x_reset_chip(bp, reset_code); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7174 | |
| 7175 | /* Report UNLOAD_DONE to MCP */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7176 | if (!BP_NOMCP(bp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7177 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
Eilon Greenstein | 9a03544 | 2008-11-03 16:45:55 -0800 | [diff] [blame] | 7178 | bp->port.pmf = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7179 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 7180 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7181 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7182 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7183 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7184 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 7185 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7186 | bnx2x_free_mem(bp); |
| 7187 | |
| 7188 | bp->state = BNX2X_STATE_CLOSED; |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 7189 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7190 | netif_carrier_off(bp->dev); |
| 7191 | |
| 7192 | return 0; |
| 7193 | } |
| 7194 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7195 | static void bnx2x_reset_task(struct work_struct *work) |
| 7196 | { |
| 7197 | struct bnx2x *bp = container_of(work, struct bnx2x, reset_task); |
| 7198 | |
| 7199 | #ifdef BNX2X_STOP_ON_ERROR |
| 7200 | BNX2X_ERR("reset task called but STOP_ON_ERROR defined" |
| 7201 | " so reset not done to allow debug dump,\n" |
| 7202 | KERN_ERR " you will need to reboot when done\n"); |
| 7203 | return; |
| 7204 | #endif |
| 7205 | |
| 7206 | rtnl_lock(); |
| 7207 | |
| 7208 | if (!netif_running(bp->dev)) |
| 7209 | goto reset_task_exit; |
| 7210 | |
| 7211 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 7212 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 7213 | |
| 7214 | reset_task_exit: |
| 7215 | rtnl_unlock(); |
| 7216 | } |
| 7217 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7218 | /* end of nic load/unload */ |
| 7219 | |
| 7220 | /* ethtool_ops */ |
| 7221 | |
| 7222 | /* |
| 7223 | * Init service functions |
| 7224 | */ |
| 7225 | |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 7226 | static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func) |
| 7227 | { |
| 7228 | switch (func) { |
| 7229 | case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0; |
| 7230 | case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1; |
| 7231 | case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2; |
| 7232 | case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3; |
| 7233 | case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4; |
| 7234 | case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5; |
| 7235 | case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6; |
| 7236 | case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7; |
| 7237 | default: |
| 7238 | BNX2X_ERR("Unsupported function index: %d\n", func); |
| 7239 | return (u32)(-1); |
| 7240 | } |
| 7241 | } |
| 7242 | |
| 7243 | static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func) |
| 7244 | { |
| 7245 | u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val; |
| 7246 | |
| 7247 | /* Flush all outstanding writes */ |
| 7248 | mmiowb(); |
| 7249 | |
| 7250 | /* Pretend to be function 0 */ |
| 7251 | REG_WR(bp, reg, 0); |
| 7252 | /* Flush the GRC transaction (in the chip) */ |
| 7253 | new_val = REG_RD(bp, reg); |
| 7254 | if (new_val != 0) { |
| 7255 | BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n", |
| 7256 | new_val); |
| 7257 | BUG(); |
| 7258 | } |
| 7259 | |
| 7260 | /* From now we are in the "like-E1" mode */ |
| 7261 | bnx2x_int_disable(bp); |
| 7262 | |
| 7263 | /* Flush all outstanding writes */ |
| 7264 | mmiowb(); |
| 7265 | |
| 7266 | /* Restore the original funtion settings */ |
| 7267 | REG_WR(bp, reg, orig_func); |
| 7268 | new_val = REG_RD(bp, reg); |
| 7269 | if (new_val != orig_func) { |
| 7270 | BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n", |
| 7271 | orig_func, new_val); |
| 7272 | BUG(); |
| 7273 | } |
| 7274 | } |
| 7275 | |
| 7276 | static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func) |
| 7277 | { |
| 7278 | if (CHIP_IS_E1H(bp)) |
| 7279 | bnx2x_undi_int_disable_e1h(bp, func); |
| 7280 | else |
| 7281 | bnx2x_int_disable(bp); |
| 7282 | } |
| 7283 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7284 | static void __devinit bnx2x_undi_unload(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7285 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7286 | u32 val; |
| 7287 | |
| 7288 | /* Check if there is any driver already loaded */ |
| 7289 | val = REG_RD(bp, MISC_REG_UNPREPARED); |
| 7290 | if (val == 0x1) { |
| 7291 | /* Check if it is the UNDI driver |
| 7292 | * UNDI driver initializes CID offset for normal bell to 0x7 |
| 7293 | */ |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 7294 | bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7295 | val = REG_RD(bp, DORQ_REG_NORM_CID_OFST); |
| 7296 | if (val == 0x7) { |
| 7297 | u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7298 | /* save our func */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7299 | int func = BP_FUNC(bp); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7300 | u32 swap_en; |
| 7301 | u32 swap_val; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7302 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7303 | /* clear the UNDI indication */ |
| 7304 | REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0); |
| 7305 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7306 | BNX2X_DEV_INFO("UNDI is active! reset device\n"); |
| 7307 | |
| 7308 | /* try unload UNDI on port 0 */ |
| 7309 | bp->func = 0; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7310 | bp->fw_seq = |
| 7311 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7312 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7313 | reset_code = bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7314 | |
| 7315 | /* if UNDI is loaded on the other port */ |
| 7316 | if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) { |
| 7317 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7318 | /* send "DONE" for previous unload */ |
| 7319 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7320 | |
| 7321 | /* unload UNDI on port 1 */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7322 | bp->func = 1; |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7323 | bp->fw_seq = |
| 7324 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7325 | DRV_MSG_SEQ_NUMBER_MASK); |
| 7326 | reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7327 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7328 | bnx2x_fw_command(bp, reset_code); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7329 | } |
| 7330 | |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7331 | /* now it's safe to release the lock */ |
| 7332 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
| 7333 | |
Eilon Greenstein | f1ef27e | 2009-02-12 08:36:23 +0000 | [diff] [blame] | 7334 | bnx2x_undi_int_disable(bp, func); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7335 | |
| 7336 | /* close input traffic and wait for it */ |
| 7337 | /* Do not rcv packets to BRB */ |
| 7338 | REG_WR(bp, |
| 7339 | (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK : |
| 7340 | NIG_REG_LLH0_BRB1_DRV_MASK), 0x0); |
| 7341 | /* Do not direct rcv packets that are not for MCP to |
| 7342 | * the BRB */ |
| 7343 | REG_WR(bp, |
| 7344 | (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP : |
| 7345 | NIG_REG_LLH0_BRB1_NOT_MCP), 0x0); |
| 7346 | /* clear AEU */ |
| 7347 | REG_WR(bp, |
| 7348 | (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 : |
| 7349 | MISC_REG_AEU_MASK_ATTN_FUNC_0), 0); |
| 7350 | msleep(10); |
| 7351 | |
| 7352 | /* save NIG port swap info */ |
| 7353 | swap_val = REG_RD(bp, NIG_REG_PORT_SWAP); |
| 7354 | swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7355 | /* reset device */ |
| 7356 | REG_WR(bp, |
| 7357 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7358 | 0xd3ffffff); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7359 | REG_WR(bp, |
| 7360 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, |
| 7361 | 0x1403); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7362 | /* take the NIG out of reset and restore swap values */ |
| 7363 | REG_WR(bp, |
| 7364 | GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, |
| 7365 | MISC_REGISTERS_RESET_REG_1_RST_NIG); |
| 7366 | REG_WR(bp, NIG_REG_PORT_SWAP, swap_val); |
| 7367 | REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en); |
| 7368 | |
| 7369 | /* send unload done to the MCP */ |
| 7370 | bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE); |
| 7371 | |
| 7372 | /* restore our func and fw_seq */ |
| 7373 | bp->func = func; |
| 7374 | bp->fw_seq = |
| 7375 | (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) & |
| 7376 | DRV_MSG_SEQ_NUMBER_MASK); |
Eilon Greenstein | b466173 | 2009-01-14 06:43:56 +0000 | [diff] [blame] | 7377 | |
| 7378 | } else |
| 7379 | bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7380 | } |
| 7381 | } |
| 7382 | |
| 7383 | static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp) |
| 7384 | { |
| 7385 | u32 val, val2, val3, val4, id; |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 7386 | u16 pmc; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7387 | |
| 7388 | /* Get the chip revision id and number. */ |
| 7389 | /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */ |
| 7390 | val = REG_RD(bp, MISC_REG_CHIP_NUM); |
| 7391 | id = ((val & 0xffff) << 16); |
| 7392 | val = REG_RD(bp, MISC_REG_CHIP_REV); |
| 7393 | id |= ((val & 0xf) << 12); |
| 7394 | val = REG_RD(bp, MISC_REG_CHIP_METAL); |
| 7395 | id |= ((val & 0xff) << 4); |
Eilon Greenstein | 5a40e08 | 2009-01-14 06:44:04 +0000 | [diff] [blame] | 7396 | val = REG_RD(bp, MISC_REG_BOND_ID); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7397 | id |= (val & 0xf); |
| 7398 | bp->common.chip_id = id; |
| 7399 | bp->link_params.chip_id = bp->common.chip_id; |
| 7400 | BNX2X_DEV_INFO("chip ID is 0x%x\n", id); |
| 7401 | |
Eilon Greenstein | 1c06328 | 2009-02-12 08:36:43 +0000 | [diff] [blame] | 7402 | val = (REG_RD(bp, 0x2874) & 0x55); |
| 7403 | if ((bp->common.chip_id & 0x1) || |
| 7404 | (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) { |
| 7405 | bp->flags |= ONE_PORT_FLAG; |
| 7406 | BNX2X_DEV_INFO("single port device\n"); |
| 7407 | } |
| 7408 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7409 | val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4); |
| 7410 | bp->common.flash_size = (NVRAM_1MB_SIZE << |
| 7411 | (val & MCPR_NVM_CFG4_FLASH_SIZE)); |
| 7412 | BNX2X_DEV_INFO("flash_size 0x%x (%d)\n", |
| 7413 | bp->common.flash_size, bp->common.flash_size); |
| 7414 | |
| 7415 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 7416 | bp->link_params.shmem_base = bp->common.shmem_base; |
| 7417 | BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base); |
| 7418 | |
| 7419 | if (!bp->common.shmem_base || |
| 7420 | (bp->common.shmem_base < 0xA0000) || |
| 7421 | (bp->common.shmem_base >= 0xC0000)) { |
| 7422 | BNX2X_DEV_INFO("MCP not active\n"); |
| 7423 | bp->flags |= NO_MCP_FLAG; |
| 7424 | return; |
| 7425 | } |
| 7426 | |
| 7427 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 7428 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 7429 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 7430 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 7431 | |
| 7432 | bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config); |
Eilon Greenstein | 35b19ba | 2009-02-12 08:36:47 +0000 | [diff] [blame] | 7433 | BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7434 | |
| 7435 | bp->link_params.hw_led_mode = ((bp->common.hw_config & |
| 7436 | SHARED_HW_CFG_LED_MODE_MASK) >> |
| 7437 | SHARED_HW_CFG_LED_MODE_SHIFT); |
| 7438 | |
| 7439 | val = SHMEM_RD(bp, dev_info.bc_rev) >> 8; |
| 7440 | bp->common.bc_ver = val; |
| 7441 | BNX2X_DEV_INFO("bc_ver %X\n", val); |
| 7442 | if (val < BNX2X_BC_VER) { |
| 7443 | /* for now only warn |
| 7444 | * later we might need to enforce this */ |
| 7445 | BNX2X_ERR("This driver needs bc_ver %X but found %X," |
| 7446 | " please upgrade BC\n", BNX2X_BC_VER, val); |
| 7447 | } |
Eilon Greenstein | 72ce58c | 2008-08-13 15:52:46 -0700 | [diff] [blame] | 7448 | |
| 7449 | if (BP_E1HVN(bp) == 0) { |
| 7450 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc); |
| 7451 | bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG; |
| 7452 | } else { |
| 7453 | /* no WOL capability for E1HVN != 0 */ |
| 7454 | bp->flags |= NO_WOL_FLAG; |
| 7455 | } |
| 7456 | BNX2X_DEV_INFO("%sWoL capable\n", |
| 7457 | (bp->flags & NO_WOL_FLAG) ? "Not " : ""); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7458 | |
| 7459 | val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num); |
| 7460 | val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]); |
| 7461 | val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]); |
| 7462 | val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]); |
| 7463 | |
| 7464 | printk(KERN_INFO PFX "part number %X-%X-%X-%X\n", |
| 7465 | val, val2, val3, val4); |
| 7466 | } |
| 7467 | |
| 7468 | static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp, |
| 7469 | u32 switch_cfg) |
| 7470 | { |
| 7471 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7472 | u32 ext_phy_type; |
| 7473 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7474 | switch (switch_cfg) { |
| 7475 | case SWITCH_CFG_1G: |
| 7476 | BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg); |
| 7477 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7478 | ext_phy_type = |
| 7479 | SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7480 | switch (ext_phy_type) { |
| 7481 | case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT: |
| 7482 | BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n", |
| 7483 | ext_phy_type); |
| 7484 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7485 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 7486 | SUPPORTED_10baseT_Full | |
| 7487 | SUPPORTED_100baseT_Half | |
| 7488 | SUPPORTED_100baseT_Full | |
| 7489 | SUPPORTED_1000baseT_Full | |
| 7490 | SUPPORTED_2500baseX_Full | |
| 7491 | SUPPORTED_TP | |
| 7492 | SUPPORTED_FIBRE | |
| 7493 | SUPPORTED_Autoneg | |
| 7494 | SUPPORTED_Pause | |
| 7495 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7496 | break; |
| 7497 | |
| 7498 | case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482: |
| 7499 | BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n", |
| 7500 | ext_phy_type); |
| 7501 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7502 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 7503 | SUPPORTED_10baseT_Full | |
| 7504 | SUPPORTED_100baseT_Half | |
| 7505 | SUPPORTED_100baseT_Full | |
| 7506 | SUPPORTED_1000baseT_Full | |
| 7507 | SUPPORTED_TP | |
| 7508 | SUPPORTED_FIBRE | |
| 7509 | SUPPORTED_Autoneg | |
| 7510 | SUPPORTED_Pause | |
| 7511 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7512 | break; |
| 7513 | |
| 7514 | default: |
| 7515 | BNX2X_ERR("NVRAM config error. " |
| 7516 | "BAD SerDes ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7517 | bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7518 | return; |
| 7519 | } |
| 7520 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7521 | bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + |
| 7522 | port*0x10); |
| 7523 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7524 | break; |
| 7525 | |
| 7526 | case SWITCH_CFG_10G: |
| 7527 | BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg); |
| 7528 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7529 | ext_phy_type = |
| 7530 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7531 | switch (ext_phy_type) { |
| 7532 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT: |
| 7533 | BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n", |
| 7534 | ext_phy_type); |
| 7535 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7536 | bp->port.supported |= (SUPPORTED_10baseT_Half | |
| 7537 | SUPPORTED_10baseT_Full | |
| 7538 | SUPPORTED_100baseT_Half | |
| 7539 | SUPPORTED_100baseT_Full | |
| 7540 | SUPPORTED_1000baseT_Full | |
| 7541 | SUPPORTED_2500baseX_Full | |
| 7542 | SUPPORTED_10000baseT_Full | |
| 7543 | SUPPORTED_TP | |
| 7544 | SUPPORTED_FIBRE | |
| 7545 | SUPPORTED_Autoneg | |
| 7546 | SUPPORTED_Pause | |
| 7547 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7548 | break; |
| 7549 | |
| 7550 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7551 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7552 | ext_phy_type); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7553 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7554 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7555 | SUPPORTED_FIBRE | |
| 7556 | SUPPORTED_Pause | |
| 7557 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7558 | break; |
| 7559 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7560 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706: |
| 7561 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n", |
| 7562 | ext_phy_type); |
| 7563 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7564 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7565 | SUPPORTED_1000baseT_Full | |
| 7566 | SUPPORTED_FIBRE | |
| 7567 | SUPPORTED_Pause | |
| 7568 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7569 | break; |
| 7570 | |
| 7571 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
| 7572 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n", |
| 7573 | ext_phy_type); |
| 7574 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7575 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7576 | SUPPORTED_1000baseT_Full | |
| 7577 | SUPPORTED_FIBRE | |
| 7578 | SUPPORTED_Autoneg | |
| 7579 | SUPPORTED_Pause | |
| 7580 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7581 | break; |
| 7582 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7583 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
| 7584 | BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n", |
| 7585 | ext_phy_type); |
| 7586 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7587 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7588 | SUPPORTED_2500baseX_Full | |
| 7589 | SUPPORTED_1000baseT_Full | |
| 7590 | SUPPORTED_FIBRE | |
| 7591 | SUPPORTED_Autoneg | |
| 7592 | SUPPORTED_Pause | |
| 7593 | SUPPORTED_Asym_Pause); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7594 | break; |
| 7595 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7596 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
| 7597 | BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n", |
| 7598 | ext_phy_type); |
| 7599 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7600 | bp->port.supported |= (SUPPORTED_10000baseT_Full | |
| 7601 | SUPPORTED_TP | |
| 7602 | SUPPORTED_Autoneg | |
| 7603 | SUPPORTED_Pause | |
| 7604 | SUPPORTED_Asym_Pause); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7605 | break; |
| 7606 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7607 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE: |
| 7608 | BNX2X_ERR("XGXS PHY Failure detected 0x%x\n", |
| 7609 | bp->link_params.ext_phy_config); |
| 7610 | break; |
| 7611 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7612 | default: |
| 7613 | BNX2X_ERR("NVRAM config error. " |
| 7614 | "BAD XGXS ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7615 | bp->link_params.ext_phy_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7616 | return; |
| 7617 | } |
| 7618 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7619 | bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + |
| 7620 | port*0x18); |
| 7621 | BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7622 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7623 | break; |
| 7624 | |
| 7625 | default: |
| 7626 | BNX2X_ERR("BAD switch_cfg link_config 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7627 | bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7628 | return; |
| 7629 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7630 | bp->link_params.phy_addr = bp->port.phy_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7631 | |
| 7632 | /* mask what we support according to speed_cap_mask */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7633 | if (!(bp->link_params.speed_cap_mask & |
| 7634 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7635 | bp->port.supported &= ~SUPPORTED_10baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7636 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7637 | if (!(bp->link_params.speed_cap_mask & |
| 7638 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7639 | bp->port.supported &= ~SUPPORTED_10baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7640 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7641 | if (!(bp->link_params.speed_cap_mask & |
| 7642 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7643 | bp->port.supported &= ~SUPPORTED_100baseT_Half; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7644 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7645 | if (!(bp->link_params.speed_cap_mask & |
| 7646 | PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7647 | bp->port.supported &= ~SUPPORTED_100baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7648 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7649 | if (!(bp->link_params.speed_cap_mask & |
| 7650 | PORT_HW_CFG_SPEED_CAPABILITY_D0_1G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7651 | bp->port.supported &= ~(SUPPORTED_1000baseT_Half | |
| 7652 | SUPPORTED_1000baseT_Full); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7653 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7654 | if (!(bp->link_params.speed_cap_mask & |
| 7655 | PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7656 | bp->port.supported &= ~SUPPORTED_2500baseX_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7657 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7658 | if (!(bp->link_params.speed_cap_mask & |
| 7659 | PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7660 | bp->port.supported &= ~SUPPORTED_10000baseT_Full; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7661 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7662 | BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7663 | } |
| 7664 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7665 | static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7666 | { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7667 | bp->link_params.req_duplex = DUPLEX_FULL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7668 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7669 | switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7670 | case PORT_FEATURE_LINK_SPEED_AUTO: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7671 | if (bp->port.supported & SUPPORTED_Autoneg) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7672 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7673 | bp->port.advertising = bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7674 | } else { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7675 | u32 ext_phy_type = |
| 7676 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
| 7677 | |
| 7678 | if ((ext_phy_type == |
| 7679 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) || |
| 7680 | (ext_phy_type == |
| 7681 | PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7682 | /* force 10G, no AN */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7683 | bp->link_params.req_line_speed = SPEED_10000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7684 | bp->port.advertising = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7685 | (ADVERTISED_10000baseT_Full | |
| 7686 | ADVERTISED_FIBRE); |
| 7687 | break; |
| 7688 | } |
| 7689 | BNX2X_ERR("NVRAM config error. " |
| 7690 | "Invalid link_config 0x%x" |
| 7691 | " Autoneg not supported\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7692 | bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7693 | return; |
| 7694 | } |
| 7695 | break; |
| 7696 | |
| 7697 | case PORT_FEATURE_LINK_SPEED_10M_FULL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7698 | if (bp->port.supported & SUPPORTED_10baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7699 | bp->link_params.req_line_speed = SPEED_10; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7700 | bp->port.advertising = (ADVERTISED_10baseT_Full | |
| 7701 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7702 | } else { |
| 7703 | BNX2X_ERR("NVRAM config error. " |
| 7704 | "Invalid link_config 0x%x" |
| 7705 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7706 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7707 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7708 | return; |
| 7709 | } |
| 7710 | break; |
| 7711 | |
| 7712 | case PORT_FEATURE_LINK_SPEED_10M_HALF: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7713 | if (bp->port.supported & SUPPORTED_10baseT_Half) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7714 | bp->link_params.req_line_speed = SPEED_10; |
| 7715 | bp->link_params.req_duplex = DUPLEX_HALF; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7716 | bp->port.advertising = (ADVERTISED_10baseT_Half | |
| 7717 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7718 | } else { |
| 7719 | BNX2X_ERR("NVRAM config error. " |
| 7720 | "Invalid link_config 0x%x" |
| 7721 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7722 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7723 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7724 | return; |
| 7725 | } |
| 7726 | break; |
| 7727 | |
| 7728 | case PORT_FEATURE_LINK_SPEED_100M_FULL: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7729 | if (bp->port.supported & SUPPORTED_100baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7730 | bp->link_params.req_line_speed = SPEED_100; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7731 | bp->port.advertising = (ADVERTISED_100baseT_Full | |
| 7732 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7733 | } else { |
| 7734 | BNX2X_ERR("NVRAM config error. " |
| 7735 | "Invalid link_config 0x%x" |
| 7736 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7737 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7738 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7739 | return; |
| 7740 | } |
| 7741 | break; |
| 7742 | |
| 7743 | case PORT_FEATURE_LINK_SPEED_100M_HALF: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7744 | if (bp->port.supported & SUPPORTED_100baseT_Half) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7745 | bp->link_params.req_line_speed = SPEED_100; |
| 7746 | bp->link_params.req_duplex = DUPLEX_HALF; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7747 | bp->port.advertising = (ADVERTISED_100baseT_Half | |
| 7748 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7749 | } else { |
| 7750 | BNX2X_ERR("NVRAM config error. " |
| 7751 | "Invalid link_config 0x%x" |
| 7752 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7753 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7754 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7755 | return; |
| 7756 | } |
| 7757 | break; |
| 7758 | |
| 7759 | case PORT_FEATURE_LINK_SPEED_1G: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7760 | if (bp->port.supported & SUPPORTED_1000baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7761 | bp->link_params.req_line_speed = SPEED_1000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7762 | bp->port.advertising = (ADVERTISED_1000baseT_Full | |
| 7763 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7764 | } else { |
| 7765 | BNX2X_ERR("NVRAM config error. " |
| 7766 | "Invalid link_config 0x%x" |
| 7767 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7768 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7769 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7770 | return; |
| 7771 | } |
| 7772 | break; |
| 7773 | |
| 7774 | case PORT_FEATURE_LINK_SPEED_2_5G: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7775 | if (bp->port.supported & SUPPORTED_2500baseX_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7776 | bp->link_params.req_line_speed = SPEED_2500; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7777 | bp->port.advertising = (ADVERTISED_2500baseX_Full | |
| 7778 | ADVERTISED_TP); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7779 | } else { |
| 7780 | BNX2X_ERR("NVRAM config error. " |
| 7781 | "Invalid link_config 0x%x" |
| 7782 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7783 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7784 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7785 | return; |
| 7786 | } |
| 7787 | break; |
| 7788 | |
| 7789 | case PORT_FEATURE_LINK_SPEED_10G_CX4: |
| 7790 | case PORT_FEATURE_LINK_SPEED_10G_KX4: |
| 7791 | case PORT_FEATURE_LINK_SPEED_10G_KR: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7792 | if (bp->port.supported & SUPPORTED_10000baseT_Full) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7793 | bp->link_params.req_line_speed = SPEED_10000; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7794 | bp->port.advertising = (ADVERTISED_10000baseT_Full | |
| 7795 | ADVERTISED_FIBRE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7796 | } else { |
| 7797 | BNX2X_ERR("NVRAM config error. " |
| 7798 | "Invalid link_config 0x%x" |
| 7799 | " speed_cap_mask 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7800 | bp->port.link_config, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7801 | bp->link_params.speed_cap_mask); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7802 | return; |
| 7803 | } |
| 7804 | break; |
| 7805 | |
| 7806 | default: |
| 7807 | BNX2X_ERR("NVRAM config error. " |
| 7808 | "BAD link speed link_config 0x%x\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7809 | bp->port.link_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7810 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7811 | bp->port.advertising = bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7812 | break; |
| 7813 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7814 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7815 | bp->link_params.req_flow_ctrl = (bp->port.link_config & |
| 7816 | PORT_FEATURE_FLOW_CONTROL_MASK); |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 7817 | if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) && |
Randy Dunlap | 4ab84d4 | 2008-08-07 20:33:19 -0700 | [diff] [blame] | 7818 | !(bp->port.supported & SUPPORTED_Autoneg)) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 7819 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7820 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7821 | BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x" |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7822 | " advertising 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7823 | bp->link_params.req_line_speed, |
| 7824 | bp->link_params.req_duplex, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7825 | bp->link_params.req_flow_ctrl, bp->port.advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7826 | } |
| 7827 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7828 | static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7829 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7830 | int port = BP_PORT(bp); |
| 7831 | u32 val, val2; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7832 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7833 | bp->link_params.bp = bp; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7834 | bp->link_params.port = port; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7835 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7836 | bp->link_params.serdes_config = |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 7837 | SHMEM_RD(bp, dev_info.port_hw_config[port].serdes_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7838 | bp->link_params.lane_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7839 | SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7840 | bp->link_params.ext_phy_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7841 | SHMEM_RD(bp, |
| 7842 | dev_info.port_hw_config[port].external_phy_config); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7843 | bp->link_params.speed_cap_mask = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7844 | SHMEM_RD(bp, |
| 7845 | dev_info.port_hw_config[port].speed_capability_mask); |
| 7846 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7847 | bp->port.link_config = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7848 | SHMEM_RD(bp, dev_info.port_feature_config[port].link_config); |
| 7849 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7850 | BNX2X_DEV_INFO("serdes_config 0x%08x lane_config 0x%08x\n" |
| 7851 | KERN_INFO " ext_phy_config 0x%08x speed_cap_mask 0x%08x" |
| 7852 | " link_config 0x%08x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7853 | bp->link_params.serdes_config, |
| 7854 | bp->link_params.lane_config, |
| 7855 | bp->link_params.ext_phy_config, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7856 | bp->link_params.speed_cap_mask, bp->port.link_config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7857 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7858 | bp->link_params.switch_cfg = (bp->port.link_config & |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7859 | PORT_FEATURE_CONNECTED_SWITCH_MASK); |
| 7860 | bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7861 | |
| 7862 | bnx2x_link_settings_requested(bp); |
| 7863 | |
| 7864 | val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper); |
| 7865 | val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower); |
| 7866 | bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff); |
| 7867 | bp->dev->dev_addr[1] = (u8)(val2 & 0xff); |
| 7868 | bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff); |
| 7869 | bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff); |
| 7870 | bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff); |
| 7871 | bp->dev->dev_addr[5] = (u8)(val & 0xff); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 7872 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN); |
| 7873 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7874 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7875 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7876 | static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp) |
| 7877 | { |
| 7878 | int func = BP_FUNC(bp); |
| 7879 | u32 val, val2; |
| 7880 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7881 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7882 | bnx2x_get_common_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7883 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7884 | bp->e1hov = 0; |
| 7885 | bp->e1hmf = 0; |
| 7886 | if (CHIP_IS_E1H(bp)) { |
| 7887 | bp->mf_config = |
| 7888 | SHMEM_RD(bp, mf_cfg.func_mf_config[func].config); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7889 | |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 7890 | val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].e1hov_tag) & |
| 7891 | FUNC_MF_CFG_E1HOV_TAG_MASK); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7892 | if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7893 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7894 | bp->e1hov = val; |
| 7895 | bp->e1hmf = 1; |
| 7896 | BNX2X_DEV_INFO("MF mode E1HOV for func %d is %d " |
| 7897 | "(0x%04x)\n", |
| 7898 | func, bp->e1hov, bp->e1hov); |
| 7899 | } else { |
| 7900 | BNX2X_DEV_INFO("Single function mode\n"); |
| 7901 | if (BP_E1HVN(bp)) { |
| 7902 | BNX2X_ERR("!!! No valid E1HOV for func %d," |
| 7903 | " aborting\n", func); |
| 7904 | rc = -EPERM; |
| 7905 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7906 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7907 | } |
| 7908 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7909 | if (!BP_NOMCP(bp)) { |
| 7910 | bnx2x_get_port_hwinfo(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7911 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7912 | bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) & |
| 7913 | DRV_MSG_SEQ_NUMBER_MASK); |
| 7914 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 7915 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7916 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7917 | if (IS_E1HMF(bp)) { |
| 7918 | val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper); |
| 7919 | val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower); |
| 7920 | if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) && |
| 7921 | (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) { |
| 7922 | bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff); |
| 7923 | bp->dev->dev_addr[1] = (u8)(val2 & 0xff); |
| 7924 | bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff); |
| 7925 | bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff); |
| 7926 | bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff); |
| 7927 | bp->dev->dev_addr[5] = (u8)(val & 0xff); |
| 7928 | memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, |
| 7929 | ETH_ALEN); |
| 7930 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, |
| 7931 | ETH_ALEN); |
| 7932 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 7933 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7934 | return rc; |
| 7935 | } |
| 7936 | |
| 7937 | if (BP_NOMCP(bp)) { |
| 7938 | /* only supposed to happen on emulation/FPGA */ |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 7939 | BNX2X_ERR("warning random MAC workaround active\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7940 | random_ether_addr(bp->dev->dev_addr); |
| 7941 | memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN); |
| 7942 | } |
| 7943 | |
| 7944 | return rc; |
| 7945 | } |
| 7946 | |
| 7947 | static int __devinit bnx2x_init_bp(struct bnx2x *bp) |
| 7948 | { |
| 7949 | int func = BP_FUNC(bp); |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 7950 | int timer_interval; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7951 | int rc; |
| 7952 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 7953 | /* Disable interrupt handling until HW is initialized */ |
| 7954 | atomic_set(&bp->intr_sem, 1); |
| 7955 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7956 | mutex_init(&bp->port.phy_mutex); |
| 7957 | |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 7958 | INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7959 | INIT_WORK(&bp->reset_task, bnx2x_reset_task); |
| 7960 | |
| 7961 | rc = bnx2x_get_hwinfo(bp); |
| 7962 | |
| 7963 | /* need to reset chip if undi was active */ |
| 7964 | if (!BP_NOMCP(bp)) |
| 7965 | bnx2x_undi_unload(bp); |
| 7966 | |
| 7967 | if (CHIP_REV_IS_FPGA(bp)) |
| 7968 | printk(KERN_ERR PFX "FPGA detected\n"); |
| 7969 | |
| 7970 | if (BP_NOMCP(bp) && (func == 0)) |
| 7971 | printk(KERN_ERR PFX |
| 7972 | "MCP disabled, must load devices in order!\n"); |
| 7973 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7974 | /* Set multi queue mode */ |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7975 | if ((multi_mode != ETH_RSS_MODE_DISABLED) && |
| 7976 | ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) { |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7977 | printk(KERN_ERR PFX |
Eilon Greenstein | 8badd27 | 2009-02-12 08:36:15 +0000 | [diff] [blame] | 7978 | "Multi disabled since int_mode requested is not MSI-X\n"); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 7979 | multi_mode = ETH_RSS_MODE_DISABLED; |
| 7980 | } |
| 7981 | bp->multi_mode = multi_mode; |
| 7982 | |
| 7983 | |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 7984 | /* Set TPA flags */ |
| 7985 | if (disable_tpa) { |
| 7986 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 7987 | bp->dev->features &= ~NETIF_F_LRO; |
| 7988 | } else { |
| 7989 | bp->flags |= TPA_ENABLE_FLAG; |
| 7990 | bp->dev->features |= NETIF_F_LRO; |
| 7991 | } |
| 7992 | |
| 7993 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7994 | bp->tx_ring_size = MAX_TX_AVAIL; |
| 7995 | bp->rx_ring_size = MAX_RX_AVAIL; |
| 7996 | |
| 7997 | bp->rx_csum = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 7998 | |
| 7999 | bp->tx_ticks = 50; |
| 8000 | bp->rx_ticks = 25; |
| 8001 | |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 8002 | timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ); |
| 8003 | bp->current_interval = (poll ? poll : timer_interval); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8004 | |
| 8005 | init_timer(&bp->timer); |
| 8006 | bp->timer.expires = jiffies + bp->current_interval; |
| 8007 | bp->timer.data = (unsigned long) bp; |
| 8008 | bp->timer.function = bnx2x_timer; |
| 8009 | |
| 8010 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8011 | } |
| 8012 | |
| 8013 | /* |
| 8014 | * ethtool service functions |
| 8015 | */ |
| 8016 | |
| 8017 | /* All ethtool functions called with rtnl_lock */ |
| 8018 | |
| 8019 | static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 8020 | { |
| 8021 | struct bnx2x *bp = netdev_priv(dev); |
| 8022 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8023 | cmd->supported = bp->port.supported; |
| 8024 | cmd->advertising = bp->port.advertising; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8025 | |
| 8026 | if (netif_carrier_ok(dev)) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8027 | cmd->speed = bp->link_vars.line_speed; |
| 8028 | cmd->duplex = bp->link_vars.duplex; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8029 | } else { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8030 | cmd->speed = bp->link_params.req_line_speed; |
| 8031 | cmd->duplex = bp->link_params.req_duplex; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8032 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8033 | if (IS_E1HMF(bp)) { |
| 8034 | u16 vn_max_rate; |
| 8035 | |
| 8036 | vn_max_rate = ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >> |
| 8037 | FUNC_MF_CFG_MAX_BW_SHIFT) * 100; |
| 8038 | if (vn_max_rate < cmd->speed) |
| 8039 | cmd->speed = vn_max_rate; |
| 8040 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8041 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8042 | if (bp->link_params.switch_cfg == SWITCH_CFG_10G) { |
| 8043 | u32 ext_phy_type = |
| 8044 | XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8045 | |
| 8046 | switch (ext_phy_type) { |
| 8047 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT: |
| 8048 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705: |
| 8049 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706: |
| 8050 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072: |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8051 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8052 | cmd->port = PORT_FIBRE; |
| 8053 | break; |
| 8054 | |
| 8055 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101: |
| 8056 | cmd->port = PORT_TP; |
| 8057 | break; |
| 8058 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8059 | case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE: |
| 8060 | BNX2X_ERR("XGXS PHY Failure detected 0x%x\n", |
| 8061 | bp->link_params.ext_phy_config); |
| 8062 | break; |
| 8063 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8064 | default: |
| 8065 | DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8066 | bp->link_params.ext_phy_config); |
| 8067 | break; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8068 | } |
| 8069 | } else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8070 | cmd->port = PORT_TP; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8071 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8072 | cmd->phy_address = bp->port.phy_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8073 | cmd->transceiver = XCVR_INTERNAL; |
| 8074 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8075 | if (bp->link_params.req_line_speed == SPEED_AUTO_NEG) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8076 | cmd->autoneg = AUTONEG_ENABLE; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8077 | else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8078 | cmd->autoneg = AUTONEG_DISABLE; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8079 | |
| 8080 | cmd->maxtxpkt = 0; |
| 8081 | cmd->maxrxpkt = 0; |
| 8082 | |
| 8083 | DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n" |
| 8084 | DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n" |
| 8085 | DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n" |
| 8086 | DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n", |
| 8087 | cmd->cmd, cmd->supported, cmd->advertising, cmd->speed, |
| 8088 | cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver, |
| 8089 | cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt); |
| 8090 | |
| 8091 | return 0; |
| 8092 | } |
| 8093 | |
| 8094 | static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 8095 | { |
| 8096 | struct bnx2x *bp = netdev_priv(dev); |
| 8097 | u32 advertising; |
| 8098 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8099 | if (IS_E1HMF(bp)) |
| 8100 | return 0; |
| 8101 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8102 | DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n" |
| 8103 | DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n" |
| 8104 | DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n" |
| 8105 | DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n", |
| 8106 | cmd->cmd, cmd->supported, cmd->advertising, cmd->speed, |
| 8107 | cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver, |
| 8108 | cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt); |
| 8109 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8110 | if (cmd->autoneg == AUTONEG_ENABLE) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8111 | if (!(bp->port.supported & SUPPORTED_Autoneg)) { |
| 8112 | DP(NETIF_MSG_LINK, "Autoneg not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8113 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8114 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8115 | |
| 8116 | /* advertise the requested speed and duplex if supported */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8117 | cmd->advertising &= bp->port.supported; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8118 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8119 | bp->link_params.req_line_speed = SPEED_AUTO_NEG; |
| 8120 | bp->link_params.req_duplex = DUPLEX_FULL; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8121 | bp->port.advertising |= (ADVERTISED_Autoneg | |
| 8122 | cmd->advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8123 | |
| 8124 | } else { /* forced speed */ |
| 8125 | /* advertise the requested speed and duplex if supported */ |
| 8126 | switch (cmd->speed) { |
| 8127 | case SPEED_10: |
| 8128 | if (cmd->duplex == DUPLEX_FULL) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8129 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8130 | SUPPORTED_10baseT_Full)) { |
| 8131 | DP(NETIF_MSG_LINK, |
| 8132 | "10M full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8133 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8134 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8135 | |
| 8136 | advertising = (ADVERTISED_10baseT_Full | |
| 8137 | ADVERTISED_TP); |
| 8138 | } else { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8139 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8140 | SUPPORTED_10baseT_Half)) { |
| 8141 | DP(NETIF_MSG_LINK, |
| 8142 | "10M half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8143 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8144 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8145 | |
| 8146 | advertising = (ADVERTISED_10baseT_Half | |
| 8147 | ADVERTISED_TP); |
| 8148 | } |
| 8149 | break; |
| 8150 | |
| 8151 | case SPEED_100: |
| 8152 | if (cmd->duplex == DUPLEX_FULL) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8153 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8154 | SUPPORTED_100baseT_Full)) { |
| 8155 | DP(NETIF_MSG_LINK, |
| 8156 | "100M full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8157 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8158 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8159 | |
| 8160 | advertising = (ADVERTISED_100baseT_Full | |
| 8161 | ADVERTISED_TP); |
| 8162 | } else { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8163 | if (!(bp->port.supported & |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8164 | SUPPORTED_100baseT_Half)) { |
| 8165 | DP(NETIF_MSG_LINK, |
| 8166 | "100M half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8167 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8168 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8169 | |
| 8170 | advertising = (ADVERTISED_100baseT_Half | |
| 8171 | ADVERTISED_TP); |
| 8172 | } |
| 8173 | break; |
| 8174 | |
| 8175 | case SPEED_1000: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8176 | if (cmd->duplex != DUPLEX_FULL) { |
| 8177 | DP(NETIF_MSG_LINK, "1G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8178 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8179 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8180 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8181 | if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8182 | DP(NETIF_MSG_LINK, "1G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8183 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8184 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8185 | |
| 8186 | advertising = (ADVERTISED_1000baseT_Full | |
| 8187 | ADVERTISED_TP); |
| 8188 | break; |
| 8189 | |
| 8190 | case SPEED_2500: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8191 | if (cmd->duplex != DUPLEX_FULL) { |
| 8192 | DP(NETIF_MSG_LINK, |
| 8193 | "2.5G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8194 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8195 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8196 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8197 | if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8198 | DP(NETIF_MSG_LINK, |
| 8199 | "2.5G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8200 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8201 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8202 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8203 | advertising = (ADVERTISED_2500baseX_Full | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8204 | ADVERTISED_TP); |
| 8205 | break; |
| 8206 | |
| 8207 | case SPEED_10000: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8208 | if (cmd->duplex != DUPLEX_FULL) { |
| 8209 | DP(NETIF_MSG_LINK, "10G half not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8210 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8211 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8212 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8213 | if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8214 | DP(NETIF_MSG_LINK, "10G full not supported\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8215 | return -EINVAL; |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8216 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8217 | |
| 8218 | advertising = (ADVERTISED_10000baseT_Full | |
| 8219 | ADVERTISED_FIBRE); |
| 8220 | break; |
| 8221 | |
| 8222 | default: |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8223 | DP(NETIF_MSG_LINK, "Unsupported speed\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8224 | return -EINVAL; |
| 8225 | } |
| 8226 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8227 | bp->link_params.req_line_speed = cmd->speed; |
| 8228 | bp->link_params.req_duplex = cmd->duplex; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8229 | bp->port.advertising = advertising; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8230 | } |
| 8231 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8232 | DP(NETIF_MSG_LINK, "req_line_speed %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8233 | DP_LEVEL " req_duplex %d advertising 0x%x\n", |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8234 | bp->link_params.req_line_speed, bp->link_params.req_duplex, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8235 | bp->port.advertising); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8236 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8237 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8238 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8239 | bnx2x_link_set(bp); |
| 8240 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8241 | |
| 8242 | return 0; |
| 8243 | } |
| 8244 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8245 | #define PHY_FW_VER_LEN 10 |
| 8246 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8247 | static void bnx2x_get_drvinfo(struct net_device *dev, |
| 8248 | struct ethtool_drvinfo *info) |
| 8249 | { |
| 8250 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | f0e53a8 | 2008-08-13 15:58:30 -0700 | [diff] [blame] | 8251 | u8 phy_fw_ver[PHY_FW_VER_LEN]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8252 | |
| 8253 | strcpy(info->driver, DRV_MODULE_NAME); |
| 8254 | strcpy(info->version, DRV_MODULE_VERSION); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8255 | |
| 8256 | phy_fw_ver[0] = '\0'; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8257 | if (bp->port.pmf) { |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8258 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8259 | bnx2x_get_ext_phy_fw_version(&bp->link_params, |
| 8260 | (bp->state != BNX2X_STATE_CLOSED), |
| 8261 | phy_fw_ver, PHY_FW_VER_LEN); |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8262 | bnx2x_release_phy_lock(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8263 | } |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8264 | |
Eilon Greenstein | f0e53a8 | 2008-08-13 15:58:30 -0700 | [diff] [blame] | 8265 | snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s", |
| 8266 | (bp->common.bc_ver & 0xff0000) >> 16, |
| 8267 | (bp->common.bc_ver & 0xff00) >> 8, |
| 8268 | (bp->common.bc_ver & 0xff), |
| 8269 | ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8270 | strcpy(info->bus_info, pci_name(bp->pdev)); |
| 8271 | info->n_stats = BNX2X_NUM_STATS; |
| 8272 | info->testinfo_len = BNX2X_NUM_TESTS; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8273 | info->eedump_len = bp->common.flash_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8274 | info->regdump_len = 0; |
| 8275 | } |
| 8276 | |
| 8277 | static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 8278 | { |
| 8279 | struct bnx2x *bp = netdev_priv(dev); |
| 8280 | |
| 8281 | if (bp->flags & NO_WOL_FLAG) { |
| 8282 | wol->supported = 0; |
| 8283 | wol->wolopts = 0; |
| 8284 | } else { |
| 8285 | wol->supported = WAKE_MAGIC; |
| 8286 | if (bp->wol) |
| 8287 | wol->wolopts = WAKE_MAGIC; |
| 8288 | else |
| 8289 | wol->wolopts = 0; |
| 8290 | } |
| 8291 | memset(&wol->sopass, 0, sizeof(wol->sopass)); |
| 8292 | } |
| 8293 | |
| 8294 | static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 8295 | { |
| 8296 | struct bnx2x *bp = netdev_priv(dev); |
| 8297 | |
| 8298 | if (wol->wolopts & ~WAKE_MAGIC) |
| 8299 | return -EINVAL; |
| 8300 | |
| 8301 | if (wol->wolopts & WAKE_MAGIC) { |
| 8302 | if (bp->flags & NO_WOL_FLAG) |
| 8303 | return -EINVAL; |
| 8304 | |
| 8305 | bp->wol = 1; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8306 | } else |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8307 | bp->wol = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8308 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8309 | return 0; |
| 8310 | } |
| 8311 | |
| 8312 | static u32 bnx2x_get_msglevel(struct net_device *dev) |
| 8313 | { |
| 8314 | struct bnx2x *bp = netdev_priv(dev); |
| 8315 | |
| 8316 | return bp->msglevel; |
| 8317 | } |
| 8318 | |
| 8319 | static void bnx2x_set_msglevel(struct net_device *dev, u32 level) |
| 8320 | { |
| 8321 | struct bnx2x *bp = netdev_priv(dev); |
| 8322 | |
| 8323 | if (capable(CAP_NET_ADMIN)) |
| 8324 | bp->msglevel = level; |
| 8325 | } |
| 8326 | |
| 8327 | static int bnx2x_nway_reset(struct net_device *dev) |
| 8328 | { |
| 8329 | struct bnx2x *bp = netdev_priv(dev); |
| 8330 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8331 | if (!bp->port.pmf) |
| 8332 | return 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8333 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8334 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8335 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8336 | bnx2x_link_set(bp); |
| 8337 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8338 | |
| 8339 | return 0; |
| 8340 | } |
| 8341 | |
| 8342 | static int bnx2x_get_eeprom_len(struct net_device *dev) |
| 8343 | { |
| 8344 | struct bnx2x *bp = netdev_priv(dev); |
| 8345 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8346 | return bp->common.flash_size; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8347 | } |
| 8348 | |
| 8349 | static int bnx2x_acquire_nvram_lock(struct bnx2x *bp) |
| 8350 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8351 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8352 | int count, i; |
| 8353 | u32 val = 0; |
| 8354 | |
| 8355 | /* adjust timeout for emulation/FPGA */ |
| 8356 | count = NVRAM_TIMEOUT_COUNT; |
| 8357 | if (CHIP_REV_IS_SLOW(bp)) |
| 8358 | count *= 100; |
| 8359 | |
| 8360 | /* request access to nvram interface */ |
| 8361 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, |
| 8362 | (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port)); |
| 8363 | |
| 8364 | for (i = 0; i < count*10; i++) { |
| 8365 | val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB); |
| 8366 | if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) |
| 8367 | break; |
| 8368 | |
| 8369 | udelay(5); |
| 8370 | } |
| 8371 | |
| 8372 | if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8373 | DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8374 | return -EBUSY; |
| 8375 | } |
| 8376 | |
| 8377 | return 0; |
| 8378 | } |
| 8379 | |
| 8380 | static int bnx2x_release_nvram_lock(struct bnx2x *bp) |
| 8381 | { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8382 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8383 | int count, i; |
| 8384 | u32 val = 0; |
| 8385 | |
| 8386 | /* adjust timeout for emulation/FPGA */ |
| 8387 | count = NVRAM_TIMEOUT_COUNT; |
| 8388 | if (CHIP_REV_IS_SLOW(bp)) |
| 8389 | count *= 100; |
| 8390 | |
| 8391 | /* relinquish nvram interface */ |
| 8392 | REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB, |
| 8393 | (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port)); |
| 8394 | |
| 8395 | for (i = 0; i < count*10; i++) { |
| 8396 | val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB); |
| 8397 | if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) |
| 8398 | break; |
| 8399 | |
| 8400 | udelay(5); |
| 8401 | } |
| 8402 | |
| 8403 | if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8404 | DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8405 | return -EBUSY; |
| 8406 | } |
| 8407 | |
| 8408 | return 0; |
| 8409 | } |
| 8410 | |
| 8411 | static void bnx2x_enable_nvram_access(struct bnx2x *bp) |
| 8412 | { |
| 8413 | u32 val; |
| 8414 | |
| 8415 | val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE); |
| 8416 | |
| 8417 | /* enable both bits, even on read */ |
| 8418 | REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE, |
| 8419 | (val | MCPR_NVM_ACCESS_ENABLE_EN | |
| 8420 | MCPR_NVM_ACCESS_ENABLE_WR_EN)); |
| 8421 | } |
| 8422 | |
| 8423 | static void bnx2x_disable_nvram_access(struct bnx2x *bp) |
| 8424 | { |
| 8425 | u32 val; |
| 8426 | |
| 8427 | val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE); |
| 8428 | |
| 8429 | /* disable both bits, even after read */ |
| 8430 | REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE, |
| 8431 | (val & ~(MCPR_NVM_ACCESS_ENABLE_EN | |
| 8432 | MCPR_NVM_ACCESS_ENABLE_WR_EN))); |
| 8433 | } |
| 8434 | |
| 8435 | static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, u32 *ret_val, |
| 8436 | u32 cmd_flags) |
| 8437 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8438 | int count, i, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8439 | u32 val; |
| 8440 | |
| 8441 | /* build the command word */ |
| 8442 | cmd_flags |= MCPR_NVM_COMMAND_DOIT; |
| 8443 | |
| 8444 | /* need to clear DONE bit separately */ |
| 8445 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); |
| 8446 | |
| 8447 | /* address of the NVRAM to read from */ |
| 8448 | REG_WR(bp, MCP_REG_MCPR_NVM_ADDR, |
| 8449 | (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); |
| 8450 | |
| 8451 | /* issue a read command */ |
| 8452 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); |
| 8453 | |
| 8454 | /* adjust timeout for emulation/FPGA */ |
| 8455 | count = NVRAM_TIMEOUT_COUNT; |
| 8456 | if (CHIP_REV_IS_SLOW(bp)) |
| 8457 | count *= 100; |
| 8458 | |
| 8459 | /* wait for completion */ |
| 8460 | *ret_val = 0; |
| 8461 | rc = -EBUSY; |
| 8462 | for (i = 0; i < count; i++) { |
| 8463 | udelay(5); |
| 8464 | val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND); |
| 8465 | |
| 8466 | if (val & MCPR_NVM_COMMAND_DONE) { |
| 8467 | val = REG_RD(bp, MCP_REG_MCPR_NVM_READ); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8468 | /* we read nvram data in cpu order |
| 8469 | * but ethtool sees it as an array of bytes |
| 8470 | * converting to big-endian will do the work */ |
| 8471 | val = cpu_to_be32(val); |
| 8472 | *ret_val = val; |
| 8473 | rc = 0; |
| 8474 | break; |
| 8475 | } |
| 8476 | } |
| 8477 | |
| 8478 | return rc; |
| 8479 | } |
| 8480 | |
| 8481 | static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf, |
| 8482 | int buf_size) |
| 8483 | { |
| 8484 | int rc; |
| 8485 | u32 cmd_flags; |
| 8486 | u32 val; |
| 8487 | |
| 8488 | if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8489 | DP(BNX2X_MSG_NVM, |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 8490 | "Invalid parameter: offset 0x%x buf_size 0x%x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8491 | offset, buf_size); |
| 8492 | return -EINVAL; |
| 8493 | } |
| 8494 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8495 | if (offset + buf_size > bp->common.flash_size) { |
| 8496 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8497 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8498 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8499 | return -EINVAL; |
| 8500 | } |
| 8501 | |
| 8502 | /* request access to nvram interface */ |
| 8503 | rc = bnx2x_acquire_nvram_lock(bp); |
| 8504 | if (rc) |
| 8505 | return rc; |
| 8506 | |
| 8507 | /* enable access to nvram interface */ |
| 8508 | bnx2x_enable_nvram_access(bp); |
| 8509 | |
| 8510 | /* read the first word(s) */ |
| 8511 | cmd_flags = MCPR_NVM_COMMAND_FIRST; |
| 8512 | while ((buf_size > sizeof(u32)) && (rc == 0)) { |
| 8513 | rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags); |
| 8514 | memcpy(ret_buf, &val, 4); |
| 8515 | |
| 8516 | /* advance to the next dword */ |
| 8517 | offset += sizeof(u32); |
| 8518 | ret_buf += sizeof(u32); |
| 8519 | buf_size -= sizeof(u32); |
| 8520 | cmd_flags = 0; |
| 8521 | } |
| 8522 | |
| 8523 | if (rc == 0) { |
| 8524 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 8525 | rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags); |
| 8526 | memcpy(ret_buf, &val, 4); |
| 8527 | } |
| 8528 | |
| 8529 | /* disable access to nvram interface */ |
| 8530 | bnx2x_disable_nvram_access(bp); |
| 8531 | bnx2x_release_nvram_lock(bp); |
| 8532 | |
| 8533 | return rc; |
| 8534 | } |
| 8535 | |
| 8536 | static int bnx2x_get_eeprom(struct net_device *dev, |
| 8537 | struct ethtool_eeprom *eeprom, u8 *eebuf) |
| 8538 | { |
| 8539 | struct bnx2x *bp = netdev_priv(dev); |
| 8540 | int rc; |
| 8541 | |
Eilon Greenstein | 2add3ac | 2009-01-14 06:44:07 +0000 | [diff] [blame] | 8542 | if (!netif_running(dev)) |
| 8543 | return -EAGAIN; |
| 8544 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8545 | DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8546 | DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n", |
| 8547 | eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset, |
| 8548 | eeprom->len, eeprom->len); |
| 8549 | |
| 8550 | /* parameters already validated in ethtool_get_eeprom */ |
| 8551 | |
| 8552 | rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len); |
| 8553 | |
| 8554 | return rc; |
| 8555 | } |
| 8556 | |
| 8557 | static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val, |
| 8558 | u32 cmd_flags) |
| 8559 | { |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8560 | int count, i, rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8561 | |
| 8562 | /* build the command word */ |
| 8563 | cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR; |
| 8564 | |
| 8565 | /* need to clear DONE bit separately */ |
| 8566 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE); |
| 8567 | |
| 8568 | /* write the data */ |
| 8569 | REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val); |
| 8570 | |
| 8571 | /* address of the NVRAM to write to */ |
| 8572 | REG_WR(bp, MCP_REG_MCPR_NVM_ADDR, |
| 8573 | (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE)); |
| 8574 | |
| 8575 | /* issue the write command */ |
| 8576 | REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags); |
| 8577 | |
| 8578 | /* adjust timeout for emulation/FPGA */ |
| 8579 | count = NVRAM_TIMEOUT_COUNT; |
| 8580 | if (CHIP_REV_IS_SLOW(bp)) |
| 8581 | count *= 100; |
| 8582 | |
| 8583 | /* wait for completion */ |
| 8584 | rc = -EBUSY; |
| 8585 | for (i = 0; i < count; i++) { |
| 8586 | udelay(5); |
| 8587 | val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND); |
| 8588 | if (val & MCPR_NVM_COMMAND_DONE) { |
| 8589 | rc = 0; |
| 8590 | break; |
| 8591 | } |
| 8592 | } |
| 8593 | |
| 8594 | return rc; |
| 8595 | } |
| 8596 | |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8597 | #define BYTE_OFFSET(offset) (8 * (offset & 0x03)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8598 | |
| 8599 | static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf, |
| 8600 | int buf_size) |
| 8601 | { |
| 8602 | int rc; |
| 8603 | u32 cmd_flags; |
| 8604 | u32 align_offset; |
| 8605 | u32 val; |
| 8606 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8607 | if (offset + buf_size > bp->common.flash_size) { |
| 8608 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8609 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8610 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8611 | return -EINVAL; |
| 8612 | } |
| 8613 | |
| 8614 | /* request access to nvram interface */ |
| 8615 | rc = bnx2x_acquire_nvram_lock(bp); |
| 8616 | if (rc) |
| 8617 | return rc; |
| 8618 | |
| 8619 | /* enable access to nvram interface */ |
| 8620 | bnx2x_enable_nvram_access(bp); |
| 8621 | |
| 8622 | cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST); |
| 8623 | align_offset = (offset & ~0x03); |
| 8624 | rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags); |
| 8625 | |
| 8626 | if (rc == 0) { |
| 8627 | val &= ~(0xff << BYTE_OFFSET(offset)); |
| 8628 | val |= (*data_buf << BYTE_OFFSET(offset)); |
| 8629 | |
| 8630 | /* nvram data is returned as an array of bytes |
| 8631 | * convert it back to cpu order */ |
| 8632 | val = be32_to_cpu(val); |
| 8633 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8634 | rc = bnx2x_nvram_write_dword(bp, align_offset, val, |
| 8635 | cmd_flags); |
| 8636 | } |
| 8637 | |
| 8638 | /* disable access to nvram interface */ |
| 8639 | bnx2x_disable_nvram_access(bp); |
| 8640 | bnx2x_release_nvram_lock(bp); |
| 8641 | |
| 8642 | return rc; |
| 8643 | } |
| 8644 | |
| 8645 | static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf, |
| 8646 | int buf_size) |
| 8647 | { |
| 8648 | int rc; |
| 8649 | u32 cmd_flags; |
| 8650 | u32 val; |
| 8651 | u32 written_so_far; |
| 8652 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8653 | if (buf_size == 1) /* ethtool */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8654 | return bnx2x_nvram_write1(bp, offset, data_buf, buf_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8655 | |
| 8656 | if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8657 | DP(BNX2X_MSG_NVM, |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 8658 | "Invalid parameter: offset 0x%x buf_size 0x%x\n", |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8659 | offset, buf_size); |
| 8660 | return -EINVAL; |
| 8661 | } |
| 8662 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8663 | if (offset + buf_size > bp->common.flash_size) { |
| 8664 | DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8665 | " buf_size (0x%x) > flash_size (0x%x)\n", |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8666 | offset, buf_size, bp->common.flash_size); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8667 | return -EINVAL; |
| 8668 | } |
| 8669 | |
| 8670 | /* request access to nvram interface */ |
| 8671 | rc = bnx2x_acquire_nvram_lock(bp); |
| 8672 | if (rc) |
| 8673 | return rc; |
| 8674 | |
| 8675 | /* enable access to nvram interface */ |
| 8676 | bnx2x_enable_nvram_access(bp); |
| 8677 | |
| 8678 | written_so_far = 0; |
| 8679 | cmd_flags = MCPR_NVM_COMMAND_FIRST; |
| 8680 | while ((written_so_far < buf_size) && (rc == 0)) { |
| 8681 | if (written_so_far == (buf_size - sizeof(u32))) |
| 8682 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 8683 | else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0) |
| 8684 | cmd_flags |= MCPR_NVM_COMMAND_LAST; |
| 8685 | else if ((offset % NVRAM_PAGE_SIZE) == 0) |
| 8686 | cmd_flags |= MCPR_NVM_COMMAND_FIRST; |
| 8687 | |
| 8688 | memcpy(&val, data_buf, 4); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8689 | |
| 8690 | rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags); |
| 8691 | |
| 8692 | /* advance to the next dword */ |
| 8693 | offset += sizeof(u32); |
| 8694 | data_buf += sizeof(u32); |
| 8695 | written_so_far += sizeof(u32); |
| 8696 | cmd_flags = 0; |
| 8697 | } |
| 8698 | |
| 8699 | /* disable access to nvram interface */ |
| 8700 | bnx2x_disable_nvram_access(bp); |
| 8701 | bnx2x_release_nvram_lock(bp); |
| 8702 | |
| 8703 | return rc; |
| 8704 | } |
| 8705 | |
| 8706 | static int bnx2x_set_eeprom(struct net_device *dev, |
| 8707 | struct ethtool_eeprom *eeprom, u8 *eebuf) |
| 8708 | { |
| 8709 | struct bnx2x *bp = netdev_priv(dev); |
| 8710 | int rc; |
| 8711 | |
Eilon Greenstein | 9f4c958 | 2009-01-08 11:21:43 -0800 | [diff] [blame] | 8712 | if (!netif_running(dev)) |
| 8713 | return -EAGAIN; |
| 8714 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8715 | DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n" |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8716 | DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n", |
| 8717 | eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset, |
| 8718 | eeprom->len, eeprom->len); |
| 8719 | |
| 8720 | /* parameters already validated in ethtool_set_eeprom */ |
| 8721 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8722 | /* If the magic number is PHY (0x00504859) upgrade the PHY FW */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8723 | if (eeprom->magic == 0x00504859) |
| 8724 | if (bp->port.pmf) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8725 | |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8726 | bnx2x_acquire_phy_lock(bp); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8727 | rc = bnx2x_flash_download(bp, BP_PORT(bp), |
| 8728 | bp->link_params.ext_phy_config, |
| 8729 | (bp->state != BNX2X_STATE_CLOSED), |
| 8730 | eebuf, eeprom->len); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8731 | if ((bp->state == BNX2X_STATE_OPEN) || |
| 8732 | (bp->state == BNX2X_STATE_DISABLED)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8733 | rc |= bnx2x_link_reset(&bp->link_params, |
| 8734 | &bp->link_vars); |
| 8735 | rc |= bnx2x_phy_init(&bp->link_params, |
| 8736 | &bp->link_vars); |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8737 | } |
Yitchak Gertner | 4a37fb6 | 2008-08-13 15:50:23 -0700 | [diff] [blame] | 8738 | bnx2x_release_phy_lock(bp); |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8739 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8740 | } else /* Only the PMF can access the PHY */ |
| 8741 | return -EINVAL; |
| 8742 | else |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8743 | rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8744 | |
| 8745 | return rc; |
| 8746 | } |
| 8747 | |
| 8748 | static int bnx2x_get_coalesce(struct net_device *dev, |
| 8749 | struct ethtool_coalesce *coal) |
| 8750 | { |
| 8751 | struct bnx2x *bp = netdev_priv(dev); |
| 8752 | |
| 8753 | memset(coal, 0, sizeof(struct ethtool_coalesce)); |
| 8754 | |
| 8755 | coal->rx_coalesce_usecs = bp->rx_ticks; |
| 8756 | coal->tx_coalesce_usecs = bp->tx_ticks; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8757 | |
| 8758 | return 0; |
| 8759 | } |
| 8760 | |
| 8761 | static int bnx2x_set_coalesce(struct net_device *dev, |
| 8762 | struct ethtool_coalesce *coal) |
| 8763 | { |
| 8764 | struct bnx2x *bp = netdev_priv(dev); |
| 8765 | |
| 8766 | bp->rx_ticks = (u16) coal->rx_coalesce_usecs; |
| 8767 | if (bp->rx_ticks > 3000) |
| 8768 | bp->rx_ticks = 3000; |
| 8769 | |
| 8770 | bp->tx_ticks = (u16) coal->tx_coalesce_usecs; |
| 8771 | if (bp->tx_ticks > 0x3000) |
| 8772 | bp->tx_ticks = 0x3000; |
| 8773 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8774 | if (netif_running(dev)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8775 | bnx2x_update_coalesce(bp); |
| 8776 | |
| 8777 | return 0; |
| 8778 | } |
| 8779 | |
| 8780 | static void bnx2x_get_ringparam(struct net_device *dev, |
| 8781 | struct ethtool_ringparam *ering) |
| 8782 | { |
| 8783 | struct bnx2x *bp = netdev_priv(dev); |
| 8784 | |
| 8785 | ering->rx_max_pending = MAX_RX_AVAIL; |
| 8786 | ering->rx_mini_max_pending = 0; |
| 8787 | ering->rx_jumbo_max_pending = 0; |
| 8788 | |
| 8789 | ering->rx_pending = bp->rx_ring_size; |
| 8790 | ering->rx_mini_pending = 0; |
| 8791 | ering->rx_jumbo_pending = 0; |
| 8792 | |
| 8793 | ering->tx_max_pending = MAX_TX_AVAIL; |
| 8794 | ering->tx_pending = bp->tx_ring_size; |
| 8795 | } |
| 8796 | |
| 8797 | static int bnx2x_set_ringparam(struct net_device *dev, |
| 8798 | struct ethtool_ringparam *ering) |
| 8799 | { |
| 8800 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8801 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8802 | |
| 8803 | if ((ering->rx_pending > MAX_RX_AVAIL) || |
| 8804 | (ering->tx_pending > MAX_TX_AVAIL) || |
| 8805 | (ering->tx_pending <= MAX_SKB_FRAGS + 4)) |
| 8806 | return -EINVAL; |
| 8807 | |
| 8808 | bp->rx_ring_size = ering->rx_pending; |
| 8809 | bp->tx_ring_size = ering->tx_pending; |
| 8810 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8811 | if (netif_running(dev)) { |
| 8812 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 8813 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8814 | } |
| 8815 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8816 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8817 | } |
| 8818 | |
| 8819 | static void bnx2x_get_pauseparam(struct net_device *dev, |
| 8820 | struct ethtool_pauseparam *epause) |
| 8821 | { |
| 8822 | struct bnx2x *bp = netdev_priv(dev); |
| 8823 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8824 | epause->autoneg = (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) && |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8825 | (bp->link_params.req_line_speed == SPEED_AUTO_NEG); |
| 8826 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8827 | epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) == |
| 8828 | BNX2X_FLOW_CTRL_RX); |
| 8829 | epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) == |
| 8830 | BNX2X_FLOW_CTRL_TX); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8831 | |
| 8832 | DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n" |
| 8833 | DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n", |
| 8834 | epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause); |
| 8835 | } |
| 8836 | |
| 8837 | static int bnx2x_set_pauseparam(struct net_device *dev, |
| 8838 | struct ethtool_pauseparam *epause) |
| 8839 | { |
| 8840 | struct bnx2x *bp = netdev_priv(dev); |
| 8841 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8842 | if (IS_E1HMF(bp)) |
| 8843 | return 0; |
| 8844 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8845 | DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n" |
| 8846 | DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n", |
| 8847 | epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause); |
| 8848 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8849 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8850 | |
| 8851 | if (epause->rx_pause) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8852 | bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8853 | |
| 8854 | if (epause->tx_pause) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8855 | bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8856 | |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8857 | if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) |
| 8858 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8859 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8860 | if (epause->autoneg) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8861 | if (!(bp->port.supported & SUPPORTED_Autoneg)) { |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 8862 | DP(NETIF_MSG_LINK, "autoneg not supported\n"); |
Eliezer Tamir | f141064 | 2008-02-28 11:51:50 -0800 | [diff] [blame] | 8863 | return -EINVAL; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8864 | } |
| 8865 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8866 | if (bp->link_params.req_line_speed == SPEED_AUTO_NEG) |
David S. Miller | c0700f9 | 2008-12-16 23:53:20 -0800 | [diff] [blame] | 8867 | bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO; |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8868 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8869 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 8870 | DP(NETIF_MSG_LINK, |
| 8871 | "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8872 | |
| 8873 | if (netif_running(dev)) { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 8874 | bnx2x_stats_handle(bp, STATS_EVENT_STOP); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 8875 | bnx2x_link_set(bp); |
| 8876 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8877 | |
| 8878 | return 0; |
| 8879 | } |
| 8880 | |
Vladislav Zolotarov | df0f234 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 8881 | static int bnx2x_set_flags(struct net_device *dev, u32 data) |
| 8882 | { |
| 8883 | struct bnx2x *bp = netdev_priv(dev); |
| 8884 | int changed = 0; |
| 8885 | int rc = 0; |
| 8886 | |
| 8887 | /* TPA requires Rx CSUM offloading */ |
| 8888 | if ((data & ETH_FLAG_LRO) && bp->rx_csum) { |
| 8889 | if (!(dev->features & NETIF_F_LRO)) { |
| 8890 | dev->features |= NETIF_F_LRO; |
| 8891 | bp->flags |= TPA_ENABLE_FLAG; |
| 8892 | changed = 1; |
| 8893 | } |
| 8894 | |
| 8895 | } else if (dev->features & NETIF_F_LRO) { |
| 8896 | dev->features &= ~NETIF_F_LRO; |
| 8897 | bp->flags &= ~TPA_ENABLE_FLAG; |
| 8898 | changed = 1; |
| 8899 | } |
| 8900 | |
| 8901 | if (changed && netif_running(dev)) { |
| 8902 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 8903 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
| 8904 | } |
| 8905 | |
| 8906 | return rc; |
| 8907 | } |
| 8908 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8909 | static u32 bnx2x_get_rx_csum(struct net_device *dev) |
| 8910 | { |
| 8911 | struct bnx2x *bp = netdev_priv(dev); |
| 8912 | |
| 8913 | return bp->rx_csum; |
| 8914 | } |
| 8915 | |
| 8916 | static int bnx2x_set_rx_csum(struct net_device *dev, u32 data) |
| 8917 | { |
| 8918 | struct bnx2x *bp = netdev_priv(dev); |
Vladislav Zolotarov | df0f234 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 8919 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8920 | |
| 8921 | bp->rx_csum = data; |
Vladislav Zolotarov | df0f234 | 2008-08-13 15:53:38 -0700 | [diff] [blame] | 8922 | |
| 8923 | /* Disable TPA, when Rx CSUM is disabled. Otherwise all |
| 8924 | TPA'ed packets will be discarded due to wrong TCP CSUM */ |
| 8925 | if (!data) { |
| 8926 | u32 flags = ethtool_op_get_flags(dev); |
| 8927 | |
| 8928 | rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO)); |
| 8929 | } |
| 8930 | |
| 8931 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8932 | } |
| 8933 | |
| 8934 | static int bnx2x_set_tso(struct net_device *dev, u32 data) |
| 8935 | { |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 8936 | if (data) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8937 | dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 8938 | dev->features |= NETIF_F_TSO6; |
| 8939 | } else { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8940 | dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 8941 | dev->features &= ~NETIF_F_TSO6; |
| 8942 | } |
| 8943 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8944 | return 0; |
| 8945 | } |
| 8946 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 8947 | static const struct { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8948 | char string[ETH_GSTRING_LEN]; |
| 8949 | } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = { |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 8950 | { "register_test (offline)" }, |
| 8951 | { "memory_test (offline)" }, |
| 8952 | { "loopback_test (offline)" }, |
| 8953 | { "nvram_test (online)" }, |
| 8954 | { "interrupt_test (online)" }, |
| 8955 | { "link_test (online)" }, |
Eilon Greenstein | d3d4f49 | 2009-02-12 08:36:27 +0000 | [diff] [blame] | 8956 | { "idle check (online)" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 8957 | }; |
| 8958 | |
| 8959 | static int bnx2x_self_test_count(struct net_device *dev) |
| 8960 | { |
| 8961 | return BNX2X_NUM_TESTS; |
| 8962 | } |
| 8963 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 8964 | static int bnx2x_test_registers(struct bnx2x *bp) |
| 8965 | { |
| 8966 | int idx, i, rc = -ENODEV; |
| 8967 | u32 wr_val = 0; |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 8968 | int port = BP_PORT(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 8969 | static const struct { |
| 8970 | u32 offset0; |
| 8971 | u32 offset1; |
| 8972 | u32 mask; |
| 8973 | } reg_tbl[] = { |
| 8974 | /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff }, |
| 8975 | { DORQ_REG_DB_ADDR0, 4, 0xffffffff }, |
| 8976 | { HC_REG_AGG_INT_0, 4, 0x000003ff }, |
| 8977 | { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 }, |
| 8978 | { PBF_REG_P0_INIT_CRD, 4, 0x000007ff }, |
| 8979 | { PRS_REG_CID_PORT_0, 4, 0x00ffffff }, |
| 8980 | { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff }, |
| 8981 | { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff }, |
| 8982 | { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff }, |
| 8983 | { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff }, |
| 8984 | /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff }, |
| 8985 | { QM_REG_CONNNUM_0, 4, 0x000fffff }, |
| 8986 | { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff }, |
| 8987 | { SRC_REG_KEYRSS0_0, 40, 0xffffffff }, |
| 8988 | { SRC_REG_KEYRSS0_7, 40, 0xffffffff }, |
| 8989 | { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 }, |
| 8990 | { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 }, |
| 8991 | { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff }, |
| 8992 | { NIG_REG_EGRESS_MNG0_FIFO, 20, 0xffffffff }, |
| 8993 | { NIG_REG_LLH0_T_BIT, 4, 0x00000001 }, |
| 8994 | /* 20 */ { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 }, |
| 8995 | { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 }, |
| 8996 | { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 }, |
| 8997 | { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 }, |
| 8998 | { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 }, |
| 8999 | { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff }, |
| 9000 | { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff }, |
| 9001 | { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff }, |
| 9002 | { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff }, |
| 9003 | { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 }, |
| 9004 | /* 30 */ { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff }, |
| 9005 | { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff }, |
| 9006 | { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff }, |
| 9007 | { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 }, |
| 9008 | { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 }, |
| 9009 | { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff }, |
| 9010 | { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 }, |
| 9011 | { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f }, |
| 9012 | |
| 9013 | { 0xffffffff, 0, 0x00000000 } |
| 9014 | }; |
| 9015 | |
| 9016 | if (!netif_running(bp->dev)) |
| 9017 | return rc; |
| 9018 | |
| 9019 | /* Repeat the test twice: |
| 9020 | First by writing 0x00000000, second by writing 0xffffffff */ |
| 9021 | for (idx = 0; idx < 2; idx++) { |
| 9022 | |
| 9023 | switch (idx) { |
| 9024 | case 0: |
| 9025 | wr_val = 0; |
| 9026 | break; |
| 9027 | case 1: |
| 9028 | wr_val = 0xffffffff; |
| 9029 | break; |
| 9030 | } |
| 9031 | |
| 9032 | for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) { |
| 9033 | u32 offset, mask, save_val, val; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9034 | |
| 9035 | offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1; |
| 9036 | mask = reg_tbl[i].mask; |
| 9037 | |
| 9038 | save_val = REG_RD(bp, offset); |
| 9039 | |
| 9040 | REG_WR(bp, offset, wr_val); |
| 9041 | val = REG_RD(bp, offset); |
| 9042 | |
| 9043 | /* Restore the original register's value */ |
| 9044 | REG_WR(bp, offset, save_val); |
| 9045 | |
| 9046 | /* verify that value is as expected value */ |
| 9047 | if ((val & mask) != (wr_val & mask)) |
| 9048 | goto test_reg_exit; |
| 9049 | } |
| 9050 | } |
| 9051 | |
| 9052 | rc = 0; |
| 9053 | |
| 9054 | test_reg_exit: |
| 9055 | return rc; |
| 9056 | } |
| 9057 | |
| 9058 | static int bnx2x_test_memory(struct bnx2x *bp) |
| 9059 | { |
| 9060 | int i, j, rc = -ENODEV; |
| 9061 | u32 val; |
| 9062 | static const struct { |
| 9063 | u32 offset; |
| 9064 | int size; |
| 9065 | } mem_tbl[] = { |
| 9066 | { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9067 | { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE }, |
| 9068 | { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE }, |
| 9069 | { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE }, |
| 9070 | { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9071 | { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9072 | { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE }, |
| 9073 | |
| 9074 | { 0xffffffff, 0 } |
| 9075 | }; |
| 9076 | static const struct { |
| 9077 | char *name; |
| 9078 | u32 offset; |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9079 | u32 e1_mask; |
| 9080 | u32 e1h_mask; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9081 | } prty_tbl[] = { |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9082 | { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9083 | { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 }, |
| 9084 | { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 }, |
| 9085 | { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9086 | { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 }, |
| 9087 | { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 }, |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9088 | |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9089 | { NULL, 0xffffffff, 0, 0 } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9090 | }; |
| 9091 | |
| 9092 | if (!netif_running(bp->dev)) |
| 9093 | return rc; |
| 9094 | |
| 9095 | /* Go through all the memories */ |
| 9096 | for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) |
| 9097 | for (j = 0; j < mem_tbl[i].size; j++) |
| 9098 | REG_RD(bp, mem_tbl[i].offset + j*4); |
| 9099 | |
| 9100 | /* Check the parity status */ |
| 9101 | for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) { |
| 9102 | val = REG_RD(bp, prty_tbl[i].offset); |
Yitchak Gertner | 9dabc42 | 2008-08-13 15:51:28 -0700 | [diff] [blame] | 9103 | if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) || |
| 9104 | (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) { |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9105 | DP(NETIF_MSG_HW, |
| 9106 | "%s is 0x%x\n", prty_tbl[i].name, val); |
| 9107 | goto test_mem_exit; |
| 9108 | } |
| 9109 | } |
| 9110 | |
| 9111 | rc = 0; |
| 9112 | |
| 9113 | test_mem_exit: |
| 9114 | return rc; |
| 9115 | } |
| 9116 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9117 | static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up) |
| 9118 | { |
| 9119 | int cnt = 1000; |
| 9120 | |
| 9121 | if (link_up) |
| 9122 | while (bnx2x_link_test(bp) && cnt--) |
| 9123 | msleep(10); |
| 9124 | } |
| 9125 | |
| 9126 | static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up) |
| 9127 | { |
| 9128 | unsigned int pkt_size, num_pkts, i; |
| 9129 | struct sk_buff *skb; |
| 9130 | unsigned char *packet; |
| 9131 | struct bnx2x_fastpath *fp = &bp->fp[0]; |
| 9132 | u16 tx_start_idx, tx_idx; |
| 9133 | u16 rx_start_idx, rx_idx; |
| 9134 | u16 pkt_prod; |
| 9135 | struct sw_tx_bd *tx_buf; |
| 9136 | struct eth_tx_bd *tx_bd; |
| 9137 | dma_addr_t mapping; |
| 9138 | union eth_rx_cqe *cqe; |
| 9139 | u8 cqe_fp_flags; |
| 9140 | struct sw_rx_bd *rx_buf; |
| 9141 | u16 len; |
| 9142 | int rc = -ENODEV; |
| 9143 | |
| 9144 | if (loopback_mode == BNX2X_MAC_LOOPBACK) { |
| 9145 | bp->link_params.loopback_mode = LOOPBACK_BMAC; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9146 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9147 | |
| 9148 | } else if (loopback_mode == BNX2X_PHY_LOOPBACK) { |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 9149 | u16 cnt = 1000; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9150 | bp->link_params.loopback_mode = LOOPBACK_XGXS_10; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9151 | bnx2x_phy_init(&bp->link_params, &bp->link_vars); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9152 | /* wait until link state is restored */ |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 9153 | if (link_up) |
| 9154 | while (cnt-- && bnx2x_test_link(&bp->link_params, |
| 9155 | &bp->link_vars)) |
| 9156 | msleep(10); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9157 | } else |
| 9158 | return -EINVAL; |
| 9159 | |
| 9160 | pkt_size = 1514; |
| 9161 | skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size); |
| 9162 | if (!skb) { |
| 9163 | rc = -ENOMEM; |
| 9164 | goto test_loopback_exit; |
| 9165 | } |
| 9166 | packet = skb_put(skb, pkt_size); |
| 9167 | memcpy(packet, bp->dev->dev_addr, ETH_ALEN); |
| 9168 | memset(packet + ETH_ALEN, 0, (ETH_HLEN - ETH_ALEN)); |
| 9169 | for (i = ETH_HLEN; i < pkt_size; i++) |
| 9170 | packet[i] = (unsigned char) (i & 0xff); |
| 9171 | |
| 9172 | num_pkts = 0; |
| 9173 | tx_start_idx = le16_to_cpu(*fp->tx_cons_sb); |
| 9174 | rx_start_idx = le16_to_cpu(*fp->rx_cons_sb); |
| 9175 | |
| 9176 | pkt_prod = fp->tx_pkt_prod++; |
| 9177 | tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)]; |
| 9178 | tx_buf->first_bd = fp->tx_bd_prod; |
| 9179 | tx_buf->skb = skb; |
| 9180 | |
| 9181 | tx_bd = &fp->tx_desc_ring[TX_BD(fp->tx_bd_prod)]; |
| 9182 | mapping = pci_map_single(bp->pdev, skb->data, |
| 9183 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 9184 | tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 9185 | tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 9186 | tx_bd->nbd = cpu_to_le16(1); |
| 9187 | tx_bd->nbytes = cpu_to_le16(skb_headlen(skb)); |
| 9188 | tx_bd->vlan = cpu_to_le16(pkt_prod); |
| 9189 | tx_bd->bd_flags.as_bitfield = (ETH_TX_BD_FLAGS_START_BD | |
| 9190 | ETH_TX_BD_FLAGS_END_BD); |
| 9191 | tx_bd->general_data = ((UNICAST_ADDRESS << |
| 9192 | ETH_TX_BD_ETH_ADDR_TYPE_SHIFT) | 1); |
| 9193 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 9194 | wmb(); |
| 9195 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9196 | fp->hw_tx_prods->bds_prod = |
| 9197 | cpu_to_le16(le16_to_cpu(fp->hw_tx_prods->bds_prod) + 1); |
| 9198 | mb(); /* FW restriction: must not reorder writing nbd and packets */ |
| 9199 | fp->hw_tx_prods->packets_prod = |
| 9200 | cpu_to_le32(le32_to_cpu(fp->hw_tx_prods->packets_prod) + 1); |
| 9201 | DOORBELL(bp, FP_IDX(fp), 0); |
| 9202 | |
| 9203 | mmiowb(); |
| 9204 | |
| 9205 | num_pkts++; |
| 9206 | fp->tx_bd_prod++; |
| 9207 | bp->dev->trans_start = jiffies; |
| 9208 | |
| 9209 | udelay(100); |
| 9210 | |
| 9211 | tx_idx = le16_to_cpu(*fp->tx_cons_sb); |
| 9212 | if (tx_idx != tx_start_idx + num_pkts) |
| 9213 | goto test_loopback_exit; |
| 9214 | |
| 9215 | rx_idx = le16_to_cpu(*fp->rx_cons_sb); |
| 9216 | if (rx_idx != rx_start_idx + num_pkts) |
| 9217 | goto test_loopback_exit; |
| 9218 | |
| 9219 | cqe = &fp->rx_comp_ring[RCQ_BD(fp->rx_comp_cons)]; |
| 9220 | cqe_fp_flags = cqe->fast_path_cqe.type_error_flags; |
| 9221 | if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS)) |
| 9222 | goto test_loopback_rx_exit; |
| 9223 | |
| 9224 | len = le16_to_cpu(cqe->fast_path_cqe.pkt_len); |
| 9225 | if (len != pkt_size) |
| 9226 | goto test_loopback_rx_exit; |
| 9227 | |
| 9228 | rx_buf = &fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)]; |
| 9229 | skb = rx_buf->skb; |
| 9230 | skb_reserve(skb, cqe->fast_path_cqe.placement_offset); |
| 9231 | for (i = ETH_HLEN; i < pkt_size; i++) |
| 9232 | if (*(skb->data + i) != (unsigned char) (i & 0xff)) |
| 9233 | goto test_loopback_rx_exit; |
| 9234 | |
| 9235 | rc = 0; |
| 9236 | |
| 9237 | test_loopback_rx_exit: |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9238 | |
| 9239 | fp->rx_bd_cons = NEXT_RX_IDX(fp->rx_bd_cons); |
| 9240 | fp->rx_bd_prod = NEXT_RX_IDX(fp->rx_bd_prod); |
| 9241 | fp->rx_comp_cons = NEXT_RCQ_IDX(fp->rx_comp_cons); |
| 9242 | fp->rx_comp_prod = NEXT_RCQ_IDX(fp->rx_comp_prod); |
| 9243 | |
| 9244 | /* Update producers */ |
| 9245 | bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod, |
| 9246 | fp->rx_sge_prod); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9247 | |
| 9248 | test_loopback_exit: |
| 9249 | bp->link_params.loopback_mode = LOOPBACK_NONE; |
| 9250 | |
| 9251 | return rc; |
| 9252 | } |
| 9253 | |
| 9254 | static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up) |
| 9255 | { |
| 9256 | int rc = 0; |
| 9257 | |
| 9258 | if (!netif_running(bp->dev)) |
| 9259 | return BNX2X_LOOPBACK_FAILED; |
| 9260 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 9261 | bnx2x_netif_stop(bp, 1); |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 9262 | bnx2x_acquire_phy_lock(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9263 | |
| 9264 | if (bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up)) { |
| 9265 | DP(NETIF_MSG_PROBE, "MAC loopback failed\n"); |
| 9266 | rc |= BNX2X_MAC_LOOPBACK_FAILED; |
| 9267 | } |
| 9268 | |
| 9269 | if (bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up)) { |
| 9270 | DP(NETIF_MSG_PROBE, "PHY loopback failed\n"); |
| 9271 | rc |= BNX2X_PHY_LOOPBACK_FAILED; |
| 9272 | } |
| 9273 | |
Eilon Greenstein | 3910c8a | 2009-01-22 06:01:32 +0000 | [diff] [blame] | 9274 | bnx2x_release_phy_lock(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9275 | bnx2x_netif_start(bp); |
| 9276 | |
| 9277 | return rc; |
| 9278 | } |
| 9279 | |
| 9280 | #define CRC32_RESIDUAL 0xdebb20e3 |
| 9281 | |
| 9282 | static int bnx2x_test_nvram(struct bnx2x *bp) |
| 9283 | { |
| 9284 | static const struct { |
| 9285 | int offset; |
| 9286 | int size; |
| 9287 | } nvram_tbl[] = { |
| 9288 | { 0, 0x14 }, /* bootstrap */ |
| 9289 | { 0x14, 0xec }, /* dir */ |
| 9290 | { 0x100, 0x350 }, /* manuf_info */ |
| 9291 | { 0x450, 0xf0 }, /* feature_info */ |
| 9292 | { 0x640, 0x64 }, /* upgrade_key_info */ |
| 9293 | { 0x6a4, 0x64 }, |
| 9294 | { 0x708, 0x70 }, /* manuf_key_info */ |
| 9295 | { 0x778, 0x70 }, |
| 9296 | { 0, 0 } |
| 9297 | }; |
| 9298 | u32 buf[0x350 / 4]; |
| 9299 | u8 *data = (u8 *)buf; |
| 9300 | int i, rc; |
| 9301 | u32 magic, csum; |
| 9302 | |
| 9303 | rc = bnx2x_nvram_read(bp, 0, data, 4); |
| 9304 | if (rc) { |
| 9305 | DP(NETIF_MSG_PROBE, "magic value read (rc -%d)\n", -rc); |
| 9306 | goto test_nvram_exit; |
| 9307 | } |
| 9308 | |
| 9309 | magic = be32_to_cpu(buf[0]); |
| 9310 | if (magic != 0x669955aa) { |
| 9311 | DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic); |
| 9312 | rc = -ENODEV; |
| 9313 | goto test_nvram_exit; |
| 9314 | } |
| 9315 | |
| 9316 | for (i = 0; nvram_tbl[i].size; i++) { |
| 9317 | |
| 9318 | rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data, |
| 9319 | nvram_tbl[i].size); |
| 9320 | if (rc) { |
| 9321 | DP(NETIF_MSG_PROBE, |
| 9322 | "nvram_tbl[%d] read data (rc -%d)\n", i, -rc); |
| 9323 | goto test_nvram_exit; |
| 9324 | } |
| 9325 | |
| 9326 | csum = ether_crc_le(nvram_tbl[i].size, data); |
| 9327 | if (csum != CRC32_RESIDUAL) { |
| 9328 | DP(NETIF_MSG_PROBE, |
| 9329 | "nvram_tbl[%d] csum value (0x%08x)\n", i, csum); |
| 9330 | rc = -ENODEV; |
| 9331 | goto test_nvram_exit; |
| 9332 | } |
| 9333 | } |
| 9334 | |
| 9335 | test_nvram_exit: |
| 9336 | return rc; |
| 9337 | } |
| 9338 | |
| 9339 | static int bnx2x_test_intr(struct bnx2x *bp) |
| 9340 | { |
| 9341 | struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config); |
| 9342 | int i, rc; |
| 9343 | |
| 9344 | if (!netif_running(bp->dev)) |
| 9345 | return -ENODEV; |
| 9346 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 9347 | config->hdr.length = 0; |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 9348 | if (CHIP_IS_E1(bp)) |
| 9349 | config->hdr.offset = (BP_PORT(bp) ? 32 : 0); |
| 9350 | else |
| 9351 | config->hdr.offset = BP_FUNC(bp); |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9352 | config->hdr.client_id = BP_CL_ID(bp); |
| 9353 | config->hdr.reserved1 = 0; |
| 9354 | |
| 9355 | rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 9356 | U64_HI(bnx2x_sp_mapping(bp, mac_config)), |
| 9357 | U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0); |
| 9358 | if (rc == 0) { |
| 9359 | bp->set_mac_pending++; |
| 9360 | for (i = 0; i < 10; i++) { |
| 9361 | if (!bp->set_mac_pending) |
| 9362 | break; |
| 9363 | msleep_interruptible(10); |
| 9364 | } |
| 9365 | if (i == 10) |
| 9366 | rc = -ENODEV; |
| 9367 | } |
| 9368 | |
| 9369 | return rc; |
| 9370 | } |
| 9371 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9372 | static void bnx2x_self_test(struct net_device *dev, |
| 9373 | struct ethtool_test *etest, u64 *buf) |
| 9374 | { |
| 9375 | struct bnx2x *bp = netdev_priv(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9376 | |
| 9377 | memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS); |
| 9378 | |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9379 | if (!netif_running(dev)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9380 | return; |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9381 | |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 9382 | /* offline tests are not supported in MF mode */ |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9383 | if (IS_E1HMF(bp)) |
| 9384 | etest->flags &= ~ETH_TEST_FL_OFFLINE; |
| 9385 | |
| 9386 | if (etest->flags & ETH_TEST_FL_OFFLINE) { |
| 9387 | u8 link_up; |
| 9388 | |
| 9389 | link_up = bp->link_vars.link_up; |
| 9390 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9391 | bnx2x_nic_load(bp, LOAD_DIAG); |
| 9392 | /* wait until link state is restored */ |
| 9393 | bnx2x_wait_for_link(bp, link_up); |
| 9394 | |
| 9395 | if (bnx2x_test_registers(bp) != 0) { |
| 9396 | buf[0] = 1; |
| 9397 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9398 | } |
| 9399 | if (bnx2x_test_memory(bp) != 0) { |
| 9400 | buf[1] = 1; |
| 9401 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9402 | } |
| 9403 | buf[2] = bnx2x_test_loopback(bp, link_up); |
| 9404 | if (buf[2] != 0) |
| 9405 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9406 | |
| 9407 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 9408 | bnx2x_nic_load(bp, LOAD_NORMAL); |
| 9409 | /* wait until link state is restored */ |
| 9410 | bnx2x_wait_for_link(bp, link_up); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9411 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9412 | if (bnx2x_test_nvram(bp) != 0) { |
| 9413 | buf[3] = 1; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9414 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9415 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9416 | if (bnx2x_test_intr(bp) != 0) { |
| 9417 | buf[4] = 1; |
| 9418 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9419 | } |
| 9420 | if (bp->port.pmf) |
| 9421 | if (bnx2x_link_test(bp) != 0) { |
| 9422 | buf[5] = 1; |
| 9423 | etest->flags |= ETH_TEST_FL_FAILED; |
| 9424 | } |
Yitchak Gertner | f3c87cd | 2008-06-23 20:35:51 -0700 | [diff] [blame] | 9425 | |
| 9426 | #ifdef BNX2X_EXTRA_DEBUG |
| 9427 | bnx2x_panic_dump(bp); |
| 9428 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9429 | } |
| 9430 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9431 | static const struct { |
| 9432 | long offset; |
| 9433 | int size; |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9434 | u8 string[ETH_GSTRING_LEN]; |
| 9435 | } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = { |
| 9436 | /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" }, |
| 9437 | { Q_STATS_OFFSET32(error_bytes_received_hi), |
| 9438 | 8, "[%d]: rx_error_bytes" }, |
| 9439 | { Q_STATS_OFFSET32(total_unicast_packets_received_hi), |
| 9440 | 8, "[%d]: rx_ucast_packets" }, |
| 9441 | { Q_STATS_OFFSET32(total_multicast_packets_received_hi), |
| 9442 | 8, "[%d]: rx_mcast_packets" }, |
| 9443 | { Q_STATS_OFFSET32(total_broadcast_packets_received_hi), |
| 9444 | 8, "[%d]: rx_bcast_packets" }, |
| 9445 | { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" }, |
| 9446 | { Q_STATS_OFFSET32(rx_err_discard_pkt), |
| 9447 | 4, "[%d]: rx_phy_ip_err_discards"}, |
| 9448 | { Q_STATS_OFFSET32(rx_skb_alloc_failed), |
| 9449 | 4, "[%d]: rx_skb_alloc_discard" }, |
| 9450 | { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" }, |
| 9451 | |
| 9452 | /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" }, |
| 9453 | { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi), |
| 9454 | 8, "[%d]: tx_packets" } |
| 9455 | }; |
| 9456 | |
| 9457 | static const struct { |
| 9458 | long offset; |
| 9459 | int size; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9460 | u32 flags; |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9461 | #define STATS_FLAGS_PORT 1 |
| 9462 | #define STATS_FLAGS_FUNC 2 |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9463 | #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT) |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9464 | u8 string[ETH_GSTRING_LEN]; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9465 | } bnx2x_stats_arr[BNX2X_NUM_STATS] = { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9466 | /* 1 */ { STATS_OFFSET32(total_bytes_received_hi), |
| 9467 | 8, STATS_FLAGS_BOTH, "rx_bytes" }, |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9468 | { STATS_OFFSET32(error_bytes_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9469 | 8, STATS_FLAGS_BOTH, "rx_error_bytes" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9470 | { STATS_OFFSET32(total_unicast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9471 | 8, STATS_FLAGS_BOTH, "rx_ucast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9472 | { STATS_OFFSET32(total_multicast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9473 | 8, STATS_FLAGS_BOTH, "rx_mcast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9474 | { STATS_OFFSET32(total_broadcast_packets_received_hi), |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9475 | 8, STATS_FLAGS_BOTH, "rx_bcast_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9476 | { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9477 | 8, STATS_FLAGS_PORT, "rx_crc_errors" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9478 | { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9479 | 8, STATS_FLAGS_PORT, "rx_align_errors" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9480 | { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi), |
| 9481 | 8, STATS_FLAGS_PORT, "rx_undersize_packets" }, |
| 9482 | { STATS_OFFSET32(etherstatsoverrsizepkts_hi), |
| 9483 | 8, STATS_FLAGS_PORT, "rx_oversize_packets" }, |
| 9484 | /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi), |
| 9485 | 8, STATS_FLAGS_PORT, "rx_fragments" }, |
| 9486 | { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi), |
| 9487 | 8, STATS_FLAGS_PORT, "rx_jabbers" }, |
| 9488 | { STATS_OFFSET32(no_buff_discard_hi), |
| 9489 | 8, STATS_FLAGS_BOTH, "rx_discards" }, |
| 9490 | { STATS_OFFSET32(mac_filter_discard), |
| 9491 | 4, STATS_FLAGS_PORT, "rx_filtered_packets" }, |
| 9492 | { STATS_OFFSET32(xxoverflow_discard), |
| 9493 | 4, STATS_FLAGS_PORT, "rx_fw_discards" }, |
| 9494 | { STATS_OFFSET32(brb_drop_hi), |
| 9495 | 8, STATS_FLAGS_PORT, "rx_brb_discard" }, |
| 9496 | { STATS_OFFSET32(brb_truncate_hi), |
| 9497 | 8, STATS_FLAGS_PORT, "rx_brb_truncate" }, |
| 9498 | { STATS_OFFSET32(pause_frames_received_hi), |
| 9499 | 8, STATS_FLAGS_PORT, "rx_pause_frames" }, |
| 9500 | { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi), |
| 9501 | 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" }, |
| 9502 | { STATS_OFFSET32(nig_timer_max), |
| 9503 | 4, STATS_FLAGS_PORT, "rx_constant_pause_events" }, |
| 9504 | /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt), |
| 9505 | 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"}, |
| 9506 | { STATS_OFFSET32(rx_skb_alloc_failed), |
| 9507 | 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" }, |
| 9508 | { STATS_OFFSET32(hw_csum_err), |
| 9509 | 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" }, |
| 9510 | |
| 9511 | { STATS_OFFSET32(total_bytes_transmitted_hi), |
| 9512 | 8, STATS_FLAGS_BOTH, "tx_bytes" }, |
| 9513 | { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi), |
| 9514 | 8, STATS_FLAGS_PORT, "tx_error_bytes" }, |
| 9515 | { STATS_OFFSET32(total_unicast_packets_transmitted_hi), |
| 9516 | 8, STATS_FLAGS_BOTH, "tx_packets" }, |
| 9517 | { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi), |
| 9518 | 8, STATS_FLAGS_PORT, "tx_mac_errors" }, |
| 9519 | { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi), |
| 9520 | 8, STATS_FLAGS_PORT, "tx_carrier_errors" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9521 | { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9522 | 8, STATS_FLAGS_PORT, "tx_single_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9523 | { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9524 | 8, STATS_FLAGS_PORT, "tx_multi_collisions" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9525 | /* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9526 | 8, STATS_FLAGS_PORT, "tx_deferred" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9527 | { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9528 | 8, STATS_FLAGS_PORT, "tx_excess_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9529 | { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9530 | 8, STATS_FLAGS_PORT, "tx_late_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9531 | { STATS_OFFSET32(tx_stat_etherstatscollisions_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9532 | 8, STATS_FLAGS_PORT, "tx_total_collisions" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9533 | { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9534 | 8, STATS_FLAGS_PORT, "tx_64_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9535 | { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9536 | 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9537 | { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9538 | 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9539 | { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9540 | 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9541 | { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9542 | 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" }, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9543 | { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9544 | 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9545 | /* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi), |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9546 | 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" }, |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9547 | { STATS_OFFSET32(pause_frames_sent_hi), |
| 9548 | 8, STATS_FLAGS_PORT, "tx_pause_frames" } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9549 | }; |
| 9550 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9551 | #define IS_PORT_STAT(i) \ |
| 9552 | ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT) |
| 9553 | #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC) |
| 9554 | #define IS_E1HMF_MODE_STAT(bp) \ |
| 9555 | (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS)) |
Yitchak Gertner | 66e855f | 2008-08-13 15:49:05 -0700 | [diff] [blame] | 9556 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9557 | static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
| 9558 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9559 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9560 | int i, j, k; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9561 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9562 | switch (stringset) { |
| 9563 | case ETH_SS_STATS: |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9564 | if (is_multi(bp)) { |
| 9565 | k = 0; |
| 9566 | for_each_queue(bp, i) { |
| 9567 | for (j = 0; j < BNX2X_NUM_Q_STATS; j++) |
| 9568 | sprintf(buf + (k + j)*ETH_GSTRING_LEN, |
| 9569 | bnx2x_q_stats_arr[j].string, i); |
| 9570 | k += BNX2X_NUM_Q_STATS; |
| 9571 | } |
| 9572 | if (IS_E1HMF_MODE_STAT(bp)) |
| 9573 | break; |
| 9574 | for (j = 0; j < BNX2X_NUM_STATS; j++) |
| 9575 | strcpy(buf + (k + j)*ETH_GSTRING_LEN, |
| 9576 | bnx2x_stats_arr[j].string); |
| 9577 | } else { |
| 9578 | for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) { |
| 9579 | if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i)) |
| 9580 | continue; |
| 9581 | strcpy(buf + j*ETH_GSTRING_LEN, |
| 9582 | bnx2x_stats_arr[i].string); |
| 9583 | j++; |
| 9584 | } |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9585 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9586 | break; |
| 9587 | |
| 9588 | case ETH_SS_TEST: |
| 9589 | memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr)); |
| 9590 | break; |
| 9591 | } |
| 9592 | } |
| 9593 | |
| 9594 | static int bnx2x_get_stats_count(struct net_device *dev) |
| 9595 | { |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9596 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9597 | int i, num_stats; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9598 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9599 | if (is_multi(bp)) { |
| 9600 | num_stats = BNX2X_NUM_Q_STATS * BNX2X_NUM_QUEUES(bp); |
| 9601 | if (!IS_E1HMF_MODE_STAT(bp)) |
| 9602 | num_stats += BNX2X_NUM_STATS; |
| 9603 | } else { |
| 9604 | if (IS_E1HMF_MODE_STAT(bp)) { |
| 9605 | num_stats = 0; |
| 9606 | for (i = 0; i < BNX2X_NUM_STATS; i++) |
| 9607 | if (IS_FUNC_STAT(i)) |
| 9608 | num_stats++; |
| 9609 | } else |
| 9610 | num_stats = BNX2X_NUM_STATS; |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9611 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9612 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9613 | return num_stats; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9614 | } |
| 9615 | |
| 9616 | static void bnx2x_get_ethtool_stats(struct net_device *dev, |
| 9617 | struct ethtool_stats *stats, u64 *buf) |
| 9618 | { |
| 9619 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9620 | u32 *hw_stats, *offset; |
| 9621 | int i, j, k; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9622 | |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9623 | if (is_multi(bp)) { |
| 9624 | k = 0; |
| 9625 | for_each_queue(bp, i) { |
| 9626 | hw_stats = (u32 *)&bp->fp[i].eth_q_stats; |
| 9627 | for (j = 0; j < BNX2X_NUM_Q_STATS; j++) { |
| 9628 | if (bnx2x_q_stats_arr[j].size == 0) { |
| 9629 | /* skip this counter */ |
| 9630 | buf[k + j] = 0; |
| 9631 | continue; |
| 9632 | } |
| 9633 | offset = (hw_stats + |
| 9634 | bnx2x_q_stats_arr[j].offset); |
| 9635 | if (bnx2x_q_stats_arr[j].size == 4) { |
| 9636 | /* 4-byte counter */ |
| 9637 | buf[k + j] = (u64) *offset; |
| 9638 | continue; |
| 9639 | } |
| 9640 | /* 8-byte counter */ |
| 9641 | buf[k + j] = HILO_U64(*offset, *(offset + 1)); |
| 9642 | } |
| 9643 | k += BNX2X_NUM_Q_STATS; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9644 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9645 | if (IS_E1HMF_MODE_STAT(bp)) |
| 9646 | return; |
| 9647 | hw_stats = (u32 *)&bp->eth_stats; |
| 9648 | for (j = 0; j < BNX2X_NUM_STATS; j++) { |
| 9649 | if (bnx2x_stats_arr[j].size == 0) { |
| 9650 | /* skip this counter */ |
| 9651 | buf[k + j] = 0; |
| 9652 | continue; |
| 9653 | } |
| 9654 | offset = (hw_stats + bnx2x_stats_arr[j].offset); |
| 9655 | if (bnx2x_stats_arr[j].size == 4) { |
| 9656 | /* 4-byte counter */ |
| 9657 | buf[k + j] = (u64) *offset; |
| 9658 | continue; |
| 9659 | } |
| 9660 | /* 8-byte counter */ |
| 9661 | buf[k + j] = HILO_U64(*offset, *(offset + 1)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9662 | } |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 9663 | } else { |
| 9664 | hw_stats = (u32 *)&bp->eth_stats; |
| 9665 | for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) { |
| 9666 | if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i)) |
| 9667 | continue; |
| 9668 | if (bnx2x_stats_arr[i].size == 0) { |
| 9669 | /* skip this counter */ |
| 9670 | buf[j] = 0; |
| 9671 | j++; |
| 9672 | continue; |
| 9673 | } |
| 9674 | offset = (hw_stats + bnx2x_stats_arr[i].offset); |
| 9675 | if (bnx2x_stats_arr[i].size == 4) { |
| 9676 | /* 4-byte counter */ |
| 9677 | buf[j] = (u64) *offset; |
| 9678 | j++; |
| 9679 | continue; |
| 9680 | } |
| 9681 | /* 8-byte counter */ |
| 9682 | buf[j] = HILO_U64(*offset, *(offset + 1)); |
| 9683 | j++; |
| 9684 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9685 | } |
| 9686 | } |
| 9687 | |
| 9688 | static int bnx2x_phys_id(struct net_device *dev, u32 data) |
| 9689 | { |
| 9690 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9691 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9692 | int i; |
| 9693 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9694 | if (!netif_running(dev)) |
| 9695 | return 0; |
| 9696 | |
| 9697 | if (!bp->port.pmf) |
| 9698 | return 0; |
| 9699 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9700 | if (data == 0) |
| 9701 | data = 2; |
| 9702 | |
| 9703 | for (i = 0; i < (data * 2); i++) { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9704 | if ((i % 2) == 0) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9705 | bnx2x_set_led(bp, port, LED_MODE_OPER, SPEED_1000, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9706 | bp->link_params.hw_led_mode, |
| 9707 | bp->link_params.chip_id); |
| 9708 | else |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9709 | bnx2x_set_led(bp, port, LED_MODE_OFF, 0, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9710 | bp->link_params.hw_led_mode, |
| 9711 | bp->link_params.chip_id); |
| 9712 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9713 | msleep_interruptible(500); |
| 9714 | if (signal_pending(current)) |
| 9715 | break; |
| 9716 | } |
| 9717 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9718 | if (bp->link_vars.link_up) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9719 | bnx2x_set_led(bp, port, LED_MODE_OPER, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 9720 | bp->link_vars.line_speed, |
| 9721 | bp->link_params.hw_led_mode, |
| 9722 | bp->link_params.chip_id); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9723 | |
| 9724 | return 0; |
| 9725 | } |
| 9726 | |
| 9727 | static struct ethtool_ops bnx2x_ethtool_ops = { |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9728 | .get_settings = bnx2x_get_settings, |
| 9729 | .set_settings = bnx2x_set_settings, |
| 9730 | .get_drvinfo = bnx2x_get_drvinfo, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9731 | .get_wol = bnx2x_get_wol, |
| 9732 | .set_wol = bnx2x_set_wol, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9733 | .get_msglevel = bnx2x_get_msglevel, |
| 9734 | .set_msglevel = bnx2x_set_msglevel, |
| 9735 | .nway_reset = bnx2x_nway_reset, |
| 9736 | .get_link = ethtool_op_get_link, |
| 9737 | .get_eeprom_len = bnx2x_get_eeprom_len, |
| 9738 | .get_eeprom = bnx2x_get_eeprom, |
| 9739 | .set_eeprom = bnx2x_set_eeprom, |
| 9740 | .get_coalesce = bnx2x_get_coalesce, |
| 9741 | .set_coalesce = bnx2x_set_coalesce, |
| 9742 | .get_ringparam = bnx2x_get_ringparam, |
| 9743 | .set_ringparam = bnx2x_set_ringparam, |
| 9744 | .get_pauseparam = bnx2x_get_pauseparam, |
| 9745 | .set_pauseparam = bnx2x_set_pauseparam, |
| 9746 | .get_rx_csum = bnx2x_get_rx_csum, |
| 9747 | .set_rx_csum = bnx2x_set_rx_csum, |
| 9748 | .get_tx_csum = ethtool_op_get_tx_csum, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9749 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9750 | .set_flags = bnx2x_set_flags, |
| 9751 | .get_flags = ethtool_op_get_flags, |
| 9752 | .get_sg = ethtool_op_get_sg, |
| 9753 | .set_sg = ethtool_op_set_sg, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9754 | .get_tso = ethtool_op_get_tso, |
| 9755 | .set_tso = bnx2x_set_tso, |
| 9756 | .self_test_count = bnx2x_self_test_count, |
Vladislav Zolotarov | 7a9b255 | 2008-06-23 20:34:36 -0700 | [diff] [blame] | 9757 | .self_test = bnx2x_self_test, |
| 9758 | .get_strings = bnx2x_get_strings, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9759 | .phys_id = bnx2x_phys_id, |
| 9760 | .get_stats_count = bnx2x_get_stats_count, |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 9761 | .get_ethtool_stats = bnx2x_get_ethtool_stats, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9762 | }; |
| 9763 | |
| 9764 | /* end of ethtool_ops */ |
| 9765 | |
| 9766 | /**************************************************************************** |
| 9767 | * General service functions |
| 9768 | ****************************************************************************/ |
| 9769 | |
| 9770 | static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state) |
| 9771 | { |
| 9772 | u16 pmcsr; |
| 9773 | |
| 9774 | pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr); |
| 9775 | |
| 9776 | switch (state) { |
| 9777 | case PCI_D0: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9778 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9779 | ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) | |
| 9780 | PCI_PM_CTRL_PME_STATUS)); |
| 9781 | |
| 9782 | if (pmcsr & PCI_PM_CTRL_STATE_MASK) |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 9783 | /* delay required during transition out of D3hot */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9784 | msleep(20); |
| 9785 | break; |
| 9786 | |
| 9787 | case PCI_D3hot: |
| 9788 | pmcsr &= ~PCI_PM_CTRL_STATE_MASK; |
| 9789 | pmcsr |= 3; |
| 9790 | |
| 9791 | if (bp->wol) |
| 9792 | pmcsr |= PCI_PM_CTRL_PME_ENABLE; |
| 9793 | |
| 9794 | pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, |
| 9795 | pmcsr); |
| 9796 | |
| 9797 | /* No more memory access after this point until |
| 9798 | * device is brought back to D0. |
| 9799 | */ |
| 9800 | break; |
| 9801 | |
| 9802 | default: |
| 9803 | return -EINVAL; |
| 9804 | } |
| 9805 | return 0; |
| 9806 | } |
| 9807 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 9808 | static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp) |
| 9809 | { |
| 9810 | u16 rx_cons_sb; |
| 9811 | |
| 9812 | /* Tell compiler that status block fields can change */ |
| 9813 | barrier(); |
| 9814 | rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb); |
| 9815 | if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT) |
| 9816 | rx_cons_sb++; |
| 9817 | return (fp->rx_comp_cons != rx_cons_sb); |
| 9818 | } |
| 9819 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9820 | /* |
| 9821 | * net_device service functions |
| 9822 | */ |
| 9823 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9824 | static int bnx2x_poll(struct napi_struct *napi, int budget) |
| 9825 | { |
| 9826 | struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath, |
| 9827 | napi); |
| 9828 | struct bnx2x *bp = fp->bp; |
| 9829 | int work_done = 0; |
| 9830 | |
| 9831 | #ifdef BNX2X_STOP_ON_ERROR |
| 9832 | if (unlikely(bp->panic)) |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9833 | goto poll_panic; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9834 | #endif |
| 9835 | |
| 9836 | prefetch(fp->tx_buf_ring[TX_BD(fp->tx_pkt_cons)].skb); |
| 9837 | prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb); |
| 9838 | prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256); |
| 9839 | |
| 9840 | bnx2x_update_fpsb_idx(fp); |
| 9841 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 9842 | if (bnx2x_has_tx_work(fp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9843 | bnx2x_tx_int(fp, budget); |
| 9844 | |
Eilon Greenstein | 237907c | 2009-01-14 06:42:44 +0000 | [diff] [blame] | 9845 | if (bnx2x_has_rx_work(fp)) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9846 | work_done = bnx2x_rx_int(fp, budget); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 9847 | rmb(); /* BNX2X_HAS_WORK() reads the status block */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9848 | |
| 9849 | /* must not complete if we consumed full budget */ |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 9850 | if ((work_done < budget) && !BNX2X_HAS_WORK(fp)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9851 | |
| 9852 | #ifdef BNX2X_STOP_ON_ERROR |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9853 | poll_panic: |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9854 | #endif |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 9855 | napi_complete(napi); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9856 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9857 | bnx2x_ack_sb(bp, FP_SB_ID(fp), USTORM_ID, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9858 | le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 9859 | bnx2x_ack_sb(bp, FP_SB_ID(fp), CSTORM_ID, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9860 | le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1); |
| 9861 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 9862 | return work_done; |
| 9863 | } |
| 9864 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9865 | |
| 9866 | /* we split the first BD into headers and data BDs |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 9867 | * to ease the pain of our fellow microcode engineers |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9868 | * we use one mapping for both BDs |
| 9869 | * So far this has only been observed to happen |
| 9870 | * in Other Operating Systems(TM) |
| 9871 | */ |
| 9872 | static noinline u16 bnx2x_tx_split(struct bnx2x *bp, |
| 9873 | struct bnx2x_fastpath *fp, |
| 9874 | struct eth_tx_bd **tx_bd, u16 hlen, |
| 9875 | u16 bd_prod, int nbd) |
| 9876 | { |
| 9877 | struct eth_tx_bd *h_tx_bd = *tx_bd; |
| 9878 | struct eth_tx_bd *d_tx_bd; |
| 9879 | dma_addr_t mapping; |
| 9880 | int old_len = le16_to_cpu(h_tx_bd->nbytes); |
| 9881 | |
| 9882 | /* first fix first BD */ |
| 9883 | h_tx_bd->nbd = cpu_to_le16(nbd); |
| 9884 | h_tx_bd->nbytes = cpu_to_le16(hlen); |
| 9885 | |
| 9886 | DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d " |
| 9887 | "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi, |
| 9888 | h_tx_bd->addr_lo, h_tx_bd->nbd); |
| 9889 | |
| 9890 | /* now get a new data BD |
| 9891 | * (after the pbd) and fill it */ |
| 9892 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 9893 | d_tx_bd = &fp->tx_desc_ring[bd_prod]; |
| 9894 | |
| 9895 | mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi), |
| 9896 | le32_to_cpu(h_tx_bd->addr_lo)) + hlen; |
| 9897 | |
| 9898 | d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 9899 | d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 9900 | d_tx_bd->nbytes = cpu_to_le16(old_len - hlen); |
| 9901 | d_tx_bd->vlan = 0; |
| 9902 | /* this marks the BD as one that has no individual mapping |
| 9903 | * the FW ignores this flag in a BD not marked start |
| 9904 | */ |
| 9905 | d_tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_SW_LSO; |
| 9906 | DP(NETIF_MSG_TX_QUEUED, |
| 9907 | "TSO split data size is %d (%x:%x)\n", |
| 9908 | d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo); |
| 9909 | |
| 9910 | /* update tx_bd for marking the last BD flag */ |
| 9911 | *tx_bd = d_tx_bd; |
| 9912 | |
| 9913 | return bd_prod; |
| 9914 | } |
| 9915 | |
| 9916 | static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix) |
| 9917 | { |
| 9918 | if (fix > 0) |
| 9919 | csum = (u16) ~csum_fold(csum_sub(csum, |
| 9920 | csum_partial(t_header - fix, fix, 0))); |
| 9921 | |
| 9922 | else if (fix < 0) |
| 9923 | csum = (u16) ~csum_fold(csum_add(csum, |
| 9924 | csum_partial(t_header, -fix, 0))); |
| 9925 | |
| 9926 | return swab16(csum); |
| 9927 | } |
| 9928 | |
| 9929 | static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb) |
| 9930 | { |
| 9931 | u32 rc; |
| 9932 | |
| 9933 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 9934 | rc = XMIT_PLAIN; |
| 9935 | |
| 9936 | else { |
| 9937 | if (skb->protocol == ntohs(ETH_P_IPV6)) { |
| 9938 | rc = XMIT_CSUM_V6; |
| 9939 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 9940 | rc |= XMIT_CSUM_TCP; |
| 9941 | |
| 9942 | } else { |
| 9943 | rc = XMIT_CSUM_V4; |
| 9944 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 9945 | rc |= XMIT_CSUM_TCP; |
| 9946 | } |
| 9947 | } |
| 9948 | |
| 9949 | if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4) |
| 9950 | rc |= XMIT_GSO_V4; |
| 9951 | |
| 9952 | else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) |
| 9953 | rc |= XMIT_GSO_V6; |
| 9954 | |
| 9955 | return rc; |
| 9956 | } |
| 9957 | |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 9958 | #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3) |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9959 | /* check if packet requires linearization (packet is too fragmented) */ |
| 9960 | static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb, |
| 9961 | u32 xmit_type) |
| 9962 | { |
| 9963 | int to_copy = 0; |
| 9964 | int hlen = 0; |
| 9965 | int first_bd_sz = 0; |
| 9966 | |
| 9967 | /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */ |
| 9968 | if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) { |
| 9969 | |
| 9970 | if (xmit_type & XMIT_GSO) { |
| 9971 | unsigned short lso_mss = skb_shinfo(skb)->gso_size; |
| 9972 | /* Check if LSO packet needs to be copied: |
| 9973 | 3 = 1 (for headers BD) + 2 (for PBD and last BD) */ |
| 9974 | int wnd_size = MAX_FETCH_BD - 3; |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 9975 | /* Number of windows to check */ |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 9976 | int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size; |
| 9977 | int wnd_idx = 0; |
| 9978 | int frag_idx = 0; |
| 9979 | u32 wnd_sum = 0; |
| 9980 | |
| 9981 | /* Headers length */ |
| 9982 | hlen = (int)(skb_transport_header(skb) - skb->data) + |
| 9983 | tcp_hdrlen(skb); |
| 9984 | |
| 9985 | /* Amount of data (w/o headers) on linear part of SKB*/ |
| 9986 | first_bd_sz = skb_headlen(skb) - hlen; |
| 9987 | |
| 9988 | wnd_sum = first_bd_sz; |
| 9989 | |
| 9990 | /* Calculate the first sum - it's special */ |
| 9991 | for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++) |
| 9992 | wnd_sum += |
| 9993 | skb_shinfo(skb)->frags[frag_idx].size; |
| 9994 | |
| 9995 | /* If there was data on linear skb data - check it */ |
| 9996 | if (first_bd_sz > 0) { |
| 9997 | if (unlikely(wnd_sum < lso_mss)) { |
| 9998 | to_copy = 1; |
| 9999 | goto exit_lbl; |
| 10000 | } |
| 10001 | |
| 10002 | wnd_sum -= first_bd_sz; |
| 10003 | } |
| 10004 | |
| 10005 | /* Others are easier: run through the frag list and |
| 10006 | check all windows */ |
| 10007 | for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) { |
| 10008 | wnd_sum += |
| 10009 | skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size; |
| 10010 | |
| 10011 | if (unlikely(wnd_sum < lso_mss)) { |
| 10012 | to_copy = 1; |
| 10013 | break; |
| 10014 | } |
| 10015 | wnd_sum -= |
| 10016 | skb_shinfo(skb)->frags[wnd_idx].size; |
| 10017 | } |
| 10018 | |
| 10019 | } else { |
| 10020 | /* in non-LSO too fragmented packet should always |
| 10021 | be linearized */ |
| 10022 | to_copy = 1; |
| 10023 | } |
| 10024 | } |
| 10025 | |
| 10026 | exit_lbl: |
| 10027 | if (unlikely(to_copy)) |
| 10028 | DP(NETIF_MSG_TX_QUEUED, |
| 10029 | "Linearization IS REQUIRED for %s packet. " |
| 10030 | "num_frags %d hlen %d first_bd_sz %d\n", |
| 10031 | (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO", |
| 10032 | skb_shinfo(skb)->nr_frags, hlen, first_bd_sz); |
| 10033 | |
| 10034 | return to_copy; |
| 10035 | } |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10036 | #endif |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10037 | |
| 10038 | /* called with netif_tx_lock |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10039 | * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10040 | * netif_wake_queue() |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10041 | */ |
| 10042 | static int bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 10043 | { |
| 10044 | struct bnx2x *bp = netdev_priv(dev); |
| 10045 | struct bnx2x_fastpath *fp; |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10046 | struct netdev_queue *txq; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10047 | struct sw_tx_bd *tx_buf; |
| 10048 | struct eth_tx_bd *tx_bd; |
| 10049 | struct eth_tx_parse_bd *pbd = NULL; |
| 10050 | u16 pkt_prod, bd_prod; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10051 | int nbd, fp_index; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10052 | dma_addr_t mapping; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10053 | u32 xmit_type = bnx2x_xmit_type(bp, skb); |
| 10054 | int vlan_off = (bp->e1hov ? 4 : 0); |
| 10055 | int i; |
| 10056 | u8 hlen = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10057 | |
| 10058 | #ifdef BNX2X_STOP_ON_ERROR |
| 10059 | if (unlikely(bp->panic)) |
| 10060 | return NETDEV_TX_BUSY; |
| 10061 | #endif |
| 10062 | |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10063 | fp_index = skb_get_queue_mapping(skb); |
| 10064 | txq = netdev_get_tx_queue(dev, fp_index); |
| 10065 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10066 | fp = &bp->fp[fp_index]; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10067 | |
Yitchak Gertner | 231fd58 | 2008-08-25 15:27:06 -0700 | [diff] [blame] | 10068 | if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) { |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10069 | fp->eth_q_stats.driver_xoff++, |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10070 | netif_tx_stop_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10071 | BNX2X_ERR("BUG! Tx ring full when queue awake!\n"); |
| 10072 | return NETDEV_TX_BUSY; |
| 10073 | } |
| 10074 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10075 | DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)" |
| 10076 | " gso type %x xmit_type %x\n", |
| 10077 | skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr, |
| 10078 | ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type); |
| 10079 | |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10080 | #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3) |
Eilon Greenstein | 3347162 | 2008-08-13 15:59:08 -0700 | [diff] [blame] | 10081 | /* First, check if we need to linearize the skb |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10082 | (due to FW restrictions) */ |
| 10083 | if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) { |
| 10084 | /* Statistics of linearization */ |
| 10085 | bp->lin_cnt++; |
| 10086 | if (skb_linearize(skb) != 0) { |
| 10087 | DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - " |
| 10088 | "silently dropping this SKB\n"); |
| 10089 | dev_kfree_skb_any(skb); |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 10090 | return NETDEV_TX_OK; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10091 | } |
| 10092 | } |
Eilon Greenstein | 632da4d | 2009-01-14 06:44:10 +0000 | [diff] [blame] | 10093 | #endif |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10094 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10095 | /* |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10096 | Please read carefully. First we use one BD which we mark as start, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10097 | then for TSO or xsum we have a parsing info BD, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10098 | and only then we have the rest of the TSO BDs. |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10099 | (don't forget to mark the last one as last, |
| 10100 | and to unmap only AFTER you write to the BD ...) |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10101 | And above all, all pdb sizes are in words - NOT DWORDS! |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10102 | */ |
| 10103 | |
| 10104 | pkt_prod = fp->tx_pkt_prod++; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10105 | bd_prod = TX_BD(fp->tx_bd_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10106 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10107 | /* get a tx_buf and first BD */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10108 | tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)]; |
| 10109 | tx_bd = &fp->tx_desc_ring[bd_prod]; |
| 10110 | |
| 10111 | tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD; |
| 10112 | tx_bd->general_data = (UNICAST_ADDRESS << |
| 10113 | ETH_TX_BD_ETH_ADDR_TYPE_SHIFT); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10114 | /* header nbd */ |
| 10115 | tx_bd->general_data |= (1 << ETH_TX_BD_HDR_NBDS_SHIFT); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10116 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10117 | /* remember the first BD of the packet */ |
| 10118 | tx_buf->first_bd = fp->tx_bd_prod; |
| 10119 | tx_buf->skb = skb; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10120 | |
| 10121 | DP(NETIF_MSG_TX_QUEUED, |
| 10122 | "sending pkt %u @%p next_idx %u bd %u @%p\n", |
| 10123 | pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_bd); |
| 10124 | |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10125 | #ifdef BCM_VLAN |
| 10126 | if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) && |
| 10127 | (bp->flags & HW_VLAN_TX_FLAG)) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10128 | tx_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb)); |
| 10129 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG; |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10130 | vlan_off += 4; |
| 10131 | } else |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10132 | #endif |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10133 | tx_bd->vlan = cpu_to_le16(pkt_prod); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10134 | |
| 10135 | if (xmit_type) { |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10136 | /* turn on parsing and get a BD */ |
| 10137 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10138 | pbd = (void *)&fp->tx_desc_ring[bd_prod]; |
| 10139 | |
| 10140 | memset(pbd, 0, sizeof(struct eth_tx_parse_bd)); |
| 10141 | } |
| 10142 | |
| 10143 | if (xmit_type & XMIT_CSUM) { |
| 10144 | hlen = (skb_network_header(skb) - skb->data + vlan_off) / 2; |
| 10145 | |
| 10146 | /* for now NS flag is not used in Linux */ |
| 10147 | pbd->global_data = (hlen | |
| 10148 | ((skb->protocol == ntohs(ETH_P_8021Q)) << |
| 10149 | ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT)); |
| 10150 | |
| 10151 | pbd->ip_hlen = (skb_transport_header(skb) - |
| 10152 | skb_network_header(skb)) / 2; |
| 10153 | |
| 10154 | hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2; |
| 10155 | |
| 10156 | pbd->total_hlen = cpu_to_le16(hlen); |
| 10157 | hlen = hlen*2 - vlan_off; |
| 10158 | |
| 10159 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_TCP_CSUM; |
| 10160 | |
| 10161 | if (xmit_type & XMIT_CSUM_V4) |
| 10162 | tx_bd->bd_flags.as_bitfield |= |
| 10163 | ETH_TX_BD_FLAGS_IP_CSUM; |
| 10164 | else |
| 10165 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IPV6; |
| 10166 | |
| 10167 | if (xmit_type & XMIT_CSUM_TCP) { |
| 10168 | pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check); |
| 10169 | |
| 10170 | } else { |
| 10171 | s8 fix = SKB_CS_OFF(skb); /* signed! */ |
| 10172 | |
| 10173 | pbd->global_data |= ETH_TX_PARSE_BD_CS_ANY_FLG; |
| 10174 | pbd->cs_offset = fix / 2; |
| 10175 | |
| 10176 | DP(NETIF_MSG_TX_QUEUED, |
| 10177 | "hlen %d offset %d fix %d csum before fix %x\n", |
| 10178 | le16_to_cpu(pbd->total_hlen), pbd->cs_offset, fix, |
| 10179 | SKB_CS(skb)); |
| 10180 | |
| 10181 | /* HW bug: fixup the CSUM */ |
| 10182 | pbd->tcp_pseudo_csum = |
| 10183 | bnx2x_csum_fix(skb_transport_header(skb), |
| 10184 | SKB_CS(skb), fix); |
| 10185 | |
| 10186 | DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n", |
| 10187 | pbd->tcp_pseudo_csum); |
| 10188 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10189 | } |
| 10190 | |
| 10191 | mapping = pci_map_single(bp->pdev, skb->data, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10192 | skb_headlen(skb), PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10193 | |
| 10194 | tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 10195 | tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
Eilon Greenstein | 6378c02 | 2008-08-13 15:59:25 -0700 | [diff] [blame] | 10196 | nbd = skb_shinfo(skb)->nr_frags + ((pbd == NULL) ? 1 : 2); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10197 | tx_bd->nbd = cpu_to_le16(nbd); |
| 10198 | tx_bd->nbytes = cpu_to_le16(skb_headlen(skb)); |
| 10199 | |
| 10200 | DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d" |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10201 | " nbytes %d flags %x vlan %x\n", |
| 10202 | tx_bd, tx_bd->addr_hi, tx_bd->addr_lo, le16_to_cpu(tx_bd->nbd), |
| 10203 | le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield, |
| 10204 | le16_to_cpu(tx_bd->vlan)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10205 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10206 | if (xmit_type & XMIT_GSO) { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10207 | |
| 10208 | DP(NETIF_MSG_TX_QUEUED, |
| 10209 | "TSO packet len %d hlen %d total len %d tso size %d\n", |
| 10210 | skb->len, hlen, skb_headlen(skb), |
| 10211 | skb_shinfo(skb)->gso_size); |
| 10212 | |
| 10213 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO; |
| 10214 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10215 | if (unlikely(skb_headlen(skb) > hlen)) |
| 10216 | bd_prod = bnx2x_tx_split(bp, fp, &tx_bd, hlen, |
| 10217 | bd_prod, ++nbd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10218 | |
| 10219 | pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size); |
| 10220 | pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10221 | pbd->tcp_flags = pbd_tcp_flags(skb); |
| 10222 | |
| 10223 | if (xmit_type & XMIT_GSO_V4) { |
| 10224 | pbd->ip_id = swab16(ip_hdr(skb)->id); |
| 10225 | pbd->tcp_pseudo_csum = |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10226 | swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr, |
| 10227 | ip_hdr(skb)->daddr, |
| 10228 | 0, IPPROTO_TCP, 0)); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10229 | |
| 10230 | } else |
| 10231 | pbd->tcp_pseudo_csum = |
| 10232 | swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 10233 | &ipv6_hdr(skb)->daddr, |
| 10234 | 0, IPPROTO_TCP, 0)); |
| 10235 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10236 | pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN; |
| 10237 | } |
| 10238 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10239 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 10240 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10241 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10242 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10243 | tx_bd = &fp->tx_desc_ring[bd_prod]; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10244 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10245 | mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset, |
| 10246 | frag->size, PCI_DMA_TODEVICE); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10247 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10248 | tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping)); |
| 10249 | tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping)); |
| 10250 | tx_bd->nbytes = cpu_to_le16(frag->size); |
| 10251 | tx_bd->vlan = cpu_to_le16(pkt_prod); |
| 10252 | tx_bd->bd_flags.as_bitfield = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10253 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10254 | DP(NETIF_MSG_TX_QUEUED, |
| 10255 | "frag %d bd @%p addr (%x:%x) nbytes %d flags %x\n", |
| 10256 | i, tx_bd, tx_bd->addr_hi, tx_bd->addr_lo, |
| 10257 | le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10258 | } |
| 10259 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10260 | /* now at last mark the BD as the last BD */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10261 | tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_END_BD; |
| 10262 | |
| 10263 | DP(NETIF_MSG_TX_QUEUED, "last bd @%p flags %x\n", |
| 10264 | tx_bd, tx_bd->bd_flags.as_bitfield); |
| 10265 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10266 | bd_prod = TX_BD(NEXT_TX_IDX(bd_prod)); |
| 10267 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10268 | /* now send a tx doorbell, counting the next BD |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10269 | * if the packet contains or ends with it |
| 10270 | */ |
| 10271 | if (TX_BD_POFF(bd_prod) < nbd) |
| 10272 | nbd++; |
| 10273 | |
| 10274 | if (pbd) |
| 10275 | DP(NETIF_MSG_TX_QUEUED, |
| 10276 | "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u" |
| 10277 | " tcp_flags %x xsum %x seq %u hlen %u\n", |
| 10278 | pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id, |
| 10279 | pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum, |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10280 | pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen)); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10281 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10282 | DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10283 | |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 10284 | /* |
| 10285 | * Make sure that the BD data is updated before updating the producer |
| 10286 | * since FW might read the BD right after the producer is updated. |
| 10287 | * This is only applicable for weak-ordered memory model archs such |
| 10288 | * as IA-64. The following barrier is also mandatory since FW will |
| 10289 | * assumes packets must have BDs. |
| 10290 | */ |
| 10291 | wmb(); |
| 10292 | |
Eliezer Tamir | 96fc178 | 2008-02-28 11:57:55 -0800 | [diff] [blame] | 10293 | fp->hw_tx_prods->bds_prod = |
| 10294 | cpu_to_le16(le16_to_cpu(fp->hw_tx_prods->bds_prod) + nbd); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10295 | mb(); /* FW restriction: must not reorder writing nbd and packets */ |
Eliezer Tamir | 96fc178 | 2008-02-28 11:57:55 -0800 | [diff] [blame] | 10296 | fp->hw_tx_prods->packets_prod = |
| 10297 | cpu_to_le32(le32_to_cpu(fp->hw_tx_prods->packets_prod) + 1); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10298 | DOORBELL(bp, FP_IDX(fp), 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10299 | |
| 10300 | mmiowb(); |
| 10301 | |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10302 | fp->tx_bd_prod += nbd; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10303 | dev->trans_start = jiffies; |
| 10304 | |
| 10305 | if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) { |
Eilon Greenstein | 58f4c4c | 2009-01-14 21:23:36 -0800 | [diff] [blame] | 10306 | /* We want bnx2x_tx_int to "see" the updated tx_bd_prod |
| 10307 | if we put Tx into XOFF state. */ |
| 10308 | smp_mb(); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10309 | netif_tx_stop_queue(txq); |
Eilon Greenstein | de832a5 | 2009-02-12 08:36:33 +0000 | [diff] [blame] | 10310 | fp->eth_q_stats.driver_xoff++; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10311 | if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3) |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10312 | netif_tx_wake_queue(txq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10313 | } |
| 10314 | fp->tx_pkt++; |
| 10315 | |
| 10316 | return NETDEV_TX_OK; |
| 10317 | } |
| 10318 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10319 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10320 | static int bnx2x_open(struct net_device *dev) |
| 10321 | { |
| 10322 | struct bnx2x *bp = netdev_priv(dev); |
| 10323 | |
Eilon Greenstein | 6eccabb | 2009-01-22 03:37:48 +0000 | [diff] [blame] | 10324 | netif_carrier_off(dev); |
| 10325 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10326 | bnx2x_set_power_state(bp, PCI_D0); |
| 10327 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10328 | return bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10329 | } |
| 10330 | |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10331 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10332 | static int bnx2x_close(struct net_device *dev) |
| 10333 | { |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10334 | struct bnx2x *bp = netdev_priv(dev); |
| 10335 | |
| 10336 | /* Unload the driver, release IRQs */ |
Yitchak Gertner | bb2a0f7 | 2008-06-23 20:33:36 -0700 | [diff] [blame] | 10337 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
| 10338 | if (atomic_read(&bp->pdev->enable_cnt) == 1) |
| 10339 | if (!CHIP_REV_IS_SLOW(bp)) |
| 10340 | bnx2x_set_power_state(bp, PCI_D3hot); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10341 | |
| 10342 | return 0; |
| 10343 | } |
| 10344 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10345 | /* called with netif_tx_lock from set_multicast */ |
| 10346 | static void bnx2x_set_rx_mode(struct net_device *dev) |
| 10347 | { |
| 10348 | struct bnx2x *bp = netdev_priv(dev); |
| 10349 | u32 rx_mode = BNX2X_RX_MODE_NORMAL; |
| 10350 | int port = BP_PORT(bp); |
| 10351 | |
| 10352 | if (bp->state != BNX2X_STATE_OPEN) { |
| 10353 | DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state); |
| 10354 | return; |
| 10355 | } |
| 10356 | |
| 10357 | DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags); |
| 10358 | |
| 10359 | if (dev->flags & IFF_PROMISC) |
| 10360 | rx_mode = BNX2X_RX_MODE_PROMISC; |
| 10361 | |
| 10362 | else if ((dev->flags & IFF_ALLMULTI) || |
| 10363 | ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp))) |
| 10364 | rx_mode = BNX2X_RX_MODE_ALLMULTI; |
| 10365 | |
| 10366 | else { /* some multicasts */ |
| 10367 | if (CHIP_IS_E1(bp)) { |
| 10368 | int i, old, offset; |
| 10369 | struct dev_mc_list *mclist; |
| 10370 | struct mac_configuration_cmd *config = |
| 10371 | bnx2x_sp(bp, mcast_config); |
| 10372 | |
| 10373 | for (i = 0, mclist = dev->mc_list; |
| 10374 | mclist && (i < dev->mc_count); |
| 10375 | i++, mclist = mclist->next) { |
| 10376 | |
| 10377 | config->config_table[i]. |
| 10378 | cam_entry.msb_mac_addr = |
| 10379 | swab16(*(u16 *)&mclist->dmi_addr[0]); |
| 10380 | config->config_table[i]. |
| 10381 | cam_entry.middle_mac_addr = |
| 10382 | swab16(*(u16 *)&mclist->dmi_addr[2]); |
| 10383 | config->config_table[i]. |
| 10384 | cam_entry.lsb_mac_addr = |
| 10385 | swab16(*(u16 *)&mclist->dmi_addr[4]); |
| 10386 | config->config_table[i].cam_entry.flags = |
| 10387 | cpu_to_le16(port); |
| 10388 | config->config_table[i]. |
| 10389 | target_table_entry.flags = 0; |
| 10390 | config->config_table[i]. |
| 10391 | target_table_entry.client_id = 0; |
| 10392 | config->config_table[i]. |
| 10393 | target_table_entry.vlan_id = 0; |
| 10394 | |
| 10395 | DP(NETIF_MSG_IFUP, |
| 10396 | "setting MCAST[%d] (%04x:%04x:%04x)\n", i, |
| 10397 | config->config_table[i]. |
| 10398 | cam_entry.msb_mac_addr, |
| 10399 | config->config_table[i]. |
| 10400 | cam_entry.middle_mac_addr, |
| 10401 | config->config_table[i]. |
| 10402 | cam_entry.lsb_mac_addr); |
| 10403 | } |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10404 | old = config->hdr.length; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10405 | if (old > i) { |
| 10406 | for (; i < old; i++) { |
| 10407 | if (CAM_IS_INVALID(config-> |
| 10408 | config_table[i])) { |
Eilon Greenstein | af24640 | 2009-01-14 06:43:59 +0000 | [diff] [blame] | 10409 | /* already invalidated */ |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10410 | break; |
| 10411 | } |
| 10412 | /* invalidate */ |
| 10413 | CAM_INVALIDATE(config-> |
| 10414 | config_table[i]); |
| 10415 | } |
| 10416 | } |
| 10417 | |
| 10418 | if (CHIP_REV_IS_SLOW(bp)) |
| 10419 | offset = BNX2X_MAX_EMUL_MULTI*(1 + port); |
| 10420 | else |
| 10421 | offset = BNX2X_MAX_MULTICAST*(1 + port); |
| 10422 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10423 | config->hdr.length = i; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10424 | config->hdr.offset = offset; |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10425 | config->hdr.client_id = bp->fp->cl_id; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10426 | config->hdr.reserved1 = 0; |
| 10427 | |
| 10428 | bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0, |
| 10429 | U64_HI(bnx2x_sp_mapping(bp, mcast_config)), |
| 10430 | U64_LO(bnx2x_sp_mapping(bp, mcast_config)), |
| 10431 | 0); |
| 10432 | } else { /* E1H */ |
| 10433 | /* Accept one or more multicasts */ |
| 10434 | struct dev_mc_list *mclist; |
| 10435 | u32 mc_filter[MC_HASH_SIZE]; |
| 10436 | u32 crc, bit, regidx; |
| 10437 | int i; |
| 10438 | |
| 10439 | memset(mc_filter, 0, 4 * MC_HASH_SIZE); |
| 10440 | |
| 10441 | for (i = 0, mclist = dev->mc_list; |
| 10442 | mclist && (i < dev->mc_count); |
| 10443 | i++, mclist = mclist->next) { |
| 10444 | |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 10445 | DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n", |
| 10446 | mclist->dmi_addr); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10447 | |
| 10448 | crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN); |
| 10449 | bit = (crc >> 24) & 0xff; |
| 10450 | regidx = bit >> 5; |
| 10451 | bit &= 0x1f; |
| 10452 | mc_filter[regidx] |= (1 << bit); |
| 10453 | } |
| 10454 | |
| 10455 | for (i = 0; i < MC_HASH_SIZE; i++) |
| 10456 | REG_WR(bp, MC_HASH_OFFSET(bp, i), |
| 10457 | mc_filter[i]); |
| 10458 | } |
| 10459 | } |
| 10460 | |
| 10461 | bp->rx_mode = rx_mode; |
| 10462 | bnx2x_set_storm_rx_mode(bp); |
| 10463 | } |
| 10464 | |
| 10465 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10466 | static int bnx2x_change_mac_addr(struct net_device *dev, void *p) |
| 10467 | { |
| 10468 | struct sockaddr *addr = p; |
| 10469 | struct bnx2x *bp = netdev_priv(dev); |
| 10470 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10471 | if (!is_valid_ether_addr((u8 *)(addr->sa_data))) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10472 | return -EINVAL; |
| 10473 | |
| 10474 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10475 | if (netif_running(dev)) { |
| 10476 | if (CHIP_IS_E1(bp)) |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 10477 | bnx2x_set_mac_addr_e1(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10478 | else |
Yitchak Gertner | 3101c2b | 2008-08-13 15:52:28 -0700 | [diff] [blame] | 10479 | bnx2x_set_mac_addr_e1h(bp, 1); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10480 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10481 | |
| 10482 | return 0; |
| 10483 | } |
| 10484 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10485 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10486 | static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 10487 | { |
| 10488 | struct mii_ioctl_data *data = if_mii(ifr); |
| 10489 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10490 | int port = BP_PORT(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10491 | int err; |
| 10492 | |
| 10493 | switch (cmd) { |
| 10494 | case SIOCGMIIPHY: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10495 | data->phy_id = bp->port.phy_addr; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10496 | |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 10497 | /* fallthrough */ |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10498 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10499 | case SIOCGMIIREG: { |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10500 | u16 mii_regval; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10501 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10502 | if (!netif_running(dev)) |
| 10503 | return -EAGAIN; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10504 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10505 | mutex_lock(&bp->port.phy_mutex); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10506 | err = bnx2x_cl45_read(bp, port, 0, bp->port.phy_addr, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10507 | DEFAULT_PHY_DEV_ADDR, |
| 10508 | (data->reg_num & 0x1f), &mii_regval); |
| 10509 | data->val_out = mii_regval; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10510 | mutex_unlock(&bp->port.phy_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10511 | return err; |
| 10512 | } |
| 10513 | |
| 10514 | case SIOCSMIIREG: |
| 10515 | if (!capable(CAP_NET_ADMIN)) |
| 10516 | return -EPERM; |
| 10517 | |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10518 | if (!netif_running(dev)) |
| 10519 | return -EAGAIN; |
| 10520 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10521 | mutex_lock(&bp->port.phy_mutex); |
Eilon Greenstein | 3196a88 | 2008-08-13 15:58:49 -0700 | [diff] [blame] | 10522 | err = bnx2x_cl45_write(bp, port, 0, bp->port.phy_addr, |
Yaniv Rosner | c18487e | 2008-06-23 20:27:52 -0700 | [diff] [blame] | 10523 | DEFAULT_PHY_DEV_ADDR, |
| 10524 | (data->reg_num & 0x1f), data->val_in); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10525 | mutex_unlock(&bp->port.phy_mutex); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10526 | return err; |
| 10527 | |
| 10528 | default: |
| 10529 | /* do nothing */ |
| 10530 | break; |
| 10531 | } |
| 10532 | |
| 10533 | return -EOPNOTSUPP; |
| 10534 | } |
| 10535 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10536 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10537 | static int bnx2x_change_mtu(struct net_device *dev, int new_mtu) |
| 10538 | { |
| 10539 | struct bnx2x *bp = netdev_priv(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10540 | int rc = 0; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10541 | |
| 10542 | if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) || |
| 10543 | ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE)) |
| 10544 | return -EINVAL; |
| 10545 | |
| 10546 | /* This does not race with packet allocation |
Eliezer Tamir | c14423f | 2008-02-28 11:49:42 -0800 | [diff] [blame] | 10547 | * because the actual alloc size is |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10548 | * only updated as part of load |
| 10549 | */ |
| 10550 | dev->mtu = new_mtu; |
| 10551 | |
| 10552 | if (netif_running(dev)) { |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10553 | bnx2x_nic_unload(bp, UNLOAD_NORMAL); |
| 10554 | rc = bnx2x_nic_load(bp, LOAD_NORMAL); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10555 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10556 | |
| 10557 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10558 | } |
| 10559 | |
| 10560 | static void bnx2x_tx_timeout(struct net_device *dev) |
| 10561 | { |
| 10562 | struct bnx2x *bp = netdev_priv(dev); |
| 10563 | |
| 10564 | #ifdef BNX2X_STOP_ON_ERROR |
| 10565 | if (!bp->panic) |
| 10566 | bnx2x_panic(); |
| 10567 | #endif |
| 10568 | /* This allows the netif to be shutdown gracefully before resetting */ |
| 10569 | schedule_work(&bp->reset_task); |
| 10570 | } |
| 10571 | |
| 10572 | #ifdef BCM_VLAN |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10573 | /* called with rtnl_lock */ |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10574 | static void bnx2x_vlan_rx_register(struct net_device *dev, |
| 10575 | struct vlan_group *vlgrp) |
| 10576 | { |
| 10577 | struct bnx2x *bp = netdev_priv(dev); |
| 10578 | |
| 10579 | bp->vlgrp = vlgrp; |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10580 | |
| 10581 | /* Set flags according to the required capabilities */ |
| 10582 | bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG); |
| 10583 | |
| 10584 | if (dev->features & NETIF_F_HW_VLAN_TX) |
| 10585 | bp->flags |= HW_VLAN_TX_FLAG; |
| 10586 | |
| 10587 | if (dev->features & NETIF_F_HW_VLAN_RX) |
| 10588 | bp->flags |= HW_VLAN_RX_FLAG; |
| 10589 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10590 | if (netif_running(dev)) |
Eliezer Tamir | 49d6677 | 2008-02-28 11:53:13 -0800 | [diff] [blame] | 10591 | bnx2x_set_client_config(bp); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10592 | } |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10593 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10594 | #endif |
| 10595 | |
| 10596 | #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER) |
| 10597 | static void poll_bnx2x(struct net_device *dev) |
| 10598 | { |
| 10599 | struct bnx2x *bp = netdev_priv(dev); |
| 10600 | |
| 10601 | disable_irq(bp->pdev->irq); |
| 10602 | bnx2x_interrupt(bp->pdev->irq, dev); |
| 10603 | enable_irq(bp->pdev->irq); |
| 10604 | } |
| 10605 | #endif |
| 10606 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 10607 | static const struct net_device_ops bnx2x_netdev_ops = { |
| 10608 | .ndo_open = bnx2x_open, |
| 10609 | .ndo_stop = bnx2x_close, |
| 10610 | .ndo_start_xmit = bnx2x_start_xmit, |
| 10611 | .ndo_set_multicast_list = bnx2x_set_rx_mode, |
| 10612 | .ndo_set_mac_address = bnx2x_change_mac_addr, |
| 10613 | .ndo_validate_addr = eth_validate_addr, |
| 10614 | .ndo_do_ioctl = bnx2x_ioctl, |
| 10615 | .ndo_change_mtu = bnx2x_change_mtu, |
| 10616 | .ndo_tx_timeout = bnx2x_tx_timeout, |
| 10617 | #ifdef BCM_VLAN |
| 10618 | .ndo_vlan_rx_register = bnx2x_vlan_rx_register, |
| 10619 | #endif |
| 10620 | #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER) |
| 10621 | .ndo_poll_controller = poll_bnx2x, |
| 10622 | #endif |
| 10623 | }; |
| 10624 | |
| 10625 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10626 | static int __devinit bnx2x_init_dev(struct pci_dev *pdev, |
| 10627 | struct net_device *dev) |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10628 | { |
| 10629 | struct bnx2x *bp; |
| 10630 | int rc; |
| 10631 | |
| 10632 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 10633 | bp = netdev_priv(dev); |
| 10634 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10635 | bp->dev = dev; |
| 10636 | bp->pdev = pdev; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10637 | bp->flags = 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10638 | bp->func = PCI_FUNC(pdev->devfn); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10639 | |
| 10640 | rc = pci_enable_device(pdev); |
| 10641 | if (rc) { |
| 10642 | printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n"); |
| 10643 | goto err_out; |
| 10644 | } |
| 10645 | |
| 10646 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 10647 | printk(KERN_ERR PFX "Cannot find PCI device base address," |
| 10648 | " aborting\n"); |
| 10649 | rc = -ENODEV; |
| 10650 | goto err_out_disable; |
| 10651 | } |
| 10652 | |
| 10653 | if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) { |
| 10654 | printk(KERN_ERR PFX "Cannot find second PCI device" |
| 10655 | " base address, aborting\n"); |
| 10656 | rc = -ENODEV; |
| 10657 | goto err_out_disable; |
| 10658 | } |
| 10659 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10660 | if (atomic_read(&pdev->enable_cnt) == 1) { |
| 10661 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 10662 | if (rc) { |
| 10663 | printk(KERN_ERR PFX "Cannot obtain PCI resources," |
| 10664 | " aborting\n"); |
| 10665 | goto err_out_disable; |
| 10666 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10667 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10668 | pci_set_master(pdev); |
| 10669 | pci_save_state(pdev); |
| 10670 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10671 | |
| 10672 | bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM); |
| 10673 | if (bp->pm_cap == 0) { |
| 10674 | printk(KERN_ERR PFX "Cannot find power management" |
| 10675 | " capability, aborting\n"); |
| 10676 | rc = -EIO; |
| 10677 | goto err_out_release; |
| 10678 | } |
| 10679 | |
| 10680 | bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 10681 | if (bp->pcie_cap == 0) { |
| 10682 | printk(KERN_ERR PFX "Cannot find PCI Express capability," |
| 10683 | " aborting\n"); |
| 10684 | rc = -EIO; |
| 10685 | goto err_out_release; |
| 10686 | } |
| 10687 | |
| 10688 | if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) { |
| 10689 | bp->flags |= USING_DAC_FLAG; |
| 10690 | if (pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK) != 0) { |
| 10691 | printk(KERN_ERR PFX "pci_set_consistent_dma_mask" |
| 10692 | " failed, aborting\n"); |
| 10693 | rc = -EIO; |
| 10694 | goto err_out_release; |
| 10695 | } |
| 10696 | |
| 10697 | } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) { |
| 10698 | printk(KERN_ERR PFX "System does not support DMA," |
| 10699 | " aborting\n"); |
| 10700 | rc = -EIO; |
| 10701 | goto err_out_release; |
| 10702 | } |
| 10703 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10704 | dev->mem_start = pci_resource_start(pdev, 0); |
| 10705 | dev->base_addr = dev->mem_start; |
| 10706 | dev->mem_end = pci_resource_end(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10707 | |
| 10708 | dev->irq = pdev->irq; |
| 10709 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 10710 | bp->regview = pci_ioremap_bar(pdev, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10711 | if (!bp->regview) { |
| 10712 | printk(KERN_ERR PFX "Cannot map register space, aborting\n"); |
| 10713 | rc = -ENOMEM; |
| 10714 | goto err_out_release; |
| 10715 | } |
| 10716 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10717 | bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2), |
| 10718 | min_t(u64, BNX2X_DB_SIZE, |
| 10719 | pci_resource_len(pdev, 2))); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10720 | if (!bp->doorbells) { |
| 10721 | printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n"); |
| 10722 | rc = -ENOMEM; |
| 10723 | goto err_out_unmap; |
| 10724 | } |
| 10725 | |
| 10726 | bnx2x_set_power_state(bp, PCI_D0); |
| 10727 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10728 | /* clean indirect addresses */ |
| 10729 | pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, |
| 10730 | PCICFG_VENDOR_ID_OFFSET); |
| 10731 | REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0); |
| 10732 | REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0); |
| 10733 | REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0); |
| 10734 | REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10735 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10736 | dev->watchdog_timeo = TX_TIMEOUT; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10737 | |
Stephen Hemminger | c64213c | 2008-11-21 17:36:04 -0800 | [diff] [blame] | 10738 | dev->netdev_ops = &bnx2x_netdev_ops; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10739 | dev->ethtool_ops = &bnx2x_ethtool_ops; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10740 | dev->features |= NETIF_F_SG; |
| 10741 | dev->features |= NETIF_F_HW_CSUM; |
| 10742 | if (bp->flags & USING_DAC_FLAG) |
| 10743 | dev->features |= NETIF_F_HIGHDMA; |
| 10744 | #ifdef BCM_VLAN |
| 10745 | dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX); |
Eilon Greenstein | 0c6671b | 2009-01-14 21:26:51 -0800 | [diff] [blame] | 10746 | bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10747 | #endif |
| 10748 | dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN); |
Eilon Greenstein | 755735eb | 2008-06-23 20:35:13 -0700 | [diff] [blame] | 10749 | dev->features |= NETIF_F_TSO6; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10750 | |
| 10751 | return 0; |
| 10752 | |
| 10753 | err_out_unmap: |
| 10754 | if (bp->regview) { |
| 10755 | iounmap(bp->regview); |
| 10756 | bp->regview = NULL; |
| 10757 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10758 | if (bp->doorbells) { |
| 10759 | iounmap(bp->doorbells); |
| 10760 | bp->doorbells = NULL; |
| 10761 | } |
| 10762 | |
| 10763 | err_out_release: |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10764 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10765 | pci_release_regions(pdev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10766 | |
| 10767 | err_out_disable: |
| 10768 | pci_disable_device(pdev); |
| 10769 | pci_set_drvdata(pdev, NULL); |
| 10770 | |
| 10771 | err_out: |
| 10772 | return rc; |
| 10773 | } |
| 10774 | |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 10775 | static int __devinit bnx2x_get_pcie_width(struct bnx2x *bp) |
| 10776 | { |
| 10777 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); |
| 10778 | |
| 10779 | val = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT; |
| 10780 | return val; |
| 10781 | } |
| 10782 | |
| 10783 | /* return value of 1=2.5GHz 2=5GHz */ |
| 10784 | static int __devinit bnx2x_get_pcie_speed(struct bnx2x *bp) |
| 10785 | { |
| 10786 | u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL); |
| 10787 | |
| 10788 | val = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT; |
| 10789 | return val; |
| 10790 | } |
| 10791 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10792 | static int __devinit bnx2x_init_one(struct pci_dev *pdev, |
| 10793 | const struct pci_device_id *ent) |
| 10794 | { |
| 10795 | static int version_printed; |
| 10796 | struct net_device *dev = NULL; |
| 10797 | struct bnx2x *bp; |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 10798 | int rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10799 | |
| 10800 | if (version_printed++ == 0) |
| 10801 | printk(KERN_INFO "%s", version); |
| 10802 | |
| 10803 | /* dev zeroed in init_etherdev */ |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10804 | dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10805 | if (!dev) { |
| 10806 | printk(KERN_ERR PFX "Cannot allocate net device\n"); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10807 | return -ENOMEM; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10808 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10809 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10810 | bp = netdev_priv(dev); |
| 10811 | bp->msglevel = debug; |
| 10812 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10813 | rc = bnx2x_init_dev(pdev, dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10814 | if (rc < 0) { |
| 10815 | free_netdev(dev); |
| 10816 | return rc; |
| 10817 | } |
| 10818 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10819 | pci_set_drvdata(pdev, dev); |
| 10820 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10821 | rc = bnx2x_init_bp(bp); |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 10822 | if (rc) |
| 10823 | goto init_one_exit; |
| 10824 | |
| 10825 | rc = register_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10826 | if (rc) { |
Eilon Greenstein | 693fc0d | 2009-01-14 06:43:52 +0000 | [diff] [blame] | 10827 | dev_err(&pdev->dev, "Cannot register net device\n"); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10828 | goto init_one_exit; |
| 10829 | } |
| 10830 | |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 10831 | printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx," |
Eilon Greenstein | 87942b4 | 2009-02-12 08:36:49 +0000 | [diff] [blame^] | 10832 | " IRQ %d, ", dev->name, board_info[ent->driver_data].name, |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10833 | (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4), |
Eliezer Tamir | 2504795 | 2008-02-28 11:50:16 -0800 | [diff] [blame] | 10834 | bnx2x_get_pcie_width(bp), |
| 10835 | (bnx2x_get_pcie_speed(bp) == 2) ? "5GHz (Gen2)" : "2.5GHz", |
| 10836 | dev->base_addr, bp->pdev->irq); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 10837 | printk(KERN_CONT "node addr %pM\n", dev->dev_addr); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10838 | return 0; |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10839 | |
| 10840 | init_one_exit: |
| 10841 | if (bp->regview) |
| 10842 | iounmap(bp->regview); |
| 10843 | |
| 10844 | if (bp->doorbells) |
| 10845 | iounmap(bp->doorbells); |
| 10846 | |
| 10847 | free_netdev(dev); |
| 10848 | |
| 10849 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10850 | pci_release_regions(pdev); |
| 10851 | |
| 10852 | pci_disable_device(pdev); |
| 10853 | pci_set_drvdata(pdev, NULL); |
| 10854 | |
| 10855 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10856 | } |
| 10857 | |
| 10858 | static void __devexit bnx2x_remove_one(struct pci_dev *pdev) |
| 10859 | { |
| 10860 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10861 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10862 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10863 | if (!dev) { |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10864 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 10865 | return; |
| 10866 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10867 | bp = netdev_priv(dev); |
| 10868 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10869 | unregister_netdev(dev); |
| 10870 | |
| 10871 | if (bp->regview) |
| 10872 | iounmap(bp->regview); |
| 10873 | |
| 10874 | if (bp->doorbells) |
| 10875 | iounmap(bp->doorbells); |
| 10876 | |
| 10877 | free_netdev(dev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10878 | |
| 10879 | if (atomic_read(&pdev->enable_cnt) == 1) |
| 10880 | pci_release_regions(pdev); |
| 10881 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10882 | pci_disable_device(pdev); |
| 10883 | pci_set_drvdata(pdev, NULL); |
| 10884 | } |
| 10885 | |
| 10886 | static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state) |
| 10887 | { |
| 10888 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10889 | struct bnx2x *bp; |
| 10890 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10891 | if (!dev) { |
| 10892 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 10893 | return -ENODEV; |
| 10894 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10895 | bp = netdev_priv(dev); |
| 10896 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10897 | rtnl_lock(); |
| 10898 | |
| 10899 | pci_save_state(pdev); |
| 10900 | |
| 10901 | if (!netif_running(dev)) { |
| 10902 | rtnl_unlock(); |
| 10903 | return 0; |
| 10904 | } |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10905 | |
| 10906 | netif_device_detach(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10907 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 10908 | bnx2x_nic_unload(bp, UNLOAD_CLOSE); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10909 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10910 | bnx2x_set_power_state(bp, pci_choose_state(pdev, state)); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10911 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10912 | rtnl_unlock(); |
| 10913 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10914 | return 0; |
| 10915 | } |
| 10916 | |
| 10917 | static int bnx2x_resume(struct pci_dev *pdev) |
| 10918 | { |
| 10919 | struct net_device *dev = pci_get_drvdata(pdev); |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10920 | struct bnx2x *bp; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10921 | int rc; |
| 10922 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10923 | if (!dev) { |
| 10924 | printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n"); |
| 10925 | return -ENODEV; |
| 10926 | } |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10927 | bp = netdev_priv(dev); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10928 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10929 | rtnl_lock(); |
| 10930 | |
Eliezer Tamir | 228241e | 2008-02-28 11:56:57 -0800 | [diff] [blame] | 10931 | pci_restore_state(pdev); |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10932 | |
| 10933 | if (!netif_running(dev)) { |
| 10934 | rtnl_unlock(); |
| 10935 | return 0; |
| 10936 | } |
| 10937 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10938 | bnx2x_set_power_state(bp, PCI_D0); |
| 10939 | netif_device_attach(dev); |
| 10940 | |
Vladislav Zolotarov | da5a662 | 2008-08-13 15:50:00 -0700 | [diff] [blame] | 10941 | rc = bnx2x_nic_load(bp, LOAD_OPEN); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10942 | |
Eilon Greenstein | 34f80b0 | 2008-06-23 20:33:01 -0700 | [diff] [blame] | 10943 | rtnl_unlock(); |
| 10944 | |
| 10945 | return rc; |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 10946 | } |
| 10947 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10948 | static int bnx2x_eeh_nic_unload(struct bnx2x *bp) |
| 10949 | { |
| 10950 | int i; |
| 10951 | |
| 10952 | bp->state = BNX2X_STATE_ERROR; |
| 10953 | |
| 10954 | bp->rx_mode = BNX2X_RX_MODE_NONE; |
| 10955 | |
| 10956 | bnx2x_netif_stop(bp, 0); |
| 10957 | |
| 10958 | del_timer_sync(&bp->timer); |
| 10959 | bp->stats_state = STATS_STATE_DISABLED; |
| 10960 | DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n"); |
| 10961 | |
| 10962 | /* Release IRQs */ |
| 10963 | bnx2x_free_irq(bp); |
| 10964 | |
| 10965 | if (CHIP_IS_E1(bp)) { |
| 10966 | struct mac_configuration_cmd *config = |
| 10967 | bnx2x_sp(bp, mcast_config); |
| 10968 | |
Eilon Greenstein | 8d9c5f3 | 2009-02-15 23:24:08 -0800 | [diff] [blame] | 10969 | for (i = 0; i < config->hdr.length; i++) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10970 | CAM_INVALIDATE(config->config_table[i]); |
| 10971 | } |
| 10972 | |
| 10973 | /* Free SKBs, SGEs, TPA pool and driver internals */ |
| 10974 | bnx2x_free_skbs(bp); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10975 | for_each_rx_queue(bp, i) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10976 | bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE); |
Eilon Greenstein | 555f6c7 | 2009-02-12 08:36:11 +0000 | [diff] [blame] | 10977 | for_each_rx_queue(bp, i) |
Eilon Greenstein | 7cde1c8 | 2009-01-22 06:01:25 +0000 | [diff] [blame] | 10978 | netif_napi_del(&bnx2x_fp(bp, i, napi)); |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 10979 | bnx2x_free_mem(bp); |
| 10980 | |
| 10981 | bp->state = BNX2X_STATE_CLOSED; |
| 10982 | |
| 10983 | netif_carrier_off(bp->dev); |
| 10984 | |
| 10985 | return 0; |
| 10986 | } |
| 10987 | |
| 10988 | static void bnx2x_eeh_recover(struct bnx2x *bp) |
| 10989 | { |
| 10990 | u32 val; |
| 10991 | |
| 10992 | mutex_init(&bp->port.phy_mutex); |
| 10993 | |
| 10994 | bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR); |
| 10995 | bp->link_params.shmem_base = bp->common.shmem_base; |
| 10996 | BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base); |
| 10997 | |
| 10998 | if (!bp->common.shmem_base || |
| 10999 | (bp->common.shmem_base < 0xA0000) || |
| 11000 | (bp->common.shmem_base >= 0xC0000)) { |
| 11001 | BNX2X_DEV_INFO("MCP not active\n"); |
| 11002 | bp->flags |= NO_MCP_FLAG; |
| 11003 | return; |
| 11004 | } |
| 11005 | |
| 11006 | val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]); |
| 11007 | if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 11008 | != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB)) |
| 11009 | BNX2X_ERR("BAD MCP validity signature\n"); |
| 11010 | |
| 11011 | if (!BP_NOMCP(bp)) { |
| 11012 | bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header) |
| 11013 | & DRV_MSG_SEQ_NUMBER_MASK); |
| 11014 | BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq); |
| 11015 | } |
| 11016 | } |
| 11017 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11018 | /** |
| 11019 | * bnx2x_io_error_detected - called when PCI error is detected |
| 11020 | * @pdev: Pointer to PCI device |
| 11021 | * @state: The current pci connection state |
| 11022 | * |
| 11023 | * This function is called after a PCI bus error affecting |
| 11024 | * this device has been detected. |
| 11025 | */ |
| 11026 | static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev, |
| 11027 | pci_channel_state_t state) |
| 11028 | { |
| 11029 | struct net_device *dev = pci_get_drvdata(pdev); |
| 11030 | struct bnx2x *bp = netdev_priv(dev); |
| 11031 | |
| 11032 | rtnl_lock(); |
| 11033 | |
| 11034 | netif_device_detach(dev); |
| 11035 | |
| 11036 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11037 | bnx2x_eeh_nic_unload(bp); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11038 | |
| 11039 | pci_disable_device(pdev); |
| 11040 | |
| 11041 | rtnl_unlock(); |
| 11042 | |
| 11043 | /* Request a slot reset */ |
| 11044 | return PCI_ERS_RESULT_NEED_RESET; |
| 11045 | } |
| 11046 | |
| 11047 | /** |
| 11048 | * bnx2x_io_slot_reset - called after the PCI bus has been reset |
| 11049 | * @pdev: Pointer to PCI device |
| 11050 | * |
| 11051 | * Restart the card from scratch, as if from a cold-boot. |
| 11052 | */ |
| 11053 | static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev) |
| 11054 | { |
| 11055 | struct net_device *dev = pci_get_drvdata(pdev); |
| 11056 | struct bnx2x *bp = netdev_priv(dev); |
| 11057 | |
| 11058 | rtnl_lock(); |
| 11059 | |
| 11060 | if (pci_enable_device(pdev)) { |
| 11061 | dev_err(&pdev->dev, |
| 11062 | "Cannot re-enable PCI device after reset\n"); |
| 11063 | rtnl_unlock(); |
| 11064 | return PCI_ERS_RESULT_DISCONNECT; |
| 11065 | } |
| 11066 | |
| 11067 | pci_set_master(pdev); |
| 11068 | pci_restore_state(pdev); |
| 11069 | |
| 11070 | if (netif_running(dev)) |
| 11071 | bnx2x_set_power_state(bp, PCI_D0); |
| 11072 | |
| 11073 | rtnl_unlock(); |
| 11074 | |
| 11075 | return PCI_ERS_RESULT_RECOVERED; |
| 11076 | } |
| 11077 | |
| 11078 | /** |
| 11079 | * bnx2x_io_resume - called when traffic can start flowing again |
| 11080 | * @pdev: Pointer to PCI device |
| 11081 | * |
| 11082 | * This callback is called when the error recovery driver tells us that |
| 11083 | * its OK to resume normal operation. |
| 11084 | */ |
| 11085 | static void bnx2x_io_resume(struct pci_dev *pdev) |
| 11086 | { |
| 11087 | struct net_device *dev = pci_get_drvdata(pdev); |
| 11088 | struct bnx2x *bp = netdev_priv(dev); |
| 11089 | |
| 11090 | rtnl_lock(); |
| 11091 | |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11092 | bnx2x_eeh_recover(bp); |
| 11093 | |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11094 | if (netif_running(dev)) |
Yitchak Gertner | f8ef6e4 | 2008-09-09 05:07:25 -0700 | [diff] [blame] | 11095 | bnx2x_nic_load(bp, LOAD_NORMAL); |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11096 | |
| 11097 | netif_device_attach(dev); |
| 11098 | |
| 11099 | rtnl_unlock(); |
| 11100 | } |
| 11101 | |
| 11102 | static struct pci_error_handlers bnx2x_err_handler = { |
| 11103 | .error_detected = bnx2x_io_error_detected, |
| 11104 | .slot_reset = bnx2x_io_slot_reset, |
| 11105 | .resume = bnx2x_io_resume, |
| 11106 | }; |
| 11107 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11108 | static struct pci_driver bnx2x_pci_driver = { |
Wendy Xiong | 493adb1 | 2008-06-23 20:36:22 -0700 | [diff] [blame] | 11109 | .name = DRV_MODULE_NAME, |
| 11110 | .id_table = bnx2x_pci_tbl, |
| 11111 | .probe = bnx2x_init_one, |
| 11112 | .remove = __devexit_p(bnx2x_remove_one), |
| 11113 | .suspend = bnx2x_suspend, |
| 11114 | .resume = bnx2x_resume, |
| 11115 | .err_handler = &bnx2x_err_handler, |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11116 | }; |
| 11117 | |
| 11118 | static int __init bnx2x_init(void) |
| 11119 | { |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 11120 | bnx2x_wq = create_singlethread_workqueue("bnx2x"); |
| 11121 | if (bnx2x_wq == NULL) { |
| 11122 | printk(KERN_ERR PFX "Cannot create workqueue\n"); |
| 11123 | return -ENOMEM; |
| 11124 | } |
| 11125 | |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11126 | return pci_register_driver(&bnx2x_pci_driver); |
| 11127 | } |
| 11128 | |
| 11129 | static void __exit bnx2x_cleanup(void) |
| 11130 | { |
| 11131 | pci_unregister_driver(&bnx2x_pci_driver); |
Eilon Greenstein | 1cf167f | 2009-01-14 21:22:18 -0800 | [diff] [blame] | 11132 | |
| 11133 | destroy_workqueue(bnx2x_wq); |
Eliezer Tamir | a2fbb9e | 2007-11-15 20:09:02 +0200 | [diff] [blame] | 11134 | } |
| 11135 | |
| 11136 | module_init(bnx2x_init); |
| 11137 | module_exit(bnx2x_cleanup); |
| 11138 | |